2 * simple backtrace facility
6 * This software is part of the SBCL system. See the README file for
9 * This software is derived from the CMU CL system, which was
10 * written at Carnegie Mellon University and released into the
11 * public domain. The software is in the public domain and is
12 * provided with absolutely no warranty. See the COPYING and CREDITS
13 * files for more information.
22 #include "interrupt.h"
24 #ifdef LISP_FEATURE_GENCGC
25 #include "gencgc-alloc-region.h"
27 #include "genesis/static-symbols.h"
28 #include "genesis/primitive-objects.h"
33 /* KLUDGE: Sigh ... I know what the call frame looks like and it had
34 * better not change. */
38 struct call_frame
*old_cont
;
44 lispobj other_state
[5];
49 struct call_frame
*frame
;
60 int pc
; /* Note: this is the trace file offset, not the actual pc. */
63 #define HEADER_LENGTH(header) ((header)>>8)
65 static int previous_info(struct call_info
*info
);
68 code_pointer(lispobj object
)
70 lispobj
*headerp
, header
;
73 headerp
= (lispobj
*) native_pointer(object
);
75 type
= widetag_of(header
);
78 case CODE_HEADER_WIDETAG
:
80 case RETURN_PC_HEADER_WIDETAG
:
81 case SIMPLE_FUN_HEADER_WIDETAG
:
82 case CLOSURE_FUN_HEADER_WIDETAG
:
83 len
= HEADER_LENGTH(header
);
93 return (struct code
*) headerp
;
97 cs_valid_pointer_p(struct call_frame
*pointer
)
99 struct thread
*thread
=arch_os_get_current_thread();
100 return (((char *) thread
->control_stack_start
<= (char *) pointer
) &&
101 ((char *) pointer
< (char *) current_control_stack_pointer
));
105 call_info_from_lisp_state(struct call_info
*info
)
107 info
->frame
= (struct call_frame
*)current_control_frame_pointer
;
108 info
->interrupted
= 0;
117 call_info_from_context(struct call_info
*info
, os_context_t
*context
)
121 info
->interrupted
= 1;
122 if (lowtag_of(*os_context_register_addr(context
, reg_CODE
))
123 == FUN_POINTER_LOWTAG
) {
124 /* We tried to call a function, but crapped out before $CODE could
125 * be fixed up. Probably an undefined function. */
127 (struct call_frame
*)(*os_context_register_addr(context
,
129 info
->lra
= (lispobj
)(*os_context_register_addr(context
, reg_LRA
));
130 info
->code
= code_pointer(info
->lra
);
131 pc
= (unsigned long)native_pointer(info
->lra
);
135 (struct call_frame
*)(*os_context_register_addr(context
, reg_CFP
));
137 code_pointer(*os_context_register_addr(context
, reg_CODE
));
139 pc
= *os_context_pc_addr(context
);
141 if (info
->code
!= NULL
)
142 info
->pc
= pc
- (unsigned long) info
->code
-
144 (HEADER_LENGTH(info
->code
->header
) * sizeof(lispobj
));
146 (HEADER_LENGTH(((struct code
*)info
->code
)->header
) * sizeof(lispobj
));
153 previous_info(struct call_info
*info
)
155 struct call_frame
*this_frame
;
156 struct thread
*thread
=arch_os_get_current_thread();
159 if (!cs_valid_pointer_p(info
->frame
)) {
160 printf("Bogus callee value (0x%08x).\n", (unsigned long)info
->frame
);
164 this_frame
= info
->frame
;
165 info
->lra
= this_frame
->saved_lra
;
166 info
->frame
= this_frame
->old_cont
;
167 info
->interrupted
= 0;
169 if (info
->frame
== NULL
|| info
->frame
== this_frame
)
172 if (info
->lra
== NIL
) {
173 /* We were interrupted. Find the correct signal context. */
174 free
= SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX
,thread
)>>2;
176 os_context_t
*context
=
177 thread
->interrupt_contexts
[free
];
178 if ((struct call_frame
*)(*os_context_register_addr(context
,
181 call_info_from_context(info
, context
);
187 info
->code
= code_pointer(info
->lra
);
188 if (info
->code
!= NULL
)
189 info
->pc
= (unsigned long)native_pointer(info
->lra
) -
190 (unsigned long)info
->code
-
192 (HEADER_LENGTH(info
->code
->header
) * sizeof(lispobj
));
194 (HEADER_LENGTH(((struct code
*)info
->code
)->header
) * sizeof(lispobj
));
204 backtrace(int nframes
)
206 struct call_info info
;
208 call_info_from_lisp_state(&info
);
211 printf("<Frame 0x%08x%s, ", (unsigned long) info
.frame
,
212 info
.interrupted
? " [interrupted]" : "");
214 if (info
.code
!= (struct code
*) 0) {
217 printf("CODE: 0x%08X, ", (unsigned long) info
.code
| OTHER_POINTER_LOWTAG
);
220 function
= info
.code
->entry_points
;
222 function
= ((struct code
*)info
.code
)->entry_points
;
224 while (function
!= NIL
) {
225 struct simple_fun
*header
;
228 header
= (struct simple_fun
*) native_pointer(function
);
231 if (lowtag_of(name
) == OTHER_POINTER_LOWTAG
) {
234 object
= (lispobj
*) native_pointer(name
);
236 if (widetag_of(*object
) == SYMBOL_HEADER_WIDETAG
) {
237 struct symbol
*symbol
;
239 symbol
= (struct symbol
*) object
;
240 object
= (lispobj
*) native_pointer(symbol
->name
);
242 if (widetag_of(*object
) == SIMPLE_BASE_STRING_WIDETAG
) {
243 struct vector
*string
;
245 string
= (struct vector
*) object
;
246 printf("%s, ", (char *) string
->data
);
248 printf("(Not simple string??\?), ");
250 printf("(Not other pointer??\?), ");
253 function
= header
->next
;
257 printf("CODE: ???, ");
260 printf("LRA: 0x%08x, ", (unsigned long)info
.lra
);
262 printf("<no LRA>, ");
265 printf("PC: 0x%x>\n", info
.pc
);
267 printf("PC: ??\?>\n");
269 } while (--nframes
> 0 && previous_info(&info
));
277 backtrace(int nframes
)
279 printf("Can't backtrace on this hardware platform.\n");