From patchwork Thu Apr 5 15:28:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 26615 Received: (qmail 8349 invoked by alias); 5 Apr 2018 15:28:57 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 7520 invoked by uid 89); 5 Apr 2018 15:28:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=81, AAA, frequently, readily X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Apr 2018 15:28:54 +0000 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w35FR1vc027049 for ; Thu, 5 Apr 2018 11:28:52 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 2h5p5k0yj6-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Thu, 05 Apr 2018 11:28:51 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 5 Apr 2018 16:28:49 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 5 Apr 2018 16:28:48 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w35FSmu456885416; Thu, 5 Apr 2018 15:28:48 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1E01B4C044; Thu, 5 Apr 2018 16:21:36 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E2B094C04E; Thu, 5 Apr 2018 16:21:35 +0100 (BST) Received: from oc1027705133.ibm.com (unknown [9.152.212.201]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 5 Apr 2018 16:21:35 +0100 (BST) From: Andreas Arnez To: gdb-patches@sourceware.org Cc: Eli Zaretskii Subject: [PATCH v2] Show line numbers in output for "info var/func/type" Date: Thu, 05 Apr 2018 17:28:46 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18040515-0040-0000-0000-0000042ADAA4 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18040515-0041-0000-0000-0000262E12FC Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-04-05_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804050160 X-IsSubscribed: yes Just for completeness, here's the updated version of the patch. Only the manual update has been added; nothing else has changed. The documentation parts have been reviewed by Eli. OK to push? --- Andreas -- >8 -- Subject: [PATCH v2] Show line numbers in output for "info var/func/type" 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. --- gdb/NEWS | 3 +++ gdb/doc/gdb.texinfo | 23 ++++++++++++++--------- 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 +- 10 files changed, 31 insertions(+), 18 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/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index bd20b39c63..0ea11898e5 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -17522,7 +17522,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 @@ -17600,24 +17600,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 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]+ }