Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@gnat.com>
To: gdb-patches@sources.redhat.com
Subject: Re: [RFC/RFA] find_pc_sect_psymtab(): symbol table not always complete
Date: Thu, 20 Nov 2003 00:24:00 -0000	[thread overview]
Message-ID: <20031120002359.GB504@gnat.com> (raw)
In-Reply-To: <20031119182634.GA1423@nevyn.them.org>

[-- Attachment #1: Type: text/plain, Size: 684 bytes --]

> > 2003-11-19  J. Brobecker  <brobecker@gnat.com>
> > 
> >         * symtab.c (find_pc_sect_psymtab): Refine the search for the
> >         partial symtab corresponding to the given PC address, taking
> >         into account the fact that the symbol table might be incomplete.
> 
> FWIW, this looks good to me, but I'd like another comment on the new
> test to the effect of, the find_pc_sect_psymtab call will always return
> the closest symbol below pc in tpst.  Threw me for a moment how you
> were just checking for the highest valued symbol.

Thanks for your feedback Daniel. I agree on that a comment is useful.
Here is a revised version of the patch. Is it better?

-- 
Joel

[-- Attachment #2: symtab.c.diff --]
[-- Type: text/plain, Size: 2152 bytes --]

Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.122
diff -u -p -r1.122 symtab.c
--- symtab.c	8 Nov 2003 00:13:03 -0000	1.122
+++ symtab.c	20 Nov 2003 00:21:30 -0000
@@ -698,6 +698,8 @@ find_pc_sect_psymtab (CORE_ADDR pc, asec
     if (pc >= pst->textlow && pc < pst->texthigh)
       {
 	struct partial_symtab *tpst;
+       struct partial_symtab *best_pst = pst;
+       struct partial_symbol *best_psym = NULL;
 
 	/* An objfile that has its functions reordered might have
 	   many partial symbol tables containing the PC, but
@@ -710,6 +712,11 @@ find_pc_sect_psymtab (CORE_ADDR pc, asec
 	if (msymbol == NULL)
 	  return (pst);
 
+       /* The code range of partial symtabs sometimes overlap, so
+          we need to check all partial symtabs and find the one that
+          fits better for the given PC address. We select the partial
+          symtab that contains a symbol which address is closest to
+          the PC address.  */
 	for (tpst = pst; tpst != NULL; tpst = tpst->next)
 	  {
 	    if (pc >= tpst->textlow && pc < tpst->texthigh)
@@ -721,9 +728,24 @@ find_pc_sect_psymtab (CORE_ADDR pc, asec
 		    && SYMBOL_VALUE_ADDRESS (p)
 		    == SYMBOL_VALUE_ADDRESS (msymbol))
 		  return (tpst);
+                 if (p != NULL)
+                   {
+                     /* We found a symbol in this partial symtab which
+                        matches PC, check whether it is closer than our
+                        current BEST_PSYM.  Since this symbol address is
+                        necessarily lower or equal to PC, the symbol closer
+                        to PC is the symbol which address is the highest.  */
+                     if (best_psym == NULL
+                         || SYMBOL_VALUE_ADDRESS (p)
+                              > SYMBOL_VALUE_ADDRESS (best_psym))
+                       {
+                         best_psym = p;
+                         best_pst = tpst;
+                       }
+                   }
 	      }
 	  }
-	return (pst);
+       return best_pst;
       }
   }
   return (NULL);

  reply	other threads:[~2003-11-20  0:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-19 18:19 Joel Brobecker
2003-11-19 18:26 ` Daniel Jacobowitz
2003-11-20  0:24   ` Joel Brobecker [this message]
2003-12-02 16:15     ` Daniel Jacobowitz
2004-01-17  8:13     ` Joel Brobecker
2004-02-19 19:01     ` Elena Zannoni
2004-02-20 17:11       ` Joel Brobecker

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=20031120002359.GB504@gnat.com \
    --to=brobecker@gnat.com \
    --cc=gdb-patches@sources.redhat.com \
    /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