Re: How to print info of each function by running an executable (compiled with -g) in gdb?

[email protected]
Newsgroups gmane.comp.gdb.devel
Message-ID <20161020235720.0f3ef16a@ulgy_thing>
Hope this is not too late, I've been catching up on my mail.

On Sat, 1 Oct 2016 00:11:58 Peng Yu <[email protected]> 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;
done

To undo:

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

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)!

Sincerely,
David
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.