summaryrefslogtreecommitdiffstats
path: root/sys/sparc64
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2004-07-10 23:47:20 +0000
committermarcel <marcel@FreeBSD.org>2004-07-10 23:47:20 +0000
commitaae5483213805c645aad67985fa4f638d6e34915 (patch)
tree533bc344dcaf70d30b9a52c0dc5327488516647b /sys/sparc64
parent1dca995d693b9df1e65a294b6385cc1d442233b1 (diff)
downloadFreeBSD-src-aae5483213805c645aad67985fa4f638d6e34915.zip
FreeBSD-src-aae5483213805c645aad67985fa4f638d6e34915.tar.gz
Mega update for the KDB framework: turn DDB into a KDB backend.
Most of the changes are a direct result of adding thread awareness. Typically, DDB_REGS is gone. All registers are taken from the trapframe and backtraces use the PCB based contexts. DDB_REGS was defined to be a trapframe on all platforms anyway. Thread awareness introduces the following new commands: thread X switch to thread X (where X is the TID), show threads list all threads. The backtrace code has been made more flexible so that one can create backtraces for any thread by giving the thread ID as an argument to trace. With this change, ia64 has support for breakpoints.
Diffstat (limited to 'sys/sparc64')
-rw-r--r--sys/sparc64/include/db_machdep.h14
-rw-r--r--sys/sparc64/sparc64/db_interface.c79
-rw-r--r--sys/sparc64/sparc64/db_trace.c302
3 files changed, 178 insertions, 217 deletions
diff --git a/sys/sparc64/include/db_machdep.h b/sys/sparc64/include/db_machdep.h
index a31ec62..bb29deb 100644
--- a/sys/sparc64/include/db_machdep.h
+++ b/sys/sparc64/include/db_machdep.h
@@ -38,23 +38,19 @@
typedef vm_offset_t db_addr_t;
typedef long db_expr_t;
-typedef struct trapframe db_regs_t;
-extern db_regs_t ddb_regs;
-#define DDB_REGS (&ddb_regs)
-
-#define PC_REGS(regs) ((db_addr_t)(regs)->tf_tpc)
+#define PC_REGS() ((db_addr_t)kdb_thrctx->pcb_pc)
#define BKPT_INST (0x91d03001)
#define BKPT_SIZE (4)
#define BKPT_SET(inst) (BKPT_INST)
#define BKPT_SKIP do { \
- ddb_regs.tf_tpc = ddb_regs.tf_tnpc + 4; \
- ddb_regs.tf_tnpc += 8; \
+ kdb_frame->tf_tpc = kdb_frame->tf_tnpc + 4; \
+ kdb_frame->tf_tnpc += 8; \
} while (0)
-#define db_clear_single_step(regs)
-#define db_set_single_step(regs)
+#define db_clear_single_step kdb_cpu_clear_singlestep
+#define db_set_single_step kdb_cpu_set_singlestep
#define IS_BREAKPOINT_TRAP(type, code) (type == T_BREAKPOINT)
#define IS_WATCHPOINT_TRAP(type, code) (0)
diff --git a/sys/sparc64/sparc64/db_interface.c b/sys/sparc64/sparc64/db_interface.c
index b6a1e20..77e1493 100644
--- a/sys/sparc64/sparc64/db_interface.c
+++ b/sys/sparc64/sparc64/db_interface.c
@@ -30,6 +30,7 @@
#include <sys/systm.h>
#include <sys/reboot.h>
#include <sys/cons.h>
+#include <sys/kdb.h>
#include <sys/ktr.h>
#include <sys/linker_set.h>
#include <sys/lock.h>
@@ -51,66 +52,42 @@
#include <machine/atomic.h>
#include <machine/setjmp.h>
-static jmp_buf *db_nofault = 0;
-extern jmp_buf db_jmpbuf;
-
-int db_active;
-db_regs_t ddb_regs;
-
-static jmp_buf db_global_jmpbuf;
-static int db_global_jmpbuf_valid;
-
int
-kdb_trap(struct trapframe *tf)
-{
-
- if (db_global_jmpbuf_valid)
- longjmp(db_global_jmpbuf, 1);
- flushw();
- ddb_regs = *tf;
- critical_enter();
- setjmp(db_global_jmpbuf);
- db_global_jmpbuf_valid = TRUE;
- atomic_add_acq_int(&db_active, 1);
-#ifdef SMP
- stop_cpus(PCPU_GET(other_cpus));
-#endif
- cndbctl(TRUE);
- db_trap(tf->tf_type, 0);
- cndbctl(FALSE);
- db_active--;
-#ifdef SMP
- restart_cpus(stopped_cpus);
-#endif
- db_global_jmpbuf_valid = FALSE;
- critical_exit();
- *tf = ddb_regs;
- TF_DONE(tf);
- return (1);
-}
-
-void
db_read_bytes(vm_offset_t addr, size_t size, char *data)
{
+ jmp_buf jb;
+ void *prev_jb;
char *src;
-
- db_nofault = &db_jmpbuf;
- src = (char *)addr;
- while (size-- > 0)
- *data++ = *src++;
- db_nofault = NULL;
+ int ret;
+
+ prev_jb = kdb_jmpbuf(jb);
+ ret = setjmp(jb);
+ if (ret == 0) {
+ src = (char *)addr;
+ while (size-- > 0)
+ *data++ = *src++;
+ }
+ (void)kdb_jmpbuf(prev_jb);
+ return (ret);
}
-void
+int
db_write_bytes(vm_offset_t addr, size_t size, char *data)
{
+ jmp_buf jb;
+ void *prev_jb;
char *dst;
-
- db_nofault = &db_jmpbuf;
- dst = (char *)addr;
- while (size-- > 0)
- *dst++ = *data++;
- db_nofault = NULL;
+ int ret;
+
+ prev_jb = kdb_jmpbuf(jb);
+ ret = setjmp(jb);
+ if (ret == 0) {
+ dst = (char *)addr;
+ while (size-- > 0)
+ *dst++ = *data++;
+ }
+ (void)kdb_jmpbuf(prev_jb);
+ return (ret);
}
void
diff --git a/sys/sparc64/sparc64/db_trace.c b/sys/sparc64/sparc64/db_trace.c
index c57223f..ae53841 100644
--- a/sys/sparc64/sparc64/db_trace.c
+++ b/sys/sparc64/sparc64/db_trace.c
@@ -28,6 +28,7 @@
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/kdb.h>
#include <sys/linker_set.h>
#include <sys/proc.h>
#include <sys/sysent.h>
@@ -47,138 +48,89 @@
#include <ddb/db_variables.h>
#include <ddb/db_watch.h>
-static int db_print_trap(struct thread *td, struct trapframe *);
-static void db_utrace(struct thread *td, struct trapframe *tf);
-
#define INKERNEL(va) \
((va) >= VM_MIN_KERNEL_ADDRESS && (va) <= VM_MAX_KERNEL_ADDRESS)
+static db_varfcn_t db_frame;
+
+#define DB_OFFSET(x) (db_expr_t *)offsetof(struct trapframe, x)
struct db_variable db_regs[] = {
- { "g0", &ddb_regs.tf_global[0], FCN_NULL },
- { "g1", &ddb_regs.tf_global[1], FCN_NULL },
- { "g2", &ddb_regs.tf_global[2], FCN_NULL },
- { "g3", &ddb_regs.tf_global[3], FCN_NULL },
- { "g4", &ddb_regs.tf_global[4], FCN_NULL },
- { "g5", &ddb_regs.tf_global[5], FCN_NULL },
- { "g6", &ddb_regs.tf_global[6], FCN_NULL },
- { "g7", &ddb_regs.tf_global[7], FCN_NULL },
- { "i0", &ddb_regs.tf_out[0], FCN_NULL },
- { "i1", &ddb_regs.tf_out[1], FCN_NULL },
- { "i2", &ddb_regs.tf_out[2], FCN_NULL },
- { "i3", &ddb_regs.tf_out[3], FCN_NULL },
- { "i4", &ddb_regs.tf_out[4], FCN_NULL },
- { "i5", &ddb_regs.tf_out[5], FCN_NULL },
- { "i6", &ddb_regs.tf_out[6], FCN_NULL },
- { "i7", &ddb_regs.tf_out[7], FCN_NULL },
- { "tnpc", &ddb_regs.tf_tnpc, FCN_NULL },
- { "tpc", &ddb_regs.tf_tpc, FCN_NULL },
- { "tstate", &ddb_regs.tf_tstate, FCN_NULL },
+ { "g0", DB_OFFSET(tf_global[0]), db_frame },
+ { "g1", DB_OFFSET(tf_global[1]), db_frame },
+ { "g2", DB_OFFSET(tf_global[2]), db_frame },
+ { "g3", DB_OFFSET(tf_global[3]), db_frame },
+ { "g4", DB_OFFSET(tf_global[4]), db_frame },
+ { "g5", DB_OFFSET(tf_global[5]), db_frame },
+ { "g6", DB_OFFSET(tf_global[6]), db_frame },
+ { "g7", DB_OFFSET(tf_global[7]), db_frame },
+ { "i0", DB_OFFSET(tf_out[0]), db_frame },
+ { "i1", DB_OFFSET(tf_out[1]), db_frame },
+ { "i2", DB_OFFSET(tf_out[2]), db_frame },
+ { "i3", DB_OFFSET(tf_out[3]), db_frame },
+ { "i4", DB_OFFSET(tf_out[4]), db_frame },
+ { "i5", DB_OFFSET(tf_out[5]), db_frame },
+ { "i6", DB_OFFSET(tf_out[6]), db_frame },
+ { "i7", DB_OFFSET(tf_out[7]), db_frame },
+ { "tnpc", DB_OFFSET(tf_tnpc), db_frame },
+ { "tpc", DB_OFFSET(tf_tpc), db_frame },
+ { "tstate", DB_OFFSET(tf_tstate), db_frame },
};
struct db_variable *db_eregs = db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
-void
-db_stack_trace_cmd(db_expr_t addr, boolean_t have_addr, db_expr_t count,
- char *modif)
+static int
+db_frame(struct db_variable *vp, db_expr_t *valuep, int op)
{
- struct trapframe *tf;
- struct frame *fp;
- struct proc *p;
- struct thread *td;
- const char *name;
- c_db_sym_t sym;
- db_expr_t offset;
- db_expr_t value;
- db_addr_t npc;
- db_addr_t pc;
- int trap;
- int user;
- pid_t pid;
+ uint64_t *reg;
- trap = 0;
- user = 0;
- npc = 0;
- if (count == -1)
- count = 1024;
- td = curthread;
- p = td->td_proc;
- /*
- * Provide an /a modifier to pass the stack address instead of a PID
- * as argument.
- * Note that, if this address is not on the stack of curthread, the
- * printed data may be wrong (at the moment, this applies only to the
- * sysent list).
- */
- if (!have_addr)
- addr = DDB_REGS->tf_out[6];
- else if (strcmp(modif, "a") != 0) {
- /*
- * addr was parsed as hex, convert so it is interpreted as
- * decimal (ugh).
- */
- pid = (addr % 16) + ((addr >> 4) % 16) * 10 +
- ((addr >> 8) % 16) * 100 + ((addr >> 12) % 16) * 1000 +
- ((addr >> 16) % 16) * 10000;
- /*
- * The pcb for curproc is not valid at this point,
- * so fall back to the default case.
- */
- if (pid == curthread->td_proc->p_pid) {
- td = curthread;
- p = td->td_proc;
- addr = DDB_REGS->tf_out[6];
- } else {
- /* sx_slock(&allproc_lock); */
- LIST_FOREACH(p, &allproc, p_list) {
- if (p->p_pid == pid)
- break;
- }
- /* sx_sunlock(&allproc_lock); */
- if (p == NULL) {
- db_printf("pid %d not found\n", pid);
- return;
- }
- if ((p->p_sflag & PS_INMEM) == 0) {
- db_printf("pid %d swapped out\n", pid);
- return;
- }
- td = FIRST_THREAD_IN_PROC(p); /* XXXKSE */
- addr = td->td_pcb->pcb_sp;
- }
- }
- fp = (struct frame *)(addr + SPOFF);
+ if (kdb_frame == NULL)
+ return (0);
+ reg = (uint64_t*)((uintptr_t)kdb_frame + (uintptr_t)vp->valuep);
+ if (op == DB_VAR_GET)
+ *valuep = *reg;
+ else
+ *reg = *valuep;
+ return (1);
+}
- while (count-- && !user) {
- pc = (db_addr_t)db_get_value((db_addr_t)&fp->fr_pc,
- sizeof(fp->fr_pc), FALSE);
- if (trap) {
- pc = npc;
- trap = 0;
+/*
+ * User stack trace (debugging aid).
+ */
+static void
+db_utrace(struct thread *td, struct trapframe *tf)
+{
+ struct pcb *pcb;
+ db_addr_t sp, rsp, o7, pc;
+ int i, found;
+
+ pcb = td->td_pcb;
+ sp = db_get_value((db_addr_t)&tf->tf_sp, sizeof(tf->tf_sp), FALSE);
+ o7 = db_get_value((db_addr_t)&tf->tf_out[7], sizeof(tf->tf_out[7]),
+ FALSE);
+ pc = db_get_value((db_addr_t)&tf->tf_tpc, sizeof(tf->tf_tpc), FALSE);
+ db_printf("user trace: trap %%o7=%#lx\n", o7);
+ while (sp != 0) {
+ db_printf("pc %#lx, sp %#lx\n", pc, sp);
+ /* First, check whether the frame is in the pcb. */
+ found = 0;
+ for (i = 0; i < pcb->pcb_nsaved; i++) {
+ if (pcb->pcb_rwsp[i] == sp) {
+ found = 1;
+ sp = pcb->pcb_rw[i].rw_in[6];
+ pc = pcb->pcb_rw[i].rw_in[7];
+ break;
+ }
}
- if (!INKERNEL((vm_offset_t)pc))
- break;
- sym = db_search_symbol(pc, DB_STGY_ANY, &offset);
- if (sym == C_DB_SYM_NULL) {
- value = 0;
- name = NULL;
- } else
- db_symbol_values(sym, &name, &value);
- if (name == NULL)
- name = "(null)";
- fp = (struct frame *)(db_get_value((db_addr_t)&fp->fr_fp,
- sizeof(fp->fr_fp), FALSE) + SPOFF);
- if (bcmp(name, "tl0_", 4) == 0 ||
- bcmp(name, "tl1_", 4) == 0) {
- tf = (struct trapframe *)(fp + 1);
- npc = db_get_value((db_addr_t)&tf->tf_tpc,
- sizeof(tf->tf_tpc), FALSE);
- user = db_print_trap(td, tf);
- trap = 1;
- } else {
- db_printf("%s() at ", name);
- db_printsym(pc, DB_STGY_PROC);
- db_printf("\n");
+ if (!found) {
+ rsp = sp + SPOFF;
+ sp = 0;
+ if (copyin((void *)(rsp + offsetof(struct frame, fr_fp)),
+ &sp, sizeof(sp)) != 0 ||
+ copyin((void *)(rsp + offsetof(struct frame, fr_pc)),
+ &pc, sizeof(pc)) != 0)
+ break;
}
}
+ db_printf("done\n");
}
static int
@@ -265,52 +217,88 @@ db_print_trap(struct thread *td, struct trapframe *tf)
return (user);
}
-/*
- * User stack trace (debugging aid).
- */
-static void
-db_utrace(struct thread *td, struct trapframe *tf)
+static int
+db_backtrace(struct thread *td, struct frame *fp, int count)
{
- struct pcb *pcb;
- db_addr_t sp, rsp, o7, pc;
- int i, found;
+ struct trapframe *tf;
+ const char *name;
+ c_db_sym_t sym;
+ db_expr_t offset;
+ db_expr_t value;
+ db_addr_t npc;
+ db_addr_t pc;
+ int trap;
+ int user;
- pcb = td->td_pcb;
- sp = db_get_value((db_addr_t)&tf->tf_sp, sizeof(tf->tf_sp), FALSE);
- o7 = db_get_value((db_addr_t)&tf->tf_out[7], sizeof(tf->tf_out[7]),
- FALSE);
- pc = db_get_value((db_addr_t)&tf->tf_tpc, sizeof(tf->tf_tpc), FALSE);
- db_printf("user trace: trap %%o7=%#lx\n", o7);
- while (sp != 0) {
- db_printf("pc %#lx, sp %#lx\n", pc, sp);
- /* First, check whether the frame is in the pcb. */
- found = 0;
- for (i = 0; i < pcb->pcb_nsaved; i++) {
- if (pcb->pcb_rwsp[i] == sp) {
- found = 1;
- sp = pcb->pcb_rw[i].rw_in[6];
- pc = pcb->pcb_rw[i].rw_in[7];
- break;
- }
+ if (count == -1)
+ count = 1024;
+
+ trap = 0;
+ user = 0;
+ npc = 0;
+ while (count-- && !user) {
+ pc = (db_addr_t)db_get_value((db_addr_t)&fp->fr_pc,
+ sizeof(fp->fr_pc), FALSE);
+ if (trap) {
+ pc = npc;
+ trap = 0;
}
- if (!found) {
- rsp = sp + SPOFF;
- sp = 0;
- if (copyin((void *)(rsp + offsetof(struct frame, fr_fp)),
- &sp, sizeof(sp)) != 0 ||
- copyin((void *)(rsp + offsetof(struct frame, fr_pc)),
- &pc, sizeof(pc)) != 0)
- break;
+ if (!INKERNEL((vm_offset_t)pc))
+ break;
+ sym = db_search_symbol(pc, DB_STGY_ANY, &offset);
+ if (sym == C_DB_SYM_NULL) {
+ value = 0;
+ name = NULL;
+ } else
+ db_symbol_values(sym, &name, &value);
+ if (name == NULL)
+ name = "(null)";
+ fp = (struct frame *)(db_get_value((db_addr_t)&fp->fr_fp,
+ sizeof(fp->fr_fp), FALSE) + SPOFF);
+ if (bcmp(name, "tl0_", 4) == 0 ||
+ bcmp(name, "tl1_", 4) == 0) {
+ tf = (struct trapframe *)(fp + 1);
+ npc = db_get_value((db_addr_t)&tf->tf_tpc,
+ sizeof(tf->tf_tpc), FALSE);
+ user = db_print_trap(td, tf);
+ trap = 1;
+ } else {
+ db_printf("%s() at ", name);
+ db_printsym(pc, DB_STGY_PROC);
+ db_printf("\n");
}
}
- db_printf("done\n");
+ return (0);
}
void
-db_print_backtrace(void)
+db_stack_trace_cmd(db_expr_t addr, boolean_t have_addr, db_expr_t count,
+ char *modif)
+{
+ struct thread *td;
+
+ td = (have_addr) ? kdb_thr_lookup(addr) : kdb_thread;
+ if (td == NULL) {
+ db_printf("Thread %d not found\n", (int)addr);
+ return;
+ }
+ db_trace_thread(td, count);
+}
+
+void
+db_trace_self(void)
+{
+ db_expr_t addr;
+
+ addr = (db_expr_t)__builtin_frame_address(1);
+ db_backtrace(curthread, (struct frame *)(addr + SPOFF), -1);
+}
+
+int
+db_trace_thread(struct thread *td, int count)
{
- u_long *sp;
+ struct pcb *ctx;
- sp = __builtin_frame_address(1);
- db_stack_trace_cmd((db_expr_t)sp, TRUE, -1, "a");
+ ctx = kdb_thr_ctx(td);
+ return (db_backtrace(td, (struct frame*)(ctx->pcb_sp + SPOFF), count));
}
OpenPOWER on IntegriCloud