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"
27 /* KLUDGE: Sigh ... I know what the call frame looks like and it had
28 * better not change. */
32 struct call_frame *old_cont;
38 lispobj other_state[5];
43 struct call_frame *frame;
54 int pc; /* Note: this is the trace file offset, not the actual pc. */
57 #define HEADER_LENGTH(header) ((header)>>8)
59 static int previous_info(struct call_info *info);
62 code_pointer(lispobj object)
64 lispobj *headerp, header;
67 headerp = (lispobj *) native_pointer(object);
69 type = TypeOf(header);
74 case type_ReturnPcHeader:
75 case type_FunctionHeader:
76 case type_ClosureFunctionHeader:
77 len = HEADER_LENGTH(header);
87 return (struct code *) headerp;
91 cs_valid_pointer_p(struct call_frame *pointer)
93 /* lose("stub: hasn't been updated for X86"); */
94 return (((char *) CONTROL_STACK_START <= (char *) pointer) &&
95 ((char *) pointer < (char *) current_control_stack_pointer));
99 call_info_from_lisp_state(struct call_info *info)
101 info->frame = (struct call_frame *)current_control_frame_pointer;
102 info->interrupted = 0;
111 call_info_from_context(struct call_info *info, os_context_t *context)
115 info->interrupted = 1;
116 if (LowtagOf(*os_context_register_addr(context, reg_CODE))
117 == type_FunctionPointer) {
118 /* We tried to call a function, but crapped out before $CODE could
119 * be fixed up. Probably an undefined function. */
121 (struct call_frame *)(*os_context_register_addr(context,
123 info->lra = (lispobj)(*os_context_register_addr(context, reg_LRA));
124 info->code = code_pointer(info->lra);
125 pc = (unsigned long)native_pointer(info->lra);
129 (struct call_frame *)(*os_context_register_addr(context, reg_CFP));
131 code_pointer(*os_context_register_addr(context, reg_CODE));
133 pc = *os_context_pc_addr(context);
135 if (info->code != NULL)
136 info->pc = pc - (unsigned long) info->code -
138 (HEADER_LENGTH(info->code->header) * sizeof(lispobj));
140 (HEADER_LENGTH(((struct code *)info->code)->header) * sizeof(lispobj));
147 previous_info(struct call_info *info)
149 struct call_frame *this_frame;
152 if (!cs_valid_pointer_p(info->frame)) {
153 printf("Bogus callee value (0x%08x).\n", (unsigned long)info->frame);
157 this_frame = info->frame;
158 info->lra = this_frame->saved_lra;
159 info->frame = this_frame->old_cont;
160 info->interrupted = 0;
162 if (info->frame == NULL || info->frame == this_frame)
165 if (info->lra == NIL) {
166 /* We were interrupted. Find the correct signal context. */
167 free = SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX)>>2;
169 os_context_t *context =
170 lisp_interrupt_contexts[free];
171 if ((struct call_frame *)(*os_context_register_addr(context,
174 call_info_from_context(info, context);
180 info->code = code_pointer(info->lra);
181 if (info->code != NULL)
182 info->pc = (unsigned long)native_pointer(info->lra) -
183 (unsigned long)info->code -
185 (HEADER_LENGTH(info->code->header) * sizeof(lispobj));
187 (HEADER_LENGTH(((struct code *)info->code)->header) * sizeof(lispobj));
197 backtrace(int nframes)
199 struct call_info info;
201 call_info_from_lisp_state(&info);
204 printf("<Frame 0x%08x%s, ", (unsigned long) info.frame,
205 info.interrupted ? " [interrupted]" : "");
207 if (info.code != (struct code *) 0) {
210 printf("CODE: 0x%08X, ", (unsigned long) info.code | type_OtherPointer);
213 function = info.code->entry_points;
215 function = ((struct code *)info.code)->entry_points;
217 while (function != NIL) {
218 struct function *header;
221 header = (struct function *) native_pointer(function);
224 if (LowtagOf(name) == type_OtherPointer) {
227 object = (lispobj *) native_pointer(name);
229 if (TypeOf(*object) == type_SymbolHeader) {
230 struct symbol *symbol;
232 symbol = (struct symbol *) object;
233 object = (lispobj *) native_pointer(symbol->name);
235 if (TypeOf(*object) == type_SimpleString) {
236 struct vector *string;
238 string = (struct vector *) object;
239 printf("%s, ", (char *) string->data);
241 printf("(Not simple string??\?), ");
243 printf("(Not other pointer??\?), ");
246 function = header->next;
250 printf("CODE: ???, ");
253 printf("LRA: 0x%08x, ", (unsigned long)info.lra);
255 printf("<no LRA>, ");
258 printf("PC: 0x%x>\n", info.pc);
260 printf("PC: ??\?>\n");
262 } while (--nframes > 0 && previous_info(&info));
268 backtrace(int nframes)
270 printf("Can't backtrace on this hardware platform.\n");