2 * Copyright (c) 2003, 2004 Marcel Moolenaar
3 * Copyright (c) 2000-2001 Doug Rabson
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/param.h>
33 #include <sys/stack.h>
35 #include <machine/db_machdep.h>
36 #include <machine/frame.h>
37 #include <machine/md_var.h>
38 #include <machine/pcb.h>
39 #include <machine/unwind.h>
40 #include <machine/vmparam.h>
43 #include <ddb/db_sym.h>
44 #include <ddb/db_access.h>
45 #include <ddb/db_variables.h>
46 #include <ddb/db_output.h>
48 int db_md_set_watchpoint(db_expr_t addr, db_expr_t size);
49 int db_md_clr_watchpoint(db_expr_t addr, db_expr_t size);
50 void db_md_list_watchpoints(void);
53 db_backtrace(struct thread *td, struct pcb *pcb, int count)
55 struct unw_regstate rs;
59 uint64_t bsp, cfm, ip, pfs, reg, sp;
61 int args, error, i, quit;
64 db_setup_paging(db_simple_pager, &quit, db_lines_per_page);
65 error = unw_create_from_pcb(&rs, pcb);
66 while (!error && count-- && !quit) {
67 error = unw_get_cfm(&rs, &cfm);
69 error = unw_get_bsp(&rs, &bsp);
71 error = unw_get_ip(&rs, &ip);
73 error = unw_get_sp(&rs, &sp);
77 args = IA64_CFM_SOL(cfm);
81 error = unw_step(&rs);
83 if (!unw_get_cfm(&rs, &pfs)) {
84 i = IA64_CFM_SOF(pfs) - IA64_CFM_SOL(pfs);
90 sym = db_search_symbol(ip, DB_STGY_ANY, &offset);
91 db_symbol_values(sym, &name, NULL);
92 db_printf("%s(", name);
93 if (bsp >= IA64_RR_BASE(5)) {
94 for (i = 0; i < args; i++) {
95 if ((bsp & 0x1ff) == 0x1f8)
97 db_read_bytes(bsp, sizeof(reg), (void*)®);
100 db_printf("0x%lx", reg);
107 db_printsym(ip, DB_STGY_PROC);
110 if (error != ERESTART)
112 if (sp < IA64_RR_BASE(5))
115 tf = (struct trapframe *)(sp + 16);
116 if ((tf->tf_flags & FRAME_SYSCALL) != 0 ||
117 tf->tf_special.iip < IA64_RR_BASE(5))
120 /* XXX ask if we should unwind across the trapframe. */
121 db_printf("--- trapframe at %p\n", tf);
123 error = unw_create_from_frame(&rs, tf);
128 * EJUSTRETURN and ERESTART signal the end of a trace and
129 * are not really errors.
131 return ((error > 0) ? error : 0);
140 db_backtrace(curthread, &pcb, -1);
144 db_trace_thread(struct thread *td, int count)
148 ctx = kdb_thr_ctx(td);
149 return (db_backtrace(td, ctx, count));
153 stack_save(struct stack *st)
159 * Is libuwx reentrant?
160 * Can unw_create* sleep?
165 db_md_set_watchpoint(addr, size)
174 db_md_clr_watchpoint(addr, size)
183 db_md_list_watchpoints()