From 6179ce7957df004d50d5cae22b389ded58104d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 30 Oct 2008 16:29:37 +0000 Subject: [PATCH] * Removed the DEBUG_DEBUGGER_COMMANDS define again, and followed Ingo's suggestion by adding a "faults" command that now sets the gInvokeCommandDirectly variable as wished. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28382 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/debug/debug_builtin_commands.cpp | 21 +++++++++++++++++++ src/system/kernel/debug/debug_commands.cpp | 18 +++++++--------- src/system/kernel/debug/debug_commands.h | 1 + 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/system/kernel/debug/debug_builtin_commands.cpp b/src/system/kernel/debug/debug_builtin_commands.cpp index 4d36b8650a..fb9e4b14d2 100644 --- a/src/system/kernel/debug/debug_builtin_commands.cpp +++ b/src/system/kernel/debug/debug_builtin_commands.cpp @@ -313,6 +313,23 @@ cmd_wc(int argc, char** argv) } +static int +cmd_faults(int argc, char** argv) +{ + if (argc > 2) { + print_debugger_command_usage(argv[0]); + return B_KDEBUG_ERROR; + } + + if (argc == 2) + gInvokeCommandDirectly = parse_expression(argv[1]) == 0; + + kprintf("Fault handling is %s%s.\n", argc == 2 ? "now " : "", + gInvokeCommandDirectly ? "off" : "on"); + return 0; +} + + // #pragma mark - @@ -347,6 +364,10 @@ debug_builtin_commands_init() "Prints a human-readable description for the given numeric error\n" "code.\n" " - The numeric error code.\n", 0); + add_debugger_command_etc("faults", &cmd_faults, "Toggles fault handling " + "for debugger commands", + "[0|1]\n" + "Toggles fault handling on (1) or off (0).\n", 0); add_debugger_command_etc("head", &cmd_head, "Prints only the first lines of output from another command", "\n" diff --git a/src/system/kernel/debug/debug_commands.cpp b/src/system/kernel/debug/debug_commands.cpp index 34a991c2c5..8a4575dcc7 100644 --- a/src/system/kernel/debug/debug_commands.cpp +++ b/src/system/kernel/debug/debug_commands.cpp @@ -24,23 +24,22 @@ #include "debug_variables.h" -#define DEBUG_DEBUGGER_COMMANDS 0 - // Turns off the "FAULT" message to get a stack crawl - // of the failing debugger command. - #define INVOKE_COMMAND_FAULT 1 #define INVOKE_COMMAND_ERROR 2 + static const int32 kMaxInvokeCommandDepth = 5; static const int32 kOutputBufferSize = 1024; + +bool gInvokeCommandDirectly = false; + static spinlock sSpinlock = B_SPINLOCK_INITIALIZER; static struct debugger_command *sCommands; static jmp_buf sInvokeCommandEnv[kMaxInvokeCommandDepth]; static int32 sInvokeCommandLevel = 0; -static bool sInvokeCommandDirectly = false; static bool sInCommand = false; static char sOutputBuffers[MAX_DEBUGGER_COMMAND_PIPE_LENGTH][kOutputBufferSize]; static debugger_command_pipe* sCurrentPipe; @@ -276,7 +275,7 @@ invoke_debugger_command(struct debugger_command *command, int argc, char** argv) // Invoking the command directly might be useful when debugging debugger // commands. - if (sInvokeCommandDirectly) + if (gInvokeCommandDirectly) return command->func(argc, argv); sInCommand = true; @@ -284,13 +283,11 @@ invoke_debugger_command(struct debugger_command *command, int argc, char** argv) switch (setjmp(sInvokeCommandEnv[sInvokeCommandLevel++])) { case 0: int result; -#if DEBUG_DEBUGGER_COMMANDS thread->fault_handler = (addr_t)&&error; // Fake goto to trick the compiler not to optimize the code at the // label away. if (!thread) goto error; -#endif result = command->func(argc, argv); @@ -299,12 +296,11 @@ invoke_debugger_command(struct debugger_command *command, int argc, char** argv) sInCommand = false; return result; -#if DEBUG_DEBUGGER_COMMANDS error: // jump to INVOKE_COMMAND_FAULT case, cleaning up the stack longjmp(sInvokeCommandEnv[--sInvokeCommandLevel], INVOKE_COMMAND_FAULT); -#endif + case INVOKE_COMMAND_FAULT: { debug_page_fault_info* info = debug_get_page_fault_info(); @@ -337,7 +333,7 @@ invoke_debugger_command(struct debugger_command *command, int argc, char** argv) void abort_debugger_command() { - if (!sInvokeCommandDirectly && sInvokeCommandLevel > 0) { + if (!gInvokeCommandDirectly && sInvokeCommandLevel > 0) { longjmp(sInvokeCommandEnv[--sInvokeCommandLevel], INVOKE_COMMAND_ERROR); } diff --git a/src/system/kernel/debug/debug_commands.h b/src/system/kernel/debug/debug_commands.h index 15f6e00809..4b521f50a6 100644 --- a/src/system/kernel/debug/debug_commands.h +++ b/src/system/kernel/debug/debug_commands.h @@ -36,6 +36,7 @@ typedef struct debugger_command_pipe { bool broken; } debugger_command_pipe; +extern bool gInvokeCommandDirectly; #ifdef __cplusplus extern "C" {