public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* How to print info of each function by running an executable (compiled with -g) in gdb?
@ 2016-10-01  5:12 Peng Yu
  2016-10-21 22:22 ` doark
  0 siblings, 1 reply; 2+ messages in thread
From: Peng Yu @ 2016-10-01  5:12 UTC (permalink / raw)
  To: gdb

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?

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to print info of each function by running an executable (compiled with -g) in gdb?
  2016-10-01  5:12 How to print info of each function by running an executable (compiled with -g) in gdb? Peng Yu
@ 2016-10-21 22:22 ` doark
  0 siblings, 0 replies; 2+ messages in thread
From: doark @ 2016-10-21 22:22 UTC (permalink / raw)
  To: gdb; +Cc: pengyu.ut

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-10-21 22:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-01  5:12 How to print info of each function by running an executable (compiled with -g) in gdb? Peng Yu
2016-10-21 22:22 ` doark

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).