Browse Source

Add validation

pull/191/merge
Eusebiu Marcu 15 years ago
parent
commit
ad89c09578
  1. 25
      Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs
  2. 13
      ICSharpCode.Decompiler/CodeMappings.cs

25
Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs

@ -826,9 +826,19 @@ namespace ILSpy.Debugger.Services @@ -826,9 +826,19 @@ namespace ILSpy.Debugger.Services
if (CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out type, out line)) {
DebuggerService.JumpToCurrentLine(type, line, 0, line, 0);
} else {
// is possible that the type is not decompiled yet, so we must do a decompilation on demand
DecompileOnDemand(frame);
}
}
}
void DecompileOnDemand(StackFrame frame)
{
var debugType = frame.MethodInfo.DeclaringType;
string fullName = debugType.Namespace + "." + debugType.Name;
uint token = (uint)frame.MethodInfo.MetadataToken;
int ilOffset = frame.IP;
string fullName = debugType.Namespace + "." + debugType.Name;
if (DebugData.LoadedAssemblies == null)
Continue();
else {
@ -840,28 +850,27 @@ namespace ILSpy.Debugger.Services @@ -840,28 +850,27 @@ namespace ILSpy.Debugger.Services
break;
}
}
if (typeRef != null)
break;
}
if (typeRef != null) {
// decompile on demand
AstBuilder builder = new AstBuilder(new DecompilerContext());
builder.AddType(typeRef.Resolve());
builder.GenerateCode(new PlainTextOutput());
// jump
// try jump
int line;
TypeDefinition type;
if (CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out type, out line)) {
DebuggerService.JumpToCurrentLine(type, line, 0, line, 0);
} else {
StepOut();
// continue since we cannot find the debugged type
Continue();
}
} else {
// continue since we cannot find the debugged type
StepOut();
}
}
Continue();
}
}
}

13
ICSharpCode.Decompiler/CodeMappings.cs

@ -48,7 +48,9 @@ namespace ICSharpCode.Decompiler @@ -48,7 +48,9 @@ namespace ICSharpCode.Decompiler
var resultList = new List<int>();
// add list for the current source code line
var currentList = MemberMapping.MemberCodeMappings.FindAll(m => m.SourceCodeLine == this.SourceCodeLine);
var currentList = MemberMapping.MemberCodeMappings
.FindAll(m => m.SourceCodeLine == this.SourceCodeLine)
.OrderBy(m => m.ILInstructionOffset.From);
foreach (var element in currentList.Distinct(new SourceCodeMappingComparer())) {
resultList.Add(element.ILInstructionOffset.From);
resultList.Add(element.ILInstructionOffset.To);
@ -166,6 +168,12 @@ namespace ICSharpCode.Decompiler @@ -166,6 +168,12 @@ namespace ICSharpCode.Decompiler
this MethodDefinition member,
ConcurrentDictionary<string, List<MemberMapping>> codeMappings)
{
if (member == null || !member.HasBody)
return null;
if (codeMappings == null)
throw new ArgumentNullException("CodeMappings storage must be valid!");
// create IL/CSharp code mappings - used in debugger
MemberMapping currentMemberMapping = null;
if (codeMappings.ContainsKey(member.DeclaringType.FullName)) {
@ -198,6 +206,9 @@ namespace ICSharpCode.Decompiler @@ -198,6 +206,9 @@ namespace ICSharpCode.Decompiler
int lineNumber,
out uint metadataToken)
{
if (codeMappings == null)
throw new ArgumentNullException("CodeMappings storage must be valid!");
if (!codeMappings.ContainsKey(typeName)) {
metadataToken = 0;
return null;

Loading…
Cancel
Save