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

[mono] Fix assertion while adding a new method using Hot Reload. #75432

Merged
merged 2 commits into from
Sep 12, 2022
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
15 changes: 7 additions & 8 deletions src/mono/mono/component/hot_reload.c
Original file line number Diff line number Diff line change
Expand Up @@ -2118,6 +2118,13 @@ apply_enclog_pass2 (Pass2Context *ctx, MonoImage *image_base, BaselineInfo *base
if (func_code == ENC_FUNC_ADD_PARAM)
break;

if (!base_info->method_table_update)
base_info->method_table_update = g_hash_table_new (g_direct_hash, g_direct_equal);
if (!delta_info->method_table_update)
delta_info->method_table_update = g_hash_table_new (g_direct_hash, g_direct_equal);
if (!delta_info->method_ppdb_table_update)
delta_info->method_ppdb_table_update = g_hash_table_new (g_direct_hash, g_direct_equal);

if (is_addition) {
g_assertf (add_member_typedef, "EnC: new method added but I don't know the class, should be caught by pass1");
if (pass2_context_is_skeleton (ctx, add_member_typedef)) {
Expand All @@ -2139,14 +2146,6 @@ apply_enclog_pass2 (Pass2Context *ctx, MonoImage *image_base, BaselineInfo *base
add_member_typedef = 0;
}

if (!base_info->method_table_update)
base_info->method_table_update = g_hash_table_new (g_direct_hash, g_direct_equal);
if (!delta_info->method_table_update)
delta_info->method_table_update = g_hash_table_new (g_direct_hash, g_direct_equal);
if (!delta_info->method_ppdb_table_update)

delta_info->method_ppdb_table_update = g_hash_table_new (g_direct_hash, g_direct_equal);

int mapped_token = hot_reload_relative_delta_index (image_dmeta, delta_info, mono_metadata_make_token (token_table, token_index));
guint32 rva = mono_metadata_decode_row_col (&image_dmeta->tables [MONO_TABLE_METHOD], mapped_token - 1, MONO_METHOD_RVA);
if (rva < dil_length) {
Expand Down
10 changes: 5 additions & 5 deletions src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ private void PopulateEnC(MetadataReader asmMetadataReaderParm, MetadataReader pd
{
var document = pdbMetadataReaderParm.GetDocument(methodDebugInformation.Document);
var documentName = pdbMetadataReaderParm.GetString(document.Name);
source = GetOrAddSourceFile(methodDebugInformation.Document, asmMetadataReaderParm.GetRowNumber(methodDebugInformation.Document), documentName);
source = GetOrAddSourceFile(methodDebugInformation.Document, documentName);
}
var methodInfo = new MethodInfo(this, MetadataTokens.MethodDefinitionHandle(methodIdxAsm), entryRow, source, typeInfo, asmMetadataReaderParm, pdbMetadataReaderParm);
methods[entryRow] = methodInfo;
Expand All @@ -1018,13 +1018,13 @@ private void PopulateEnC(MetadataReader asmMetadataReaderParm, MetadataReader pd
}
}
}
private SourceFile GetOrAddSourceFile(DocumentHandle doc, int rowid, string documentName)
private SourceFile GetOrAddSourceFile(DocumentHandle doc, string documentName)
{
if (_documentIdToSourceFileTable.TryGetValue(rowid, out SourceFile source))
if (_documentIdToSourceFileTable.TryGetValue(documentName.GetHashCode(), out SourceFile source))
return source;

var src = new SourceFile(this, _documentIdToSourceFileTable.Count, doc, GetSourceLinkUrl(documentName), documentName);
_documentIdToSourceFileTable[rowid] = src;
_documentIdToSourceFileTable[documentName.GetHashCode()] = src;
return src;
}

Expand Down Expand Up @@ -1054,7 +1054,7 @@ private void Populate()
{
var document = pdbMetadataReader.GetDocument(methodDebugInformation.Document);
var documentName = pdbMetadataReader.GetString(document.Name);
source = GetOrAddSourceFile(methodDebugInformation.Document, asmMetadataReader.GetRowNumber(methodDebugInformation.Document), documentName);
source = GetOrAddSourceFile(methodDebugInformation.Document, documentName);
}
}
var methodInfo = new MethodInfo(this, method, asmMetadataReader.GetRowNumber(method), source, typeInfo, asmMetadataReader, pdbMetadataReader);
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ private async Task<bool> SendBreakpointsOfMethodUpdated(SessionId sessionId, Exe
{
var methodId = retDebuggerCmdReader.ReadInt32();
var method = await context.SdbAgent.GetMethodInfo(methodId, token);
if (method == null)
if (method == null || method.Info.Source is null)
{
return true;
}
Expand Down
15 changes: 10 additions & 5 deletions src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ internal async Task<JObject> LoadAssemblyDynamicallyALCAndRunMethod(string asm_f
return await WaitFor(Inspector.PAUSE);
}

internal async Task<JObject> LoadAssemblyAndTestHotReloadUsingSDBWithoutChanges(string asm_file, string pdb_file, string class_name, string method_name, bool expectBpResolvedEvent)
internal async Task<JObject> LoadAssemblyAndTestHotReloadUsingSDBWithoutChanges(string asm_file, string pdb_file, string class_name, string method_name, bool expectBpResolvedEvent, params string[] sourcesToWait)
{
byte[] bytes = File.ReadAllBytes(asm_file);
string asm_base64 = Convert.ToBase64String(bytes);
Expand All @@ -1338,7 +1338,7 @@ internal async Task<JObject> LoadAssemblyAndTestHotReloadUsingSDBWithoutChanges(

Task eventTask = expectBpResolvedEvent
? WaitForBreakpointResolvedEvent()
: WaitForScriptParsedEventsAsync("MethodBody0.cs", "MethodBody1.cs");
: WaitForScriptParsedEventsAsync(sourcesToWait);
(await cli.SendCommand("Runtime.evaluate", load_assemblies, token)).AssertOk();
await eventTask;

Expand Down Expand Up @@ -1397,7 +1397,7 @@ internal async Task<JObject> LoadAssemblyAndTestHotReloadUsingSDB(string asm_fil
return await WaitFor(Inspector.PAUSE);
}

internal async Task<JObject> LoadAssemblyAndTestHotReload(string asm_file, string pdb_file, string asm_file_hot_reload, string class_name, string method_name, bool expectBpResolvedEvent)
internal async Task<JObject> LoadAssemblyAndTestHotReload(string asm_file, string pdb_file, string asm_file_hot_reload, string class_name, string method_name, bool expectBpResolvedEvent, string[] sourcesToWait, string methodName2 = "", string methodName3 = "")
{
byte[] bytes = File.ReadAllBytes(asm_file);
string asm_base64 = Convert.ToBase64String(bytes);
Expand Down Expand Up @@ -1434,13 +1434,18 @@ internal async Task<JObject> LoadAssemblyAndTestHotReload(string asm_file, strin

Task eventTask = expectBpResolvedEvent
? WaitForBreakpointResolvedEvent()
: WaitForScriptParsedEventsAsync("MethodBody0.cs", "MethodBody1.cs");
: WaitForScriptParsedEventsAsync(sourcesToWait);
(await cli.SendCommand("Runtime.evaluate", load_assemblies, token)).AssertOk();
await eventTask;

if (methodName2 == "")
methodName2 = method_name;
if (methodName3 == "")
methodName3 = method_name;

var run_method = JObject.FromObject(new
{
expression = "window.setTimeout(function() { invoke_static_method('[debugger-test] TestHotReload:RunMethod', '" + class_name + "', '" + method_name + "'); }, 1);"
expression = "window.setTimeout(function() { invoke_static_method('[debugger-test] TestHotReload:RunMethod', '" + class_name + "', '" + method_name + "', '" + methodName2 + "', '" + methodName3 + "'); }, 1);"
});

await cli.SendCommand("Runtime.evaluate", run_method, token);
Expand Down
Loading