A
anirbid.banerjee
Hi List,
This question can be categorised under "C programming in Linux", but
as I didnt find any group of that sort, I post it here.
I have a small program to print the stack trace of a particular
function. Here is the code:
====================================================
#include <stdio.h>
#include <execinfo.h>
#include <stdlib.h>
void print_trace (void){
void *arr[20];
size_t asize, icnt;
char **str;
asize = backtrace (arr, 20);
str = backtrace_symbols (arr, asize);
for (icnt=0; icnt<asize; ++icnt)
printf ("%s\n",str[icnt]);
free (str);
}
int main(int argc, char **argv)
{
print_trace ();
return 0;
}
====================================================
By calling backtrace ( ) and backtrace_symbols ( ) I can get a trace
of the calling functions path.
What I would like to know is if I can find the contents of the calling
functions () s argument values too?
More precisely:
A(void) {
....
backtrace ( )
backtrace_symbols ( )
....
}
B (int foo, int bar){
A () ;
....
}
C (int foo, int bar, int baz){
B ();
....
}
int main (){
C ()
....
....
}
get the values for the arguments used in C (foo, bar, baz) and B (foo,
bar)? If we could then how?
Thanks
Anirbid
This question can be categorised under "C programming in Linux", but
as I didnt find any group of that sort, I post it here.
I have a small program to print the stack trace of a particular
function. Here is the code:
====================================================
#include <stdio.h>
#include <execinfo.h>
#include <stdlib.h>
void print_trace (void){
void *arr[20];
size_t asize, icnt;
char **str;
asize = backtrace (arr, 20);
str = backtrace_symbols (arr, asize);
for (icnt=0; icnt<asize; ++icnt)
printf ("%s\n",str[icnt]);
free (str);
}
int main(int argc, char **argv)
{
print_trace ();
return 0;
}
====================================================
By calling backtrace ( ) and backtrace_symbols ( ) I can get a trace
of the calling functions path.
What I would like to know is if I can find the contents of the calling
functions () s argument values too?
More precisely:
A(void) {
....
backtrace ( )
backtrace_symbols ( )
....
}
B (int foo, int bar){
A () ;
....
}
C (int foo, int bar, int baz){
B ();
....
}
int main (){
C ()
....
....
}
main() calling C ()-> C() calling B() -> B() calling A(). Can we alsoFrom the backtrace_symbols we can generate a path of the function call
get the values for the arguments used in C (foo, bar, baz) and B (foo,
bar)? If we could then how?
Thanks
Anirbid