Subject: Re: 'machine' DDB command
To: Jaromír Dolecek <dolecek@ics.muni.cz>
From: enami tsugutomo <enami@but-b.or.jp>
List: tech-kern
Date: 01/19/2001 01:58:46
> Probably the most simple solution is to mandate the data have to
> be in db_machine_command_table[], change the entry in
> db_command.c:db_command_table[] to:
> #ifdef DB_MACHINE_COMMANDS
> 	{ "machine",    NULL,                   0, db_machine_command_table },
> #endif
> 
> and g/c db_machine_commands_install(). This would also eliminate
> need to glue in the table on boot (and allow the tables to be const).

Hm, like this?

enami.
Index: ./ddb/db_command.h
===================================================================
RCS file: /cvsroot/syssrc/sys/ddb/db_command.h,v
retrieving revision 1.19
diff -u -r1.19 db_command.h
--- ./ddb/db_command.h	2001/01/17 19:50:03	1.19
+++ ./ddb/db_command.h	2001/01/18 16:56:25
@@ -46,7 +46,6 @@
 void db_pool_print_cmd __P((db_expr_t, int, db_expr_t, char *));
 void db_namecache_print_cmd __P((db_expr_t, int, db_expr_t, char *));
 void db_uvmexp_print_cmd __P((db_expr_t, int, db_expr_t, char *));
-void db_machine_commands_install __P((struct db_command *));
 void db_command_loop __P((void));
 void db_error __P((char *));
 void db_fncall __P((db_expr_t, int, db_expr_t, char *));
Index: ./ddb/db_command.c
===================================================================
RCS file: /cvsroot/syssrc/sys/ddb/db_command.c,v
retrieving revision 1.54
diff -u -r1.54 db_command.c
--- ./ddb/db_command.c	2001/01/18 08:52:26	1.54
+++ ./ddb/db_command.c	2001/01/18 16:56:25
@@ -482,7 +482,7 @@
 	{ NULL,		NULL,			0,	NULL }
 };
 
-static struct db_command db_command_table[] = {
+static const struct db_command db_command_table[] = {
 	{ "break",	db_breakpoint_cmd,	0,		NULL },
 	{ "c",		db_continue_cmd,	0,		NULL },
 	{ "call",	db_fncall,		CS_OWN,		NULL },
@@ -494,7 +494,7 @@
 	{ "examine",	db_examine_cmd,		CS_SET_DOT, 	NULL },
 	{ "kill",	db_kill_proc,		CS_OWN,		NULL },
 #ifdef DB_MACHINE_COMMANDS
-	{ "machine",    NULL,                   0,     		NULL },
+	{ "machine",    NULL,                   0, db_machine_command_table },
 #endif
 	{ "match",	db_trace_until_matching_cmd,0,		NULL },
 	{ "next",	db_trace_until_matching_cmd,0,		NULL },
@@ -517,28 +517,6 @@
 	{ "x",		db_examine_cmd,		CS_SET_DOT, 	NULL },
 	{ NULL, 	NULL,			0,		NULL }
 };
-
-#ifdef DB_MACHINE_COMMANDS
-
-/*
- * this function should be called to install the machine dependent
- * commands. It should be called before the debugger is enabled
- */
-void
-db_machine_commands_install(ptr)
-	struct db_command *ptr;
-{
-	struct db_command *cmd;
-
-	for (cmd = db_command_table; cmd != 0; cmd++) {
-		if (strcmp(cmd->name, "machine") == 0) {
-			cmd->more = ptr;
-			break;
-		}
-	}
-}
-
-#endif
 
 const struct db_command	*db_last_command = NULL;
 
Index: ./ddb/db_interface.h
===================================================================
RCS file: /cvsroot/syssrc/sys/ddb/db_interface.h,v
retrieving revision 1.5
diff -u -r1.5 db_interface.h
--- ./ddb/db_interface.h	2000/05/26 03:34:32	1.5
+++ ./ddb/db_interface.h	2001/01/18 16:56:25
@@ -44,6 +44,9 @@
 
 /* arch/<arch>/<arch>/db_interface.c */
 void db_machine_init __P((void));
+#ifdef DB_MACHINE_COMMANDS
+extern const struct db_command db_machine_command_table[];
+#endif
 
 /* arch/<arch>/<arch>/db_trace.c */
 /* arch/vax/vax/db_machdep.c */
Index: ./arch/alpha/alpha/machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/alpha/alpha/machdep.c,v
retrieving revision 1.229
diff -u -r1.229 machdep.c
--- ./arch/alpha/alpha/machdep.c	2000/12/27 23:47:59	1.229
+++ ./arch/alpha/alpha/machdep.c	2001/01/18 16:56:23
@@ -767,7 +768,6 @@
 	 * Initialize debuggers, and break into them if appropriate.
 	 */
 #ifdef DDB
-	db_machine_init();
 	ddb_init((int)((u_int64_t)ksym_end - (u_int64_t)ksym_start),
 	    ksym_start, ksym_end);
 	if (boothowto & RB_KDB)
Index: ./arch/alpha/alpha/db_interface.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/alpha/alpha/db_interface.c,v
retrieving revision 1.13
diff -u -r1.13 db_interface.c
--- ./arch/alpha/alpha/db_interface.c	2001/01/18 10:55:29	1.13
+++ ./arch/alpha/alpha/db_interface.c	2001/01/18 16:56:23
@@ -94,7 +94,7 @@
 void	db_mach_cpu __P((db_expr_t, int, db_expr_t, char *));
 #endif
 
-struct db_command db_machine_cmds[] = {
+const struct db_command db_machine_command_table[] = {
 #if defined(MULTIPROCESSOR)
 	{ "cpu",	db_mach_cpu,	0,	0 },
 #endif
@@ -255,17 +255,6 @@
 {
 
 	__asm __volatile("call_pal 0x81");		/* bugchk */
-}
-
-/*
- * This is called before ddb_init() to install the
- * machine-specific command table.  (see machdep.c)
- */
-void
-db_machine_init()
-{
-
-	db_machine_commands_install(db_machine_cmds);
 }
 
 /*
Index: ./arch/arm32/arm32/db_interface.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/arm32/arm32/db_interface.c,v
retrieving revision 1.33
diff -u -r1.33 db_interface.c
--- ./arch/arm32/arm32/db_interface.c	2001/01/18 10:55:30	1.33
+++ ./arch/arm32/arm32/db_interface.c	2001/01/18 16:56:23
@@ -52,6 +52,7 @@
 #include <ddb/db_variables.h>
 #include <ddb/db_sym.h>
 #include <ddb/db_extern.h>
+#include <ddb/db_interface.h>
 #include <dev/cons.h>
 
 static int nil;
@@ -310,7 +311,7 @@
 void db_of_exit_cmd	__P((db_expr_t addr, int have_addr, db_expr_t count, char *modif));
 #endif
 
-struct db_command arm32_db_command_table[] = {
+const struct db_command db_machine_command_table[] = {
 	{ "frame",	db_show_frame_cmd,	0, NULL },
 	{ "intrchain",	db_show_intrchain_cmd,	0, NULL },
 #ifdef	OFW
@@ -373,7 +374,6 @@
 	}
 
 	install_coproc_handler(0, db_trapper);
-	db_machine_commands_install(arm32_db_command_table);
 }
 
 u_int
Index: ./arch/mips/mips/db_interface.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/mips/mips/db_interface.c,v
retrieving revision 1.34
diff -u -r1.34 db_interface.c
--- ./arch/mips/mips/db_interface.c	2000/11/09 06:02:40	1.34
+++ ./arch/mips/mips/db_interface.c	2001/01/18 16:56:23
@@ -51,6 +51,7 @@
 #include <ddb/db_output.h>
 #include <ddb/db_sym.h>
 #include <ddb/db_extern.h>
+#include <ddb/db_interface.h>
 #endif
 
 int	db_active = 0;
@@ -397,17 +398,11 @@
 		printf("not a kernel virtual address\n");
 }
 
-struct db_command mips_db_command_table[] = {
+const struct db_command db_machine_command_table[] = {
 	{ "kvtop",	db_kvtophys_cmd,	0,	0 },
 	{ "tlb",	db_tlbdump_cmd,		0,	0 },
 	{ (char *)0, }
 };
-
-void
-db_machine_init()
-{
-	db_machine_commands_install(mips_db_command_table);
-}
 
 #endif	/* !KGDB */
 
Index: ./arch/pmax/pmax/machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/pmax/pmax/machdep.c,v
retrieving revision 1.185
diff -u -r1.185 machdep.c
--- ./arch/pmax/pmax/machdep.c	2001/01/15 20:19:56	1.185
+++ ./arch/pmax/pmax/machdep.c	2001/01/18 16:56:24
@@ -293,10 +293,6 @@
 #endif
 
 #ifdef DDB
-	/*
-	 * Initialize machine-dependent DDB commands, in case of early panic.
-	 */
-	db_machine_init();
 	/* init symbols if present */
 	if (esym)
 		ddb_init(esym - ssym, ssym, esym);
Index: ./arch/sparc/sparc/db_interface.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/sparc/sparc/db_interface.c,v
retrieving revision 1.33
diff -u -r1.33 db_interface.c
--- ./arch/sparc/sparc/db_interface.c	2001/01/18 10:54:29	1.33
+++ ./arch/sparc/sparc/db_interface.c	2001/01/18 16:56:24
@@ -50,6 +50,7 @@
 #include <ddb/db_variables.h>
 #include <ddb/db_extern.h>
 #include <ddb/db_output.h>
+#include <ddb/db_interface.h>
 #endif
 
 #include <machine/instr.h>
@@ -237,16 +238,10 @@
 	prom_abort();
 }
 
-struct db_command sparc_db_command_table[] = {
+const struct db_command db_machine_command_table[] = {
 	{ "prom",	db_prom_cmd,	0,	0 },
 	{ (char *)0, }
 };
-
-void
-db_machine_init()
-{
-	db_machine_commands_install(sparc_db_command_table);
-}
 #endif /* DDB */
 
 
Index: ./arch/sparc/sparc/autoconf.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/sparc/sparc/autoconf.c,v
retrieving revision 1.142
diff -u -r1.142 autoconf.c
--- ./arch/sparc/sparc/autoconf.c	2000/09/24 12:32:38	1.142
+++ ./arch/sparc/sparc/autoconf.c	2001/01/18 16:56:24
@@ -216,7 +216,6 @@
 
 	/* Moved zs_kgdb_init() to dev/zs.c:consinit(). */
 #ifdef DDB
-	db_machine_init();
 	if ((bi_sym = lookup_bootinfo(BTINFO_SYMTAB)) != NULL) {
 	   	bi_sym->ssym += KERNBASE; 
 	   	bi_sym->esym += KERNBASE; 
Index: ./arch/sun3/sun3/machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/sun3/sun3/machdep.c,v
retrieving revision 1.141
diff -u -r1.141 machdep.c
--- ./arch/sun3/sun3/machdep.c	2000/09/13 15:00:23	1.141
+++ ./arch/sun3/sun3/machdep.c	2001/01/18 16:56:24
@@ -142,7 +142,6 @@
 	cninit();
 
 #ifdef DDB
-	db_machine_init();
 	{
 		extern int end[];
 		extern char *esym;
Index: ./arch/sun3/sun3/db_machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/sun3/sun3/db_machdep.c,v
retrieving revision 1.15
diff -u -r1.15 db_machdep.c
--- ./arch/sun3/sun3/db_machdep.c	2000/11/03 06:27:34	1.15
+++ ./arch/sun3/sun3/db_machdep.c	2001/01/18 16:56:24
@@ -53,29 +53,20 @@
 
 #include <ddb/db_command.h>
 #include <ddb/db_output.h>
+#include <ddb/db_interface.h>
 
 static void db_mach_abort   __P((db_expr_t, int, db_expr_t, char *));
 static void db_mach_halt    __P((db_expr_t, int, db_expr_t, char *));
 static void db_mach_reboot  __P((db_expr_t, int, db_expr_t, char *));
 static void db_mach_pagemap __P((db_expr_t, int, db_expr_t, char *));
 
-struct db_command db_machine_cmds[] = {
+const struct db_command db_machine_command_table[] = {
 	{ "abort",	db_mach_abort,	0,	0 },
 	{ "halt",	db_mach_halt,	0,	0 },
 	{ "pgmap",	db_mach_pagemap, 	CS_SET_DOT, 0 },
 	{ "reboot",	db_mach_reboot,	0,	0 },
 	{ (char *)0, }
 };
-
-/*
- * This is called before ddb_init() to install the
- * machine-specific command table. (see machdep.c)
- */
-void
-db_machine_init()
-{
-	db_machine_commands_install(db_machine_cmds);
-}
 
 /*
  * Machine-specific ddb commands for the sun3:
Index: ./arch/newsmips/newsmips/machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/newsmips/newsmips/machdep.c,v
retrieving revision 1.50
diff -u -r1.50 machdep.c
--- ./arch/newsmips/newsmips/machdep.c	2001/01/15 20:19:55	1.50
+++ ./arch/newsmips/newsmips/machdep.c	2001/01/18 16:56:24
@@ -288,10 +288,6 @@
 #endif
 
 #ifdef DDB
-	/*
-	 * Initialize machine-dependent DDB commands, in case of early panic.
-	 */
-	db_machine_init();
 	if (nsym)
 		ddb_init(esym - ssym, ssym, esym);
 #endif
Index: ./arch/sparc64/sparc64/autoconf.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/sparc64/sparc64/autoconf.c,v
retrieving revision 1.41
diff -u -r1.41 autoconf.c
--- ./arch/sparc64/sparc64/autoconf.c	2000/10/04 23:05:08	1.41
+++ ./arch/sparc64/sparc64/autoconf.c	2001/01/18 16:56:25
@@ -217,9 +217,9 @@
 
 	/* 
 	 * Initialize ddb first and register OBP callbacks.
-	 * We can do this because ddb_machine_init() and 
-	 * ddb_init() do not allocate anything, just initialze
-	 * some pointers to important things like the symtab.
+	 * We can do this because ddb_init() does not allocate anything,
+	 * just initialze some pointers to important things
+	 * like the symtab.
 	 *
 	 * By doing this first and installing the OBP callbacks
 	 * we get to do symbolic debugging of pmap_bootstrap().
@@ -231,7 +231,6 @@
 	/* Initialize the PROM console so printf will not panic */
 	(*cn_tab->cn_init)(cn_tab);
 #ifdef DDB
-	db_machine_init();
 #ifdef DB_ELF_SYMBOLS
 	ddb_init((int)((caddr_t)esym - (caddr_t)ssym), ssym, esym); 
 #else
Index: ./arch/sparc64/sparc64/db_interface.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/sparc64/sparc64/db_interface.c,v
retrieving revision 1.54
diff -u -r1.54 db_interface.c
--- ./arch/sparc64/sparc64/db_interface.c	2001/01/18 10:54:29	1.54
+++ ./arch/sparc64/sparc64/db_interface.c	2001/01/18 16:56:25
@@ -863,7 +863,7 @@
 extern void db_esp(db_expr_t, int, db_expr_t, char*);
 #endif
 
-struct db_command sparc_db_command_table[] = {
+const struct db_command db_machine_command_table[] = {
 	{ "ctx",	db_ctx_cmd,	0,	0 },
 	{ "dtlb",	db_dump_dtlb,	0,	0 },
 	{ "dtsb",	db_dump_dtsb,	0,	0 },
@@ -889,12 +889,6 @@
 	{ "window",	db_dump_window,	0,	0 },
 	{ (char *)0, }
 };
-
-void
-db_machine_init()
-{
-	db_machine_commands_install(sparc_db_command_table);
-}
 
 /*
  * support for SOFTWARE_SSTEP:
Index: ./arch/hpcmips/hpcmips/machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/hpcmips/hpcmips/machdep.c,v
retrieving revision 1.38
diff -u -r1.38 machdep.c
--- ./arch/hpcmips/hpcmips/machdep.c	2001/01/15 20:19:54	1.38
+++ ./arch/hpcmips/hpcmips/machdep.c	2001/01/18 16:56:25
@@ -352,10 +352,6 @@
 #endif
 
 #ifdef DDB
-	/*
-	 * Initialize machine-dependent DDB commands, in case of early panic.
-	 */
-	db_machine_init();
 	/* init symbols if present */
 	if (esym)
 		ddb_init(1000, &end, (int*)esym);
Index: ./arch/arm26/arm26/cons_machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/arm26/arm26/cons_machdep.c,v
retrieving revision 1.1
diff -u -r1.1 cons_machdep.c
--- ./arch/arm26/arm26/cons_machdep.c	2000/05/09 21:55:55	1.1
+++ ./arch/arm26/arm26/cons_machdep.c	2001/01/18 16:56:25
@@ -63,7 +63,6 @@
 /*       	cninit();*/
 
 #ifdef DDB
-	db_machine_init();
 	ddb_init(bootconfig.esym - bootconfig.ssym,
 		 MEMC_PHYS_BASE + bootconfig.ssym,
 		 MEMC_PHYS_BASE + bootconfig.esym);
Index: ./arch/arm26/arm26/db_interface.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/arm26/arm26/db_interface.c,v
retrieving revision 1.6
diff -u -r1.6 db_interface.c
--- ./arch/arm26/arm26/db_interface.c	2001/01/18 10:55:30	1.6
+++ ./arch/arm26/arm26/db_interface.c	2001/01/18 16:56:25
@@ -208,7 +208,7 @@
 void db_bus_write_cmd	__P((db_expr_t addr, int have_addr, db_expr_t count, char *modif));
 void db_irqstat_cmd	__P((db_expr_t addr, int have_addr, db_expr_t count, char *modif));
 
-struct db_command arm26_db_command_table[] = {
+const struct db_command db_machine_command_table[] = {
 	{ "bsw",	db_bus_write_cmd,	CS_MORE, NULL },
 	{ "frame",	db_show_frame_cmd,	0, NULL },
 	{ "irqstat",	db_irqstat_cmd,		0, NULL },
@@ -237,13 +237,6 @@
 
 extern u_int esym;
 extern u_int end;
-
-void
-db_machine_init()
-{
-
-	db_machine_commands_install(arm26_db_command_table);
-}
 
 u_int
 db_fetch_reg(reg, db_regs)
Index: ./arch/mipsco/mipsco/machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/mipsco/mipsco/machdep.c,v
retrieving revision 1.14
diff -u -r1.14 machdep.c
--- ./arch/mipsco/mipsco/machdep.c	2001/01/15 20:19:55	1.14
+++ ./arch/mipsco/mipsco/machdep.c	2001/01/18 16:56:25
@@ -302,10 +302,6 @@
 
 
 #ifdef DDB
-	/*
-	 * Initialize machine-dependent DDB commands, in case of early panic.
-	 */
-	db_machine_init();
 	/* init symbols if present */
 	if (esym)
 		ddb_init(esym - ssym, ssym, esym);
Index: ./arch/sgimips/sgimips/machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/sgimips/sgimips/machdep.c,v
retrieving revision 1.8
diff -u -r1.8 machdep.c
--- ./arch/sgimips/sgimips/machdep.c	2001/01/15 20:19:57	1.8
+++ ./arch/sgimips/sgimips/machdep.c	2001/01/18 16:56:25
@@ -201,11 +201,6 @@
 	}
 
 #ifdef DDB
-	/*
-	 * Initialize machine-dependent DDB commands, in case of early panic.
-	 */
-	db_machine_init();
-
 	if (boothowto & RB_KDB)
 		Debugger();
 #endif