From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 7/9] Add second mi_parse constructor
Date: Thu, 18 May 2023 14:18:13 -0600 [thread overview]
Message-ID: <20230404-dap-loaded-sources-v2-7-93f229095e03@adacore.com> (raw)
In-Reply-To: <20230404-dap-loaded-sources-v2-0-93f229095e03@adacore.com>
This adds a second mi_parse constructor. This constructor takes a
command name and vector of arguments, and does not do any escape
processing. This also changes mi_parse::args to handle parse objects
created this new way.
---
gdb/mi/mi-parse.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
gdb/mi/mi-parse.h | 12 +++++--
2 files changed, 107 insertions(+), 2 deletions(-)
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
index 09207164291..a113d4d48da 100644
--- a/gdb/mi/mi-parse.c
+++ b/gdb/mi/mi-parse.c
@@ -109,6 +109,11 @@ mi_parse_escape (const char **string_ptr)
void
mi_parse::parse_argv ()
{
+ /* If arguments were already computed (or were supplied at
+ construction), then there's no need to re-compute them. */
+ if (argv != nullptr)
+ return;
+
const char *chp = m_args.c_str ();
int argc = 0;
char **argv = XNEWVEC (char *, argc + 1);
@@ -217,6 +222,27 @@ mi_parse::~mi_parse ()
/* See mi-parse.h. */
+const char *
+mi_parse::args ()
+{
+ /* If args were already computed, or if there is no pre-computed
+ argv, just return the args. */
+ if (!m_args.empty () || argv == nullptr)
+ return m_args.c_str ();
+
+ /* Compute args from argv. */
+ for (int i = 0; i < argc; ++i)
+ {
+ if (!m_args.empty ())
+ m_args += " ";
+ m_args += argv[i];
+ }
+
+ return m_args.c_str ();
+}
+
+/* See mi-parse.h. */
+
void
mi_parse::set_thread_group (const char *arg, char **endp)
{
@@ -387,6 +413,77 @@ mi_parse::make (const char *cmd, char **token)
return parse;
}
+/* See mi-parse.h. */
+
+std::unique_ptr<struct mi_parse>
+mi_parse::make (gdb::unique_xmalloc_ptr<char> command,
+ std::vector<gdb::unique_xmalloc_ptr<char>> args)
+{
+ std::unique_ptr<struct mi_parse> parse (new struct mi_parse);
+
+ parse->command = command.release ();
+ parse->token = xstrdup ("");
+
+ if (parse->command[0] != '-')
+ throw_error (UNDEFINED_COMMAND_ERROR,
+ _("MI command '%s' does not start with '-'"),
+ parse->command);
+
+ /* Find the command in the MI table. */
+ parse->cmd = mi_cmd_lookup (parse->command + 1);
+ if (parse->cmd == NULL)
+ throw_error (UNDEFINED_COMMAND_ERROR,
+ _("Undefined MI command: %s"), parse->command);
+
+ /* This over-allocates slightly, but it seems unimportant. */
+ parse->argv = XCNEWVEC (char *, args.size () + 1);
+
+ for (size_t i = 0; i < args.size (); ++i)
+ {
+ const char *chp = args[i].get ();
+
+ /* See if --all is the last token in the input. */
+ if (strcmp (chp, "--all") == 0)
+ {
+ parse->all = 1;
+ }
+ else if (strcmp (chp, "--thread-group") == 0)
+ {
+ ++i;
+ if (i == args.size ())
+ error ("No argument to '--thread-group'");
+ parse->set_thread_group (args[i].get (), nullptr);
+ }
+ else if (strcmp (chp, "--thread") == 0)
+ {
+ ++i;
+ if (i == args.size ())
+ error ("No argument to '--thread'");
+ parse->set_thread (args[i].get (), nullptr);
+ }
+ else if (strcmp (chp, "--frame") == 0)
+ {
+ ++i;
+ if (i == args.size ())
+ error ("No argument to '--frame'");
+ parse->set_frame (args[i].get (), nullptr);
+ }
+ else if (strcmp (chp, "--language") == 0)
+ {
+ ++i;
+ if (i == args.size ())
+ error ("No argument to '--language'");
+ parse->set_language (args[i].get (), nullptr);
+ }
+ else
+ parse->argv[parse->argc++] = args[i].release ();
+ }
+
+ /* Fully parsed, flag as an MI command. */
+ parse->op = MI_COMMAND;
+ return parse;
+}
+
enum print_values
mi_parse_print_values (const char *name)
{
diff --git a/gdb/mi/mi-parse.h b/gdb/mi/mi-parse.h
index 19c41f23ed6..6373543529b 100644
--- a/gdb/mi/mi-parse.h
+++ b/gdb/mi/mi-parse.h
@@ -52,6 +52,15 @@ struct mi_parse
static std::unique_ptr<struct mi_parse> make (const char *cmd,
char **token);
+ /* Create an mi_parse object given the command name and a vector
+ of arguments. Unlike with the other constructor, here the
+ arguments are treated "as is" -- no escape processing is
+ done. */
+
+ static std::unique_ptr<struct mi_parse> make
+ (gdb::unique_xmalloc_ptr<char> command,
+ std::vector<gdb::unique_xmalloc_ptr<char>> args);
+
~mi_parse ();
DISABLE_COPY_AND_ASSIGN (mi_parse);
@@ -61,8 +70,7 @@ struct mi_parse
/* Return the full argument string, as used by commands which are
implemented as CLI commands. */
- const char *args () const
- { return m_args.c_str (); }
+ const char *args ();
enum mi_command_type op = MI_COMMAND;
char *command = nullptr;
--
2.40.0
next prev parent reply other threads:[~2023-05-18 20:18 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-18 20:18 [PATCH v2 0/9] Implement the DAP "loadedSources" request Tom Tromey
2023-05-18 20:18 ` [PATCH v2 1/9] Use field_signed from Python MI commands Tom Tromey
2023-05-18 20:18 ` [PATCH v2 2/9] Use member initializers in mi_parse Tom Tromey
2023-05-18 20:18 ` [PATCH v2 3/9] Use accessor for mi_parse::args Tom Tromey
2023-05-18 20:18 ` [PATCH v2 4/9] Change mi_parse_argv to a method Tom Tromey
2023-05-18 20:18 ` [PATCH v2 5/9] Introduce "static constructor" for mi_parse Tom Tromey
2023-08-11 11:02 ` Andrew Burgess
2023-08-11 13:10 ` Tom Tromey
2023-08-11 15:06 ` Andrew Burgess
2023-05-18 20:18 ` [PATCH v2 6/9] Introduce mi_parse helper methods Tom Tromey
2023-05-18 20:18 ` Tom Tromey [this message]
2023-05-18 20:18 ` [PATCH v2 8/9] Implement gdb.execute_mi Tom Tromey
2023-05-19 5:37 ` Eli Zaretskii
2023-05-29 15:54 ` Simon Marchi
2023-06-02 19:19 ` Tom Tromey
2023-06-08 20:16 ` Tom Tromey
2023-05-18 20:18 ` [PATCH v2 9/9] Implement DAP loadedSources request Tom Tromey
2023-05-23 19:46 ` [PATCH v2 0/9] Implement the DAP "loadedSources" request Tom Tromey
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-v2-7-93f229095e03@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).