Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Jim Blandy <jimb@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: RFA: general prologue analysis framework
Date: Sat, 15 Oct 2005 12:12:00 -0000	[thread overview]
Message-ID: <ud5m7kmi6.fsf@gnu.org> (raw)
In-Reply-To: <m3y8568as0.fsf@alligator.red-bean.com> (message from Jim Blandy on Thu, 06 Oct 2005 16:51:11 -0700)

> From: Jim Blandy <jimb@redhat.com>
> Date: Thu, 06 Oct 2005 16:51:11 -0700
> 
> + /* When we analyze a prologue, we're really doing 'abstract
> +    interpretation' or 'pseudo-evaluation': running the function's code
> +    in simulation, but using conservative approximations of the values
> +    it would have when it actually runs.  For example, if our function
> +    starts with the instruction:
> + 
> +       addi r1, 42     # add 42 to r1
> + 
> +    we don't know exactly what value will be in r1 after executing this
> +    instruction, but we do know it'll be 42 greater than its original
> +    value.
> + 
> +    If we then see an instruction like:
> + 
> +       addi r1, 22     # add 22 to r1
> + 
> +    we still don't know what r1's value is, but again, we can say it is
> +    now 64 greater than its original value.
> + 
> +    If the next instruction were:
> + 
> +       mov r2, r1      # set r2 to r1's value
> + 
> +    then we can say that r2's value is now the original value of r1
> +    plus 64.
> + 
> +    It's common for prologues to save registers on the stack, so we'll
> +    need to track the values of stack frame slots, as well as the
> +    registers.  So after an instruction like this:
> + 
> +       mov (fp+4), r2
> + 
> +    Then we'd know that the stack slot four bytes above the frame
> +    pointer holds the original value of r1 plus 64.
> + 
> +    And so on.
> + 
> +    Of course, this can only go so far before it gets unreasonable.  If
> +    we wanted to be able to say anything about the value of r1 after
> +    the instruction:
> + 
> +       xor r1, r3      # exclusive-or r1 and r3, place result in r1
> + 
> +    then things would get pretty complex.  But remember, we're just
> +    doing a conservative approximation; if exclusive-or instructions
> +    aren't relevant to prologues, we can just say r1's value is now
> +    'unknown'.  We can ignore things that are too complex, if that loss
> +    of information is acceptable for our application.
> + 
> +    So when I say "conservative approximation" here, what I mean is an
> +    approximation that is either accurate, or marked "unknown", but
> +    never inaccurate.
> +    
> +    Once you've reached the current PC, or an instruction that you
> +    don't know how to simulate, you stop.  Now you can examine the
> +    state of the registers and stack slots you've kept track of.
> + 
> +    - To see how large your stack frame is, just check the value of the
> +      stack pointer register; if it's the original value of the SP
> +      minus a constant, then that constant is the stack frame's size.
> +      If the SP's value has been marked as 'unknown', then that means
> +      the prologue has done something too complex for us to track, and
> +      we don't know the frame size.
> + 
> +    - To see where we've saved the previous frame's registers, we just
> +      search the values we've tracked --- stack slots, usually, but
> +      registers, too, if you want --- for something equal to the
> +      register's original value.  If the ABI suggests a standard place
> +      to save a given register, then we can check there first, but
> +      really, anything that will get us back the original value will
> +      probably work.
> + 
> +    Sure, this takes some work.  But prologue analyzers aren't
> +    quick-and-simple pattern patching to recognize a few fixed prologue
> +    forms any more; they're big, hairy functions.  Along with inferior
> +    function calls, prologue analysis accounts for a substantial
> +    portion of the time needed to stabilize a GDB port.  So I think
> +    it's worthwhile to look for an approach that will be easier to
> +    understand and maintain.  In the approach used here:
> + 
> +    - It's easier to see that the analyzer is correct: you just see
> +      whether the analyzer properly (albiet conservatively) simulates
> +      the effect of each instruction.
> + 
> +    - It's easier to extend the analyzer: you can add support for new
> +      instructions, and know that you haven't broken anything that
> +      wasn't already broken before.
> + 
> +    - It's orthogonal: to gather new information, you don't need to
> +      complicate the code for each instruction.  As long as your domain
> +      of conservative values is already detailed enough to tell you
> +      what you need, then all the existing instruction simulations are
> +      already gathering the right data for you.
> + 
> +    A 'struct prologue_value' is a conservative approximation of the
> +    real value the register or stack slot will have.  */

Jim, I'd be thrilled to see this text in gdbint.texinfo (if and when
the patch is committed), perhaps with a few more general words about
prologue analysis, which is currently completely undocumented.


  parent reply	other threads:[~2005-10-15 12:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-07 20:39 Jim Blandy
2005-10-07 21:25 ` Nathan J. Williams
2005-10-07 21:30   ` Daniel Jacobowitz
2005-10-07 21:41     ` Nathan J. Williams
2005-10-08  7:02       ` Jim Blandy
2005-10-08  7:01   ` Jim Blandy
2005-10-08 16:00     ` Daniel Jacobowitz
2005-10-09 20:27 ` Daniel Jacobowitz
2005-10-13  0:20   ` Jim Blandy
2005-10-13  1:04     ` Daniel Jacobowitz
2005-10-13 13:50     ` Ulrich Weigand
2005-10-13 17:17       ` Jim Blandy
2005-10-13 17:48         ` Ulrich Weigand
2005-10-13 18:03           ` Daniel Jacobowitz
2005-10-14 18:13           ` Jim Blandy
2005-10-17 18:52             ` Ulrich Weigand
2005-10-17 20:28               ` Jim Blandy
2005-11-23  2:56                 ` Ulrich Weigand
2005-10-15 12:12 ` Eli Zaretskii [this message]
2005-10-17 20:32   ` Jim Blandy
2005-10-19  8:55     ` Eli Zaretskii

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=ud5m7kmi6.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=jimb@redhat.com \
    /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