Browse Source

ILSpyAddIn can be a symbol source for the debugger

pull/32/merge
David Srbecký 13 years ago
parent
commit
01ec356fa1
  1. 4
      src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.addin
  2. 1
      src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.csproj
  3. 106
      src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs

4
src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.addin

@ -12,6 +12,10 @@ @@ -12,6 +12,10 @@
<Import assembly = "ILSpyAddIn.dll"/>
</Runtime>
<Path name="/SharpDevelop/Services/DebuggerService/SymbolSource">
<Class id="ILSpy" class="ICSharpCode.ILSpyAddIn.ILSpySymbolSource"/>
</Path>
<Path name="/SharpDevelop/Services/NavigateToEntityService">
<Class id="ILSpy" class="ICSharpCode.ILSpyAddIn.NavigateToDecompiledEntityService"/>
</Path>

1
src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.csproj

@ -66,6 +66,7 @@ @@ -66,6 +66,7 @@
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="DebuggerTextOutput.cs" />
<Compile Include="ILSpySymbolSource.cs" />
<Compile Include="LaunchILSpy\ILSpyAssemblyResolver.cs" />
<Compile Include="NavigateToDecompiledEntityService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

106
src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs

@ -0,0 +1,106 @@ @@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Debugger;
using ICSharpCode.Core;
using ICSharpCode.Decompiler;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.Documentation;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.ILSpyAddIn
{
public class ILSpySymbolSource : ISymbolSource
{
public static MethodDebugSymbols GetSymbols(IMethod method)
{
var id = IdStringProvider.GetIdString(method);
var content = DecompiledViewContent.Get(method);
if (content != null && content.DebugSymbols.ContainsKey(id)) {
return content.DebugSymbols[id];
}
return null;
}
public Debugger.SequencePoint GetSequencePoint(IMethod method, int iloffset)
{
var symbols = GetSymbols(method);
if (symbols == null)
return null;
var content = DecompiledViewContent.Get(method);
var seq = symbols.SequencePoints.FirstOrDefault(p => p.ILRanges.Any(r => r.From <= iloffset && iloffset < r.To));
return seq.ToDebugger(symbols, content.VirtualFileName);
}
public Debugger.SequencePoint GetSequencePoint(Module module, string filename, int line, int column)
{
var content = DecompiledViewContent.Get(new FileName(filename));
if (content == null)
return null;
if (!FileUtility.IsEqualFileName(module.FullPath, content.AssemblyFile))
return null;
TextLocation loc = new TextLocation(line, column);
foreach(var symbols in content.DebugSymbols.Values.Where(s => s.StartLocation <= loc && loc <= s.EndLocation)) {
Decompiler.SequencePoint seq = null;
if (column != 0)
seq = symbols.SequencePoints.FirstOrDefault(p => p.StartLocation <= loc && loc <= p.EndLocation);
if (seq == null)
seq = symbols.SequencePoints.FirstOrDefault(p => line <= p.StartLocation.Line);
if (seq != null)
return seq.ToDebugger(symbols, content.VirtualFileName);
}
return null;
}
public bool HasSymbols(IMethod method)
{
var symbols = GetSymbols(method);
return symbols != null && symbols.SequencePoints.Any();
}
public IEnumerable<ILRange> GetIgnoredILRanges(IMethod method)
{
var symbols = GetSymbols(method);
if (symbols == null)
return new ILRange[] { };
int codesize = symbols.CecilMethod.Body.CodeSize;
var inv = ICSharpCode.Decompiler.ILAst.ILRange.Invert(symbols.SequencePoints.SelectMany(s => s.ILRanges), codesize);
return inv.Select(r => new ILRange(r.From, r.To));
}
public IEnumerable<ILLocalVariable> GetLocalVariables(IMethod method)
{
var symbols = GetSymbols(method);
if (symbols == null)
return null;
return symbols.LocalVariables.Select(v => new Debugger.ILLocalVariable() {
Index = v.OriginalVariable.Index,
Type = method.Compilation.FindType(KnownTypeCode.Object), // TODO
Name = v.Name,
IsCompilerGenerated = false,
ILRanges = new [] { new Debugger.ILRange(0, int.MaxValue) }
});
}
}
static class ILSpySymbolSourceExtensions
{
public static Debugger.SequencePoint ToDebugger(this ICSharpCode.Decompiler.SequencePoint seq, ICSharpCode.Decompiler.MethodDebugSymbols symbols, string filename)
{
return new Debugger.SequencePoint() {
MethodDefToken = symbols.CecilMethod.MetadataToken.ToUInt32(),
ILRanges = seq.ILRanges.Select(r => new ILRange(r.From, r.To)).ToArray(),
Filename = filename,
StartLine = seq.StartLocation.Line,
StartColumn = seq.StartLocation.Column,
EndLine = seq.EndLocation.Line,
EndColumn = seq.EndLocation.Column,
};
}
}
}
Loading…
Cancel
Save