From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id B770F3858C62; Wed, 8 Feb 2023 16:47:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B770F3858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675874823; bh=2zv7nNw+oquPQvF9sOv8b6oTAj2O5OGI/o5MMdNniNo=; h=From:To:Subject:Date:From; b=T7HVhgqO8T/RDeocfRDVHXWvZP2c4GSdCumG4IQqGkz3X/vQwL4sfwFWpmR5QG6Ij /wBTOz0xLFReWwSI1UBMNoDHjAUDLYxC9UhZdBuFHkassFnBCfC6vjjvYN+nWAoZ90 dHuZYcw7XJIuvn2qXKKWiQ+taHQ+3aM7ydaTk4Jk= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Merge fixup_section and fixup_symbol_section X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: dae58e04442670270fe116ff1f2e38a2b184b4a1 X-Git-Newrev: 49c1de0e72098e71c28faa13ae2705988de81220 Message-Id: <20230208164703.B770F3858C62@sourceware.org> Date: Wed, 8 Feb 2023 16:47:03 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D49c1de0e7209= 8e71c28faa13ae2705988de81220 commit 49c1de0e72098e71c28faa13ae2705988de81220 Author: Tom Tromey Date: Fri Jan 13 09:59:29 2023 -0700 Merge fixup_section and fixup_symbol_section =20 fixup_symbol_section delegates all its work to fixup_section, so merge the two. =20 Because there is only a single caller to fixup_symbol_section, we can also remove some of the introductory logic. For example, this will never be called with a NULL objfile any more. =20 The LOC_BLOCK case can be removed, because such symbols are handled by the buildsym code now. =20 Finally, a symbol can only appear in a SEC_ALLOC section, so the loop is modified to skip sections that do not have this flag set. Diff: --- gdb/symtab.c | 107 ++++++++++++++++++++++---------------------------------= ---- gdb/symtab.h | 8 +++-- 2 files changed, 45 insertions(+), 70 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index d3b2edfba9a..9d6ee388ca2 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -1701,18 +1701,39 @@ symtab_free_objfile_observer (struct objfile *objfi= le) symbol_cache_flush (objfile->pspace); } =0C -/* Debug symbols usually don't have section information. We need to dig t= hat - out of the minimal symbols and stash that in the debug symbol. - - DEFAULT_SECTION is the section index to use as the default if the - correct section cannot be found. It may be -1, in which case a - built-in default is used. */ +/* See symtab.h. */ =20 -static void -fixup_section (struct general_symbol_info *ginfo, - CORE_ADDR addr, struct objfile *objfile, - int default_section) +void +fixup_symbol_section (struct symbol *sym, struct objfile *objfile) { + gdb_assert (sym !=3D nullptr); + gdb_assert (sym->is_objfile_owned ()); + gdb_assert (objfile !=3D nullptr); + gdb_assert (sym->section_index () =3D=3D -1); + + /* 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 fallback; + switch (sym->aclass ()) + { + case LOC_STATIC: + fallback =3D objfile->sect_index_data; + break; + + case LOC_LABEL: + fallback =3D objfile->sect_index_text; + break; + + default: + /* Nothing else will be listed in the minsyms -- no use looking + it up. */ + return; + } + + CORE_ADDR addr =3D sym->value_address (); + struct minimal_symbol *msym; =20 /* First, check whether a minimal symbol with the same name exists @@ -1720,10 +1741,10 @@ fixup_section (struct general_symbol_info *ginfo, e.g. on PowerPC64, where the minimal symbol for a function will point to the function descriptor, while the debug symbol will point to the actual function code. */ - msym =3D lookup_minimal_symbol_by_pc_name (addr, ginfo->linkage_name (), + msym =3D lookup_minimal_symbol_by_pc_name (addr, sym->linkage_name (), objfile); if (msym) - ginfo->set_section_index (msym->section_index ()); + sym->set_section_index (msym->section_index ()); else { /* Static, function-local variables do appear in the linker @@ -1762,10 +1783,12 @@ fixup_section (struct general_symbol_info *ginfo, a search of the section table. */ =20 struct obj_section *s; - int fallback =3D default_section; =20 ALL_OBJFILE_OSECTIONS (objfile, s) { + if ((bfd_section_flags (s->the_bfd_section) & SEC_ALLOC) =3D=3D 0) + continue; + int idx =3D s - objfile->sections; CORE_ADDR offset =3D objfile->section_offsets[idx]; =20 @@ -1774,7 +1797,7 @@ fixup_section (struct general_symbol_info *ginfo, =20 if (s->addr () - offset <=3D addr && addr < s->endaddr () - offset) { - ginfo->set_section_index (idx); + sym->set_section_index (idx); return; } } @@ -1783,62 +1806,10 @@ fixup_section (struct general_symbol_info *ginfo, section. If there is no allocated section, then it hardly matters what we pick, so just pick zero. */ if (fallback =3D=3D -1) - ginfo->set_section_index (0); + sym->set_section_index (0); else - ginfo->set_section_index (fallback); - } -} - -struct symbol * -fixup_symbol_section (struct symbol *sym, struct objfile *objfile) -{ - CORE_ADDR addr; - - if (!sym) - return NULL; - - if (!sym->is_objfile_owned ()) - return sym; - - /* We either have an OBJFILE, or we can get at it from the sym's - symtab. Anything else is a bug. */ - gdb_assert (objfile || sym->symtab ()); - - if (objfile =3D=3D NULL) - objfile =3D sym->objfile (); - - if (sym->obj_section (objfile) !=3D nullptr) - return sym; - - /* 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 =3D objfile->sect_index_text; - switch (sym->aclass ()) - { - case LOC_STATIC: - default_section =3D objfile->sect_index_data; - /* FALLTHROUGH. */ - case LOC_LABEL: - addr =3D sym->value_address (); - break; - case LOC_BLOCK: - addr =3D sym->value_block ()->entry_pc (); - break; - - default: - /* Nothing else will be listed in the minsyms -- no use looking - it up. */ - return sym; + sym->set_section_index (fallback); } - - fixup_section (sym, addr, objfile, default_section); - - return sym; } =20 /* See symtab.h. */ diff --git a/gdb/symtab.h b/gdb/symtab.h index 50ce7525793..11ff875c6b8 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2381,8 +2381,12 @@ extern void skip_prologue_sal (struct symtab_and_lin= e *); extern CORE_ADDR skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr); =20 -extern struct symbol *fixup_symbol_section (struct symbol *, - struct objfile *); +/* If SYM requires a section index, find it either via minimal symbols + or examining OBJFILE's sections. Note that SYM's current address + must not have any runtime offsets applied. */ + +extern void fixup_symbol_section (struct symbol *sym, + struct objfile *objfile); =20 /* If MSYMBOL is an text symbol, look for a function debug symbol with the same address. Returns NULL if not found. This is necessary in