How to print info of each function by running an executable (compiled with -g) in gdb?
Fri Oct 21 22:22:00 GMT 2016

Hope this is not too late, I've been catching up on my mail.

On Sat, 1 Oct 2016 00:11:58 Peng Yu <> wrote:
> Hi, I am currently inserting the following line into functions for
> which I want to print the function info. However, this can be tedious
> if the source code is large.
> fprintf(stderr, "%s:%d:%s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
> Is there a way to automatically print the information of each function
> being called using gdb?

Don't know, but you can do (in the shell, and you
will need moreutils and gawk (gnu awk)):

for i in SOURCE; do
    gawk '{ if($0 ~ /^{/){ printf("{\n    fprintf(stderr, "
    "\"%%s:%%d:%%s\n\", __FILE__, __LINE__, __PRETTY_FUNCTION__);\n");
    } else { print $0; } }' $i | sponge $i;

To undo:

for i in SOURCE; do
    grep -v 'fprintf(stderr, "%s:%d:%s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);' $i | sponge $i;

I've done similar things before, it's simple if you've formatted
your code nicely (and put your unions and structs in your headers)!


More information about the Gdb mailing list