mirror of https://github.com/icsharpcode/ILSpy.git
10 changed files with 136 additions and 73 deletions
@ -1,55 +0,0 @@ |
|||||||
using System; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.IO; |
|
||||||
using System.Linq; |
|
||||||
using ICSharpCode.Decompiler.CSharp.OutputVisitor; |
|
||||||
using ICSharpCode.Decompiler.Tests.Helpers; |
|
||||||
using ICSharpCode.Decompiler.TypeSystem; |
|
||||||
using NUnit.Framework; |
|
||||||
|
|
||||||
namespace ICSharpCode.Decompiler.Tests.Util |
|
||||||
{ |
|
||||||
[TestFixture] |
|
||||||
public class SequencePointTests |
|
||||||
{ |
|
||||||
[Test] |
|
||||||
public void BasicSequencePoints() |
|
||||||
{ |
|
||||||
TestCreateSequencePoints(@"class C { void M() { int i = 0; int j = 1; } }", |
|
||||||
"int num = 0;", |
|
||||||
"int num2 = 1;"); |
|
||||||
} |
|
||||||
|
|
||||||
private void TestCreateSequencePoints(string code, params string[] expectedSequencePoints) |
|
||||||
{ |
|
||||||
var decompiler = Tester.GetDecompilerForSnippet(code); |
|
||||||
|
|
||||||
var tree = decompiler.DecompileType(new FullTypeName("C")); |
|
||||||
|
|
||||||
var output = new StringWriter(); |
|
||||||
tree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); |
|
||||||
TokenWriter tokenWriter = new TextWriterTokenWriter(output); |
|
||||||
tokenWriter = new InsertMissingTokensDecorator(tokenWriter, (ILocatable)tokenWriter); |
|
||||||
var formattingOptions = FormattingOptionsFactory.CreateSharpDevelop(); |
|
||||||
tree.AcceptVisitor(new CSharpOutputVisitor(tokenWriter, formattingOptions)); |
|
||||||
|
|
||||||
var functionsWithSequencePoints = decompiler.CreateSequencePoints(tree); |
|
||||||
var finalText = output.ToString(); |
|
||||||
|
|
||||||
var lines = finalText.Split(new[] { output.NewLine }, StringSplitOptions.None); |
|
||||||
|
|
||||||
var actualSequencePoints = new List<string>(); |
|
||||||
foreach (var sequencePoint in functionsWithSequencePoints.Values.First()) { |
|
||||||
if (sequencePoint.IsHidden) { |
|
||||||
continue; |
|
||||||
} |
|
||||||
|
|
||||||
var line = lines[sequencePoint.StartLine - 1]; |
|
||||||
var text = line.Substring(sequencePoint.StartColumn - 1, sequencePoint.EndColumn - sequencePoint.StartColumn); |
|
||||||
actualSequencePoints.Add(text); |
|
||||||
} |
|
||||||
|
|
||||||
Assert.True(Enumerable.SequenceEqual(expectedSequencePoints, actualSequencePoints)); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,54 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.IO; |
||||||
|
using System.Linq; |
||||||
|
using System.Reflection.PortableExecutable; |
||||||
|
using System.Runtime.CompilerServices; |
||||||
|
using System.Xml.Linq; |
||||||
|
using ICSharpCode.Decompiler.CSharp; |
||||||
|
using ICSharpCode.Decompiler.CSharp.OutputVisitor; |
||||||
|
using ICSharpCode.Decompiler.DebugInfo; |
||||||
|
using ICSharpCode.Decompiler.Metadata; |
||||||
|
using ICSharpCode.Decompiler.Tests.Helpers; |
||||||
|
using ICSharpCode.Decompiler.TypeSystem; |
||||||
|
using Microsoft.CodeAnalysis.CSharp; |
||||||
|
using Microsoft.DiaSymReader.Tools; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace ICSharpCode.Decompiler.Tests |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class PdbGenerationTestRunner |
||||||
|
{ |
||||||
|
static readonly string TestCasePath = Tester.TestCasePath + "/PdbGen"; |
||||||
|
|
||||||
|
[Test, Ignore("Needs adjustments in generator")] |
||||||
|
public void HelloWorld() |
||||||
|
{ |
||||||
|
TestGeneratePdb(); |
||||||
|
} |
||||||
|
|
||||||
|
private void TestGeneratePdb([CallerMemberName] string testName = null) |
||||||
|
{ |
||||||
|
const PdbToXmlOptions options = PdbToXmlOptions.IncludeEmbeddedSources | PdbToXmlOptions.ThrowOnError | PdbToXmlOptions.IncludeTokens | PdbToXmlOptions.ResolveTokens | PdbToXmlOptions.IncludeMethodSpans; |
||||||
|
|
||||||
|
string xmlFile = Path.Combine(TestCasePath, testName + ".xml"); |
||||||
|
string xmlContent = File.ReadAllText(xmlFile); |
||||||
|
XDocument document = XDocument.Parse(xmlContent); |
||||||
|
var files = document.Descendants("file").ToDictionary(f => f.Attribute("name").Value, f => f.Value); |
||||||
|
Tester.CompileCSharpWithPdb(Path.Combine(TestCasePath, testName + ".expected"), files, options); |
||||||
|
|
||||||
|
string peFileName = Path.Combine(TestCasePath, testName + ".expected.dll"); |
||||||
|
string pdbFileName = Path.Combine(TestCasePath, testName + ".expected.pdb"); |
||||||
|
var moduleDefinition = new PEFile(peFileName); |
||||||
|
var resolver = new UniversalAssemblyResolver(peFileName, false, moduleDefinition.Reader.DetectTargetFrameworkId(), PEStreamOptions.PrefetchEntireImage); |
||||||
|
var decompiler = new CSharpDecompiler(moduleDefinition, resolver, new DecompilerSettings()); |
||||||
|
using (FileStream pdbStream = File.Open(Path.Combine(TestCasePath, testName + ".pdb"), FileMode.OpenOrCreate, FileAccess.ReadWrite)) { |
||||||
|
PortablePdbWriter.WritePdb(moduleDefinition, decompiler, new DecompilerSettings(), pdbStream); |
||||||
|
pdbStream.Position = 0; |
||||||
|
string resultFile = PdbToXmlConverter.ToXml(pdbStream, moduleDefinition.Reader.GetEntireImage().GetContent().ToArray(), options); |
||||||
|
Assert.AreEqual(xmlContent, resultFile); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,2 @@ |
|||||||
|
/*.dll |
||||||
|
/*.pdb |
@ -0,0 +1,33 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-16"?> |
||||||
|
<symbols> |
||||||
|
<files> |
||||||
|
<file id="1" name="HelloWorld.cs" language="C#" checksumAlgorithm="SHA1" checksum="80-99-0D-B3-EA-B0-A3-72-39-A0-C5-FB-17-13-1B-CC-BF-3D-4C-AA" embeddedSourceLength="200"><![CDATA[using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.Decompiler.Tests.TestCases.PdbGen |
||||||
|
{ |
||||||
|
public class HelloWorld |
||||||
|
{ |
||||||
|
public static void Hello() |
||||||
|
{ |
||||||
|
Console.WriteLine("Hello World!"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
]]></file> |
||||||
|
</files> |
||||||
|
<methods> |
||||||
|
<method containingType="ICSharpCode.Decompiler.Tests.TestCases.PdbGen.HelloWorld" name="Hello" token="0x6000001"> |
||||||
|
<sequencePoints> |
||||||
|
<entry offset="0x0" startLine="8" startColumn="3" endLine="8" endColumn="4" document="1" /> |
||||||
|
<entry offset="0x1" startLine="9" startColumn="4" endLine="9" endColumn="38" document="1" /> |
||||||
|
<entry offset="0xc" startLine="10" startColumn="3" endLine="10" endColumn="4" document="1" /> |
||||||
|
</sequencePoints> |
||||||
|
<scope startOffset="0x0" endOffset="0xd" /> |
||||||
|
</method> |
||||||
|
</methods> |
||||||
|
<method-spans> |
||||||
|
<method declaringType="ICSharpCode.Decompiler.Tests.TestCases.PdbGen.HelloWorld" methodName="Hello" token="0x6000001"> |
||||||
|
<document startLine="8" endLine="10" /> |
||||||
|
</method> |
||||||
|
</method-spans> |
||||||
|
</symbols> |
Loading…
Reference in new issue