summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoruwe <uwe@openbsd.org>2006-11-28 18:56:17 +0000
committeruwe <uwe@openbsd.org>2006-11-28 18:56:17 +0000
commit20d7efdce3ea0f3c8970df03ae70a4d1cc4ac14c (patch)
treeb875a5ca9359652f180892a7d764d477f8913092
parentfix the installation guide of the Thecus boxes by (diff)
downloadwireguard-openbsd-20d7efdce3ea0f3c8970df03ae70a4d1cc4ac14c.tar.xz
wireguard-openbsd-20d7efdce3ea0f3c8970df03ae70a4d1cc4ac14c.zip
Support "trace /p <pid>" to show the stack trace of any process.
(Keep in mind that $radix is 0x10 by default.); ok by many
-rw-r--r--share/man/man4/ddb.413
-rw-r--r--sys/arch/i386/i386/db_trace.c15
2 files changed, 25 insertions, 3 deletions
diff --git a/share/man/man4/ddb.4 b/share/man/man4/ddb.4
index cee0a3f8e33..28598799f30 100644
--- a/share/man/man4/ddb.4
+++ b/share/man/man4/ddb.4
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ddb.4,v 1.47 2006/07/06 18:16:19 miod Exp $
+.\" $OpenBSD: ddb.4,v 1.48 2006/11/28 18:56:17 uwe Exp $
.\" $NetBSD: ddb.4,v 1.5 1994/11/30 16:22:09 jtc Exp $
.\"
.\" Mach Operating System
@@ -531,12 +531,21 @@ command is a synonym for
.\" --------------------
.It Xo
.Ic trace
-.Op Cm /u
+.Op Cm /pu
.Op Ar frameaddr Ns
.Op Ic \&, Ns Ar count
.Xc
Show the stack trace.
The
+.Cm /p
+modifier interprets the
+.Ar frameaddr
+argument as the PID of a process and shows the stack trace of
+that process.
+The
+.Cm /p
+modifier is not supported on all platforms.
+The
.Cm /u
modifier shows the stack trace of user space;
if omitted, the kernel stack is traced instead.
diff --git a/sys/arch/i386/i386/db_trace.c b/sys/arch/i386/i386/db_trace.c
index 81ab9296920..8bff4455178 100644
--- a/sys/arch/i386/i386/db_trace.c
+++ b/sys/arch/i386/i386/db_trace.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_trace.c,v 1.12 2006/09/19 11:06:33 jsg Exp $ */
+/* $OpenBSD: db_trace.c,v 1.13 2006/11/28 18:56:17 uwe Exp $ */
/* $NetBSD: db_trace.c,v 1.18 1996/05/03 19:42:01 christos Exp $ */
/*
@@ -30,6 +30,7 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
+#include <sys/user.h>
#include <machine/db_machdep.h>
@@ -184,6 +185,7 @@ db_stack_trace_print(db_expr_t addr, boolean_t have_addr, db_expr_t count,
int is_trap = 0;
boolean_t kernel_only = TRUE;
boolean_t trace_thread = FALSE;
+ boolean_t trace_proc = FALSE;
#if 0
if (!db_trace_symbols_found)
@@ -197,6 +199,8 @@ db_stack_trace_print(db_expr_t addr, boolean_t have_addr, db_expr_t count,
while ((c = *cp++) != 0) {
if (c == 't')
trace_thread = TRUE;
+ if (c == 'p')
+ trace_proc = TRUE;
if (c == 'u')
kernel_only = FALSE;
}
@@ -210,6 +214,15 @@ db_stack_trace_print(db_expr_t addr, boolean_t have_addr, db_expr_t count,
callpc = (db_addr_t)ddb_regs.tf_eip;
} else if (trace_thread) {
(*pr) ("db_trace.c: can't trace thread\n");
+ } else if (trace_proc) {
+ struct proc *p = pfind((pid_t)addr);
+ if (p == NULL) {
+ (*pr) ("db_trace.c: process not found\n");
+ return;
+ }
+ frame = (struct i386_frame *)p->p_addr->u_pcb.pcb_ebp;
+ callpc = (db_addr_t)
+ db_get_value((int)&frame->f_retaddr, 4, FALSE);
} else {
frame = (struct i386_frame *)addr;
callpc = (db_addr_t)