[1/6] Use default section indexes in fixup_symbol_section
Commit Message
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
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
>> -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
@@ -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;
}
@@ -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. */