Is there a way to measure elapsed time running the program under gdb
?
Look to this:
<------------bp---------------------------------->
Assume that we are debugging a file and in some random place, we set a breakpoint. Now in gdb
we perform something and then we let the program continue the execution by using the gdb
command line (run
).
My question is here.
I want to measure the elapsed time from the bp until the program either successfully ends or some error occurs.
My suggestion is to use .gdbinit
file, and in that file we call some C function to start the timer after run
command and at the end of the execution we also call a gettime()
C fun.
So, my pseudo code is a bit like this (.gdbinit
file):
break *0x8048452 (random place)
//start time
run
//get time
Best Answer
The easiest way to do this (if your gdb has python support):
If your gdb doesn't have python support but can run shell commands, then use this:
Alternatively, you could make the target process call gettimeofday or clock_gettime, but that is a lot more tedious. These functions return the time by writing to variables in the process's address space, which you'd probably have to allocate by calling something like
malloc
, and that may not work if your breakpoint stopped the program in the middle of a call to anothermalloc
orfree
.