Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Re: syscall backtraces on arm-linux-gnu
       [not found] <20090805160852.GA25684@radix50.net>
@ 2009-08-07 16:07 ` Baurzhan Ismagulov
  2009-08-07 17:22   ` Daniel Jacobowitz
  0 siblings, 1 reply; 2+ messages in thread
From: Baurzhan Ismagulov @ 2009-08-07 16:07 UTC (permalink / raw)
  To: gdb-patches; +Cc: gdb

Hello,

I'm taking this to gdb-patches.

On Wed, Aug 05, 2009 at 06:08:52PM +0200, Baurzhan Ismagulov wrote:
> I can't get gdb 6.8.50.20090804 to print complete backtraces on
> arm-linux-gnu.
...
> (gdb) bt
> #0  0x400e16c8 in select () from /lib/libc.so.6
> #1  0x00000000 in ?? ()
> 
> I stopped on select and stepped through the instructions. The function
> starts like this:
> 
insn      mnemonic
>         push    {lr}
>         ...
1a000007  bne     0x400e16dc
>         push    {r4}
>         ...
>         svc     0x0090008e
>         pop     {r4}       
>         ...
> 
> I've seen that bt starts showing incorrect results after the second
> push

It turned out that select is implemented in assembly in glibc, so no CFI
is provided and gdb falls back to prologue analysis. The following hack
fixes the use case for me:

diff -Naurp -X /opt/ibr/bin/dontdiff.ibr -X dontdiff.prj gdb-6.8.50.20090804.orig/gdb/arm-tdep.c gdb-6.8.50.20090804/gdb/arm-tdep.c
--- gdb-6.8.50.20090804.orig/gdb/arm-tdep.c	2009-07-31 01:05:04.000000000 +0200
+++ gdb-6.8.50.20090804/gdb/arm-tdep.c	2009-08-07 17:26:10.000000000 +0200
@@ -891,12 +891,14 @@ arm_scan_prologue (struct frame_info *th
 	  regs[ARM_IP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -imm);
 	  continue;
 	}
-      else if (insn == 0xe52de004)	/* str lr, [sp, #-4]! */
+      else if ((insn & 0xffff0000) == 0xe52d0000)       /* str rx, [sp, #-4]! */
 	{
+	  unsigned reg = (insn & 0xf000) >> 12;
 	  if (pv_area_store_would_trash (stack, regs[ARM_SP_REGNUM]))
 	    break;
 	  regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -4);
-	  pv_area_store (stack, regs[ARM_SP_REGNUM], 4, regs[ARM_LR_REGNUM]);
+	  if (reg == ARM_LR_REGNUM)
+	    pv_area_store (stack, regs[ARM_SP_REGNUM], 4, regs[ARM_LR_REGNUM]);
 	  continue;
 	}
       else if ((insn & 0xffff0000) == 0xe92d0000)
@@ -988,8 +990,6 @@ arm_scan_prologue (struct frame_info *th
 			     regs[fp_start_reg++]);
 	    }
 	}
-      else if ((insn & 0xf0000000) != 0xe0000000)
-	break;			/* Condition not true, exit early */
       else if ((insn & 0xfe200000) == 0xe8200000)	/* ldm? */
 	break;			/* Don't scan past a block load */
       else

The first hunk handles pushes of any register, not just lr; the second
one prevents early exit on a jump (see disassembly above).

What do you think?

Meanwhile, I will see whether I can get the testsuite to work on arm.

Thanks in advance,
-- 
Baurzhan Ismagulov
http://www.kz-easy.com/


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

* Re: syscall backtraces on arm-linux-gnu
  2009-08-07 16:07 ` syscall backtraces on arm-linux-gnu Baurzhan Ismagulov
@ 2009-08-07 17:22   ` Daniel Jacobowitz
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jacobowitz @ 2009-08-07 17:22 UTC (permalink / raw)
  To: gdb-patches

On Fri, Aug 07, 2009 at 05:49:49PM +0200, Baurzhan Ismagulov wrote:
> It turned out that select is implemented in assembly in glibc, so no CFI
> is provided and gdb falls back to prologue analysis. The following hack
> fixes the use case for me:

The right answer is to somehow get CFI for this.  My preferred
solution is to teach gas how to generate DWARF-2 CFI from the ARM
EH directives (the functions in glibc are already annotated).
Worst case, someone can write the necessary DWARF by hand using
.byte directives.

> @@ -988,8 +990,6 @@ arm_scan_prologue (struct frame_info *th
>  			     regs[fp_start_reg++]);
>  	    }
>  	}
> -      else if ((insn & 0xf0000000) != 0xe0000000)
> -	break;			/* Condition not true, exit early */
>        else if ((insn & 0xfe200000) == 0xe8200000)	/* ldm? */
>  	break;			/* Don't scan past a block load */
>        else

Skipping a jump during scanning is definitely not safe.  That means
GDB's got no idea whether following instructions - pushes and stack
adjusts included - were executed.

You won't see much in the way of testsuite changes with this, because
the testsuite runs (A) with DWARF CFI from the compiler, and (B)
mostly without optimization.

-- 
Daniel Jacobowitz
CodeSourcery


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

end of thread, other threads:[~2009-08-07 16:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20090805160852.GA25684@radix50.net>
2009-08-07 16:07 ` syscall backtraces on arm-linux-gnu Baurzhan Ismagulov
2009-08-07 17:22   ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox