コード例 #1
0
void
CliStackTraceCommand::Execute(int argc, const char* const* argv,
	CliContext& context)
{
	// get the current thread
	Team* team = context.GetTeam();
	AutoLocker<Team> teamLocker(team);
	Thread* thread = context.CurrentThread();
	if (thread == NULL) {
		printf("no current thread\n");
		return;
	}

	if (thread->State() != THREAD_STATE_STOPPED) {
		printf("Current thread is not stopped. Can't get stack trace.\n");
		return;
	}

	// get its stack trace
	StackTrace* stackTrace = thread->GetStackTrace();
	while (stackTrace == NULL) {
		context.WaitForEvents(CliContext::EVENT_THREAD_STACK_TRACE_CHANGED);
		if (context.IsTerminating())
			return;
		stackTrace = thread->GetStackTrace();
	}
	BReference<StackTrace> stackTraceReference(stackTrace);
		// hold a reference until we're done

	teamLocker.Unlock();

	// print the stack trace
	int32 frameCount = stackTrace->CountFrames();
	for (int32 i = 0; i < frameCount; i++) {
		StackFrame* frame = stackTrace->FrameAt(i);
		printf("%3" B_PRId32 "  %#" B_PRIx64 "  %#" B_PRIx64, i,
			(uint64)frame->FrameAddress(), (uint64)frame->InstructionPointer());

		char functionName[512];
		UiUtils::FunctionNameForFrame(frame, functionName,
			sizeof(functionName));
		printf("  %s\n", functionName);
	}
}
コード例 #2
0
void
CliWriteCoreFileCommand::Execute(int argc, const char* const* argv, CliContext& context)
{
	BPath path;
	if (argc > 1) {
		path.SetTo(argv[1]);
		if (path.InitCheck() != B_OK) {
			printf("Invalid core file path %s given.\n", argv[1]);
			return;
		}
	} else {
		char buffer[B_FILE_NAME_LENGTH];
		UiUtils::CoreFileNameForTeam(context.GetTeam(), buffer,
			sizeof(buffer));
		find_directory(B_DESKTOP_DIRECTORY, &path);
		path.Append(buffer);
	}

	entry_ref ref;
	if (get_ref_for_path(path.Path(), &ref) == B_OK) {
		printf("Writing core file to %s...\n", path.Path());
		context.GetUserInterfaceListener()->WriteCoreFileRequested(&ref);
	}
}