How to backtrace stack frames?

How to backtrace stack frames?

Post by Jung-Ho A » Sat, 10 Jun 1995 04:00:00



Hello,

I would like to backtrace all stack frames in a signal
handler and then get 'program counter' for each nested
function call. Any suggestions or information about
stack frame would be appreciated.
I'm using Sparc10(SunOS 4.1.3) and g++ 2.6.3.

Thanks in advance

--
==============================================================
 Jung-Ho Ahn                        ||
 OOPSLA Lab. Dept. of Computer Eng. || fax.   871-6945
 Seoul National University          || email:

 Seoul 151-742, KOREA               ||
==============================================================

 
 
 

How to backtrace stack frames?

Post by s.. » Wed, 14 Jun 1995 04:00:00


Quote:> < How get PC for nested function calls in SunOS 4.1.3 >

[ Please note the followup, this is a very system dependent answer ]

For SunOS4.1.3, one way is to call FLUSH_WINDOWS in the kernel, which
saves the register windows in memory, then trace through the stack
frames. You can look at the format of stack frames in
/usr/include/frame.h

For instance, (making inappropriate calls to printf() from a signal
handler :)

netcom12: 14> cat dmpstk.s
        .global _dump_stack
_dump_stack:
        ta 0x3
        retl
        mov %sp, %o0
netcom12: 15> cat sig.c
#include <stdio.h>
#include <signal.h>
#include <frame.h>

extern void *dump_stack(void);

void sig_handler()
{
  struct frame *this;

  for (this = dump_stack(); this; this = this->fr_savfp)
    {
      if (this->fr_savpc) printf("%#x\n", (unsigned int)(this->fr_savpc));
    }

Quote:}

int main()
{
  signal(SIGINT, sig_handler);
  getchar(); return(0);
Quote:}

netcom12: 16> /bin/as -o dmpstk.o dmpstk.s
netcom12: 17> gcc -o sig sig.c dmpstk.o
netcom12: 18> ./sig
^C0xef77dcd4
0xef786b88
0x237c
0x2064

netcom12: 19>

Hope this helps,
-KB-

 
 
 

1. How to backtrace stack frames?

I'm trying to print backtrace of all stack frames.
Does anybody know how to do it?
or Is there any information about stack frame?

Any tips would be appreciated.

Many thanks in advance,

--
==============================================================
 Jung-Ho Ahn                        ||
 OOPSLA Lab. Dept. of Computer Eng. || fax.   871-6945
 Seoul National University          || email:

 Seoul 151-742, KOREA               ||
==============================================================

2. How to log into AIX without root password?

3. gdb: missing frames in frame stack or function name garbled

4. i2c driver changes for 2.5.66

5. call stack backtrace from a C program

6. indirect route

7. Stack backtrace from signal handler

8. Minor Numbers on Clone Open

9. Stack Backtrace for Solaris 2.3/SunPro C 2.0

10. Seeking stack backtrace function

11. adb and dbx gives different stack backtraces

12. call stack backtrace from a C program (Solaris)

13. Interpreting the results from backtrace()/ backtrace() usability