Blob Blame History Raw
commit 06871ae84096ed1672eb76f44cea4d5dbe79ae24
Author: Pedro Alves <palves@redhat.com>
Date:   Wed Sep 20 16:12:54 2017 +0100

    Make "list ambiguous" show symbol names too
    
    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  <palves@redhat.com>
    
            * 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  <palves@redhat.com>
    
            * gdb.base/list-ambiguous.exp (test_list_ambiguous_symbol): Expect
            symbol names in gdb's output.
            * gdb.cp/overload.exp ("list all overloads"): Likewise.

### a/gdb/ChangeLog
### b/gdb/ChangeLog
## -1,5 +1,14 @@
 2017-09-20  Pedro Alves  <palves@redhat.com>
 
+	* 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  <palves@redhat.com>
+
 	* linespec.c (minsym_found): Handle non-text minsyms.
 	(symbol_to_sal): Record a sal.pc for non-block, non-label symbols.
 
Index: gdb-7.6.1/gdb/linespec.c
===================================================================
--- gdb-7.6.1.orig/gdb/linespec.c	2017-10-27 20:44:32.493790183 +0200
+++ gdb-7.6.1/gdb/linespec.c	2017-10-27 20:49:52.460307350 +0200
@@ -3648,6 +3648,7 @@
 	{
 	  init_sal (result);
 	  result->symtab = SYMBOL_SYMTAB (sym);
+	  result->symbol = sym;
 	  result->line = SYMBOL_LINE (sym);
 	  result->pc = SYMBOL_VALUE_ADDRESS (sym);
 	  result->pspace = SYMTAB_PSPACE (SYMBOL_SYMTAB (sym));
@@ -3663,6 +3664,7 @@
 	  /* We know its line number.  */
 	  init_sal (result);
 	  result->symtab = SYMBOL_SYMTAB (sym);
+	  result->symbol = sym;
 	  result->line = SYMBOL_LINE (sym);
 	  result->pspace = SYMTAB_PSPACE (SYMBOL_SYMTAB (sym));
 	  return 1;
Index: gdb-7.6.1/gdb/symtab.c
===================================================================
--- gdb-7.6.1.orig/gdb/symtab.c	2017-10-27 20:44:32.493790183 +0200
+++ gdb-7.6.1/gdb/symtab.c	2017-10-27 21:02:02.162058159 +0200
@@ -872,6 +872,7 @@
 {
   sal->pspace = NULL;
   sal->symtab = 0;
+  sal->symbol = NULL;
   sal->section = 0;
   sal->line = 0;
   sal->pc = 0;
@@ -2774,6 +2775,7 @@
   fixup_symbol_section (sym, NULL);
   sal = find_pc_sect_line (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)),
 			   SYMBOL_OBJ_SECTION (sym), 0);
+  sal.symbol = sym;
 
   if (funfirstline && sal.symtab != NULL
       && (sal.symtab->locations_valid
@@ -2797,6 +2799,7 @@
       sal.pspace = current_program_space;
       sal.pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
       sal.section = SYMBOL_OBJ_SECTION (sym);
+      sal.symbol = sym;
     }
 
   if (funfirstline)
Index: gdb-7.6.1/gdb/symtab.h
===================================================================
--- gdb-7.6.1.orig/gdb/symtab.h	2017-10-27 20:44:32.493790183 +0200
+++ gdb-7.6.1/gdb/symtab.h	2017-10-27 21:01:41.522895501 +0200
@@ -1105,6 +1105,7 @@
   struct program_space *pspace;
 
   struct symtab *symtab;
+  struct symbol *symbol;
   struct obj_section *section;
   /* 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