Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFC/RFA] find_pc_sect_psymtab(): symbol table not always complete
@ 2003-11-19 18:19 Joel Brobecker
  2003-11-19 18:26 ` Daniel Jacobowitz
  0 siblings, 1 reply; 7+ messages in thread
From: Joel Brobecker @ 2003-11-19 18:19 UTC (permalink / raw)
  To: gdb-patches

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

Hello,

Re: http://sources.redhat.com/ml/gdb-patches/2003-11/msg00368.html

The following change tweaks find_pc_sect_psymtab() to stop assuming
that the symbol table will contain all symbols. So when we don't find
a partial symtab containing a symbol at the same address as the minimal
symbol we found, we return the symtab containing  symbol which address
is the closest to the given PC address.

This fixes the problem reported in the message referenced above.

As noted by Daniel J, the cleanest fix, in the long run, is probably to
record accurate code ranges rather insted of the textlow/texthigh
addresses. This is a more long term project which I wanted to tackle
without the pressure of the users not being able to debug comfortably.
This will be the subject of another post coming shortly.

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.

It has been tested on x86-linux with stabs & dwarf-2 with no regression.
It has also been tested on mips-irix but on a 5.3-based version of GDB
(we haven't moved to a more recent version of GDB on this platform yet,
and the HEAD version is giving me some trouble that I need to sort out).

Comments? OK to apply?

Thanks,
-- 
Joel

[-- Attachment #2: symtab.c.diff --]
[-- Type: text/plain, Size: 1777 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	19 Nov 2003 18:04:15 -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,19 @@ find_pc_sect_psymtab (CORE_ADDR pc, asec
 		    && SYMBOL_VALUE_ADDRESS (p)
 		    == SYMBOL_VALUE_ADDRESS (msymbol))
 		  return (tpst);
+                 if (p != NULL)
+                   {
+                     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);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC/RFA] find_pc_sect_psymtab(): symbol table not always complete
  2003-11-19 18:19 [RFC/RFA] find_pc_sect_psymtab(): symbol table not always complete Joel Brobecker
@ 2003-11-19 18:26 ` Daniel Jacobowitz
  2003-11-20  0:24   ` Joel Brobecker
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Jacobowitz @ 2003-11-19 18:26 UTC (permalink / raw)
  To: gdb-patches

On Wed, Nov 19, 2003 at 10:19:10AM -0800, Joel Brobecker wrote:
> Hello,
> 
> Re: http://sources.redhat.com/ml/gdb-patches/2003-11/msg00368.html
> 
> The following change tweaks find_pc_sect_psymtab() to stop assuming
> that the symbol table will contain all symbols. So when we don't find
> a partial symtab containing a symbol at the same address as the minimal
> symbol we found, we return the symtab containing  symbol which address
> is the closest to the given PC address.
> 
> This fixes the problem reported in the message referenced above.
> 
> As noted by Daniel J, the cleanest fix, in the long run, is probably to
> record accurate code ranges rather insted of the textlow/texthigh
> addresses. This is a more long term project which I wanted to tackle
> without the pressure of the users not being able to debug comfortably.
> This will be the subject of another post coming shortly.
> 
> 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.
> 
> It has been tested on x86-linux with stabs & dwarf-2 with no regression.
> It has also been tested on mips-irix but on a 5.3-based version of GDB
> (we haven't moved to a more recent version of GDB on this platform yet,
> and the HEAD version is giving me some trouble that I need to sort out).
> 
> Comments? OK to apply?

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.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC/RFA] find_pc_sect_psymtab(): symbol table not always complete
  2003-11-19 18:26 ` Daniel Jacobowitz
@ 2003-11-20  0:24   ` Joel Brobecker
  2003-12-02 16:15     ` Daniel Jacobowitz
                       ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Joel Brobecker @ 2003-11-20  0:24 UTC (permalink / raw)
  To: gdb-patches

[-- 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);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC/RFA] find_pc_sect_psymtab(): symbol table not always complete
  2003-11-20  0:24   ` Joel Brobecker
@ 2003-12-02 16:15     ` Daniel Jacobowitz
  2004-01-17  8:13     ` Joel Brobecker
  2004-02-19 19:01     ` Elena Zannoni
  2 siblings, 0 replies; 7+ messages in thread
From: Daniel Jacobowitz @ 2003-12-02 16:15 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On Wed, Nov 19, 2003 at 04:23:59PM -0800, Joel Brobecker wrote:
> > > 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?

This looks great to me.  It'll need to be approved by the symtab
maintainers.

> 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);


-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC/RFA] find_pc_sect_psymtab(): symbol table not always complete
  2003-11-20  0:24   ` Joel Brobecker
  2003-12-02 16:15     ` Daniel Jacobowitz
@ 2004-01-17  8:13     ` Joel Brobecker
  2004-02-19 19:01     ` Elena Zannoni
  2 siblings, 0 replies; 7+ messages in thread
From: Joel Brobecker @ 2004-01-17  8:13 UTC (permalink / raw)
  To: gdb-patches

On Wed, Nov 19, 2003 at 04:23:59PM -0800, Joel Brobecker wrote:
> 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.

ping?

(DanielJ gave a positive feedback on this patch early december)

> 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);


-- 
Joel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC/RFA] find_pc_sect_psymtab(): symbol table not always complete
  2003-11-20  0:24   ` Joel Brobecker
  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
  2 siblings, 1 reply; 7+ messages in thread
From: Elena Zannoni @ 2004-02-19 19:01 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

Joel Brobecker writes:


 Joel, I committed an updated version of your patch. By updated I mean
 with new/more comments. Now let's keep an eye on any apparently
 unrelated breakage :-)

elena

2004-02-19  Joel Brobecker  <brobecker@gnat.com>

	Committed by Elena Zannoni  <ezannoni@redhat.com>
	* symtab.c (find_pc_sect_psymtab): Return the psymtab that
	contains a symbol wich is the best, non-exact match for the given
	pc.  Update comments.


Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.127
diff -u -p -r1.127 symtab.c
--- symtab.c    17 Feb 2004 15:21:22 -0000      1.127
+++ symtab.c    19 Feb 2004 17:13:11 -0000
@@ -672,8 +672,10 @@ init_sal (struct symtab_and_line *sal)
 
  
  
-/* Find which partial symtab on contains PC and SECTION.  Return 0 if none.  */-
+/* Find which partial symtab contains PC and SECTION.  Return 0 if
+   none.  We return the psymtab that contains a symbol whose address
+   exactly matches PC, or, if we cannot find an exact match, the
+   psymtab that contains a symbol whose address is closest to PC.  */
 struct partial_symtab *
 find_pc_sect_psymtab (CORE_ADDR pc, asection *section)
 {
@@ -698,6 +700,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 +714,13 @@ find_pc_sect_psymtab (CORE_ADDR pc, asec
        if (msymbol == NULL)
          return (pst);
  
+       /* The code range of partial symtabs sometimes overlap, so, in
+          the loop below, 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 whose
+          address is closest to the PC address.  By closest we mean
+          that find_pc_sect_symbol returns the symbol with address
+          that is closest and still less than the given PC.  */
        for (tpst = pst; tpst != NULL; tpst = tpst->next)
          {
            if (pc >= tpst->textlow && pc < tpst->texthigh)
@@ -721,9 +732,33 @@ 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 (or is closest to) 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.  */
+                   /* This way we return the psymtab which contains
+                      such best match symbol. This can help in cases
+                      where the symbol information/debuginfo is not
+                      complete, like for instance on IRIX6 with gcc,
+                      where no debug info is emitted for
+                      statics. (See also the nodebug.exp
+                      testcase.)  */
+                   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);



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC/RFA] find_pc_sect_psymtab(): symbol table not always complete
  2004-02-19 19:01     ` Elena Zannoni
@ 2004-02-20 17:11       ` Joel Brobecker
  0 siblings, 0 replies; 7+ messages in thread
From: Joel Brobecker @ 2004-02-20 17:11 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: gdb-patches

Elena,

>  Joel, I committed an updated version of your patch. By updated I mean
>  with new/more comments. Now let's keep an eye on any apparently
>  unrelated breakage :-)
> 
> elena
> 
> 2004-02-19  Joel Brobecker  <brobecker@gnat.com>
> 
> 	Committed by Elena Zannoni  <ezannoni@redhat.com>
> 	* symtab.c (find_pc_sect_psymtab): Return the psymtab that
> 	contains a symbol wich is the best, non-exact match for the given
> 	pc.  Update comments.

Thanks. You are too kind to have fixed the comments for me...

-- 
Joel


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-02-20 17:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-19 18:19 [RFC/RFA] find_pc_sect_psymtab(): symbol table not always complete Joel Brobecker
2003-11-19 18:26 ` Daniel Jacobowitz
2003-11-20  0:24   ` Joel Brobecker
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox