gdb支持程序反向执行。
record 让程序开始记录反向调试所必要的信息
rn : reverse next
rc: reverse continue ,Continue program being debugged but run it in reverse
record stop: 停止记录
GDB调试C程序时,默认情况下输出很不直观,看起来很费劲.
set print pretty on
https://github.com/google/sanitizers/wiki/AddressSanitizerAndDebugger
b __asan::ReportGenericError
p __asan_describe_address(0x7ffff73c3f80)
设置条件断点:
cond 1 $rdi==0x0 //在断点一设置条件断点
b 57 if $rdi==0x0 //在当前文件的57行设置条件断点
有时候你会发现条件断点没有生效,我的解决方案是,先单步运行(n)几行,在运行c.
Greg 在他的blog中也提到过这个问题:http://www.brendangregg.com/blog/2016-08-09/gdb-example-ncurses.html
上例中在断点1设置command, 先打印堆栈,再continue, 你会发现gdb 还是会被自动阻塞住。
你需要在gdb的配置文件.gdbinit中添加 set height 0, 会自动避免阻塞问题
Print definition of type TYPE. 可以显示类型的定义。
有个重要参数: \o
/o print offsets and sizes of fields in a struct (like pahole)
struct tuv
{
int a1;
char *a2;
int a3;
};
(gdb) ptype /o struct tuv
/* offset | size */ type = struct tuv {
/* 0 | 4 */ int a1;
/* XXX 4-byte hole */
/* 8 | 8 */ char *a2;
/* 16 | 4 */ int a3;
/* total size (bytes): 24 */
}
Notice the format of the first column of comments. There, you
can find two parts separated by the ‘|’ character: the offset, which
indicates where the field is located inside the struct, in bytes, and
the size of the field. Another interesting line is the marker of a hole
in the struct, indicating that it may be possible to pack the struct
and make it use less space by reorganizing its fields.
修改code后,重新build。
gdb无须退出,在gdb中运行 file a.out 命令,新编译的a.out会自动加载到gdb。
info threads
thread 1
set scheduler-locking on/off/step
set schedule-multiple on/off
thead apply all bt
thead apply 1 bt