internal string VisualizeIL(CompilationTestData.MethodData methodData, bool realIL, string sequencePoints = null, string source = null) { Dictionary <int, string> markers = null; if (sequencePoints != null) { var actualPdbXml = PdbToXmlConverter.ToXml( pdbStream: new MemoryStream(EmittedAssemblyPdb.ToArray()), peStream: new MemoryStream(EmittedAssemblyData.ToArray()), options: PdbToXmlOptions.ResolveTokens | PdbToXmlOptions.ThrowOnError | PdbToXmlOptions.ExcludeDocuments | PdbToXmlOptions.ExcludeCustomDebugInformation | PdbToXmlOptions.ExcludeScopes, methodName: sequencePoints); markers = ILValidation.GetSequencePointMarkers(actualPdbXml, source); } if (!realIL) { return(ILBuilderVisualizer.ILBuilderToString(methodData.ILBuilder, markers: markers)); } if (_lazyModuleSymbol == null) { var targetReference = LoadTestEmittedExecutableForSymbolValidation(EmittedAssemblyData, _compilation.Options.OutputKind, display: _compilation.AssemblyName); _lazyModuleSymbol = GetSymbolFromMetadata(targetReference, MetadataImportOptions.All); } return(_lazyModuleSymbol != null?_visualizeRealIL(_lazyModuleSymbol, methodData, markers) : null); }
internal string VisualizeIL(CompilationTestData.MethodData methodData, bool realIL, string sequencePoints = null, string source = null) { Dictionary <int, string> markers = null; if (sequencePoints != null) { if (EmittedAssemblyPdb == null) { throw new InvalidOperationException($"{nameof(EmittedAssemblyPdb)} is not set"); } if (EmittedAssemblyData == null) { throw new InvalidOperationException($"{nameof(EmittedAssemblyData)} is not set"); } var actualPdbXml = PdbToXmlConverter.ToXml( pdbStream: new MemoryStream(EmittedAssemblyPdb.ToArray()), peStream: new MemoryStream(EmittedAssemblyData.ToArray()), options: PdbToXmlOptions.ResolveTokens | PdbToXmlOptions.ThrowOnError | PdbToXmlOptions.ExcludeDocuments | PdbToXmlOptions.ExcludeCustomDebugInformation | PdbToXmlOptions.ExcludeScopes, methodName: sequencePoints); if (actualPdbXml.StartsWith("<error>")) { throw new Exception($"Failed to extract PDB information for method '{sequencePoints}'. PdbToXmlConverter returned:\r\n{actualPdbXml}"); } markers = ILValidation.GetSequencePointMarkers(actualPdbXml, source); } if (!realIL) { return(ILBuilderVisualizer.ILBuilderToString(methodData.ILBuilder, markers: markers)); } if (_lazyModuleSymbol == null) { var targetReference = LoadTestEmittedExecutableForSymbolValidation(EmittedAssemblyData, _compilation.Options.OutputKind, display: _compilation.AssemblyName); _lazyModuleSymbol = GetSymbolFromMetadata(targetReference, MetadataImportOptions.All); } if (_lazyModuleSymbol != null) { if (_visualizeRealIL == null) { throw new InvalidOperationException("IL visualization function is not set"); } return(_visualizeRealIL(_lazyModuleSymbol, methodData, markers, _testData.Module.GetMethodBody(methodData.Method).AreLocalsZeroed)); } return(null); }
internal void VerifyIL( string qualifiedMethodName, string expectedIL, Func <Cci.ILocalDefinition, ILVisualizer.LocalInfo> mapLocal = null, MethodDefinitionHandle methodToken = default, [CallerFilePath] string callerPath = null, [CallerLineNumber] int callerLine = 0 ) { var ilBuilder = TestData.GetMethodData(qualifiedMethodName).ILBuilder; Dictionary <int, string> sequencePointMarkers = null; if (!methodToken.IsNil) { string actualPdb = PdbToXmlConverter.DeltaPdbToXml( new ImmutableMemoryStream(PdbDelta), new[] { MetadataTokens.GetToken(methodToken) } ); sequencePointMarkers = ILValidation.GetSequencePointMarkers(actualPdb); Assert.True( sequencePointMarkers.Count > 0, $"No sequence points found in:{Environment.NewLine}{actualPdb}" ); } string actualIL = ILBuilderVisualizer.ILBuilderToString( ilBuilder, mapLocal ?? ToLocalInfo, sequencePointMarkers ); AssertEx.AssertEqualToleratingWhitespaceDifferences( expectedIL, actualIL, escapeQuotes: true, expectedValueSourcePath: callerPath, expectedValueSourceLine: callerLine ); }