From dad4ae32f19e9cf1a55f016a4a7a2635ae392bf9 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Mon, 9 Dec 2013 18:39:50 -0500 Subject: [PATCH] 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. --- .../cli/CommandLineUserInterface.cpp | 36 ++++++++++++++++--- .../cli/CommandLineUserInterface.h | 3 ++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp index 48e937a4b8..ab2c8379f8 100644 --- a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp +++ b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp @@ -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()); +} diff --git a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h index 7f1e534505..12d479c3b6 100644 --- a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h +++ b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h @@ -50,6 +50,8 @@ public: // input loop. // Team::Listener + virtual void ThreadStateChanged( + const Team::ThreadEvent& event); virtual void DebugReportChanged( const Team::DebugReportEvent& event); @@ -78,6 +80,7 @@ private: const CommandEntry* command2); bool _ReportTargetThreadStopNeeded() const; + void _SubmitSaveReport(); private: CliContext fContext;