: i would like to get a stack trace from inside a program. that is, i would
: like to obtain the name of the current function's caller, the name of that
: function's caller, and so on, all the way up to "main", and do all of this
: from inside a running program. is such a thing possible? i am running
: under SunOS 4.1.3/gcc 2.5.8 if it matters. thanks!
Yes, I have made such a function called print_stack that make all this.
It currently works on SunOS 4.1.x on Sparc
When called a stack trace is written out in the same format as the
$c command in adb. If the files are compiled with the -g flag, then file,
linenumber and function name is also written. A test program sttest.c is also
supplied. The program will only work on sun4! Compile as follows:
cc -c print_stack.c (NOTE! Do not use the -O flag!!!)
cc -g sttest.c print_stack.c -o sttest
When run the following is printed:
Programname = ./sttest
Backtrace:
subr2(0x9,0xe,0xd,0xd,0xf82a2dec,0x10000) + 18
file sttest.c line 6 function subr2()
subr1(0x9,0xf8420fb4,0xf778a118,0x80,0x3,0x0) + 34
file sttest.c line 17 function subr1()
main(0x1,0xf7ffef74,0xf7ffef7c,0x4000,0x0,0x0) + 18
file sttest.c line 25 function main()
start(0x0,0x0,0x0,0x0,0x0,0x0) + 44
If this is what You want I will be glad mail You the source code.
/ Lesley
--
Lesley Stoa
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Computer consultant Voice : +46 31 354732 FAX: +46 31 354750
CAP Programator Stockholm AB Mobile: +46 10 2846927
Division Energy & Telecom Pager : 0740 191404 (Sweden only)
----------------------------------------------------------------------
At the moment working for Voice : +46 31 673606
TM/PT, Ericsson Telecom AB FAX : +46 31 672942
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-