rem: "B_DEBUGGED_THREAD_MESSAGE_CONTINUE\n", thread->id)); result = commandMessage.run.handle_event;
add: "B_DEBUGGED_THREAD_MESSAGE_CONTINUE\n", thread->id)); result = commandMessage.continue_thread.handle_event;   state = disable_interrupts(); GRAB_THREAD_LOCK();  if (commandMessage.continue_thread.single_step) { atomic_or(&thread->debug_info.flags, B_THREAD_DEBUG_SINGLE_STEP); } else { atomic_and(&thread->debug_info.flags, ~B_THREAD_DEBUG_SINGLE_STEP); }  RELEASE_THREAD_LOCK(); restore_interrupts(state);
context: thread_hit_debug_event(uint32 event, const void *message, int32 size,	debug_why_stopped whyStopped, void *additionalData){	struct thread *thread = thread_get_current_thread();	TRACE(("thread_hit_debug_event(): thread: %ld, event: %lu, message: %p, "		"size: %ld\n", thread->id, event, message, size));	// check, if there's a debug port already	bool setPort = !(atomic_get(&thread->debug_info.flags)		& B_THREAD_DEBUG_INITIALIZED);	// create a port, if there is none yet	port_id port = -1;	if (setPort) {		char nameBuffer[128];		snprintf(nameBuffer, sizeof(nameBuffer), "nub to thread %ld",			thread->id);		port = create_port(1, nameBuffer);		if (port < 0) {			dprintf("thread_hit_debug_event(): Failed to create debug port: "				"%s\n", strerror(port));			return port;		}		setPort = true;	}	// check the debug info structures once more: get the debugger port, set	// the thread's debug port, and update the thread's debug flags	port_id deletePort = port;	port_id debuggerPort = -1;	status_t error = B_OK;	cpu_status state = disable_interrupts();	GRAB_TEAM_LOCK();	GRAB_THREAD_LOCK();	uint32 threadFlags = thread->debug_info.flags;	threadFlags &= ~B_THREAD_DEBUG_STOP;	if (thread->team->debug_info.flags & B_TEAM_DEBUG_DEBUGGER_INSTALLED) {		debuggerPort = thread->team->debug_info.debugger_port;		if (setPort) {			if (threadFlags & B_THREAD_DEBUG_INITIALIZED) {				// someone created a port for us (the port we've created will				// be deleted below)				port = thread->debug_info.debug_port;			} else {				thread->debug_info.debug_port = port;				deletePort = -1;	// keep the port				threadFlags |= B_THREAD_DEBUG_INITIALIZED;			}		} else {			if (threadFlags & B_THREAD_DEBUG_INITIALIZED) {				port = thread->debug_info.debug_port;			} else {				// someone deleted our port				error = B_ERROR;			}		}	} else		error = B_ERROR;	// update the flags	if (error == B_OK)		threadFlags |= B_THREAD_DEBUG_STOPPED;	atomic_set(&thread->debug_info.flags, threadFlags);	RELEASE_THREAD_LOCK();	RELEASE_TEAM_LOCK();	restore_interrupts(state);	// delete the superfluous port	if (deletePort >= 0)		delete_port(deletePort);	if (error != B_OK) {		TRACE(("thread_hit_debug_event() error: thread: %ld, error: %lx\n",			thread->id, error));		return error;	}	// send a message to the debugger port	TRACE(("thread_hit_debug_event(): thread: %ld, sending message to debugger "		"port %ld\n", thread->id, debuggerPort));	do {		error = write_port(debuggerPort, event, message, size);	} while (error == B_INTERRUPTED);	status_t result = B_THREAD_DEBUG_HANDLE_EVENT;	if (error == B_OK) {		bool done = false;		while (!done) {			// read a command from the debug port			int32 command;			debugged_thread_message_data commandMessage;			ssize_t commandMessageSize = kill_interruptable_read_port(port,				&command, &commandMessage, sizeof(commandMessage));			if (commandMessageSize < 0) {				error = commandMessageSize;				TRACE(("thread_hit_debug_event(): thread: %ld, failed to "					"receive message from port %ld: %lx\n", thread->id, port,					error));				break;			}			switch (command) {				case B_DEBUGGED_THREAD_MESSAGE_CONTINUE:					TRACE(("thread_hit_debug_event(): thread: %ld: "						"B_DEBUGGED_THREAD_MESSAGE_CONTINUE\n", thread->id));					result = commandMessage.run.handle_event;					done = true;					break;				case B_DEBUGGED_THREAD_GET_WHY_STOPPED:				{					// get the team debug info (just in case it has changed)					team_debug_info teamDebugInfo;					get_team_debug_info(teamDebugInfo);					if (!(teamDebugInfo.flags							& B_TEAM_DEBUG_DEBUGGER_INSTALLED)) {						done = true;						break;					}					debuggerPort = teamDebugInfo.debugger_port;					// prepare the message					debug_thread_stopped stoppedMessage;					prepare_thread_stopped_message(stoppedMessage, whyStopped,						teamDebugInfo.nub_port, additionalData);					// send it					error = kill_interruptable_write_port(debuggerPort, event,						&stoppedMessage, sizeof(stoppedMessage));					break;				}			}		}	} else {		TRACE(("thread_hit_debug_event(): thread: %ld, failed to send message "			"to debugger port %ld: %lx\n", thread->id, debuggerPort, error));	}	// unset the "stopped" state	state = disable_interrupts();	GRAB_THREAD_LOCK();	atomic_and(&thread->debug_info.flags, ~B_THREAD_DEBUG_STOPPED);	RELEASE_THREAD_LOCK();	restore_interrupts(state);	return (error == B_OK ? result : error);}