]> Git Repo - binutils.git/commitdiff
Make "list ambiguous" show symbol names too
authorPedro Alves <[email protected]>
Wed, 20 Sep 2017 15:12:54 +0000 (16:12 +0100)
committerPedro Alves <[email protected]>
Wed, 20 Sep 2017 15:21:26 +0000 (16:21 +0100)
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:
2017-09-20  Pedro Alves  <[email protected]>

* 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:
2017-09-20  Pedro Alves  <[email protected]>

* 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/ChangeLog
gdb/cli/cli-cmds.c
gdb/linespec.c
gdb/symtab.c
gdb/symtab.h
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/list-ambiguous.exp
gdb/testsuite/gdb.cp/overload.exp

index 1e0ae7db6a8c7ce43152733a613055680920434b..8db2f6e4ce0b82aa9245e576f79acdf83d5cf05a 100644 (file)
@@ -1,3 +1,12 @@
+2017-09-20  Pedro Alves  <[email protected]>
+
+       * 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.
+
 2017-09-20  Pedro Alves  <[email protected]>
 
        * linespec.c (minsym_found): Handle non-text minsyms.
index 883844ee7082e24b0d361caa0d31bdc1f042d020..260fd3f63532514db9b44084946a5b4a217971de 100644 (file)
@@ -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<const symtab_and_line> 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)
     }
 }
 \f
+/* 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<const symtab_and_line> 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
index 35ef15983653017455ec7c24d0fa0c84cf354d10..6e472e242972018521e275e1a95edb47fe141236 100644 (file)
@@ -4623,6 +4623,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);
@@ -4638,6 +4639,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);
index b504cd626313385ca501cd8c6e0496062ae1f90b..bf7ee646d4286d11201b787ae19339203bae5c65 100644 (file)
@@ -3461,6 +3461,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))
@@ -3484,6 +3485,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)
index 1bf77c199ba2d51027788d4813da157ddab2a6ee..8b429a8b65a4f0f108050f53d96b1bf8db39bda3 100644 (file)
@@ -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
index 7ab92a2c0c77286341c4ec92554fcc21403e7289..721bd81ed81d480a194963de20d0cfdeca14e9ad 100644 (file)
@@ -1,3 +1,9 @@
+2017-09-20  Pedro Alves  <[email protected]>
+
+       * gdb.base/list-ambiguous.exp (test_list_ambiguous_symbol): Expect
+       symbol names in gdb's output.
+       * gdb.cp/overload.exp ("list all overloads"): Likewise.
+
 2017-09-20  Pedro Alves  <[email protected]>
 
        * gdb.base/list-ambiguous.exp (test_list_ambiguous_function):
index dd473caf62f985ae36d81291c7f465c90ab61173..ace3494a262a158fca0b18c223a65a77c2a05d32 100644 (file)
@@ -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" \
index 8cb9311d397e2be339cae2ece80714e8261aa6ab..3bf2a6a576fc56d1915fcc1f4127d5d9d31a7c4e 100644 (file)
@@ -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}"
 }
 
This page took 0.073271 seconds and 4 git commands to generate.