void CommandLineUserInterface::Run() { // Wait for the Show() semaphore to be released. status_t error; do { error = acquire_sem(fShowSemaphore); } while (error == B_INTERRUPTED); if (error != B_OK) return; if (!fSaveReport) { _InputLoop(); // Release the Show() semaphore to signal Terminate(). release_sem(fShowSemaphore); } else { ArgumentVector args; char buffer[256]; const char* parseErrorLocation; if (_ReportTargetThreadStopNeeded()) { snprintf(buffer, sizeof(buffer), "stop %" B_PRId32, fReportTargetThread); args.Parse(buffer, &parseErrorLocation); _ExecuteCommand(args.ArgumentCount(), args.Arguments()); } else _SubmitSaveReport(); } }
void CommandLineUserInterface::_SubmitSaveReport() { 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()); }
status_t CommandLineUserInterface::_InputLoop() { thread_id currentThread = -1; while (!fTerminating) { // Wait for a thread or Ctrl-C. fContext.WaitForThreadOrUser(); if (fContext.IsTerminating()) break; // Print the active thread, if it changed. if (fContext.CurrentThreadID() != currentThread) { fContext.PrintCurrentThread(); currentThread = fContext.CurrentThreadID(); } // read a command line const char* line = fContext.PromptUser(kDebuggerPrompt); if (line == NULL) break; // parse the command line ArgumentVector args; const char* parseErrorLocation; switch (args.Parse(line, &parseErrorLocation)) { case ArgumentVector::NO_ERROR: break; case ArgumentVector::NO_MEMORY: printf("Insufficient memory parsing the command line.\n"); continue; case ArgumentVector::UNTERMINATED_QUOTED_STRING: printf("Parse error: Unterminated quoted string starting at " "character %zu.\n", parseErrorLocation - line + 1); continue; case ArgumentVector::TRAILING_BACKSPACE: printf("Parse error: trailing backspace.\n"); continue; } if (args.ArgumentCount() == 0) continue; // add line to history fContext.AddLineToInputHistory(line); // execute command _ExecuteCommand(args.ArgumentCount(), args.Arguments()); } return B_OK; }
status_t CommandLineUserInterface::_InputLoop() { while (!fTerminating) { // read a command line printf("debugger> "); fflush(stdout); char buffer[256]; if (fgets(buffer, sizeof(buffer), stdin) == NULL) break; // parse the command line ArgumentVector args; const char* parseErrorLocation; switch (args.Parse(buffer, &parseErrorLocation)) { case ArgumentVector::NO_ERROR: break; case ArgumentVector::NO_MEMORY: printf("Insufficient memory parsing the command line.\n"); continue; case ArgumentVector::UNTERMINATED_QUOTED_STRING: printf("Parse error: Unterminated quoted string starting at " "character %zu.\n", parseErrorLocation - buffer + 1); continue; case ArgumentVector::TRAILING_BACKSPACE: printf("Parse error: trailing backspace.\n"); continue; } if (args.ArgumentCount() == 0) continue; _ExecuteCommand(args.ArgumentCount(), args.Arguments()); } return B_OK; }