我如何让GDB自动多次调用给定的函数? [英] How do I make GDB call a given function several times automatically?

查看:172
本文介绍了我如何让GDB自动多次调用给定的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让GDB自动调用一个给定的函数很多次,比如说100.有没有任何命令可以让我这样做?

I'd like to make GDB call a given function a large number of times automatically, say 100. Is there any command that will let me do that?

推荐答案

将这个示例脚本保存到一个文件中,比如my_gdb_extensions

Save this example script into a file say my_gdb_extensions

define fcall_n_times
 set $count = $arg0
 set $i=0
 while($i < $arg0)
  call $arg1
  set $i = $i + 1
 end
end

你可以找到更多关于gdb扩展的信息 here。

You can find more about gdb extensions here.

$ gdb -x my_gdb_extensions <your_bin>
(gdb) start
(gdb) fcall_n_times 10 fact(3)

在上面提到的例子中, 10 是你想调用函数的次数。 fact(3)是参数为3的函数名称。

In the mentioned example 10 is the number of times you want to call the function. fact(3) is the function name with argument as 3.

这篇关于我如何让GDB自动多次调用给定的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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