aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2021-05-18 13:46:19 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2021-06-25 20:54:29 +0100
commit0e350a054bbeb4d00f2c430c4815c82d5ffb47a7 (patch)
tree079b2ed8a2344ef2b6b7c854b9ccfe8450d34137 /gdb/testsuite
parent4a0788e08cbf9e7b90640475b17afbbf5423ea9d (diff)
downloadgdb-0e350a054bbeb4d00f2c430c4815c82d5ffb47a7.zip
gdb-0e350a054bbeb4d00f2c430c4815c82d5ffb47a7.tar.gz
gdb-0e350a054bbeb4d00f2c430c4815c82d5ffb47a7.tar.bz2
gdb/mi: add regexp filtering to -file-list-exec-source-files
This commit extends the existing MI command -file-list-exec-source-files to provide the same regular expression based filtering that the equivalent CLI command "info sources" provides. The new command syntax is: -file-list-exec-source-files [--basename | --dirname] [--] [REGEXP] All options are optional, which ensures the command is backward compatible. As part of this work I have unified the CLI and MI code. As a result of the unified code I now provide additional information in the MI command output, there is now a new field 'debug-fully-read' included with each source file. This field which has the values 'true' or 'false', indicates if the source file is from a compilation unit that has had its debug information fully read. However, as this is additional information, a well written front-end should just ignore this field if it doesn't understand it, so things should still be backward compatible. gdb/ChangeLog: * NEWS: Mention additions to -file-list-exec-source-files. * mi/mi-cmd-file.c (print_partial_file_name): Delete. (mi_cmd_file_list_exec_source_files): Rewrite to handle command options, and make use of info_sources_worker. * symtab.c (struct info_sources_filter): Moved to symtab.h. (info_sources_filter::print): Take uiout argument, produce output through uiout. (struct output_source_filename_data) <output_source_filename_data>: Take uiout argument, store into m_uiout. <output>: Rewrite comment, add additional arguments to declaration. <operator()>: Send more arguments to output. <m_uiout>: New member variable. (output_source_filename_data::output): Take extra arguments, produce output through m_uiout, and structure for MI. (output_source_filename_data::print_header): Produce output through m_uiout. (info_sources_worker): New function, the implementation is taken from info_sources_command, but modified so produce output through a ui_out. (info_sources_command): The second half of this function has gone to become info_sources_worker. * symtab.h (struct info_sources_filter): Moved from symtab.c, add extra parameter to print member function. (info_sources_worker): Declare. gdb/doc/ChangeLog: * gdb.texinfo (GDB/MI File Commands): Document extensions to -file-list-exec-source-files. gdb/testsuite/ChangeLog: * gdb.dwarf2/dw2-filename.exp: Update expected results. * gdb.mi/mi-file.exp: Likewise. * gdb.mi/mi-info-sources-base.c: New file. * gdb.mi/mi-info-sources.c: New file. * gdb.mi/mi-info-sources.exp: New file.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog8
-rw-r--r--gdb/testsuite/gdb.dwarf2/dw2-filename.exp2
-rw-r--r--gdb/testsuite/gdb.mi/mi-file.exp2
-rw-r--r--gdb/testsuite/gdb.mi/mi-info-sources-base.c23
-rw-r--r--gdb/testsuite/gdb.mi/mi-info-sources.c25
-rw-r--r--gdb/testsuite/gdb.mi/mi-info-sources.exp147
6 files changed, 205 insertions, 2 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 9bf8e9e..7eb13b8 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,13 @@
2021-06-25 Andrew Burgess <andrew.burgess@embecosm.com>
+ * gdb.dwarf2/dw2-filename.exp: Update expected results.
+ * gdb.mi/mi-file.exp: Likewise.
+ * gdb.mi/mi-info-sources-base.c: New file.
+ * gdb.mi/mi-info-sources.c: New file.
+ * gdb.mi/mi-info-sources.exp: New file.
+
+2021-06-25 Andrew Burgess <andrew.burgess@embecosm.com>
+
* gdb.cp/method-call-in-c.cc (struct foo_type): Add static member
function static_method.
(global_var): New global.
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-filename.exp b/gdb/testsuite/gdb.dwarf2/dw2-filename.exp
index 3e60f7d..bd303c8 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-filename.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-filename.exp
@@ -37,7 +37,7 @@ clean_restart ${testfile}
# the full path to that file. What we want to verify, most of all,
# is that the file and fullname fields are now inverted.
gdb_test "interpreter-exec mi -file-list-exec-source-files" \
- ".*{file=\"file1\\.txt\",fullname=\".+file1\\.txt\"}.*"
+ ".*{file=\"file1\\.txt\",fullname=\".+file1\\.txt\",debug-fully-read=\"\[^\"\]+\"}.*"
# And `info sources' should return the fullname incl. the directories.
gdb_test "info sources" {[/]file1\.txt.*}
diff --git a/gdb/testsuite/gdb.mi/mi-file.exp b/gdb/testsuite/gdb.mi/mi-file.exp
index 15d7d9f..4cae33c 100644
--- a/gdb/testsuite/gdb.mi/mi-file.exp
+++ b/gdb/testsuite/gdb.mi/mi-file.exp
@@ -68,7 +68,7 @@ proc test_file_list_exec_source_files {} {
# get the path and absolute path to the current executable
mi_gdb_test "222-file-list-exec-source-files" \
- "222\\\^done,files=\\\[\{file=\".*${srcfile}\",fullname=\"$fullname_syntax${srcfile}\"\}.*]" \
+ "222\\\^done,files=\\\[\{file=\".*${srcfile}\",fullname=\"$fullname_syntax${srcfile}\",debug-fully-read=\"\[^\"\]+\"\}.*]" \
"Getting a list of source files."
}
diff --git a/gdb/testsuite/gdb.mi/mi-info-sources-base.c b/gdb/testsuite/gdb.mi/mi-info-sources-base.c
new file mode 100644
index 0000000..cc73612
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-info-sources-base.c
@@ -0,0 +1,23 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2019-2021 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/>. */
+
+/* This file was originally copied from gdb.base/info_sources_base.c. */
+
+void some_other_func (void)
+{
+ return;
+}
diff --git a/gdb/testsuite/gdb.mi/mi-info-sources.c b/gdb/testsuite/gdb.mi/mi-info-sources.c
new file mode 100644
index 0000000..b91b828
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-info-sources.c
@@ -0,0 +1,25 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2019-2021 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/>. */
+
+/* This file was originally copied from gdb.base/info_sources.c. */
+
+extern void some_other_func (void);
+int main ()
+{
+ some_other_func ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.mi/mi-info-sources.exp b/gdb/testsuite/gdb.mi/mi-info-sources.exp
new file mode 100644
index 0000000..c218af4
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-info-sources.exp
@@ -0,0 +1,147 @@
+# Copyright 2021 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 the -file-list-exec-source-files command.
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+standard_testfile .c -base.c
+
+if {[prepare_for_testing $testfile.exp $testfile \
+ [list $srcfile $srcfile2] debug]} {
+ untested $testfile.exp
+ return -1
+}
+
+mi_clean_restart $binfile
+
+mi_runto_main
+
+# Helper to build expected MI output pattern for a list. NAME is the
+# name of the list (which can be the empty string) and args is one
+# or more strings representing the fields of the list, which will be
+# joined with a comma.
+#
+# If any of the fields in args matches ".*" then the comma before and
+# after are dropped from the final pattern.
+proc mi_list { name args } {
+ set str ""
+
+ if { $name != "" } {
+ set str "${name}="
+ }
+
+ set pattern ""
+ foreach a $args {
+ if { [string length $pattern] > 0 } {
+ if { [string range $pattern end-1 end] != ".*" \
+ && [string range $a 0 1] != ".*" } {
+ set pattern "${pattern},"
+ }
+ }
+ set pattern "${pattern}${a}"
+ }
+ set str "$str\\\[${pattern}\\\]"
+ return ${str}
+}
+
+# Helper to build expected MI output pattern for a tuple. NAME is the
+# name of the tuple (which can be the empty string) and args is one
+# or more strings representing the fields of the tuple, which will be
+# joined with a comma.
+#
+# If any of the fields in args matches ".*" then the comma before and
+# after are dropped from the final pattern.
+proc mi_tuple { name args } {
+ set str ""
+
+ if { $name != "" } {
+ set str "${name}="
+ }
+
+ set pattern ""
+ foreach a $args {
+ if { [string length $pattern] > 0 } {
+ if { [string range $pattern end-1 end] != ".*" \
+ && [string range $a 0 1] != ".*" } {
+ set pattern "${pattern},"
+ }
+ }
+ set pattern "${pattern}${a}"
+ }
+ set str "$str\\{${pattern}\\}"
+ return ${str}
+}
+
+# Helper to build expected MI output pattern for a single field. NAME
+# is the name of the field, and PATTERN matches the fields contents.
+# This proc will add quotes around PATTERN.
+proc mi_field { name pattern } {
+ set str ""
+
+ if { $name != "" } {
+ set str "${name}="
+ }
+
+ set str "$str\"${pattern}\""
+ return ${str}
+}
+
+# Run tests on '-file-list-exec-source-files'. DEBUG_FULLY_READ is either the string
+# "true" or "false" and indicates if the GDB will have read all the
+# debug for the test program or not yet.
+proc check_info_sources { debug_fully_read } {
+
+ with_test_prefix "debug_read=${debug_fully_read}" {
+
+ if { $debug_fully_read } {
+ set p [mi_list "files" \
+ [mi_tuple "" \
+ [mi_field "file" "\[^\"\]+/mi-info-sources-base\\.c"] \
+ [mi_field "fullname" "\[^\"\]+/mi-info-sources-base\\.c"] \
+ [mi_field "debug-fully-read" "${debug_fully_read}"]] \
+ [mi_tuple "" \
+ [mi_field "file" "\[^\"\]+/mi-info-sources\\.c"] \
+ [mi_field "fullname" "\[^\"\]+/mi-info-sources\\.c"] \
+ [mi_field "debug-fully-read" "true"]]]
+ } else {
+ set p [mi_list "files" \
+ [mi_tuple "" \
+ [mi_field "file" "\[^\"\]+/mi-info-sources\\.c"] \
+ [mi_field "fullname" "\[^\"\]+/mi-info-sources\\.c"] \
+ [mi_field "debug-fully-read" "true"]] \
+ [mi_tuple "" \
+ [mi_field "file" "\[^\"\]+/mi-info-sources-base\\.c"] \
+ [mi_field "fullname" "\[^\"\]+/mi-info-sources-base\\.c"] \
+ [mi_field "debug-fully-read" "${debug_fully_read}"]]]
+ }
+ mi_gdb_test "-file-list-exec-source-files" ".*\\^done,${p}" "-file-list-exec-source-files"
+
+ set p [mi_list "files" \
+ [mi_tuple "" \
+ [mi_field "file" "\[^\"\]+/mi-info-sources-base\\.c"] \
+ [mi_field "fullname" "\[^\"\]+/mi-info-sources-base\\.c"] \
+ [mi_field "debug-fully-read" "${debug_fully_read}"]]]
+ mi_gdb_test "-file-list-exec-source-files --basename -- base" ".*\\^done,${p}" \
+ "-file-list-exec-source-files --basename -- base"
+ }
+}
+
+check_info_sources "false"
+
+mi_continue_to "some_other_func"
+
+check_info_sources "true"