Subject: Re: ddb help command patch
To: Adam Hamsik <haaaad@gmail.com>
From: Adam Hamsik <haaaad@gmail.com>
List: tech-kern
Date: 07/13/2007 14:20:44
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--Apple-Mail-3--136385819
Content-Type: multipart/mixed; boundary=Apple-Mail-2--136385872


--Apple-Mail-2--136385872
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	delsp=yes;
	format=flowed

and patch included.

patch can be reviewed at wasabi.fiit.stuba.sk/~haad/netbsd/ 
ddb_cmd.diff also.


--Apple-Mail-2--136385872
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name=ddb_cmd.diff
Content-Disposition: attachment;
	filename=ddb_cmd.diff

? arch/i386/compile/GENERIC
? arch/i386/conf/.t41_not.swp
? arch/i386/conf/GENERIC_CD
? arch/i386/conf/GENERIC_T41
? arch/i386/conf/t41_not
? arch/i386/stand/boot/lib
? arch/i386/stand/genprom/genprom
? arch/i386/stand/genprom/genprom.lo
? arch/i386/stand/mbr/mbr/.gdbinit
? arch/i386/stand/mbr/mbr_bootsel/.gdbinit
? arch/i386/stand/mbr/mbr_ext/.gdbinit
? lkm/misc/example/test/.gdbinit
? lkm/misc/example/test/testmisc
Index: arch/acorn26/acorn26/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/acorn26/acorn26/db_interface.c,v
retrieving revision 1.14
diff -n -r1.14 db_interface.c
d244 5
a248 5
	{ DDB_ADD_CMD("bsw",	db_bus_write_cmd,	CS_MORE, NULL,NULL) },
	{ DDB_ADD_CMD("frame",	db_show_frame_cmd,	0, NULL, NULL) },
	{ DDB_ADD_CMD("irqstat",db_irqstat_cmd,		0, NULL, NULL) },
	{ DDB_ADD_CMD("panic",	db_show_panic_cmd,	0, NULL, NULL) },
	{ DDB_ADD_CMD( NULL,     NULL,              0, NULL, NULL) }
Index: arch/alpha/alpha/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/alpha/alpha/db_interface.c,v
retrieving revision 1.25
diff -n -r1.25 db_interface.c
d97 1
a97 1
	{ DDB_ADD_CMD("cpu",	db_mach_cpu,	0,NULL,NULL) },
d99 1
a99 1
	{ DDB_ADD_CMD(NULL,     NULL,           0,NULL,NULL) },
Index: arch/amd64/amd64/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/amd64/amd64/db_interface.c,v
retrieving revision 1.8
diff -n -r1.8 db_interface.c
d76 1
a76 1
	{ DDB_ADD_CMD("cpu",	db_mach_cpu,	0,	NULL,NULL )},
d78 1
a78 1
	{ DDB_ADD_CMD(NULL,     NULL,          0,NULL,NULL) },
Index: arch/arm/arm32/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/arm32/db_interface.c,v
retrieving revision 1.42
diff -n -r1.42 db_interface.c
d368 2
a369 2
	{ DDB_ADD_CMD("frame",	db_show_frame_cmd,	0, NULL,NULL) },
	{ DDB_ADD_CMD("panic",	db_show_panic_cmd,	0, NULL,NULL) },
d373 1
a373 1
	{ DDB_ADD_CMD(NULL,     NULL,           0,NULL,NULL) }
Index: arch/i386/conf/GENERIC
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/conf/GENERIC,v
retrieving revision 1.835
diff -n -r1.835 GENERIC
d126 3
a128 3
options 	DIAGNOSTIC	# expensive kernel consistency checks
options 	DEBUG		# expensive debugging checks/support
options 	KMEMSTATS	# kernel memory statistics (vmstat -m)
d130 1
a130 2
options         DDB_VERBOSE_HELP=1 #verbose in kernel debuger help (increase size of kernel)  
options 	DDB_ONPANIC=1	# see also sysctl(8): `ddb.onpanic'
d134 3
a136 3
makeoptions	DEBUG="-g"	# compile full symbol table
options 	SYSCALL_STATS	# per syscall counts
options 	SYSCALL_TIMES	# per syscall times
Index: arch/i386/i386/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/i386/db_interface.c,v
retrieving revision 1.51
diff -n -r1.51 db_interface.c
d75 1
a75 1
	{ DDB_ADD_CMD("cpu",	db_mach_cpu,	0, NULL,NULL) },
d77 1
a77 1
	{ DDB_ADD_CMD(NULL, NULL, 0,  NULL,NULL) },
Index: arch/ia64/ia64/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/ia64/ia64/db_interface.c,v
retrieving revision 1.2
diff -n -r1.2 db_interface.c
d114 1
a114 1
	{  DDB_ADD_CMD(NULL,     NULL,           0,NULL,NULL) },
Index: arch/mips/mips/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mips/mips/db_interface.c,v
retrieving revision 1.61
diff -n -r1.61 db_interface.c
d545 4
a548 4
	{ DDB_ADD_CMD("kvtop",	db_kvtophys_cmd,	0,	NULL,NULL) },
	{ DDB_ADD_CMD("tlb",	db_tlbdump_cmd,		0,	NULL,NULL) },
	{ DDB_ADD_CMD("cp0",	db_cp0dump_cmd,		0,	NULL,NULL) },
	{ DDB_ADD_CMD(NULL,     NULL,               0,  NULL,NULL) }
Index: arch/powerpc/powerpc/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/powerpc/powerpc/db_interface.c,v
retrieving revision 1.37
diff -n -r1.37 db_interface.c
d195 6
a200 6
	{ DDB_ADD_CMD("ctx",	db_ppc4xx_ctx,		0,	NULL,NULL) },
	{ DDB_ADD_CMD("pv",		db_ppc4xx_pv,		0,	NULL,NULL) },
	{ DDB_ADD_CMD("reset",	db_ppc4xx_reset,	0,	NULL,NULL) },
	{ DDB_ADD_CMD("tf",		db_ppc4xx_tf,		0,	NULL,NULL) },
	{ DDB_ADD_CMD("tlb",	db_ppc4xx_dumptlb,	0,	NULL,NULL) },
	{ DDB_ADD_CMD("dcr",	db_ppc4xx_dcr,		CS_MORE|CS_SET_DOT,	NULL,NULL) },
d202 1
a202 1
	{ DDB_ADD_CMD("user",	db_ppc4xx_useracc,	0,	NULL,NULL) },
d204 1
a204 1
	{ DDB_ADD_CMD(NULL,     NULL,               0,  NULL,NULL) }
Index: arch/sh3/sh3/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sh3/sh3/db_interface.c,v
retrieving revision 1.43
diff -n -r1.43 db_interface.c
d93 3
a95 3
	{ DDB_ADD_CMD("tlb",	db_tlbdump_cmd,		0,	NULL, NULL) },
	{ DDB_ADD_CMD("cache",	db_cachedump_cmd,	0,	NULL, NULL) },
	{ DDB_ADD_CMD("frame",	db_frame_cmd,		0,	NULL, NULL) },
d97 1
a97 1
	{ DDB_ADD_CMD("stack",	db_stackcheck_cmd,	0,	NULL, NULL) },
d99 1
a99 1
	{  DDB_ADD_CMD(NULL,     NULL,              0,  NULL, NULL) }
Index: arch/sparc/sparc/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc/sparc/db_interface.c,v
retrieving revision 1.71
diff -n -r1.71 db_interface.c
d546 7
a552 7
	{ DDB_ADD_CMD("prom",	db_prom_cmd,	0,	NULL,NULL) },
	{ DDB_ADD_CMD("proc",	db_proc_cmd,	0,	NULL,NULL) },
	{ DDB_ADD_CMD("pcb",	db_dump_pcb,	0,	NULL,NULL) },
	{ DDB_ADD_CMD("lock",	db_lock_cmd,	0,	NULL,NULL) },
	{ DDB_ADD_CMD("slock",	db_simple_lock_cmd,	0,	NULL,NULL) },
	{ DDB_ADD_CMD("page",	db_page_cmd,	0,	NULL,NULL) },
	{ DDB_ADD_CMD("uvmdump",	db_uvmhistdump,	0,	NULL,NULL) },
d554 1
a554 1
	{ DDB_ADD_CMD("cpu",	db_cpu_cmd,	0,	NULL,NULL) },
d556 1
a556 1
	{ DDB_ADD_CMD(NULL,     NULL,           0,NULL,NULL) }
Index: arch/sparc64/sparc64/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc64/sparc64/db_interface.c,v
retrieving revision 1.97
diff -n -r1.97 db_interface.c
d1260 5
a1264 5
	{ DDB_ADD_CMD("ctx",	db_ctx_cmd,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("dtlb",	db_dump_dtlb,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("itlb",	db_dump_itlb,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("dtsb",	db_dump_dtsb,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("itsb",	db_dump_itsb,	0,	NULL,NULL )},
d1266 1
a1266 1
	{ DDB_ADD_CMD("esp",	db_esp,		0,	NULL,NULL )},
d1268 23
a1290 23
	{ DDB_ADD_CMD("extract",	db_pm_extract,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("fpstate",	db_dump_fpstate,0,	NULL,NULL )},
	{ DDB_ADD_CMD("kmap",	db_pmap_kernel,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("lock",	db_lock_cmd,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("lwp",	db_lwp_cmd,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("pcb",	db_dump_pcb,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("pctx",	db_setpcb,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("page",	db_page_cmd,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("phys",	db_pload_cmd,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("pmap",	db_pmap_cmd,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("proc",	db_proc_cmd,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("prom",	db_prom_cmd,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("pv",		db_dump_pv,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("stack",	db_dump_stack,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("tf",		db_dump_trap,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("ts",		db_dump_ts,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("traptrace",	db_traptrace,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("uvmdump",	db_uvmhistdump,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("watch",	db_watch,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("window",	db_dump_window,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("cpu",	db_cpu_cmd,	0,	NULL,NULL )},
	{ DDB_ADD_CMD("sir",	db_sir_cmd,	0,	NULL,NULL )},
	{ DDB_ADD_CMD(NULL,     NULL,           0,NULL,NULL) }
Index: arch/sun2/sun2/db_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sun2/sun2/db_machdep.c,v
retrieving revision 1.8
diff -n -r1.8 db_machdep.c
d68 5
a72 5
	{ DDB_ADD_CMD("abort",	db_mach_abort,	0,	NULL,NULL) },
	{ DDB_ADD_CMD("halt",	db_mach_halt,	0,	NULL,NULL) },
	{ DDB_ADD_CMD("pgmap",	db_mach_pagemap, 	CS_SET_DOT, NULL,NULL) },
	{ DDB_ADD_CMD("reboot",	db_mach_reboot,	0,	NULL,NULL) },
	{ DDB_ADD_CMD( NULL,NULL,0,NULL,NULL) }
Index: arch/sun3/sun3/db_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sun3/sun3/db_machdep.c,v
retrieving revision 1.23
diff -n -r1.23 db_machdep.c
d67 5
a71 5
	{ DDB_ADD_CMD("abort",	db_mach_abort,	0,	NULL,NULL) },
	{ DDB_ADD_CMD("halt",	db_mach_halt,	0,	NULL,NULL) },
	{ DDB_ADD_CMD("pgmap",	db_mach_pagemap, 	CS_SET_DOT, NULL,NULL) },
	{ DDB_ADD_CMD("reboot",	db_mach_reboot,	0,	NULL,NULL) },
	{ DDB_ADD_CMD(NULL,NULL,0,NULL,NULL)}
Index: arch/vax/vax/db_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/vax/vax/db_machdep.c,v
retrieving revision 1.46
diff -n -r1.46 db_machdep.c
d661 1
a661 1
	{ DDB_ADD_CMD("cpu",	db_mach_cpu,	0,	NULL,NULL) },
d663 1
a663 1
	{ DDB_ADD_CMD(NULL,NULL,0,NULL,NULL)},
Index: ddb/db_command.c
===================================================================
RCS file: /cvsroot/src/sys/ddb/db_command.c,v
retrieving revision 1.96
diff -n -r1.96 db_command.c
a1 35
/*
 * Copyright (c) 1996, 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Adam Hamsik.
 *
 * 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.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *        This product includes software developed by the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
 */
a53 3
/*include queue macros*/
#include <sys/queue.h>

a72 1
#include <ddb/db_command_list.h>
d86 1
a86 17

#define CMD_SWITCH(result) do {          \
        switch (result) {                \
        case CMD_NONE:                   \
		 db_printf("No such command\n"); \
		 db_flush_lex();                 \
		 return;                         \
        case CMD_AMBIGUOUS:              \
		 db_printf("Ambiguous\n");       \
		 db_flush_lex();                 \
		 return;                         \
        default:                         \
		 break;                          \
        }                                \
        } while(/* CONSTCOND */ 0)


a97 17

/*
  New DDB api for adding and removing commands uses two lists, because
  we use two types of commands
  a) standard commands without subcommands -> reboot
  b) show commands which are subcommands of show command -> show aio_jobs

  ddb_add_cmd, ddb_rem_cmd use type (DDB_SHOW_CMD||DDB_BASE_CMD)argument to add them
  to representativ lists.
*/

/*head of base commands list*/
static struct db_cmd_tbl_en_head db_base_cmd_list=TAILQ_HEAD_INITIALIZER(db_base_cmd_list);

/*head of show commands list*/
static struct db_cmd_tbl_en_head db_show_cmd_list=TAILQ_HEAD_INITIALIZER(db_show_cmd_list);

d105 2
a106 1
static void	db_cmd_list(const struct db_cmd_tbl_en_head *);
d108 3
a110 3
						  const struct db_command **);
static void	db_command(const struct db_command **);
static void	db_buf_print_cmd(db_expr_t, bool, db_expr_t, const char *);
a112 6
static int  db_get_list_type(const char *);
static void db_help_print_cmd(db_expr_t, bool, db_expr_t, const char *);
static void db_init_commands(void);
static void	db_lock_print_cmd(db_expr_t, bool, db_expr_t, const char *);
static void	db_mount_print_cmd(db_expr_t, bool, db_expr_t, const char *);
static void	db_mbuf_print_cmd(db_expr_t, bool, db_expr_t, const char *);
a124 1
static void	db_ui_compat_cmd(db_expr_t, bool, db_expr_t, const char *);
d126 7
d134 7
d143 2
a144 8
		/*added from all sub cmds*/
		{ DDB_ADD_CMD("callout",  db_show_callout,	0,NULL,NULL) },
		{ DDB_ADD_CMD("pages",	db_show_all_pages,	0,NULL,NULL) },
		{ DDB_ADD_CMD("procs",	db_show_all_procs,	0,NULL,NULL) },
		{ DDB_ADD_CMD("pools",	db_show_all_pools,	0,NULL,NULL) },
		/*added from all sub cmds*/
		{ DDB_ADD_CMD("aio_jobs",	db_show_aio_jobs,	0,"Show aio jobs", NULL) },
		{ DDB_ADD_CMD("all",	db_ui_compat_cmd,	CS_OWN, NULL, NULL) },
d146 1
a146 1
		{ DDB_ADD_CMD("arptab",	db_show_arptab,		0,NULL,NULL) },
d148 18
a165 31
		{ DDB_ADD_CMD("breaks",	db_listbreak_cmd, 	0,"Display all breaks.", NULL) },
		{ DDB_ADD_CMD("buf",	db_buf_print_cmd,	0,
					  "Print the struct buf at address.", "[/f] address") },
		{ DDB_ADD_CMD("event",	db_event_print_cmd,	0,
					  "Print all the non-zero evcnt(9) event counters.", "[/f]") },
		{ DDB_ADD_CMD("lock",	db_lock_print_cmd,	0,NULL,NULL) },
		{ DDB_ADD_CMD("malloc",	db_malloc_print_cmd,0,NULL,NULL) },
		{ DDB_ADD_CMD("map",	db_map_print_cmd,	0,
					  "Print the vm_map at address.", "[/f] address") },
		{ DDB_ADD_CMD("mount",	db_mount_print_cmd,	0,
					  "Print the mount structure at address.", "[/f] address") },
		{ DDB_ADD_CMD("mbuf",	db_mbuf_print_cmd,	0,NULL,NULL) },
		{ DDB_ADD_CMD("ncache",	db_namecache_print_cmd,	0,
					  "Dump the namecache list.", "address") },
		{ DDB_ADD_CMD("object",	db_object_print_cmd,	0,
					  "Print the vm_object at address.", "[/f] address") },
		{ DDB_ADD_CMD("page",	db_page_print_cmd,	0,
					  "Print the vm_page at address.", "[/f] address") },
		{ DDB_ADD_CMD("pool",	db_pool_print_cmd,	0,
					  "Print the pool at address.", "[/clp] address") },
		{ DDB_ADD_CMD("registers",	db_show_regs,		0,
					  "Display the register set.", "[/u]") },
		{ DDB_ADD_CMD("sched_qs",	db_show_sched_qs,	0,
					  "Print the state of the scheduler's run queues.",NULL) },
		{ DDB_ADD_CMD("uvmexp",	db_uvmexp_print_cmd, 0,
					  "Print a selection of UVM counters and statistics.", NULL) },
		{ DDB_ADD_CMD("vnode",	db_vnode_print_cmd,	0,
					  "Print the vnode at address.", "[/f] address") },
		{ DDB_ADD_CMD("watches",	db_listwatch_cmd, 	0,
					  "Display all watchpoints.", NULL) },
		{ DDB_ADD_CMD(NULL,		NULL,			0,NULL,NULL) }
d174 13
a186 28
		{ DDB_ADD_CMD("b",		db_breakpoint_cmd,	0,
					  "Set a breakpoint at address", "[/u] address[,count].") },
		{ DDB_ADD_CMD("break",	db_breakpoint_cmd,	0,
					  "Set a breakpoint at address", "[/u] address[,count].") },
		{ DDB_ADD_CMD("bt",		db_stack_trace_cmd,	0,
					  "Show backtrace.", "See help trace.") },
		{ DDB_ADD_CMD("c",		db_continue_cmd,	0,"Continue execution.", "[/c]") },
		{ DDB_ADD_CMD("call",	db_fncall,		CS_OWN,
					  "Call the function", "address[(expression[,...])]") },
		{ DDB_ADD_CMD("callout",	db_show_callout,	0, NULL, NULL) },
		{ DDB_ADD_CMD("continue",	db_continue_cmd,	0,
					  "Continue execution.", "[/c]") },
		{ DDB_ADD_CMD("d",		db_delete_cmd,		0,
					  "Delete a breakpoint.", "address | #number") },
		{ DDB_ADD_CMD("delete",	db_delete_cmd,		0,
					  "Delete a breakpoint.", "address | #number") },
		{ DDB_ADD_CMD("dmesg",	db_dmesg,		0,
					  "Show kernel message buffer.", "[count]") },
		{ DDB_ADD_CMD("dwatch",	db_deletewatch_cmd,	0,
					  "Delete the watchpoint.", "address") },
		{ DDB_ADD_CMD("examine",	db_examine_cmd,		CS_SET_DOT,
					  "Display the address locations.",
					  "[/modifier] address[,count]") },
		{ DDB_ADD_CMD("help",   db_help_print_cmd, CS_OWN,
					  "Display help about commands",
					  "Use other commands as arguments.") },
		{ DDB_ADD_CMD("kill",	db_kill_proc,		CS_OWN,
					  "Send a signal to the process","pid[,signal_number]") },
d188 4
a191 1
		{ DDB_ADD_CMD("kgdb",	db_kgdb_cmd,		0,		NULL) },
d193 20
a212 45
		{ DDB_ADD_CMD("match",	db_trace_until_matching_cmd,0,
					  "Stop at the matching return instruction.","See help next") },
		{ DDB_ADD_CMD("next",	db_trace_until_matching_cmd,0,
					  "Stop at the matching return instruction.","[/p]") },
		{ DDB_ADD_CMD("p",		db_print_cmd,		0,
					  "Print address according to the format.",
					  "[/axzodurc] address [address ...]") },
		{ DDB_ADD_CMD("print",	db_print_cmd,		0,
					  "Print address according to the format.",
					  "[/axzodurc] address [address ...]") },
		{ DDB_ADD_CMD("ps",		db_show_all_procs,	0,
					  "Print all processes.","See show all procs") },
		{ DDB_ADD_CMD("reboot",	db_reboot_cmd,		CS_OWN,
					  "Reboot","0x1  RB_ASKNAME, 0x2 RB_SINGLE, 0x4 RB_NOSYNC, 0x8 RB_HALT,"
					  "0x40 RB_KDB, 0x100 RB_DUMP, 0x808 RB_POWERDOWN") },
		{ DDB_ADD_CMD("s",		db_single_step_cmd,	0,
					  "Single-step count times.","[/p] [,count]") },
		{ DDB_ADD_CMD("search",	db_search_cmd,		CS_OWN|CS_SET_DOT,
					  "Search memory from address for value.",
					  "[/bhl] address value [mask] [,count]") },
		{ DDB_ADD_CMD("set",	db_set_cmd,		CS_OWN,
					  "Set the named variable","$variable [=] expression") },
		{ DDB_ADD_CMD("show",	NULL,			0,"Show kernel stats.", NULL) },
		{ DDB_ADD_CMD("sifting",	db_sifting_cmd,		CS_OWN,
					  "Search the symbol tables ","[/F] string") },
		{ DDB_ADD_CMD("step",	db_single_step_cmd,	0,
					  "Single-step count times.","[/p] [,count]") },
		{ DDB_ADD_CMD("sync",	db_sync_cmd,		CS_OWN,
					  "Force a crash dump, and then reboot.",NULL) },
		{ DDB_ADD_CMD("trace",	db_stack_trace_cmd,	0,
					  "Stack trace from frame-address.",
					  "[/u[l]] [frame-address][,count]") },
		{ DDB_ADD_CMD("until",	db_trace_until_call_cmd,0,
					  "Stop at the next call or return instruction.","[/p]") },
		{ DDB_ADD_CMD("w",		db_write_cmd,		CS_MORE|CS_SET_DOT,
					  "Set a watchpoint for a region. ","address[,size]") },
		{ DDB_ADD_CMD("watch",	db_watchpoint_cmd,	CS_MORE,
					  "Set a watchpoint for a region. ","address[,size]") },
		{ DDB_ADD_CMD("write",	db_write_cmd,		CS_MORE|CS_SET_DOT,
					  "Write the expressions at succeeding locations.",
					  "[/bhl] address expression [expression ...]") },
		{ DDB_ADD_CMD("x",		db_examine_cmd,		CS_SET_DOT,
					  "Display the address locations.",
					  "[/modifier] address[,count]") },
		{ DDB_ADD_CMD(NULL, 	NULL,		   0, NULL, NULL) }
d227 5
a231 4
db_skip_to_eol(void){
  
		int t;
	 do {
d237 2
a238 1
db_error(const char *s){
d240 1
a240 1
		if (s)
d242 2
a243 2
	 db_flush_lex();
	 longjmp(db_recover);
a245 1
/*Execute commandlist after ddb start*/
d247 4
a250 4
db_execute_commandlist(const char *cmdlist){
  
		const char *cmd = cmdlist;
	 const struct db_command	*dummy = NULL;
d252 1
a252 1
	 while (*cmd != '\0') {
d255 8
a262 2
		 while (*ep != '\0' && *ep != DB_LINE_SEP) {
		ep++;
d264 1
a264 7
		 db_set_line(cmd, ep);
		 db_command(&dummy);
		 cmd = ep;
		 if (*cmd == DB_LINE_SEP) {
				 cmd++;
		 }
	 }
d267 5
a271 4
/*Initialize ddb command tables*/
static void
db_init_commands(void){
		struct db_cmd_tbl_en *list_ent;
d273 5
a277 3
		
/*		TAILQ_INIT(&db_base_cmd_list);
		TAILQ_INIT(&db_show_cmd_list);*/
d279 1
a279 3
		TAILQ_FOREACH(list_ent,&db_base_cmd_list,db_cmd_next)
				if (list_ent->db_cmd == db_command_table)
						return;
d281 3
a283 3
		TAILQ_FOREACH(list_ent,&db_show_cmd_list,db_cmd_next)
				if (list_ent->db_cmd == db_show_cmds)
						return;
d285 1
a285 1
		printf("Initialize command tables\n");
d287 4
a290 143
		(void)db_add_command_tbl(DDB_BASE_CMD,db_command_table);
		(void)db_add_command_tbl(DDB_BASE_CMD,db_machine_command_table);
   
		(void)db_add_command_tbl(DDB_SHOW_CMD,db_show_cmds);


		/*  (void)db_rem_command_tbl(DDB_BASE_CMD,db_command_table);
			(void)db_rem_command_tbl(DDB_SHOW_CMD,db_show_cmds);*/
		return;
}


/*
 * Add command table to the specified list
 * Arg:
 * int type specifies type of command DDB_SHOW_CMD|DDB_BASE_CMD
 * *cmd_tbl poiter to static allocated db_command table
 *
 *Command talbe have to be NULL terminated array of struct db_command
 */
int
db_add_command_tbl(uint8_t type, const struct db_command *cmd_tbl){
		/*XXX what is better count number of elements here or use num argument ?*/
		uint32_t i=0; 
		struct db_cmd_tbl_en *list_ent;
		const struct db_command *cmd;
		/*I have to check this because e.g. machine commands can be NULL*/
		if (cmd_tbl->name != 0) {   

				if ((list_ent = malloc (sizeof(struct db_cmd_tbl_en),M_TEMP,M_ZERO)) == NULL)
						return (ENOMEM);

				list_ent->db_cmd=cmd_tbl;
  

				for (cmd = cmd_tbl; cmd->name != 0; cmd++)
						i++;

				list_ent->db_cmd_num=i;
				printf("Number of elements :%d \n",i);

				/*Type specify list*/
				if (type == DDB_BASE_CMD){
						printf("Adding base cmds\n");
						if (TAILQ_EMPTY(&db_base_cmd_list))
								/*If head is empty we add first table here*/
								TAILQ_INSERT_HEAD(&db_base_cmd_list,list_ent,db_cmd_next); 
	  
						else
								/*new commands go to the end*/
								TAILQ_INSERT_TAIL(&db_base_cmd_list,list_ent,db_cmd_next); 
	  
				} else if (type == DDB_SHOW_CMD){
						printf("Adding Show cmds\n");

						if (TAILQ_EMPTY(&db_show_cmd_list))
								/*If head is empty we add first table here*/
								TAILQ_INSERT_HEAD(&db_show_cmd_list,list_ent,db_cmd_next);

						else
								/*new commands go to the end*/
								TAILQ_INSERT_TAIL(&db_show_cmd_list,list_ent,db_cmd_next);
                                

				} else
						return (ENOENT);
		}	
		return 0;
}
/*
 *Remove command table specified with db_cmd address == cmd_tbl
 */
int
db_rem_command_tbl(uint8_t type,const struct db_command *cmd_tbl){

		struct db_cmd_tbl_en *list_ent;
		int error=ENOENT;
  
		if  (db_base_cmd_list.tqh_first == NULL)
				return (error);
		printf("Removing command table\n");

		/*I go through the list, selected with type and look for
		  cmd_tbl address in list entries.*/
		if (type == DDB_BASE_CMD){

				TAILQ_FOREACH(list_ent,&db_base_cmd_list,db_cmd_next){
						if (list_ent->db_cmd == cmd_tbl){
								/*first I need to remove command table from
								  TAILQ list and then I can freed it*/
								TAILQ_REMOVE(&db_base_cmd_list,list_ent,db_cmd_next);
								free(list_ent,M_TEMP);
								error=0;/*I succefully find address so I return 0*/
						}
				}

		}else if (type == DDB_SHOW_CMD){

				TAILQ_FOREACH(list_ent,&db_show_cmd_list,db_cmd_next){
						if (list_ent->db_cmd == cmd_tbl){
								TAILQ_REMOVE(&db_show_cmd_list,list_ent,db_cmd_next);
								free(list_ent,M_TEMP);
								error=0;
						}
				}

		} else
				error=EINVAL;

		return (error);
}


void
db_command_loop(void){
  
		label_t	db_jmpbuf;
		label_t	*savejmp;

		/*
		 * Initialize 'prev' and 'next' to dot.
		 */
		db_prev = db_dot;
		db_next = db_dot;

		db_cmd_loop_done = 0;

		/*save context for return from ddb*/
		savejmp = db_recover;
		db_recover = &db_jmpbuf;
		(void) setjmp(&db_jmpbuf);

		/*Init default command tables add machine, base,
		  show command tables to the list*/
		(void) db_init_commands();

		/*Execute default ddb start commands*/
		db_execute_commandlist(db_cmd_on_enter);

		while (!db_cmd_loop_done) {
				if (db_print_position() != 0)
						db_printf("\n");
				db_output_line = 0;
d294 1
a294 1
				db_printf("db{%ld}> ", (long)cpu_number());
d296 1
a296 1
				db_printf("db> ");
d298 1
a298 1
				(void) db_read_line();
d300 2
a301 2
				db_command(&db_last_command);
		}
d303 1
a303 1
		db_recover = savejmp;
d307 1
a307 5
 * Search for command table for command prefix
 * ret: CMD_UNIQUE -> completly match cmd prefix
 *      CMD_FOUND  -> partialy match cmd prefix
 *      CMD_AMBIGIOUS ->more partialy matches
 *      CMD_NONE   -> command not found
d310 5
a314 37
db_cmd_search(const char *name,const struct db_command *table,
			  const struct db_command **cmdp){
  
		const struct db_command	*cmd;
		int			result = CMD_NONE;

		for (cmd = table; cmd->name != 0; cmd++) {
				const char *lp;
				const char *rp;
				int  c;

				lp = name;
				rp = cmd->name;
				while ((c = *lp) == *rp) {
						if (c == 0) {
								/* complete match */
								*cmdp = cmd;
								return (CMD_UNIQUE);
						}
						lp++;
						rp++;
				}
				if (c == 0) {
						/* end of name, not end of command -
						   partial match */
						if (result == CMD_FOUND) {
								result = CMD_AMBIGUOUS;
								/* but keep looking for a full match -
								   this lets us match single letters */
						} else {
								*cmdp = cmd;
								result = CMD_FOUND;
						}
				}
		}
		return (result);
}
d316 86
a401 2
static void
db_cmd_list(const struct db_cmd_tbl_en_head *list){
d403 1
a403 4
		struct db_cmd_tbl_en *list_ent;
		const struct db_command *table;
		int	 i, j, w, columns, lines, width=0, numcmds=0;
		const char	*p;
d405 25
a429 42
		TAILQ_FOREACH(list_ent,list,db_cmd_next){	  
				numcmds+=list_ent->db_cmd_num;
				table=list_ent->db_cmd;
	
				for (i = 0; i<list_ent->db_cmd_num; i++) {
						w = strlen(table[i].name);
						if (w > width)
								width = w;
				}
		}

		width = DB_NEXT_TAB(width);

		columns = db_max_width / width;
		if (columns == 0)
				columns = 1;

  
		TAILQ_FOREACH(list_ent,list,db_cmd_next){
				table=list_ent->db_cmd;

				lines = (list_ent->db_cmd_num + columns - 1) / columns;
	
				for (i = 0; i < lines; i++) {
						for (j = 0; j < columns; j++) {
								p = table[j * lines + i].name;
								if (p)
										db_printf("%s", p);
								if (j * lines + i + lines >= list_ent->db_cmd_num){
										db_putchar('\n');
										break;
								}
								if (p) {
										w = strlen(p);
										while (w < width) {
												w = DB_NEXT_TAB(w);
												db_putchar('\t');
										}
								}
						}
				}
		}
d431 10
a440 80
}

static int
db_get_list_type(const char *name){

		const struct db_command    *cmd;
		struct db_cmd_tbl_en *list_ent;
		int error,ret=-1;

		/*I go through base cmd list and search command with name(form cmd line)*/
		TAILQ_FOREACH(list_ent,&db_base_cmd_list,db_cmd_next){
				/*cmd_search returns CMD_UNIQUE, CMD_FOUND ...
				 *CMD_UNIQUE when name was completly matched to cmd->name
				 *CMD_FOUND  when name was only partially matched to cmd->name
				 *CMD_NONE   command not found in a list
				 *CMD_AMBIGIOUS ->more partialy matches   
				 */

				error=db_cmd_search(name,list_ent->db_cmd,&cmd);
				/*because I can't have better result then CMD_UNIQUE I break*/
				if (error == CMD_UNIQUE){
						if (strncmp(cmd->name,"show",4) == 0){
								ret=DDB_SHOW_CMD;
								break;
						} else {
								ret=DDB_BASE_CMD;
								break;
						}
						/*I have only partially matched name so I continue search*/
				} else if (error == CMD_FOUND){
						if (strncmp(cmd->name,"show",4) == 0)
								ret=DDB_SHOW_CMD;
						else
								ret=DDB_BASE_CMD;
				}
		}
  
		return(ret);
}

/*
 *Parse command line and execute apropriate function.
 */
static void
db_command(const struct db_command **last_cmdp){
		const struct db_command *command;
		struct db_cmd_tbl_en *list_ent;
		struct db_cmd_tbl_en_head *list;
  
		int		t;
		char		modif[TOK_STRING_SIZE];
		db_expr_t	addr, count;
		bool		have_addr = false;
		int		result;
		static db_expr_t last_count = 0;
  
		command = NULL;	/* XXX gcc */

		t = db_read_token();
		if ((t == tEOL) || (t == tCOMMA)) {
				/*
				 * An empty line repeats last command, at 'next'.
				 * Only a count repeats the last command with the new count.
				 */
				command = *last_cmdp;
				addr = (db_expr_t)db_next;
				if (t == tCOMMA) {
						if (!db_expression(&count)) {
								db_printf("Count missing\n");
								db_flush_lex();
								return;
						}
				} else
						count = last_count;
				have_addr = false;
				modif[0] = '\0';
				db_skip_to_eol();

		} else if (t == tEXCL) {
				db_fncall(0, 0, 0, NULL);
d442 2
a443 3

		} else if (t != tIDENT) {
				db_printf("?\n");
d446 3
a448 207

		} else {

				switch(db_get_list_type(db_tok_string)){
	  
				case DDB_BASE_CMD:
						list=&db_base_cmd_list;
						break;
				case DDB_SHOW_CMD:
						list=&db_show_cmd_list;
						/*I need to read show subcommand If show command list is used.*/
						t = db_read_token(); 

						if (t != tIDENT) {
								/*if only show command is executed I print all subcommands*/
								db_cmd_list(&db_show_cmd_list); 
								db_flush_lex();
								return;
						}
	  
						break;
				default:
						db_printf("No such command\n");
						db_flush_lex();                 
						return;
				}


				TAILQ_FOREACH(list_ent,list,db_cmd_next){
						result = db_cmd_search(db_tok_string, list_ent->db_cmd, &command);
						/*after CMD_UNIQUE in cmd_list only one same command name is possible*/
						if (result == CMD_UNIQUE)
								break;
				}

				if ((command->flag & CS_OWN) == 0) {

						/*
						 * Standard syntax:
						 * command [/modifier] [addr] [,count]
						 */
						t = db_read_token(); /*get modifier*/
						if (t == tSLASH) { 
								t = db_read_token();
								if (t != tIDENT) {
										db_printf("Bad modifier\n");
										db_flush_lex();
										return;
								}
								strlcpy(modif, db_tok_string, sizeof(modif)); /*save modifier*/
		
						} else {
								db_unread_token(t);
								modif[0] = '\0';
						}

						if (db_expression(&addr)) { /*get address*/
								db_dot = (db_addr_t) addr;
								db_last_addr = db_dot;
								have_addr = true;
						} else {
								addr = (db_expr_t) db_dot;
								have_addr = false;
						}

						t = db_read_token();
						if (t == tCOMMA) { /*Get count*/
								if (!db_expression(&count)) {
										db_printf("Count missing\n");
										db_flush_lex();
										return;
								}
						} else { 
								db_unread_token(t);
								count = -1;
						}
						if ((command->flag & CS_MORE) == 0) {
								db_skip_to_eol();
						}
				}
		}

		*last_cmdp = command;
		last_count = count;

		if (command != 0) {
				/*
				 * Execute the command.
				 */
				(*command->fcn)(addr, have_addr, count, modif);

				if (command->flag & CS_SET_DOT) {
						/*
						 * If command changes dot, set dot to
						 * previous address displayed (if 'ed' style).
						 */
						if (db_ed_style)
								db_dot = db_prev;
						else
								db_dot = db_next;
				} else {
						/*
						 * If command does not change dot,
						 * set 'next' location to be the same.
						 */
						db_next = db_dot;
				}
		}
}

/*
 *Print help for commands
 */
static void
db_help_print_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
				  const char *modif){
  
		const struct db_cmd_tbl_en_head *list;
		const struct db_cmd_tbl_en *list_ent;
		const struct db_command *help;
		int t,result;
  
		t=db_read_token();
		/*I have also another command not only help*/
		if (t == tIDENT){

				switch(db_get_list_type(db_tok_string)){

				case DDB_BASE_CMD:
						list=&db_base_cmd_list;
						break;
				case DDB_SHOW_CMD:
						list=&db_show_cmd_list;
						/*I need to read show subcommand If show command list is used.*/
						t = db_read_token(); 

						if (t != tIDENT) {
								/*if only show command is executed I print all subcommands*/
								db_cmd_list(&db_show_cmd_list);
								db_flush_lex();
								return;
						}

						if (strncmp("all",db_tok_string,3) == 0){
								t = db_read_token();

								if (t != tIDENT) {
										/*if only show command is executed I print all subcommands*/
										db_printf("callout, pages, polls, procs\n");
										db_flush_lex();
										return;
								}

						}
						
	  
						break;
				default:
						db_printf("No such command\n");
						db_flush_lex();
						return;
				}

				TAILQ_FOREACH(list_ent,list,db_cmd_next){
						result = db_cmd_search(db_tok_string, list_ent->db_cmd, &help);
						/*after CMD_UNIQUE in cmd_list only one same command name is possible*/
						if (result == CMD_UNIQUE)
								break;
				}

				/*print help*/
				if (help->cmd_arg != NULL)
						db_printf("Command: %s Arguments: %s\n Descr: %s\n",
								  help->name,help->cmd_arg,help->cmd_descr);
				else
						db_printf("Command: %s Doesn't have any help message included.\n",
								  help->name);

		} else
				/*print base commands*/
				db_cmd_list(&db_base_cmd_list);
		
		return;
}

/*
 *Keep DDB interface backward compatible with old versions
 */
static void
db_ui_compat_cmd(db_expr_t ar_addr, bool ar_have_addr, db_expr_t ar_count,
				 const char *ar_modif){

		const struct db_command *command;
		struct db_cmd_tbl_en *list_ent;
  
		int		t;
		char		modif[TOK_STRING_SIZE];
		db_expr_t	addr, count;
		bool		have_addr = false;
		int		result;
		static db_expr_t last_count = 0;

		/*read next command behind all*/
		t = db_read_token();
		
		if (t != tIDENT){
				printf("callout,pages,procs,pools are show all subcommands\n");
d450 11
d463 18
a480 7
		/*XXX Search inserted command  we support no show all whatever show command*/
		TAILQ_FOREACH(list_ent,&db_show_cmd_list,db_cmd_next){
				result = db_cmd_search(db_tok_string, list_ent->db_cmd, &command);
				/*after CMD_UNIQUE in cmd_list only one same command name is possible*/
				if (result == CMD_UNIQUE)
						break;
		}
d482 22
a503 44
		if ((command->flag & CS_OWN) == 0) {

				/*
				 * Standard syntax:
				 * command [/modifier] [addr] [,count]
				 */
				t = db_read_token(); /*get modifier*/
				if (t == tSLASH) { 
						t = db_read_token();
						if (t != tIDENT) {
								db_printf("Bad modifier\n");
								db_flush_lex();
								return;
						}
						strlcpy(modif, db_tok_string, sizeof(modif)); /*save modifier*/
						
				} else {
						db_unread_token(t);
						modif[0] = '\0';
				}
				
				if (db_expression(&addr)) { /*get address*/
						db_dot = (db_addr_t) addr;
						db_last_addr = db_dot;
						have_addr = true;
				} else {
						addr = (db_expr_t) db_dot;
						have_addr = false;
				}
				
				t = db_read_token();
				if (t == tCOMMA) { /*Get count*/
						if (!db_expression(&count)) {
								db_printf("Count missing\n");
								db_flush_lex();
								return;
						}
				} else { 
						db_unread_token(t);
						count = -1;
				}
				if ((command->flag & CS_MORE) == 0) {
						db_skip_to_eol();
				}
d505 8
d514 15
a528 27

		last_count = count;
		
		if (command != 0) {
				/*
				 * Execute the command.
				 */
				(*command->fcn)(addr, have_addr, count, modif);
				
				if (command->flag & CS_SET_DOT) {
						/*
						 * If command changes dot, set dot to
						 * previous address displayed (if 'ed' style).
						 */
						if (db_ed_style)
								db_dot = db_prev;
						else
								db_dot = db_next;
				} else {
						/*
						 * If command does not change dot,
						 * set 'next' location to be the same.
						 */
						db_next = db_dot;
				}
				
				
d530 1
a530 1
		return;
d536 1
a536 1
				 const char *modif)
d538 1
a538 1
		bool full = false;
d540 2
a541 2
		if (modif[0] == 'f')
				full = true;
d543 2
a544 2
		if (have_addr == false)
				addr = (db_expr_t)(intptr_t) kernel_map;
d546 1
a546 1
		uvm_map_printit((struct vm_map *)(intptr_t) addr, full, db_printf);
d552 1
a552 1
					db_expr_t count, const char *modif)
d556 2
a557 2
		if (!have_addr)
				addr = 0;
d559 1
a559 1
		debug_malloc_printit(db_printf, (vaddr_t) addr);
d561 1
a561 1
		db_printf("The kernel is not built with the MALLOC_DEBUG option.\n");
d568 1
a568 1
					db_expr_t count, const char *modif)
d570 1
a570 1
		bool full = false;
d572 2
a573 2
		if (modif[0] == 'f')
				full = true;
d575 2
a576 2
		uvm_object_printit((struct uvm_object *)(intptr_t) addr, full,
						   db_printf);
d582 1
a582 1
				  db_expr_t count, const char *modif)
d584 1
a584 1
		bool full = false;
d586 2
a587 2
		if (modif[0] == 'f')
				full = true;
d589 1
a589 1
		uvm_page_printit((struct vm_page *)(intptr_t) addr, full, db_printf);
d595 1
a595 1
				  db_expr_t count, const char *modif)
d598 1
a598 1
		uvm_page_printall(db_printf);
d604 1
a604 1
				 db_expr_t count, const char *modif)
d606 1
a606 1
		bool full = false;
d608 2
a609 2
		if (modif[0] == 'f')
				full = true;
d611 1
a611 1
		vfs_buf_print((struct buf *)(intptr_t) addr, full, db_printf);
d617 1
a617 1
				   db_expr_t count, const char *modif)
d619 1
a619 1
		bool full = false;
d621 2
a622 2
		if (modif[0] == 'f')
				full = true;
d624 1
a624 1
		event_print(full, db_printf);
d630 1
a630 1
				   db_expr_t count, const char *modif)
d632 1
a632 1
		bool full = false;
d634 2
a635 2
		if (modif[0] == 'f')
				full = true;
d637 1
a637 1
		vfs_vnode_print((struct vnode *)(intptr_t) addr, full, db_printf);
d642 1
a642 1
				   db_expr_t count, const char *modif)
d644 1
a644 1
		bool full = false;
d646 2
a647 2
		if (modif[0] == 'f')
				full = true;
d649 1
a649 1
		vfs_mount_print((struct mount *)(intptr_t) addr, full, db_printf);
d655 1
a655 1
				  db_expr_t count, const char *modif)
d658 1
a658 1
		m_print((const struct mbuf *)(intptr_t) addr, modif, db_printf);
d664 1
a664 1
				  db_expr_t count, const char *modif)
d667 1
a667 1
		pool_printit((struct pool *)(intptr_t) addr, modif, db_printf);
d673 1
a673 1
					   db_expr_t count, const char *modif)
d676 1
a676 1
		namecache_print((struct vnode *)(intptr_t) addr, db_printf);
d682 1
a682 1
					db_expr_t count, const char *modif)
d685 1
a685 1
		uvmexp_print(db_printf);
d691 1
a691 1
				  db_expr_t count, const char *modif)
d694 1
a694 1
		lockdebug_lock_print((void *)addr, db_printf);
d704 1
a704 1
		  db_expr_t count, const char *modif)
d706 1
a706 1
		db_expr_t	fn_addr;
d708 12
a719 5
		db_expr_t	args[MAXARGS];
		int		nargs = 0;
		db_expr_t	retval;
		db_expr_t	(*func)(db_expr_t, ...);
		int		t;
d721 34
a754 41
		if (!db_expression(&fn_addr)) {
				db_printf("Bad function\n");
				db_flush_lex();
				return;
		}
		func = (db_expr_t (*)(db_expr_t, ...))(intptr_t) fn_addr;

		t = db_read_token();
		if (t == tLPAREN) {
				if (db_expression(&args[0])) {
						nargs++;
						while ((t = db_read_token()) == tCOMMA) {
								if (nargs == MAXARGS) {
										db_printf("Too many arguments\n");
										db_flush_lex();
										return;
								}
								if (!db_expression(&args[nargs])) {
										db_printf("Argument missing\n");
										db_flush_lex();
										return;
								}
								nargs++;
						}
						db_unread_token(t);
				}
				if (db_read_token() != tRPAREN) {
						db_printf("?\n");
						db_flush_lex();
						return;
				}
		}
		db_skip_to_eol();

		while (nargs < MAXARGS) {
				args[nargs++] = 0;
		}

		retval = (*func)(args[0], args[1], args[2], args[3], args[4],
						 args[5], args[6], args[7], args[8], args[9]);
		db_printf("%s\n", db_num_to_str(retval));
d759 1
a759 1
			  db_expr_t count, const char *modif)
d761 1
a761 1
		db_expr_t bootflags;
d763 14
a776 14
		/* Flags, default to RB_AUTOBOOT */
		if (!db_expression(&bootflags))
				bootflags = (db_expr_t)RB_AUTOBOOT;
		if (db_read_token() != tEOL) {
				db_error("?\n");
				/*NOTREACHED*/
		}
		/*
		 * We are leaving DDB, never to return upward.
		 * Clear db_recover so that we can debug faults in functions
		 * called from cpu_reboot.
		 */
		db_recover = 0;
		cpu_reboot((int)bootflags, NULL);
d781 1
a781 1
			   db_expr_t count, const char *modif)
d783 1
a783 1
		int	mode, t;
d785 2
d788 13
a800 15
		if (t == tSLASH) {
				t = db_read_token();
				if (t != tIDENT) {
				bad_modifier:
						db_printf("Bad modifier\n");
						db_flush_lex();
						return;
				}
				if (!strcmp(db_tok_string, "F"))
						mode = 'F';
				else
						goto bad_modifier;
				t = db_read_token();
		} else
				mode = 0;
d802 6
a807 6
		if (t == tIDENT)
				db_sifting(db_tok_string, mode);
		else {
				db_printf("Bad argument (non-string)\n");
				db_flush_lex();
		}
d811 1
a811 2
db_stack_trace_cmd(db_expr_t addr, bool have_addr,
				   db_expr_t count, const char *modif)
d813 8
a820 8
		register const char *cp = modif;
		register char c;
		void (*pr)(const char *, ...);

		pr = db_printf;
		while ((c = *cp++) != 0)
				if (c == 'l')
						pr = printf;
d822 2
a823 2
		if (count == -1)
				count = 65535;
d825 1
a825 1
		db_stack_trace_print(addr, have_addr, count, modif, pr);
d830 1
a830 1
			db_expr_t count, const char *modif)
d833 7
a839 7
		/*
		 * We are leaving DDB, never to return upward.
		 * Clear db_recover so that we can debug faults in functions
		 * called from cpu_reboot.
		 */
		db_recover = 0;
		cpu_reboot(RB_DUMP, NULL);
Index: ddb/db_command.h
===================================================================
RCS file: /cvsroot/src/sys/ddb/db_command.h,v
retrieving revision 1.27
diff -n -r1.27 db_command.h
a2 36
/*-
 * Copyright (c) 1996, 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Adam Hamsik.
 *
 * 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.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *        This product includes software developed by the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
 */

d32 4
a35 2
#ifndef _DDB_COMMAND_
#define _DDB_COMMAND_
d44 1
a44 1
							   or written */
d46 1
a46 1
							   or written */
a49 29
struct db_command;



/*
 * Macro include help when DDB_VERBOSE_HELP option(9) is used
 */
#if defined(DDB_VERBOSE_HELP)
#define DDB_ADD_CMD(name,funct,type,cmd_descr,cmd_arg)\
 name,funct,type,cmd_descr,cmd_arg
#else
#define DDB_ADD_CMD(name,funct,type,cmd_descr,cmd_arg)\
 name,funct,type,NULL,NULL
#endif
   


/*
 * we have two types of lists one for base commands like reboot
 * and another list for show subcommands.
 */

#define DDB_BASE_CMD 0
#define DDB_SHOW_CMD 1


int db_add_command_tbl(uint8_t, const struct db_command *);
int db_rem_command_tbl(uint8_t, const struct db_command *);

d54 4
a57 5
  const char	*name;		/* command name */
  
  /* function to call */
  void		(*fcn)(db_expr_t, bool, db_expr_t, const char *);
  uint16_t		flag;		/* extra info: */
d60 1
a60 1
							   words at end */
d62 1
a62 4

  const char *cmd_descr; /*description of command*/
  const char *cmd_arg;   /*command arguments*/
  
a63 4

#endif /*_DDB_COMMAND_*/


Index: ddb/files.ddb
===================================================================
RCS file: /cvsroot/src/sys/ddb/files.ddb,v
retrieving revision 1.1
diff -n -r1.1 files.ddb
d6 1
a6 1
defflag opt_ddb.h		DDB 
d9 1
a9 1
				DDB_COMMANDONENTER DDB_VERBOSE_HELP

--Apple-Mail-2--136385872
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

Regards
-----------------------------------------
Adam Hamsik
jabber: haad@jabber.org
icq: 249727910

Proud NetBSD user.

We program to have fun.
Even when we program for money, we want to have fun as well.
~~ Yukihiro Matsumoto





--Apple-Mail-2--136385872--

--Apple-Mail-3--136385819
content-type: application/pgp-signature; x-mac-type=70674453;
	name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)

iD8DBQFGl24clIxPgX3Go0MRAorpAKCcDhsh+X0nOCjvPslXMvLozNRa3gCfUcbi
lJ3rSike8AzPUJPm+DkYbH4=
=nrQy
-----END PGP SIGNATURE-----

--Apple-Mail-3--136385819--