From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 486AD3858D39; Wed, 8 Feb 2023 16:46:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 486AD3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675874793; bh=Ckpr42qgmBNlDgXuBhMpcj7fLy3glbbsDy+sFpliHkc=; h=From:To:Subject:Date:From; b=JUJDF6y3J/2D+Rvg+yNewn14ZD9f0KRhMGEpyeNiT02ZEzeim+kUWDQHe3ONGjc/f 6Pjs2lMMldWgRS75iOs24gue8Jiqc4rxtf2RtTHMS8XT47h492tKI1mlmpc4WLX/ZC tUFgZTC9U5K9K4ghanuUCIhnSMyEqQljLwD27mCY= 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] Use default section indexes in fixup_symbol_section X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 1947a4a4bb7651a4656edceb1f9b246f96f89ebd X-Git-Newrev: 3f01c12b9006227529823a07aee8a21627da63dd Message-Id: <20230208164633.486AD3858D39@sourceware.org> Date: Wed, 8 Feb 2023 16:46:33 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D3f01c12b9006= 227529823a07aee8a21627da63dd commit 3f01c12b9006227529823a07aee8a21627da63dd Author: Tom Tromey Date: Tue Jan 10 11:39:50 2023 -0700 Use default section indexes in fixup_symbol_section =20 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. =20 I've also made fixup_section static, as it only has one caller. Diff: --- gdb/symtab.c | 22 +++++++++++++++++----- gdb/symtab.h | 3 --- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 4cc0d023095..a120c1d5e15 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -1703,11 +1703,16 @@ symtab_free_objfile_observer (struct objfile *objfi= le) } =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. */ + out of the minimal symbols and stash that in the debug symbol. =20 -void + 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. */ + +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; =20 @@ -1758,7 +1763,7 @@ fixup_section (struct general_symbol_info *ginfo, a search of the section table. */ =20 struct obj_section *s; - int fallback =3D -1; + int fallback =3D default_section; =20 ALL_OBJFILE_OSECTIONS (objfile, s) { @@ -1809,9 +1814,16 @@ fixup_symbol_section (struct symbol *sym, struct obj= file *objfile) /* We should have an objfile by now. */ gdb_assert (objfile); =20 + /* 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; @@ -1825,7 +1837,7 @@ fixup_symbol_section (struct symbol *sym, struct objf= ile *objfile) return sym; } =20 - fixup_section (sym, addr, objfile); + fixup_section (sym, addr, objfile, default_section); =20 return sym; } diff --git a/gdb/symtab.h b/gdb/symtab.h index 3ba40bd9af5..484644f6129 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2608,9 +2608,6 @@ extern struct block_symbol compiler (armcc). */ bool producer_is_realview (const char *producer); =20 -void fixup_section (struct general_symbol_info *ginfo, - CORE_ADDR addr, struct objfile *objfile); - extern unsigned int symtab_create_debug; =20 /* Print a "symtab-create" debug statement. */