// sample.c
#include "sample.h"
struct sample foo; //把所有有用的struct都放进来!
gcc -g -c sample.c
(gdb) add-symbol-file sample.o 0
add symbol table from file "sample.o" at .text_addr = 0x0
(gdb) p (struct sample *)0x7fffffffd6b0
$1 = (struct sample *) 0x7fffffffd6b0
(gdb) p *$1
$2 = {i = 42, less = 0x7fffffffd6b0, more = 0x7fffffffd6b0}
1
2
3
4
5
6
7
8
9
10
连续打印链表
In GDB, the value of $ is the value returned from the previous command.
(gdb) p mgmt_thread_data.next_thread
$67 = (struct k_thread *) 0x2000188c
(gdb) p $.next_thread
$68 = (struct k_thread *) 0x200022ac
(gdb)
$69 = (struct k_thread *) 0x2000a120
需求:回到刚刚运行的代码再执行一遍
This is yet another use case for Reverse Debugging.
1. You should start process record and replay at some point:
(gdb) record
2. When you want to see last executed lines you can go backwards like this:
(gdb) reverse-step 3
1
2
3
4
5
6
反汇编
(gdb) disass 函数
(gdb) layout asm
1
2
列出信号处理函数
有时想知道当前怎么处理信号的,又不想从代码里找,有个gdb脚本可以用
http://palves.net/list-active-signal-handlers-with-gdb/
(gdb) info signal-dispositions 2 5
Number Name Description Disposition
2 SIGINT Interrupt rl_signal_handler in section .text of build/gdb/gdb
5 SIGTRAP Trace/breakpoint trap SIG_DFL