|function call stack walk/print function names firstname.lastname@example.org (2000-08-27)|
|Re: function call stack walk/print function names email@example.com (Graeme Roy) (2000-09-02)|
|Re: function call stack walk/print function names firstname.lastname@example.org (Martin Waller) (2000-09-08)|
|Date:||27 Aug 2000 22:47:41 -0400|
|Organization:||Deja.com - Before you buy.|
I'm currently working on my debug module and it should be able to
print out the function call stack in case of a crash. I'm developing
for MS Windows with Visual C++.
Inspirated by an article in the MSDN, i got the following idea:
In case of a crash I walk down the stack with BP/SP from function to
function. That way I could print out the address of the function. But
that's not enough - i also want to have the function name. So i got
the idea of declaring a static char *FUNC_NAME="foobar"; as the FIRST
local variable in every function i write. When walking down the stack
i can access this string with BP plus offset.
1) my code gets ugly since i have to define that variable in every function
2) I could "forget" to declare FUNC_NAME (i know that i am lazy)
3) it only works for MY functions but not for API-calls or other DLLs etc.
At least for 1) and 2) I got an idea, and this leads to my question:
is it possible that I Change the assembler code which is created by
the compiler when i call a function? That way i could automatically
declare FUNC_NAME (maybe not as static char * but as a local array of
char). Speed is not a problem since i would only do that in my debug
Maybe one of you has an idea how i could find an elegant solution for that...
[It's certainly possible to futz with the assembler code in an
intermediate pass, and hiding the function name in the object code is
an old trick dating back at least to the 1960s, but the normal way to
figure out what function you're tracing through is to look up its
address in the symbol table. -John]
Return to the
Search the comp.compilers archives again.