Skip to content

Commit

Permalink
Improve error reporting when reading bad metadata during EnC
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Sep 30, 2024
1 parent f4f21cb commit 2825b44
Show file tree
Hide file tree
Showing 32 changed files with 127 additions and 105 deletions.
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -5876,7 +5876,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<value>Local function '{0}' must declare a body because it is not marked 'static extern'.</value>
</data>
<data name="ERR_InvalidDebugInfo" xml:space="preserve">
<value>Unable to read debug information of method '{0}' (token 0x{1:X8}) from assembly '{2}'</value>
<value>Unable to read debug information of method '{0}' (token 0x{1:X8}) from assembly '{2}': {3}</value>
</data>
<data name="IConversionExpressionIsNotCSharpConversion" xml:space="preserve">
<value>{0} is not a valid C# conversion expression</value>
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12760,52 +12760,35 @@ public void ManyGenerations()
}
}

[Theory]
[InlineData(typeof(IOException))]
[InlineData(typeof(BadImageFormatException))]
[InlineData(typeof(InvalidDataException))]
[WorkItem(187868, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/187868")]
[Fact]
public void PdbReadingErrors()
public void SymReaderErrors(Type exceptionType)
{
var source0 = MarkedSource(@"
using System;

class C
{
static void F()
{
<N:0>Console.WriteLine(1);</N:0>
}
}");

var source1 = MarkedSource(@"
using System;

class C
{
static void F()
{
<N:0>Console.WriteLine(2);</N:0>
}
}");
var compilation0 = CreateCompilation(source0.Tree, options: TestOptions.DebugDll, assemblyName: "PdbReadingErrorsAssembly");
var compilation1 = compilation0.WithSource(source1.Tree);

var v0 = CompileAndVerify(compilation0);
var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData);

var f0 = compilation0.GetMember<MethodSymbol>("C.F");
var f1 = compilation1.GetMember<MethodSymbol>("C.F");

var generation0 = CreateInitialBaseline(compilation0, md0, methodHandle =>
{
throw new InvalidDataException("Bad PDB!");
});

var diff1 = compilation1.EmitDifference(
generation0,
ImmutableArray.Create(SemanticEdit.Create(SemanticEditKind.Update, f0, f1, GetSyntaxMapFromMarkers(source0, source1))));

diff1.EmitResult.Diagnostics.Verify(
// (6,14): error CS7038: Failed to emit module 'Unable to read debug information of method 'C.F()' (token 0x06000001) from assembly 'PdbReadingErrorsAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null''.
Diagnostic(ErrorCode.ERR_InvalidDebugInfo, "F").WithArguments("C.F()", "100663297", "PdbReadingErrorsAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").WithLocation(6, 14));
using var _ = new EditAndContinueTest(assemblyName: "test")
.AddBaseline(
"""
class C { void F() { int x = 1; } }
""",
debugInformationProvider: _ => throw (Exception)Activator.CreateInstance(exceptionType, ["bug!"]))
.AddGeneration(
// 1
"""
class C { void F() { int x = 2; } }
""",
edits:
[
Edit(SemanticEditKind.Update, c => c.GetMember("C.F"), preserveLocalVariables: true)
],
expectedErrors:
[
// (1,16): error CS7103: Unable to read debug information of method 'C.F()' (token 0x06000001) from assembly 'test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null': bug!
// class C { void F() { int x = 2; } }
Diagnostic(ErrorCode.ERR_InvalidDebugInfo, "F").WithArguments("C.F()", "100663297", "test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "bug!").WithLocation(1, 16)
])
.Verify();
}

[Fact]
Expand Down Expand Up @@ -12846,7 +12829,7 @@ static void F()
throw new ArgumentOutOfRangeException();
});

// the compiler should't swallow any exceptions but InvalidDataException
// the compiler should't swallow any exceptions but InvalidDataException, IOException and BadImageFormatException
Assert.Throws<ArgumentOutOfRangeException>(() =>
compilation1.EmitDifference(
generation0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,15 @@ protected abstract void GetStateMachineFieldMapFromMetadata(
debugInfo = Baseline.DebugInformationProvider(methodHandle);
localSignature = Baseline.LocalSignatureProvider(methodHandle);
}
catch (Exception e) when (e is InvalidDataException or IOException)
catch (Exception e) when (e is InvalidDataException or IOException or BadImageFormatException)
{
diagnostics.Add(MessageProvider.CreateDiagnostic(
MessageProvider.ERR_InvalidDebugInfo,
method.Locations.First(),
method,
MetadataTokens.GetToken(methodHandle),
method.ContainingAssembly
method.ContainingAssembly,
e.Message
));

return null;
Expand Down Expand Up @@ -382,7 +383,8 @@ protected abstract void GetStateMachineFieldMapFromMetadata(
method.Locations.First(),
method,
MetadataTokens.GetToken(localSignature),
method.ContainingAssembly
method.ContainingAssembly,
e.Message
));

return null;
Expand Down Expand Up @@ -690,7 +692,7 @@ static ImmutableArray<string> getHoistedVariableNames(ImmutableArray<ISymbolInte
{
provider = Baseline.DebugInformationProvider(MetadataTokens.MethodDefinitionHandle(methodRowId));
}
catch (Exception e) when (e is InvalidDataException or IOException)
catch (Exception e) when (e is InvalidDataException or IOException or BadImageFormatException)
{
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/VisualBasic/Portable/VBResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -5541,7 +5541,7 @@
<value>Type is for evaluation purposes only and is subject to change or removal in future updates.</value>
</data>
<data name="ERR_InvalidDebugInfo" xml:space="preserve">
<value>Unable to read debug information of method '{0}' (token 0x{1}) from assembly '{2}'</value>
<value>Unable to read debug information of method '{0}' (token 0x{1:X8}) from assembly '{2}': {3}</value>
</data>
<data name="IConversionExpressionIsNotVisualBasicConversion" xml:space="preserve">
<value>{0} is not a valid Visual Basic conversion expression</value>
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/VisualBasic/Portable/xlf/VBResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/VisualBasic/Portable/xlf/VBResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/VisualBasic/Portable/xlf/VBResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/VisualBasic/Portable/xlf/VBResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2825b44

Please sign in to comment.