From 37a25a6ceb750024cbc7ba8241099c2efcc9050c Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 3 Nov 2005 00:40:36 +0000 Subject: [PATCH] * Fail, if debug_thread() is invoked for the debug nub thread. * To always be on the safe side, thread_hit_debug_event() now checks whether the thread is the debug nub thread. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14655 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/user_debugger.h | 2 ++ src/system/kernel/debug/user_debugger.cpp | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/headers/private/kernel/user_debugger.h b/headers/private/kernel/user_debugger.h index 6c854f15d4..fbce350d71 100644 --- a/headers/private/kernel/user_debugger.h +++ b/headers/private/kernel/user_debugger.h @@ -87,6 +87,8 @@ enum { B_THREAD_DEBUG_STOPPED = 0x0008, B_THREAD_DEBUG_SINGLE_STEP = 0x0010, + B_THREAD_DEBUG_NUB_THREAD = 0x0020, // marks the nub thread + B_THREAD_DEBUG_KERNEL_FLAG_MASK = 0xffff, B_THREAD_DEBUG_DEFAULT_FLAGS = 0, diff --git a/src/system/kernel/debug/user_debugger.cpp b/src/system/kernel/debug/user_debugger.cpp index e71a034b46..7be3fa6092 100644 --- a/src/system/kernel/debug/user_debugger.cpp +++ b/src/system/kernel/debug/user_debugger.cpp @@ -339,7 +339,14 @@ thread_hit_debug_event_internal(debug_debugger_message event, threadFlags &= ~B_THREAD_DEBUG_STOP; bool debuggerInstalled = (thread->team->debug_info.flags & B_TEAM_DEBUG_DEBUGGER_INSTALLED); - if (debuggerInstalled || !requireDebugger) { + if (thread->id == thread->team->debug_info.nub_thread) { + // Ugh, we're the nub thread. We shouldn't be here. + TRACE(("thread_hit_debug_event(): Misdirected nub thread: %ld\n", + thread->id)); + + error = B_ERROR; + + } else if (debuggerInstalled || !requireDebugger) { if (debuggerInstalled) { debuggerPort = thread->team->debug_info.debugger_port; nubPort = thread->team->debug_info.nub_port; @@ -1794,7 +1801,9 @@ install_team_debugger_init_debug_infos(struct team *team, team_id debuggerTeam, for (struct thread *thread = team->thread_list; thread; thread = thread->team_next) { - if (thread->id != nubThread) { + if (thread->id == nubThread) { + atomic_set(&thread->debug_info.flags, B_THREAD_DEBUG_NUB_THREAD); + } else { int32 flags = thread->debug_info.flags & ~B_THREAD_DEBUG_USER_FLAG_MASK; atomic_set(&thread->debug_info.flags, @@ -2181,6 +2190,9 @@ _user_debug_thread(thread_id threadID) } else if (thread->debug_info.flags & B_THREAD_DEBUG_DYING) { // the thread is already dying -- too late to debug it error = B_BAD_THREAD_ID; + } else if (thread->debug_info.flags & B_THREAD_DEBUG_NUB_THREAD) { + // don't debug the nub thread + error = B_NOT_ALLOWED; } else if (!(thread->debug_info.flags & B_THREAD_DEBUG_STOPPED)) { // set the flag that tells the thread to stop as soon as possible atomic_or(&thread->debug_info.flags, B_THREAD_DEBUG_STOP);