(1) Don't print the message buffer (via ddb's dmesg command) if the

message buffer has not yet been set up, mimicking code from the top of
the sysctl routine for retrieving the message buffer.

(2) Add a /l modifier to the trace command.  This makes it print the
backtrace using printf() instead of db_printf(), which has the nice
side-effect of also putting it into the message buffer.  A kernel with
ddb in it but disabled (ie, ddb.onpanic set to zero) will print a
backtrace (which ends up in the message buffer) before dumping (or
not, depending on the value of kern.dump_on_panic) and rebooting, but
if ddb is not disabled, the backtrace is not printed, and there's no
way to get it to display a backtrace such that you can retrieve it
after the dump.  The backtrace printed by gdb is sometimes a little
different.

(3) Documentation for the above.
This commit is contained in:
atatat 2003-05-15 13:18:18 +00:00
parent 804526377b
commit b5329c1d85
3 changed files with 35 additions and 9 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: ddb.4,v 1.64 2003/05/08 05:38:10 wiz Exp $
.\" $NetBSD: ddb.4,v 1.65 2003/05/15 13:18:19 atatat Exp $
.\"
.\" Copyright (c) 1997 - 2003 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -357,6 +357,10 @@ or by the breakpoint number returned by
if it's prefixed with
.Sq Cm \&# .
.It Xo
.Ic dmesg
.Xc
Prints the contents of the kernel message buffer.
.It Xo
.Ic dwatch
.Ar address
.Xc
@ -730,7 +734,8 @@ do the wrong thing.
.It Ic sync
Force a crash dump, and then reboot.
.It Xo
.Ic trace Ns Op Cm /u
.Ic trace
.Ic Ns Op Cm /u Ns Op Cm l
.Sm off
.Op Ar frame-address
.Op Cm , Ar count
@ -746,11 +751,15 @@ is the number of frames to be traced.
If
.Ar count
is omitted, all frames are printed.
If
.Cm /l
is specified, the trace is printed and also stored in the kernel
message buffer.
.Pp
Warning: user-space stack trace is valid only if the machine dependent
code supports it.
.It Xo
.Ic trace/t
.Ic trace/t Ns Op Cm l
.Sm off
.Op Ar pid
.Op Cm , Ar count
@ -771,7 +780,11 @@ with
.Sq 0t
to force it to be interpreted as decimal (see
.Sx VARIABLES
section for radix)
section for radix).
If
.Cm /l
is specified, the trace is printed and also stored in the kernel
message buffer.
.Pp
Warning: trace by pid is valid only if the machine dependent code
supports it.

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_command.c,v 1.69 2003/04/28 02:49:54 briggs Exp $ */
/* $NetBSD: db_command.c,v 1.70 2003/05/15 13:18:18 atatat Exp $ */
/*
* Mach Operating System
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.69 2003/04/28 02:49:54 briggs Exp $");
__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.70 2003/05/15 13:18:18 atatat Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@ -707,11 +707,19 @@ db_sifting_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
static void
db_stack_trace_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
{
register char *cp = modif;
register char c;
void (*pr)(const char *, ...);
pr = db_printf;
while ((c = *cp++) != 0)
if (c == 'l')
pr = printf;
if (count == -1)
count = 65535;
db_stack_trace_print(addr, have_addr, count, modif, db_printf);
db_stack_trace_print(addr, have_addr, count, modif, pr);
}
static void

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_xxx.c,v 1.21 2003/04/28 02:49:55 briggs Exp $ */
/* $NetBSD: db_xxx.c,v 1.22 2003/05/15 13:18:18 atatat Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1991, 1993
@ -43,7 +43,7 @@
#include "opt_kgdb.h"
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.21 2003/04/28 02:49:55 briggs Exp $");
__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.22 2003/05/15 13:18:18 atatat Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -237,6 +237,11 @@ db_dmesg(db_expr_t addr, int haddr, db_expr_t count, char *modif)
int ch, newl, skip, i;
char *p, *bufdata;
if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
db_printf("message buffer not available\n");
return;
}
mbp = msgbufp;
bufdata = &mbp->msg_bufc[0];