From b196064201befd215f6ff121788280ce84626abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 11 Nov 2003 03:47:14 +0000 Subject: [PATCH] dbg_init() no longer sets sCommands to NULL - variables in the BSS are always zeroed anyway. cmd_help() is now able to print out help about the specified command only - it will also print out all aliases of that command. Reduced the distance between the command name and its description; NULL descriptions are now also allowed. There is now a find_command() function that's used throughout the module. Like in the Be debugger, it will now also accept partial matches, i.e. "co" will most probably match "continue" (as long as there is no new "co*" command added by another component). It will first try to find an exact match, and only if that failed it will search for a partial match. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5307 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/debug.c | 63 ++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/src/kernel/core/debug.c b/src/kernel/core/debug.c index 32a5c1bc26..eb2cce41f5 100644 --- a/src/kernel/core/debug.c +++ b/src/kernel/core/debug.c @@ -26,12 +26,12 @@ #include -struct debugger_command { +typedef struct debugger_command { struct debugger_command *next; int (*func)(int, char **); const char *name; const char *description; -}; +} debugger_command; int dbg_register_file[2][14]; /* XXXmpetit -- must be made generic */ @@ -53,6 +53,30 @@ static char *args[MAX_ARGS] = { NULL, }; #define distance(a, b) ((a) < (b) ? (b) - (a) : (a) - (b)) +static debugger_command * +find_command(char *name) +{ + debugger_command *command; + int length; + + // search command by full name + + for (command = sCommands; command != NULL; command = command->next) { + if (strcmp(name, command->name) == 0) + return command; + } + + // if it couldn't be found, search for a partial match + + length = strlen(name); + + for (command = sCommands; command != NULL; command = command->next) { + if (strncmp(name, command->name, length) == 0) + return command; + } +} + + static int debug_read_line(char *buf, int max_len) { @@ -222,15 +246,8 @@ kernel_debugger_loop(void) debugger_on_cpu = smp_get_current_cpu(); - if (argc > 0) { - // search command by name - cmd = sCommands; - while (cmd != NULL) { - if (strcmp(args[0], cmd->name) == 0) - break; - cmd = cmd->next; - } - } + if (argc > 0) + cmd = find_command(args[0]); if (cmd == NULL) dprintf("unknown command, enter \"help\" to get a list of all supported commands\n"); @@ -290,20 +307,28 @@ static int cmd_reboot(int argc, char **argv) { reboot(); - return 0; // I'll be really suprised if this line ever run! ;-) + return 0; + // I'll be really suprised if this line ever run! ;-) } static int cmd_help(int argc, char **argv) { - struct debugger_command *cmd; + debugger_command *command, *specified = NULL; - dprintf("debugger commands:\n"); - cmd = sCommands; - while (cmd != NULL) { - dprintf(" %-32s\t\t%s\n", cmd->name, cmd->description ? cmd->description : ""); - cmd = cmd->next; + if (argc > 1) { + // only print out the help of the specified command (and all of its aliases) + specified = find_command(argv[1]); + dprintf("debugger command for \"%s\" and aliases:\n", specified->name); + } else + dprintf("debugger commands:\n"); + + for (command = sCommands; command != NULL; command = command->next) { + if (specified && command->func != specified->func) + continue; + + dprintf(" %-20s\t\t%s\n", command->name, command->description ? command->description : "-"); } return 0; @@ -320,8 +345,6 @@ cmd_continue(int argc, char **argv) int dbg_init(kernel_args *ka) { - sCommands = NULL; - return arch_dbg_con_init(ka); }