如何在 GDB 中自动打印下 N 个执行的行? [英] How to print the next N executed lines automatically in GDB?

查看:15
本文介绍了如何在 GDB 中自动打印下 N 个执行的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我一直在尝试寻找一种方法来自动化 GDB 中跟踪程序控制流的进度.

I have been trying to find a way for some time to automate the progress in GDB of tracing the control flow of a program.

甚至只是自动化 n 命令的简单方法,这样您就可以看到例程被调用的顺序.

Even just a simple way of automating the n command so you can see in what order routines are called.

我知道你可以发出 n x 其中 x 是 GDB 执行的次数,但问题是它显示的是命令而不是例程的地址!但是如果你在 GDB 中手动按 n (然后按回车键发出上一个命令)它会显示地址.

I realise that you can issues n x where x is the number of times GDB steps through, but the trouble with that is that it shows the command but not the address of the routine! But if you press n manually in GDB (then press return to issue the previous command) it shows the address.

我在 GDB 中尝试了以下方法:

I have tried the following in GDB:

(after setting a breakpoint at say 0x0123456)
b *0x0123456

GDB 说 .我输入:

GDB says <breakpoint 1 at 0x123456>. I type:

commands 1
n 1000
c
end

但它没有按预期循环,也没有显示地址位置 :-(.

but it doesn't loop as expected, and it doesn't show the address location :-(.

任何帮助将不胜感激!自动记录调用的顺序例程肯定很简单吗??

Any help would be appreciated! Surely it must be simple to automatically log the order routines are called??

推荐答案

其实这很简单.我会给你最基本的,你可以修改以适应.

This is easy, actually. I'll give you the bare bones, and you can modify to suit.

(gdb) define nstep
> set $foo = $arg0
> while ($foo--)
>  step
>  end
> end
(gdb) nstep 100

我已经做过很多次了.希望这会有所帮助!

I've done this many times. Hope this helps!

这篇关于如何在 GDB 中自动打印下 N 个执行的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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