Get gdb call stack

Sometimes GDB cannot parse the call stack correctly, and the call stack in gdb shows as:

(gdb) bt

0 0xb7f33410 in ?? ()
1 0xa89793a8 in ?? ()
2 0x00000002 in ?? ()
3 0x00000000 in ?? ()

since the call stack can be re-calculated by the stack frame, so if we can get the correct %ebp(frame pointer) reigster values, then we can get the call stack easily.

The ebp saves the current bottom of stack frame, and we know, when a function is invoked, the return address will be pushed into stack, and then the current ebp will be pushed, typical code as:

The code:

func(params);
means:
push eip;
jmp @func
push %ebp // save previous frame pointer
mov %esp, %ebp // save current frame pointer
...

So we can say, the pointer of %ebp is the last frame pointer, and the %ebp + 1 is the return address, then we can recursively get the address of each function call, and with "info symbol" to get each function's symbol information.

An example:

(gdb) bt

0 0xb7f33410 in ?? ()
1 0xa89793a8 in ?? ()
2 0x00000002 in ?? ()
3 0x00000000 in ?? ()
(gdb) x/10 $ebp
0xa89793a8:    0xa89793c8    0x08078734    0x0827e9e4    0x00000000
0xa89793b8:    0x00000000    0x00000000    0x00000000    0x00000000
0xa89793c8:    0xa89793e8    0x0806d1b1

(gdb) info symbol 0x08078734
IMSS::PsMutex::lock() + 18 in section .text

(gdb) x/10 0xa89793c8
0xa89793c8:    0xa89793e8    0x0806d1b1    0x0827e9e0    0x00000000
0xa89793d8:    0x00000000    0x00000000    0x00000000    0x0827e9e0
0xa89793e8:    0xa8979418    0x08077f3f

(gdb) info symbol 0x0806d1b1
IMSS::PsMutexLock::privateLock() + 35 in section .text

(gdb) x/10 0xa89793e8
0xa89793e8:    0xa8979418    0x08077f3f    0xa8979400    0x080a338c
0xa89793f8:    0xa8979418    0x08075d59    0x0827e9e0    0x00000001
0xa8979408:    0x00000001    0x00000000

(gdb) info symbol 0x08077f3f
SOAPRequestSocket::Accept(soap*&) + 41 in section .text

(gdb) x/10 0xa8979418
0xa8979418:    0xa8979438    0x08075c1c    0x0827e9e0    0x0829e8c8
0xa8979428:    0x00000019    0x00000000    0x00000000    0x0829e8b8
0xa8979438:    0xa8979458    0xb73dd797

(gdb) info symbol 0x08075c1c
PolicyRequestHandler::main() + 146 in section .text

Then we can get the call stack is:

IMSS::PsMutex::lock() + 18 in section .text

IMSS::PsMutexLock::privateLock() + 35 in section .text
SOAPRequestSocket::Accept(soap*&) + 41 in section .text
PolicyRequestHandler::main() + 146 in section .text

- END -

 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值