Show line numbers in output for "info var/func/type"
authorAndreas Arnez <arnez@linux.vnet.ibm.com>
Fri, 13 Apr 2018 17:26:05 +0000 (19:26 +0200)
committerAndreas Arnez <arnez@linux.vnet.ibm.com>
Fri, 13 Apr 2018 17:26:05 +0000 (19:26 +0200)
The GDB commands "info variables", "info functions", and "info types" show
the appropriate list of definitions matching the given pattern.  They also
group them by source files.  But no line numbers within these source files
are shown.

The line number information is particularly useful to the user when a
simple "grep" doesn't readily point to a definition.  This is often the
case when the definition involves a macro, occurs within a namespace, or
when the identifier appears very frequently in the source file.

This patch enriches the printout of these commands by the line numbers and
adjusts affected test cases to the changed output where necessary.  The
new output looks like this:

  (gdb) i variables
  All defined variables:

  File foo.c:
  3: const char * const foo;
  1: int x;

The line number is followed by a colon and a tab character, which is then
followed by the symbol definition.  If no line number is available, the
tab is printed out anyhow, so definitions line up.

gdb/ChangeLog:

* symtab.c (print_symbol_info): Precede the symbol definition by
the line number when available.
* NEWS: Advertise this enhancement.

gdb/doc/ChangeLog:

* gdb.texinfo (Symbols): Mention the fact that "info
variables/functions/types" show source files and line numbers.

gdb/testsuite/ChangeLog:

* gdb.ada/info_types.exp: Adjust expected output to the line
numbers now printed by "info var/func/type".
* gdb.base/completion.exp: Likewise.
* gdb.base/included.exp: Likewise.
* gdb.cp/cp-relocate.exp: Likewise.
* gdb.cp/cplusfuncs.exp: Likewise.
* gdb.cp/namespace.exp: Likewise.
* gdb.dwarf2/dw2-case-insensitive.exp: Likewise.

13 files changed:
gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/symtab.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/info_types.exp
gdb/testsuite/gdb.base/completion.exp
gdb/testsuite/gdb.base/included.exp
gdb/testsuite/gdb.cp/cp-relocate.exp
gdb/testsuite/gdb.cp/cplusfuncs.exp
gdb/testsuite/gdb.cp/namespace.exp
gdb/testsuite/gdb.dwarf2/dw2-case-insensitive.exp

index b86bb7f43cc86a1d695e719b5bdec2016d5eaec9..82b803d737bf0ec8ee301d7b895e273b3f5a384a 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-13  Andreas Arnez  <arnez@linux.vnet.ibm.com>
+
+       * symtab.c (print_symbol_info): Precede the symbol definition by
+       the line number when available.
+       * NEWS: Advertise this enhancement.
+
 2018-04-13  Markus Metzger  <markus.t.metzger@intel.com>
 
        * NEWS (New options): announce set/show record btrace cpu.
index ec0dd239d1bdf103e174c2d07e5f0f935ac208b7..1ab11459688cee1c438e625eddc39008c2c36cf5 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,9 @@
 
 *** Changes since GDB 8.1
 
+* The commands 'info variables/functions/types' now show the source line
+  numbers of symbol definitions when available.
+
 * 'info proc' now works on running processes on FreeBSD systems and core
   files created on FreeBSD systems.
 
index d21288b34481471718bf78440a5c90f0b4b6460d..83d48781f904bebf0d13c68ad0745ae865874c43 100644 (file)
@@ -1,3 +1,8 @@
+2018-04-13  Andreas Arnez  <arnez@linux.vnet.ibm.com>
+
+       * gdb.texinfo (Symbols): Mention the fact that "info
+       variables/functions/types" show source files and line numbers.
+
 2018-04-13  Markus Metzger  <markus.t.metzger@intel.com>
 
        * gdb.texinfo: Document set/show record btrace cpu.
index 5a83619f6aa85abfba83a669d1d2822a5537ca67..28f083f96e37dc7aeb1893d4660ce9fa95f93ca1 100644 (file)
@@ -17585,7 +17585,7 @@ name is @code{value}.
 
 This command differs from @code{ptype} in two ways: first, like
 @code{whatis}, it does not print a detailed description; second, it
-lists all source files where a type is defined.
+lists all source files and line numbers where a type is defined.
 
 @kindex info type-printers
 @item info type-printers
@@ -17663,24 +17663,29 @@ have already been read, and files whose symbols will be read when needed.
 @kindex info functions
 @item info functions
 Print the names and data types of all defined functions.
+Similarly to @samp{info types}, this command groups its output by source
+files and annotates each function definition with its source line
+number.
 
 @item info functions @var{regexp}
-Print the names and data types of all defined functions
-whose names contain a match for regular expression @var{regexp}.
-Thus, @samp{info fun step} finds all functions whose names
-include @code{step}; @samp{info fun ^step} finds those whose names
-start with @code{step}.  If a function name contains characters
-that conflict with the regular expression language (e.g.@:
+Like @samp{info functions}, but only print the names and data types of
+functions whose names contain a match for regular expression
+@var{regexp}.  Thus, @samp{info fun step} finds all functions whose
+names include @code{step}; @samp{info fun ^step} finds those whose names
+start with @code{step}.  If a function name contains characters that
+conflict with the regular expression language (e.g.@:
 @samp{operator*()}), they may be quoted with a backslash.
 
 @kindex info variables
 @item info variables
 Print the names and data types of all variables that are defined
 outside of functions (i.e.@: excluding local variables).
+The printed variables are grouped by source files and annotated with
+their respective source line numbers.
 
 @item info variables @var{regexp}
-Print the names and data types of all variables (except for local
-variables) whose names contain a match for regular expression
+Like @kbd{info variables}, but only print the names and data types of
+non-local variables whose names contain a match for regular expression
 @var{regexp}.
 
 @kindex info classes
index 2b1f9558abeba0c8b95ad60779b57792450cc840..f66b6f00f0e67693edcdca69c2269464db61a8e9 100644 (file)
@@ -4517,6 +4517,11 @@ print_symbol_info (enum search_domain kind,
       fputs_filtered (":\n", gdb_stdout);
     }
 
+  if (SYMBOL_LINE (sym) != 0)
+    printf_filtered ("%d:\t", SYMBOL_LINE (sym));
+  else
+    puts_filtered ("\t");
+
   if (kind != TYPES_DOMAIN && block == STATIC_BLOCK)
     printf_filtered ("static ");
 
index 47fa4cffc7ad9961b715507575e49a91950ecc07..ed464a14fc6a562ecc3d428aafce1dfb6b154705 100644 (file)
@@ -1,3 +1,14 @@
+2018-04-13  Andreas Arnez  <arnez@linux.vnet.ibm.com>
+
+       * gdb.ada/info_types.exp: Adjust expected output to the line
+       numbers now printed by "info var/func/type".
+       * gdb.base/completion.exp: Likewise.
+       * gdb.base/included.exp: Likewise.
+       * gdb.cp/cp-relocate.exp: Likewise.
+       * gdb.cp/cplusfuncs.exp: Likewise.
+       * gdb.cp/namespace.exp: Likewise.
+       * gdb.dwarf2/dw2-case-insensitive.exp: Likewise.
+
 2018-04-13  Markus Metzger  <markus.t.metzger@intel.com>
 
        * gdb.btrace/cpu.exp: New.
index 7bc74fdfd36886250456019286e7e6cfc8cda56b..326c25cdd588f0f9d20d72289ac58cc06847ad70 100644 (file)
@@ -27,5 +27,5 @@ gdb_test "set lang ada" ""
 set eol "\[\r\n\]+"
 
 gdb_test "info types new_integer_type" \
-         "All types matching regular expression \"new_integer_type\":${eol}File .*info_types.c:${eol}int"
+         "All types matching regular expression \"new_integer_type\":${eol}File .*info_types.c:${eol}.*\tint"
 
index b0d11d2dc12e434849c49f3ca67cdd74cc5aae15..cb88918648549fa6f356d084c1d194624c3119b3 100644 (file)
@@ -749,7 +749,7 @@ gdb_test_multiple "" "$test" {
            -re "marker1.*$gdb_prompt " {
                send_gdb "\n"
                gdb_test_multiple "" "$test" {
-                   -re "All functions matching regular expression \"marker\":.*File.*break1.c:\r\nint marker1\\((void|)\\);\r\nint marker2\\(int\\).*marker3\\(char.*char.*\\).*marker4\\(long( int)?\\);.*$gdb_prompt $" {
+                   -re "All functions matching regular expression \"marker\":.*File.*break1.c:.*\tint marker1\\((void|)\\);\r\n.*:\tint marker2\\(int\\).*marker3\\(char.*char.*\\).*marker4\\(long( int)?\\);.*$gdb_prompt $" {
                        pass "$test"
                    }
                }
index b79e7de7beff0b85b54a9c55b9e5831089878f74..65e694d6a524e67775865a2199f8893dde4fed64 100644 (file)
@@ -33,4 +33,4 @@ gdb_test "ptype integer" "type = int"
 
 # We should report that integer comes from the header file.
 if { $non_dwarf } { setup_xfail *-*-* }
-gdb_test "info variables integer" "\r\nFile \[^\r\n\]*/${subdir}/${testfile}.h:\r\nint integer;"
+gdb_test "info variables integer" "\r\nFile \[^\r\n\]*/${subdir}/${testfile}.h:\r\n.*\tint integer;"
index e48eb8c4e505f5447464af900586f965efaad703..63d2ad476d27958fc6d4cf5a5d6ec6758a7d25d9 100644 (file)
@@ -56,11 +56,11 @@ gdb_file_cmd ${binfile}
 set func1_name ""
 set func2_name ""
 gdb_test_multiple "info functions func<.>" "info functions" {
-    -re "\r\nint (\[^\r\]*func<1>\[^\r]*);" {
+    -re "\tint (\[^\r\]*func<1>\[^\r]*);" {
        set func1_name $expect_out(1,string)
        exp_continue
     }
-    -re "\r\nint (\[^\r\]*func<2>\[^\r]*);" {
+    -re "\tint (\[^\r\]*func<2>\[^\r]*);" {
        set func2_name $expect_out(1,string)
        exp_continue
     }
index 6f6b425a11ae8a31900e36d10ae1037886693e3c..f80790c5dfb3ed5357bf3c7b4d0bc8519039618a 100644 (file)
@@ -292,7 +292,7 @@ proc info_func_regexp { name demangled } {
     regsub {\\\(void\\\)} $demangled {\(\)} demangled
 
     gdb_test "info function $name" \
-       "File .*:\r\n(class|)${demangled}.*" \
+       "File .*:\t(class|)${demangled}.*" \
        "info function for \"$name\""
 }
 
index 958ee0e917699917eea91b5e8a37dcc0bc72afa4..b0511b13e03b09859be50a48f80c88d2a02e7975 100644 (file)
@@ -95,10 +95,10 @@ gdb_test_multiple "ptype ina" "ptype ina" {
 
 setup_xfail hppa*-*-*11* CLLbs14869
 gdb_test_multiple "info func xyzq" "info func xyzq" {
-    -re "All functions.*File.*namespace.cc:\r\nint AAA::A_xyzq\\(int\\);\r\nint BBB::B_xyzq\\(int\\);\r\nchar AAA::xyzq\\(char\\);\r\nchar BBB::xyzq\\(char\\);\r\nchar BBB::CCC::xyzq\\(char\\);\r\nchar BBB::Class::xyzq\\(char\\);\r\n$gdb_prompt $" {
+    -re "All functions.*File.*namespace.cc:\r\n.*\tint AAA::A_xyzq\\(int\\);\r\n.*\tint BBB::B_xyzq\\(int\\);\r\n.*\tchar AAA::xyzq\\(char\\);\r\n.*\tchar BBB::xyzq\\(char\\);\r\n.*\tchar BBB::CCC::xyzq\\(char\\);\r\n.*\tchar BBB::Class::xyzq\\(char\\);\r\n$gdb_prompt $" {
        pass "info func xyzq"
     }    
-    -re "All functions.*File.*namespace.cc:\r\nint AAA::A_xyzq\\(int\\);\r\nchar AAA::xyzq\\(char\\);\r\nint BBB::B_xyzq\\(int\\);\r\nchar BBB::CCC::xyzq\\(char\\);\r\nchar BBB::Class::xyzq\\(char\\);\r\nchar BBB::xyzq\\(char\\);\r\n$gdb_prompt $" {
+    -re "All functions.*File.*namespace.cc:\r\n.*\tint AAA::A_xyzq\\(int\\);\r\n.*\tchar AAA::xyzq\\(char\\);\r\n.*\tint BBB::B_xyzq\\(int\\);\r\n.*\tchar BBB::CCC::xyzq\\(char\\);\r\n.*\tchar BBB::Class::xyzq\\(char\\);\r\n.*\tchar BBB::xyzq\\(char\\);\r\n$gdb_prompt $" {
        pass "info func xyzq"
     }    
 }
index f93a80b46a3bd19de3741d55b591aa2d8d486c58..b15dcafa005e930f96ced3e58ba0cf287fb10c46 100644 (file)
@@ -43,7 +43,7 @@ gdb_test "set case-sensitive off" {warning: the current case sensitivity setting
 
 # The dot-leading symbol is for ppc64 function descriptors.
 gdb_test "info functions fUnC_lang" \
-        "All functions matching regular expression \"fUnC_lang\":\[\r\n\]+File file1.txt:\r\nfoo FUNC_lang\\(void\\);(\r\n\r\nNon-debugging symbols:\r\n0x\[0-9a-f\]+ +\\.FUNC_lang)?" \
+        "All functions matching regular expression \"fUnC_lang\":\[\r\n\]+File file1.txt:\r\n\tfoo FUNC_lang\\(void\\);(\r\n\r\nNon-debugging symbols:\r\n0x\[0-9a-f\]+ +\\.FUNC_lang)?" \
         "regexp case-sensitive off"
 
 gdb_test "p fuNC_lang" { = {foo \(void\)} 0x[0-9a-f]+ <FUNC_lang>}
This page took 0.06516 seconds and 4 git commands to generate.