Reputation: 30765
I want to trace an application compiled by gcc. By tracing, I mean I want to the see address of every instruction executed. What is the easiest way to achieve this?
Upvotes: 0
Views: 1777
Reputation: 227
I think you could try this
strace -i program_name
Note: this will print only system calls called from the desired program.
Upvotes: 0
Reputation: 43688
Using gdb, you could turn on logging:
set logging file my_log_filename.log
set logging on
and write a recursive step macro:
define s
stepi
s
end
Using ptrace, just ptrace(PTRACE_SINGLESTEP...)
until the tracee ends or gets a signal.
Upvotes: 0
Reputation: 181280
Your best bet is using GDB, of course.
Compile your code:
$ gcc -Wall m.c -o m
Trace it with gdb:
$ gdb m
> b main
> r
GDB will break on your entry function: main
.
If this kind of trace is not good for you, try using strace
on linux, or dtrace
on Solaris, BSD or Mac OS X.
Upvotes: 2