2

Is there a way to attach a print statement to the call of a function? I would like to debug a x64 program with nested loops and logic and it would be faster to see the sequence of function calls by printing them as they occur, rather than setting breakpoints.

Can this be done with a post hook in gdb or a different technique?

1 Answer 1

2

Is there a way to attach a print statement to the call of a function?

Yes: attach a breakpoint to every function you want to trace, and attach commands to each of these breakpoints:

(gdb) break foo
(gdb) commands $bpnum
continue
end

Now every time foo is called, GDB will print the usual "Breakpoint N ..." message, and then continue.

Obviously you could print additional info (argument values, call stack, thread-id, etc.).

You will probably want to set height 0 to disable pagination. You will also probably want to log this to a file (see set logging file, set logging on, etc.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.