Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Mezz

debug - tracking function calls

This topic is 6011 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m interested in tracing calls through a program''s execution - for debugging purposes (C/C++). For example, if I''m in WinMain() then go into SetupRender() and then SetFOV(), and an error occurs in SetFOV() I''d like to error with a string of maybe "SetFOV->SetupRender->WinMain" (obviously there would be the actual error details as well, but its the function track I''m interested in right now). So, is there an efficient/easy way to accomplish this, possibly without having to manually add something to every function I write? Also, I''d only be doing this on debug builds but I guess that could be overcome by #ifdefs and the appropriate redefinitions. Thanks. -Mezz

Share this post


Link to post
Share on other sites
Advertisement
That''s called a stack. One thing you can do is make a linked list, like so.
  
class Node
{
public:
Node()
{
next=NULL;
last=NULL;
}
Node *next;
Node *last;
char functionName[100];
}


Then create functions to add nodes and delete nodes. Call an addnode function at the start of each function, and an remover at the end.

  
int Foo()
{
globalList->AddNode("Foo");
//blah blah blah

globalList->RemoveNode("Foo");
}


Then to print out the stack, you would do something like this. I used cout for simplicity here.

GetStackCout(Node* list)
{
Node* current = list;
while(current!=NULL)
{
cout << "->" << current->functionName;
current = current->next;
}
}

Tada, a printed stack list of all the functions you have gone in, in the order you entered them. The add function would just go the the last node in the list and dynamically allocate a new one. Simple enough.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"

Share this post


Link to post
Share on other sites
You could make it so if something like WRITE_STACK was defined, it saved the stack info to a file on entering each function. It would be slow, but then again it would also be only used during a debug session, right? Otherwise, a standard debug would lead you to the source of the infinite loop, so there would be no real need to use the stack info for that one. The stack info is more likely to be used when an assert fails or something. Anyway, I gotta go now. So I can''t answer anything for a while.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"

Share this post


Link to post
Share on other sites
Thanks for the replies.

MonkeyChuff: I know - but somebody (i.e. a tester) who is running a debug build and doesn''t have the compiler, doesn''t get such a window.

ATronic: You''re solution is viable, but I was looking for something that perhaps didn''t require manually adding a log line of the entry/exit of the function.

You''ve also hit it home with the assert() failure - that is what I intend to use this for.

-Mezz

Share this post


Link to post
Share on other sites
I''m afraid you may need to put entry exit point declarations. It''s not such a big deal really, fairly easy. Why don''t you want to?

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"

Share this post


Link to post
Share on other sites
It isn''t really that I don''t want to, I just thought there must be some kind of approach that provides such functionality - I mean I''d like to pretend I understand the StackWalk() function but I don''t.

-Mezz

Share this post


Link to post
Share on other sites
StackWalk?

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"

Share this post


Link to post
Share on other sites
Yes there is a function called StackWalk() - it''s in MSDN if you search for it.

As I said, I don''t understand it a great deal but I think it can be used for tracing. Maybe.

-Mezz

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!