-
Notifications
You must be signed in to change notification settings - Fork 6
MacOS Debug Support #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
keyz182
wants to merge
3
commits into
Garethp:main
Choose a base branch
from
keyz182:mac
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,27 @@ | ||
| package RimworldDev.Rider.run | ||
|
|
||
| import RimworldDev.Rider.helpers.ScopeHelper | ||
| import com.intellij.execution.ExecutionException | ||
| import com.intellij.execution.ExecutionResult | ||
| import com.intellij.execution.Executor | ||
| import com.intellij.execution.configurations.RunProfileState | ||
| import com.intellij.execution.process.* | ||
| import com.intellij.execution.runners.ExecutionEnvironment | ||
| import com.intellij.execution.runners.ProgramRunner | ||
| import com.intellij.ide.actions.searcheverywhere.evaluate | ||
| import com.intellij.util.system.OS | ||
| import com.jetbrains.rd.util.lifetime.Lifetime | ||
| import com.jetbrains.rider.debugger.DebuggerWorkerProcessHandler | ||
| import com.jetbrains.rider.plugins.unity.run.configurations.UnityAttachProfileState | ||
| import com.jetbrains.rider.run.configurations.remote.RemoteConfiguration | ||
| import com.jetbrains.rider.run.getProcess | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.delay | ||
| import kotlinx.coroutines.withContext | ||
| import java.io.File | ||
| import java.io.FileOutputStream | ||
| import java.net.BindException | ||
| import java.net.InetSocketAddress | ||
| import java.net.ServerSocket | ||
| import java.nio.file.Files | ||
| import kotlin.io.path.Path | ||
|
|
||
|
|
@@ -59,12 +65,16 @@ class RunState( | |
| "Doorstop/pdb2mdb.exe", | ||
| ), | ||
| OS.macOS to listOf( | ||
| "run.sh", | ||
| ".doorstop_version", | ||
| ".doorstop_config.ini", | ||
| "doorstop_config.ini", | ||
|
|
||
| "Doorstop/0Harmony.dll", | ||
| "Doorstop/dnlib.dll", | ||
| "Doorstop/Doorstop.dll", | ||
| "Doorstop/Doorstop.pdb", | ||
| "Doorstop/HotReload.dll", | ||
| "Doorstop/libdoorstop.dylib", | ||
| "Doorstop/Mono.Cecil.dll", | ||
| "Doorstop/Mono.CompilerServices.SymbolWriter.dll", | ||
| "Doorstop/pdb2mdb.exe", | ||
|
|
@@ -78,31 +88,76 @@ class RunState( | |
| lifetime: Lifetime | ||
| ): ExecutionResult { | ||
| setupDoorstop() | ||
| val result = super.execute(executor, runner, workerProcessHandler) | ||
| ProcessTerminatedListener.attach(workerProcessHandler.debuggerWorkerRealHandler) | ||
|
|
||
| val rimworldResult = rimworldState.execute(executor, runner) | ||
| workerProcessHandler.debuggerWorkerRealHandler.addProcessListener(createProcessListener(rimworldResult?.processHandler)) | ||
| QuickStartUtils.setup(modListPath, saveFilePath) | ||
|
|
||
| // On macOS/Linux we must bypass rimworldState.execute() for two reasons: | ||
| // 1. CommandLineState.execute() has implicit EDT dependencies (console view creation) | ||
| // that fail silently when called from this suspend function's coroutine context. | ||
| // 2. On macOS, the 'open' command launches apps through launchd, which is SIP-protected | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a comment here to explain why this is required on mac for future reference |
||
| // and strips DYLD_INSERT_LIBRARIES — preventing Doorstop injection entirely. | ||
| // ProcessBuilder with run.sh avoids both: it fork/exec's directly, preserving DYLD_* vars, | ||
| // and has no IntelliJ threading requirements. Windows uses DLL hijacking (winhttp.dll) | ||
| // instead of DYLD injection, so rimworldState.execute() works fine there. | ||
| val gameProcess: Process? = if (OS.CURRENT == OS.macOS || OS.CURRENT == OS.Linux) { | ||
| val bashScriptPath = "${Path(rimworldLocation).parent}/run.sh" | ||
| withContext(Dispatchers.IO) { | ||
| val logFile = File(System.getProperty("java.io.tmpdir"), "rimworld-doorstop.log") | ||
| ProcessBuilder("/bin/sh", bashScriptPath, rimworldLocation) | ||
| .redirectErrorStream(true) | ||
| .redirectOutput(logFile) | ||
| .start() | ||
| } | ||
| } else { | ||
| // Windows: rimworldState handles env vars and process lifecycle normally. | ||
| rimworldState.execute(executor, runner)?.processHandler?.getProcess() | ||
| } | ||
|
|
||
| return result | ||
| } | ||
| // Poll until the Mono debug server is reachable before attaching the debugger. | ||
| if (!waitForMonoDebugServer()) { | ||
| throw ExecutionException( | ||
| "Timed out waiting for Mono debug server on port 56000. " + | ||
| "The game process may have failed to start, or Doorstop may not have injected. " + | ||
| "Check that run.sh is executable and that libdoorstop.dylib is present in the game directory." | ||
| ) | ||
| } | ||
|
|
||
| private fun createProcessListener(siblingProcessHandler: ProcessHandler?): ProcessListener { | ||
| return object : ProcessAdapter() { | ||
| val result = super.execute(executor, runner, workerProcessHandler) | ||
| ProcessTerminatedListener.attach(workerProcessHandler.debuggerWorkerRealHandler) | ||
| workerProcessHandler.debuggerWorkerRealHandler.addProcessListener(object : ProcessAdapter() { | ||
| override fun processTerminated(event: ProcessEvent) { | ||
| val processHandler = event.processHandler | ||
| processHandler.removeProcessListener(this) | ||
|
|
||
| event.processHandler.removeProcessListener(this) | ||
| if (OS.CURRENT == OS.Linux) { | ||
| siblingProcessHandler?.getProcess()?.destroyForcibly() | ||
| gameProcess?.destroyForcibly() | ||
| } else { | ||
| siblingProcessHandler?.getProcess()?.destroy() | ||
| gameProcess?.destroy() | ||
| } | ||
|
|
||
| QuickStartUtils.tearDown(saveFilePath) | ||
| removeDoorstep() | ||
| } | ||
| }) | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| private suspend fun waitForMonoDebugServer(port: Int = 56000, timeoutMs: Long = 60_000): Boolean { | ||
| val deadline = System.currentTimeMillis() + timeoutMs | ||
| while (System.currentTimeMillis() < deadline) { | ||
| // Bind to 127.0.0.1 explicitly — on macOS, 0.0.0.0 and 127.0.0.1 are distinct | ||
| // bind targets, so ServerSocket(port) alone wouldn't detect Mono listening. | ||
| val isListening = withContext(Dispatchers.IO) { | ||
| try { | ||
| ServerSocket().use { it.bind(InetSocketAddress("127.0.0.1", port)) } | ||
| false | ||
| } catch (_: BindException) { | ||
| true | ||
| } catch (_: Exception) { | ||
| false | ||
| } | ||
| } | ||
| if (isListening) return true | ||
| delay(500) | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| private fun setupDoorstop() { | ||
|
|
||
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+102 KB
src/rider/main/resources/UnityDoorstop/macOS/Doorstop/libdoorstop.dylib
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested without these changes and get
So I believe they're needed.