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][debugger] Fixing "Frame not in module" after vscode-js-debug changes #87979

Merged
merged 3 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/mono/wasm/debugger/BrowserDebugProxy/DevToolsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,14 +515,22 @@ public ExecutionContext GetCurrentContext(SessionId sessionId)
? context
: throw new KeyNotFoundException($"No execution context found for session {sessionId}");

public bool TryGetCurrentExecutionContextValue(SessionId id, out ExecutionContext executionContext)
public bool TryGetCurrentExecutionContextValue(SessionId id, out ExecutionContext executionContext, bool ignoreDestroyedContext = true)
{
executionContext = null;
if (!contexts.TryGetValue(id, out ConcurrentBag<ExecutionContext> contextBag))
return false;
if (contextBag.IsEmpty)
return false;
executionContext = contextBag.Where(context => context.Id == contextBag.Where(context => context.Destroyed == false).Max(context => context.Id)).FirstOrDefault();
IEnumerable<ExecutionContext> validContexts = null;
if (ignoreDestroyedContext)
validContexts = contextBag.Where(context => context.Destroyed == false);
else
validContexts = contextBag;
if (!validContexts.Any())
return false;
int maxId = validContexts.Max(context => context.Id);
executionContext = contextBag.FirstOrDefault(context => context.Id == maxId);
return executionContext != null;
}

Expand All @@ -540,7 +548,7 @@ public void OnDefaultContextUpdate(SessionId sessionId, ExecutionContext newCont

public bool TryGetAndAddContext(SessionId sessionId, ExecutionContext newExecutionContext, out ExecutionContext previousExecutionContext)
{
bool hasExisting = TryGetCurrentExecutionContextValue(sessionId, out previousExecutionContext);
bool hasExisting = TryGetCurrentExecutionContextValue(sessionId, out previousExecutionContext, ignoreDestroyedContext: false);
ConcurrentBag<ExecutionContext> bag = contexts.GetOrAdd(sessionId, _ => new ConcurrentBag<ExecutionContext>());
bag.Add(newExecutionContext);
return hasExisting;
Expand Down Expand Up @@ -569,6 +577,13 @@ public void DestroyContext(SessionId sessionId, int id)
foreach (ExecutionContext context in contextBag.Where(x => x.Id == id).ToList())
context.Destroyed = true;
}
public void ClearContexts(SessionId sessionId)
{
if (!contexts.TryGetValue(sessionId, out ConcurrentBag<ExecutionContext> contextBag))
return;
foreach (ExecutionContext context in contextBag)
context.Destroyed = true;
Comment on lines +584 to +585
Copy link
Member

Choose a reason for hiding this comment

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

We'll probably be looking at this stuff more with the mt+debugging, but it's fine for now.

}
public bool ContainsKey(SessionId sessionId) => contexts.ContainsKey(sessionId);
}
}
17 changes: 16 additions & 1 deletion src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ protected override async Task<bool> AcceptEvent(SessionId sessionId, JObject par
Contexts.DestroyContext(sessionId, args["executionContextId"].Value<int>());
return false;
}
case "Runtime.executionContextsCleared":
{
Contexts.ClearContexts(sessionId);
return false;
}

case "Debugger.paused":
{
Expand Down Expand Up @@ -1541,7 +1546,17 @@ internal virtual async Task OnSourceFileAdded(SessionId sessionId, SourceFile so
{
if (req.TryResolve(source))
{
await SetBreakpoint(sessionId, context.store, req, true, false, token);
try
{
await SetBreakpoint(sessionId, context.store, req, true, false, token);
}
catch (DebuggerAgentException e)
{
//it's not a wasm page then the command throws an error
if (!e.Message.Contains("getDotnetRuntime is not defined"))
Copy link
Member

Choose a reason for hiding this comment

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

Might be useful to add a comment next to getDotnetRuntime saying that when changing the name, instances in debugger should be changed too. And we might have this in more than one place?

logger.LogDebug($"Unexpected error on RuntimeReady {e}");
return;
}
}
}
}
Expand Down