This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

problem with unwinding stack on mips when syscall is involved


Sometimes, when there is a syscall involved, which is manipulating
stack pointer before call itself, gdb can't unwind the stack properly.
It appears, that GDB is ignoring the "addiu   sp,sp,-32" before
syscall, and because of that unwinding produces incorrect results.
The libc.so is in fact uClibc version 0.9.28 (if this is somehow relevant).
I can reproduce it on 6.8 and 7.0 as well.

Example:
(gdb) thread 4
[Switching to thread 4 (process 511)]#0  0x2ae95c58 in select () from
./lib/libc.so.0
(gdb) bt
#0  0x2ae95c58 in select () from ./lib/libc.so.0
#1  0x00000000 in ?? ()
(gdb) info reg
          zero       at       v0       v1       a0       a1       a2       a3
 R0   00000000 80150710 0000102e 00000000 000000c5 759ffc20 00000000 00000000
            t0       t1       t2       t3       t4       t5       t6       t7
 R8   0000fd00 85fdef60 00000000 00004000 00000000 10003264 00000000 10006f58
            s0       s1       s2       s3       s4       s5       s6       s7
 R16  001ff000 00000000 00017051 00000000 2ab39330 75801000 00000000 2ab39850
            t8       t9       k0       k1       gp       sp       s8       ra
 R24  00000000 2ae95c20 00000000 00000000 2aee94b0 759ffb38 00200000 2e326c60
            sr       lo       hi      bad    cause       pc
      0000fd13 00000058 00000000 7ffe7b6e 10800020 2ae95c58
           fsr      fir      hi1      lo1      hi2      lo2      hi3      lo3
      00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
        dspctl
      00000000
(gdb) disassemble 0x2ae95c58
Dump of assembler code for function select:
0x2ae95c20 <select+0>:  lui     gp,0x5
0x2ae95c24 <select+4>:  addiu   gp,gp,14480
0x2ae95c28 <select+8>:  addu    gp,gp,t9
0x2ae95c2c <select+12>: addiu   sp,sp,-40
0x2ae95c30 <select+16>: sw      ra,36(sp)
0x2ae95c34 <select+20>: sw      s0,32(sp)
0x2ae95c38 <select+24>: sw      gp,16(sp)
0x2ae95c3c <select+28>: lw      v0,56(sp)
0x2ae95c40 <select+32>: sw      v0,24(sp)
0x2ae95c44 <select+36>: lw      v0,24(sp)
0x2ae95c48 <select+40>: addiu   sp,sp,-32
0x2ae95c4c <select+44>: sw      v0,16(sp)
0x2ae95c50 <select+48>: li      v0,4142
0x2ae95c54 <select+52>: syscall
0x2ae95c58 <select+56>: addiu   sp,sp,32
0x2ae95c5c <select+60>: lw      t9,-32352(gp)
0x2ae95c60 <select+64>: beqz    a3,0x2ae95c7c <select+92>
0x2ae95c64 <select+68>: move    s0,v0
0x2ae95c68 <select+72>: jalr    t9
0x2ae95c6c <select+76>: nop
0x2ae95c70 <select+80>: lw      gp,16(sp)
0x2ae95c74 <select+84>: sw      s0,0(v0)
0x2ae95c78 <select+88>: li      v0,-1
0x2ae95c7c <select+92>: lw      ra,36(sp)
0x2ae95c80 <select+96>: lw      s0,32(sp)
0x2ae95c84 <select+100>:        jr      ra
0x2ae95c88 <select+104>:        addiu   sp,sp,40
0x2ae95c8c <select+108>:        nop
End of assembler dump.

(gdb) x/1x $sp+32+36
0x759ffb7c:     0x2e326c60
(gdb) x/1x $sp+36
0x759ffb5c:     0x00000000
(gdb) p/x $ra
$3 = 0x2e326c60


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]