PERFORCE change 52048 for review
Marcel Moolenaar
marcel at FreeBSD.org
Sat May 1 14:54:40 PDT 2004
http://perforce.freebsd.org/chv.cgi?CH=52048
Change 52048 by marcel at marcel_nfs on 2004/05/01 14:54:36
Add 3 sysctls:
debug.kdb.available - this lists the availably KDB
backends (RO).
debug.kdb.current - the current backend (RW).
debug.kdb.enter - enter KDB when written to.
These sysctls replace debug.enter_debugger.
Affected files ...
.. //depot/projects/gdb/sys/kern/subr_kdb.c#11 edit
Differences ...
==== //depot/projects/gdb/sys/kern/subr_kdb.c#11 (text+ko) ====
@@ -31,9 +31,11 @@
#include <sys/systm.h>
#include <sys/kdb.h>
#include <sys/kernel.h>
+#include <sys/malloc.h>
#include <sys/pcpu.h>
#include <sys/proc.h>
#include <sys/smp.h>
+#include <sys/sysctl.h>
#include <machine/kdb.h>
@@ -46,6 +48,94 @@
KDB_BACKEND(null, NULL, NULL, NULL);
SET_DECLARE(kdb_dbbe_set, struct kdb_dbbe);
+static int kdb_sysctl_available(SYSCTL_HANDLER_ARGS);
+static int kdb_sysctl_current(SYSCTL_HANDLER_ARGS);
+static int kdb_sysctl_enter(SYSCTL_HANDLER_ARGS);
+
+SYSCTL_NODE(_debug, OID_AUTO, kdb, CTLFLAG_RW, NULL, "KDB nodes");
+
+SYSCTL_PROC(_debug_kdb, OID_AUTO, available, CTLTYPE_STRING | CTLFLAG_RD, 0, 0,
+ kdb_sysctl_available, "A", "list of available KDB backends");
+
+SYSCTL_PROC(_debug_kdb, OID_AUTO, current, CTLTYPE_STRING | CTLFLAG_RW, 0, 0,
+ kdb_sysctl_current, "A", "currently selected KDB backend");
+
+SYSCTL_PROC(_debug_kdb, OID_AUTO, enter, CTLTYPE_INT | CTLFLAG_RW, 0, 0,
+ kdb_sysctl_enter, "I", "set to enter the debugger");
+
+static int
+kdb_sysctl_available(SYSCTL_HANDLER_ARGS)
+{
+ struct kdb_dbbe *be, **iter;
+ char *avail, *p;
+ ssize_t len, sz;
+ int error;
+
+ sz = 0;
+ SET_FOREACH(iter, kdb_dbbe_set) {
+ be = *iter;
+ if (be->dbbe_active == 0)
+ sz += strlen(be->dbbe_name) + 1;
+ }
+ sz++;
+ avail = malloc(sz, M_TEMP, M_WAITOK);
+ p = avail;
+ SET_FOREACH(iter, kdb_dbbe_set) {
+ be = *iter;
+ if (be->dbbe_active == 0) {
+ len = snprintf(p, sz, "%s ", be->dbbe_name);
+ p += len;
+ sz -= len;
+ }
+ }
+ KASSERT(sz >= 0, ("%s", __func__));
+ error = sysctl_handle_string(oidp, avail, 0, req);
+ free(avail, M_TEMP);
+ return (error);
+}
+
+static int
+kdb_sysctl_current(SYSCTL_HANDLER_ARGS)
+{
+ char buf[16];
+ struct kdb_dbbe *be, **iter;
+ int error;
+
+ strncpy(buf, kdb_dbbe->dbbe_name, sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
+ if (error != 0 || req->newptr == NULL)
+ return (error);
+ if (kdb_active)
+ return (EBUSY);
+ SET_FOREACH(iter, kdb_dbbe_set) {
+ be = *iter;
+ if (be->dbbe_active == 0 && strcmp(be->dbbe_name, buf) == 0) {
+ kdb_dbbe = be;
+ return (0);
+ }
+ }
+ return (EINVAL);
+}
+
+static int
+kdb_sysctl_enter(SYSCTL_HANDLER_ARGS)
+{
+ int error, i;
+
+ error = sysctl_wire_old_buffer(req, sizeof(int));
+ if (error == 0) {
+ i = 0;
+ error = sysctl_handle_int(oidp, &i, 0, req);
+ }
+ if (error != 0 || req->newptr == NULL)
+ return (error);
+ if (kdb_active)
+ return (EBUSY);
+ kdb_enter("sysctl debug.kdb.enter");
+ return (0);
+}
+
/*
* Solaris implements a new BREAK which is initiated by a character sequence
* CR ~ ^b which is similar to a familiar pattern used on Sun servers by the
More information about the p4-projects
mailing list