* [RFA 2/3] New test for 'info sources [-d | -b] [--] [REGEXP]'.
2019-03-31 19:08 [RFA 0/3] new arguments [-d | -b] [--] [REGEXP] to info sources Philippe Waroquiers
@ 2019-03-31 19:08 ` Philippe Waroquiers
2019-06-07 18:11 ` Tom Tromey
2019-03-31 19:08 ` [RFA 3/3] NEWS and documentation for new info sources [-d | -b] [--] [REGEXP] args Philippe Waroquiers
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Philippe Waroquiers @ 2019-03-31 19:08 UTC (permalink / raw)
To: gdb-patches; +Cc: Philippe Waroquiers
gdb/testsuite/ChangeLog
2019-03-31 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* gdb.base/info_sources.exp: New file.
* gdb.base/info_sources.c: New file.
* gdb.base/info_sources_base.c: New file.
---
gdb/testsuite/gdb.base/info_sources.c | 23 ++++++
gdb/testsuite/gdb.base/info_sources.exp | 85 ++++++++++++++++++++++
gdb/testsuite/gdb.base/info_sources_base.c | 5 ++
3 files changed, 113 insertions(+)
create mode 100644 gdb/testsuite/gdb.base/info_sources.c
create mode 100644 gdb/testsuite/gdb.base/info_sources.exp
create mode 100644 gdb/testsuite/gdb.base/info_sources_base.c
diff --git a/gdb/testsuite/gdb.base/info_sources.c b/gdb/testsuite/gdb.base/info_sources.c
new file mode 100644
index 0000000000..75fab6df70
--- /dev/null
+++ b/gdb/testsuite/gdb.base/info_sources.c
@@ -0,0 +1,23 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2019 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+extern void some_other_func (void);
+int main ()
+{
+ some_other_func ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/info_sources.exp b/gdb/testsuite/gdb.base/info_sources.exp
new file mode 100644
index 0000000000..e5a08f1c5e
--- /dev/null
+++ b/gdb/testsuite/gdb.base/info_sources.exp
@@ -0,0 +1,85 @@
+# Copyright 2019 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test 'info sources [-d | -b] [--] [REGEáº]'
+
+standard_testfile .c info_sources_base.c
+
+if {[prepare_for_testing $testfile.exp $testfile \
+ [list $srcfile $srcfile2] debug]} {
+ untested $testfile.exp
+ return -1
+}
+
+proc test_info_sources {args expect_seen_info_sources expect_seen_info_sources_base} {
+ global gdb_prompt
+
+ set seen_info_sources 0
+ set seen_info_sources_base 0
+ set cmd [concat "info sources " $args]
+ gdb_test_multiple $cmd $cmd {
+ -re "^\[^,\]*info_sources.c(, |\[\r\n\]+)" {
+ set seen_info_sources 1
+ exp_continue
+ }
+ -re "^\[^,\]*info_sources_base.c(, |\[\r\n\]+)" {
+ set seen_info_sources_base 1
+ exp_continue
+ }
+ -re ", " {
+ exp_continue
+ }
+ -re "$gdb_prompt $" {
+ if {$seen_info_sources == $expect_seen_info_sources \
+ && $seen_info_sources_base == $expect_seen_info_sources_base} {
+ pass $cmd
+ } else {
+ fail $cmd
+ }
+ }
+ }
+}
+
+if ![runto_main] {
+ untested $testfile.exp
+ return -1
+}
+gdb_test "break some_other_func" ""
+
+gdb_test "continue"
+
+# List both files with no regexp:
+test_info_sources "" 1 1
+# Same but with option terminator:
+test_info_sources "--" 1 1
+
+# List both files with regexp matching anywhere in the filenames:
+test_info_sources "info_sources" 1 1
+test_info_sources "gdb.base" 1 1
+
+# List both files with regexp matching the filename basenames:
+test_info_sources "-b info_sources" 1 1
+test_info_sources "-b -- info_sources" 1 1
+
+# List only the file with basename matching regexp:
+test_info_sources "-b base" 0 1
+
+# List the files with dirname matching regexp:
+test_info_sources "-d base" 1 1
+
+# Test non matching regexp, with option terminator:
+test_info_sources "-b -- -d" 0 0
+test_info_sources "-d -- -d" 0 0
+
diff --git a/gdb/testsuite/gdb.base/info_sources_base.c b/gdb/testsuite/gdb.base/info_sources_base.c
new file mode 100644
index 0000000000..a4c03a0341
--- /dev/null
+++ b/gdb/testsuite/gdb.base/info_sources_base.c
@@ -0,0 +1,5 @@
+void some_other_func (void)
+{
+ return;
+}
+
--
2.20.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [RFA 3/3] NEWS and documentation for new info sources [-d | -b] [--] [REGEXP] args
2019-03-31 19:08 [RFA 0/3] new arguments [-d | -b] [--] [REGEXP] to info sources Philippe Waroquiers
2019-03-31 19:08 ` [RFA 2/3] New test for 'info sources [-d | -b] [--] [REGEXP]' Philippe Waroquiers
@ 2019-03-31 19:08 ` Philippe Waroquiers
2019-03-31 19:16 ` Eli Zaretskii
2019-03-31 19:08 ` [RFA 1/3] Implement info sources args [-d | -b] [--] [REGEXP] Philippe Waroquiers
2019-04-18 4:18 ` PING Re: [RFA 0/3] new arguments [-d | -b] [--] [REGEXP] to info sources Philippe Waroquiers
3 siblings, 1 reply; 8+ messages in thread
From: Philippe Waroquiers @ 2019-03-31 19:08 UTC (permalink / raw)
To: gdb-patches; +Cc: Philippe Waroquiers
gdb/ChangeLog
2019-03-31 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* NEWS: Mention changes to info sources.
gdb/doc/ChangeLog
2019-03-31 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* gdb.texinfo (info sources): Document new args.
---
gdb/NEWS | 8 ++++++++
gdb/doc/gdb.texinfo | 9 +++++++++
2 files changed, 17 insertions(+)
diff --git a/gdb/NEWS b/gdb/NEWS
index 4bfa15becf..04b2b45909 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -16,6 +16,14 @@
* Support for Pointer Authentication on AArch64 Linux.
+* Changed commands
+
+info sources [-d | -b] [--] [REGEXP]
+ This command has now optional arguments to only print the files
+ whose names match REGEXP. The arguments -d and -b allow to
+ restrict matching respectively to the dirname and basename
+ parts of the files.
+
*** Changes in GDB 8.3
* GDB and GDBserver now support access to additional registers on
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index bb958cf25d..66068816cd 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17985,6 +17985,15 @@ Print the names of all source files in your program for which there is
debugging information, organized into two lists: files whose symbols
have already been read, and files whose symbols will be read when needed.
+@item info sources [-d | -b] [--] [@var{regexp}]
+Like @samp{info sources}, but only print the names of the files
+matching the provided regexp.
+By default, the regexp is used to match anywhere in the filename.
+If -d, only files having a dirname matching regexp are shown.
+If -b, only files having a basename matching regexp are shown.
+The matching is case-sensitive, except on operating systems that
+have case-insensitive filesystem (e.g., MS-Windows).
+
@kindex info functions
@item info functions [-q]
Print the names and data types of all defined functions.
--
2.20.1
^ permalink raw reply [flat|nested] 8+ messages in thread* [RFA 1/3] Implement info sources args [-d | -b] [--] [REGEXP]
2019-03-31 19:08 [RFA 0/3] new arguments [-d | -b] [--] [REGEXP] to info sources Philippe Waroquiers
2019-03-31 19:08 ` [RFA 2/3] New test for 'info sources [-d | -b] [--] [REGEXP]' Philippe Waroquiers
2019-03-31 19:08 ` [RFA 3/3] NEWS and documentation for new info sources [-d | -b] [--] [REGEXP] args Philippe Waroquiers
@ 2019-03-31 19:08 ` Philippe Waroquiers
2019-06-07 18:09 ` Tom Tromey
2019-04-18 4:18 ` PING Re: [RFA 0/3] new arguments [-d | -b] [--] [REGEXP] to info sources Philippe Waroquiers
3 siblings, 1 reply; 8+ messages in thread
From: Philippe Waroquiers @ 2019-03-31 19:08 UTC (permalink / raw)
To: gdb-patches; +Cc: Philippe Waroquiers
gdb/ChangeLog
2019-03-31 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* symtab.c (struct output_source_filename_data): New members
regexp, c_regexp, dirname, basename.
(output_source_filename): Use new members to decide to print file.
(extract_info_sources_args): New function.
(print_info_sources_header): New function.
(info_sources_command): Read new optional arguments.
(_initialize_symtab): Update info sources help.
---
gdb/symtab.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 128 insertions(+), 8 deletions(-)
diff --git a/gdb/symtab.c b/gdb/symtab.c
index d25f560f08..7a96aaf76e 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4144,6 +4144,15 @@ operator_chars (const char *p, const char **end)
struct output_source_filename_data
{
+ /* Output only filenames matching REGEXP. */
+ std::string regexp;
+ gdb::optional<compiled_regex> c_regexp;
+ /* Only match the dirname part. */
+ bool dirname;
+ /* Only match the basename part. */
+ bool basename;
+
+
/* Cache of what we've seen so far. */
struct filename_seen_cache *filename_seen_cache;
@@ -4175,7 +4184,27 @@ output_source_filename (const char *name,
return;
}
- /* No; print it and reset *FIRST. */
+ /* Does it match data->regexp? */
+ if (data->c_regexp.has_value ())
+ {
+ const char *to_match;
+ std::string dirname;
+
+ if (data->dirname)
+ {
+ dirname = ldirname (name);
+ to_match = dirname.c_str ();
+ }
+ else if (data->basename)
+ to_match = lbasename (name);
+ else
+ to_match = name;
+
+ if (data->c_regexp->exec (to_match, 0, NULL, 0) != 0)
+ return;
+ }
+
+ /* Print it and reset *FIRST. */
if (! data->first)
printf_filtered (", ");
data->first = 0;
@@ -4194,8 +4223,68 @@ output_partial_symbol_filename (const char *filename, const char *fullname,
(struct output_source_filename_data *) data);
}
+/* Extract from ARGS the arguments [-d | -b] [--] REGEXP.
+
+ The caller is responsible to initialize *DIRNAME, *BASENAME to false,
+ and *REGEXP to "".
+
+ Returns true and updates *ARGS and one of *DIRNAME, *BASENAME, *REGEXP if
+ it finds a valid argument.
+ Returns false if not valid argument is found at the beginning of ARGS. */
+
+static bool
+extract_info_sources_args (const char **args,
+ bool *dirname,
+ bool *basename,
+ std::string *regexp)
+{
+ /* Check for REGEXP or -- REGEXP. */
+ if (**args != '-' || check_for_argument (args, "--", 2))
+ {
+ *args = skip_spaces (*args);
+ *regexp = *args;
+ *args = NULL;
+ return true;
+ }
+
+ if (check_for_argument (args, "-d", 2))
+ {
+ *dirname = true;
+ *args = skip_spaces (*args);
+ return true;
+ }
+
+ if (check_for_argument (args, "-b", 2))
+ {
+ *basename = true;
+ *args = skip_spaces (*args);
+ return true;
+ }
+
+ return false;
+}
+
static void
-info_sources_command (const char *ignore, int from_tty)
+print_info_sources_header (const char *symbol_msg,
+ const struct output_source_filename_data *data)
+{
+ printf_filtered ("Source files ");
+ if (!data->regexp.empty ())
+ {
+ if (data->dirname)
+ printf_filtered ("(dirname ");
+ else if (data->basename)
+ printf_filtered ("(basename ");
+ else
+ printf_filtered ("(filename ");
+ printf_filtered ("matching regular expression \"%s\") ",
+ data->regexp.c_str ());
+ }
+ printf_filtered ("for which symbols %s:\n\n", symbol_msg);
+}
+
+static void
+info_sources_command (const char *args, int from_tty)
{
struct output_source_filename_data data;
@@ -4206,11 +4295,38 @@ info_sources_command (const char *ignore, int from_tty)
filename_seen_cache filenames_seen;
+ data.dirname = false;
+ data.basename = false;
data.filename_seen_cache = &filenames_seen;
+ data.first = 1;
- printf_filtered ("Source files for which symbols have been read in:\n\n");
+ while (args != NULL
+ && extract_info_sources_args (&args, &data.dirname, &data.basename,
+ &data.regexp))
+ ;
+
+ if (args != NULL)
+ report_unrecognized_option_error ("info sources", args);
+
+ if (data.dirname && data.basename)
+ error (_("You cannot give both -b and -d to 'info sources'."));
+ if ((data.dirname || data.basename) && data.regexp.empty ())
+ error (_("Missing REGEXP for 'info sources'."));
+
+ if (data.regexp.empty ())
+ data.c_regexp.reset ();
+ else
+ {
+ int cflags = REG_NOSUB;
+#ifdef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
+ cflags |= REG_ICASE;
+#endif
+ data.c_regexp.emplace (data.regexp.c_str (), cflags,
+ _("Invalid regexp"));
+ }
+
+ print_info_sources_header ("have been read in", &data);
- data.first = 1;
for (objfile *objfile : current_program_space->objfiles ())
{
for (compunit_symtab *cu : objfile->compunits ())
@@ -4225,8 +4341,7 @@ info_sources_command (const char *ignore, int from_tty)
}
printf_filtered ("\n\n");
- printf_filtered ("Source files for which symbols "
- "will be read in on demand:\n\n");
+ print_info_sources_header ("will be read in on demand", &data);
filenames_seen.clear ();
data.first = 1;
@@ -6092,8 +6207,13 @@ Prints the functions.\n"),
add_info ("types", info_types_command,
_("All type names, or those matching REGEXP."));
- add_info ("sources", info_sources_command,
- _("Source files in the program."));
+ add_info ("sources", info_sources_command, _("\
+All source files in the program or those matching REGEXP.\n\
+Usage: info sources [-d | -b] [--] [REGEXP]\n\
+By default, REGEXP is used to match anywhere in the filename.\n\
+If -d, only files having a dirname matching REGEXP are shown.\n\
+If -b, only files having a basename matching REGEXP are shown."));
+
add_com ("rbreak", class_breakpoint, rbreak_command,
_("Set a breakpoint for all functions matching REGEXP."));
--
2.20.1
^ permalink raw reply [flat|nested] 8+ messages in thread