Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ Programming
➜ General
➜ How do I find the call sequence?
|
How do I find the call sequence?
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Hrishikesh
(1 post) Bio
|
| Date
| Fri 11 May 2007 10:12 AM (UTC) |
| Message
| Hi,
I am trying to find the sequence in which the functions in a C++ code are getting called. I was wondering if I could use gdb for this.
I was thinking of putting a tracepoint at each function, and then just displaying or dumping the function name into a file would help.
But unfortunately, I was not able to do so.
Can someone plz help me out ?
Regards,
Hrishikesh | | Top |
|
| Posted by
| Conner
USA (381 posts) Bio
|
| Date
| Reply #1 on Fri 11 May 2007 09:44 PM (UTC) |
| Message
| | gdb is pretty powerful and probably could do it, though I wouldn't know how to do such a thing in gdb myself. Might I ssuggest that it'd probably be easier just to create a log file and add a line in each function to output to the log when the function runs? |
-=Conner=-
--
Come test your mettle in the Land of Legends at telnet://tcdbbs.zapto.org:4000
or, for a little family oriented medieval fun, come join us at The Castle's Dungeon BBS at telnet://tcdbbs.zapto.org
or, if you just want information about either, check our web page at http://tcdbbs.zapto.org | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #2 on Fri 11 May 2007 10:26 PM (UTC) |
| Message
| If you put a breakpoint on a function at the bottom of the chain, and then do a "bt" (backtrace) you will see the sequence of nested calls that got you there.
If you just want to see when functions are being called in general, I don't think there is a particularly easy way.
One method could be to make a small helper function like this one:
http://www.gammon.com.au/forum/bbshowpost.php?id=2998
Then you could put (in the source code) at the start of each function a line that shows that function is being called. Once you have debugged you could "define" it to do nothing.
Here is an example that shows what I mean:
#include <iostream>
#include <string>
void fname (const std::string s)
{
std::cout << "Entering function: " << s << std::endl;
}
void bar ()
{
fname ("bar");
}
void foo ()
{
fname ("foo");
bar ();
}
int main ()
{
std::cout << "Program starting" << std::endl;
foo ();
return 0;
}
Output
Program starting
Entering function: foo
Entering function: bar
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
16,576 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top