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)
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<CliCommand> 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;
}
@@ -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 @@ public:
// everything has been set up. Enters the
// input loop.
// Team::Listener
virtual void DebugReportChanged(
const Team::DebugReportEvent& event);
private:
struct CommandEntry;
typedef BObjectList<CommandEntry> CommandList;