随笔-常用记录-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输出语句复制粘贴执行
dprintf
dprintf locspec,template,expression[,expression…] # locspec 具体行号或者函数
修改变量的值
set var foo=1
more
https://www.cnblogs.com/TechNomad/category/2371473.html?page=1
本文来自博客园,作者:LiYanbin,转载请注明原文链接:https://www.cnblogs.com/stellar-liyanbin/p/18058331
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统