Browse Source

use ParserService.ParseFile instead of a collection of ViewContents to get information about a decompiled type

pull/80/head
Siegfried Pammer 12 years ago
parent
commit
8f8b4975f1
  1. 41
      src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs

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

@ -24,26 +24,20 @@ namespace ICSharpCode.ILSpyAddIn
return false; return false;
} }
public static MethodDebugSymbols GetSymbols(IMethod method) public static ILSpyUnresolvedFile GetSymbols(IMethod method)
{ {
var typeName = DecompiledTypeReference.FromTypeDefinition(method.DeclaringTypeDefinition); var typeName = DecompiledTypeReference.FromTypeDefinition(method.DeclaringTypeDefinition);
var id = IdStringProvider.GetIdString(method.MemberDefinition);
if (typeName == null) return null; if (typeName == null) return null;
var file = SD.ParserService.ParseFile(typeName.ToFileName()) as ILSpyUnresolvedFile; return SD.ParserService.ParseFile(typeName.ToFileName()) as ILSpyUnresolvedFile;
if (file != null && file.DebugSymbols.ContainsKey(id)) {
return file.DebugSymbols[id];
}
return null;
} }
public Debugger.SequencePoint GetSequencePoint(IMethod method, int iloffset) public Debugger.SequencePoint GetSequencePoint(IMethod method, int iloffset)
{ {
string id = IdStringProvider.GetIdString(method.MemberDefinition); string id = IdStringProvider.GetIdString(method.MemberDefinition);
var content = DecompiledViewContent.Get(method); var file = GetSymbols(method);
if (content == null || !content.DebugSymbols.ContainsKey(id)) if (file == null || !file.DebugSymbols.ContainsKey(id))
return null; return null;
var symbols = content.DebugSymbols[id]; var symbols = file.DebugSymbols[id];
var seqs = symbols.SequencePoints; var seqs = symbols.SequencePoints;
var seq = seqs.FirstOrDefault(p => p.ILRanges.Any(r => r.From <= iloffset && iloffset < r.To)); var seq = seqs.FirstOrDefault(p => p.ILRanges.Any(r => r.From <= iloffset && iloffset < r.To));
if (seq == null) if (seq == null)
@ -54,7 +48,7 @@ namespace ICSharpCode.ILSpyAddIn
seq = seqs.Where(p => p.ILRanges.Any(r => r.From <= iloffset && iloffset < r.To)) seq = seqs.Where(p => p.ILRanges.Any(r => r.From <= iloffset && iloffset < r.To))
.OrderByDescending(p => p.ILRanges.Last().To - p.ILRanges.First().From) .OrderByDescending(p => p.ILRanges.Last().To - p.ILRanges.First().From)
.FirstOrDefault(); .FirstOrDefault();
return seq.ToDebugger(symbols, content.PrimaryFileName); return seq.ToDebugger(symbols, file.FileName);
} }
return null; return null;
} }
@ -65,28 +59,31 @@ namespace ICSharpCode.ILSpyAddIn
if (name == null || !FileUtility.IsEqualFileName(module.FullPath, name.AssemblyFile)) if (name == null || !FileUtility.IsEqualFileName(module.FullPath, name.AssemblyFile))
yield break; yield break;
var content = DecompiledViewContent.Get(name); var file = SD.ParserService.ParseFile(name.ToFileName()) as ILSpyUnresolvedFile;
if (content == null) if (file == null)
yield break; yield break;
TextLocation loc = new TextLocation(line, column); TextLocation loc = new TextLocation(line, column);
foreach(var symbols in content.DebugSymbols.Values.Where(s => s.StartLocation <= loc && loc <= s.EndLocation)) { foreach(var symbols in file.DebugSymbols.Values.Where(s => s.StartLocation <= loc && loc <= s.EndLocation)) {
Decompiler.SequencePoint seq = null; Decompiler.SequencePoint seq = null;
if (column != 0) if (column != 0)
seq = symbols.SequencePoints.FirstOrDefault(p => p.StartLocation <= loc && loc <= p.EndLocation); seq = symbols.SequencePoints.FirstOrDefault(p => p.StartLocation <= loc && loc <= p.EndLocation);
if (seq == null) if (seq == null)
seq = symbols.SequencePoints.FirstOrDefault(p => line <= p.StartLocation.Line); seq = symbols.SequencePoints.FirstOrDefault(p => line <= p.StartLocation.Line);
if (seq != null) if (seq != null)
yield return seq.ToDebugger(symbols, content.PrimaryFileName); yield return seq.ToDebugger(symbols, filename);
} }
} }
public IEnumerable<ILRange> GetIgnoredILRanges(IMethod method) public IEnumerable<ILRange> GetIgnoredILRanges(IMethod method)
{ {
var symbols = GetSymbols(method); string id = IdStringProvider.GetIdString(method.MemberDefinition);
if (symbols == null) var file = GetSymbols(method);
if (file == null || !file.DebugSymbols.ContainsKey(id))
return new ILRange[] { }; return new ILRange[] { };
var symbols = file.DebugSymbols[id];
int codesize = symbols.CecilMethod.Body.CodeSize; int codesize = symbols.CecilMethod.Body.CodeSize;
var inv = ICSharpCode.Decompiler.ILAst.ILRange.Invert(symbols.SequencePoints.SelectMany(s => s.ILRanges), 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)); return inv.Select(r => new ILRange(r.From, r.To));
@ -94,10 +91,14 @@ namespace ICSharpCode.ILSpyAddIn
public IEnumerable<ILLocalVariable> GetLocalVariables(IMethod method) public IEnumerable<ILLocalVariable> GetLocalVariables(IMethod method)
{ {
var symbols = GetSymbols(method); string id = IdStringProvider.GetIdString(method.MemberDefinition);
if (symbols == null) var file = GetSymbols(method);
if (file == null || !file.DebugSymbols.ContainsKey(id))
return null; return null;
var symbols = file.DebugSymbols[id];
var context = new SimpleTypeResolveContext(method); var context = new SimpleTypeResolveContext(method);
var loader = new CecilLoader(); var loader = new CecilLoader();

Loading…
Cancel
Save