Skip to content

Commit c623d96

Browse files
github-actions[bot]thaystgradical
authored
[release/7.0] [wasm][debugger] fixing setting a breakpoint in an invalid IL offset after hotreload (#75564)
* fixing setting a breakpoint in an invalid IL offset * addressing @radical comments * Update src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs Co-authored-by: Ankit Jain <[email protected]> * Update src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs Co-authored-by: Ankit Jain <[email protected]> * addressing @radical comments * addressing @radical comments Co-authored-by: Thays Grazia <[email protected]> Co-authored-by: Ankit Jain <[email protected]>
1 parent 6297d41 commit c623d96

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -361,37 +361,44 @@ protected override async Task<bool> AcceptCommand(MessageId id, JObject parms, C
361361
SendResponse(id, resp, token);
362362
return true;
363363
}
364+
try
365+
{
366+
string bpid = resp.Value["breakpointId"]?.ToString();
367+
IEnumerable<object> locations = resp.Value["locations"]?.Values<object>();
368+
var request = BreakpointRequest.Parse(bpid, args);
364369

365-
string bpid = resp.Value["breakpointId"]?.ToString();
366-
IEnumerable<object> locations = resp.Value["locations"]?.Values<object>();
367-
var request = BreakpointRequest.Parse(bpid, args);
370+
// is the store done loading?
371+
bool loaded = context.Source.Task.IsCompleted;
372+
if (!loaded)
373+
{
374+
// Send and empty response immediately if not
375+
// and register the breakpoint for resolution
376+
context.BreakpointRequests[bpid] = request;
377+
SendResponse(id, resp, token);
378+
}
368379

369-
// is the store done loading?
370-
bool loaded = context.Source.Task.IsCompleted;
371-
if (!loaded)
372-
{
373-
// Send and empty response immediately if not
374-
// and register the breakpoint for resolution
375-
context.BreakpointRequests[bpid] = request;
376-
SendResponse(id, resp, token);
377-
}
380+
if (await IsRuntimeAlreadyReadyAlready(id, token))
381+
{
382+
DebugStore store = await RuntimeReady(id, token);
378383

379-
if (await IsRuntimeAlreadyReadyAlready(id, token))
380-
{
381-
DebugStore store = await RuntimeReady(id, token);
384+
Log("verbose", $"BP req {args}");
385+
await SetBreakpoint(id, store, request, !loaded, false, token);
386+
}
382387

383-
Log("verbose", $"BP req {args}");
384-
await SetBreakpoint(id, store, request, !loaded, false, token);
385-
}
388+
if (loaded)
389+
{
390+
// we were already loaded so we should send a response
391+
// with the locations included and register the request
392+
context.BreakpointRequests[bpid] = request;
393+
var result = Result.OkFromObject(request.AsSetBreakpointByUrlResponse(locations));
394+
SendResponse(id, result, token);
386395

387-
if (loaded)
396+
}
397+
}
398+
catch (Exception e)
388399
{
389-
// we were already loaded so we should send a response
390-
// with the locations included and register the request
391-
context.BreakpointRequests[bpid] = request;
392-
var result = Result.OkFromObject(request.AsSetBreakpointByUrlResponse(locations));
393-
SendResponse(id, result, token);
394-
400+
logger.LogDebug($"Debugger.setBreakpointByUrl - {args} - failed with exception: {e}");
401+
SendResponse(id, Result.Err($"Debugger.setBreakpointByUrl - {args} - failed with exception: {e}"), token);
395402
}
396403
return true;
397404
}
@@ -1449,7 +1456,8 @@ private async Task<Breakpoint> SetMonoBreakpoint(SessionId sessionId, string req
14491456

14501457
var assembly_id = await context.SdbAgent.GetAssemblyId(asm_name, token);
14511458
var methodId = await context.SdbAgent.GetMethodIdByToken(assembly_id, method_token, token);
1452-
var breakpoint_id = await context.SdbAgent.SetBreakpoint(methodId, il_offset, token);
1459+
//the breakpoint can be invalid because a race condition between the changes already applied on runtime and not applied yet on debugger side
1460+
var breakpoint_id = await context.SdbAgent.SetBreakpointNoThrow(methodId, il_offset, token);
14531461

14541462
if (breakpoint_id > 0)
14551463
{
@@ -1726,7 +1734,10 @@ private async Task<bool> OnSetNextIP(MessageId sessionId, SourceLocation targetL
17261734
if (!ret)
17271735
return false;
17281736

1729-
var breakpointId = await context.SdbAgent.SetBreakpoint(scope.Method.DebugId, ilOffset.Offset, token);
1737+
var breakpointId = await context.SdbAgent.SetBreakpointNoThrow(scope.Method.DebugId, ilOffset.Offset, token);
1738+
if (breakpointId == -1)
1739+
return false;
1740+
17301741
context.TempBreakpointForSetNextIP = breakpointId;
17311742
await SendResume(sessionId, token);
17321743
return true;

src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ public async Task<string> GetParameters(int methodId, CancellationToken token)
13561356
return parameters;
13571357
}
13581358

1359-
public async Task<int> SetBreakpoint(int methodId, long il_offset, CancellationToken token)
1359+
public async Task<int> SetBreakpointNoThrow(int methodId, long il_offset, CancellationToken token)
13601360
{
13611361
using var commandParamsWriter = new MonoBinaryWriter();
13621362
commandParamsWriter.Write((byte)EventKind.Breakpoint);
@@ -1365,7 +1365,9 @@ public async Task<int> SetBreakpoint(int methodId, long il_offset, CancellationT
13651365
commandParamsWriter.Write((byte)ModifierKind.LocationOnly);
13661366
commandParamsWriter.Write(methodId);
13671367
commandParamsWriter.Write(il_offset);
1368-
using var retDebuggerCmdReader = await SendDebuggerAgentCommand(CmdEventRequest.Set, commandParamsWriter, token);
1368+
using var retDebuggerCmdReader = await SendDebuggerAgentCommand(CmdEventRequest.Set, commandParamsWriter, token, throwOnError: false);
1369+
if (retDebuggerCmdReader.HasError)
1370+
return -1;
13691371
return retDebuggerCmdReader.ReadInt32();
13701372
}
13711373

0 commit comments

Comments
 (0)