Add command line option to ask Debugger to save a report.
- When invoked, starts up the CLI such that it bypasses waiting for input and instead save a crash report of the running team, then exits. Mainly intended to be used by debug_server.
This commit is contained in:
@@ -56,8 +56,10 @@ static const char* kUsage =
|
|||||||
"fourth form additionally stops the specified thread.\n"
|
"fourth form additionally stops the specified thread.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
" -h, --help - Print this usage info and exit.\n"
|
" -h, --help - Print this usage info and exit.\n"
|
||||||
" -c, --cli - Use command line user interface\n"
|
" -c, --cli - Use command line user interface\n"
|
||||||
|
" -s, --save-report - Save crash report for the targetted team and exit.\n"
|
||||||
|
" Implies --cli.\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
@@ -76,6 +78,8 @@ struct Options {
|
|||||||
team_id team;
|
team_id team;
|
||||||
thread_id thread;
|
thread_id thread;
|
||||||
bool useCLI;
|
bool useCLI;
|
||||||
|
bool saveReport;
|
||||||
|
const char* reportPath;
|
||||||
|
|
||||||
Options()
|
Options()
|
||||||
:
|
:
|
||||||
@@ -83,7 +87,9 @@ struct Options {
|
|||||||
commandLineArgv(NULL),
|
commandLineArgv(NULL),
|
||||||
team(-1),
|
team(-1),
|
||||||
thread(-1),
|
thread(-1),
|
||||||
useCLI(false)
|
useCLI(false),
|
||||||
|
saveReport(false),
|
||||||
|
reportPath(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -105,15 +111,16 @@ parse_arguments(int argc, const char* const* argv, bool noOutput,
|
|||||||
while (true) {
|
while (true) {
|
||||||
static struct option sLongOptions[] = {
|
static struct option sLongOptions[] = {
|
||||||
{ "help", no_argument, 0, 'h' },
|
{ "help", no_argument, 0, 'h' },
|
||||||
|
{ "cli", no_argument, 0, 'c' },
|
||||||
|
{ "save-report", optional_argument, 0, 's' },
|
||||||
{ "team", required_argument, 0, 't' },
|
{ "team", required_argument, 0, 't' },
|
||||||
{ "thread", required_argument, 0, 'T' },
|
{ "thread", required_argument, 0, 'T' },
|
||||||
{ "cli", no_argument, 0, 'c' },
|
|
||||||
{ 0, 0, 0, 0 }
|
{ 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
opterr = 0; // don't print errors
|
opterr = 0; // don't print errors
|
||||||
|
|
||||||
int c = getopt_long(argc, (char**)argv, "+ch", sLongOptions, NULL);
|
int c = getopt_long(argc, (char**)argv, "+chs", sLongOptions, NULL);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -128,6 +135,14 @@ parse_arguments(int argc, const char* const* argv, bool noOutput,
|
|||||||
print_usage_and_exit(false);
|
print_usage_and_exit(false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
{
|
||||||
|
options.useCLI = true;
|
||||||
|
options.saveReport = true;
|
||||||
|
options.reportPath = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
{
|
{
|
||||||
options.team = strtol(optarg, NULL, 0);
|
options.team = strtol(optarg, NULL, 0);
|
||||||
@@ -581,7 +596,8 @@ CliDebugger::Run(const Options& options)
|
|||||||
|
|
||||||
// create the command line UI
|
// create the command line UI
|
||||||
CommandLineUserInterface* userInterface
|
CommandLineUserInterface* userInterface
|
||||||
= new(std::nothrow) CommandLineUserInterface;
|
= new(std::nothrow) CommandLineUserInterface(options.saveReport,
|
||||||
|
options.reportPath);
|
||||||
if (userInterface == NULL) {
|
if (userInterface == NULL) {
|
||||||
fprintf(stderr, "Error: Out of memory!\n");
|
fprintf(stderr, "Error: Out of memory!\n");
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -88,9 +88,12 @@ private:
|
|||||||
// #pragma mark - CommandLineUserInterface
|
// #pragma mark - CommandLineUserInterface
|
||||||
|
|
||||||
|
|
||||||
CommandLineUserInterface::CommandLineUserInterface()
|
CommandLineUserInterface::CommandLineUserInterface(bool saveReport,
|
||||||
|
const char* reportPath)
|
||||||
:
|
:
|
||||||
fCommands(20, true),
|
fCommands(20, true),
|
||||||
|
fReportPath(reportPath),
|
||||||
|
fSaveReport(saveReport),
|
||||||
fShowSemaphore(-1),
|
fShowSemaphore(-1),
|
||||||
fShown(false),
|
fShown(false),
|
||||||
fTerminating(false)
|
fTerminating(false)
|
||||||
@@ -202,7 +205,18 @@ CommandLineUserInterface::Run()
|
|||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_InputLoop();
|
if (!fSaveReport)
|
||||||
|
_InputLoop();
|
||||||
|
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 the Show() semaphore to signal Terminate().
|
||||||
release_sem(fShowSemaphore);
|
release_sem(fShowSemaphore);
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ class CliCommand;
|
|||||||
|
|
||||||
class CommandLineUserInterface : public UserInterface {
|
class CommandLineUserInterface : public UserInterface {
|
||||||
public:
|
public:
|
||||||
CommandLineUserInterface();
|
CommandLineUserInterface(bool saveReport,
|
||||||
|
const char* reportPath);
|
||||||
virtual ~CommandLineUserInterface();
|
virtual ~CommandLineUserInterface();
|
||||||
|
|
||||||
virtual const char* ID() const;
|
virtual const char* ID() const;
|
||||||
@@ -70,6 +71,8 @@ private:
|
|||||||
private:
|
private:
|
||||||
CliContext fContext;
|
CliContext fContext;
|
||||||
CommandList fCommands;
|
CommandList fCommands;
|
||||||
|
const char* fReportPath;
|
||||||
|
bool fSaveReport;
|
||||||
sem_id fShowSemaphore;
|
sem_id fShowSemaphore;
|
||||||
bool fShown;
|
bool fShown;
|
||||||
volatile bool fTerminating;
|
volatile bool fTerminating;
|
||||||
|
|||||||
Reference in New Issue
Block a user