From fe47f15fb4341b67910e8aeff52a093f051cad28 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Thu, 30 Oct 2014 20:16:01 -0400 Subject: [PATCH] Debugger: ThreadHandler cleanups. - Ask the architecture for a stack trace directly, as we only need the top frame. - Properly update thread state before we go into condition evaluation. Otherwise, other parts of the debugger potentially wouldn't notice that we had continued execution in the case where the condition evaluates to false, and would indicate a program stop at the breakpoint erroneously. --- .../debugger/controllers/ThreadHandler.cpp | 22 +++++++++---------- src/apps/debugger/controllers/ThreadHandler.h | 1 - 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/apps/debugger/controllers/ThreadHandler.cpp b/src/apps/debugger/controllers/ThreadHandler.cpp index e44bbbbf8f..e711d59893 100644 --- a/src/apps/debugger/controllers/ThreadHandler.cpp +++ b/src/apps/debugger/controllers/ThreadHandler.cpp @@ -100,7 +100,6 @@ ThreadHandler::ThreadHandler(Thread* thread, Worker* worker, fPreviousInstructionPointer(0), fPreviousFrameAddress(0), fSingleStepping(false), - fHasPendingConditionEvaluation(false), fConditionWaitSem(-1), fConditionResult(NULL) { @@ -441,13 +440,6 @@ ThreadHandler::HandleCpuStateChanged() void ThreadHandler::HandleStackTraceChanged() { - AutoLocker< ::Team> teamLocker(fThread->GetTeam()); - if (fHasPendingConditionEvaluation && fThread->GetStackTrace() != NULL) { - fHasPendingConditionEvaluation = false; - teamLocker.Unlock(); - - _HandleBreakpointConditionIfNeeded(fThread->GetCpuState()); - } } @@ -876,10 +868,14 @@ ThreadHandler::_HandleBreakpointConditionIfNeeded(CpuState* cpuState) continue; StackTrace* stackTrace = fThread->GetStackTrace(); + BReference stackTraceReference; if (stackTrace == NULL) { - fThread->SetCpuState(cpuState); - fHasPendingConditionEvaluation = true; - return true; + if (fDebuggerInterface->GetArchitecture()->CreateStackTrace( + fThread->GetTeam(), this, cpuState, stackTrace, NULL, 1, + false, true) == B_OK) { + stackTraceReference.SetTo(stackTrace, true); + } else + return false; } StackFrame* frame = stackTrace->FrameAt(0); @@ -909,6 +905,8 @@ ThreadHandler::_HandleBreakpointConditionIfNeeded(CpuState* cpuState) BPrivate::ObjectDeleter deleter(listener); if (error == B_OK) { + _SetThreadState(THREAD_STATE_STOPPED, cpuState, + THREAD_STOPPED_BREAKPOINT, BString()); teamLocker.Unlock(); do { @@ -934,6 +932,8 @@ ThreadHandler::_HandleBreakpointConditionIfNeeded(CpuState* cpuState) if (stop) return false; else { + _SetThreadState(THREAD_STATE_RUNNING, NULL, + THREAD_STOPPED_UNKNOWN, BString()); fDebuggerInterface->ContinueThread(fThread->ID()); return true; } diff --git a/src/apps/debugger/controllers/ThreadHandler.h b/src/apps/debugger/controllers/ThreadHandler.h index f29f539b79..a134fc70e2 100644 --- a/src/apps/debugger/controllers/ThreadHandler.h +++ b/src/apps/debugger/controllers/ThreadHandler.h @@ -123,7 +123,6 @@ private: target_addr_t fPreviousInstructionPointer; target_addr_t fPreviousFrameAddress; bool fSingleStepping; - bool fHasPendingConditionEvaluation; sem_id fConditionWaitSem; Value* fConditionResult;