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][debug] Avoid pausing on breakpoint while invoking methods. #81162

Merged
merged 11 commits into from
Feb 7, 2023

Conversation

thaystg
Copy link
Member

@thaystg thaystg commented Jan 25, 2023

This is trying to proactively fix a potential issue. It was prompted by this error on CI while running test SteppingIntoLibrarySymbolsLoadedFromSymbolServerRemoveSymbolServerAndStepAgain:

Error while evaluating ToString method: Microsoft.WebAssembly.Diagnostics.DebuggerAgentException:
    SendDebuggerAgentCommand failed for InvokeMethod: [Result: IsOk: False, IsErr: True, Value: ,
        Error: {
            "result": {
                "type": "object",
                "subtype": "error",
                "className": "RuntimeError",
                "description": "RuntimeError: memory access out of bounds
                                at create_event_list (http://localhost:9400/dotnet.wasm:wasm-function[1360]:0x709ca)
                                at mono_dbg_create_breakpoint_events (http://localhost:9400/dotnet.wasm:wasm-function[1359]:0x70490)
                                at mono_de_process_single_step (http://localhost:9400/dotnet.wasm:wasm-function[1250]:0x6a78a)
                                at mono_wasm_single_step_hit (http://localhost:9400/dotnet.wasm:wasm-function[1194]:0x68095)
                                at do_debugger_tramp (http://localhost:9400/dotnet.wasm:wasm-function[259]:0x19dd6)
                                at mono_interp_exec_method (http://localhost:9400/dotnet.wasm:wasm-function[256]:0x17409)
                                at interp_runtime_invoke (http://localhost:9400/dotnet.wasm:wasm-function[288]:0x1b5bd)
                                at mono_jit_runtime_invoke (http://localhost:9400/dotnet.wasm:wasm-function[15887]:0x299e5e)
                                at do_runtime_invoke (http://localhost:9400/dotnet.wasm:wasm-function[3412]:0xf5296)
                                at mono_runtime_try_invoke (http://localhost:9400/dotnet.wasm:wasm-function[3426]:0xf5fc6)",
                "objectId": "-2154664807079430451.2.463" 
                }
             }]

I run it all the night locally and couldn't reproduce it again, the test was executed 812 times.

Looking at the proxy log, console.warning: MONO_WASM: Adding an id (0) that already exists in commands_received"
message was seen it. And based on reading the code, my understanding is:

  • This is a case where a method is called, while we are already PAUSEd.

  • For example, if we are paused in a method foo.run()

    • then a breakpoint is set in foo.method(){} [1]
    • then we evaluate the expression foo.method()
    • the second breakpoint in foo.method should not cause any failures, or cause a second pause
  • The missing fix here is to set ..
    invoke_data.flags = INVOKE_FLAG_DISABLE_BREAKPOINTS;
    .. when invoking the method in the runtime.

    • this change is correct irrespective of anything else
  • A related issue is seen when we are stepping through the code (global
    stepping), and call a method while paused. The debugger agent behaves as it
    is stepping through code while running this method.

    • To fix this, we disable breakpoints, and stepping while a method a being
      invoked in the runtime.
  • Since, we failed to reproduce the original issue, the test has to depend on
    the original message seen. And test checks for the absence of this message.

  • As long as the test passes it means that the above case does not cause any
    failures

--

  1. we also test the case of the breakpoint in foo.method() being set before
    foo.run() is called at all

@ghost
Copy link

ghost commented Jan 25, 2023

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

Issue Details

Trying to fix the error on CI while running test SteppingIntoLibrarySymbolsLoadedFromSymbolServerRemoveSymbolServerAndStepAgain:

| [2023-01-25T01:48:06] DevToolsProxy-3 Debug: Error while evaluating ToString method: Microsoft.WebAssembly.Diagnostics.DebuggerAgentException: SendDebuggerAgentCommand failed for InvokeMethod: [Result: IsOk: False, IsErr: True, Value: , Error: {
 |                                                "result": {
 |                                                  "type": "object",
 |                                                  "subtype": "error",
 |                                                  "className": "RuntimeError",
 |                                                  "description": "RuntimeError: memory access out of bounds\n    at create_event_list (http://localhost:9400/dotnet.wasm:wasm-function[1360]:0x709ca)\n    at mono_dbg_create_breakpoint_events (http://localhost:9400/dotnet.wasm:wasm-function[1359]:0x70490)\n    at mono_de_process_single_step (http://localhost:9400/dotnet.wasm:wasm-function[1250]:0x6a78a)\n    at mono_wasm_single_step_hit (http://localhost:9400/dotnet.wasm:wasm-function[1194]:0x68095)\n    at do_debugger_tramp (http://localhost:9400/dotnet.wasm:wasm-function[259]:0x19dd6)\n    at mono_interp_exec_method (http://localhost:9400/dotnet.wasm:wasm-function[256]:0x17409)\n    at interp_runtime_invoke (http://localhost:9400/dotnet.wasm:wasm-function[288]:0x1b5bd)\n    at mono_jit_runtime_invoke (http://localhost:9400/dotnet.wasm:wasm-function[15887]:0x299e5e)\n    at do_runtime_invoke (http://localhost:9400/dotnet.wasm:wasm-function[3412]:0xf5296)\n    at mono_runtime_try_invoke (http://localhost:9400/dotnet.wasm:wasm-function[3426]:0xf5fc6)",
 |                                                  "objectId": "-2154664807079430451.2.463" 

I run it all the night locally and couldn't reproduce it again, the test was executed 812 times.

Author: thaystg
Assignees: -
Labels:

area-Debugger-mono

Milestone: -

@radical radical added the arch-wasm WebAssembly architecture label Jan 25, 2023
@ghost
Copy link

ghost commented Jan 25, 2023

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

Issue Details

Trying to fix the error on CI while running test SteppingIntoLibrarySymbolsLoadedFromSymbolServerRemoveSymbolServerAndStepAgain:

| [2023-01-25T01:48:06] DevToolsProxy-3 Debug: Error while evaluating ToString method: Microsoft.WebAssembly.Diagnostics.DebuggerAgentException: SendDebuggerAgentCommand failed for InvokeMethod: [Result: IsOk: False, IsErr: True, Value: , Error: {
 |                                                "result": {
 |                                                  "type": "object",
 |                                                  "subtype": "error",
 |                                                  "className": "RuntimeError",
 |                                                  "description": "RuntimeError: memory access out of bounds\n    at create_event_list (http://localhost:9400/dotnet.wasm:wasm-function[1360]:0x709ca)\n    at mono_dbg_create_breakpoint_events (http://localhost:9400/dotnet.wasm:wasm-function[1359]:0x70490)\n    at mono_de_process_single_step (http://localhost:9400/dotnet.wasm:wasm-function[1250]:0x6a78a)\n    at mono_wasm_single_step_hit (http://localhost:9400/dotnet.wasm:wasm-function[1194]:0x68095)\n    at do_debugger_tramp (http://localhost:9400/dotnet.wasm:wasm-function[259]:0x19dd6)\n    at mono_interp_exec_method (http://localhost:9400/dotnet.wasm:wasm-function[256]:0x17409)\n    at interp_runtime_invoke (http://localhost:9400/dotnet.wasm:wasm-function[288]:0x1b5bd)\n    at mono_jit_runtime_invoke (http://localhost:9400/dotnet.wasm:wasm-function[15887]:0x299e5e)\n    at do_runtime_invoke (http://localhost:9400/dotnet.wasm:wasm-function[3412]:0xf5296)\n    at mono_runtime_try_invoke (http://localhost:9400/dotnet.wasm:wasm-function[3426]:0xf5fc6)",
 |                                                  "objectId": "-2154664807079430451.2.463" 

I run it all the night locally and couldn't reproduce it again, the test was executed 812 times.

Author: thaystg
Assignees: thaystg
Labels:

arch-wasm, area-Debugger-mono

Milestone: -

@thaystg thaystg marked this pull request as ready for review January 31, 2023 16:25
@thaystg thaystg requested a review from radical as a code owner January 31, 2023 16:25
@thaystg
Copy link
Member Author

thaystg commented Jan 31, 2023

/azp run runtime-wasm-non-libtests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

public async Task WaitForWarningMessage(string message)
{
object llock = new();
var tcs = new TaskCompletionSource();
Copy link
Member

Choose a reason for hiding this comment

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

Should this method take a CancellationToken, cancel this tcs when the token is cancelled?

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'm not sure, I copied from the method that you wrote WaitForScriptParsedEventsAsync.
If you think we should please let me know and probably we should change both.

[ConditionalFact(nameof(RunningOnChrome))]
public async Task EvaluateMethodAndCheckIsNotPausingOnBreakpoint()
{
var waitForScript = WaitForWarningMessage("console.warning: MONO_WASM: Adding an id (0) that already exists in commands_received");
Copy link
Member

Choose a reason for hiding this comment

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

What does this message mean, and why are we waiting to see that we don't get it?

Copy link
Member Author

Choose a reason for hiding this comment

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

This message means that we are paused in a breakpoint and we are receiving another pause.
With the fix we don't see the message anymore.

@@ -870,5 +870,23 @@ public async Task EvaluatePropertyThatThrows()
props = await GetObjectOnFrame(frame, "this");
CheckNumber(props, "a", 11);
});

[ConditionalFact(nameof(RunningOnChrome))]
public async Task EvaluateMethodAndCheckIsNotPausingOnBreakpoint()
Copy link
Member

Choose a reason for hiding this comment

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

We should also add tests which do this but with an actual breakpoint.

void Foo()
{
   // bp here
}

void Method1()
{
	Method2();
}

void Method2()
{
	... // bp set here
}
  • set bp in Foo, and Method2
  • if we are originally stopped at bp in Foo
  • then we call Method1, we should no break again at Method2
  1. And the same thing with a property getter - explicitly invoked, bp in the getter or a method called by that getter
  2. And the same thing with a property getter - implicitly invoked because we were evaluating properties on some local var

@thaystg
Copy link
Member Author

thaystg commented Feb 1, 2023

/azp run runtime-wasm-non-libtests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@radical
Copy link
Member

radical commented Feb 1, 2023

/azp run runtime-wasm-dbgtests

@azure-pipelines
Copy link

Azure Pipelines failed to run 1 pipeline(s).

@thaystg
Copy link
Member Author

thaystg commented Feb 2, 2023

/azp run runtime-wasm-dbgtests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@thaystg
Copy link
Member Author

thaystg commented Feb 2, 2023

/azp run runtime-wasm-dbgtests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@thaystg
Copy link
Member Author

thaystg commented Feb 5, 2023

/azp run runtime-wasm-dbgtests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@thaystg
Copy link
Member Author

thaystg commented Feb 6, 2023

/azp run runtime-wasm-dbgtests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@radical radical left a comment

Choose a reason for hiding this comment

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

LGTM! And good job on tracking this one down with almost no information, or being able to reproduce it!

@thaystg
Copy link
Member Author

thaystg commented Feb 7, 2023

LGTM! And good job on tracking this one down with almost no information, or being able to reproduce it!

You helped a lot, thanks!

@thaystg thaystg merged commit e3af787 into dotnet:main Feb 7, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Mar 10, 2023
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.

4 participants