This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: How to print info of each function by running an executable (compiled with -g) in gdb?
- From: doark at mail dot com
- To: gdb at sourceware dot org
- Cc: pengyu dot ut at gmail dot com
- Date: Thu, 20 Oct 2016 23:57:20 -0400
- Subject: Re: How to print info of each function by running an executable (compiled with -g) in gdb?
- Authentication-results: sourceware.org; auth=none
- References: <CABrM6w=eLY+eoeQZLtSfPAB2q7Rxc20aHvTwv1gurNeSs+S+Tg@mail.gmail.com>
Hope this is not too late, I've been catching up on my mail.
On Sat, 1 Oct 2016 00:11:58 Peng Yu <pengyu.ut@gmail.com> 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