Skip to content

[debug] Replace mojo run JIT execution with AOT compilation and debugging of produced executable#192

Open
rolfmorel wants to merge 15 commits into
mainfrom
users/rolfmorel/debug/compile-first-aot
Open

[debug] Replace mojo run JIT execution with AOT compilation and debugging of produced executable#192
rolfmorel wants to merge 15 commits into
mainfrom
users/rolfmorel/debug/compile-first-aot

Conversation

@rolfmorel

@rolfmorel rolfmorel commented Jun 8, 2026

Copy link
Copy Markdown

Moves debug execution from in-process with the compilation (i.e. mojo run making 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 run will soon adopt as well.

Also enables file debugging for wheel-installed Mojo SDKs.

Summary of changes:

  • Add buildMojoFile: runs mojo build --no-optimization --debug-level full into a uniquely-named, mode-700 temp directory (created via
    mkdtemp), ad-hoc codesigns with get-task-allow on macOS (required
    for 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 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
    remove the temp directory after each session.
  • 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

rolfmorel and others added 2 commits May 29, 2026 17:14
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>
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Comment thread extension/debug/debug.ts Fixed
rolfmorel and others added 2 commits June 8, 2026 13:16
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>
@rolfmorel

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

modular-cla-bot Bot added a commit to modular/cla that referenced this pull request Jun 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-lldb and mojo-cuda-gdb configuration resolvers to build first, then set program to 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.

Comment thread extension/debug/debug.ts
Comment thread extension/debug/debug.ts Outdated
Comment thread extension/debug/debug.ts
Comment thread extension/debug/debug.ts
Comment thread extension/debug/debug.ts Outdated
Comment thread extension/debug/debug.ts
rolfmorel and others added 5 commits June 8, 2026 13:46
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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread extension/debug/debug.ts
Comment thread extension/debug/debug.ts
rolfmorel and others added 3 commits June 8, 2026 13:58
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rolfmorel rolfmorel requested a review from aahrun June 8, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants