Skip to content
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

[wasm][debugging] Adding instructions for native debugging #69873

Merged
merged 18 commits into from
Jun 1, 2022

Conversation

thaystg
Copy link
Member

@thaystg thaystg commented May 26, 2022

Fix #69599

@ghost
Copy link

ghost commented May 26, 2022

Tagging subscribers to this area: @thaystg
See info in area-owners.md if you want to be subscribed.

Issue Details

Fix #69599

Author: thaystg
Assignees: -
Labels:

area-Debugger-mono

Milestone: -

@@ -247,12 +247,10 @@ protected override async Task<bool> AcceptEvent(SessionId sessionId, JObject par
switch (url)
{
case var _ when url == "":
case var _ when url.StartsWith("wasm://", StringComparison.Ordinal):
case var _ when url.EndsWith(".wasm", StringComparison.Ordinal):
Copy link
Member

Choose a reason for hiding this comment

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

Does this have any negative interaction with the code that filters unmanaged frames out of the callstack?

Copy link
Member Author

@thaystg thaystg May 26, 2022

Choose a reason for hiding this comment

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

As far as I know no. I will check it again.

Copy link
Member Author

Choose a reason for hiding this comment

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

With this PR:
image
Without this PR:
image

src/mono/wasm/debugger/debugger.md Outdated Show resolved Hide resolved
It's possible to debug native code and managed code using BrowserDebugProxy.

Steps:
- Install C/C++ DevTools Support (DWARF) extension on chrome.
Copy link
Member

Choose a reason for hiding this comment

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

Is there a link that can be provided for this? How does one find this tool.

Copy link
Member Author

Choose a reason for hiding this comment

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

- You will see c# files and c files available to add breakpoint.

Hint:
- If you are running a Blazor app that has .c file(s) and you added <WasmNativeBuild>true</WasmNativeBuild> in the .csproj file, also add ``<_WasmDevel>true</_WasmDevel>`` to disable optimizations and have a better native debugging experience.
Copy link
Member

Choose a reason for hiding this comment

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

A suggestion here. I think this value should be set to true automatically if the user is building in Debug.

Copy link
Member Author

@thaystg thaystg May 26, 2022

Choose a reason for hiding this comment

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

@radical @lewing , if you agree I can change by default.

Copy link
Member

Choose a reason for hiding this comment

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

For context - right now we use -O1 for Debug by default. And _WasmDevel would make it -O0. @Thays Am I correct in thinking that it won't change the compile times by too much, but it would be very helpful for native debugging, which is not common? We could set it if the user has any native code being linked in.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! It would be very helpful for native debugging.
So we could check, if build is debug and WasmNativeBuild is true then we set _WasmDevel to true?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added this in the PR.

Co-authored-by: Aaron Robinson <arobins@microsoft.com>
- Run chrome using this startup parameter: --remote-debugging-port=9222
- Go to your Blazor App Page
- Press Ctrl-Alt-D (windows) it will open the debugger page
- It will show something like this in the Address Bar: ``http://localhost:9222/devtools/inspector.html?ws=127.0.0.1:9300/devtools/page/97FCDA5A332CA3B72031790B26A264EF``
Copy link
Member

Choose a reason for hiding this comment

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

Is this manual process needed for native debugging specifically?

And does this work with dotnet run --debug for a template browser app too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, without launching using chrome://inspect the extension doesn't work.

Yes. Debugging the runtime while running artifacts\bin\dotnet-workload\dotnet run -f net7.0 -r browser-wasm -v n -c Debug --project src/libraries/System.Collections.Concurrent/tests/System.Collections.Concurrent.Tests.csproj --debug --host browser -p:DebuggerSupport=true

image

Copy link
Member

@ilonatommy ilonatommy left a comment

Choose a reason for hiding this comment

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

Looks good.


Steps:
- Install C/C++ DevTools Support (DWARF) extension on chrome.
- Enable DWARF support: Open DevTools, click on the Engine, click on experiments and enable WebAssembly Debugging: Enable DWARF support.
Copy link
Member

Choose a reason for hiding this comment

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

Probably most people would understand but I at first was not sure what Engine might mean. It's about Settings, right?
image

src/mono/wasm/debugger/debugger.md Show resolved Hide resolved
Comment on lines 26 to 28

Hint:
- If you are running a Blazor app that has .c file(s) and you added <WasmBuildNative>true</WasmBuildNative> in the .csproj file, also add ``<_WasmDevel>true</_WasmDevel>`` to disable optimizations and have a better native debugging experience.
Copy link
Member

Choose a reason for hiding this comment

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

this can be dropped now, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes!

@radical radical added the arch-wasm WebAssembly architecture label May 31, 2022
@ghost
Copy link

ghost commented May 31, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Fix #69599

Author: thaystg
Assignees: thaystg
Labels:

arch-wasm, area-Debugger-mono

Milestone: -

@thaystg thaystg merged commit 72a6f6a into dotnet:main Jun 1, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Debugger-mono
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't debug C native dependency of WASM Blazor
5 participants