From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 5/9] Introduce "static constructor" for mi_parse
Date: Tue, 04 Apr 2023 11:08:53 -0600 [thread overview]
Message-ID: <20230404-dap-loaded-sources-v1-5-75c796bd644b@adacore.com> (raw)
In-Reply-To: <20230404-dap-loaded-sources-v1-0-75c796bd644b@adacore.com>
Change the mi_parse function to be a static method of mi_parse. This
lets us remove the 'set_args' setter function.
---
gdb/mi/mi-main.c | 2 +-
gdb/mi/mi-parse.c | 6 +++---
gdb/mi/mi-parse.h | 28 +++++++++++++---------------
3 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 1149cb984d3..3a114589e7c 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1917,7 +1917,7 @@ mi_execute_command (const char *cmd, int from_tty)
try
{
- command = mi_parse (cmd, &token);
+ command = mi_parse::make (cmd, &token);
}
catch (const gdb_exception &exception)
{
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
index db3c4ae2368..57b9c46fc24 100644
--- a/gdb/mi/mi-parse.c
+++ b/gdb/mi/mi-parse.c
@@ -109,7 +109,7 @@ mi_parse_escape (const char **string_ptr)
void
mi_parse::parse_argv ()
{
- const char *chp = m_args.get ();
+ const char *chp = m_args.c_str ();
int argc = 0;
char **argv = XNEWVEC (char *, argc + 1);
@@ -216,7 +216,7 @@ mi_parse::~mi_parse ()
}
std::unique_ptr<struct mi_parse>
-mi_parse (const char *cmd, char **token)
+mi_parse::make (const char *cmd, char **token)
{
const char *chp;
@@ -346,7 +346,7 @@ mi_parse (const char *cmd, char **token)
}
/* Save the rest of the arguments for the command. */
- parse->set_args (chp);
+ parse->m_args = chp;
/* Fully parsed, flag as an MI command. */
parse->op = MI_COMMAND;
diff --git a/gdb/mi/mi-parse.h b/gdb/mi/mi-parse.h
index edb61547354..6f1da6e6eb5 100644
--- a/gdb/mi/mi-parse.h
+++ b/gdb/mi/mi-parse.h
@@ -41,7 +41,17 @@ enum mi_command_type
struct mi_parse
{
- mi_parse () = default;
+ /* Attempts to parse CMD returning a ``struct mi_parse''. If CMD is
+ invalid, an exception is thrown. For an MI_COMMAND COMMAND, ARGS
+ and OP are initialized. Un-initialized fields are zero. *TOKEN is
+ set to the token, even if an exception is thrown. It is allocated
+ with xmalloc; it must either be freed with xfree, or assigned to
+ the TOKEN field of the resultant mi_parse object, to be freed by
+ mi_parse_free. */
+
+ static std::unique_ptr<struct mi_parse> make (const char *cmd,
+ char **token);
+
~mi_parse ();
DISABLE_COPY_AND_ASSIGN (mi_parse);
@@ -54,9 +64,6 @@ struct mi_parse
const char *args () const
{ return m_args.c_str (); }
- void set_args (const char *args)
- { m_args = args; }
-
enum mi_command_type op = MI_COMMAND;
char *command = nullptr;
char *token = nullptr;
@@ -75,20 +82,11 @@ struct mi_parse
private:
+ mi_parse () = default;
+
std::string m_args;
};
-/* Attempts to parse CMD returning a ``struct mi_parse''. If CMD is
- invalid, an exception is thrown. For an MI_COMMAND COMMAND, ARGS
- and OP are initialized. Un-initialized fields are zero. *TOKEN is
- set to the token, even if an exception is thrown. It is allocated
- with xmalloc; it must either be freed with xfree, or assigned to
- the TOKEN field of the resultant mi_parse object, to be freed by
- mi_parse_free. */
-
-extern std::unique_ptr<struct mi_parse> mi_parse (const char *cmd,
- char **token);
-
/* Parse a string argument into a print_values value. */
enum print_values mi_parse_print_values (const char *name);
--
2.39.1
next prev parent reply other threads:[~2023-04-04 17:08 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-04 17:08 [PATCH 0/9] Implement the DAP "loadedSources" request Tom Tromey
2023-04-04 17:08 ` [PATCH 1/9] Use field_signed from Python MI commands Tom Tromey
2023-04-04 17:08 ` [PATCH 2/9] Use member initializers in mi_parse Tom Tromey
2023-04-04 17:08 ` [PATCH 3/9] Use accessor for mi_parse::args Tom Tromey
2023-04-04 17:08 ` [PATCH 4/9] Change mi_parse_argv to a method Tom Tromey
2023-04-04 17:08 ` Tom Tromey [this message]
2023-04-04 17:08 ` [PATCH 6/9] Introduce mi_parse helper methods Tom Tromey
2023-04-04 17:08 ` [PATCH 7/9] Add second mi_parse constructor Tom Tromey
2023-04-04 17:08 ` [PATCH 8/9] Implement gdb.execute_mi Tom Tromey
2023-04-04 19:08 ` Eli Zaretskii
2023-05-18 17:57 ` Tom Tromey
2023-05-18 18:31 ` Eli Zaretskii
2023-05-18 20:15 ` Tom Tromey
2023-05-18 20:34 ` Matt Rice
2023-05-19 15:57 ` Tom Tromey
2023-04-04 17:08 ` [PATCH 9/9] Implement DAP loadedSources request Tom Tromey
2023-04-10 23:43 ` [PATCH 0/9] Implement the DAP "loadedSources" request Matt Rice
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230404-dap-loaded-sources-v1-5-75c796bd644b@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).