Browse Source

Fix #1344: Fix GetCodeMappingInfo for nested async FSMs

pull/1360/head
Siegfried Pammer 7 years ago
parent
commit
00a54a278a
  1. 8
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 4
      ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs

8
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -526,7 +526,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (!processedMethods.Add(part)) if (!processedMethods.Add(part))
continue; continue;
try { try {
ReadCodeMappingInfo(module, declaringType, info, parent, part, connectedMethods, processedNestedTypes); ReadCodeMappingInfo(module, info, parent, part, connectedMethods, processedNestedTypes);
} catch (BadImageFormatException) { } catch (BadImageFormatException) {
// ignore invalid IL // ignore invalid IL
} }
@ -536,14 +536,16 @@ namespace ICSharpCode.Decompiler.CSharp
return info; return info;
} }
private static void ReadCodeMappingInfo(PEFile module, TypeDefinitionHandle declaringType, CodeMappingInfo info, MethodDefinitionHandle parent, MethodDefinitionHandle part, Queue<MethodDefinitionHandle> connectedMethods, HashSet<TypeDefinitionHandle> processedNestedTypes) private static void ReadCodeMappingInfo(PEFile module, CodeMappingInfo info, MethodDefinitionHandle parent, MethodDefinitionHandle part, Queue<MethodDefinitionHandle> connectedMethods, HashSet<TypeDefinitionHandle> processedNestedTypes)
{ {
var md = module.Metadata.GetMethodDefinition(part); var md = module.Metadata.GetMethodDefinition(part);
if (!md.HasBody()) { if (!md.HasBody()) {
info.AddMapping(parent, part); info.AddMapping(parent, part);
return; return;
} }
var declaringType = md.GetDeclaringType();
var blob = module.Reader.GetMethodBody(md.RelativeVirtualAddress).GetILReader(); var blob = module.Reader.GetMethodBody(md.RelativeVirtualAddress).GetILReader();
while (blob.RemainingBytes > 0) { while (blob.RemainingBytes > 0) {

4
ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs

@ -36,7 +36,9 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
public static bool IsCompilerGeneratedStateMachine(TypeDefinitionHandle type, MetadataReader metadata) public static bool IsCompilerGeneratedStateMachine(TypeDefinitionHandle type, MetadataReader metadata)
{ {
TypeDefinition td; TypeDefinition td;
if (type.IsNil || !type.IsCompilerGenerated(metadata) || (td = metadata.GetTypeDefinition(type)).GetDeclaringType().IsNil) if (type.IsNil || (td = metadata.GetTypeDefinition(type)).GetDeclaringType().IsNil)
return false;
if (!(type.IsCompilerGenerated(metadata) || td.GetDeclaringType().IsCompilerGenerated(metadata)))
return false; return false;
foreach (var i in td.GetInterfaceImplementations()) { foreach (var i in td.GetInterfaceImplementations()) {
var tr = metadata.GetInterfaceImplementation(i).Interface.GetFullTypeName(metadata); var tr = metadata.GetInterfaceImplementation(i).Interface.GetFullTypeName(metadata);

Loading…
Cancel
Save