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.
This commit is contained in:
Rene Gollent
2012-11-24 00:53:09 -05:00
parent 248c2ff45c
commit 5fe3a57c43
2 changed files with 36 additions and 16 deletions
@@ -130,6 +130,8 @@ CommandLineUserInterface::Init(Team* team, UserInterfaceListener* listener)
if (fShowSemaphore < 0) if (fShowSemaphore < 0)
return fShowSemaphore; return fShowSemaphore;
team->AddListener(this);
return B_OK; return B_OK;
} }
@@ -205,9 +207,11 @@ CommandLineUserInterface::Run()
if (error != B_OK) if (error != B_OK)
return; return;
if (!fSaveReport) if (!fSaveReport) {
_InputLoop(); _InputLoop();
else { // Release the Show() semaphore to signal Terminate().
release_sem(fShowSemaphore);
} else {
ArgumentVector args; ArgumentVector args;
char buffer[256]; char buffer[256];
const char* parseErrorLocation; const char* parseErrorLocation;
@@ -215,11 +219,22 @@ CommandLineUserInterface::Run()
fReportPath != NULL ? fReportPath : ""); fReportPath != NULL ? fReportPath : "");
args.Parse(buffer, &parseErrorLocation); args.Parse(buffer, &parseErrorLocation);
_ExecuteCommand(args.ArgumentCount(), args.Arguments()); _ExecuteCommand(args.ArgumentCount(), args.Arguments());
fContext.QuitSession(true);
} }
}
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 the Show() semaphore to signal Terminate().
release_sem(fShowSemaphore); release_sem(fShowSemaphore);
}
} }
@@ -292,16 +307,16 @@ CommandLineUserInterface::_RegisterCommands()
BReference<CliCommand> stackTraceCommandReference2( BReference<CliCommand> stackTraceCommandReference2(
stackTraceCommandReference.Get()); stackTraceCommandReference.Get());
if (_RegisterCommand("bt", stackTraceCommandReference.Detach()) && if (_RegisterCommand("bt", stackTraceCommandReference.Detach())
_RegisterCommand("continue", new(std::nothrow) CliContinueCommand) && && _RegisterCommand("continue", new(std::nothrow) CliContinueCommand)
_RegisterCommand("help", new(std::nothrow) HelpCommand(this)) && && _RegisterCommand("help", new(std::nothrow) HelpCommand(this))
_RegisterCommand("quit", new(std::nothrow) CliQuitCommand) && && _RegisterCommand("quit", new(std::nothrow) CliQuitCommand)
_RegisterCommand("save-report", && _RegisterCommand("save-report",
new(std::nothrow) CliDebugReportCommand) && new(std::nothrow) CliDebugReportCommand)
_RegisterCommand("sc", stackTraceCommandReference2.Detach()) && && _RegisterCommand("sc", stackTraceCommandReference2.Detach())
_RegisterCommand("stop", new(std::nothrow) CliStopCommand) && && _RegisterCommand("stop", new(std::nothrow) CliStopCommand)
_RegisterCommand("thread", new(std::nothrow) CliThreadCommand) && && _RegisterCommand("thread", new(std::nothrow) CliThreadCommand)
_RegisterCommand("threads", new(std::nothrow) CliThreadsCommand)) { && _RegisterCommand("threads", new(std::nothrow) CliThreadsCommand)) {
return B_OK; return B_OK;
} }
@@ -17,7 +17,8 @@
class CliCommand; class CliCommand;
class CommandLineUserInterface : public UserInterface { class CommandLineUserInterface : public UserInterface,
public ::Team::Listener {
public: public:
CommandLineUserInterface(bool saveReport, CommandLineUserInterface(bool saveReport,
const char* reportPath); const char* reportPath);
@@ -47,6 +48,10 @@ public:
// everything has been set up. Enters the // everything has been set up. Enters the
// input loop. // input loop.
// Team::Listener
virtual void DebugReportChanged(
const Team::DebugReportEvent& event);
private: private:
struct CommandEntry; struct CommandEntry;
typedef BObjectList<CommandEntry> CommandList; typedef BObjectList<CommandEntry> CommandList;