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
if (CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out type, out line)) { if (CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out type, out line)) {
DebuggerService.JumpToCurrentLine(type, line, 0, line, 0); DebuggerService.JumpToCurrentLine(type, line, 0, line, 0);
} else { } 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; 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) if (DebugData.LoadedAssemblies == null)
Continue(); Continue();
else { else {
@ -840,28 +850,27 @@ namespace ILSpy.Debugger.Services
break; break;
} }
} }
if (typeRef != null) if (typeRef != null)
break; break;
} }
if (typeRef != null) { if (typeRef != null) {
// decompile on demand // decompile on demand
AstBuilder builder = new AstBuilder(new DecompilerContext()); AstBuilder builder = new AstBuilder(new DecompilerContext());
builder.AddType(typeRef.Resolve()); builder.AddType(typeRef.Resolve());
builder.GenerateCode(new PlainTextOutput()); builder.GenerateCode(new PlainTextOutput());
// jump // try jump
int line;
TypeDefinition type;
if (CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out type, out line)) { if (CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out type, out line)) {
DebuggerService.JumpToCurrentLine(type, line, 0, line, 0); DebuggerService.JumpToCurrentLine(type, line, 0, line, 0);
} else { } else {
StepOut(); // continue since we cannot find the debugged type
Continue();
} }
} else { } else {
// continue since we cannot find the debugged type // continue since we cannot find the debugged type
StepOut(); Continue();
}
}
} }
} }
} }

13
ICSharpCode.Decompiler/CodeMappings.cs

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

Loading…
Cancel
Save