getting stack trace from inside program?

getting stack trace from inside program?

Post by that's Mister Mike to yo » Mon, 16 Jan 1995 18:22:30



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!

--
never speak before you strike. it's bad luck. - Psin, "Until The Sun Falls"

Mike Nemeth          Virtual Universe Corp      Calgary, Alberta, Canada

 
 
 

getting stack trace from inside program?

Post by Lesley St » Fri, 20 Jan 1995 00:01:07



: 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

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

 
 
 

getting stack trace from inside program?

Post by Arne Vajho » Sat, 21 Jan 1995 04:45:02



Quote:> 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!

I am not familar with SunOS/gcc, but on many platforms this is impossible,
because part of the compilation process is to convert all routines to
addresses and there are no reason to save an address-routine table !

Since a de* would want that information, then compiling with debug
can help.

                                                                Arne

Arne Vajh?j                             local DECNET:  KO::ARNE
Computer Department                     PSI:           PSI%238310013040::ARNE

                WWW URL: http://www.veryComputer.com/~arne/arne.html

 
 
 

1. Problems calling a gdb stack trace from inside the program thats being traced.

I'm trying to get my C program to stack trace itself using gdb.

Upon detecting an error my program does a

system("gdb -x configfile programname programPID > outputfile");

Where the configfile contains the lines:-

bt
quit

Now that works fine from a bash shell but all I get when my program
hits it is a frozen program that needs a Ctrl-C.

Whats going on? Can I use this technique to stack trace my program?

It is a multi-threaded (pthreads) program, compiled using -gstabs+ in
the compile line, with gcc 3.1.

I don't want to have to write my own stack tracing routines!

Thanks,

Joe

2. 3com 3c509b etherlink problem -- I have tried for a LONG time!

3. Getting stack trace from a core file

4. Scripts for automatic action with Openview NNM

5. Getting a stack trace

6. Tropez 32 (TBS-2000) Help Please

7. getting a stack trace w/o running in a debugger

8. Strange network problem with RH 7

9. Getting the stack trace

10. getting stack trace from signal handler U_STACK_TRACE()

11. Printing a stack trace upon program error

12. How can I get a stack trace within a program?

13. stack trace of C/C++ programs (under SunOS)