From 15f1e19781af3b462c4542cb19df687bb9aca6c0 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 16 Jan 2008 01:14:40 +0000 Subject: [PATCH] * Added support for the "--help" argument to some debugger commands. * The kernel debugger does now define some temporary variables when entered (current thread and team, etc.). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23549 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/arch/x86/arch_debug.cpp | 43 ++++++++++++++++---- src/system/kernel/debug/debug.cpp | 48 ++++++++++++++++++++++- 2 files changed, 81 insertions(+), 10 deletions(-) diff --git a/src/system/kernel/arch/x86/arch_debug.cpp b/src/system/kernel/arch/x86/arch_debug.cpp index ddad5bf295..af693c36a5 100644 --- a/src/system/kernel/arch/x86/arch_debug.cpp +++ b/src/system/kernel/arch/x86/arch_debug.cpp @@ -233,17 +233,22 @@ get_previous_iframe(struct thread* thread, struct iframe* frame) static int stack_trace(int argc, char **argv) { + static const char* usage = "usage: %s [ ]\n" + "Prints a stack trace for the current, respectively the specified\n" + "thread.\n" + " - The ID of the thread for which to print the stack\n" + " trace.\n"; + if (argc > 2 || argc == 2 && strcmp(argv[1], "--help") == 0) { + kprintf(usage, argv[0]); + return 0; + } + uint32 previousLocations[NUM_PREVIOUS_LOCATIONS]; struct thread *thread = NULL; addr_t oldPageDirectory = 0; uint32 ebp = x86_read_ebp(); int32 i, num = 0, last = 0; - if (argc > 2) { - kprintf("usage: %s [thread id]\n", argv[0]); - return 0; - } - setup_for_thread(argc == 2 ? argv[1] : NULL, &thread, &ebp, &oldPageDirectory); @@ -363,6 +368,18 @@ print_call(struct thread *thread, addr_t eip, addr_t ebp, int32 argCount) static int show_call(int argc, char **argv) { + static const char* usage + = "usage: %s [ ] [ - ]\n" + "Prints a function call with parameters of the current, respectively\n" + "the specified thread.\n" + " - The ID of the thread for which to print the call.\n" + " - The index of the call in the stack trace.\n" + " - The number of call arguments to print.\n"; + if (argc == 2 && strcmp(argv[1], "--help") == 0) { + kprintf(usage, argv[0]); + return 0; + } + struct thread *thread = NULL; addr_t oldPageDirectory = 0; uint32 ebp = x86_read_ebp(); @@ -378,7 +395,7 @@ show_call(int argc, char **argv) } if (argc < 2 || argc > 3) { - kprintf("usage: %s [thread id] [-]\n", argv[0]); + kprintf(usage, argv[0]); return 0; } @@ -424,7 +441,7 @@ show_call(int argc, char **argv) } if (oldPageDirectory != 0) { - // switch back to the previous page directory to no cause any troubles + // switch back to the previous page directory to not cause any troubles write_cr3(oldPageDirectory); } @@ -435,6 +452,16 @@ show_call(int argc, char **argv) static int dump_iframes(int argc, char **argv) { + static const char* usage = "usage: %s [ ]\n" + "Prints the iframe stack for the current, respectively the specified\n" + "thread.\n" + " - The ID of the thread for which to print the iframe\n" + " stack.\n"; + if (argc == 2 && strcmp(argv[1], "--help") == 0) { + kprintf(usage, argv[0]); + return 0; + } + struct thread *thread = NULL; int32 i; @@ -448,7 +475,7 @@ dump_iframes(int argc, char **argv) return 0; } } else if (argc > 2) { - kprintf("usage: %s [thread id]\n", argv[0]); + kprintf(usage, argv[0]); return 0; } diff --git a/src/system/kernel/debug/debug.cpp b/src/system/kernel/debug/debug.cpp index 5f0739081e..f210c5a999 100644 --- a/src/system/kernel/debug/debug.cpp +++ b/src/system/kernel/debug/debug.cpp @@ -497,6 +497,15 @@ kernel_debugger_loop(void) int32 previousCPU = sDebuggerOnCPU; sDebuggerOnCPU = smp_get_current_cpu(); + // set a few temporary debug variables + if (struct thread* thread = thread_get_current_thread()) { + set_debug_variable("_thread", (uint64)(addr_t)thread); + set_debug_variable("_threadID", thread->id); + set_debug_variable("_team", (uint64)(addr_t)thread->team); + set_debug_variable("_teamID", thread->team->id); + set_debug_variable("_cpu", sDebuggerOnCPU); + } + kprintf("Welcome to Kernel Debugging Land...\n"); kprintf("Running on CPU %ld\n", sDebuggerOnCPU); @@ -549,6 +558,13 @@ kernel_debugger_loop(void) static int cmd_reboot(int argc, char **argv) { + static const char* usage = "usage: %s\n" + "Reboots the system.\n"; + if (argc > 1 && strcmp(argv[1], "--help") == 0) { + kprintf(usage, argv[0]); + return 0; + } + arch_cpu_shutdown(true); return 0; // I'll be really suprised if this line ever runs! ;-) @@ -558,6 +574,13 @@ cmd_reboot(int argc, char **argv) static int cmd_shutdown(int argc, char **argv) { + static const char* usage = "usage: %s\n" + "Shuts down the system.\n"; + if (argc > 1 && strcmp(argv[1], "--help") == 0) { + kprintf(usage, argv[0]); + return 0; + } + arch_cpu_shutdown(false); return 0; } @@ -566,6 +589,13 @@ cmd_shutdown(int argc, char **argv) static int cmd_help(int argc, char **argv) { + static const char* usage = "usage: %s\n" + "Lists all debugger commands.\n"; + if (argc > 1 && strcmp(argv[1], "--help") == 0) { + kprintf(usage, argv[0]); + return 0; + } + debugger_command *command, *specified = NULL; const char *start = NULL; int32 startLength = 0; @@ -604,6 +634,13 @@ cmd_help(int argc, char **argv) static int cmd_continue(int argc, char **argv) { + static const char* usage = "usage: %s\n" + "Leaves kernel debugger.\n"; + if (argc > 1 && strcmp(argv[1], "--help") == 0) { + kprintf(usage, argv[0]); + return 0; + } + return B_KDEBUG_QUIT; } @@ -611,6 +648,13 @@ cmd_continue(int argc, char **argv) static int cmd_dump_kdl_message(int argc, char **argv) { + static const char* usage = "usage: %s\n" + "Reprints the message printed when entering KDL.\n"; + if (argc > 1 && strcmp(argv[1], "--help") == 0) { + kprintf(usage, argv[0]); + return 0; + } + if (sCurrentKernelDebuggerMessage) { kputs(sCurrentKernelDebuggerMessage); kputchar('\n'); @@ -622,10 +666,10 @@ cmd_dump_kdl_message(int argc, char **argv) static int cmd_expr(int argc, char **argv) { - static const char* usage = "usage: expr \n" + static const char* usage = "usage: %s \n" "Evaluates the given expression and prints the result.\n"; if (argc != 2 || strcmp(argv[1], "--help") == 0) { - kprintf(usage); + kprintf(usage, argv[0]); return 0; }