diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-05-18 14:27:25 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-06-25 20:54:29 +0100 |
commit | bd742128ba3b0eebda581a26c5bfa52ac0995584 (patch) | |
tree | da0044bc2b93ad6a437c37247f79deedcfab4818 /gdb/testsuite | |
parent | 1fb1ce02fc0e311c1dede3f2b992c9fc31124d6d (diff) | |
download | gdb-bd742128ba3b0eebda581a26c5bfa52ac0995584.zip gdb-bd742128ba3b0eebda581a26c5bfa52ac0995584.tar.gz gdb-bd742128ba3b0eebda581a26c5bfa52ac0995584.tar.bz2 |
gdb: change info sources to group results by objfile
Currently the 'info sources' command lists all of the known source
files together, regardless of their source, e.g. here is a session
debugging a test application that makes use of a shared library:
(gdb) info sources
Source files for which symbols have been read in:
/tmp/info-sources/test.c, /usr/include/stdc-predef.h,
/tmp/info-sources/header.h, /tmp/info-sources/helper.c
Source files for which symbols will be read in on demand:
(gdb)
In this commit I change the format of the 'info sources' results so
that the results are grouped by the object file that uses that source
file. Here's the same session with the new output format:
(gdb) info sources
/tmp/info-sources/test.x:
/tmp/info-sources/test.c, /usr/include/stdc-predef.h,
/tmp/info-sources/header.h
/lib64/ld-linux-x86-64.so.2:
(Objfile has no debug information.)
system-supplied DSO at 0x7ffff7fcf000:
(Objfile has no debug information.)
/tmp/info-sources/libhelper.so:
/tmp/info-sources/helper.c, /usr/include/stdc-predef.h,
/tmp/info-sources/header.h
/lib64/libc.so.6:
(Objfile has no debug information.)
(gdb)
Notice that in the new output some source files are repeated,
e.g. /tmp/info-sources/header.h, as multiple objfiles use this source
file.
Further, some object files are tagged with the message '(Objfile has
no debug information.)', it is also possible to see the message '(Full
debug information has not yet been read for this file.)', which is
printed when some symtabs within an objfile have not yet been
expanded.
All of the existing regular expression based filtering still works.
An original version of this patch added the new format as an option to
'info sources', however, it was felt that the new layout was so much
better than the old style that GDB should just switch to the new
result format completely.
gdb/ChangeLog:
* NEWS: Mention changes to 'info sources'.
* symtab.c (info_sources_filter::print): Delete.
(struct output_source_filename_data) <print_header>: Delete
declaration. <printed_filename_p>: New member function.
(output_source_filename_data::print_header): Delete.
(info_sources_worker): Update group-by-objfile style output to
make it CLI suitable, simplify non-group-by-objfile now this is
only used from the MI.
(info_sources_command): Make group-by-objfile be the default for
CLI info sources command.
* symtab.h (struct info_sources_filter) <print>: Delete.
gdb/doc/ChangeLog:
* gdb.texinfo (Symbols): Document new output format for 'info
sources'.
gdb/testsuite/ChangeLog:
* gdb.base/info_sources_2-header.h: New file.
* gdb.base/info_sources_2-lib.c: New file.
* gdb.base/info_sources_2-test.c: New file.
* gdb.base/info_sources_2.exp: New file.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/info_sources_2-header.h | 28 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/info_sources_2-lib.c | 25 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/info_sources_2-test.c | 26 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/info_sources_2.exp | 169 |
5 files changed, 255 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 8a8c7f2..26dcea6 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,12 @@ 2021-06-25 Andrew Burgess <andrew.burgess@embecosm.com> + * gdb.base/info_sources_2-header.h: New file. + * gdb.base/info_sources_2-lib.c: New file. + * gdb.base/info_sources_2-test.c: New file. + * gdb.base/info_sources_2.exp: New file. + +2021-06-25 Andrew Burgess <andrew.burgess@embecosm.com> + * gdb.mi/mi-info-sources.exp: Add additional tests. 2021-06-25 Andrew Burgess <andrew.burgess@embecosm.com> diff --git a/gdb/testsuite/gdb.base/info_sources_2-header.h b/gdb/testsuite/gdb.base/info_sources_2-header.h new file mode 100644 index 0000000..b3379ba --- /dev/null +++ b/gdb/testsuite/gdb.base/info_sources_2-header.h @@ -0,0 +1,28 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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/>. */ + +#ifndef INFO_SOURCES_2_HEADER +#define INFO_SOURCES_2_HEADER + +extern int foo (void); + +inline static int compare_values (int a, int b) +{ + return a == b; +} + +#endif /* INFO_SOURCES_2_HEADER */ diff --git a/gdb/testsuite/gdb.base/info_sources_2-lib.c b/gdb/testsuite/gdb.base/info_sources_2-lib.c new file mode 100644 index 0000000..7df1a81 --- /dev/null +++ b/gdb/testsuite/gdb.base/info_sources_2-lib.c @@ -0,0 +1,25 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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/>. */ + + +#include "info_sources_2-header.h" + +int +foo () +{ + return compare_values (0, 1); +} diff --git a/gdb/testsuite/gdb.base/info_sources_2-test.c b/gdb/testsuite/gdb.base/info_sources_2-test.c new file mode 100644 index 0000000..87a030a --- /dev/null +++ b/gdb/testsuite/gdb.base/info_sources_2-test.c @@ -0,0 +1,26 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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/>. */ + + +#include "info_sources_2-header.h" + +int +main () +{ + int res = foo (); + return compare_values (res, 1); +} diff --git a/gdb/testsuite/gdb.base/info_sources_2.exp b/gdb/testsuite/gdb.base/info_sources_2.exp new file mode 100644 index 0000000..3aed25b --- /dev/null +++ b/gdb/testsuite/gdb.base/info_sources_2.exp @@ -0,0 +1,169 @@ +# 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 'info sources' when the test file makes use of a shared +# library. + +if { [skip_shlib_tests] } { + return 0 +} + +standard_testfile -test.c -lib.c +set solib_name [standard_output_file ${testfile}-lib.so] + +if { [gdb_compile_shlib ${srcdir}/${subdir}/${srcfile2} ${solib_name} \ + {debug}] != "" } { + untested "failed to compile shared library" + return -1 +} + +if {[gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable \ + [list debug shlib=${solib_name} ]] != ""} { + untested "failed to compile executable" + return -1 +} + +clean_restart ${binfile} + +if ![runto foo] { + untested "failed to run to function foo" + return -1 +} + +# Invoke 'info sources EXTRA_ARGS' and extract the results. +# The results are then compared to the list ARGS. +# +# The list ARGS should consist of pairs of values, the first item being the +# path to an object file, and the second item being the name of a source file. +# This proc checks that source file was listed as being a source file for the +# given object file. +# +# If the name of the source file starts with the character "!" (exclamation +# character, without the quotes) then the check is inverted, that the source +# file is NOT listed for the given object file. +proc run_info_sources { extra_args args } { + global gdb_prompt srcdir subdir + + with_test_prefix "args: ${extra_args}" { + + # The results of running info sources will be placed into this local. + array set info_sources {} + + # The command we are going to run. + set cmd "info sources ${extra_args}" + set command_regex [string_to_regexp $cmd] + + # Run the command and extract the results into INFO_SOURCES. + set objfile_name "" + set source_files {} + gdb_test_multiple $cmd "" { + -re "${command_regex}\r\n" { + exp_continue + } + + -re "^(\[^\r\n\]+):\r\n" { + set objfile_name $expect_out(1,string) + exp_continue + } + + -re "^\\(Full debug information has not yet been read for this file\\.\\)\r\n" { + exp_continue + } + + -re "^\r\n" { + exp_continue + } + + -re "^$gdb_prompt $" { + pass $gdb_test_name + } + + -re "^(\[^\r\n\]+)\r\n" { + if { $objfile_name == "" } { + fail "${gdb_test_name} (no objfile name)" + return + } + + set files {} + foreach f [split $expect_out(1,string) ,] { + lappend files [string trim $f] + } + set info_sources($objfile_name) $files + set $objfile_name "" + exp_continue + } + } + + # Now check ARGS agaisnt the values held in INFO_SOURCES map. + foreach {objfile sourcefile} $args { + # First, figure out if we're expecting SOURCEFILE to be present, + # or not. + set present True + set match_type "is" + if {[string index $sourcefile 0] == "!"} { + set present False + set match_type "is not" + set sourcefile [string range $sourcefile 1 end] + } + + # Figure out the path for SOURCEFILE that we're looking for. + set sourcepath [file normalize ${srcdir}/${subdir}/${sourcefile}] + + # Make sure we handle the case where there are no source files + # associated with a particular objfile. + set source_list {} + if [info exists info_sources($objfile)] { + set source_list $info_sources($objfile) + } + + # Now perform the search, and check the results. + set idx [lsearch -exact $source_list $sourcepath] + gdb_assert {($present && $idx >= 0) || (!$present && $idx == -1)} \ + "source file '$sourcefile' ${match_type} present for '[file tail $objfile]'" + } + } +} + +# The actual tests. + +run_info_sources "" \ + ${binfile} ${srcfile} \ + ${binfile} ${testfile}-header.h \ + ${solib_name} ${srcfile2} \ + ${solib_name} ${testfile}-header.h + +run_info_sources "-basename info_sources_2" \ + ${binfile} ${srcfile} \ + ${binfile} ${testfile}-header.h \ + ${solib_name} ${srcfile2} \ + ${solib_name} ${testfile}-header.h + +run_info_sources "-basename \\.c" \ + ${binfile} ${srcfile} \ + ${binfile} !${testfile}-header.h \ + ${solib_name} ${srcfile2} \ + ${solib_name} !${testfile}-header.h + +run_info_sources "-basename -- -test\\.c" \ + ${binfile} ${srcfile} \ + ${binfile} !${testfile}-header.h \ + ${solib_name} !${srcfile2} \ + ${solib_name} !${testfile}-header.h + +run_info_sources "-basename -- -lib\\.c" \ + ${binfile} !${srcfile} \ + ${binfile} !${testfile}-header.h \ + ${solib_name} ${srcfile2} \ + ${solib_name} !${testfile}-header.h |