From 03f92cacce1185b0ad9d919775eb6acb016e8dbb Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 12 Mar 2005 21:37:01 +0000 Subject: [PATCH] Added new function get_debug_exception_string(). Refactored a bit. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11702 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/os/debug.c | 93 +++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 36 deletions(-) diff --git a/src/kernel/libroot/os/debug.c b/src/kernel/libroot/os/debug.c index d418c60acc..71deed13c2 100644 --- a/src/kernel/libroot/os/debug.c +++ b/src/kernel/libroot/os/debug.c @@ -13,6 +13,40 @@ #include +static const char *const sDebugWhyStrings[] = { + "Thread not running", // B_THREAD_NOT_RUNNING + "Signal received", // B_SIGNAL_RECEIVED + "Team created", // B_TEAM_CREATED + "Thread created", // B_THREAD_CREATED + "Image created", // B_IMAGE_CREATED + "Image deleted", // B_IMAGE_DELETED + "Debugger call", // B_DEBUGGER_CALL + "Breakpoint hit", // B_BREAKPOINT_HIT + "watchpoint hit", // B_WATCHPOINT_HIT + "Before syscall", // B_PRE_SYSCALL_HIT + "After syscall", // B_POST_SYSCALL_HIT + "Single step", // B_SINGLE_STEP +}; +static const int32 sDebugWhyStringCount = B_SINGLE_STEP + 1; + +static const char *const sDebugExceptionTypeStrings[] = { + "Non-maskable interrupt", // B_NMI + "Machine check exception", // B_MACHINE_CHECK_EXCEPTION + "Segment violation", // B_SEGMENT_VIOLATION + "Alignment exception", // B_ALIGNMENT_EXCEPTION + "Divide error", // B_DIVIDE_ERROR + "Overflow exception", // B_OVERFLOW_EXCEPTION + "Bounds check exception", // B_BOUNDS_CHECK_EXCEPTION + "Invalid opcode exception", // B_INVALID_OPCODE_EXCEPTION + "Segment not present", // B_SEGMENT_NOT_PRESENT + "Stack fault", // B_STACK_FAULT + "General protection fault", // B_GENERAL_PROTECTION_FAULT + "Floating point exception", // B_FLOATING_POINT_EXCEPTION +}; +static const int32 sDebugExceptionTypeStringCount + = B_FLOATING_POINT_EXCEPTION + 1; + + void debugger(const char *message) { @@ -70,47 +104,34 @@ wait_for_debugger(void) } -static const char *const sDebugWhyStrings[] = { - "Thread not running", // B_THREAD_NOT_RUNNING - "Signal received", // B_SIGNAL_RECEIVED - "Team created", // B_TEAM_CREATED - "Thread created", // B_THREAD_CREATED - "Image created", // B_IMAGE_CREATED - "Image deleted", // B_IMAGE_DELETED - "Debugger call", // B_DEBUGGER_CALL - "Breakpoint hit", // B_BREAKPOINT_HIT - "watchpoint hit", // B_WATCHPOINT_HIT - "Before syscall", // B_PRE_SYSCALL_HIT - "After syscall", // B_POST_SYSCALL_HIT - "Single step", // B_SINGLE_STEP - - "Non-masked interrupt", // B_NMI - "Machine check exception", // B_MACHINE_CHECK_EXCEPTION - "Segment violation", // B_SEGMENT_VIOLATION - "Alignment exception", // B_ALIGNMENT_EXCEPTION - "Divide error", // B_DIVIDE_ERROR - "Overflow exception", // B_OVERFLOW_EXCEPTION - "Bounds check exception", // B_BOUNDS_CHECK_EXCEPTION - "Invalid opcode exception", // B_INVALID_OPCODE_EXCEPTION - "Segment not present", // B_SEGMENT_NOT_PRESENT - "Stack fault", // B_STACK_FAULT - "General protection fault", // B_GENERAL_PROTECTION_FAULT - "Floating point exception", // B_FLOATING_POINT_EXCEPTION -}; -static const int32 sDebugWhyStringCount = B_FLOATING_POINT_EXCEPTION + 1; - - -void -get_why_stopped_string(debug_why_stopped whyStopped, char *buffer, - int32 bufferSize) +static void +get_debug_string(const char *const *strings, int32 stringCount, + const char *defaultString, int32 index, char *buffer, int32 bufferSize) { if (!buffer || bufferSize <= 0) return; - if ((int32)whyStopped >= 0 && (int32)whyStopped < sDebugWhyStringCount) - strlcpy(buffer, sDebugWhyStrings[whyStopped], bufferSize); + if ((int32)index >= 0 && (int32)index < stringCount) + strlcpy(buffer, strings[index], bufferSize); else - snprintf(buffer, bufferSize, "Unknown reason %ld", (int32)whyStopped); + snprintf(buffer, bufferSize, defaultString, index); +} + + +void +get_debug_why_stopped_string(debug_why_stopped whyStopped, char *buffer, + int32 bufferSize) +{ + get_debug_string(sDebugWhyStrings, sDebugWhyStringCount, + "Unknown reason %ld", (int32)whyStopped, buffer, bufferSize); +} + +void +get_debug_exception_string(debug_exception_type exception, char *buffer, + int32 bufferSize) +{ + get_debug_string(sDebugExceptionTypeStrings, sDebugExceptionTypeStringCount, + "Unknown exception %ld", (int32)exception, buffer, bufferSize); }