Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Richard Smith <richard@ex-parrot.com>
To: gdb@sourceware.org
Subject: Backtraces broken on i386 by unorthodox encoding of push %ebp
Date: Sat, 30 Mar 2013 19:13:00 -0000	[thread overview]
Message-ID: <alpine.LRH.2.02.1303301849040.2445@sphinx.mythic-beasts.com> (raw)


I have an i386 program on Linux where some of the functions 
start with a slightly unorthodox encoding of the usual 
function prologue:

   08048104 <foo>:
    8048104:	ff f5                	push   %ebp
    8048106:	89 e5                	mov    %esp,%ebp

However, when I have this form of prologue, gdb doesn't 
recongnise it, and doesn't give a meaningful backtrace.

In this case, the push instruction is encoded using the 
two-byte PUSH r/m32 (FF /6) form, instead of the more common 
one-byte PUSH r32 (50+rd) form.  The two instructions 
execute identically, and both have been around since the 
8086.  So far as I'm aware, the ABI doesn't require the use 
of the shorter encoding of the instruction in the function 
prologue.  And for this particular application, I would 
prefer to continue using the two-byte form.

I think it should be pretty straightforward to make gdb 
accept both versions of the instruction.  I'm not familiar 
with gdb's source code, but at a guess, modifying the start 
of i386_analyze_frame_setup in gdb/i386-tdep.c so that it 
does something like this:

   /* Check for `pushl %ebp', either encoded using `push r32' (55)
      or less commonly using `push r/m32' (FF F5). */
   if (op == 0x55 || op == 0xff
       && read_memory_unsigned_integer (pc + 1, 1, byte_order) == 0xf5)
     {
       /* Take into account that we've executed the `pushl %ebp' that
          starts this instruction sequence.  */
       cache->saved_regs[I386_EBP_REGNUM] = 0;
       cache->sp_offset += 4;
       pc += op == 0x55 ? 1 : 2;

I expect the amd64 version of the code could do with a 
similar change.

Richard


             reply	other threads:[~2013-03-30 19:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-30 19:13 Richard Smith [this message]
2013-03-30 19:50 ` Jan Kratochvil
2013-03-30 20:07   ` Joel Brobecker
2013-03-30 21:03   ` Richard Smith
2013-03-30 23:53     ` Mike Frysinger
2013-03-31  5:48     ` Jan Kratochvil

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=alpine.LRH.2.02.1303301849040.2445@sphinx.mythic-beasts.com \
    --to=richard@ex-parrot.com \
    --cc=gdb@sourceware.org \
    /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