From 8b9099b1b24358076e28f6e3a894e6f39de4cece Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Tue, 4 Nov 2014 17:38:43 -0500 Subject: [PATCH] Debugger: Fix #11411. CliContext/CommandLineUserInterface: - Process the debug report event asynchronously. The missing lock that was fixed in commit 5ac34e5a78305abac4c758a34db9f1e34aee54ed highlighted a problem in how the CLI was handling the case where it was intended to exit immediately after saving a report, since it issued the quit request directly from the report event handler. This resulted in locking issues, as the team debugger would then attempt to tear itself down, during which it needs to acquire the team lock. However, that was already being held by the thread in which the CLI was initiating the quit, resulting in a deadlock. --- .../user_interface/cli/CliContext.cpp | 26 ++++++++++++++++++ .../debugger/user_interface/cli/CliContext.h | 10 ++++++- .../cli/CommandLineUserInterface.cpp | 27 +++++-------------- .../cli/CommandLineUserInterface.h | 2 -- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/apps/debugger/user_interface/cli/CliContext.cpp b/src/apps/debugger/user_interface/cli/CliContext.cpp index f36f87d3e3..6acb238f6f 100644 --- a/src/apps/debugger/user_interface/cli/CliContext.cpp +++ b/src/apps/debugger/user_interface/cli/CliContext.cpp @@ -97,6 +97,7 @@ CliContext::CliContext() fInputLoopWaitingForEvents(0), fEventsOccurred(0), fInputLoopWaiting(false), + fInteractive(true), fTerminating(false), fCurrentThread(NULL), fCurrentStackTrace(NULL), @@ -207,6 +208,13 @@ CliContext::Terminating() } +void +CliContext::SetInteractive(bool interactive) +{ + fInteractive = interactive; +} + + thread_id CliContext::CurrentThreadID() const { @@ -444,6 +452,13 @@ CliContext::ProcessPendingEvents() fExpressionValue->AcquireReference(); } break; + case EVENT_DEBUG_REPORT_CHANGED: + if (!IsInteractive()) { + Terminating(); + QuitSession(true); + } + break; + } } } @@ -503,6 +518,17 @@ CliContext::ExpressionEvaluated(const Team::ExpressionEvaluationEvent& event) } +void +CliContext::DebugReportChanged(const Team::DebugReportEvent& event) +{ + printf("Successfully saved debug report to %s\n", + event.GetReportPath()); + + _QueueEvent(new(std::nothrow) Event(EVENT_DEBUG_REPORT_CHANGED)); + _SignalInputLoop(EVENT_DEBUG_REPORT_CHANGED); +} + + void CliContext::MemoryBlockRetrieved(TeamMemoryBlock* block) { diff --git a/src/apps/debugger/user_interface/cli/CliContext.h b/src/apps/debugger/user_interface/cli/CliContext.h index f83cc34f2a..b2a349fca4 100644 --- a/src/apps/debugger/user_interface/cli/CliContext.h +++ b/src/apps/debugger/user_interface/cli/CliContext.h @@ -39,7 +39,8 @@ public: EVENT_THREAD_STACK_TRACE_CHANGED = 0x20, EVENT_VALUE_NODE_CHANGED = 0x40, EVENT_TEAM_MEMORY_BLOCK_RETRIEVED = 0x80, - EVENT_EXPRESSION_EVALUATED = 0x100 + EVENT_EXPRESSION_EVALUATED = 0x100, + EVENT_DEBUG_REPORT_CHANGED = 0x200 }; public: @@ -54,6 +55,9 @@ public: bool IsTerminating() const { return fTerminating; } + bool IsInteractive() const { return fInteractive; } + void SetInteractive(bool interactive); + // service methods for the input loop thread follow Team* GetTeam() const { return fTeam; } @@ -110,6 +114,9 @@ private: const Team::ExpressionEvaluationEvent& event); + virtual void DebugReportChanged( + const Team::DebugReportEvent& event); + // TeamMemoryBlock::Listener virtual void MemoryBlockRetrieved(TeamMemoryBlock* block); @@ -141,6 +148,7 @@ private: uint32 fInputLoopWaitingForEvents; uint32 fEventsOccurred; bool fInputLoopWaiting; + bool fInteractive; volatile bool fTerminating; Thread* fCurrentThread; diff --git a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp index 5494b24b12..dfbe7c598d 100644 --- a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp +++ b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp @@ -128,6 +128,8 @@ CommandLineUserInterface::Init(Team* team, UserInterfaceListener* listener) if (error != B_OK) return error; + fContext.SetInteractive(!fSaveReport); + error = _RegisterCommands(); if (error != B_OK) return error; @@ -229,11 +231,7 @@ CommandLineUserInterface::Run() if (error != B_OK) return; - if (!fSaveReport) { - _InputLoop(); - // Release the Show() semaphore to signal Terminate(). - release_sem(fShowSemaphore); - } else { + if (fSaveReport) { ArgumentVector args; char buffer[256]; const char* parseErrorLocation; @@ -245,6 +243,10 @@ CommandLineUserInterface::Run() } else _SubmitSaveReport(); } + + _InputLoop(); + // Release the Show() semaphore to signal Terminate(). + release_sem(fShowSemaphore); } @@ -266,21 +268,6 @@ CommandLineUserInterface::ThreadStateChanged(const Team::ThreadEvent& event) } -void -CommandLineUserInterface::DebugReportChanged( - const Team::DebugReportEvent& event) -{ - printf("Successfully saved debug report to %s\n", - event.GetReportPath()); - - if (fSaveReport) { - fContext.QuitSession(true); - // Release the Show() semaphore to signal Terminate(). - release_sem(fShowSemaphore); - } -} - - /*static*/ status_t CommandLineUserInterface::_InputLoopEntry(void* data) { diff --git a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h index 85dffcd3a7..8eec3a3c87 100644 --- a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h +++ b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h @@ -55,8 +55,6 @@ public: // Team::Listener virtual void ThreadStateChanged( const Team::ThreadEvent& event); - virtual void DebugReportChanged( - const Team::DebugReportEvent& event); private: struct CommandEntry;