2 * Copyright (c) 2015 The FreeBSD Foundation
4 * This software was developed by Semihalf under
5 * the sponsorship of the FreeBSD Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/param.h>
35 #include <machine/pcb.h>
37 #include <ddb/db_sym.h>
39 #include <machine/armreg.h>
40 #include <machine/debug_monitor.h>
41 #include <machine/stack.h>
42 #include <machine/vmparam.h>
44 #define FRAME_NORMAL 0
47 #define FRAME_SERROR 3
48 #define FRAME_UNHANDLED 4
51 db_md_list_watchpoints(void)
54 dbg_show_watchpoint();
57 static void __nosanitizeaddress
58 db_stack_trace_cmd(struct thread *td, struct unwind_state *frame)
67 sym = db_search_symbol(frame->pc, DB_STGY_ANY, &offset);
68 if (sym == C_DB_SYM_NULL) {
72 db_symbol_values(sym, &name, &value);
74 db_printf("%s() at ", name);
75 db_printsym(frame->pc, DB_STGY_PROC);
78 if (strcmp(name, "handle_el0_sync") == 0 ||
79 strcmp(name, "handle_el1h_sync") == 0)
80 frame_type = FRAME_SYNC;
81 else if (strcmp(name, "handle_el0_irq") == 0 ||
82 strcmp(name, "handle_el1h_irq") == 0)
83 frame_type = FRAME_IRQ;
84 else if (strcmp(name, "handle_serror") == 0)
85 frame_type = FRAME_SERROR;
86 else if (strcmp(name, "handle_empty_exception") == 0)
87 frame_type = FRAME_UNHANDLED;
89 frame_type = FRAME_NORMAL;
91 if (frame_type != FRAME_NORMAL) {
94 tf = (struct trapframe *)(uintptr_t)frame->fp - 1;
95 if (!__is_aligned(tf, _Alignof(struct trapframe)) ||
96 !kstack_contains(td, (vm_offset_t)tf,
98 db_printf("--- invalid trapframe %p\n", tf);
102 switch (frame_type) {
104 db_printf("--- exception, esr %#lx\n",
108 db_printf("--- interrupt\n");
111 db_printf("--- system error, esr %#lx\n",
114 case FRAME_UNHANDLED:
115 db_printf("--- unhandled exception, esr %#lx\n",
119 __assert_unreachable();
123 frame->fp = tf->tf_x[29];
124 frame->pc = ADDR_MAKE_CANONICAL(tf->tf_elr);
125 if (!INKERNEL(frame->fp))
128 if (strcmp(name, "fork_trampoline") == 0)
131 if (!unwind_frame(td, frame))
137 int __nosanitizeaddress
138 db_trace_thread(struct thread *thr, int count)
140 struct unwind_state frame;
143 if (thr != curthread) {
144 ctx = kdb_thr_ctx(thr);
146 frame.fp = (uintptr_t)ctx->pcb_x[PCB_FP];
147 frame.pc = (uintptr_t)ctx->pcb_x[PCB_LR];
148 db_stack_trace_cmd(thr, &frame);
154 void __nosanitizeaddress
157 struct unwind_state frame;
159 frame.fp = (uintptr_t)__builtin_frame_address(0);
160 frame.pc = (uintptr_t)db_trace_self;
161 db_stack_trace_cmd(curthread, &frame);