1. 官网
https://www.sourceware.org/gdb/documentation/
参数:
-
-quiet -silent -q
“Quiet”. Do not print the introductory and copyright messages. These messages are also suppressed in batch mode.
This can also be enabled using set startup-quietly on. The default is
off. Use show startup-quietly to see the current setting. Place set
startup-quietly on into your early initialization file (see Section 2.1.4
[Initialization Files], page 17) to have future gdb sessions startup quietly. -
-batch
Run in batch mode. Exit with status 0 after processing all the command files
specified with ‘-x’ (and all commands from initialization files, if not inhibited
with ‘-n’). Exit with nonzero status if an error occurs in executing the gdb
commands in the command files. Batch mode also disables pagination, sets unlimited terminal width and height see Section 22.4 [Screen Size], page 360, and acts as if set confirm off were in effect (see Section 22.9 [Messages/Warnings], page 371).
Batch mode may be useful for running gdb as a filter, for example to download
and run a program on another computer; in order to make this more useful, the message Program exited normally.
(which is ordinarily issued whenever a program running under gdb control
terminates) is not issued when running in batch mode. -
-ex command
Execute a single gdb command.
This option may be used multiple times to call multiple commands. It may also
be interleaved with ‘-command’ as required.
gdb -ex ’target sim’ -ex ’load’ \
-x setbreakpoints -ex ’run’ a.out
2. 不阻塞调试
gdb -quiet -batch -ex='call func()' -p `pidof xxx`
3. x命令
在没有符号表的情况下,查看结构体的数据
gdb -quiet -batch -ex='x/128db &stdata' -p `pidof xxx`
d:十进制
b:字节
以十进制打印128个字节
4. 反汇编
使用场景示例:想获取或修改静态变量的值,但是没有相关接口gdb调用的时候,可以反汇编相关接口看看能不能算出静态变量的地址,然后进行操作。不过计算不对的话会有风险。
gdb -quiet -batch -ex='disassemble functionxxx' -p `pidof processxxx`
问题
1. gdb调用返回类型为long long的函数
现象:在设备上调试,有符号表时,返回值正确;没符号表时,始终返回0。
定位:在服务器上写了demo测试没这个问题,具体原因未知,可能设备与服务器上的gdb版本不一致。
shell# ls
test_proc.sym
shell# gdb -quiet -batch -ex='call (long long)test_func()' -p `pidof test_proc`
$1 = 11083
shell# gdb -quiet -batch -ex='call (long long)test_func()' -p `pidof test_proc`
$1 = 11181
shell# mv test_proc.sym test_proc.symbak
shell# gdb -quiet -batch -ex='call (long long)test_func()' -p `pidof test_proc`
$1 = 0
shell# gdb -quiet -batch -ex='call (long long)test_func()' -p `pidof test_proc`
$1 = 0
待续…
文章介绍了如何使用GDB进行批处理调试,包括启动选项如-quiet,-batch,-ex等,并展示了在无符号表情况下查看结构体数据和反汇编代码的方法。同时,文章提出了一个调试问题,即在设备上缺少符号表时,调用返回类型为longlong的函数会返回0,而在服务器上没有此问题,可能是由于GDB版本差异导致。

401

被折叠的 条评论
为什么被折叠?



