File: getretlinux.c

package info (click to toggle)
debauch 0.3-11
  • links: PTS
  • area: main
  • in suites: potato
  • size: 220 kB
  • ctags: 685
  • sloc: ansic: 2,136; makefile: 531; sh: 84; asm: 34
file content (27 lines) | stat: -rw-r--r-- 555 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
 * modified from getreti386.c
 *
 * Copyright (c) 1995 Jeffrey Hsu
 * Copyright (c) 1999 Jon A. Christopher
 */

#define get_current_fp(first_local)	((unsigned)&(first_local) + 4)
#define prev_fp_from_fp(fp)		*((unsigned *) fp)
#define ret_addr_from_fp(fp)		*((unsigned *) (fp+4))

void
getStackTrace(unsigned long *results, int max)
{

  int first_local;
  unsigned long fp, ret_addr;

  fp = get_current_fp(first_local);

  while (fp!=0 && max--) {
    ret_addr = ret_addr_from_fp(fp);
    *results++ = ret_addr;
    fp = prev_fp_from_fp(fp);
  }

}