Skip to content

Commit

Permalink
Fix handling of automatic debug reports.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
anevilyak committed Nov 24, 2012
1 parent 248c2ff commit 5fe3a57
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
45 changes: 30 additions & 15 deletions src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp
Expand Up @@ -130,6 +130,8 @@ CommandLineUserInterface::Init(Team* team, UserInterfaceListener* listener)
if (fShowSemaphore < 0)
return fShowSemaphore;

team->AddListener(this);

return B_OK;
}

Expand Down Expand Up @@ -205,21 +207,34 @@ 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;
snprintf(buffer, sizeof(buffer), "save-report %s",
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);
}
}


Expand Down Expand Up @@ -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;
}

Expand Down
Expand Up @@ -17,7 +17,8 @@
class CliCommand;


class CommandLineUserInterface : public UserInterface {
class CommandLineUserInterface : public UserInterface,
public ::Team::Listener {
public:
CommandLineUserInterface(bool saveReport,
const char* reportPath);
Expand Down Expand Up @@ -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<CommandEntry> CommandList;
Expand Down

0 comments on commit 5fe3a57

Please sign in to comment.