Skip to content

Commit

Permalink
Debugger: ThreadHandler cleanups.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
anevilyak committed Oct 31, 2014
1 parent 601b2f7 commit fe47f15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
22 changes: 11 additions & 11 deletions src/apps/debugger/controllers/ThreadHandler.cpp
Expand Up @@ -100,7 +100,6 @@ ThreadHandler::ThreadHandler(Thread* thread, Worker* worker,
fPreviousInstructionPointer(0),
fPreviousFrameAddress(0),
fSingleStepping(false),
fHasPendingConditionEvaluation(false),
fConditionWaitSem(-1),
fConditionResult(NULL)
{
Expand Down Expand Up @@ -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());
}
}


Expand Down Expand Up @@ -876,10 +868,14 @@ ThreadHandler::_HandleBreakpointConditionIfNeeded(CpuState* cpuState)
continue;

StackTrace* stackTrace = fThread->GetStackTrace();
BReference<StackTrace> 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);
Expand Down Expand Up @@ -909,6 +905,8 @@ ThreadHandler::_HandleBreakpointConditionIfNeeded(CpuState* cpuState)

BPrivate::ObjectDeleter<ExpressionJobListener> deleter(listener);
if (error == B_OK) {
_SetThreadState(THREAD_STATE_STOPPED, cpuState,
THREAD_STOPPED_BREAKPOINT, BString());
teamLocker.Unlock();

do {
Expand All @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion src/apps/debugger/controllers/ThreadHandler.h
Expand Up @@ -123,7 +123,6 @@ class ThreadHandler : public BReferenceable, private ImageDebugInfoProvider,
target_addr_t fPreviousInstructionPointer;
target_addr_t fPreviousFrameAddress;
bool fSingleStepping;
bool fHasPendingConditionEvaluation;
sem_id fConditionWaitSem;
Value* fConditionResult;

Expand Down

0 comments on commit fe47f15

Please sign in to comment.