示例#1
0
status_t
DebugReportGenerator::_DumpFunctionDisassembly(BFile& _output,
	target_addr_t instructionPointer)
{
	AutoLocker< ::Team> teamLocker(fTeam);
	BString data;
	FunctionInstance* instance = NULL;
	Statement* statement = NULL;
	status_t error = fTeam->GetStatementAtAddress(instructionPointer, instance,
		statement);
	if (error != B_OK) {
		data.SetToFormat("Unable to retrieve disassembly for IP %#" B_PRIx64
				": %s\n", instructionPointer, strerror(error));
		WRITE_AND_CHECK(_output, data);
		return B_OK;
	}

	DisassembledCode* code = instance->GetSourceCode();
	Function* function = instance->GetFunction();
	if (code == NULL) {
		switch (function->SourceCodeState()) {
			case FUNCTION_SOURCE_NOT_LOADED:
			case FUNCTION_SOURCE_LOADED:
				// FUNCTION_SOURCE_LOADED is included since, if we entered
				// here, it implies that the high level source for the
				// function has been loaded, but the disassembly has not.
				function->AddListener(this);
				fSourceWaitingFunction = function;
				fListener->FunctionSourceCodeRequested(instance, true);
				// fall through
			case FUNCTION_SOURCE_LOADING:
			{
				teamLocker.Unlock();
				do {
					error = acquire_sem(fTeamDataSem);
				} while (error == B_INTERRUPTED);

				if (error != B_OK)
					return error;

				teamLocker.Lock();
				break;
			}
			default:
				return B_OK;
		}

		if (instance->SourceCodeState() == 	FUNCTION_SOURCE_UNAVAILABLE)
			return B_OK;

		error = fTeam->GetStatementAtAddress(instructionPointer, instance,
			statement);
		code = instance->GetSourceCode();
	}

	SourceLocation location = statement->StartSourceLocation();

	data = "\t\t\tDisassembly:\n";
	WRITE_AND_CHECK(_output, data);
	for (int32 i = 0; i <= location.Line(); i++) {
		data = "\t\t\t\t";
		data << code->LineAt(i);
		if (i == location.Line())
			data << " <--";
		data << "\n";
		WRITE_AND_CHECK(_output, data);
	}
	data = "\n";
	WRITE_AND_CHECK(_output, data);

	return B_OK;
}