[1/6] Use default section indexes in fixup_symbol_section

Message ID 20230118153025.342512-2-tromey@adacore.com
State New
Headers
Series Change how symbol section indices are set |

Commit Message

Tom Tromey Jan. 18, 2023, 3:30 p.m. UTC
  If fixup_section does not find a matching section, it arbitrarily
chooses the first one.  However, it seems better to make this default
depend on the type of the symbol -- i.e., default data symbols to
.data and text symbols to .text.

I've also made fixup_section static, as it only has one caller.
---
 gdb/symtab.c | 16 ++++++++++++----
 gdb/symtab.h |  3 ---
 2 files changed, 12 insertions(+), 7 deletions(-)
  

Comments

Simon Marchi Jan. 18, 2023, 5:19 p.m. UTC | #1
On 1/18/23 10:30, Tom Tromey via Gdb-patches wrote:
> If fixup_section does not find a matching section, it arbitrarily
> chooses the first one.  However, it seems better to make this default
> depend on the type of the symbol -- i.e., default data symbols to
> .data and text symbols to .text.
> 
> I've also made fixup_section static, as it only has one caller.

I don't really know the big picture to tell whether this is right, but
one small comment:

> ---
>  gdb/symtab.c | 16 ++++++++++++----
>  gdb/symtab.h |  3 ---
>  2 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/gdb/symtab.c b/gdb/symtab.c
> index b3445133c8c..fe247ab70eb 100644
> --- a/gdb/symtab.c
> +++ b/gdb/symtab.c
> @@ -1704,9 +1704,10 @@ symtab_free_objfile_observer (struct objfile *objfile)
>  /* Debug symbols usually don't have section information.  We need to dig that
>     out of the minimal symbols and stash that in the debug symbol.  */
>  
> -void
> +static void
>  fixup_section (struct general_symbol_info *ginfo,
> -	       CORE_ADDR addr, struct objfile *objfile)
> +	       CORE_ADDR addr, struct objfile *objfile,
> +	       int default_section)

Could you expand the comment above to describe default_section?

Simon
  
Tom Tromey Jan. 18, 2023, 7:13 p.m. UTC | #2
>> -void
>> +static void
>> fixup_section (struct general_symbol_info *ginfo,
>> -	       CORE_ADDR addr, struct objfile *objfile)
>> +	       CORE_ADDR addr, struct objfile *objfile,
>> +	       int default_section)

Simon> Could you expand the comment above to describe default_section?

I did this, but note the comment is deleted again in patch #6 when the
two functions are merged.

Tom
  

Patch

diff --git a/gdb/symtab.c b/gdb/symtab.c
index b3445133c8c..fe247ab70eb 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1704,9 +1704,10 @@  symtab_free_objfile_observer (struct objfile *objfile)
 /* Debug symbols usually don't have section information.  We need to dig that
    out of the minimal symbols and stash that in the debug symbol.  */
 
-void
+static void
 fixup_section (struct general_symbol_info *ginfo,
-	       CORE_ADDR addr, struct objfile *objfile)
+	       CORE_ADDR addr, struct objfile *objfile,
+	       int default_section)
 {
   struct minimal_symbol *msym;
 
@@ -1757,7 +1758,7 @@  fixup_section (struct general_symbol_info *ginfo,
 	 a search of the section table.  */
 
       struct obj_section *s;
-      int fallback = -1;
+      int fallback = default_section;
 
       ALL_OBJFILE_OSECTIONS (objfile, s)
 	{
@@ -1808,9 +1809,16 @@  fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
   /* We should have an objfile by now.  */
   gdb_assert (objfile);
 
+  /* Note that if this ends up as -1, fixup_section will handle that
+     reasonably well.  So, it's fine to use the objfile's section
+     index without doing the check that is done by the wrapper macros
+     like SECT_OFF_TEXT.  */
+  int default_section = objfile->sect_index_text;
   switch (sym->aclass ())
     {
     case LOC_STATIC:
+      default_section = objfile->sect_index_data;
+      /* FALLTHROUGH.  */
     case LOC_LABEL:
       addr = sym->value_address ();
       break;
@@ -1824,7 +1832,7 @@  fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
       return sym;
     }
 
-  fixup_section (sym, addr, objfile);
+  fixup_section (sym, addr, objfile, default_section);
 
   return sym;
 }
diff --git a/gdb/symtab.h b/gdb/symtab.h
index ae3a81991df..ac3f6391dc3 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2607,9 +2607,6 @@  extern struct block_symbol
    compiler (armcc).  */
 bool producer_is_realview (const char *producer);
 
-void fixup_section (struct general_symbol_info *ginfo,
-		    CORE_ADDR addr, struct objfile *objfile);
-
 extern unsigned int symtab_create_debug;
 
 /* Print a "symtab-create" debug statement.  */