don't print SYSTEM stacktrace on exceptions as it's not scheduled any more.
[minix.git] / lib / libsys / stacktrace.c
blob6ddb4442e43964799d20d45f75dcbab3fc08244b
1 /*
2 stacktrace.c
4 Created: Jan 19, 1993 by Philip Homburg
6 Copyright 1995 Philip Homburg
7 */
9 #include <stdio.h>
10 #include <string.h>
12 typedef unsigned int reg_t;
14 #define FUNC_STACKTRACE(statement) \
15 { \
16 reg_t bp, pc, hbp; \
17 extern reg_t get_bp(void); \
19 bp= get_bp(); \
20 while(bp) \
21 { \
22 pc= ((reg_t *)bp)[1]; \
23 hbp= ((reg_t *)bp)[0]; \
24 statement; \
25 if (hbp != 0 && hbp <= bp) \
26 { \
27 pc = -1; \
28 statement; \
29 break; \
30 } \
31 bp= hbp; \
32 } \
35 void util_nstrcat(char *str, unsigned long number)
37 int n = 10, lead = 1;
38 char nbuf[12], *p;
39 p = nbuf;
40 *p++ = '0';
41 *p++ = 'x';
42 for(n = 0; n < 8; n++) {
43 int i;
44 i = (number >> ((7-n)*4)) & 0xF;
45 if(!lead || i) {
46 *p++ = i < 10 ? '0' + i : 'a' + i - 10;
47 lead = 0;
50 if(lead) *p++ = '0';
51 *p++ = ' ';
52 *p++ = '\0';
53 strcat(str, nbuf);
56 void util_stacktrace(void)
58 FUNC_STACKTRACE(printf("0x%lx ", (unsigned long) pc));
59 printf("\n");
62 void util_stacktrace_strcat(char *str)
64 FUNC_STACKTRACE(util_nstrcat(str, pc));