1 /* $NetBSD: db_trace.c,v 1.8 2003/01/17 22:28:48 thorpej Exp $ */
4 * Copyright (c) 2000, 2001 Ben Harris
5 * Copyright (c) 1996 Scott K. Stevens
7 * Mach Operating System
8 * Copyright (c) 1991,1990 Carnegie Mellon University
11 * Permission to use, copy, modify and distribute this software and its
12 * documentation is hereby granted, provided that both the copyright
13 * notice and this permission notice appear in all copies of the
14 * software, derivative works or modified versions, and any portions
15 * thereof, and that both notices appear in supporting documentation.
17 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
18 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
19 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
21 * Carnegie Mellon requests users of this software to return to
23 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
24 * School of Computer Science
25 * Carnegie Mellon University
26 * Pittsburgh PA 15213-3890
28 * any improvements or extensions that they make and grant Carnegie the
29 * rights to redistribute these changes.
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/systm.h>
40 #include <sys/stack.h>
41 #include <machine/armreg.h>
42 #include <machine/asm.h>
43 #include <machine/cpufunc.h>
44 #include <machine/db_machdep.h>
45 #include <machine/pcb.h>
46 #include <machine/vmparam.h>
48 #include <ddb/db_access.h>
49 #include <ddb/db_sym.h>
50 #include <ddb/db_output.h>
52 #define INKERNEL(va) (((vm_offset_t)(va)) >= VM_MIN_KERNEL_ADDRESS)
55 * APCS stack frames are awkward beasts, so I don't think even trying to use
56 * a structure to represent them is a good idea.
58 * Here's the diagram from the APCS. Increasing address is _up_ the page.
60 * save code pointer [fp] <- fp points to here
61 * return link value [fp, #-4]
62 * return sp value [fp, #-8]
63 * return fp value [fp, #-12]
76 * The save code pointer points twelve bytes beyond the start of the
77 * code sequence (usually a single STM) that created the stack frame.
78 * We have to disassemble it if we want to know which of the optional
79 * fields are actually present.
88 db_stack_trace_cmd(db_expr_t addr, db_expr_t count)
90 u_int32_t *frame, *lastframe;
95 boolean_t kernel_only = TRUE;
98 frame = (u_int32_t *)addr;
100 scp_offset = -(get_pc_str_offset() >> 2);
102 while (count-- && frame != NULL && !db_pager_quit) {
110 * In theory, the SCP isn't guaranteed to be in the function
111 * that generated the stack frame. We hope for the best.
115 sym = db_search_symbol(scp, DB_STGY_ANY, &offset);
116 if (sym == C_DB_SYM_NULL) {
120 db_symbol_values(sym, &name, &value);
121 db_printf("%s() at ", name);
122 db_printsym(scp, DB_STGY_PROC);
125 db_printf("scp=0x%08x rlv=0x%08x (", scp, frame[FR_RLV] & R15_PC);
126 db_printsym(frame[FR_RLV] & R15_PC, DB_STGY_PROC);
129 db_printf("scp=0x%08x rlv=0x%08x (", scp, frame[FR_RLV]);
130 db_printsym(frame[FR_RLV], DB_STGY_PROC);
133 db_printf("\trsp=0x%08x rfp=0x%08x", frame[FR_RSP], frame[FR_RFP]);
135 savecode = ((u_int32_t *)scp)[scp_offset];
136 if ((savecode & 0x0e100000) == 0x08000000) {
137 /* Looks like an STM */
140 for (r = 10; r >= 0; r--) {
141 if (savecode & (1 << r)) {
142 db_printf("%sr%d=0x%08x",
144 sep = (frame - rp) % 4 == 2 ?
153 * Switch to next frame up
155 if (frame[FR_RFP] == 0)
156 break; /* Top of stack */
159 frame = (u_int32_t *)(frame[FR_RFP]);
161 if (INKERNEL((int)frame)) {
162 /* staying in kernel */
163 if (frame <= lastframe) {
164 db_printf("Bad frame pointer: %p\n", frame);
167 } else if (INKERNEL((int)lastframe)) {
168 /* switch from user to kernel */
170 break; /* kernel stack only */
173 if (frame <= lastframe) {
174 db_printf("Bad user frame pointer: %p\n",
184 db_md_list_watchpoints()
189 db_md_clr_watchpoint(db_expr_t addr, db_expr_t size)
195 db_md_set_watchpoint(db_expr_t addr, db_expr_t size)
201 db_trace_thread(struct thread *thr, int count)
205 if (thr == curthread)
206 addr = (uint32_t)__builtin_frame_address(0);
208 addr = thr->td_pcb->un_32.pcb32_r11;
209 db_stack_trace_cmd(addr, -1);
216 db_trace_thread(curthread, -1);
220 stack_save(struct stack *st)
226 frame = (u_int32_t *)__builtin_frame_address(0);
228 if (!INKERNEL(frame))
230 callpc = frame[FR_SCP];
231 if (stack_put(st, callpc) == -1)
233 frame = (u_int32_t *)(frame[FR_RFP]);