Topic
  • 3 replies
  • Latest Post - ‏2010-05-26T15:06:45Z by kenws
kraiskil
kraiskil
2 Posts

Pinned topic Offset when debugging SPU assembly

‏2010-05-26T08:00:56Z |
Hi all.

I had a case of miscompilation that boiled down to this code:

.text .align   3 .global  main .type main, @function main: nop stqd  $lr,16($sp)   ai $sp, $sp, -176 lnop   nop lqd   $lr,16($sp)   nop bi $lr

This is obviously wrong. But when single-stepping the code, there seems to be an offset. Setting a break on main, results the breakpoint being set on the 'ai' instruction. Similarly, the SPU exits when single stepping the 'ai', when error happens in the 'bi' as the SPU returns to some "random" address. And even if I add a few nop/lnop:s after the 'ai', it will still be stepping the 'ai' that makes the SPU return. Does spu-gcc, as or ld do optimization on assembly files?

Program compiled wiht 'spu-gcc m.s -o m'

This is the relevant gdb output

Using host libthread_db library 
"/lib64/libthread_db.so.1". (gdb) display /i $pc (gdb) 

break main Breakpoint 1 at 0x168 (gdb) run Starting program: /home/kraiskil/temp/m (no debugging symbols found) [snip]   Breakpoint 1, 0x00000168 in main () 1: x/i $pc 0x168 <main+8>:     ai      $1,$1,-176 (gdb) stepi <cross-architecture call>

Why is there an offset?
Could be old tools (using Ubuntu 8.10 on PS3, spu-gcc 4.1.1, ppu-gdb 6.6.50.20070623-cvs). But I'd really not like to update in case it breaks something, and newer tools don't help :)

Thank you in advance,

kalle
Updated on 2010-05-26T15:06:45Z at 2010-05-26T15:06:45Z by kenws
  • kenws
    kenws
    49 Posts

    Re: Offset when debugging SPU assembly

    ‏2010-05-26T11:38:35Z  
    Hi,
    I think it's because GDB skips the function prologue. You may want to set the breakpoint at the starting address of the main function:
    
    (gdb) p main $1 = 
    {<text variable, no debug info>
    } 0x160 <main> (gdb) b *0x160 Breakpoint 1 at 0x160 (gdb) run (gdb) stepi
    

    -ken
  • kraiskil
    kraiskil
    2 Posts

    Re: Offset when debugging SPU assembly

    ‏2010-05-26T13:30:29Z  
    • kenws
    • ‏2010-05-26T11:38:35Z
    Hi,
    I think it's because GDB skips the function prologue. You may want to set the breakpoint at the starting address of the main function:
    <pre class="jive-pre"> (gdb) p main $1 = {<text variable, no debug info> } 0x160 <main> (gdb) b *0x160 Breakpoint 1 at 0x160 (gdb) run (gdb) stepi </pre>
    -ken
    That I didn't know. Thanks!

    But it still does the "<cross-architecture call>" when I step over the 'ai' instruction.
    ?
  • kenws
    kenws
    49 Posts

    Re: Offset when debugging SPU assembly

    ‏2010-05-26T15:06:45Z  
    • kraiskil
    • ‏2010-05-26T13:30:29Z
    That I didn't know. Thanks!

    But it still does the "<cross-architecture call>" when I step over the 'ai' instruction.
    ?
    It seems the corrupt stack pointer irritates GDBs logic that analyzes the stack frames.
    -ken