lindelof
lindelof

Reputation: 35240

How do I make GDB call a given function several times automatically?

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?

Upvotes: 0

Views: 794

Answers (1)

Kamath
Kamath

Reputation: 4664

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

You can find more about gdb extensions here.

$ gdb -x my_gdb_extensions <your_bin>
(gdb) start
(gdb) fcall_n_times 10 fact(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.

Upvotes: 2

Related Questions