From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
To: gdb-patches@sourceware.org
Cc: Philippe Waroquiers <philippe.waroquiers@skynet.be>
Subject: [RFC 1/5] New cli-utils.h/.c function extract_info_print_args
Date: Sun, 01 Jul 2018 21:07:00 -0000 [thread overview]
Message-ID: <20180701210734.3793-2-philippe.waroquiers@skynet.be> (raw)
In-Reply-To: <20180701210734.3793-1-philippe.waroquiers@skynet.be>
New cli-utils.h/.c function extract_info_print_args factorises
the extraction of the args '[-q] [-t TYPEREGEXP] [NAMEREGEXP]'.
This function is used by the commands
info [args|functions|locals|variables]
cli-utils.c has a new static function extract_arg_maybe_quoted
that extracts an argument, possibly single quoted.
---
gdb/cli/cli-utils.c | 113 ++++++++++++++++++++++++++++++++++++++++++++
gdb/cli/cli-utils.h | 20 ++++++++
2 files changed, 133 insertions(+)
diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index c55b5035e4..3f33c18a06 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -23,6 +23,9 @@
#include <ctype.h>
+static std::string
+extract_arg_maybe_quoted (const char **arg);
+
/* See documentation in cli-utils.h. */
int
@@ -125,6 +128,56 @@ get_number (char **pp)
return result;
}
+/* See documentation in cli-utils.h. */
+
+void
+extract_info_print_args (const char* command,
+ const char **args,
+ bool *quiet,
+ std::string *regexp,
+ std::string *t_regexp)
+{
+ *quiet = false;
+ *regexp = "";
+ *t_regexp = "";
+
+ while (*args != NULL)
+ {
+ if (check_for_argument (args, "--", 2))
+ {
+ *args = skip_spaces (*args);
+ break;
+ }
+
+ if (check_for_argument (args, "-t", 2))
+ {
+ *t_regexp = extract_arg_maybe_quoted (args);
+ *args = skip_spaces (*args);
+ continue;
+ }
+
+ if (check_for_argument (args, "-q", 2))
+ {
+ *quiet = true;
+ *args = skip_spaces (*args);
+ continue;
+ }
+
+ if (**args != '-')
+ break;
+
+ std::string option = extract_arg (args);
+ error (_("Unrecognized option '%s' to %s command. "
+ "Try \"help %s\"."), option.c_str (),
+ command, command);
+ }
+
+ if (*args != NULL && **args != '\000')
+ *regexp = extract_arg (args);
+
+}
+
+
/* See documentation in cli-utils.h. */
number_or_range_parser::number_or_range_parser (const char *string)
@@ -253,6 +306,66 @@ remove_trailing_whitespace (const char *start, const char *s)
return s;
}
+/* A helper function to extract an argument from *ARG. An argument is
+ delimited by whitespace, but it can also be optionally quoted using
+ single quote characters. The return value is empty if no argument
+ was found. */
+
+static std::string
+extract_arg_maybe_quoted (const char **arg)
+{
+ if (!*arg)
+ return std::string ();
+
+ /* Find the start of the argument. */
+ *arg = skip_spaces (*arg);
+ if (!**arg)
+ return std::string ();
+
+ if (**arg == '\'')
+ {
+ /* Quoted argument. */
+ const char *orig_arg = *arg;
+ std::string result;
+ const char *p;
+
+ (*arg)++; /* Skip starting quote. */
+
+ /* Find the end of the quoted argument. */
+ for (p = *arg; *p != '\0'; p++)
+ {
+ if (*p == '\'')
+ {
+ (*arg)++; /* Skip ending quote. */
+ return result;
+ }
+
+ if (*p == '\\' && p[1] == '\'')
+ {
+ /* Escaped quote. */
+ p++; /* Skip escape char. */
+ (*arg)++; /* Skip escape char. */
+ }
+
+ result = result + *p;
+ (*arg)++;
+ }
+ error (_("Unterminated quoted argument in %s"), orig_arg);
+ }
+ else
+ {
+ const char *result = *arg;
+
+ /* Find the end of the argument. */
+ *arg = skip_to_space (*arg + 1);
+
+ if (result == *arg)
+ return std::string ();
+
+ return std::string (result, *arg - result);
+ }
+}
+
/* See documentation in cli-utils.h. */
std::string
diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h
index e34ee0df37..f756f0d331 100644
--- a/gdb/cli/cli-utils.h
+++ b/gdb/cli/cli-utils.h
@@ -39,6 +39,26 @@ extern int get_number (const char **);
extern int get_number (char **);
+/* Extract from args the arguments [-q] [-t TYPEREGEXP] [--] NAMEREGEXP.
+ Only the above flags are accepted. any other flag will raise an error.
+ COMMAND is used to produce the error message if an invalid flag is
+ given. */
+extern void extract_info_print_args (const char* command,
+ const char **args,
+ bool *quiet,
+ std::string *regexp,
+ std::string *t_regexp);
+
+#define INFO_PRINT_ARGS_HELP(entity_kind) \
+"If NAMEREGEXP is provided, only prints the " entity_kind " whose name\n\
+matches NAMEREGEXP.\n\
+If -t TYPEREGEXP is provided, only prints the " entity_kind " whose type\n\
+matches TYPEREGEXP. Note that the matching is done with the type\n\
+printed by the 'whatis' command.\n\
+By default, the command might produce headers and/or messages indicating\n\
+why no " entity_kind " can be printed.\n\
+The flag -q disables the production of these headers and messages."
+
/* Parse a number or a range.
A number will be of the form handled by get_number.
A range will be of the form <number1> - <number2>, and
--
2.17.1
prev parent reply other threads:[~2018-07-01 21:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-01 21:07 [RFC 0/5] info [args|functions|locals|variables] [-q] [-t TYPEREGEXP] [NAMEREGEXP] Philippe Waroquiers
2018-07-01 21:07 ` [RFC 2/5] Make struct type_print_options default_ptype_flags non static Philippe Waroquiers
2018-07-01 21:07 ` [RFC 3/5] Add [-q] [-t TYPEREGEXP] [NAMEREGEXP] args to info [args|functions|locals|variables] Philippe Waroquiers
2018-07-02 15:06 ` Eli Zaretskii
2018-07-01 21:07 ` [RFC 4/5] Document changes " Philippe Waroquiers
2018-07-02 15:02 ` Eli Zaretskii
2018-07-02 20:46 ` Philippe Waroquiers
2018-07-04 16:44 ` Eli Zaretskii
2018-07-01 21:07 ` [RFC 5/5] Announce changes in NEWS " Philippe Waroquiers
2018-07-02 14:51 ` Eli Zaretskii
2018-07-01 21:07 ` Philippe Waroquiers [this message]
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=20180701210734.3793-2-philippe.waroquiers@skynet.be \
--to=philippe.waroquiers@skynet.be \
--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).