随笔-gdb-常用记录
目录
TODO:
[100-gdb-tips](https://wizardforcel.gitbooks.io/100-gdb-tips)
gdb 带参数
gdb -iex 'set pagination off' -iex 'set confirm off' -iex 'set print elements 0' -ex 'set print thread-events off' -ex 'handle SIGPIPE nostop noprint pass' --args exec_path arg1 arg2
gdb attach
xpid=$(pidof exec_name);gdb -iex 'set pagination off' -iex 'set confirm off' -iex 'set print elements 0' -ex 'set print thread-events off' -ex 'handle SIGPIPE nostop noprint pass' attach -p $xpid
gdb 调试LD_PRELOAD
gdb -iex 'set pagination off' -iex 'set print elements 0' -ex 'set print thread-events off' -ex 'handle SIGPIPE nostop noprint pass' -ex 'set exec-wrapper env LD_PRELOAD=/root/libvsuremem.so' --arg ...
gdb 条件断点
gdb 条件断点 字符串比较 $_streq() 或者正则匹配$_regex
gdb 打印$pid进程所有线程的堆栈并退出
gdb -ex "set pagination 0" -ex "thread apply all bt" -batch -p $pid # 或者使用pstack
gdb 打印内存数据
x /4cb $rbp-0x28 #打印4个字节
x /w $rbp-0x30 #打印Words (four bytes). This is the initial default.
参考: https://sourceware.org/gdb/current/onlinedocs/gdb.html/Memory.html
gdb 设置调试中间变量
set $foo=(xxxtype*)0xffff1234
使用的时候也要带$
gdb ctrl-c无法退出
xpid=$(pidof app);kill -TRAP $xpid
gdb 设置断点提示Function "xxx" not defined.
https://cloud.tencent.com/developer/ask/sof/115981075/answer/137881530
gdb call调用函数提示"has unknown return type; cast the call to its declared return type"
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Calling.html
(gdb) p getenv ("PATH")
'getenv' has unknown return type; cast the callto its declared return type
(gdb) p (char *) getenv ("PATH")
$1 = 0x7fffffffe7ba "/usr/local/bin:/"...
死锁调试
https://www.cnblogs.com/TechNomad/p/17986978
watch char
break xx.c:4944
commands
printf "watch *(char*)(%p)\n",string
end
然后将gdb输出语句复制粘贴执行
watch void*
printf "watch *(void**)%p\n",&(...)
dprintf
dprintf locspec,template,expression[,expression…] # locspec 具体行号或者函数
修改变量的值
set var foo=1
查看汇编代码
(gdb) disassemble
more
https://www.cnblogs.com/TechNomad/category/2371473.html?page=1
本文来自博客园,作者:LiYanbin,转载请注明原文链接:https://www.cnblogs.com/stellar-liyanbin/p/18058331