From 5fe3a57c43cb4d106c1109e042bc9588d67e0c9d Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sat, 24 Nov 2012 00:46:07 -0500 Subject: [PATCH] Fix handling of automatic debug reports. - CommandLineUserInterface is now a team listener. Consequently, when asked to generate a debug report on startup without running the input loop, it now waits for receipt of the debug report event to terminate. - Style fixes. --- .../cli/CommandLineUserInterface.cpp | 45 ++++++++++++------- .../cli/CommandLineUserInterface.h | 7 ++- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp index a909727aebd..54f7d4c943d 100644 --- a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp +++ b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp @@ -130,6 +130,8 @@ CommandLineUserInterface::Init(Team* team, UserInterfaceListener* listener) if (fShowSemaphore < 0) return fShowSemaphore; + team->AddListener(this); + return B_OK; } @@ -205,9 +207,11 @@ CommandLineUserInterface::Run() if (error != B_OK) return; - if (!fSaveReport) + if (!fSaveReport) { _InputLoop(); - else { + // Release the Show() semaphore to signal Terminate(). + release_sem(fShowSemaphore); + } else { ArgumentVector args; char buffer[256]; const char* parseErrorLocation; @@ -215,11 +219,22 @@ CommandLineUserInterface::Run() fReportPath != NULL ? fReportPath : ""); args.Parse(buffer, &parseErrorLocation); _ExecuteCommand(args.ArgumentCount(), args.Arguments()); - fContext.QuitSession(true); } +} - // Release the Show() semaphore to signal Terminate(). - release_sem(fShowSemaphore); + +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); + } } @@ -292,16 +307,16 @@ CommandLineUserInterface::_RegisterCommands() BReference stackTraceCommandReference2( stackTraceCommandReference.Get()); - if (_RegisterCommand("bt", stackTraceCommandReference.Detach()) && - _RegisterCommand("continue", new(std::nothrow) CliContinueCommand) && - _RegisterCommand("help", new(std::nothrow) HelpCommand(this)) && - _RegisterCommand("quit", new(std::nothrow) CliQuitCommand) && - _RegisterCommand("save-report", - new(std::nothrow) CliDebugReportCommand) && - _RegisterCommand("sc", stackTraceCommandReference2.Detach()) && - _RegisterCommand("stop", new(std::nothrow) CliStopCommand) && - _RegisterCommand("thread", new(std::nothrow) CliThreadCommand) && - _RegisterCommand("threads", new(std::nothrow) CliThreadsCommand)) { + if (_RegisterCommand("bt", stackTraceCommandReference.Detach()) + && _RegisterCommand("continue", new(std::nothrow) CliContinueCommand) + && _RegisterCommand("help", new(std::nothrow) HelpCommand(this)) + && _RegisterCommand("quit", new(std::nothrow) CliQuitCommand) + && _RegisterCommand("save-report", + new(std::nothrow) CliDebugReportCommand) + && _RegisterCommand("sc", stackTraceCommandReference2.Detach()) + && _RegisterCommand("stop", new(std::nothrow) CliStopCommand) + && _RegisterCommand("thread", new(std::nothrow) CliThreadCommand) + && _RegisterCommand("threads", new(std::nothrow) CliThreadsCommand)) { return B_OK; } diff --git a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h index fc01510256d..15630bd4a87 100644 --- a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h +++ b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h @@ -17,7 +17,8 @@ class CliCommand; -class CommandLineUserInterface : public UserInterface { +class CommandLineUserInterface : public UserInterface, + public ::Team::Listener { public: CommandLineUserInterface(bool saveReport, const char* reportPath); @@ -47,6 +48,10 @@ class CommandLineUserInterface : public UserInterface { // everything has been set up. Enters the // input loop. + // Team::Listener + virtual void DebugReportChanged( + const Team::DebugReportEvent& event); + private: struct CommandEntry; typedef BObjectList CommandList;