2 * Copyright (c) 2015 The FreeBSD Foundation
3 * Copyright (c) 2016 Ruslan Bukin <br@bsdpad.com>
6 * Portions of this software were developed by Semihalf under
7 * the sponsorship of the FreeBSD Foundation.
9 * Portions of this software were developed by SRI International and the
10 * University of Cambridge Computer Laboratory under DARPA/AFRL contract
11 * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.
13 * Portions of this software were developed by the University of Cambridge
14 * Computer Laboratory as part of the CTSRD Project, with support from the
15 * UK Higher Education Innovation Fund (HEIF).
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
41 #include <sys/param.h>
44 #include <machine/pcb.h>
46 #include <ddb/db_sym.h>
48 #include <machine/riscvreg.h>
49 #include <machine/stack.h>
52 db_md_list_watchpoints()
58 db_md_clr_watchpoint(db_expr_t addr, db_expr_t size)
65 db_md_set_watchpoint(db_expr_t addr, db_expr_t size)
72 db_stack_trace_cmd(struct unwind_state *frame)
83 if (unwind_frame(frame) < 0)
86 sym = db_search_symbol(pc, DB_STGY_ANY, &offset);
87 if (sym == C_DB_SYM_NULL) {
91 db_symbol_values(sym, &name, &value);
93 db_printf("%s() at ", name);
94 db_printsym(frame->pc, DB_STGY_PROC);
97 db_printf("\t pc = 0x%016lx ra = 0x%016lx\n",
99 db_printf("\t sp = 0x%016lx fp = 0x%016lx\n",
100 frame->sp, frame->fp);
106 db_trace_thread(struct thread *thr, int count)
108 struct unwind_state frame;
111 if (thr != curthread) {
112 ctx = kdb_thr_ctx(thr);
114 frame.sp = (uint64_t)ctx->pcb_sp;
115 frame.fp = (uint64_t)ctx->pcb_s[0];
116 frame.pc = (uint64_t)ctx->pcb_ra;
117 db_stack_trace_cmd(&frame);
126 struct unwind_state frame;
129 __asm __volatile("mv %0, sp" : "=&r" (sp));
132 frame.fp = (uint64_t)__builtin_frame_address(0);
133 frame.pc = (uint64_t)db_trace_self;
134 db_stack_trace_cmd(&frame);