打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
GDB调试Release版ELF文件
看到file的结果为not stripped,这里千万别strip。如果strip了所有的符号段都没了,就不要调试了,调试起来也很难。

接着运行gdb:

进入layou asm模式(《Debugging with gdb》的解释为:Display the assembly window only.):

在使用GDB调试Release文件时可能会用到的命令:
nexti
nexti arg
ni Execute one machine instruction, but if it is a function call, proceed until the
function returns.
An argument is a repeat count, as in next.

stepi
stepi arg
si Execute one machine instruction, then stop and return to the debugger.
It is often useful to do ‘display/i $pc’ when stepping by machine instructions.
This makes gdb automatically display the next instruction to be executed, each
time your program stops. See Section 10.7 [Automatic Display], page 111.
An argument is a repeat count, as in step.

info registers
Print the names and values of all registers except floating-point and vector
registers (in the selected stack frame).

info all-registers
Print the names and values of all registers, including floating-point and vector
registers (in the selected stack frame).

info registers regname ...
Print the relativized value of each specified register regname. As discussed in
detail below, register values are normally relative to the selected stack frame.
regname may be any register name valid on the machine you are using, with or
without the initial ‘$’.

x addr
x Use the x command to examine memory.

set var
Evaluate expression EXP and assign result to variable VAR, using assignment
syntax appropriate for the current language (VAR = EXP or VAR := EXP for
example).  VAR may be a debugger "convenience" variable (names starting
with $), a register (a few standard names starting with $), or an actual
variable in the program being debugged.  EXP is any valid expression.
This may usually be abbreviated to simply "set".参见(17.1 Assignment to Variables)

要想真正的调试,还必须了解AT&T汇编。AT&T汇编与英特尔汇编最大的区别就是操作数的顺序。(如果有人有AT&T汇编的电子书麻烦请传我一份)
需要按照逻辑关系将汇编代码与C代码相对应之后再去调试。可以试着将上面的C代码与汇编代码对应一下试试调试。

另:提供一种简单的方法来调试Release文件,这种方法的缺点在于你必须有ELF文件的源代码。
1、objcopy --only-keep-debug projectD projectsymbol.dbg #生成符号表;
2、gdb -q --symbol=projectsymbol.dbg -exec=projectR #加载符号表;
3、跟平常调试带debug段的elf一样了。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
GDB调试release程序
关于Release 断点单步调试。
release版本和debug版本调试结果不一样
配置内核调试日志
3-Simple Executive Debugger SE调试器
Openocd 安装并在Eclipse环境下通过J-Link调试
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服