From patchwork Mon Sep 4 18:47:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 22613 Received: (qmail 33714 invoked by alias); 4 Sep 2017 18:47:48 -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 33583 invoked by uid 89); 4 Sep 2017 18:47:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=progression X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 04 Sep 2017 18:47:42 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94D5CCAA70 for ; Mon, 4 Sep 2017 18:47:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 94D5CCAA70 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=palves@redhat.com Received: from cascais.lan (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1819E6047B for ; Mon, 4 Sep 2017 18:47:40 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 2/2] Make "list ambiguous" show symbol names too Date: Mon, 4 Sep 2017 19:47:38 +0100 Message-Id: <1504550858-27936-3-git-send-email-palves@redhat.com> In-Reply-To: <1504550858-27936-1-git-send-email-palves@redhat.com> References: <1504550858-27936-1-git-send-email-palves@redhat.com> Currently, with an ambiguous "list first,last", we get: (gdb) list bar,main Specified first line 'bar' is ambiguous: file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 97 file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 98 This commit makes gdb's output above a bit clearer by printing the symbol name as well: (gdb) list bar,main Specified first line 'bar' is ambiguous: file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 97, symbol: "bar(A)" file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 98, symbol: "bar(B)" And while at it, makes gdb print the symbol name when actually listing multiple locations too. I.e., before (with "set listsize 2"): (gdb) list bar file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 97 96 97 int bar (A) { return 11; } file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 98 97 int bar (A) { return 11; } 98 int bar (B) { return 22; } After: (gdb) list bar file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 97, symbol: "bar(A)" 96 97 int bar (A) { return 11; } file: "src/gdb/testsuite/gdb.cp/overload.cc", line number: 98, symbol: "bar(B)" 97 int bar (A) { return 11; } 98 int bar (B) { return 22; } Currently, the result of decoding a linespec loses information about the original symbol that was found. All we end up with is an address. This makes it difficult to find the original symbol again to get at its print name. Fix that by storing a pointer to the symbol in the sal. We already store the symtab and obj_section, so it feels like a natural progression to me. This avoids having to do any extra symbol lookup too. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * cli/cli-cmds.c (list_command): Use print_sal_location. (print_sal_location): New function. (ambiguous_line_spec): Use print_sal_location. * linespec.c (symbol_to_sal): Record the symbol in the sal. * symtab.c (find_function_start_sal): Likewise. * symtab.h (symtab_and_line::symbol): New field. gdb/testsuite/ChangeLog: yyyy-mm-dd Pedro Alves * gdb.base/list-ambiguous.exp (test_list_ambiguous_symbol): Expect symbol names in gdb's output. * gdb.cp/overload.exp ("list all overloads"): Likewise. --- gdb/cli/cli-cmds.c | 29 +++++++++++++++++++++-------- gdb/linespec.c | 2 ++ gdb/symtab.c | 2 ++ gdb/symtab.h | 1 + gdb/testsuite/gdb.base/list-ambiguous.exp | 4 ++-- gdb/testsuite/gdb.cp/overload.exp | 4 ++-- 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index b79ceb2..1dfaab9 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -90,6 +90,8 @@ static void list_command (char *, int); /* Prototypes for local utility functions */ +static void print_sal_location (const symtab_and_line &sal); + static void ambiguous_line_spec (gdb::array_view sals, const char *format, ...) ATTRIBUTE_PRINTF (2, 3); @@ -1094,11 +1096,7 @@ list_command (char *arg, int from_tty) if (first_line < 1) first_line = 1; if (sals.size () > 1) - { - printf_filtered (_("file: \"%s\", line number: %d\n"), - symtab_to_filename_for_display (sal.symtab), - sal.line); - } + print_sal_location (sal); print_source_lines (sal.symtab, first_line, first_line + get_lines_to_list (), @@ -1516,6 +1514,23 @@ alias_command (char *args, int from_tty) } } +/* Print the file / line number / symbol name of the location + specified by SAL. */ + +static void +print_sal_location (const symtab_and_line &sal) +{ + scoped_restore_current_program_space restore_pspace; + set_current_program_space (sal.pspace); + + const char *sym_name = NULL; + if (sal.symbol != NULL) + sym_name = SYMBOL_PRINT_NAME (sal.symbol); + printf_filtered (_("file: \"%s\", line number: %d, symbol: \"%s\"\n"), + symtab_to_filename_for_display (sal.symtab), + sal.line, sym_name != NULL ? sym_name : "???"); +} + /* Print a list of files and line numbers which a user may choose from in order to list a function which was specified ambiguously (as with `list classname::overloadedfuncname', for example). The SALS @@ -1533,9 +1548,7 @@ ambiguous_line_spec (gdb::array_view sals, va_end (ap); for (const auto &sal : sals) - printf_filtered (_("file: \"%s\", line number: %d\n"), - symtab_to_filename_for_display (sal.symtab), - sal.line); + print_sal_location (sal); } /* Comparison function for filter_sals. Returns a qsort-style diff --git a/gdb/linespec.c b/gdb/linespec.c index d72d19d..9398e9a 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -4627,6 +4627,7 @@ symbol_to_sal (struct symtab_and_line *result, { *result = {}; result->symtab = symbol_symtab (sym); + result->symbol = sym; result->line = SYMBOL_LINE (sym); result->pc = SYMBOL_VALUE_ADDRESS (sym); result->pspace = SYMTAB_PSPACE (result->symtab); @@ -4642,6 +4643,7 @@ symbol_to_sal (struct symtab_and_line *result, /* We know its line number. */ *result = {}; result->symtab = symbol_symtab (sym); + result->symbol = sym; result->line = SYMBOL_LINE (sym); result->pc = SYMBOL_VALUE_ADDRESS (sym); result->pspace = SYMTAB_PSPACE (result->symtab); diff --git a/gdb/symtab.c b/gdb/symtab.c index 8492315..cea26b8 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -3463,6 +3463,7 @@ find_function_start_sal (struct symbol *sym, int funfirstline) obj_section *section = SYMBOL_OBJ_SECTION (symbol_objfile (sym), sym); symtab_and_line sal = find_pc_sect_line (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)), section, 0); + sal.symbol = sym; if (funfirstline && sal.symtab != NULL && (COMPUNIT_LOCATIONS_VALID (SYMTAB_COMPUNIT (sal.symtab)) @@ -3486,6 +3487,7 @@ find_function_start_sal (struct symbol *sym, int funfirstline) sal.pspace = current_program_space; sal.pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); sal.section = section; + sal.symbol = sym; } if (funfirstline) diff --git a/gdb/symtab.h b/gdb/symtab.h index 1bf77c1..8b429a8 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1421,6 +1421,7 @@ struct symtab_and_line struct program_space *pspace = NULL; struct symtab *symtab = NULL; + struct symbol *symbol = NULL; struct obj_section *section = NULL; /* Line number. Line numbers start at 1 and proceed through symtab->nlines. 0 is never a valid line number; it is used to indicate that line number diff --git a/gdb/testsuite/gdb.base/list-ambiguous.exp b/gdb/testsuite/gdb.base/list-ambiguous.exp index dd473ca..ace3494 100644 --- a/gdb/testsuite/gdb.base/list-ambiguous.exp +++ b/gdb/testsuite/gdb.base/list-ambiguous.exp @@ -48,8 +48,8 @@ proc test_list_ambiguous_symbol {symbol_line symbol} { set lines1_re [line_range_pattern [expr $lineno1 - 5] [expr $lineno1 + 4]] set any "\[^\r\n\]*" - set h0_re "file: \"${any}list-ambiguous0.c\", line number: $lineno0" - set h1_re "file: \"${any}list-ambiguous1.c\", line number: $lineno1" + set h0_re "file: \"${any}list-ambiguous0.c\", line number: $lineno0, symbol: \"$symbol\"" + set h1_re "file: \"${any}list-ambiguous1.c\", line number: $lineno1, symbol: \"$symbol\"" gdb_test "list $symbol" "${h0_re}${lines0_re}\r\n${h1_re}${lines1_re}" gdb_test "list main,$symbol" \ diff --git a/gdb/testsuite/gdb.cp/overload.exp b/gdb/testsuite/gdb.cp/overload.exp index 8cb9311..3bf2a6a 100644 --- a/gdb/testsuite/gdb.cp/overload.exp +++ b/gdb/testsuite/gdb.cp/overload.exp @@ -351,8 +351,8 @@ with_test_prefix "list all overloads" { set lines2 [line_range_pattern [expr $line_bar_B - 5] [expr $line_bar_B + 4]] set any "\[^\r\n\]*" - set h1_re "file: \"${any}overload.cc\", line number: $line_bar_A" - set h2_re "file: \"${any}overload.cc\", line number: $line_bar_B" + set h1_re "file: \"${any}overload.cc\", line number: $line_bar_A, symbol: \"bar\\(A\\)\"" + set h2_re "file: \"${any}overload.cc\", line number: $line_bar_B, symbol: \"bar\\(B\\)\"" gdb_test "list bar" "${h1_re}${lines1}\r\n${h2_re}${lines2}" }