Debugger: Fix race condition.

- For the functionality added to address #10283, we need to wait until we
receive the Team listener's thread state change notification before submitting
the report generation request, else the thread might not actually be stopped
yet when the generator walks the thread list. Should fix some lingering issues
with stack traces sometimes not being returned when using this mode of
operation.
This commit is contained in:
Rene Gollent
2013-12-09 18:40:45 -05:00
parent 67ba05e6db
commit dad4ae32f1
2 changed files with 35 additions and 4 deletions
@@ -226,11 +226,26 @@ CommandLineUserInterface::Run()
fReportTargetThread);
args.Parse(buffer, &parseErrorLocation);
_ExecuteCommand(args.ArgumentCount(), args.Arguments());
} else
_SubmitSaveReport();
}
}
void
CommandLineUserInterface::ThreadStateChanged(const Team::ThreadEvent& event)
{
if (fSaveReport) {
Thread* thread = event.GetThread();
// If we were asked to attach/report on a specific thread
// rather than a team, and said thread was still
// running, when we attached, we need to wait for its corresponding
// stop state before generating a report, else we might not get its
// stack trace.
if (thread->ID() == fReportTargetThread
&& thread->State() == THREAD_STATE_STOPPED) {
_SubmitSaveReport();
}
snprintf(buffer, sizeof(buffer), "save-report %s",
fReportPath != NULL ? fReportPath : "");
args.Parse(buffer, &parseErrorLocation);
_ExecuteCommand(args.ArgumentCount(), args.Arguments());
}
}
@@ -465,3 +480,16 @@ CommandLineUserInterface::_ReportTargetThreadStopNeeded() const
return thread->State() != THREAD_STATE_STOPPED;
}
void
CommandLineUserInterface::_SubmitSaveReport()
{
ArgumentVector args;
char buffer[256];
const char* parseErrorLocation;
snprintf(buffer, sizeof(buffer), "save-report %s",
fReportPath != NULL ? fReportPath : "");
args.Parse(buffer, &parseErrorLocation);
_ExecuteCommand(args.ArgumentCount(), args.Arguments());
}