MetallicPriest
MetallicPriest

Reputation: 30765

Trace application compiled by gcc

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

Answers (3)

A.M.M
A.M.M

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

ninjalj
ninjalj

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

Pablo Santa Cruz
Pablo Santa Cruz

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

Related Questions