public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* How to skip function prologues with stabs debug infomation?
@ 2011-08-19 16:09 Triple Yang
  2011-08-19 16:28 ` Jan Kratochvil
  0 siblings, 1 reply; 11+ messages in thread
From: Triple Yang @ 2011-08-19 16:09 UTC (permalink / raw)
  To: gdb

Hi, everyone.
is there any chance that we use symbol and line (sal) to skip function
prologues with stabs debug infomation?
And if not, why?

-- 
Yang Yong-Yong

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

* Re: How to skip function prologues with stabs debug infomation?
  2011-08-19 16:09 How to skip function prologues with stabs debug infomation? Triple Yang
@ 2011-08-19 16:28 ` Jan Kratochvil
  2011-08-19 17:57   ` Triple Yang
  0 siblings, 1 reply; 11+ messages in thread
From: Jan Kratochvil @ 2011-08-19 16:28 UTC (permalink / raw)
  To: Triple Yang; +Cc: gdb

On Fri, 19 Aug 2011 18:08:54 +0200, Triple Yang wrote:
> is there any chance that we use symbol and line (sal) to skip function
> prologues with stabs debug infomation?
> And if not, why?

GDB does, why not?  The prologue skipping processes already decoded debug
info, no matter if it is DWARF or STABS.

gcc -Wall
Breakpoint 1 at 0x400478
gcc -gstabs
Temporary breakpoint 1 at 0x40047c: file 24.c, line 3.
(gdb) p/x $pc
$1 = 0x40047c
gcc -gdwarf-3
Temporary breakpoint 1 at 0x40047c: file 24.c, line 3.

Sure STABS is discouraged.


Regards,
Jan

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

* Re: How to skip function prologues with stabs debug infomation?
  2011-08-19 16:28 ` Jan Kratochvil
@ 2011-08-19 17:57   ` Triple Yang
  2011-08-19 18:04     ` Jan Kratochvil
                       ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Triple Yang @ 2011-08-19 17:57 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb

Thank you. Of course GDB supports SATBS debug info.

well, my question is mostly on HOW to support SATBS debug info
(specifically, to skip prologue) when I have to write a new gdb
backend, i.e. to port gdb to a new architecture whose function
prologue instructions are not that orderly.

I have checked several backend implementations such as or32 and i386,
but their prologues are tidy and clean to make the analysis much
easier. So we don't even need debug info to skip the prologue. It
seems not that easy for a rescheduled prologue, because prologues
generated with compiler optimization on make things complicated.

It's well-known that people can take advantage of SAL info when to
skip prologue with dwarf info. I wonder whether we can do the same
thing with stabs.

As for your examples, we sometimes need to skip prologue first before
we can insert breakpoints. Skipping prologue is a lower-level
function.

Best regards.

2011/8/20 Jan Kratochvil <jan.kratochvil@redhat.com>:
> On Fri, 19 Aug 2011 18:08:54 +0200, Triple Yang wrote:
>> is there any chance that we use symbol and line (sal) to skip function
>> prologues with stabs debug infomation?
>> And if not, why?
>
> GDB does, why not?  The prologue skipping processes already decoded debug
> info, no matter if it is DWARF or STABS.
>
> gcc -Wall
> Breakpoint 1 at 0x400478
> gcc -gstabs
> Temporary breakpoint 1 at 0x40047c: file 24.c, line 3.
> (gdb) p/x $pc
> $1 = 0x40047c
> gcc -gdwarf-3
> Temporary breakpoint 1 at 0x40047c: file 24.c, line 3.
>
> Sure STABS is discouraged.
>
>
> Regards,
> Jan
>



-- 
Yang Yong-Yong

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

* Re: How to skip function prologues with stabs debug infomation?
  2011-08-19 17:57   ` Triple Yang
@ 2011-08-19 18:04     ` Jan Kratochvil
  2011-08-20  3:45       ` Triple Yang
  2011-08-19 18:15     ` Joel Brobecker
       [not found]     ` <CAEG7qUwkM32O1MEoKFNrb5Hk7+npizsWE7hXCeXJvEmGbL-HQA@mail.gmail.com>
  2 siblings, 1 reply; 11+ messages in thread
From: Jan Kratochvil @ 2011-08-19 18:04 UTC (permalink / raw)
  To: Triple Yang; +Cc: gdb

On Fri, 19 Aug 2011 19:56:44 +0200, Triple Yang wrote:
> It seems not that easy for a rescheduled prologue, because prologues
> generated with compiler optimization on make things complicated.

With gcc -O2 -g gdb already no longer skips prologues, see
symtab->locations_valid (a recent change by me).  If DW_AT_location is valid
for every PC of a function you do not need to skip prologues.  I would find
best to comply with it in your compiler and do not depend on the fragile
prologue skipping.


> It's well-known that people can take advantage of SAL info when to
> skip prologue with dwarf info. I wonder whether we can do the same
> thing with stabs.

I am not proficient with STABS but when gcc can produce the line number info
for both STABS and DWARF you should be also able to do so.


> As for your examples, we sometimes need to skip prologue first before
> we can insert breakpoints. Skipping prologue is a lower-level
> function.

I have not checked what skip_prologue_sal returns but I have checked using
readelf -wl the breakpoint address is aligned with the line number info.


You may have reasons for STABS but I do not see why not to produce only DWARF.


Thanks,
Jan

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

* Re: How to skip function prologues with stabs debug infomation?
  2011-08-19 17:57   ` Triple Yang
  2011-08-19 18:04     ` Jan Kratochvil
@ 2011-08-19 18:15     ` Joel Brobecker
       [not found]     ` <CAEG7qUwkM32O1MEoKFNrb5Hk7+npizsWE7hXCeXJvEmGbL-HQA@mail.gmail.com>
  2 siblings, 0 replies; 11+ messages in thread
From: Joel Brobecker @ 2011-08-19 18:15 UTC (permalink / raw)
  To: Triple Yang; +Cc: Jan Kratochvil, gdb

> It's well-known that people can take advantage of SAL info when to
> skip prologue with dwarf info. I wonder whether we can do the same
> thing with stabs.

I think you can achieve pretty much the same results with stabs as
with DWARF. The SAL info in DWARF is more detailed, but if you only
care about line numbers, it should be mostly OK.

You do have to realize, however, that "skipping the prologue" is
very vague in the case of optimized code, since you might have your
prologue split in multiple blocks. Perhaps you meant skip all
instructions that are associated to the prologue, even if it means
skipping some instructions that are not part of the prologue.
But, myself, I'd much rather stop at the first instruction associated
to user code, which means that sometimes, part of the prologue might
still not have been run yet. Debugging optimized code often means
losing a lot of the convenient things we have when debugging non-
optimized one.

(and, really, if you are going to debug optimized code, you're going
to have a lot of problems if you must use stabs - most of them probably
worse than simple prologue skipping)

-- 
Joel

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

* Re: How to skip function prologues with stabs debug infomation?
       [not found]     ` <CAEG7qUwkM32O1MEoKFNrb5Hk7+npizsWE7hXCeXJvEmGbL-HQA@mail.gmail.com>
@ 2011-08-20  3:18       ` Triple Yang
  0 siblings, 0 replies; 11+ messages in thread
From: Triple Yang @ 2011-08-20  3:18 UTC (permalink / raw)
  To: Sterling Augustine; +Cc: gdb

2011/8/20 Sterling Augustine <saugustine@google.com>:
> The Xtensa port uses prologue analysis (and some heuristics) to
> determine its end without debug info. It's prologues are somewhat more
> complex than others. Take a look at xtensa-tdep.c starting around line
> 1151.
>
> It's only a heuristic, but for unoptimized code it works pretty well.
> For optimized code, the prologue can be sufficiently mixed with real
> code and that makes it hard to declare a single point "the end of the
> prologue" anyway.
>

OK, I'll take it as an example. Actually I've written a skip prologue
subroutine using heuristics, which works sometimes. I am thinking to
make use of SAL to do better.

> Sterling
>
> On Fri, Aug 19, 2011 at 10:56 AM, Triple Yang <triple.yang@gmail.com> wrote:
>> Thank you. Of course GDB supports SATBS debug info.
>>
>> well, my question is mostly on HOW to support SATBS debug info
>> (specifically, to skip prologue) when I have to write a new gdb
>> backend, i.e. to port gdb to a new architecture whose function
>> prologue instructions are not that orderly.
>>
>> I have checked several backend implementations such as or32 and i386,
>> but their prologues are tidy and clean to make the analysis much
>> easier. So we don't even need debug info to skip the prologue. It
>> seems not that easy for a rescheduled prologue, because prologues
>> generated with compiler optimization on make things complicated.
>>
>> It's well-known that people can take advantage of SAL info when to
>> skip prologue with dwarf info. I wonder whether we can do the same
>> thing with stabs.
>>
>> As for your examples, we sometimes need to skip prologue first before
>> we can insert breakpoints. Skipping prologue is a lower-level
>> function.
>>
>> Best regards.
>>
>> 2011/8/20 Jan Kratochvil <jan.kratochvil@redhat.com>:
>>> On Fri, 19 Aug 2011 18:08:54 +0200, Triple Yang wrote:
>>>> is there any chance that we use symbol and line (sal) to skip function
>>>> prologues with stabs debug infomation?
>>>> And if not, why?
>>>
>>> GDB does, why not?  The prologue skipping processes already decoded debug
>>> info, no matter if it is DWARF or STABS.
>>>
>>> gcc -Wall
>>> Breakpoint 1 at 0x400478
>>> gcc -gstabs
>>> Temporary breakpoint 1 at 0x40047c: file 24.c, line 3.
>>> (gdb) p/x $pc
>>> $1 = 0x40047c
>>> gcc -gdwarf-3
>>> Temporary breakpoint 1 at 0x40047c: file 24.c, line 3.
>>>
>>> Sure STABS is discouraged.
>>>
>>>
>>> Regards,
>>> Jan
>>>
>>
>>
>>
>> --
>> Yang Yong-Yong
>>
>



-- 
Yang Yong-Yong

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

* Re: How to skip function prologues with stabs debug infomation?
  2011-08-19 18:04     ` Jan Kratochvil
@ 2011-08-20  3:45       ` Triple Yang
  2011-08-20 11:40         ` Jan Kratochvil
  0 siblings, 1 reply; 11+ messages in thread
From: Triple Yang @ 2011-08-20  3:45 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb

2011/8/20 Jan Kratochvil <jan.kratochvil@redhat.com>:
> On Fri, 19 Aug 2011 19:56:44 +0200, Triple Yang wrote:
>> It seems not that easy for a rescheduled prologue, because prologues
>> generated with compiler optimization on make things complicated.
>
> With gcc -O2 -g gdb already no longer skips prologues, see
> symtab->locations_valid (a recent change by me).  If DW_AT_location is valid
> for every PC of a function you do not need to skip prologues.  I would find
> best to comply with it in your compiler and do not depend on the fragile
> prologue skipping.
>
>
>> It's well-known that people can take advantage of SAL info when to
>> skip prologue with dwarf info. I wonder whether we can do the same
>> thing with stabs.
>
> I am not proficient with STABS but when gcc can produce the line number info
> for both STABS and DWARF you should be also able to do so.
>

I agree with that. Since we can get line number from binary file's
section offset, and vice versa, we can skip prologue using line
number. The practical problem is that, I don't know how to implement
it, i.e. what functions should be called. Any suggestions?

>
>> As for your examples, we sometimes need to skip prologue first before
>> we can insert breakpoints. Skipping prologue is a lower-level
>> function.
>
> I have not checked what skip_prologue_sal returns but I have checked using
> readelf -wl the breakpoint address is aligned with the line number info.
>
>
> You may have reasons for STABS but I do not see why not to produce only DWARF.
>
>
> Thanks,
> Jan
>



-- 
Yang Yong-Yong

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

* Re: How to skip function prologues with stabs debug infomation?
  2011-08-20  3:45       ` Triple Yang
@ 2011-08-20 11:40         ` Jan Kratochvil
  2011-08-20 13:07           ` Triple Yang
  0 siblings, 1 reply; 11+ messages in thread
From: Jan Kratochvil @ 2011-08-20 11:40 UTC (permalink / raw)
  To: Triple Yang; +Cc: gdb

On Sat, 20 Aug 2011 05:45:01 +0200, Triple Yang wrote:
> I agree with that. Since we can get line number from binary file's
> section offset, and vice versa, we can skip prologue using line
> number. The practical problem is that, I don't know how to implement
> it, i.e. what functions should be called. Any suggestions?

It is already implemented, if you just want to write a new GDB arch backend.
This code in GDB is arch-independent.

It would be better to give a reproducer or I do not understand the problem.


Regards,
Jan

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

* Re: How to skip function prologues with stabs debug infomation?
  2011-08-20 11:40         ` Jan Kratochvil
@ 2011-08-20 13:07           ` Triple Yang
  2011-08-20 13:33             ` Jan Kratochvil
  0 siblings, 1 reply; 11+ messages in thread
From: Triple Yang @ 2011-08-20 13:07 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb

2011/8/20 Jan Kratochvil <jan.kratochvil@redhat.com>:
> On Sat, 20 Aug 2011 05:45:01 +0200, Triple Yang wrote:
>> I agree with that. Since we can get line number from binary file's
>> section offset, and vice versa, we can skip prologue using line
>> number. The practical problem is that, I don't know how to implement
>> it, i.e. what functions should be called. Any suggestions?
>
> It is already implemented, if you just want to write a new GDB arch backend.
> This code in GDB is arch-independent.
>
> It would be better to give a reproducer or I do not understand the problem.
>
>
> Regards,
> Jan
>

Sorry.
I will give a C-like pseudocode to describe what I plan to do in
function XXX_skip_prologue(), here XXX represents my architecture
name.

    line = get_line_number(func_addr);

    next_line = find_next_statement_line_number(line); // take
advantage of debug info

    addr = get_addr(nexe_line);

Here, if func_addr is the start address of a function, we actually
skip the function prologue. (But I am not sure this idea is proper.)

And I guess gdb does the similar thing to step a source code line,
which is of course arch-independent. But I don't know where those
codes are placed. GDBing a gdb to locate them is time-consuming and
tiring. I will be very grateful if you or someone else point it out.

Best regards.

-- 
Yang Yong-Yong

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

* Re: How to skip function prologues with stabs debug infomation?
  2011-08-20 13:07           ` Triple Yang
@ 2011-08-20 13:33             ` Jan Kratochvil
  2011-08-20 14:49               ` Triple Yang
  0 siblings, 1 reply; 11+ messages in thread
From: Jan Kratochvil @ 2011-08-20 13:33 UTC (permalink / raw)
  To: Triple Yang; +Cc: gdb

On Sat, 20 Aug 2011 15:06:44 +0200, Triple Yang wrote:
> I will give a C-like pseudocode to describe what I plan to do in
> function XXX_skip_prologue(), here XXX represents my architecture
> name.
> 
>     line = get_line_number(func_addr);
> 
>     next_line = find_next_statement_line_number(line); // take
> advantage of debug info
> 
>     addr = get_addr(nexe_line);
> 
> Here, if func_addr is the start address of a function, we actually
> skip the function prologue. (But I am not sure this idea is proper.)

Yes, it is rought what GDB already does for all the arches.

gdbarch_skip_prologue is there for the case you have no debug info (neither
DWARF nor STABS, no -g).  So it is good to implement gdbarch_skip_prologue but
it should be only based on instructions decoding in such case.


> And I guess gdb does the similar thing to step a source code line,
> which is of course arch-independent. But I don't know where those
> codes are placed. GDBing a gdb to locate them is time-consuming and
> tiring. I will be very grateful if you or someone else point it out.

I already stated here the GDB function is skip_prologue_sal.


Thanks,
Jan

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

* Re: How to skip function prologues with stabs debug infomation?
  2011-08-20 13:33             ` Jan Kratochvil
@ 2011-08-20 14:49               ` Triple Yang
  0 siblings, 0 replies; 11+ messages in thread
From: Triple Yang @ 2011-08-20 14:49 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb

Thanks a lot. I will check skip_prologue_sal to find out what it does
and returns.

Best regards.

2011/8/20 Jan Kratochvil <jan.kratochvil@redhat.com>:
> On Sat, 20 Aug 2011 15:06:44 +0200, Triple Yang wrote:
>> I will give a C-like pseudocode to describe what I plan to do in
>> function XXX_skip_prologue(), here XXX represents my architecture
>> name.
>>
>>     line = get_line_number(func_addr);
>>
>>     next_line = find_next_statement_line_number(line); // take
>> advantage of debug info
>>
>>     addr = get_addr(nexe_line);
>>
>> Here, if func_addr is the start address of a function, we actually
>> skip the function prologue. (But I am not sure this idea is proper.)
>
> Yes, it is rought what GDB already does for all the arches.
>
> gdbarch_skip_prologue is there for the case you have no debug info (neither
> DWARF nor STABS, no -g).  So it is good to implement gdbarch_skip_prologue but
> it should be only based on instructions decoding in such case.
>
>
>> And I guess gdb does the similar thing to step a source code line,
>> which is of course arch-independent. But I don't know where those
>> codes are placed. GDBing a gdb to locate them is time-consuming and
>> tiring. I will be very grateful if you or someone else point it out.
>
> I already stated here the GDB function is skip_prologue_sal.
>
>
> Thanks,
> Jan
>



-- 
Yang Yong-Yong

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

end of thread, other threads:[~2011-08-20 14:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-19 16:09 How to skip function prologues with stabs debug infomation? Triple Yang
2011-08-19 16:28 ` Jan Kratochvil
2011-08-19 17:57   ` Triple Yang
2011-08-19 18:04     ` Jan Kratochvil
2011-08-20  3:45       ` Triple Yang
2011-08-20 11:40         ` Jan Kratochvil
2011-08-20 13:07           ` Triple Yang
2011-08-20 13:33             ` Jan Kratochvil
2011-08-20 14:49               ` Triple Yang
2011-08-19 18:15     ` Joel Brobecker
     [not found]     ` <CAEG7qUwkM32O1MEoKFNrb5Hk7+npizsWE7hXCeXJvEmGbL-HQA@mail.gmail.com>
2011-08-20  3:18       ` Triple Yang

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