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;