From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 6/9] Introduce mi_parse helper methods
Date: Thu, 18 May 2023 14:18:12 -0600 [thread overview]
Message-ID: <20230404-dap-loaded-sources-v2-6-93f229095e03@adacore.com> (raw)
In-Reply-To: <20230404-dap-loaded-sources-v2-0-93f229095e03@adacore.com>
This introduces some helper methods for mi_parse that handle some of
the details of parsing. This approach lets us reuse them later.
---
gdb/mi/mi-parse.c | 69 +++++++++++++++++++++++++++++++++++++++++--------------
gdb/mi/mi-parse.h | 9 ++++++++
2 files changed, 61 insertions(+), 17 deletions(-)
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
index b7c5a8cecdf..09207164291 100644
--- a/gdb/mi/mi-parse.c
+++ b/gdb/mi/mi-parse.c
@@ -215,6 +215,54 @@ mi_parse::~mi_parse ()
freeargv (argv);
}
+/* See mi-parse.h. */
+
+void
+mi_parse::set_thread_group (const char *arg, char **endp)
+{
+ if (thread_group != -1)
+ error (_("Duplicate '--thread-group' option"));
+ if (*arg != 'i')
+ error (_("Invalid thread group id"));
+ arg += 1;
+ thread_group = strtol (arg, endp, 10);
+}
+
+/* See mi-parse.h. */
+
+void
+mi_parse::set_thread (const char *arg, char **endp)
+{
+ if (thread != -1)
+ error (_("Duplicate '--thread' option"));
+ thread = strtol (arg, endp, 10);
+}
+
+/* See mi-parse.h. */
+
+void
+mi_parse::set_frame (const char *arg, char **endp)
+{
+ if (frame != -1)
+ error (_("Duplicate '--frame' option"));
+ frame = strtol (arg, endp, 10);
+}
+
+/* See mi-parse.h. */
+
+void
+mi_parse::set_language (const char *arg, const char **endp)
+{
+ std::string lang_name = extract_arg (&arg);
+
+ language = language_enum (lang_name.c_str ());
+ if (language == language_unknown)
+ error (_("Invalid --language argument: %s"), lang_name.c_str ());
+
+ if (endp != nullptr)
+ *endp = arg;
+}
+
std::unique_ptr<struct mi_parse>
mi_parse::make (const char *cmd, char **token)
{
@@ -295,13 +343,8 @@ mi_parse::make (const char *cmd, char **token)
char *endp;
option = "--thread-group";
- if (parse->thread_group != -1)
- error (_("Duplicate '--thread-group' option"));
chp += tgs;
- if (*chp != 'i')
- error (_("Invalid thread group id"));
- chp += 1;
- parse->thread_group = strtol (chp, &endp, 10);
+ parse->set_thread_group (chp, &endp);
chp = endp;
}
else if (strncmp (chp, "--thread ", ts) == 0)
@@ -309,10 +352,8 @@ mi_parse::make (const char *cmd, char **token)
char *endp;
option = "--thread";
- if (parse->thread != -1)
- error (_("Duplicate '--thread' option"));
chp += ts;
- parse->thread = strtol (chp, &endp, 10);
+ parse->set_thread (chp, &endp);
chp = endp;
}
else if (strncmp (chp, "--frame ", fs) == 0)
@@ -320,21 +361,15 @@ mi_parse::make (const char *cmd, char **token)
char *endp;
option = "--frame";
- if (parse->frame != -1)
- error (_("Duplicate '--frame' option"));
chp += fs;
- parse->frame = strtol (chp, &endp, 10);
+ parse->set_frame (chp, &endp);
chp = endp;
}
else if (strncmp (chp, "--language ", ls) == 0)
{
option = "--language";
chp += ls;
- std::string lang_name = extract_arg (&chp);
-
- parse->language = language_enum (lang_name.c_str ());
- if (parse->language == language_unknown)
- error (_("Invalid --language argument: %s"), lang_name.c_str ());
+ parse->set_language (chp, &chp);
}
else
break;
diff --git a/gdb/mi/mi-parse.h b/gdb/mi/mi-parse.h
index 6f1da6e6eb5..19c41f23ed6 100644
--- a/gdb/mi/mi-parse.h
+++ b/gdb/mi/mi-parse.h
@@ -84,6 +84,15 @@ struct mi_parse
mi_parse () = default;
+ /* Helper methods for parsing arguments. Each takes the argument
+ to be parsed. It will either set a member of this object, or
+ throw an exception on error. In each case, *ENDP, if non-NULL,
+ will be updated to just after the argument text. */
+ void set_thread_group (const char *arg, char **endp);
+ void set_thread (const char *arg, char **endp);
+ void set_frame (const char *arg, char **endp);
+ void set_language (const char *arg, const char **endp);
+
std::string m_args;
};
--
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 ` Tom Tromey [this message]
2023-05-18 20:18 ` [PATCH v2 7/9] Add second mi_parse constructor Tom Tromey
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-6-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).