This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: question on gdbarch_skip_prologue()


On Mar 7, 10:12am, David Mosberger wrote:

> >>>>> On Thu, 7 Mar 2002 01:11:17 -0700, Kevin Buettner <kevinb@redhat.com> said:
> 
>   Kevin> GDB currently expects that the skip_prologue() function will
>   Kevin> return a PC that's after the last prologue instruction that
>   Kevin> saved an argument to its "home" location (if any) in memory
>   Kevin> (or whereever the debug info says that a parameter's location
>   Kevin> is).  The difficulty with this, of course, is that with
>   Kevin> optimized code, it can be very difficult to discern where
>   Kevin> this is.
> 
> So, if I may paraphrase, skip_prologue() returns the PC of the first
> instruction for which the debug info will be valid, right?

Right.

But you should also know that most (all?) of us working on GDB don't
really like this behavior and are eagerly waiting for the day when
it'll be possible to implement skip_prologue() as the identity
function (on the first argument).

> If so, I'd argue this has much more to do with debug info than with
> unwind info.  For example, hand-written assembly routines often have
> sizable prologues, but a programmer would almost certainly want a
> breakpoint to be placed right at the beginning of the function, not at
> the end of the prologue.

That's true.

> Now, I wonder whether it wouldn't be possible and indeed better to
> implement skip_prologue() based on debug info.  Unfortunately, I'm not
> very familiar with, say, DWARF2.  However, I did notice that applying
> the "info line" command to the first line of source code in a C
> program does indeed return a starting address that corresponds to the
> value that ought to be returned by skip_prologue().

I believe that there are implementations of skip_prologue() which do
exactly that.  You can find a somewhat better algorithm in
refine_prologue_limit() in ia64-tdep.c.  (It works for optimized
prologues too.)

I should note that this method doesn't work well when you have a
function written all on one line like this:

    int sum (int a, int b) { int c = a + b; return c; }

> Perhaps skip_prologue() could look for the first PC that is covered by
> line info and return that value (or the original PC if there is no
> such PC)?  To be on the safe side, skip_prologue() probably ought to
> give up the search as soon as it sees a branch instruction.
> 
> Would this be a safe algorithm?

I think so, though you probably want it to stop at predicated
instructions too.  (Plus you should consider using the
refine_prologue_limit() algorithm.)

Kevin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]