예제 #1
0
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();
	}
}
예제 #2
0
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());
}
예제 #3
0
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;
}
예제 #4
0
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;
}
예제 #5
0
ArgumentVector* ArgumentVector::readFromBinaryMessage(NetMessage* msg) {
	int i, maxi;
	ArgumentVector* ret;
	unsigned argType;
	std::string key;
	bool tempBool;
	float tempFloat;
	int tempInt;
	unsigned int tempUInt;
	std::string tempString;

	ret = new ArgumentVector();
	msgFunctions::decode(maxi, msg);

	for (i = 0; i < maxi; i++) {
		msgFunctions::decode(key, msg);
		msgFunctions::decode(argType, msg);
		switch (argType) {
		case Argument::BOOL:
			msgFunctions::decode(tempBool, msg);
			ret->push_back(key, tempBool);
			break;

		case Argument::INTEGER:
			msgFunctions::decode(tempInt, msg);
			ret->push_back(key, tempInt);
			break;

		case Argument::UINTEGER:
			msgFunctions::decode(tempUInt, msg);
			ret->push_back(key, tempUInt);
			break;

		case Argument::FLOAT:
			msgFunctions::decode(tempFloat, msg);
			ret->push_back(key, tempFloat);
			break;

		case Argument::STRING:
			msgFunctions::decode(tempString, msg);
			ret->push_back(key, tempString);
			break;

		default:
			assert(false);
		} // switch
	} // for

	return ret;
} // readFromBinaryMessage