[debug] Replace mojo run JIT execution with AOT compilation and debugging of produced executable#192
Open
rolfmorel wants to merge 15 commits into
Open
[debug] Replace mojo run JIT execution with AOT compilation and debugging of produced executable#192rolfmorel wants to merge 15 commits into
rolfmorel wants to merge 15 commits into
Conversation
mojo run currently executes user programs in-process via ORC JIT, with LLDB attached to the mojo process itself. This means a crash in user code produces an internal mojo crash dump rather than a clean error, and the approach is fragile as the mojo team plans to move to a fork+exec AOT model. Prepare the extension for this by switching to compile-first: build to a temp binary with `mojo build`, then have LLDB launch that binary directly. This works correctly today and will continue to work after the mojo-side change lands. - Add `buildMojoFile`: runs `mojo build --no-optimization --debug-level full` into a uniquely-named temp file, ad-hoc codesigns with `get-task-allow` on macOS (required for LLDB to debug a binary it launches), and returns a typed BuildResult. - `MojoDebugConfigurationResolver`: replace the `mojo run`-as-program block with a `withProgress`-wrapped build step; on success set `program` to the binary and preserve user run-args; on failure show an actionable error and abort. - `MojoCudaGdbDebugConfigurationResolver`: same for the cuda-gdb path. - `MojoDebugManager`: add `onDidTerminateDebugSession` listener to unlink the temp binary after each session. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
With the compile-first approach, the mojo wrapper is only invoked as a subprocess (for mojo build), not launched under LLDB. The original supportsFileDebug guard — which blocked wheel SDKs because "the wrapper can't be launched under LLDB" — no longer applies. - Remove the supportsFileDebug guard from MojoDebugConfigurationResolver. - Add MODULAR_MOJO_MAX_LLDB_PLUGIN_PATH and MODULAR_MOJO_MAX_LLDB_VISUALIZERS_PATH to SDK.getProcessEnv(): the wheel's lldb-dap is a Python wrapper that reads these at startup to bootstrap the real lldb-dap binary; without them it crashes with a KeyError before the debug session can start. - Downgrade the LLDB Python scripting unavailability log from ERROR (with full Node.js stack trace) to a single INFO line; this is a known SDK limitation, not an extension error. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
All contributors have signed the CLA ✍️ ✅ |
Use mkdtemp to create a mode-700 temporary directory so the compiled debug binary and macOS entitlements plist are not exposed to other users via the world-accessible os.tmpdir(). Cleanup now removes the whole directory rather than just unlinking the binary. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
Pull request overview
This PR updates the Mojo VS Code extension’s debugging flow to compile mojoFile configurations ahead-of-time (AOT) into a temporary executable and then debug that executable, instead of launching mojo run (JIT) under the debugger. It also improves compatibility with wheel-installed SDKs by setting additional environment variables for the SDK-provided lldb-dap wrapper.
Changes:
- Added an AOT build step (
mojo build --no-optimization --debug-level full) that produces a uniquely-named temp executable for debugging. - Updated both
mojo-lldbandmojo-cuda-gdbconfiguration resolvers to build first, then setprogramto the produced binary and preserve user run-args. - Adjusted SDK environment / logging: added
MODULAR_MOJO_MAX_LLDB_*env vars and downgraded missing LLDB Python scripting support logging to INFO.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| extension/pyenv.ts | Adds MODULAR_MOJO_MAX_LLDB_* env vars for wheel lldb-dap wrapper; reduces LLDB Python scripting failure log severity/noise. |
| extension/debug/debug.ts | Implements AOT build-to-temp-binary for debugging; adds cleanup on session termination; updates resolvers to use built executable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Moves debug execution from in-process with the compilation (i.e.
mojo runmaking use of ORC JIT) to AOT (i.e.mojo build exe.mojo; ./exe), with LLDB attached to a process running the produced executable by itself.This means crashes in user code will no longer be confused with compilation errors, a model that
mojo runwill soon adopt as well.Also enables file debugging for wheel-installed Mojo SDKs.
Summary of changes:
buildMojoFile: runsmojo build --no-optimization --debug-level fullinto a uniquely-named, mode-700 temp directory (created viamkdtemp), ad-hoc codesigns withget-task-allowon macOS (requiredfor LLDB to debug a binary it launches), and returns a typed
BuildResult. Files inside the directory are not accessible to other
users, preventing insecure temp-file races (CWE-377/378).
MojoDebugConfigurationResolver: replace themojo run-as-programblock with a
withProgress-wrapped build step; on success setprogramto the binary and preserve user run-args; on failure showan actionable error and abort.
MojoCudaGdbDebugConfigurationResolver: same for the cuda-gdb path.MojoDebugManager: addonDidTerminateDebugSessionlistener toremove the temp directory after each session.
MODULAR_MOJO_MAX_LLDB_VISUALIZERS_PATH to SDK.getProcessEnv(): the
wheel's lldb-dap is a Python wrapper that reads these at startup to
bootstrap the real lldb-dap binary; without them it crashes with a
KeyError before the debug session can start.
(with full Node.js stack trace) to a single INFO line; this is a
known SDK limitation, not an extension error.
Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com