Browse Source

Add validation

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

73
Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs

@ -826,42 +826,51 @@ 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 {
var debugType = frame.MethodInfo.DeclaringType; // is possible that the type is not decompiled yet, so we must do a decompilation on demand
string fullName = debugType.Namespace + "." + debugType.Name; DecompileOnDemand(frame);
}
}
}
if (DebugData.LoadedAssemblies == null) void DecompileOnDemand(StackFrame frame)
Continue(); {
else { var debugType = frame.MethodInfo.DeclaringType;
// search for type in the current assembly list uint token = (uint)frame.MethodInfo.MetadataToken;
TypeReference typeRef = null; int ilOffset = frame.IP;
foreach (var assembly in DebugData.LoadedAssemblies) {
foreach (var module in assembly.Modules) {
if (module.TryGetTypeReference(fullName, out typeRef)) {
break;
}
}
if (typeRef != null)
break;
}
if (typeRef != null) { string fullName = debugType.Namespace + "." + debugType.Name;
// decompile on demand if (DebugData.LoadedAssemblies == null)
AstBuilder builder = new AstBuilder(new DecompilerContext()); Continue();
builder.AddType(typeRef.Resolve()); else {
builder.GenerateCode(new PlainTextOutput()); // search for type in the current assembly list
TypeReference typeRef = null;
// jump foreach (var assembly in DebugData.LoadedAssemblies) {
if (CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out type, out line)) { foreach (var module in assembly.Modules) {
DebuggerService.JumpToCurrentLine(type, line, 0, line, 0); if (module.TryGetTypeReference(fullName, out typeRef)) {
} else { break;
StepOut();
}
} else {
// continue since we cannot find the debugged type
StepOut();
} }
} }
if (typeRef != null)
break;
}
if (typeRef != null) {
// decompile on demand
AstBuilder builder = new AstBuilder(new DecompilerContext());
builder.AddType(typeRef.Resolve());
builder.GenerateCode(new PlainTextOutput());
// try jump
int line;
TypeDefinition type;
if (CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out type, out line)) {
DebuggerService.JumpToCurrentLine(type, line, 0, line, 0);
} else {
// continue since we cannot find the debugged type
Continue();
}
} else {
// continue since we cannot find the debugged type
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