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.
26 #include "interrupt.h"
31 /* KLUDGE: Sigh ... I know what the call frame looks like and it had
32 * better not change. */
36 struct call_frame *old_cont;
42 lispobj other_state[5];
47 struct call_frame *frame;
58 int pc; /* Note: this is the trace file offset, not the actual pc. */
61 #define HEADER_LENGTH(header) ((header)>>8)
63 static int previous_info(struct call_info *info);
66 code_pointer(lispobj object)
68 lispobj *headerp, header;
71 headerp = (lispobj *) PTR(object);
73 type = TypeOf(header);
78 case type_ReturnPcHeader:
79 case type_FunctionHeader:
80 case type_ClosureFunctionHeader:
81 len = HEADER_LENGTH(header);
91 return (struct code *) headerp;
95 cs_valid_pointer_p(struct call_frame *pointer)
97 lose("stub: hasn't been updated for X86");
98 return (((char *) CONTROL_STACK_START <= (char *) pointer) &&
99 ((char *) pointer < (char *) current_control_stack_pointer));
103 call_info_from_lisp_state(struct call_info *info)
105 info->frame = (struct call_frame *)current_control_frame_pointer;
106 info->interrupted = 0;
115 call_info_from_context(struct call_info *info, os_context_t *context)
119 info->interrupted = 1;
120 if (LowtagOf(*os_context_register_addr(context, reg_CODE))
121 == type_FunctionPointer) {
122 /* We tried to call a function, but crapped out before $CODE could
123 * be fixed up. Probably an undefined function. */
125 (struct call_frame *)(*os_context_register_addr(context,
127 info->lra = (lispobj)(*os_context_register_addr(context, reg_LRA));
128 info->code = code_pointer(info->lra);
129 pc = (unsigned long)PTR(info->lra);
133 (struct call_frame *)(*os_context_register_addr(context, reg_CFP));
135 code_pointer(*os_context_register_addr(context, reg_CODE));
137 pc = *os_context_pc_addr(context);
139 if (info->code != NULL)
140 info->pc = pc - (unsigned long) info->code -
142 (HEADER_LENGTH(info->code->header) * sizeof(lispobj));
144 (HEADER_LENGTH(((struct code *)info->code)->header) * sizeof(lispobj));
151 previous_info(struct call_info *info)
153 struct call_frame *this_frame;
156 if (!cs_valid_pointer_p(info->frame)) {
157 printf("Bogus callee value (0x%08x).\n", (unsigned long)info->frame);
161 this_frame = info->frame;
162 info->lra = this_frame->saved_lra;
163 info->frame = this_frame->old_cont;
164 info->interrupted = 0;
166 if (info->frame == NULL || info->frame == this_frame)
169 if (info->lra == NIL) {
170 /* We were interrupted. Find the correct signal context. */
171 free = SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX)>>2;
173 os_context_t *context =
174 lisp_interrupt_contexts[free];
175 if ((struct call_frame *)(*os_context_register_addr(context,
178 call_info_from_context(info, context);
184 info->code = code_pointer(info->lra);
185 if (info->code != NULL)
186 info->pc = (unsigned long)PTR(info->lra) -
187 (unsigned long)info->code -
189 (HEADER_LENGTH(info->code->header) * sizeof(lispobj));
191 (HEADER_LENGTH(((struct code *)info->code)->header) * sizeof(lispobj));
201 backtrace(int nframes)
203 struct call_info info;
205 call_info_from_lisp_state(&info);
208 printf("<Frame 0x%08x%s, ", (unsigned long) info.frame,
209 info.interrupted ? " [interrupted]" : "");
211 if (info.code != (struct code *) 0) {
214 printf("CODE: 0x%08X, ", (unsigned long) info.code | type_OtherPointer);
217 function = info.code->entry_points;
219 function = ((struct code *)info.code)->entry_points;
221 while (function != NIL) {
222 struct function *header;
225 header = (struct function *) PTR(function);
228 if (LowtagOf(name) == type_OtherPointer) {
231 object = (lispobj *) PTR(name);
233 if (TypeOf(*object) == type_SymbolHeader) {
234 struct symbol *symbol;
236 symbol = (struct symbol *) object;
237 object = (lispobj *) PTR(symbol->name);
239 if (TypeOf(*object) == type_SimpleString) {
240 struct vector *string;
242 string = (struct vector *) object;
243 printf("%s, ", (char *) string->data);
245 printf("(Not simple string??\?), ");
247 printf("(Not other pointer??\?), ");
250 function = header->next;
254 printf("CODE: ???, ");
257 printf("LRA: 0x%08x, ", (unsigned long)info.lra);
259 printf("<no LRA>, ");
262 printf("PC: 0x%x>\n", info.pc);
264 printf("PC: ??\?>\n");
266 } while (--nframes > 0 && previous_info(&info));
272 backtrace(int nframes)
274 printf("Can't backtrace on this hardware platform.\n");