]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/db_trace.c
xnu-517.7.7.tar.gz
[apple/xnu.git] / osfmk / ppc / db_trace.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25
26 #include <string.h>
27
28 #include <mach/boolean.h>
29 #include <vm/vm_map.h>
30 #include <kern/thread.h>
31 #include <kern/processor.h>
32 #include <kern/task.h>
33
34 #include <machine/asm.h>
35 #include <machine/db_machdep.h>
36 #include <machine/setjmp.h>
37 #include <mach/machine.h>
38
39 #include <ddb/db_access.h>
40 #include <ddb/db_sym.h>
41 #include <ddb/db_variables.h>
42 #include <ddb/db_command.h>
43 #include <ddb/db_task_thread.h>
44 #include <ddb/db_output.h>
45
46 extern jmp_buf_t *db_recover;
47 extern struct savearea *saved_state[];
48
49 struct savearea ddb_null_kregs;
50
51 extern vm_offset_t vm_min_inks_addr; /* set by db_clone_symtabXXX */
52
53 #define DB_NUMARGS_MAX 5
54
55
56 extern char FixedStackStart[], FixedStackEnd[];
57 #define INFIXEDSTACK(va) \
58 ((((vm_offset_t)(va)) >= (vm_offset_t)&FixedStackStart) && \
59 (((vm_offset_t)(va)) < ((vm_offset_t)&FixedStackEnd)))
60
61 #define INKERNELSTACK(va, th) 1
62
63 struct db_ppc_frame {
64 struct db_ppc_frame *f_frame;
65 int pad1;
66 uint32_t f_retaddr;
67 int pad3;
68 int pad4;
69 int pad5;
70 uint32_t f_arg[DB_NUMARGS_MAX];
71 };
72
73 #define TRAP 1
74 #define INTERRUPT 2
75 #define SYSCALL 3
76
77 db_addr_t db_user_trap_symbol_value = 0;
78 db_addr_t db_kernel_trap_symbol_value = 0;
79 db_addr_t db_interrupt_symbol_value = 0;
80 db_addr_t db_return_to_iret_symbol_value = 0;
81 db_addr_t db_syscall_symbol_value = 0;
82 boolean_t db_trace_symbols_found = FALSE;
83
84 extern int db_ppc_reg_value(
85 struct db_variable * vp,
86 db_expr_t * val,
87 int flag,
88 db_var_aux_param_t ap);
89 extern void db_find_trace_symbols(void);
90 extern int db_numargs(
91 struct db_ppc_frame *fp,
92 task_t task);
93 extern boolean_t db_find_arg(
94 struct db_ppc_frame *frame,
95 db_addr_t calleepc,
96 task_t task,
97 int narg,
98 db_addr_t *arg);
99 extern void db_nextframe(
100 struct db_ppc_frame **lfp,
101 struct db_ppc_frame **fp,
102 db_addr_t *ip,
103 int frame_type,
104 thread_act_t thr_act,
105 db_addr_t linkpc);
106 extern int _setjmp(
107 jmp_buf_t * jb);
108
109 /*
110 * Machine register set.
111 */
112 struct db_variable db_regs[] = {
113 /* XXX "pc" is an alias to "srr0"... */
114 { "pc", &ddb_regs.save_srr0, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
115 { "srr0", &ddb_regs.save_srr0, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
116 { "srr1", &ddb_regs.save_srr1, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
117 { "r0", &ddb_regs.save_r0, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
118 { "r1", &ddb_regs.save_r1, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
119 { "r2", &ddb_regs.save_r2, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
120 { "r3", &ddb_regs.save_r3, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
121 { "r4", &ddb_regs.save_r4, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
122 { "r5", &ddb_regs.save_r5, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
123 { "r6", &ddb_regs.save_r6, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
124 { "r7", &ddb_regs.save_r7, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
125 { "r8", &ddb_regs.save_r8, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
126 { "r9", &ddb_regs.save_r9, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
127 { "r10", &ddb_regs.save_r10, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
128 { "r11", &ddb_regs.save_r11, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
129 { "r12", &ddb_regs.save_r12, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
130 { "r13", &ddb_regs.save_r13, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
131 { "r14", &ddb_regs.save_r14, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
132 { "r15", &ddb_regs.save_r15, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
133 { "r16", &ddb_regs.save_r16, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
134 { "r17", &ddb_regs.save_r17, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
135 { "r18", &ddb_regs.save_r18, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
136 { "r19", &ddb_regs.save_r19, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
137 { "r20", &ddb_regs.save_r20, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
138 { "r21", &ddb_regs.save_r21, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
139 { "r22", &ddb_regs.save_r22, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
140 { "r23", &ddb_regs.save_r23, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
141 { "r24", &ddb_regs.save_r24, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
142 { "r25", &ddb_regs.save_r25, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
143 { "r26", &ddb_regs.save_r26, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
144 { "r27", &ddb_regs.save_r27, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
145 { "r28", &ddb_regs.save_r28, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
146 { "r29", &ddb_regs.save_r29, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
147 { "r30", &ddb_regs.save_r30, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
148 { "r31", &ddb_regs.save_r31, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
149 { "cr", &ddb_regs.save_cr, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
150 { "xer", &ddb_regs.save_xer, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
151 { "lr", &ddb_regs.save_lr, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
152 { "ctr", &ddb_regs.save_ctr, db_ppc_reg_value, 0, 0, 0, 0, TRUE },
153 };
154 struct db_variable *db_eregs = db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
155
156 int
157 db_ppc_reg_value(
158 struct db_variable *vp,
159 db_expr_t *valuep,
160 int flag,
161 db_var_aux_param_t ap)
162 {
163 db_expr_t *dp = 0;
164 db_expr_t null_reg = 0;
165 uint32_t *dp32;
166
167 register thread_act_t thr_act = ap->thr_act;
168 int cpu;
169
170 if (db_option(ap->modif, 'u')) {
171 if (thr_act == THR_ACT_NULL) {
172 if ((thr_act = current_act()) == THR_ACT_NULL)
173 db_error("no user registers\n");
174 }
175 if (thr_act == current_act()) {
176 if (IS_USER_TRAP((&ddb_regs))) dp = vp->valuep;
177 else if (INFIXEDSTACK(ddb_regs.save_r1))
178 db_error("cannot get/set user registers in nested interrupt\n");
179 }
180 }
181 else {
182 if (thr_act == THR_ACT_NULL || thr_act == current_act()) {
183 dp = vp->valuep;
184 }
185 else {
186 if (thr_act->thread &&
187 !(thr_act->thread->state & TH_STACK_HANDOFF) &&
188 thr_act->thread->kernel_stack) {
189
190 int cpu;
191
192 for (cpu = 0; cpu < NCPUS; cpu++) {
193 if (cpu_to_processor(cpu)->state == PROCESSOR_RUNNING &&
194 cpu_to_processor(cpu)->active_thread == thr_act->thread && saved_state[cpu]) {
195
196 dp = (db_expr_t)(((uint32_t)saved_state[cpu]) +
197 (((uint32_t) vp->valuep) -
198 (uint32_t) &ddb_regs));
199 break;
200 }
201 }
202
203 if (dp == 0) dp = &null_reg;
204 }
205 else if (thr_act->thread && (thr_act->thread->state & TH_STACK_HANDOFF)){
206 /* only PC is valid */
207 if (vp->valuep == (int *) &ddb_regs.save_srr0) {
208 dp = (int *)(&thr_act->thread->continuation);
209 }
210 else {
211 dp = &null_reg;
212 }
213 }
214 }
215 }
216 if (dp == 0) {
217
218 if (!db_option(ap->modif, 'u')) {
219 for (cpu = 0; cpu < NCPUS; cpu++) {
220 if (cpu_to_processor(cpu)->state == PROCESSOR_RUNNING &&
221 cpu_to_processor(cpu)->active_thread == thr_act->thread && saved_state[cpu]) {
222 dp = (int *) (((int)saved_state[cpu]) +
223 (((int) vp->valuep) - (int) &ddb_regs));
224 break;
225 }
226 }
227 }
228 if (dp == 0) {
229 if (!thr_act || thr_act->mact.pcb == 0) db_error("no pcb\n");
230 dp = (int *)((int)thr_act->mact.pcb + ((int)vp->valuep - (int)&ddb_regs));
231 }
232 }
233
234 if(vp->valuep == (int *) &ddb_regs.save_cr) { /* Is this the CR we are doing? */
235 dp32 = (uint32_t *)dp; /* Make this easier */
236 if (flag == DB_VAR_SET) *dp32 = *valuep;
237 else *valuep = *dp32;
238 }
239 else { /* Normal 64-bit registers */
240 if (flag == DB_VAR_SET) *dp = *valuep;
241 else *valuep = *(unsigned long long *)dp;
242 }
243
244 return(0);
245 }
246
247
248 void
249 db_find_trace_symbols(void)
250 {
251 db_expr_t value;
252 boolean_t found_some;
253
254 found_some = FALSE;
255 if (db_value_of_name(CC_SYM_PREFIX "thandler", &value)) {
256 db_user_trap_symbol_value = (db_addr_t) value;
257 found_some = TRUE;
258 }
259 if (db_value_of_name(CC_SYM_PREFIX "thandler", &value)) {
260 db_kernel_trap_symbol_value = (db_addr_t) value;
261 found_some = TRUE;
262 }
263 if (db_value_of_name(CC_SYM_PREFIX "ihandler", &value)) {
264 db_interrupt_symbol_value = (db_addr_t) value;
265 found_some = TRUE;
266 }
267 #if 0
268 if (db_value_of_name(CC_SYM_PREFIX "return_to_iret", &value)) {
269 db_return_to_iret_symbol_value = (db_addr_t) value;
270 found_some = TRUE;
271 }
272 #endif
273 if (db_value_of_name(CC_SYM_PREFIX "thandler", &value)) {
274 db_syscall_symbol_value = (db_addr_t) value;
275 found_some = TRUE;
276 }
277 if (found_some)
278 db_trace_symbols_found = TRUE;
279 }
280
281 int
282 db_numargs(
283 struct db_ppc_frame *fp,
284 task_t task)
285 {
286 return (DB_NUMARGS_MAX);
287 }
288
289 boolean_t
290 db_find_arg(
291 struct db_ppc_frame *fp,
292 db_addr_t calleepc,
293 task_t task,
294 int narg,
295 db_addr_t *arg)
296 {
297 db_addr_t argp;
298 db_addr_t calleep;
299 db_addr_t offset;
300 int i;
301 int inst;
302 char *name;
303
304 #if XXX_BS
305 db_find_task_sym_and_offset(calleepc, &name, &offset, task);
306 calleep = calleepc-offset;
307
308 for (i = 0; calleep < calleepc; i++, calleep++) {
309 if (!DB_CHECK_ACCESS((int) calleep, 4, task)) {
310 continue;
311 }
312 inst = db_get_task_value(calleep, 4, FALSE, task);
313 if ((inst & 0xffff0000) == (0x907f0000 + (narg << 21)) ||
314 (inst & 0xffff0000) == (0x90610000 + (narg << 21))) {
315 argp = (db_addr_t) &(fp->f_arg[narg]);
316 *arg = argp;
317 return TRUE;
318 }
319 }
320 #endif
321 return FALSE;
322 }
323
324 /*
325 * Figure out the next frame up in the call stack.
326 * For trap(), we print the address of the faulting instruction and
327 * proceed with the calling frame. We return the ip that faulted.
328 * If the trap was caused by jumping through a bogus pointer, then
329 * the next line in the backtrace will list some random function as
330 * being called. It should get the argument list correct, though.
331 * It might be possible to dig out from the next frame up the name
332 * of the function that faulted, but that could get hairy.
333 */
334 void
335 db_nextframe(
336 struct db_ppc_frame **lfp, /* in/out */
337 struct db_ppc_frame **fp, /* in/out */
338 db_addr_t *ip, /* out */
339 int frame_type, /* in */
340 thread_act_t thr_act,
341 db_addr_t linkpc) /* in */
342 {
343 extern char * trap_type[];
344 extern int TRAP_TYPES;
345
346 struct savearea *saved_regs;
347
348 task_t task = (thr_act != THR_ACT_NULL)? thr_act->task: TASK_NULL;
349
350 switch(frame_type) {
351 case TRAP:
352
353 db_printf(">>>>> trap <<<<<\n");
354 goto miss_frame;
355 break;
356 case INTERRUPT:
357 if (*lfp == 0) {
358 db_printf(">>>>> interrupt <<<<<\n");
359 goto miss_frame;
360 }
361 db_printf(">>>>> interrupt <<<<<\n");
362 goto miss_frame;
363 break;
364 case SYSCALL:
365 if (thr_act != THR_ACT_NULL && thr_act->mact.pcb) {
366 *ip = (db_addr_t) thr_act->mact.pcb->save_srr0;
367 *fp = (struct db_ppc_frame *) (thr_act->mact.pcb->save_r1);
368 break;
369 }
370 /* falling down for unknown case */
371 default:
372 miss_frame:
373
374 if(!pmap_find_phys(kernel_pmap, (addr64_t)*fp)) { /* Check if this is valid */
375 db_printf("Frame not mapped %08X\n",*fp); /* Say not found */
376 *fp = 0; /* Show not found */
377 break; /* Out of here */
378 }
379
380 if ((*fp)->f_frame)
381 *ip = (db_addr_t)
382 db_get_task_value((int)&(*fp)->f_frame->f_retaddr,
383 4, FALSE, task);
384 else
385 *ip = (db_addr_t)
386 db_get_task_value((int)&(*fp)->f_retaddr,
387 4, FALSE, task);
388
389 *lfp = *fp;
390 *fp = (struct db_ppc_frame *)
391 db_get_task_value((int)&(*fp)->f_frame, 4, FALSE, task);
392 break;
393 }
394 }
395
396 void
397 db_stack_trace_cmd(
398 db_expr_t addr,
399 boolean_t have_addr,
400 db_expr_t count,
401 char *modif)
402 {
403 struct db_ppc_frame *frame, *lastframe;
404 db_addr_t callpc, linkpc, lastcallpc;
405 int frame_type;
406 boolean_t kernel_only = TRUE;
407 boolean_t trace_thread = FALSE;
408 boolean_t trace_all_threads = FALSE;
409 int thcount = 0;
410 char *filename;
411 int linenum;
412 task_t task;
413 thread_act_t th, top_act;
414 int user_frame;
415 int frame_count;
416 jmp_buf_t *prev;
417 jmp_buf_t db_jmp_buf;
418 queue_entry_t act_list;
419
420 if (!db_trace_symbols_found)
421 db_find_trace_symbols();
422 {
423 register char *cp = modif;
424 register char c;
425
426 while ((c = *cp++) != 0) {
427 if (c == 't')
428 trace_thread = TRUE;
429 if (c == 'T') {
430 trace_all_threads = TRUE;
431 trace_thread = TRUE;
432 }
433 if (c == 'u')
434 kernel_only = FALSE;
435 }
436 }
437
438 if (trace_all_threads) {
439 if (!have_addr && !trace_thread) {
440 have_addr = TRUE;
441 trace_thread = TRUE;
442 act_list = &(current_task()->threads);
443 addr = (db_expr_t) queue_first(act_list);
444 }
445 else if (trace_thread) {
446 if (have_addr) {
447 if (!db_check_act_address_valid((thread_act_t)addr)) {
448 if (db_lookup_task((task_t)addr) == -1)
449 return;
450 act_list = &(((task_t)addr)->threads);
451 addr = (db_expr_t) queue_first(act_list);
452 }
453 else {
454 act_list = &(((thread_act_t)addr)->task->threads);
455 thcount = db_lookup_task_act(((thread_act_t)addr)->task,
456 (thread_act_t)addr);
457 }
458 }
459 else {
460 th = db_default_act;
461 if (th == THR_ACT_NULL)
462 th = current_act();
463 if (th == THR_ACT_NULL) {
464 db_printf("no active thr_act\n");
465 return;
466 }
467 have_addr = TRUE;
468 act_list = &th->task->threads;
469 addr = (db_expr_t) queue_first(act_list);
470 }
471 }
472 }
473
474 if (count == -1)
475 count = 65535;
476
477 next_thread:
478 top_act = THR_ACT_NULL;
479
480 user_frame = 0;
481 frame_count = count;
482
483 if (!have_addr && !trace_thread) {
484 frame = (struct db_ppc_frame *)(ddb_regs.save_r1);
485 callpc = (db_addr_t)ddb_regs.save_srr0;
486 linkpc = (db_addr_t)ddb_regs.save_lr;
487 th = current_act();
488 task = (th != THR_ACT_NULL)? th->task: TASK_NULL;
489 }
490 else if (trace_thread) {
491 if (have_addr) {
492 th = (thread_act_t) addr;
493 if (!db_check_act_address_valid(th))
494 return;
495 }
496 else {
497 th = db_default_act;
498 if (th == THR_ACT_NULL)
499 th = current_act();
500 if (th == THR_ACT_NULL) {
501 db_printf("no active thread\n");
502 return;
503 }
504 }
505 if (trace_all_threads)
506 db_printf("---------- Thread 0x%x (#%d of %d) ----------\n",
507 addr, thcount, th->task->thread_count);
508
509 next_activation:
510
511 user_frame = 0;
512
513 task = th->task;
514 if (th == current_act()) {
515 frame = (struct db_ppc_frame *)(ddb_regs.save_r1);
516 callpc = (db_addr_t)ddb_regs.save_srr0;
517 linkpc = (db_addr_t)ddb_regs.save_lr;
518 }
519 else {
520 if (th->mact.pcb == 0) {
521 db_printf("thread has no pcb\n");
522 goto thread_done;
523 }
524 if (!th->thread) {
525 register struct savearea *pss =
526 th->mact.pcb;
527
528 db_printf("thread has no shuttle\n");
529 goto thread_done;
530 }
531 else if ((th->thread->state & TH_STACK_HANDOFF) ||
532 th->thread->kernel_stack == 0) {
533 register struct savearea *pss =
534 th->mact.pcb;
535
536 db_printf("Continuation ");
537 db_task_printsym((db_expr_t)th->thread->continuation,
538 DB_STGY_PROC, task);
539 db_printf("\n");
540 frame = (struct db_ppc_frame *) (pss->save_r1);
541 callpc = (db_addr_t) (pss->save_srr0);
542 linkpc = (db_addr_t) (pss->save_lr);
543 }
544 else {
545 int cpu;
546
547 for (cpu = 0; cpu < NCPUS; cpu++) {
548 if (cpu_to_processor(cpu)->state == PROCESSOR_RUNNING &&
549 cpu_to_processor(cpu)->active_thread == th->thread &&
550 saved_state[cpu]) {
551 break;
552 }
553 }
554 if (top_act != THR_ACT_NULL) {
555 /*
556 * Trying to get the backtrace of an activation
557 * which is not the top_most one in the RPC chain:
558 * use the activation's pcb.
559 */
560 struct savearea *pss;
561
562 pss = th->mact.pcb;
563 frame = (struct db_ppc_frame *) (pss->save_r1);
564 callpc = (db_addr_t) (pss->save_srr0);
565 linkpc = (db_addr_t) (pss->save_lr);
566 } else {
567 if (cpu == NCPUS) {
568 register struct savearea *iks;
569 int r;
570
571 iks = th->mact.pcb;
572 prev = db_recover;
573 if ((r = _setjmp(db_recover = &db_jmp_buf)) == 0) {
574 frame = (struct db_ppc_frame *) (iks->save_r1);
575 callpc = (db_addr_t) (iks->save_lr);
576 linkpc = 0;
577 } else {
578 /*
579 * The kernel stack has probably been
580 * paged out (swapped out activation).
581 */
582 db_recover = prev;
583 if (r == 2) /* 'q' from db_more() */
584 db_error(0);
585 db_printf("<kernel stack (0x%x) error "
586 "(probably swapped out)>\n",
587 iks);
588 goto next_act;
589 }
590 db_recover = prev;
591 } else {
592 db_printf(">>>>> active on cpu %d <<<<<\n",
593 cpu);
594 frame = (struct db_ppc_frame *)
595 (saved_state[cpu]->save_r1);
596 callpc = (db_addr_t) saved_state[cpu]->save_srr0;
597 linkpc = (db_addr_t) saved_state[cpu]->save_lr;
598 }
599 }
600 }
601 }
602 } else {
603 frame = (struct db_ppc_frame *)addr;
604 th = (db_default_act)? db_default_act: current_act();
605 task = (th != THR_ACT_NULL)? th->task: TASK_NULL;
606 if (frame->f_frame) {
607 callpc = (db_addr_t)db_get_task_value
608 ((int)&frame->f_frame->f_retaddr,
609 4, FALSE, (user_frame) ? task : 0);
610 callpc = callpc-sizeof(callpc);
611 } else
612 callpc =0;
613 linkpc = 0;
614 }
615
616 if (!INKERNELSTACK((unsigned)frame, th)) {
617 db_printf(">>>>> user space <<<<<\n");
618 if (kernel_only)
619 goto thread_done;
620 user_frame++;
621 }
622
623 lastframe = 0;
624 lastcallpc = (db_addr_t) 0;
625 while (frame_count-- && frame != 0) {
626 int narg = DB_NUMARGS_MAX;
627 int arg;
628 char * name;
629 db_expr_t offset;
630 db_addr_t call_func = 0;
631 int r;
632 db_addr_t off;
633
634 db_symbol_values(NULL,
635 db_search_task_symbol_and_line(
636 callpc, DB_STGY_XTRN, &offset, &filename,
637 &linenum, (user_frame) ? task : 0, &narg),
638 &name, (db_expr_t *)&call_func);
639 if ( name == NULL) {
640 db_find_task_sym_and_offset(callpc,
641 &name, &off, (user_frame) ? task : 0);
642 offset = (db_expr_t) off;
643 }
644
645 if (user_frame == 0) {
646 if (call_func &&
647 (call_func == db_user_trap_symbol_value ||
648 call_func == db_kernel_trap_symbol_value)) {
649 frame_type = TRAP;
650 narg = 1;
651 } else if (call_func &&
652 call_func == db_interrupt_symbol_value) {
653 frame_type = INTERRUPT;
654 goto next_frame;
655 } else if (call_func &&
656 call_func == db_syscall_symbol_value) {
657 frame_type = SYSCALL;
658 goto next_frame;
659 } else {
660 frame_type = 0;
661 prev = db_recover;
662 if ((r = _setjmp(db_recover = &db_jmp_buf))
663 == 0) {
664 if (narg < 0)
665 narg = db_numargs(frame,
666 (user_frame) ? task : 0);
667 db_recover = prev;
668 } else {
669 db_recover = prev;
670 goto next_act;
671 }
672 }
673 } else {
674 frame_type = 0;
675 prev = db_recover;
676 if ((r = _setjmp(db_recover = &db_jmp_buf)) == 0) {
677 if (narg < 0)
678 narg = db_numargs(frame,
679 (user_frame) ? task : 0);
680 db_recover = prev;
681 } else {
682 db_recover = prev;
683 goto next_act;
684 }
685 }
686
687 if (name == 0 || offset > db_maxoff) {
688 db_printf("[%08X]0x%08X(", frame, callpc);
689 } else {
690 db_printf("[%08X]%s", frame, name);
691 if (offset)
692 db_printf("+%x", offset);
693 db_printf("(");
694 };
695
696 narg = db_numargs(frame, (user_frame) ? task : 0);
697
698 for (arg =0; arg < narg; arg++) {
699 db_addr_t argp;
700 int value;
701 boolean_t found;
702
703 prev = db_recover;
704 if ((r = _setjmp(db_recover = &db_jmp_buf)) == 0) {
705 found = FALSE;
706 if (lastframe)
707 found = db_find_arg(frame, lastframe->f_retaddr,
708 (user_frame) ? task : 0, arg, &argp);
709 if (found)
710 value = db_get_task_value(argp, 4, FALSE,
711 (user_frame) ? task : 0);
712 } else {
713 db_recover = prev;
714 if (r == 2) /* 'q' from db_more() */
715 db_error(0);
716 db_printf("... <stack error>)");
717 db_printf("\n");
718 goto next_act;
719 }
720 db_recover = prev;
721 if (found)
722 db_printf("%08X", value);
723 else
724 db_printf("??");
725 argp = argp + sizeof(argp);
726 if (arg < narg-1)
727 db_printf(",");
728 }
729 if (arg != narg)
730 db_printf("...");
731 db_printf(")");
732 db_printf("\n");
733
734 next_frame:
735 lastcallpc = callpc;
736 prev = db_recover;
737 if ((r = _setjmp(db_recover = &db_jmp_buf)) == 0) {
738 db_nextframe(&lastframe, &frame, &callpc, frame_type,
739 (user_frame) ? th : THR_ACT_NULL, linkpc);
740 callpc = callpc-sizeof(callpc);
741 db_recover = prev;
742 } else {
743 db_recover = prev;
744 frame = 0;
745 }
746 linkpc = 0;
747
748 if (frame == 0) {
749 next_act:
750 if (th->lower != THR_ACT_NULL) {
751 if (top_act == THR_ACT_NULL)
752 top_act = th;
753 th = th->lower;
754 db_printf(">>>>> next activation 0x%x ($task%d.%d) <<<<<\n",
755 th,
756 db_lookup_task(th->task),
757 db_lookup_task_act(th->task, th));
758 goto next_activation;
759 }
760 /* end of chain */
761 break;
762 }
763 if (!INKERNELSTACK(lastframe, th) ||
764 !INKERNELSTACK((unsigned)frame, th))
765 user_frame++;
766 if (user_frame == 1) {
767 db_printf(">>>>> user space <<<<<\n");
768 if (kernel_only)
769 break;
770 }
771
772 if (frame <= lastframe) {
773 if ((INKERNELSTACK(lastframe, th) && !INKERNELSTACK(frame, th))) continue;
774 db_printf("Bad frame pointer: 0x%x\n", frame);
775 break;
776 }
777 }
778
779 thread_done:
780 if (trace_all_threads) {
781 if (top_act != THR_ACT_NULL)
782 th = top_act;
783 th = (thread_act_t) queue_next(&th->task_threads);
784 if (! queue_end(act_list, (queue_entry_t) th)) {
785 db_printf("\n");
786 addr = (db_expr_t) th;
787 thcount++;
788 goto next_thread;
789
790 }
791 }
792 }