Author |
Topic: Stack Trace Information (Read 923 times) |
|
nks
Junior Member
 


Gender: 
Posts: 145
|
 |
Stack Trace Information
« on: Aug 11th, 2010, 7:53am » |
Quote Modify
|
How can I find stack trace info without using any system function? Ex f1(){ .. f2(); } f2(){ f3(); } When we say f3.It should track f3->f2->f1.
|
« Last Edit: Aug 11th, 2010, 7:54am by nks » |
IP Logged |
|
|
|
Grimbal
wu::riddles Moderator Uberpuzzler
    

Gender: 
Posts: 7527
|
 |
Re: Stack Trace Information
« Reply #1 on: Aug 11th, 2010, 9:13am » |
Quote Modify
|
In what language? If f3() is a function, what is f3.It?
|
|
IP Logged |
|
|
|
nks
Junior Member
 


Gender: 
Posts: 145
|
 |
Re: Stack Trace Information
« Reply #2 on: Aug 11th, 2010, 10:19am » |
Quote Modify
|
In C/C++. f3() is also a function called in f2().
|
|
IP Logged |
|
|
|
towr
wu::riddles Moderator Uberpuzzler
    
 Some people are average, some are just mean.
Gender: 
Posts: 13730
|
 |
Re: Stack Trace Information
« Reply #3 on: Aug 11th, 2010, 10:53am » |
Quote Modify
|
You could make a global stack and have every function push its name on when it is called, and have them take it off when they're done. Or you could do something incredibly dirty like trying to read the function stack, by working down from the address of the parameters or something.
|
|
IP Logged |
Wikipedia, Google, Mathworld, Integer sequence DB
|
|
|
Grimbal
wu::riddles Moderator Uberpuzzler
    

Gender: 
Posts: 7527
|
 |
Re: Stack Trace Information
« Reply #4 on: Aug 11th, 2010, 2:58pm » |
Quote Modify
|
Do you mean to call the "show stack" function from within the call to f3, in which case I second towr's propositions, or do you mean to call f3 as an argument? In that case it is a matter of analyzing the source code and finding call references, which may not be unique.
|
|
IP Logged |
|
|
|
nks
Junior Member
 


Gender: 
Posts: 145
|
 |
Re: Stack Trace Information
« Reply #5 on: Aug 11th, 2010, 6:42pm » |
Quote Modify
|
Quote:You could make a global stack and have every function push its name on when it is called |
| You mean I need to push the function name in stack before calling the function? In that way I need to modify the existing function. Is there any way I can do it without modification of existing function?
|
« Last Edit: Aug 11th, 2010, 6:45pm by nks » |
IP Logged |
|
|
|
Grimbal
wu::riddles Moderator Uberpuzzler
    

Gender: 
Posts: 7527
|
 |
Re: Stack Trace Information
« Reply #6 on: Aug 12th, 2010, 1:06am » |
Quote Modify
|
But are you willing to modify f3? You could run your program in a debugger, you can then set a breakpoint in f3, it will display the stack trace. In java there is a library function that returns the stack trace. I guess such a library exists in C/C++. It could do so without calling the OS, since all necessary data is on the stack. So it wouldn't be a system call. What is the context? What is it you are trying to do?
|
|
IP Logged |
|
|
|
nks
Junior Member
 


Gender: 
Posts: 145
|
 |
Re: Stack Trace Information
« Reply #7 on: Aug 16th, 2010, 5:47pm » |
Quote Modify
|
Sorry for late reply. Quote:But are you willing to modify f3? |
| No. Existing function is not supposed to modify. Yes there is function stacktrace() in c/c+. But All the compiler may not have this. Quote:What is the context? What is it you are trying to do? |
| I m wriying plugin which maintains the execution path in server.
|
|
IP Logged |
|
|
|
Grimbal
wu::riddles Moderator Uberpuzzler
    

Gender: 
Posts: 7527
|
 |
Re: Stack Trace Information
« Reply #8 on: Aug 20th, 2010, 7:07am » |
Quote Modify
|
If you are worrying stacktrace() might not be available everywhere, that means you want it portable. But your only chance to make it portable is to have the compiler or the runtime library get the information for you.
|
|
IP Logged |
|
|
|
|