显示在gdb中执行的每个汇编指令 [英] Displaying each assembly instruction executed in gdb

查看:850
本文介绍了显示在gdb中执行的每个汇编指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个棘手的错误发生在我无法访问源代码或符号的地方,也就是说我可以看到发生崩溃的指令和地址,但这就是它。 我想要做的是让 gdb 运行而不需要交互并显示每条指令,但我还没有找到一个方法来做到这一点。



我希望能达到的是这样的:

 (gdb)/ * some command * / 
0x2818a7c0:push%ebp
0x2818a7c1:mov%esp,%ebp
0x2818a7c3:push%ebx
0x2818a7c4:sub $ 0x4,%esp
...
0x28563622:mov%esi,0x0(%eax)
编程接收到的信号SIGSEGV,Segmentation fault。

我一直在为程序计数器设置一个显示器,如下所示:

 (gdb)display / i $ pc 

然后使用 stepi 执行代码:

 < code $(gdb)stepi 
1:x / i $ pc 0x2818a7c0:push%ebp


$ b $然而,崩溃是数百或数千条指令,我想要一种方式来看每一个(如果可以的话),而不必多次点击输入。另外,如果我要手动完成,我会在每条指令之间看到一个(gdb)提示符,这是不太理想的。



我简要介绍过的一条路线是脚本,但我唯一的想法是设置在 main(),让它显示并且另一个break(用于下一条指令),然后继续,但是我不能在命令块中使用命令,所以它不会按照我想象的方式工作。



如果有问题,我正在使用FreeBSD。

解决方案

以下内容应该符合您的要求:

 #并非严格要求,但你可能会想要日志
(gdb)设置日志记录

#请求gdb不停止每个屏幕 - 完整
(gdb)设置高度0

(gdb)while 1
> x / i $ pc
> stepi
> end

然而,这种调试方法可能会失败:只有太多指令,即使是在大多数微不足道的程序中也是如此。

更好的方法是运行程序直到崩溃,尝试理解当前函数在做什么以及调用它,并适当地设置断点。

在x86上,即使在完全剥离的可执行文件中,您也可以经常推断出函数边界。



另一件你要看的是 strace / truss 输出,所以你可以看到系统调用立即在崩溃点之前。


I currently have a tricky bug that occurs in a place where I don't have access to source or symbols, i.e. I can see the instruction and its address where the crash occurs, but that's about it. What I'd like to do is have gdb run without requiring interaction and display every instruction as it does so, but I've yet to find a way to do it.

What I'm hoping to achieve is something like this:

(gdb) /* some command */
0x2818a7c0: push   %ebp
0x2818a7c1: mov    %esp,%ebp
0x2818a7c3: push   %ebx
0x2818a7c4: sub    $0x4,%esp
...
0x28563622: mov    %esi,0x0(%eax)
Program received signal SIGSEGV, Segmentation fault.

What I've been doing is setting up a display for the program counter, like so:

(gdb) display/i $pc

And then running through the code with stepi:

(gdb) stepi
1: x/i $pc  0x2818a7c0: push   %ebp

However, the crash is hundreds or thousands of instructions away, and I'd like a way to see each one (together, if preferable), without having to hit "enter" that many times. Also, if I were to do it manually, I'd see a (gdb) prompt between each instruction, which is less than desirable.

One route I've briefly looked into is scripting, but my only thought is to setup at main(), have it display and another break (for the next instruction), and then continue, but then I can't use commands within a commands block, so it wouldn't work the way I'm imagining it.

In case it matters, I'm working on FreeBSD.

解决方案

The following should do what you asked for:

# not strictly required, but you'll likely want the log anyway
(gdb) set logging on

# ask gdb to not stop every screen-full
(gdb) set height 0

(gdb) while 1
 > x/i $pc
 > stepi
 > end

However, this approach to debugging will likely prove futile: there are simply too many instructions executed even in most trivial programs.

A better approach might be to run the program until crash, attempt to understand what current function is doing and who calls it, and setting breakpoints appropriately.

On x86, you can often deduce function boundaries even in fully stripped executable.

Another thing you'll want to look at is strace/truss output, so you can see what system calls immediately precede the crash point.

这篇关于显示在gdb中执行的每个汇编指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆