add: GRAB_THREAD_LOCK();  for (struct thread *thread = team->thread_list; thread; thread = thread->team_next) { if (thread->id != nubThread) { int32 flags = thread->debug_info.flags & ~B_THREAD_DEBUG_USER_FLAG_MASK; atomic_set(&thread->debug_info.flags, flags | B_THREAD_DEBUG_DEFAULT_FLAGS); } }  RELEASE_THREAD_LOCK();
context: install_team_debugger(team_id teamID, port_id debuggerPort, bool useDefault,	bool dontFail){TRACE(("install_team_debugger(team: %ld, port: %ld, default: %d, ""dontFail: %d)\n", teamID, debuggerPort, useDefault, dontFail));	if (useDefault)		debuggerPort = atomic_get(&sDefaultDebuggerPort);	// check, if a debugger is already installed	status_t error = B_OK;	bool done = false;	port_id result = B_ERROR;	cpu_status state = disable_interrupts();	GRAB_TEAM_LOCK();	struct team *team = (teamID == B_CURRENT_TEAM		? thread_get_current_thread()->team		: team_get_team_struct_locked(teamID));	if (team) {		if (team == team_get_kernel_team()) {			// don't allow to debug the kernel			error = B_NOT_ALLOWED;		} else if (team->debug_info.flags & B_TEAM_DEBUG_DEBUGGER_INSTALLED) {			// there's already a debugger installed			error = (dontFail ? B_OK : B_BAD_VALUE);			done = true;			result = team->debug_info.nub_port;		}	} else		error = B_BAD_TEAM_ID;//int32 teamDebugFlags = team->debug_info.flags;//team_debug_info *teamDebugInfo = &team->debug_info;	RELEASE_TEAM_LOCK();	restore_interrupts(state);//if (error != B_OK) {//dprintf("install_team_debugger(): First check failed: team: %p (%ld), "//"sizeof(struct team): %lu, info: %p, flags: %lx, error: %lx\n", team, team->id, sizeof(struct team), teamDebugInfo, teamDebugFlags, error);//dprintf("  dead_children: %p, dead_children.kernel_time: %p, aspace: %p, "//"image_list: %p, arch_info: %p, debug_info: %p, dead_threads_kernel_time: %p, "//"dead_threads_user_time: %p\n", &team->dead_children,//&team->dead_children.kernel_time, &team->aspace, &team->image_list,//&team->arch_info, &team->debug_info, &team->dead_threads_kernel_time,//&team->dead_threads_user_time);//}	if (done || error != B_OK) {		TRACE(("install_team_debugger() done1: %ld\n",			(error == B_OK ? result : error)));		return (error == B_OK ? result : error);	}	// get the debugger team	port_info debuggerPortInfo;	error = get_port_info(debuggerPort, &debuggerPortInfo);	if (error != B_OK) {		TRACE(("install_team_debugger(): Failed to get debugger port info: "			"%lx\n", error));		return error;	}	team_id debuggerTeam = debuggerPortInfo.team;	// check the debugger team: It must neither be the kernel team nor the	// debugged team	if (debuggerTeam == team_get_kernel_team_id() || debuggerTeam == teamID) {		TRACE(("install_team_debugger(): Can't debug kernel or debugger team. "			"debugger: %ld, debugged: %ld\n", debuggerTeam, teamID));		return B_NOT_ALLOWED;	}	// create the nub port	char nameBuffer[B_OS_NAME_LENGTH];	snprintf(nameBuffer, sizeof(nameBuffer), "team %ld debug", teamID);	port_id nubPort = create_port(1, nameBuffer);	if (nubPort < 0)		error = nubPort;	else		result = nubPort;	// make the debugger team the port owner; thus we know, if the debugger is	// gone and can cleanup	if (error == B_OK)		error = set_port_owner(nubPort, debuggerTeam);	// spawn the nub thread	thread_id nubThread = -1;	if (error == B_OK) {		snprintf(nameBuffer, sizeof(nameBuffer), "team %ld debug task", teamID);		nubThread = spawn_kernel_thread_etc(debug_nub_thread, nameBuffer,			B_NORMAL_PRIORITY, NULL, teamID);		if (nubThread < 0)			error = nubThread;	}	// now adjust the debug info accordingly	if (error == B_OK) {		state = disable_interrupts();		GRAB_TEAM_LOCK();		team = (teamID == B_CURRENT_TEAM			? thread_get_current_thread()->team			: team_get_team_struct_locked(teamID));		if (team) {			if (team->debug_info.flags & B_TEAM_DEBUG_DEBUGGER_INSTALLED) {				// there's already a debugger installed				error = (dontFail ? B_OK : B_BAD_VALUE);				done = true;				result = team->debug_info.nub_port;			} else {				atomic_or(&team->debug_info.flags,					B_TEAM_DEBUG_DEBUGGER_INSTALLED);				team->debug_info.nub_port = nubPort;				team->debug_info.nub_thread = nubThread;				team->debug_info.debugger_team = debuggerTeam;				team->debug_info.debugger_port = debuggerPort;			}		} else			error = B_BAD_TEAM_ID;		RELEASE_TEAM_LOCK();		restore_interrupts(state);	}	// if everything went fine, resume the nub thread, otherwise clean up	if (error == B_OK && !done) {		resume_thread(nubThread);	} else {		// delete port and terminate thread		if (nubPort >= 0) {			set_port_owner(nubPort, B_CURRENT_TEAM);			delete_port(nubPort);		}		if (nubThread >= 0) {			int32 result;			wait_for_thread(nubThread, &result);		}	}	TRACE(("install_team_debugger() done2: %ld\n",		(error == B_OK ? result : error)));	return (error == B_OK ? result : error);}