public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Use default section indexes in fixup_symbol_section
Date: Wed,  8 Feb 2023 16:46:33 +0000 (GMT)	[thread overview]
Message-ID: <20230208164633.486AD3858D39@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3f01c12b9006227529823a07aee8a21627da63dd

commit 3f01c12b9006227529823a07aee8a21627da63dd
Author: Tom Tromey <tromey@adacore.com>
Date:   Tue Jan 10 11:39:50 2023 -0700

    Use default section indexes in fixup_symbol_section
    
    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.

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 *objfile)
 }
 \f
 /* 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.  */
+   out of the minimal symbols and stash that in the debug symbol.
 
-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;
 
@@ -1758,7 +1763,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)
 	{
@@ -1809,9 +1814,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;
@@ -1825,7 +1837,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 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);
 
-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.  */

                 reply	other threads:[~2023-02-08 16:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230208164633.486AD3858D39@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).