From: doark@mail.com
To: gdb@sourceware.org
Cc: pengyu.ut@gmail.com
Subject: Re: How to print info of each function by running an executable (compiled with -g) in gdb?
Date: Fri, 21 Oct 2016 22:22:00 -0000 [thread overview]
Message-ID: <20161020235720.0f3ef16a@ulgy_thing> (raw)
In-Reply-To: <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
prev parent reply other threads:[~2016-10-21 22:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-01 5:12 Peng Yu
2016-10-21 22:22 ` doark [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161020235720.0f3ef16a@ulgy_thing \
--to=doark@mail.com \
--cc=gdb@sourceware.org \
--cc=pengyu.ut@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox