Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* gdb not detecting function sections correctly for functions in overlays
@ 2013-09-06 20:02 Arnab Bhaduri
  2013-10-10 18:03 ` Tom Tromey
  0 siblings, 1 reply; 6+ messages in thread
From: Arnab Bhaduri @ 2013-09-06 20:02 UTC (permalink / raw)
  To: gdb

Hello,

I'm working with the Xtensa version of gdb, based off version 7.5.91. There are local patches applied, but as far as I can tell they do not affect the problem here.

While debugging overlays, I created an executable with two overlays, which are each in their own section (say .overlay0 and .overlay1). The first, .overlay0, has a function foo(), the second has a function bar(). Since the overlays are mapped at the same VMA, both functions have the same start address. When I set a breakpoint on bar(), gdb sets the breakpoint at the correct address. It also (correctly) does not set the breakpoint to the target right away. When it detects the overlay being changed, it sets the breakpoints, but in the wrong overlay. As far as I can tell, it does this because it looks up the function's address from its name, then uses the address to find the function's section (fixup_section() in symtab.c). But, since all the overlay sections share the same starting VMA address, this lookup finds the first matching section which is not always the correct one.

Since objdump --syms does show the section name for foo() and bar() correctly, I assume the information exists somewhere. It seems like gdb should be using somewhat different logic to map a function in an overlay to the correct section. Did I understand things correctly so far, or have I missed something else that is supposed to handle this case ? I am not very familiar with gdb sources so the latter is entirely possible. Any advice would be most welcome.

Thanks
Arnab


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

* Re: gdb not detecting function sections correctly for functions in overlays
  2013-09-06 20:02 gdb not detecting function sections correctly for functions in overlays Arnab Bhaduri
@ 2013-10-10 18:03 ` Tom Tromey
  2013-10-14 16:29   ` Arnab Bhaduri
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2013-10-10 18:03 UTC (permalink / raw)
  To: Arnab Bhaduri; +Cc: gdb

>>>>> "Arnab" == Arnab Bhaduri <arnab@cadence.com> writes:

Arnab> When it detects the overlay being changed, it sets the
Arnab> breakpoints, but in the wrong overlay. As far as I can tell, it
Arnab> does this because it looks up the function's address from its
Arnab> name, then uses the address to find the function's section
Arnab> (fixup_section() in symtab.c). But, since all the overlay
Arnab> sections share the same starting VMA address, this lookup finds
Arnab> the first matching section which is not always the correct one.

Arnab> Since objdump --syms does show the section name for foo() and bar()
Arnab> correctly, I assume the information exists somewhere. It seems like
Arnab> gdb should be using somewhat different logic to map a function in an
Arnab> overlay to the correct section. Did I understand things correctly so
Arnab> far, or have I missed something else that is supposed to handle this
Arnab> case ?

objdump --syms will show the ELF symbols, but not the DWARF symbols.
But if you have debuginfo, gdb will generally prefer the DWARF.
This may explain the discrepancy there.

Maybe this is a regression from my patch series to change how symbol
sections are represented.  That would be my guess, anyway, if earlier
versions of gdb worked.

Anyway, there is no high road to fixing this -- just debugging gdb.

I don't think there's a good way of associating a DWARF symbol with a
particular overlay.  That seems to be the root of the problem to me.

Tom


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

* RE: gdb not detecting function sections correctly for functions in overlays
  2013-10-10 18:03 ` Tom Tromey
@ 2013-10-14 16:29   ` Arnab Bhaduri
  2013-10-22 16:53     ` Tom Tromey
  0 siblings, 1 reply; 6+ messages in thread
From: Arnab Bhaduri @ 2013-10-14 16:29 UTC (permalink / raw)
  To: gdb; +Cc: Tom Tromey

Thanks for your reply. Yes, I came to the same conclusion after digging around in the DWARF information. I had not been familiar with DWARF, or else I might have reached that conclusion much sooner.

I have made a couple of local changes that make things work better for me. Perhaps you could give me your opinion on these (described below).

1) add_location_to_breakpoint() (breakpoint.c) - this calls set_breakpoint_location_function() which sets the function name incorrectly because it uses the PC-to-section lookup. I modified this like so: if the "symtab_and_line * sal" argument's section is an overlay section, and sal->symtab is not null, then walk over all the symbols in the symtab and find the one with a line number that is closest to (but not larger than) the line number specified in the sal. With this best match symbol, search all the overlay sections for a name match. If there is a match, select that overlay section and update the bp_location. Of course this will not work if e.g. I define two functions with the same name in two different overlays. In that case I warn the user and arbitrarily choose the first one found.

2) find_function_start_sal() (symtab.c) - this calls find_pc_sect_line() to look up the section, and fails when the PC-to-section lookup fails for overlays. It was not clear to me why it does not use the symtab in the symbol itself, which is passed in as an argument. I made a change here to use the symbol's symtab if it has one.

Arnab

> -----Original Message-----
> From: Tom Tromey [mailto:tromey@redhat.com]
> Subject: Re: gdb not detecting function sections correctly for functions
> in overlays
> 
> objdump --syms will show the ELF symbols, but not the DWARF symbols.
> But if you have debuginfo, gdb will generally prefer the DWARF.
> This may explain the discrepancy there.
> 
> Maybe this is a regression from my patch series to change how symbol
> sections are represented.  That would be my guess, anyway, if earlier
> versions of gdb worked.
> 
> Anyway, there is no high road to fixing this -- just debugging gdb.
> 
> I don't think there's a good way of associating a DWARF symbol with a
> particular overlay.  That seems to be the root of the problem to me.
> 
> Tom


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

* Re: gdb not detecting function sections correctly for functions in overlays
  2013-10-14 16:29   ` Arnab Bhaduri
@ 2013-10-22 16:53     ` Tom Tromey
  2013-10-22 17:32       ` Pedro Alves
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2013-10-22 16:53 UTC (permalink / raw)
  To: Arnab Bhaduri; +Cc: gdb

>>>>> "Arnab" == Arnab Bhaduri <arnab@cadence.com> writes:

Arnab> I have made a couple of local changes that make things work better for
Arnab> me. Perhaps you could give me your opinion on these (described below).

Arnab> 1) add_location_to_breakpoint() (breakpoint.c) - this calls
Arnab> set_breakpoint_location_function() which sets the function name
Arnab> incorrectly because it uses the PC-to-section lookup. I modified this
Arnab> like so:
[...]

I think a patch would be simpler to understand.

Tom


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

* Re: gdb not detecting function sections correctly for functions in overlays
  2013-10-22 16:53     ` Tom Tromey
@ 2013-10-22 17:32       ` Pedro Alves
  2013-10-22 17:38         ` Arnab Bhaduri
  0 siblings, 1 reply; 6+ messages in thread
From: Pedro Alves @ 2013-10-22 17:32 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Arnab Bhaduri, gdb

On 10/22/2013 05:52 PM, Tom Tromey wrote:
>>>>>> "Arnab" == Arnab Bhaduri <arnab@cadence.com> writes:
> 
> Arnab> I have made a couple of local changes that make things work better for
> Arnab> me. Perhaps you could give me your opinion on these (described below).
> 
> Arnab> 1) add_location_to_breakpoint() (breakpoint.c) - this calls
> Arnab> set_breakpoint_location_function() which sets the function name
> Arnab> incorrectly because it uses the PC-to-section lookup. I modified this
> Arnab> like so:
> [...]
> 
> I think a patch would be simpler to understand.

Assuming the patch is either small (10 lines or so), or we can get the
copyright assigned, which would be great.  I don't see Cadence mentioned
in copyright.list though.

Otherwise, a description of the bug might actually be better, for allowing
a clean room implementation.

-- 
Pedro Alves


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

* RE: gdb not detecting function sections correctly for functions in overlays
  2013-10-22 17:32       ` Pedro Alves
@ 2013-10-22 17:38         ` Arnab Bhaduri
  0 siblings, 0 replies; 6+ messages in thread
From: Arnab Bhaduri @ 2013-10-22 17:38 UTC (permalink / raw)
  To: Pedro Alves, Tom Tromey; +Cc: gdb

Tensilica has previously provided code (I forgot to mention that I'm working on the Tensilica Xtensa, which is now part of Cadence). I haven't been working on this for long and still haven't figured out how to deal with this stuff inside Cadence, so it might take a little while. I'll need to figure that out before I send you any patches. I can certainly file a bug.

Thanks
Arnab

> -----Original Message-----
> From: Pedro Alves [mailto:palves@redhat.com]
> Sent: Tuesday, October 22, 2013 10:32 AM
> To: Tom Tromey
> Cc: Arnab Bhaduri; gdb@sourceware.org
> Subject: Re: gdb not detecting function sections correctly for functions
> in overlays
> 
> On 10/22/2013 05:52 PM, Tom Tromey wrote:
> >>>>>> "Arnab" == Arnab Bhaduri <arnab@cadence.com> writes:
> >
> > Arnab> I have made a couple of local changes that make things work
> > Arnab> better for me. Perhaps you could give me your opinion on these
> (described below).
> >
> > Arnab> 1) add_location_to_breakpoint() (breakpoint.c) - this calls
> > Arnab> set_breakpoint_location_function() which sets the function name
> > Arnab> incorrectly because it uses the PC-to-section lookup. I
> > Arnab> modified this like so:
> > [...]
> >
> > I think a patch would be simpler to understand.
> 
> Assuming the patch is either small (10 lines or so), or we can get the
> copyright assigned, which would be great.  I don't see Cadence mentioned
> in copyright.list though.
> 
> Otherwise, a description of the bug might actually be better, for
> allowing a clean room implementation.
> 
> --
> Pedro Alves


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

end of thread, other threads:[~2013-10-22 17:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-06 20:02 gdb not detecting function sections correctly for functions in overlays Arnab Bhaduri
2013-10-10 18:03 ` Tom Tromey
2013-10-14 16:29   ` Arnab Bhaduri
2013-10-22 16:53     ` Tom Tromey
2013-10-22 17:32       ` Pedro Alves
2013-10-22 17:38         ` Arnab Bhaduri

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