-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[wasm] Make finding information for wasm in docs/ easier
#120096
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
Merged
ilonatommy
merged 23 commits into
main
from
copilot/fix-121e53e7-7832-4eab-9851-10b0a7e6bdf3
Oct 9, 2025
Merged
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f35935e
Initial plan
Copilot 238cab9
Create comprehensive WASM documentation index and consolidated debugg…
Copilot 19751c6
Consolidate duplicated debugging instructions and add cross-references
Copilot e6c8fbe
Address feedback: consolidate debugging docs and remove duplicated co…
Copilot 0742bbf
Rename wasm-debugging-reference.md to wasm-debugging.md and remove du…
Copilot b2a10f7
Fix markdown linting errors by removing trailing spaces
Copilot 4cdfea4
Merge branch 'main' into copilot/fix-121e53e7-7832-4eab-9851-10b0a7e6…
ilonatommy f964f68
Remove Quick Start paragraph to focus on repo workflow documentation
Copilot 532fa5e
Add JSInterop documentation link to features section
Copilot 560c881
Refocus documentation on contributors and add specific feature links
Copilot 229deb4
Move WASM documentation link to workflow README and remove build conf…
Copilot 873ac67
Add specific links to performance features and remove optimization FAQ
Copilot eceef0e
Merge native WASM debugging documentation into main debugging guide
Copilot 99c0bdf
Move wasm-debugging.md back to mono folder and merge library debuggin…
Copilot 27cbe6a
Replace specific build commands with links to general workflow docume…
Copilot c960083
Consolidate library debugging sections and improve workflow documenta…
Copilot 3e7360c
Apply suggestions from code review
ilonatommy adf8807
WASM -> Wasm
ilonatommy ee8db22
Remove redundant "comprehensive".
ilonatommy aaa6e68
Apply suggestions from code review
ilonatommy e3d9e79
Support PRs with doc-only changes.
ilonatommy 877330e
Merge branch 'main' into copilot/fix-121e53e7-7832-4eab-9851-10b0a7e6…
ilonatommy e01c246
Apply @jkotas suggestion.
ilonatommy 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
5 changes: 3 additions & 2 deletions
5
...workflow/debugging/mono/wasm-debugging.md → ...w/debugging/mono/native-wasm-debugging.md
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 |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| # WebAssembly Debugging Reference | ||
|
|
||
| This document provides consolidated debugging instructions for WebAssembly applications. | ||
|
|
||
| ## Debug with VS Code | ||
|
|
||
| To debug WebAssembly applications with Visual Studio Code: | ||
|
|
||
| ### 1. Configuration | ||
|
|
||
| Add the appropriate configuration to your `.vscode/launch.json` depending on your debugging scenario: | ||
|
|
||
| **For WebAssembly applications, library tests, and general debugging:** | ||
| ```json | ||
| { | ||
| "name": "WASM Attach", | ||
| "request": "attach", | ||
| "type": "chrome", | ||
| "address": "localhost", | ||
| "port": <PROXY_PORT> | ||
| } | ||
| ``` | ||
|
|
||
| **For WASI applications:** | ||
| ```json | ||
| { | ||
| "name": "WASI Attach", | ||
| "type": "mono", | ||
| "request": "attach", | ||
| "address": "localhost", | ||
| "port": 64000 | ||
| } | ||
| ``` | ||
|
|
||
| Replace `<PROXY_PORT>` with the proxy port shown in your application's output. | ||
|
|
||
| ### 2. Setup Steps | ||
|
|
||
| 1. **Set initial breakpoint**: Place a breakpoint in `WasmTestRunner.cs` or your main entry point to prevent execution before you're ready | ||
| 2. **Run the configuration**: Launch the VS Code debug configuration | ||
| 3. **Set additional breakpoints**: Once stopped, set breakpoints in the code you want to debug | ||
| 4. **Continue execution**: Click Resume or F5 to continue | ||
|
|
||
| ## Debug with Chrome DevTools | ||
|
|
||
| ### 1. Basic Setup | ||
|
|
||
| 1. **Open Chrome Inspector**: Navigate to `chrome://inspect/#devices` in a new Chrome tab | ||
| 2. **Configure proxy**: Click "Configure": | ||
|
|
||
|  | ||
|
|
||
| and paste the address of proxy that was provided in the program output: | ||
|
|
||
|  | ||
|
|
||
| 3. **Select target**: New remote targets will be displayed, select the address you opened in the other tab by clicking `Inspect`: | ||
|
|
||
|  | ||
|
|
||
| ### 2. Using DevTools | ||
|
|
||
| 1. **Sources tab**: A new window with Chrome DevTools will be opened. In the tab `sources` you should look for `file://` directory to browse source files | ||
| 2. **Wait for files to load**: It may take time for all source files to appear. You cannot set breakpoints in Chrome DevTools before the files get loaded | ||
| 3. **Set breakpoints**: Click on line numbers to set breakpoints | ||
| 4. **Initial run strategy**: Consider using the first run to set an initial breakpoint in `WasmTestRunner.cs`, then restart the application. DevTools will stop on the previously set breakpoint and you will have time to set breakpoints in the libs you want to debug and click Resume | ||
|
|
||
| ### 3. For Native/C Code Debugging | ||
|
|
||
| 1. **Install DWARF extension**: Install the "C/C++ DevTools Support (DWARF)" Chrome extension | ||
| 2. **Enable symbols**: Build with `WasmNativeDebugSymbols=true` and `WasmNativeStrip=false` | ||
| 3. **Debug native code**: Step through C/C++ code, set breakpoints, and inspect WebAssembly linear memory | ||
|
|
||
| ## Starting Chrome with Remote Debugging | ||
|
|
||
| To enable remote debugging for WebAssembly applications: | ||
|
|
||
| ```bash | ||
| # Close all Chrome instances first | ||
| chrome --remote-debugging-port=9222 <APP_URL> | ||
| ``` | ||
|
|
||
| Replace `<APP_URL>` with the URL shown in your application's output. | ||
|
|
||
| ## Common Debugging Workflow | ||
|
|
||
| ### For Library Tests | ||
|
|
||
| 1. **Run test with debugging**: | ||
| ```bash | ||
| dotnet run -r browser-wasm -c Debug --project src/libraries/System.Collections/tests/System.Collections.Tests.csproj --debug --host browser -p:DebuggerSupport=true | ||
| ``` | ||
|
|
||
| 2. **Note the output**: Look for lines like: | ||
| ``` | ||
| Debug proxy for chrome now listening on http://127.0.0.1:58346/ | ||
| App url: http://127.0.0.1:9000/index.html?arg=--debug&arg=--run&arg=WasmTestRunner.dll | ||
| ``` | ||
|
|
||
| 3. **Start Chrome**: Use the app URL with remote debugging enabled | ||
| 4. **Attach debugger**: Use either Chrome DevTools or VS Code as described above | ||
|
|
||
| ### For WASI Applications | ||
|
|
||
| 1. **Build with debug**: | ||
| ```bash | ||
| cd sample/console | ||
| make debug | ||
| ``` | ||
|
|
||
| 2. **Set up VS Code**: Use the Mono Debug extension configuration above | ||
| 3. **Set breakpoints**: Place breakpoints in your Program.cs or other C# files | ||
| 4. **Start debugging**: Launch the VS Code configuration | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Files Not Loading in DevTools | ||
| - Wait patiently - source files can take time to load initially | ||
| - Try refreshing the DevTools window | ||
| - Ensure your build includes debug symbols | ||
|
|
||
| ### Breakpoints Not Hit | ||
| - Verify the proxy port matches your configuration | ||
| - Check that Chrome is started with remote debugging enabled | ||
| - Ensure your breakpoints are set in code that will actually execute | ||
|
|
||
| ### Connection Issues | ||
| - Verify no firewall is blocking the proxy port | ||
| - Check that the proxy is still running (visible in application output) | ||
| - Try restarting both the application and Chrome | ||
|
|
||
| ## Advanced Debugging | ||
|
|
||
| ### Enable Additional Logging | ||
|
|
||
| Add environment variables for more detailed logging: | ||
|
|
||
| ```javascript | ||
| await dotnet | ||
| .withDiagnosticTracing(true) | ||
| .withConfig({ | ||
| environmentVariables: { | ||
| "MONO_LOG_LEVEL": "debug", | ||
| "MONO_LOG_MASK": "all" | ||
| } | ||
| }) | ||
| .run(); | ||
| ``` | ||
|
|
||
| ### Native Stack Traces | ||
|
|
||
| For native crashes with symbols: | ||
|
|
||
| 1. **Build configuration**: | ||
| ```xml | ||
| <PropertyGroup> | ||
| <WasmNativeDebugSymbols>true</WasmNativeDebugSymbols> | ||
| <WasmNativeStrip>false</WasmNativeStrip> | ||
| </PropertyGroup> | ||
| ``` | ||
|
|
||
| 2. **Install DWARF extension** in Chrome for C/C++ debugging support | ||
|
|
||
| ### Collect Stack Traces | ||
|
|
||
| From runtime code: | ||
ilonatommy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```c | ||
| #ifdef HOST_WASM | ||
| mono_wasm_print_stack_trace(); | ||
| #endif | ||
| ``` | ||
|
|
||
| Or break into JavaScript debugger: | ||
| ```c | ||
| #include <emscripten.h> | ||
| EM_ASM(debugger;); | ||
| ``` | ||
|
|
||
| ## References | ||
|
|
||
| - [Testing Libraries on WebAssembly](../testing/libraries/testing-wasm.md) | ||
| - [Debugging WebAssembly Libraries](../testing/libraries/debugging-wasm.md) | ||
| - [WASM Runtime Debugging](debugging/mono/wasm-debugging.md) | ||
| - [WASI Support](../../src/mono/wasi/README.md) | ||
| - [VS Code Debugging Guide](debugging/libraries/debugging-vscode.md) | ||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.