随笔-常用记录-开发-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 条件断点

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

more

https://www.cnblogs.com/TechNomad/category/2371473.html?page=1

posted @ 2024-03-07 10:27  LiYanbin  阅读(3)  评论(0编辑  收藏  举报