随笔-常用记录-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 Convenience Functions

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

posted @   LiYanbin  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
点击右上角即可分享
微信分享提示