Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: ligang@sunnorth.com.cn
Cc: gdb@sourceware.org, bjgnu@sunnorth.com.cn
Subject: Re: fail to get ra and bp
Date: Thu, 12 Oct 2006 05:39:00 -0000	[thread overview]
Message-ID: <20061012053944.GN1065@adacore.com> (raw)
In-Reply-To: <OFF6F48CBC.D5A8195E-ON48257205.001D53B8-48257205.001D91BF@sunnorth.com.cn>

> I am porting GDB to a new target.

Would you mind telling us what this new target is? I believe this will
greatly help us provide more accurate answers. In the meantime...

> The prologue has two insns ---- push ra and push bp.
> When back tracing and printing variables, gdb will look for return address 
> of this frame and frame pointer on stack.
> Unfortunately, If compiling with -O2, the two insns are probably deleted. 
> So, GDB will not get ra and bp value.

Typical problem. My recommendation, stay away from prologue analysis
as much as you can, because as you know, higher levels of optimization
will break the typical frame layout. What you want, is have this
information provided by the compiler itself and dumped into the
objects in some form.

One very popular form, at least in the GNU world, is DWARF CFI. There
is also another popular form, which I don't really know much about.
The information is stored in .eh_frame sections. But it essentially
does the same: It tells you how to unwind the call stack.

This is what you want because this information allows you to avoid
tricky prologue scanning and hairy heuristics to try to guess where
things are.

Now that I think of it, if you have no choice but do prologue scanning,
you might want to look at a framework that was recently contributed
which should make your task easier. I think it's prologue-value.[hc].

-- 
Joel


  reply	other threads:[~2006-10-12  5:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-12  5:21 ligang
2006-10-12  5:39 ` Joel Brobecker [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-10-12  7:14 ligang
2006-10-12 12:54 ` Daniel Jacobowitz
2006-10-12  4:33 bjgnu

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=20061012053944.GN1065@adacore.com \
    --to=brobecker@adacore.com \
    --cc=bjgnu@sunnorth.com.cn \
    --cc=gdb@sourceware.org \
    --cc=ligang@sunnorth.com.cn \
    /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