Skip site navigation (1)Skip section navigation (2)
Date:      08 Oct 2002 21:21:36 +0400
From:      "Vladimir B. " Grebenschikov <vova@sw.ru>
To:        freebsd-current@freebsd.org
Subject:   DDB sysctl function
Message-ID:  <1034097697.1548.2.camel@vbook.express.ru>

next in thread | raw e-mail | index | archive | help

--=-l9bQ/IFxPn7nk786T9io
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi 

Attached diff introduces new ddb interface - access to sysctl interface 

sysctl  - read sysctl value 
sysctlw - write sysctl value 

Example: 

Translate string to sysctl MIB: 

db> sysctlw 0.3 hw\.model 
0xcd1aaeec: 6 2 
db> 

Now get string by this MIB: 

db> sysctl 6.2 s 
0xcd1ab24: Pentium II/Pentium II Xenon/Celeron 
db> 

Or get vm.kvm_free 
db> sysctlw 0.3 vm\.kvm_free 
0xcd1aaeec: 2	2da 
db> sysctl 2.2da 
0xcd1ab2f4: 3800000 
db> 

This interface useful to inspect/change data easy accessible through
sysctl and hard accessible directly (say dynamic sysctl-mapped data, or
sysctl-mapped fields in complex structures).

Comments appreciated. 

-- 
Vladimir B. Grebenschikov
vova@sw.ru, SWsoft, Inc.

--=-l9bQ/IFxPn7nk786T9io
Content-Disposition: attachment; filename=ddb_sysctl.diff
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=ddb_sysctl.diff; charset=KOI8-R

Index: conf/files
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /ext/ncvs/src/sys/conf/files,v
retrieving revision 1.713
diff -u -r1.713 files
--- conf/files	5 Oct 2002 16:35:26 -0000	1.713
+++ conf/files	8 Oct 2002 12:24:14 -0000
@@ -218,6 +218,7 @@
 ddb/db_variables.c	optional ddb
 ddb/db_watch.c		optional ddb
 ddb/db_write_cmd.c	optional ddb
+ddb/db_sysctl_cmd.c	optional ddb
 dev/aac/aac.c		optional aac
 dev/aac/aac_debug.c	optional aac
 dev/aac/aac_disk.c	optional aac
Index: ddb/db_command.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /ext/ncvs/src/sys/ddb/db_command.c,v
retrieving revision 1.46
diff -u -r1.46 db_command.c
--- ddb/db_command.c	1 Oct 2002 21:59:46 -0000	1.46
+++ ddb/db_command.c	8 Oct 2002 12:22:58 -0000
@@ -422,6 +422,8 @@
 	{ "gdb",	db_gdb,			0,	0 },
 	{ "reset",	db_reset,		0,	0 },
 	{ "kill",	db_kill,		CS_OWN,	0 },
+	{ "sysctl",     db_sysctl_cmd,          CS_OWN, 0 },
+	{ "sysctlw",    db_sysctlw_cmd,         CS_OWN, 0 },
 	{ (char *)0, }
 };
=20
Index: ddb/db_examine.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /ext/ncvs/src/sys/ddb/db_examine.c,v
retrieving revision 1.29
diff -u -r1.29 db_examine.c
--- ddb/db_examine.c	25 Jun 2002 15:59:24 -0000	1.29
+++ ddb/db_examine.c	8 Oct 2002 12:20:53 -0000
@@ -44,7 +44,7 @@
=20
 static char	db_examine_format[TOK_STRING_SIZE] =3D "x";
=20
-static void	db_examine(db_addr_t, char *, int);
+void	db_examine(db_addr_t, char *, int);
 static void	db_search(db_addr_t, int, db_expr_t, db_expr_t, u_int);
=20
 /*
@@ -67,7 +67,7 @@
 	db_examine((db_addr_t) addr, db_examine_format, count);
 }
=20
-static void
+void
 db_examine(addr, fmt, count)
 	register
 	db_addr_t	addr;
Index: ddb/db_sysctl_cmd.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: ddb/db_sysctl_cmd.c
diff -N ddb/db_sysctl_cmd.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ddb/db_sysctl_cmd.c	8 Oct 2002 16:30:16 -0000
@@ -0,0 +1,106 @@
+/*
+ * $FreeBSD$
+ */
+
+/*
+ *	Author: Potatin Mike, SW-Soft
+ *	Date:	10/2002
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+
+#include <ddb/ddb.h>
+
+#include <ddb/db_lex.h>
+#include <ddb/db_output.h>
+#include <ddb/db_command.h>
+#include <ddb/db_sym.h>
+#include <ddb/db_access.h>
+
+#include <sys/sysctl.h>
+#include <sys/proc.h>
+
+void    db_examine __P((db_addr_t, char *, int));
+
+void
+db_sysctlw_cmd(d1, d2, d3, d4)
+	db_expr_t	d1;
+	boolean_t	d2;
+	db_expr_t	d3;
+	char *		d4;
+{
+	int t;
+	int pcount;
+	int mib[128];
+	size_t ret =3D 0;
+	size_t readcount =3D 1024;
+	size_t wsize;
+	char wbuf[1024];
+	char buf[1024];
+	int err;
+
+	pcount =3D 0;
+	while((t =3D db_read_token()) =3D=3D tNUMBER) {
+		mib[pcount] =3D db_tok_number;
+		pcount++;
+		if((t =3D db_read_token()) !=3D tDOT) {
+			break;
+		}
+	}
+	switch (t) {
+		case tIDENT:
+			strcpy(wbuf, db_tok_string);
+			wsize =3D strlen(wbuf);
+			break;
+		case tNUMBER:
+			*(int*)wbuf =3D db_tok_number;
+			wsize =3D sizeof(int);
+			break;
+		default:
+			db_printf("no ident\n");
+			db_flush_lex();
+			return;
+	}
+	db_skip_to_eol();
+	if(((err =3D kernel_sysctl(FIRST_THREAD_IN_PROC(initproc), mib, pcount, b=
uf, &readcount, wbuf, wsize, &ret))) =3D=3D 0) {
+		db_examine((db_addr_t) buf, "x", ret/sizeof(int));
+	} else {
+		db_printf("sysctl error %d %d\n", err, ret);
+	}
+}
+void
+db_sysctl_cmd(d1, d2, d3, d4)
+	db_expr_t	d1;
+	boolean_t	d2;
+	db_expr_t	d3;
+	char *		d4;
+{
+	int t;
+	int pcount;
+	int mib[128];
+	size_t ret =3D 0;
+	size_t readcount =3D 1024;
+	char buf[1024];
+	int err;
+	char modif[16]=3D"x";
+
+	pcount =3D 0;
+	while((t =3D db_read_token()) =3D=3D tNUMBER) {
+		mib[pcount] =3D db_tok_number;
+		pcount++;
+		if((t =3D db_read_token()) !=3D tDOT) {
+			break;
+		}
+	}
+	if(t =3D=3D tIDENT) {
+		strncpy(modif, db_tok_string, 15);
+	}
+	db_skip_to_eol();
+
+	if(((err =3D kernel_sysctl(FIRST_THREAD_IN_PROC(initproc), mib, pcount, b=
uf, &readcount, NULL, 0, &ret))) =3D=3D 0) {
+		db_examine((db_addr_t) buf, modif, ret/sizeof(int));
+	} else {
+		db_printf("sysctl error %d %d\n", err, ret);
+	}
+}
Index: ddb/ddb.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /ext/ncvs/src/sys/ddb/ddb.h,v
retrieving revision 1.30
diff -u -r1.30 ddb.h
--- ddb/ddb.h	21 Sep 2002 17:29:36 -0000	1.30
+++ ddb/ddb.h	8 Oct 2002 12:23:47 -0000
@@ -125,6 +125,8 @@
 db_cmdfcn_t	db_trace_until_matching_cmd;
 db_cmdfcn_t	db_watchpoint_cmd;
 db_cmdfcn_t	db_write_cmd;
+db_cmdfcn_t     db_sysctl_cmd;
+db_cmdfcn_t     db_sysctlw_cmd;
=20
 #if 0
 db_cmdfcn_t	db_help_cmd;

--=-l9bQ/IFxPn7nk786T9io--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1034097697.1548.2.camel>