χ Wed, 09.10.2002, Χ 01:03, Vladimir B. Grebenschikov ΞΑΠΙΣΑΜ:
> χ Tue, 08.10.2002, Χ 22:25, Maxime Henrion ΞΑΠΙΣΑΜ: 
> > Vladimir B.  Grebenschikov wrote:
> > > Hi 
> > > 
> > > Attached diff introduces new ddb interface - access to sysctl interface 
> > [...]
> > 
> > Looks like this would be very useful.  I have a few comments, mainly
> > about style though.
> 
> Attached fixed patch 

sorry, I have attached wong file 

 
> > - There is a TOK_STRING_SIZE macro which defines the size of the the
> >   db_tok_string variable.  Use it instead of declaring several 1k
> >   variables on the stack.
> 
> It is not token buffers - it is buffers for sysctl data interchange,
> const 1024 changed to SYSCTL_DATA_BUFSIZE define. 
> 
> > - I'm not sure if using the context of the init process to do sysctl
> >   calls is the right way to go.  However, it is not very clear what you
> >   should use to do this, at least to me.
> 
> kernel_sysctl need thread pointer, it may be used in sysctl handlers. 
> 
> > - You remove the "static" keyword for the db_examine() function to make
> >   it available in your code; that's OK, but you should then put the
> >   prototype in some header and not duplicate it in your code.
> > - Don't use the __P() macro, it is deprecated now and shouldn't be added
> >   in new code.
> > - Use the /usr/share/examples/etc/bsd-style-copyright file to put a
> >   proper copyright in your new files.  There is room for your name and
> >   the date there.
> > - Wrap lines at 80 characters. :-)
> 
> fixed
> 
> > Cheers,
> > Maxime

-- 
Vladimir B. Grebenschikov
[EMAIL PROTECTED], SWsoft, Inc.
Index: ddb/db_command.c
===================================================================
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 19:53:05 -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, }
 };
 
Index: ddb/db_examine.c
===================================================================
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 20:10:10 -0000
@@ -44,7 +44,6 @@
 
 static char	db_examine_format[TOK_STRING_SIZE] = "x";
 
-static void	db_examine(db_addr_t, char *, int);
 static void	db_search(db_addr_t, int, db_expr_t, db_expr_t, u_int);
 
 /*
@@ -67,7 +66,7 @@
 	db_examine((db_addr_t) addr, db_examine_format, count);
 }
 
-static void
+void
 db_examine(addr, fmt, count)
 	register
 	db_addr_t	addr;
Index: ddb/db_sysctl_cmd.c
===================================================================
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 20:13:05 -0000
@@ -0,0 +1,135 @@
+/*-
+ * Copyright (c) 2002  Potatin Mike
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: $
+ */
+
+#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>
+
+#define SYSCTL_DATA_BUFSIZE	256
+
+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 = 0;
+	size_t readcount = SYSCTL_DATA_BUFSIZE;
+	size_t wsize;
+	char wbuf[SYSCTL_DATA_BUFSIZE];
+	char buf[SYSCTL_DATA_BUFSIZE];
+	int err;
+
+	pcount = 0;
+	while((t = db_read_token()) == tNUMBER) {
+		mib[pcount] = db_tok_number;
+		pcount++;
+		if((t = db_read_token()) != tDOT) {
+			break;
+		}
+	}
+
+	switch (t) {
+		case tIDENT:
+			strcpy(wbuf, db_tok_string);
+			wsize = strlen(wbuf);
+			break;
+		case tNUMBER:
+			*(int*)wbuf = db_tok_number;
+			wsize = sizeof(int);
+			break;
+		default:
+			db_printf("no ident\n");
+			db_flush_lex();
+			return;
+	}
+
+	db_skip_to_eol();
+
+	if(((err = kernel_sysctl(
+		     FIRST_THREAD_IN_PROC(initproc), 
+		     mib, pcount, buf, &readcount, 
+		     wbuf, wsize, &ret))) == 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 = 0;
+	size_t readcount = SYSCTL_DATA_BUFSIZE;
+	char buf[SYSCTL_DATA_BUFSIZE];
+	int err;
+	char modif[16]="x";
+
+	pcount = 0;
+	while((t = db_read_token()) == tNUMBER) {
+		mib[pcount] = db_tok_number;
+		pcount++;
+		if((t = db_read_token()) != tDOT)
+			break;
+	}
+
+	if(t == tIDENT)
+		strncpy(modif, db_tok_string, 15);
+	
+	db_skip_to_eol();
+
+	if(((err = kernel_sysctl(
+		     FIRST_THREAD_IN_PROC(initproc), 
+		     mib, pcount, buf, 
+		     &readcount, NULL, 0, &ret))) == 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
===================================================================
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 20:09:28 -0000
@@ -84,6 +84,7 @@
 db_addr_t	db_disasm(db_addr_t loc, boolean_t altfmt);
 				/* instruction disassembler */
 void		db_error(const char *s);
+void		db_examine(db_addr_t, char *, int);
 int		db_expression(db_expr_t *valuep);
 int		db_get_variable(db_expr_t *valuep);
 void		db_iprintf(const char *,...) __printflike(1, 2);
@@ -125,6 +126,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;
 
 #if 0
 db_cmdfcn_t	db_help_cmd;
Index: conf/files
===================================================================
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 19:53:05 -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

Reply via email to