public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* i386 prologue
@ 2004-10-15 15:25 David Lecomber
  2004-10-16 11:54 ` Mark Kettenis
  0 siblings, 1 reply; 2+ messages in thread
From: David Lecomber @ 2004-10-15 15:25 UTC (permalink / raw)
  To: gdb

My knowledge of this area is very limited, but I regularly come across
bad stack traces in GDB, and I think the problem is in i386-tdep.c 
i386_analyze_frame_setup

The code there seems very specific to GNU compilers, expecting either an
"enter" - or a pushl %ebp.  Well, here's what you get from Intel version
7.1 fortran compiler:

Dump of assembler code for function test:
0x0804afd0 <test+0>:    push   %ebx
0x0804afd1 <test+1>:    mov    %esp,%ebx
0x0804afd3 <test+3>:    and    $0xfffffff0,%esp
0x0804afd6 <test+6>:    push   %edi
0x0804afd7 <test+7>:    push   %esi
0x0804afd8 <test+8>:    push   %ebp
0x0804afd9 <test+9>:    sub    $0x74,%esp
0x0804afdc <test+12>:   movl   $0x81d34ac,0x81ad07c
0x0804afe6 <test+22>:   movl   $0x81d34a0,0x81ad088
0x0804aff0 <test+32>:   push   $0x81ad06c
0x0804aff5 <test+37>:   push   $0x4
0x0804aff7 <test+39>:   call   0x816ca94 <f_iof>
0x0804affc <test+44>:   push   $0x81ad098
0x0804b001 <test+49>:   push   $0x0
0x0804b003 <test+51>:   call   0x81698b0 <f_ioc>
0x0804b008 <test+56>:   add    $0x10,%esp
0x0804b00b <test+59>:   test   %eax,%eax

and even:
0x080b71c8 <kpl_minput+0>:      push   %ebp
0x080b71c9 <kpl_minput+1>:      push   %ebx
0x080b71ca <kpl_minput+2>:      sub    $0x34,%esp
0x080b71cd <kpl_minput+5>:      mov    0x40(%esp),%ebx
0x080b71d1 <kpl_minput+9>:      mov    (%ebx),%edx
0x080b71d3 <kpl_minput+11>:     movl   $0xffffffff,0x81e4588
0x080b71dd <kpl_minput+21>:     test   %edx,%edx
0x080b71df <kpl_minput+23>:     jle    0x80b7d51 <kpl_minput+2953>
0x080b71e5 <kpl_minput+29>:     mov    0x84711b0,%eax
0x080b71ea <kpl_minput+34>:     movl   $0xd52,0x81e458c
0x080b71f4 <kpl_minput+44>:     movl   $0xffffffff,0x81e4590
0x080b71fe <kpl_minput+54>:     mov    0xfffffffc(%eax,%edx,4),%eax
0x080b7202 <kpl_minput+58>:     cmp    $0xfffffffe,%eax
0x080b7205 <kpl_minput+61>:     je     0x80b7d2f <kpl_minput+2919>


This seriously upsets things.. the stack becomes absolutely useless!!

Is there some alternative -- does libunwind offer a solution?  Or is the
prologue stuff the Right Thing To Do [TM]?

Anyone have any ideas?

d.

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

* Re: i386 prologue
  2004-10-15 15:25 i386 prologue David Lecomber
@ 2004-10-16 11:54 ` Mark Kettenis
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Kettenis @ 2004-10-16 11:54 UTC (permalink / raw)
  To: david; +Cc: gdb

   From: David Lecomber <david@streamline-computing.com>
   Content-Type: text/plain
   Date: Fri, 15 Oct 2004 14:49:20 +0100

   The code there seems very specific to GNU compilers, expecting either an
   "enter" - or a pushl %ebp.

Not really; some of the code there is trying to support the System V
compiler.  But since I've never seen such a compiler, that code patch
might have suffered some bit rot.

However, the instructions you mention ar really pretty generic.  The
`enter' instruction's sole purpose is setting up a stack frame (but
nobody uses it), and `pushl %ebp; movl %esp, %ebp' is the canonical
way to set up a stack frame suggested by the i386 System V psABI.


  Well, here's what you get from Intel version
   7.1 fortran compiler:

   Dump of assembler code for function test:
   0x0804afd0 <test+0>:    push   %ebx
   0x0804afd1 <test+1>:    mov    %esp,%ebx
   0x0804afd3 <test+3>:    and    $0xfffffff0,%esp
   0x0804afd6 <test+6>:    push   %edi
   0x0804afd7 <test+7>:    push   %esi
   0x0804afd8 <test+8>:    push   %ebp
   0x0804afd9 <test+9>:    sub    $0x74,%esp
   0x0804afdc <test+12>:   movl   $0x81d34ac,0x81ad07c
   0x0804afe6 <test+22>:   movl   $0x81d34a0,0x81ad088
   0x0804aff0 <test+32>:   push   $0x81ad06c
   0x0804aff5 <test+37>:   push   $0x4
   0x0804aff7 <test+39>:   call   0x816ca94 <f_iof>
   0x0804affc <test+44>:   push   $0x81ad098
   0x0804b001 <test+49>:   push   $0x0
   0x0804b003 <test+51>:   call   0x81698b0 <f_ioc>
   0x0804b008 <test+56>:   add    $0x10,%esp
   0x0804b00b <test+59>:   test   %eax,%eax

That's fairly non-standard indeed.  This suggests that on some intel
processors the above performs better than the almost equivalent:

    push %ebp
    mov  %esp, %ebx
    and  $0xfffffff0, %esp
    push %edi
    push %esi
    push %ebx

I've never seen GCC generate such code.

   and even:
   0x080b71c8 <kpl_minput+0>:      push   %ebp
   0x080b71c9 <kpl_minput+1>:      push   %ebx
   0x080b71ca <kpl_minput+2>:      sub    $0x34,%esp
   0x080b71cd <kpl_minput+5>:      mov    0x40(%esp),%ebx
   0x080b71d1 <kpl_minput+9>:      mov    (%ebx),%edx
   0x080b71d3 <kpl_minput+11>:     movl   $0xffffffff,0x81e4588
   0x080b71dd <kpl_minput+21>:     test   %edx,%edx
   0x080b71df <kpl_minput+23>:     jle    0x80b7d51 <kpl_minput+2953>
   0x080b71e5 <kpl_minput+29>:     mov    0x84711b0,%eax
   0x080b71ea <kpl_minput+34>:     movl   $0xd52,0x81e458c
   0x080b71f4 <kpl_minput+44>:     movl   $0xffffffff,0x81e4590
   0x080b71fe <kpl_minput+54>:     mov    0xfffffffc(%eax,%edx,4),%eax
   0x080b7202 <kpl_minput+58>:     cmp    $0xfffffffe,%eax
   0x080b7205 <kpl_minput+61>:     je     0x80b7d2f <kpl_minput+2919>

Ah, a frameless leaf-function.  I think GCC nowadays generates these
too.

   This seriously upsets things.. the stack becomes absolutely useless!!

If there is no other way to unwind the stack, yes.

   Is there some alternative -- does libunwind offer a solution?  Or is the
   prologue stuff the Right Thing To Do [TM]?

Last time I looked libunwind doesn't even try to unwind frameless
functions.  The solution is to get the compiler to generate unwind
information.  GCC can generate DWARF2 Call Frame Info, which GDB can
use.  I don't know if ICC can do that too.

Mark

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

end of thread, other threads:[~2004-10-15 18:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-15 15:25 i386 prologue David Lecomber
2004-10-16 11:54 ` Mark Kettenis

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