Subject: Re: ddb help command patch
To: Iain Hibbert <plunky@rya-online.net>
From: Adam Hamsik <haaaad@gmail.com>
List: tech-kern
Date: 08/02/2007 22:21:13
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--Apple-Mail-2--527040682
Content-Type: multipart/mixed; boundary=Apple-Mail-1--527040697
--Apple-Mail-1--527040697
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed
Hi
On Jul 21, 2007, at 9:56 AM, Iain Hibbert wrote:
> On Sat, 21 Jul 2007, Adam Hamsik wrote:
>
>> sorry for noise :( but I have generated good patch now. now my patch
>> include all files also added files. you can review it at [1].
>>
>> [1]http://wasabi.fiit.stuba.sk/~haad/netbsd/ddb_cmd.diff
>
> I have some style comments:
>
> <tab><tab> indent in a block is not necessary, just use one
>
> keep to 80 columns
>
> and
>
> static void
> db_map_print_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
> - const char *modif)
> -{
> - bool full = false;
> -
> - if (modif[0] == 'f')
> - full = true;
> + const char *modif){
> + bool full = false;
> +
> + if (modif[0] == 'f')
> + full = true;
>
> - if (have_addr == false)
> - addr = (db_expr_t)(intptr_t) kernel_map;
> + if (have_addr == false)
> + addr = (db_expr_t)(intptr_t) kernel_map;
>
> - uvm_map_printit((struct vm_map *)(intptr_t) addr, full, db_printf);
> + uvm_map_printit((struct vm_map *)(intptr_t) addr, full, db_printf);
> }
>
> in this kind of instance, there are only [unwelcome] style changes.
>
> see /usr/share/misc/style guidelines on code style. Although your
> style
> may have merit, we use a standard KNF style for a good reason. I think
> your patch would be a lot smaller (and thus easier to interpret) if
> it did
> not contain such.
>
> regards,
> iain
Sorry for late response I was quite busy at work this week.
I have made last version of my ddb patch. I have added support for
machine commands and improved code. I have changed db_add_command_tbl
&& db_rem_command_tbl to db_register_tbl && db_unregister_tbl which I
think is better. I have removed all unwanted style changes. This
patch is fully compatible with all ddb interface.
Current situation with is this.
I have defined 3 TAILQs for show commands, for machine commands and
for base commands.
Registering of commands:
db_register_tbl(DDB_SHOW_CMD|DDB_BASE_CMD|DDB_MACH_CMD,struct
db_command*);
Unregistering of commands:
db_unregister_tbl(struct db_command*);
This patch also add DDB help for commands support. For this you have to
add DDB_VERBOSE_HELP kernel option to your kernel config file and
recompile/reload your kernel.
--Apple-Mail-1--527040697
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
x-unix-mode=0644;
name=ddb_cmd.diff
Content-Disposition: attachment;
filename=ddb_cmd.diff
Index: ddb/db_command.c
===================================================================
RCS file: /cvsroot/src/sys/ddb/db_command.c,v
retrieving revision 1.96
diff -u -r1.96 db_command.c
--- ddb/db_command.c 30 Apr 2007 14:44:30 -0000 1.96
+++ ddb/db_command.c 2 Aug 2007 20:15:53 -0000
@@ -1,4 +1,39 @@
/* $NetBSD: db_command.c,v 1.96 2007/04/30 14:44:30 rmind Exp $ */
+/*
+ * 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.
+ */
/*
* Mach Operating System
@@ -51,6 +86,9 @@
#include <sys/lockdebug.h>
#include <sys/sleepq.h>
+/*include queue macros*/
+#include <sys/queue.h>
+
#include <machine/db_machdep.h> /* type definitions */
#if defined(_KERNEL_OPT)
@@ -70,6 +108,7 @@
#include <ddb/db_interface.h>
#include <ddb/db_sym.h>
#include <ddb/db_extern.h>
+#include <ddb/db_command_list.h>
#include <uvm/uvm_extern.h>
#include <uvm/uvm_ddb.h>
@@ -83,7 +122,23 @@
#define CMD_FOUND 1
#define CMD_NONE 2
#define CMD_AMBIGUOUS 3
-#define CMD_HELP 4
+
+#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)
+
+
/*
* Exported global variables
@@ -95,6 +150,30 @@
db_addr_t db_prev;
db_addr_t db_next;
+
+/*
+ New DDB api for adding and removing commands uses three 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
+ c) if defined machine specific commands
+
+ 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);
+
+#ifdef DB_MACHINE_COMMANDS
+/*head of machine commands list*/
+static struct db_cmd_tbl_en_head db_mach_cmd_list=TAILQ_HEAD_INITIALIZER(db_mach_cmd_list);
+#endif
+
/*
* if 'ed' style: 'dot' is set at start of last item printed,
* and '+' points to next line.
@@ -102,14 +181,19 @@
*/
static bool db_ed_style = true;
-static void db_buf_print_cmd(db_expr_t, bool, db_expr_t, const char *);
-static void db_cmd_list(const struct db_command *);
+static void db_cmd_list(const struct db_cmd_tbl_en_head *);
static int db_cmd_search(const char *, const struct db_command *,
- const struct db_command **);
-static void db_command(const struct db_command **,
- const struct db_command *);
+ 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 *);
static void db_event_print_cmd(db_expr_t, bool, db_expr_t, const char *);
static void db_fncall(db_expr_t, bool, db_expr_t, const char *);
+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 *);
static void db_malloc_print_cmd(db_expr_t, bool, db_expr_t, const char *);
static void db_map_print_cmd(db_expr_t, bool, db_expr_t, const char *);
static void db_namecache_print_cmd(db_expr_t, bool, db_expr_t, const char *);
@@ -123,46 +207,60 @@
static void db_sync_cmd(db_expr_t, bool, db_expr_t, const char *);
static void db_uvmexp_print_cmd(db_expr_t, bool, db_expr_t, const char *);
static void db_vnode_print_cmd(db_expr_t, bool, db_expr_t, const char *);
-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 *);
-/*
- * 'show' commands
- */
-
-static const struct db_command db_show_all_cmds[] = {
- { "callout", db_show_callout, 0, NULL },
- { "pages", db_show_all_pages, 0, NULL },
- { "procs", db_show_all_procs, 0, NULL },
- { "pools", db_show_all_pools, 0, NULL },
- { NULL, NULL, 0, NULL }
-};
static const struct db_command db_show_cmds[] = {
- { "aio_jobs", db_show_aio_jobs, 0, NULL },
- { "all", NULL, 0, db_show_all_cmds },
+ /*added from all sub cmds*/
+ { DDB_ADD_CMD("callout", db_show_callout,
+ 0 ,"List all used callout functions.",NULL) },
+ { DDB_ADD_CMD("pages", db_show_all_pages,
+ 0 ,"List all used memory pages.",NULL) },
+ { DDB_ADD_CMD("procs", db_show_all_procs,
+ 0 ,"List all processes.",NULL) },
+ { DDB_ADD_CMD("pools", db_show_all_pools,
+ 0 ,"Show all poolS",NULL) },
+ /*added from all sub cmds*/
+ { DDB_ADD_CMD("aio_jobs", db_show_aio_jobs, 0,
+ "Show aio jobs",NULL) },
+ { DDB_ADD_CMD("all", NULL,
+ CS_COMPAT, NULL, NULL) },
#if defined(INET) && (NARP > 0)
- { "arptab", db_show_arptab, 0, NULL },
+ { DDB_ADD_CMD("arptab", db_show_arptab, 0,NULL,NULL) },
#endif
- { "breaks", db_listbreak_cmd, 0, NULL },
- { "buf", db_buf_print_cmd, 0, NULL },
- { "event", db_event_print_cmd, 0, NULL },
- { "lock", db_lock_print_cmd, 0, NULL },
- { "malloc", db_malloc_print_cmd, 0, NULL },
- { "map", db_map_print_cmd, 0, NULL },
- { "mount", db_mount_print_cmd, 0, NULL },
- { "mbuf", db_mbuf_print_cmd, 0, NULL },
- { "ncache", db_namecache_print_cmd, 0, NULL },
- { "object", db_object_print_cmd, 0, NULL },
- { "page", db_page_print_cmd, 0, NULL },
- { "pool", db_pool_print_cmd, 0, NULL },
- { "registers", db_show_regs, 0, NULL },
- { "sched_qs", db_show_sched_qs, 0, NULL },
- { "uvmexp", db_uvmexp_print_cmd, 0, NULL },
- { "vnode", db_vnode_print_cmd, 0, NULL },
- { "watches", db_listwatch_cmd, 0, NULL },
- { NULL, NULL, 0, NULL }
+ { 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) }
};
/* arch/<arch>/<arch>/db_interface.c */
@@ -171,45 +269,89 @@
#endif
static const struct db_command db_command_table[] = {
- { "b", db_breakpoint_cmd, 0, NULL },
- { "break", db_breakpoint_cmd, 0, NULL },
- { "bt", db_stack_trace_cmd, 0, NULL },
- { "c", db_continue_cmd, 0, NULL },
- { "call", db_fncall, CS_OWN, NULL },
- { "callout", db_show_callout, 0, NULL },
- { "continue", db_continue_cmd, 0, NULL },
- { "d", db_delete_cmd, 0, NULL },
- { "delete", db_delete_cmd, 0, NULL },
- { "dmesg", db_dmesg, 0, NULL },
- { "dwatch", db_deletewatch_cmd, 0, NULL },
- { "examine", db_examine_cmd, CS_SET_DOT, NULL },
- { "kill", db_kill_proc, CS_OWN, NULL },
+ { 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]") },
#ifdef KGDB
- { "kgdb", db_kgdb_cmd, 0, NULL },
+ { DDB_ADD_CMD("kgdb", db_kgdb_cmd, 0, NULL) },
#endif
#ifdef DB_MACHINE_COMMANDS
- { "machine", NULL, 0, db_machine_command_table },
-#endif
- { "match", db_trace_until_matching_cmd,0, NULL },
- { "next", db_trace_until_matching_cmd,0, NULL },
- { "p", db_print_cmd, 0, NULL },
- { "print", db_print_cmd, 0, NULL },
- { "ps", db_show_all_procs, 0, NULL },
- { "reboot", db_reboot_cmd, CS_OWN, NULL },
- { "s", db_single_step_cmd, 0, NULL },
- { "search", db_search_cmd, CS_OWN|CS_SET_DOT, NULL },
- { "set", db_set_cmd, CS_OWN, NULL },
- { "show", NULL, 0, db_show_cmds },
- { "sifting", db_sifting_cmd, CS_OWN, NULL },
- { "step", db_single_step_cmd, 0, NULL },
- { "sync", db_sync_cmd, CS_OWN, NULL },
- { "trace", db_stack_trace_cmd, 0, NULL },
- { "until", db_trace_until_call_cmd,0, NULL },
- { "w", db_write_cmd, CS_MORE|CS_SET_DOT, NULL },
- { "watch", db_watchpoint_cmd, CS_MORE, NULL },
- { "write", db_write_cmd, CS_MORE|CS_SET_DOT, NULL },
- { "x", db_examine_cmd, CS_SET_DOT, NULL },
- { NULL, NULL, 0, NULL }
+ { DDB_ADD_CMD("machine",NULL,CS_MACH,
+ "Architecture specific functions.",NULL) },
+#endif
+ { 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 ,CS_SHOW,
+ "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) }
};
static const struct db_command *db_last_command = NULL;
@@ -243,6 +385,7 @@
longjmp(db_recover);
}
+/*Execute commandlist after ddb start*/
static void
db_execute_commandlist(const char *cmdlist)
{
@@ -256,7 +399,7 @@
ep++;
}
db_set_line(cmd, ep);
- db_command(&dummy, db_command_table);
+ db_command(&dummy);
cmd = ep;
if (*cmd == DB_LINE_SEP) {
cmd++;
@@ -264,9 +407,164 @@
}
}
+/*Initialize ddb command tables*/
+static void
+db_init_commands(void)
+{
+ struct db_cmd_tbl_en *list_ent;
+
+
+/* TAILQ_INIT(&db_base_cmd_list);
+ TAILQ_INIT(&db_show_cmd_list);*/
+
+ TAILQ_FOREACH(list_ent,&db_base_cmd_list,db_cmd_next)
+ if (list_ent->db_cmd == db_command_table)
+ return;
+
+ TAILQ_FOREACH(list_ent,&db_show_cmd_list,db_cmd_next)
+ if (list_ent->db_cmd == db_show_cmds)
+ return;
+
+#ifdef DB_MACHINE_COMMANDS
+ TAILQ_FOREACH(list_ent,&db_mach_cmd_list,db_cmd_next)
+ if (list_ent->db_cmd == db_machine_command_table)
+ return;
+#endif
+ printf("Initialize command tables\n");
+
+ (void)db_register_tbl(DDB_BASE_CMD,db_command_table);
+
+#ifdef DB_MACHINE_COMMANDS
+ (void)db_register_tbl(DDB_MACH_CMD,db_machine_command_table);
+#endif
+ (void)db_register_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 table DDB_SHOW_CMD|DDB_BASE_CMD|DDB_MAC_CMD
+ * *cmd_tbl poiter to static allocated db_command table
+ *
+ *Command table must be NULL terminated array of struct db_command
+ */
+int
+db_register_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;
+ struct db_cmd_tbl_en_head *list;
+
+ /*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);
+
+ switch(type){
+
+ case DDB_BASE_CMD:
+ list=&db_base_cmd_list;
+ break;
+
+ case DDB_SHOW_CMD:
+ list=&db_show_cmd_list;
+ break;
+
+ case DDB_MACH_CMD:
+ list=&db_mach_cmd_list;
+ break;
+
+ default:
+ return (ENOENT);
+ break;
+ }
+
+ /*Type specify list*/
+
+ if (TAILQ_EMPTY(list))
+ /*If head is empty we add first table here*/
+ TAILQ_INSERT_HEAD(list,
+ list_ent,db_cmd_next);
+ else
+ /*new commands go to the end*/
+ TAILQ_INSERT_TAIL(list,
+ list_ent,db_cmd_next);
+ }
+ return 0;
+}
+/*
+ *Remove command table specified with db_cmd address == cmd_tbl
+ */
+int
+db_unregister_tbl(uint8_t type,const struct db_command *cmd_tbl)
+{
+
+ struct db_cmd_tbl_en *list_ent;
+ struct db_cmd_tbl_en_head *list;
+ 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.*/
+ switch(type){
+
+ case DDB_BASE_CMD:
+ list=&db_base_cmd_list;
+ break;
+
+ case DDB_SHOW_CMD:
+ list=&db_show_cmd_list;
+ break;
+
+ case DDB_MACH_CMD:
+ list=&db_mach_cmd_list;
+ break;
+
+ default:
+ return (EINVAL);
+ break;
+ }
+
+ TAILQ_FOREACH(list_ent,list,db_cmd_next){
+
+ if (list_ent->db_cmd == cmd_tbl){
+ TAILQ_REMOVE(list,
+ list_ent,db_cmd_next);
+
+ free(list_ent,M_TEMP);
+ error=0;
+ }
+ }
+ return (error);
+}
+
+/*This function is called from machine trap code.*/
void
db_command_loop(void)
{
+
label_t db_jmpbuf;
label_t *savejmp;
@@ -278,10 +576,16 @@
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) {
@@ -297,19 +601,24 @@
#endif
(void) db_read_line();
- db_command(&db_last_command, db_command_table);
+ db_command(&db_last_command);
}
db_recover = savejmp;
}
/*
- * Search for command prefix.
+ * 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
*/
static int
-db_cmd_search(const char *name, const struct db_command *table,
+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;
@@ -342,65 +651,135 @@
}
}
}
- if (result == CMD_NONE) {
- /* check for 'help' */
- if (name[0] == 'h' && name[1] == 'e'
- && name[2] == 'l' && name[3] == 'p')
- result = CMD_HELP;
- }
return (result);
}
+/*
+ *List commands to the console.
+ */
static void
-db_cmd_list(const struct db_command *table)
+db_cmd_list(const struct db_cmd_tbl_en_head *list)
{
- int i, j, w, columns, lines, width=0, numcmds;
+
+ 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;
- for (numcmds = 0; table[numcmds].name != NULL; numcmds++) {
- w = strlen(table[numcmds].name);
- if (w > width)
- width = w;
+ 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;
- lines = (numcmds + 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 >= numcmds) {
- db_putchar('\n');
+
+
+ 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');
+ }
+ }
+ }
+ }
+ }
+ return;
+}
+
+/*
+ *Returns type of list for command with name *name.
+ */
+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 (cmd->flag == CS_SHOW){
+ ret=DDB_SHOW_CMD;
break;
}
- if (p) {
- w = strlen(p);
- while (w < width) {
- w = DB_NEXT_TAB(w);
- db_putchar('\t');
- }
+
+ if (cmd->flag == CS_MACH){
+ ret=DDB_MACH_CMD;
+ break;
+ } else {
+ ret=DDB_BASE_CMD;
+ break;
}
+ /*I have only partially matched name so I continue search*/
+ } else if (error == CMD_FOUND){
+ if (cmd->flag == CS_SHOW)
+ ret=DDB_SHOW_CMD;
+ if (cmd->flag == CS_MACH)
+ ret=DDB_MACH_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 *cmd_table)
+db_command(const struct db_command **last_cmdp)
{
- const struct db_command *cmd;
+ const struct db_command *command;
+ struct db_cmd_tbl_en *list_ent;
+ struct db_cmd_tbl_en_head *list;
+
int t;
+ int result;
+
char modif[TOK_STRING_SIZE];
db_expr_t addr, count;
bool have_addr = false;
- int result;
- static db_expr_t last_count = 0;
- cmd = NULL; /* XXX gcc */
+ static db_expr_t last_count = 0;
+
+ command = NULL; /* XXX gcc */
t = db_read_token();
if ((t == tEOL) || (t == tCOMMA)) {
@@ -408,7 +787,7 @@
* An empty line repeats last command, at 'next'.
* Only a count repeats the last command with the new count.
*/
- cmd = *last_cmdp;
+ command = *last_cmdp;
addr = (db_expr_t)db_next;
if (t == tCOMMA) {
if (!db_expression(&count)) {
@@ -421,65 +800,99 @@
have_addr = false;
modif[0] = '\0';
db_skip_to_eol();
+
} else if (t == tEXCL) {
db_fncall(0, 0, 0, NULL);
return;
+
} else if (t != tIDENT) {
db_printf("?\n");
db_flush_lex();
return;
+
} else {
- /*
- * Search for command
- */
- while (cmd_table) {
- result = db_cmd_search(db_tok_string, cmd_table, &cmd);
- switch (result) {
- case CMD_NONE:
- db_printf("No such command\n");
- db_flush_lex();
- return;
- case CMD_AMBIGUOUS:
- db_printf("Ambiguous\n");
+
+ 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(list);
db_flush_lex();
return;
- case CMD_HELP:
- db_cmd_list(cmd_table);
+ }
+ break;
+ case DDB_MACH_CMD:
+ list=&db_mach_cmd_list;
+ /*I need to read machine subcommand If
+ machine level 2 command list is used.*/
+ t = db_read_token();
+
+ if (t != tIDENT) {
+ /*if only show command is executed I print all subcommands*/
+ db_cmd_list(list);
db_flush_lex();
return;
- default:
+ }
+ break;
+ default:
+ db_printf("No such command\n");
+ db_flush_lex();
+ return;
+ }
+
+ COMPAT_RET:
+ 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 ((cmd_table = cmd->more) != 0) {
- t = db_read_token();
- if (t != tIDENT) {
- db_cmd_list(cmd_table);
+
+ }
+
+ /*check compatibility flag*/
+ if (command->flag & CS_COMPAT){
+ t = db_read_token();
+ if (t != tIDENT){
+ db_cmd_list(list);
db_flush_lex();
return;
- }
}
- }
- if ((cmd->flag & CS_OWN) == 0) {
+ goto COMPAT_RET; /*WE support only level 2 commands*/
+ }
+
+
+ if ((command->flag & CS_OWN) == 0) {
+
/*
* Standard syntax:
* command [/modifier] [addr] [,count]
*/
- t = db_read_token();
- if (t == tSLASH) {
+ 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));
+ strlcpy(modif, db_tok_string, sizeof(modif)); /*save modifier*/
+
} else {
db_unread_token(t);
modif[0] = '\0';
}
- if (db_expression(&addr)) {
+ if (db_expression(&addr)) { /*get address*/
db_dot = (db_addr_t) addr;
db_last_addr = db_dot;
have_addr = true;
@@ -487,31 +900,34 @@
addr = (db_expr_t) db_dot;
have_addr = false;
}
+
t = db_read_token();
- if (t == tCOMMA) {
+ if (t == tCOMMA) { /*Get count*/
if (!db_expression(&count)) {
db_printf("Count missing\n");
db_flush_lex();
return;
}
- } else {
+ } else {
db_unread_token(t);
count = -1;
}
- if ((cmd->flag & CS_MORE) == 0) {
+ if ((command->flag & CS_MORE) == 0) {
db_skip_to_eol();
}
}
}
- *last_cmdp = cmd;
+
+ *last_cmdp = command;
last_count = count;
- if (cmd != 0) {
+
+ if (command != 0) {
/*
* Execute the command.
*/
- (*cmd->fcn)(addr, have_addr, count, modif);
+ (*command->fcn)(addr, have_addr, count, modif);
- if (cmd->flag & CS_SET_DOT) {
+ if (command->flag & CS_SET_DOT) {
/*
* If command changes dot, set dot to
* previous address displayed (if 'ed' style).
@@ -530,6 +946,104 @@
}
}
+/*
+ *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(list);
+ db_flush_lex();
+ return;
+ }
+
+ break;
+ case DDB_MACH_CMD:
+ list=&db_mach_cmd_list;
+ /*I need to read machine subcommand
+ If machine level2 list is used.*/
+ t = db_read_token();
+
+ if (t != tIDENT) {
+ /*if only show command is
+ executed I print all subcommands*/
+ db_cmd_list(list);
+ db_flush_lex();
+ return;
+ }
+ break;
+ default:
+ db_printf("No such command\n");
+ db_flush_lex();
+ return;
+ }
+ COMPAT_RET:
+ 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*/
+
+ db_printf("Command: %s",help->name);
+
+ if (help->cmd_arg != NULL)
+ db_printf(" Arguments: %s\n",help->cmd_arg);
+
+ if (help->cmd_descr != NULL)
+ db_printf(" Description: %s\n",help->cmd_descr);
+
+ if ((help->cmd_arg == NULL) && (help->cmd_descr == NULL))
+ db_printf(" Doesn't have any help message included.\n",
+ help->name);
+
+ /*check compatibility flag*/
+ if (help->flag == CS_COMPAT){
+ t = db_read_token();
+
+ if (t != tIDENT){
+ db_cmd_list(list);
+ db_flush_lex();
+ return;
+ }
+
+ goto COMPAT_RET;
+ /*WE support only level 2 commands*/
+ }
+
+ } else /*t != tIDENT*/
+ /*print base commands*/
+ db_cmd_list(&db_base_cmd_list);
+
+ return;
+}
+
Index: ddb/db_command.h
===================================================================
RCS file: /cvsroot/src/sys/ddb/db_command.h,v
retrieving revision 1.27
diff -u -r1.27 db_command.h
--- ddb/db_command.h 22 Feb 2007 04:38:05 -0000 1.27
+++ ddb/db_command.h 2 Aug 2007 20:15:55 -0000
@@ -1,5 +1,41 @@
/* $NetBSD: db_command.h,v 1.27 2007/02/22 04:38:05 matt Exp $ */
+/*-
+ * 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.
+ */
+
/*
* Mach Operating System
* Copyright (c) 1991,1990 Carnegie Mellon University
@@ -29,10 +65,8 @@
* Date: 7/90
*/
-/*
- * Command loop declarations.
- */
-struct db_command;
+#ifndef _DDB_COMMAND_
+#define _DDB_COMMAND_
void db_skip_to_eol(void);
void db_command_loop(void);
@@ -47,17 +81,73 @@
extern char db_cmd_on_enter[];
+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
+#define DDB_MACH_CMD 2
+
+
+int db_register_tbl(uint8_t, const struct db_command *);
+int db_unregister_tbl(uint8_t, const struct db_command *);
+
/*
* Command table
*/
struct db_command {
const char *name; /* command name */
+
/* function to call */
void (*fcn)(db_expr_t, bool, db_expr_t, const char *);
- int flag; /* extra info: */
+ /*
+ *Flag is used for modifing command behaviour.
+ *CS_OWN && CS_MORE are specify type of command arguments.
+ *CS_OWN commandmanage arguments in own way.
+ *CS_MORE db_command() prepare argument list.
+ *
+ *CS_COMPAT is set for all level 2 commands with level 3 childs (show all pages)
+ *
+ *CS_SHOW identify show command in BASE command list
+ *CS_MACH identify mach command in BASE command list
+ *
+ *CS_SET_DOT specify if this command is put to last added command memory.
+ */
+ uint16_t flag; /* extra info: */
#define CS_OWN 0x1 /* non-standard syntax */
#define CS_MORE 0x2 /* standard syntax, but may have other
words at end */
+#define CS_COMPAT 0x4 /*is set for compatibilty with old ddb versions*/
+
+#define CS_SHOW 0x8 /*select show list*/
+#define CS_MACH 0x16 /*select machine dependent list*/
+
#define CS_SET_DOT 0x100 /* set dot after command */
- const struct db_command *more; /* another level of command */
+
+ const char *cmd_descr; /*description of command*/
+ const char *cmd_arg; /*command arguments*/
+
};
+
+#endif /*_DDB_COMMAND_*/
+
+
Index: ddb/db_command_list.h
===================================================================
RCS file: ddb/db_command_list.h
diff -N ddb/db_command_list.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ddb/db_command_list.h 2 Aug 2007 20:15:55 -0000
@@ -0,0 +1,78 @@
+
+/*-
+ * 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.
+ */
+
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+
+#ifndef _DDB_COMMAND_LIST_
+#define _DDB_COMMAND_LIST_
+
+/**/
+TAILQ_HEAD(db_cmd_tbl_en_head, db_cmd_tbl_en);
+
+/*TAILQ entry used in default commands and show commands lists.*/
+struct db_cmd_tbl_en {
+ uint32_t db_cmd_num; /*Number of commands in cmd table*/
+ const struct db_command *db_cmd; /*pointer to static allocated cmd table*/
+ TAILQ_ENTRY(db_cmd_tbl_en) db_cmd_next; /*TAILQ pointers*/
+};
+
+
+#endif/*!_DDB_COMMAND_LIST_*/
Index: ddb/files.ddb
===================================================================
RCS file: /cvsroot/src/sys/ddb/files.ddb,v
retrieving revision 1.1
diff -u -r1.1 files.ddb
--- ddb/files.ddb 27 Nov 2005 22:44:35 -0000 1.1
+++ ddb/files.ddb 2 Aug 2007 20:15:55 -0000
@@ -3,10 +3,10 @@
#
# DDB options
#
-defflag opt_ddb.h DDB
+defflag opt_ddb.h DDB
defparam opt_ddbparam.h DDB_FROMCONSOLE DDB_ONPANIC DDB_HISTORY_SIZE
DDB_BREAK_CHAR DDB_KEYCODE SYMTAB_SPACE
- DDB_COMMANDONENTER
+ DDB_COMMANDONENTER DDB_VERBOSE_HELP
file ddb/db_access.c ddb | kgdb # XXX kgdb reference
file ddb/db_aout.c ddb
Index: arch/acorn26/acorn26/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/acorn26/acorn26/db_interface.c,v
retrieving revision 1.14
diff -u -r1.14 db_interface.c
--- arch/acorn26/acorn26/db_interface.c 22 Feb 2007 04:47:27 -0000 1.14
+++ arch/acorn26/acorn26/db_interface.c 2 Aug 2007 20:15:56 -0000
@@ -241,11 +241,11 @@
}
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 },
- { "panic", db_show_panic_cmd, 0, NULL },
- { NULL, NULL, 0, NULL }
+ { 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) }
};
int
Index: arch/alpha/alpha/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/alpha/alpha/db_interface.c,v
retrieving revision 1.25
diff -u -r1.25 db_interface.c
--- arch/alpha/alpha/db_interface.c 22 Feb 2007 20:09:42 -0000 1.25
+++ arch/alpha/alpha/db_interface.c 2 Aug 2007 20:15:59 -0000
@@ -94,9 +94,9 @@
const struct db_command db_machine_command_table[] = {
#if defined(MULTIPROCESSOR)
- { "cpu", db_mach_cpu, 0, 0 },
+ { DDB_ADD_CMD("cpu", db_mach_cpu, 0,NULL,NULL) },
#endif
- { (char *)0, },
+ { DDB_ADD_CMD(NULL, NULL, 0,NULL,NULL) },
};
static int db_alpha_regop __P((const struct db_variable *, db_expr_t *, int));
Index: arch/amd64/amd64/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/amd64/amd64/db_interface.c,v
retrieving revision 1.8
diff -u -r1.8 db_interface.c
--- arch/amd64/amd64/db_interface.c 4 Jun 2007 23:15:00 -0000 1.8
+++ arch/amd64/amd64/db_interface.c 2 Aug 2007 20:16:00 -0000
@@ -73,9 +73,9 @@
const struct db_command db_machine_command_table[] = {
#ifdef MULTIPROCESSOR
- { "cpu", db_mach_cpu, 0, 0 },
+ { DDB_ADD_CMD("cpu", db_mach_cpu, 0, NULL,NULL )},
#endif
- { (char *)0, },
+ { DDB_ADD_CMD(NULL, NULL, 0,NULL,NULL) },
};
void kdbprinttrap(int, int);
Index: arch/arm/arm32/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/arm32/db_interface.c,v
retrieving revision 1.42
diff -u -r1.42 db_interface.c
--- arch/arm/arm32/db_interface.c 22 Feb 2007 05:14:05 -0000 1.42
+++ arch/arm/arm32/db_interface.c 2 Aug 2007 20:16:02 -0000
@@ -365,12 +365,12 @@
}
const struct db_command db_machine_command_table[] = {
- { "frame", db_show_frame_cmd, 0, NULL },
- { "panic", db_show_panic_cmd, 0, NULL },
+ { DDB_ADD_CMD("frame", db_show_frame_cmd, 0, NULL,NULL) },
+ { DDB_ADD_CMD("panic", db_show_panic_cmd, 0, NULL,NULL) },
#ifdef ARM32_DB_COMMANDS
ARM32_DB_COMMANDS,
#endif
- { NULL, NULL, 0, NULL }
+ { DDB_ADD_CMD(NULL, NULL, 0,NULL,NULL) }
};
int
Index: arch/i386/i386/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/i386/db_interface.c,v
retrieving revision 1.51
diff -u -r1.51 db_interface.c
--- arch/i386/i386/db_interface.c 7 Mar 2007 21:43:43 -0000 1.51
+++ arch/i386/i386/db_interface.c 2 Aug 2007 20:16:13 -0000
@@ -72,9 +72,10 @@
const struct db_command db_machine_command_table[] = {
#ifdef MULTIPROCESSOR
- { "cpu", db_mach_cpu, 0, 0 },
+ { DDB_ADD_CMD("cpu", db_mach_cpu, 0, NULL,NULL) },
#endif
- { NULL, NULL, 0, 0 },
+
+ { DDB_ADD_CMD(NULL, NULL, 0, NULL,NULL) },
};
void kdbprinttrap(int, int);
Index: arch/ia64/ia64/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/ia64/ia64/db_interface.c,v
retrieving revision 1.2
diff -u -r1.2 db_interface.c
--- arch/ia64/ia64/db_interface.c 21 Feb 2007 22:59:45 -0000 1.2
+++ arch/ia64/ia64/db_interface.c 2 Aug 2007 20:16:14 -0000
@@ -111,7 +111,7 @@
db_regs_t *ddb_regp;
const struct db_command db_machine_command_table[] = {
- { (char *)0, },
+ { DDB_ADD_CMD(NULL, NULL, 0,NULL,NULL) },
};
static int
Index: arch/mips/mips/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mips/mips/db_interface.c,v
retrieving revision 1.61
diff -u -r1.61 db_interface.c
--- arch/mips/mips/db_interface.c 28 Feb 2007 04:21:53 -0000 1.61
+++ arch/mips/mips/db_interface.c 2 Aug 2007 20:16:17 -0000
@@ -542,10 +542,10 @@
}
const struct db_command db_machine_command_table[] = {
- { "kvtop", db_kvtophys_cmd, 0, 0 },
- { "tlb", db_tlbdump_cmd, 0, 0 },
- { "cp0", db_cp0dump_cmd, 0, 0 },
- { NULL, }
+ { 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) }
};
#endif /* !KGDB */
Index: arch/powerpc/powerpc/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/powerpc/powerpc/db_interface.c,v
retrieving revision 1.37
diff -u -r1.37 db_interface.c
--- arch/powerpc/powerpc/db_interface.c 22 Feb 2007 04:47:07 -0000 1.37
+++ arch/powerpc/powerpc/db_interface.c 2 Aug 2007 20:16:20 -0000
@@ -192,16 +192,16 @@
}
const struct db_command db_machine_command_table[] = {
- { "ctx", db_ppc4xx_ctx, 0, 0 },
- { "pv", db_ppc4xx_pv, 0, 0 },
- { "reset", db_ppc4xx_reset, 0, 0 },
- { "tf", db_ppc4xx_tf, 0, 0 },
- { "tlb", db_ppc4xx_dumptlb, 0, 0 },
- { "dcr", db_ppc4xx_dcr, CS_MORE|CS_SET_DOT, 0 },
+ { 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) },
#ifdef USERACC
- { "user", db_ppc4xx_useracc, 0, 0 },
+ { DDB_ADD_CMD("user", db_ppc4xx_useracc, 0, NULL,NULL) },
#endif
- { NULL, }
+ { DDB_ADD_CMD(NULL, NULL, 0, NULL,NULL) }
};
static void
Index: arch/sh3/sh3/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sh3/sh3/db_interface.c,v
retrieving revision 1.43
diff -u -r1.43 db_interface.c
--- arch/sh3/sh3/db_interface.c 17 May 2007 22:12:08 -0000 1.43
+++ arch/sh3/sh3/db_interface.c 2 Aug 2007 20:16:23 -0000
@@ -90,13 +90,13 @@
const struct db_command db_machine_command_table[] = {
- { "tlb", db_tlbdump_cmd, 0, NULL },
- { "cache", db_cachedump_cmd, 0, NULL },
- { "frame", db_frame_cmd, 0, NULL },
+ { 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) },
#ifdef KSTACK_DEBUG
- { "stack", db_stackcheck_cmd, 0, NULL },
+ { DDB_ADD_CMD("stack", db_stackcheck_cmd, 0, NULL, NULL) },
#endif
- { NULL }
+ { DDB_ADD_CMD(NULL, NULL, 0, NULL, NULL) }
};
int db_active;
Index: arch/sparc/sparc/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc/sparc/db_interface.c,v
retrieving revision 1.71
diff -u -r1.71 db_interface.c
--- arch/sparc/sparc/db_interface.c 22 Feb 2007 16:48:59 -0000 1.71
+++ arch/sparc/sparc/db_interface.c 2 Aug 2007 20:16:24 -0000
@@ -543,17 +543,17 @@
}
const struct db_command db_machine_command_table[] = {
- { "prom", db_prom_cmd, 0, 0 },
- { "proc", db_proc_cmd, 0, 0 },
- { "pcb", db_dump_pcb, 0, 0 },
- { "lock", db_lock_cmd, 0, 0 },
- { "slock", db_simple_lock_cmd, 0, 0 },
- { "page", db_page_cmd, 0, 0 },
- { "uvmdump", db_uvmhistdump, 0, 0 },
+ { 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) },
#ifdef MULTIPROCESSOR
- { "cpu", db_cpu_cmd, 0, 0 },
+ { DDB_ADD_CMD("cpu", db_cpu_cmd, 0, NULL,NULL) },
#endif
- { (char *)0, }
+ { DDB_ADD_CMD(NULL, NULL, 0,NULL,NULL) }
};
#endif /* DDB */
Index: arch/sparc64/sparc64/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc64/sparc64/db_interface.c,v
retrieving revision 1.97
diff -u -r1.97 db_interface.c
--- arch/sparc64/sparc64/db_interface.c 17 May 2007 14:51:31 -0000 1.97
+++ arch/sparc64/sparc64/db_interface.c 2 Aug 2007 20:16:27 -0000
@@ -1257,37 +1257,37 @@
#endif
const struct db_command db_machine_command_table[] = {
- { "ctx", db_ctx_cmd, 0, 0 },
- { "dtlb", db_dump_dtlb, 0, 0 },
- { "itlb", db_dump_itlb, 0, 0 },
- { "dtsb", db_dump_dtsb, 0, 0 },
- { "itsb", db_dump_itsb, 0, 0 },
+ { 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 )},
#if NESP_SBUS
- { "esp", db_esp, 0, 0 },
+ { DDB_ADD_CMD("esp", db_esp, 0, NULL,NULL )},
#endif
- { "extract", db_pm_extract, 0, 0 },
- { "fpstate", db_dump_fpstate,0, 0 },
- { "kmap", db_pmap_kernel, 0, 0 },
- { "lock", db_lock_cmd, 0, 0 },
- { "lwp", db_lwp_cmd, 0, 0 },
- { "pcb", db_dump_pcb, 0, 0 },
- { "pctx", db_setpcb, 0, 0 },
- { "page", db_page_cmd, 0, 0 },
- { "phys", db_pload_cmd, 0, 0 },
- { "pmap", db_pmap_cmd, 0, 0 },
- { "proc", db_proc_cmd, 0, 0 },
- { "prom", db_prom_cmd, 0, 0 },
- { "pv", db_dump_pv, 0, 0 },
- { "stack", db_dump_stack, 0, 0 },
- { "tf", db_dump_trap, 0, 0 },
- { "ts", db_dump_ts, 0, 0 },
- { "traptrace", db_traptrace, 0, 0 },
- { "uvmdump", db_uvmhistdump, 0, 0 },
- { "watch", db_watch, 0, 0 },
- { "window", db_dump_window, 0, 0 },
- { "cpu", db_cpu_cmd, 0, 0 },
- { "sir", db_sir_cmd, 0, 0 },
- { .name = NULL, }
+ { 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) }
};
#endif /* DDB */
Index: arch/sun2/sun2/db_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sun2/sun2/db_machdep.c,v
retrieving revision 1.8
diff -u -r1.8 db_machdep.c
--- arch/sun2/sun2/db_machdep.c 4 Mar 2007 09:54:58 -0000 1.8
+++ arch/sun2/sun2/db_machdep.c 2 Aug 2007 20:16:27 -0000
@@ -65,11 +65,11 @@
static void db_mach_pagemap(db_expr_t, bool, db_expr_t, const char *);
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, }
+ { 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 -u -r1.23 db_machdep.c
--- arch/sun3/sun3/db_machdep.c 22 Feb 2007 14:39:34 -0000 1.23
+++ arch/sun3/sun3/db_machdep.c 2 Aug 2007 20:16:28 -0000
@@ -64,11 +64,11 @@
static void db_mach_pagemap(db_expr_t, bool, db_expr_t, const char *);
const struct db_command db_machine_command_table[] = {
- { "abort", db_mach_abort, 0, NULL },
- { "halt", db_mach_halt, 0, NULL },
- { "pgmap", db_mach_pagemap, CS_SET_DOT, NULL },
- { "reboot", db_mach_reboot, 0, NULL },
- { NULL }
+ { 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 -u -r1.46 db_machdep.c
--- arch/vax/vax/db_machdep.c 4 Mar 2007 06:00:58 -0000 1.46
+++ arch/vax/vax/db_machdep.c 2 Aug 2007 20:16:28 -0000
@@ -658,7 +658,7 @@
const struct db_command db_machine_command_table[] = {
#ifdef MULTIPROCESSOR
- { "cpu", db_mach_cpu, 0, 0 },
+ { DDB_ADD_CMD("cpu", db_mach_cpu, 0, NULL,NULL) },
#endif
- { NULL },
+ { DDB_ADD_CMD(NULL,NULL,0,NULL,NULL)},
};
--Apple-Mail-1--527040697
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-1--527040697--
--Apple-Mail-2--527040682
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)
iD8DBQFGsjy5lIxPgX3Go0MRArphAKDxxP9lk+YeelYwh/Si4VUJ7sEJ0ACeN0Z7
GARDXElOrlzZu5jOZtiHMuM=
=0zjU
-----END PGP SIGNATURE-----
--Apple-Mail-2--527040682--