1 /* $NetBSD: db_trace.c,v 1.49 2009/10/21 21:12:02 rmind Exp $ */
2 /* $OpenBSD: db_trace.c,v 1.3 1997/03/21 02:10:48 niklas Exp $ */
5 * Mach Operating System
6 * Copyright (c) 1992 Carnegie Mellon University
9 * Permission to use, copy, modify and distribute this software and its
10 * documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
17 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 * Carnegie Mellon requests users of this software to return to
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
26 * any improvements or extensions that they make and grant Carnegie Mellon
27 * the rights to redistribute these changes.
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.49 2009/10/21 21:12:02 rmind Exp $");
33 #include "opt_ppcarch.h"
35 #include <sys/param.h>
37 #include <sys/kernel.h>
39 #include <uvm/uvm_extern.h>
41 #include <machine/db_machdep.h>
42 #include <machine/pmap.h>
43 #include <powerpc/spr.h>
45 #include <ddb/db_access.h>
46 #include <ddb/db_interface.h>
47 #include <ddb/db_sym.h>
48 #include <ddb/db_variables.h>
50 const struct db_variable db_regs
[] = {
51 { "r0", (long *)&ddb_regs
.r
[0], FCN_NULL
, NULL
},
52 { "r1", (long *)&ddb_regs
.r
[1], FCN_NULL
, NULL
},
53 { "r2", (long *)&ddb_regs
.r
[2], FCN_NULL
, NULL
},
54 { "r3", (long *)&ddb_regs
.r
[3], FCN_NULL
, NULL
},
55 { "r4", (long *)&ddb_regs
.r
[4], FCN_NULL
, NULL
},
56 { "r5", (long *)&ddb_regs
.r
[5], FCN_NULL
, NULL
},
57 { "r6", (long *)&ddb_regs
.r
[6], FCN_NULL
, NULL
},
58 { "r7", (long *)&ddb_regs
.r
[7], FCN_NULL
, NULL
},
59 { "r8", (long *)&ddb_regs
.r
[8], FCN_NULL
, NULL
},
60 { "r9", (long *)&ddb_regs
.r
[9], FCN_NULL
, NULL
},
61 { "r10", (long *)&ddb_regs
.r
[10], FCN_NULL
, NULL
},
62 { "r11", (long *)&ddb_regs
.r
[11], FCN_NULL
, NULL
},
63 { "r12", (long *)&ddb_regs
.r
[12], FCN_NULL
, NULL
},
64 { "r13", (long *)&ddb_regs
.r
[13], FCN_NULL
, NULL
},
65 { "r14", (long *)&ddb_regs
.r
[14], FCN_NULL
, NULL
},
66 { "r15", (long *)&ddb_regs
.r
[15], FCN_NULL
, NULL
},
67 { "r16", (long *)&ddb_regs
.r
[16], FCN_NULL
, NULL
},
68 { "r17", (long *)&ddb_regs
.r
[17], FCN_NULL
, NULL
},
69 { "r18", (long *)&ddb_regs
.r
[18], FCN_NULL
, NULL
},
70 { "r19", (long *)&ddb_regs
.r
[19], FCN_NULL
, NULL
},
71 { "r20", (long *)&ddb_regs
.r
[20], FCN_NULL
, NULL
},
72 { "r21", (long *)&ddb_regs
.r
[21], FCN_NULL
, NULL
},
73 { "r22", (long *)&ddb_regs
.r
[22], FCN_NULL
, NULL
},
74 { "r23", (long *)&ddb_regs
.r
[23], FCN_NULL
, NULL
},
75 { "r24", (long *)&ddb_regs
.r
[24], FCN_NULL
, NULL
},
76 { "r25", (long *)&ddb_regs
.r
[25], FCN_NULL
, NULL
},
77 { "r26", (long *)&ddb_regs
.r
[26], FCN_NULL
, NULL
},
78 { "r27", (long *)&ddb_regs
.r
[27], FCN_NULL
, NULL
},
79 { "r28", (long *)&ddb_regs
.r
[28], FCN_NULL
, NULL
},
80 { "r29", (long *)&ddb_regs
.r
[29], FCN_NULL
, NULL
},
81 { "r30", (long *)&ddb_regs
.r
[30], FCN_NULL
, NULL
},
82 { "r31", (long *)&ddb_regs
.r
[31], FCN_NULL
, NULL
},
83 { "iar", (long *)&ddb_regs
.iar
, FCN_NULL
, NULL
},
84 { "msr", (long *)&ddb_regs
.msr
, FCN_NULL
, NULL
},
85 { "lr", (long *)&ddb_regs
.lr
, FCN_NULL
, NULL
},
86 { "ctr", (long *)&ddb_regs
.ctr
, FCN_NULL
, NULL
},
87 { "cr", (long *)&ddb_regs
.cr
, FCN_NULL
, NULL
},
88 { "xer", (long *)&ddb_regs
.xer
, FCN_NULL
, NULL
},
89 { "mq", (long *)&ddb_regs
.mq
, FCN_NULL
, NULL
},
91 { "dear", (long *)&ddb_regs
.dear
, FCN_NULL
, NULL
},
92 { "esr", (long *)&ddb_regs
.esr
, FCN_NULL
, NULL
},
93 { "pid", (long *)&ddb_regs
.pid
, FCN_NULL
, NULL
},
96 const struct db_variable
* const db_eregs
= db_regs
+ sizeof (db_regs
)/sizeof (db_regs
[0]);
102 db_stack_trace_print(db_expr_t addr
, bool have_addr
, db_expr_t count
,
103 const char *modif
, void (*pr
)(const char *, ...))
105 db_addr_t frame
, lr
, *args
;
109 const char *cp
= modif
;
111 bool kernel_only
= true;
112 bool trace_thread
= false;
113 bool lwpaddr
= false;
114 extern int trapexit
[], sctrapexit
[];
116 bool in_kernel
= true;
118 while ((c
= *cp
++) != 0) {
138 l
= (struct lwp
*)addr
;
140 (*pr
)("trace: pid %d ", p
->p_pid
);
142 (*pr
)("trace: pid %d ", (int)addr
);
143 p
= p_find(addr
, PFIND_LOCKED
);
145 (*pr
)("not found\n");
148 l
= LIST_FIRST(&p
->p_lwps
);
151 (*pr
)("lid %d ", l
->l_lid
);
153 frame
= (db_addr_t
)pcb
->pcb_sp
;
154 (*pr
)("at %p\n", frame
);
156 frame
= (db_addr_t
)addr
;
158 frame
= (db_addr_t
)ddb_regs
.r
[1];
161 if (frame
< PAGE_SIZE
)
163 frame
= *(db_addr_t
*)frame
;
165 args
= (db_addr_t
*)(frame
+ 8);
166 if (frame
< PAGE_SIZE
)
171 lr
= *(db_addr_t
*)(frame
+ 4) - 4;
172 if ((lr
& 3) || (lr
< 0x100)) {
173 (*pr
)("saved LR(0x%x) is invalid.", lr
);
177 (*pr
)("0x%08lx: ", frame
);
178 if (lr
+ 4 == (db_addr_t
) trapexit
||
179 lr
+ 4 == (db_addr_t
) sctrapexit
) {
181 struct trapframe
*tf
= (struct trapframe
*) (frame
+8);
182 (*pr
)("%s ", tf
->srr1
& PSL_PR
? "user" : "kernel");
183 if (lr
+ 4 == (db_addr_t
) sctrapexit
) {
184 (*pr
)("SC trap #%d by ", tf
->fixreg
[0]);
190 (*pr
)("DSI %s trap @ %#x by ",
191 tf
->dsisr
& DSISR_STORE
? "write" : "read",
195 (*pr
)("DSI %s trap @ %#x by ",
196 tf
->tf_xtra
[TF_ESR
] & ESR_DST
? "write" : "read",
202 (*pr
)("ALI trap @ %#x (DSISR %#x) ",
206 trapstr
= "ALI"; break;
208 case EXC_ISI
: trapstr
= "ISI"; break;
209 case EXC_PGM
: trapstr
= "PGM"; break;
210 case EXC_SC
: trapstr
= "SC"; break;
211 case EXC_EXI
: trapstr
= "EXI"; break;
212 case EXC_MCHK
: trapstr
= "MCHK"; break;
213 case EXC_VEC
: trapstr
= "VEC"; break;
214 case EXC_FPU
: trapstr
= "FPU"; break;
215 case EXC_FPA
: trapstr
= "FPA"; break;
216 case EXC_DECR
: trapstr
= "DECR"; break;
217 case EXC_BPT
: trapstr
= "BPT"; break;
218 case EXC_TRC
: trapstr
= "TRC"; break;
219 case EXC_RUNMODETRC
: trapstr
= "RUNMODETRC"; break;
220 case EXC_PERF
: trapstr
= "PERF"; break;
221 case EXC_SMI
: trapstr
= "SMI"; break;
222 case EXC_RST
: trapstr
= "RST"; break;
223 default: trapstr
= NULL
; break;
225 if (trapstr
!= NULL
) {
226 (*pr
)("%s trap by ", trapstr
);
228 (*pr
)("trap %#x by ", tf
->exc
);
231 lr
= (db_addr_t
) tf
->srr0
;
234 if (in_kernel
&& (tf
->srr1
& PSL_PR
) == 0) {
235 sym
= db_search_symbol(lr
, DB_STGY_ANY
, &diff
);
236 db_symbol_values(sym
, &symname
, 0);
238 if (symname
== NULL
|| !strcmp(symname
, "end")) {
239 (*pr
)("%p: srr1=%#x\n", lr
, tf
->srr1
);
241 (*pr
)("%s+%#x: srr1=%#x\n", symname
,
244 (*pr
)("%-10s r1=%#x cr=%#x xer=%#x ctr=%#x",
245 "", tf
->fixreg
[1], tf
->cr
, tf
->xer
, tf
->ctr
);
247 if (tf
->exc
== EXC_DSI
)
248 (*pr
)(" dsisr=%#x", tf
->dsisr
);
250 if ((mfpvr() >> 16) == MPC601
)
251 (*pr
)(" mq=%#x", tf
->tf_xtra
[TF_MQ
]);
252 #endif /* PPC_OEA601 */
255 if (tf
->exc
== EXC_DSI
)
256 (*pr
)(" dear=%#x", tf
->dar
);
257 (*pr
)(" esr=%#x pid=%#x", tf
->tf_xtra
[TF_ESR
],
258 tf
->tf_xtra
[TF_PID
]);
261 frame
= (db_addr_t
) tf
->fixreg
[1];
262 in_kernel
= !(tf
->srr1
& PSL_PR
);
263 if (kernel_only
&& !in_kernel
)
271 sym
= db_search_symbol(lr
, DB_STGY_ANY
, &diff
);
272 db_symbol_values(sym
, &symname
, 0);
274 if (symname
== NULL
|| !strcmp(symname
, "end"))
277 (*pr
)("at %s+%#x", symname
, diff
);
279 /* Print all the args stored in that stackframe. */
280 (*pr
)("(%lx, %lx, %lx, %lx, %lx, %lx, %lx, %lx)",
281 args
[0], args
[1], args
[2], args
[3],
282 args
[4], args
[5], args
[6], args
[7]);