Joe's blog

Tracking VFP registers when debugging with iPhone gdb

updated March 9, 2009 19:23:46 PDT

Apple's gdb for iPhone has a pretty stupid bug: If you ask it for the value of a floating-point register, it always gives you zero. This is a huge pain in the ass when you're tricking out your inner loops with VFP assembly and don't know where you're getting your registers mixed up. To get around this, I wrote a function to dump the VFP state:

extern "C" void _dumpvfps(void)
    __attribute__((noinline));

extern "C"
void _dumpvfps(void)
{
    volatile float regs[32];

    __asm__ volatile ("fstmias %[regs], {s0-s31}\n\t" : : [regs] "r" (regs));

    printf(
        "s0  = %10g s1  = %10g s2  = %10g s3  = %10g\n"
        "s4  = %10g s5  = %10g s6  = %10g s7  = %10g\n"
        "s8  = %10g s9  = %10g s10 = %10g s11 = %10g\n"
        "s12 = %10g s13 = %10g s14 = %10g s15 = %10g\n"
        "s16 = %10g s17 = %10g s18 = %10g s19 = %10g\n"
        "s20 = %10g s21 = %10g s22 = %10g s23 = %10g\n"
        "s24 = %10g s25 = %10g s26 = %10g s27 = %10g\n"
        "s28 = %10g s29 = %10g s30 = %10g s31 = %10g\n",
        regs[ 0], regs[ 1], regs[ 2], regs[ 3],
        regs[ 4], regs[ 5], regs[ 6], regs[ 7],
        regs[ 8], regs[ 9], regs[10], regs[11],
        regs[12], regs[13], regs[14], regs[15],
        regs[16], regs[17], regs[18], regs[19],
        regs[20], regs[21], regs[22], regs[23],
        regs[24], regs[25], regs[26], regs[27],
        regs[28], regs[29], regs[30], regs[31]
    );

    __asm__ volatile ("fldmias %[regs], {s0-s31}\n\t" : : [regs] "r" (regs));
}

You'll need to drop a call to _dumpvfps() somewhere (say, in main()) to keep the linker from stripping out the unused function. (The noinline attribute prevents that reference from being inlined away as well.) Now you can call this function from gdb any time you need to see the register state:

(gdb) call _dumpvfps()
s0  =          0 s1  =          0 s2  =          0 s3  =          0
s4  =          0 s5  =          0 s6  =          0 s7  =          0
s8  =          0 s9  =          0 s10 =          0 s11 =        176
s12 =          0 s13 =    3.16406 s14 =        nan s15 =        0.7
s16 =          0 s17 =          0 s18 =          0 s19 =          0
s20 =          0 s21 =          0 s22 =          0 s23 =          0
s24 =          0 s25 =          0 s26 =          0 s27 =          0
s28 =          0 s29 =          0 s30 =          0 s31 =          0


Archives
© 2012 Durian Software. | Contact Us