From: Andreas Arnez <arnez@linux.vnet.ibm.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] Show line numbers in output for "info var/func/type"
Date: Wed, 04 Apr 2018 18:53:00 -0000 [thread overview]
Message-ID: <m3vad6ls6r.fsf@oc1027705133.ibm.com> (raw)
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/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.
---
gdb/NEWS | 3 +++
gdb/symtab.c | 5 +++++
gdb/testsuite/gdb.ada/info_types.exp | 2 +-
gdb/testsuite/gdb.base/completion.exp | 2 +-
gdb/testsuite/gdb.base/included.exp | 2 +-
gdb/testsuite/gdb.cp/cp-relocate.exp | 4 ++--
gdb/testsuite/gdb.cp/cplusfuncs.exp | 2 +-
gdb/testsuite/gdb.cp/namespace.exp | 4 ++--
gdb/testsuite/gdb.dwarf2/dw2-case-insensitive.exp | 2 +-
9 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/gdb/NEWS b/gdb/NEWS
index ef0313d97a..2182a41be9 100644
--- 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.
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 2b1f9558ab..f66b6f00f0 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -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 ");
diff --git a/gdb/testsuite/gdb.ada/info_types.exp b/gdb/testsuite/gdb.ada/info_types.exp
index 7bc74fdfd3..326c25cdd5 100644
--- a/gdb/testsuite/gdb.ada/info_types.exp
+++ b/gdb/testsuite/gdb.ada/info_types.exp
@@ -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"
diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
index b0d11d2dc1..cb88918648 100644
--- a/gdb/testsuite/gdb.base/completion.exp
+++ b/gdb/testsuite/gdb.base/completion.exp
@@ -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"
}
}
diff --git a/gdb/testsuite/gdb.base/included.exp b/gdb/testsuite/gdb.base/included.exp
index b79e7de7be..65e694d6a5 100644
--- a/gdb/testsuite/gdb.base/included.exp
+++ b/gdb/testsuite/gdb.base/included.exp
@@ -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;"
diff --git a/gdb/testsuite/gdb.cp/cp-relocate.exp b/gdb/testsuite/gdb.cp/cp-relocate.exp
index e48eb8c4e5..63d2ad476d 100644
--- a/gdb/testsuite/gdb.cp/cp-relocate.exp
+++ b/gdb/testsuite/gdb.cp/cp-relocate.exp
@@ -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
}
diff --git a/gdb/testsuite/gdb.cp/cplusfuncs.exp b/gdb/testsuite/gdb.cp/cplusfuncs.exp
index 6f6b425a11..f80790c5df 100644
--- a/gdb/testsuite/gdb.cp/cplusfuncs.exp
+++ b/gdb/testsuite/gdb.cp/cplusfuncs.exp
@@ -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\""
}
diff --git a/gdb/testsuite/gdb.cp/namespace.exp b/gdb/testsuite/gdb.cp/namespace.exp
index 958ee0e917..b0511b13e0 100644
--- a/gdb/testsuite/gdb.cp/namespace.exp
+++ b/gdb/testsuite/gdb.cp/namespace.exp
@@ -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"
}
}
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-case-insensitive.exp b/gdb/testsuite/gdb.dwarf2/dw2-case-insensitive.exp
index f93a80b46a..b15dcafa00 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-case-insensitive.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-case-insensitive.exp
@@ -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>}
--
2.14.3
next reply other threads:[~2018-04-04 18:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-04 18:53 Andreas Arnez [this message]
2018-04-04 19:23 ` Eli Zaretskii
2018-04-05 11:59 ` Andreas Arnez
2018-04-05 13:35 ` Eli Zaretskii
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=m3vad6ls6r.fsf@oc1027705133.ibm.com \
--to=arnez@linux.vnet.ibm.com \
--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