From 1ed9f6f251fb5de0d003e0b4487d362143c69e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Mon, 12 Jul 2010 21:16:37 +0000 Subject: [PATCH] Improved the filename -> symbol document resolution git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6113 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Interop/CorSymExtensionMethods.cs | 9 +-- .../Debugger.Core/SourcecodeSegment.cs | 79 +++++++++---------- 2 files changed, 43 insertions(+), 45 deletions(-) diff --git a/src/AddIns/Debugger/Debugger.Core/Interop/CorSymExtensionMethods.cs b/src/AddIns/Debugger/Debugger.Core/Interop/CorSymExtensionMethods.cs index 1b2461f5d2..0ba2138592 100644 --- a/src/AddIns/Debugger/Debugger.Core/Interop/CorSymExtensionMethods.cs +++ b/src/AddIns/Debugger/Debugger.Core/Interop/CorSymExtensionMethods.cs @@ -47,6 +47,7 @@ namespace Debugger.Interop.CorSym fixed(byte* pCheckSum = checkSum) symDoc.GetCheckSum((uint)checkSum.Length, out actualLength, new IntPtr(pCheckSum)); } + if (actualLength == 0) return null; Array.Resize(ref checkSum, (int)actualLength); return checkSum; } @@ -182,11 +183,9 @@ namespace Debugger.Interop.CorSym public int CompareTo(SequencePoint other) { - if (this.Line == other.Line) { - return this.Column.CompareTo(other.Column); - } else { - return this.Line.CompareTo(other.Line); - } + if (this.Line != other.Line) return this.Line.CompareTo(other.Line); + if (this.Column != other.Column) return this.Column.CompareTo(other.Column); + return this.Offset.CompareTo(other.Offset); } } } diff --git a/src/AddIns/Debugger/Debugger.Core/SourcecodeSegment.cs b/src/AddIns/Debugger/Debugger.Core/SourcecodeSegment.cs index 1056e679e1..3b9da51b3a 100644 --- a/src/AddIns/Debugger/Debugger.Core/SourcecodeSegment.cs +++ b/src/AddIns/Debugger/Debugger.Core/SourcecodeSegment.cs @@ -79,58 +79,57 @@ namespace Debugger { } + /// "\lowercasename.cs" or absolute path + static string NormalizeFilename(string filename, out bool isRooted) + { + isRooted = Path.IsPathRooted(filename); + if (!isRooted) { + while (filename.StartsWith(@".\")) filename = filename.Substring(2); + if (!filename.StartsWith(@"\")) filename = @"\" + filename; + } + return filename.ToLowerInvariant(); + } + static ISymUnmanagedDocument GetSymDocumentFromFilename(Module module, string filename, byte[] checksum) { if (filename == null) throw new ArgumentNullException("filename"); - filename = filename.ToLower(); ISymUnmanagedDocument[] symDocs = module.SymDocuments; - // "c:\project\file.cs" N/A - if (Path.IsPathRooted(filename) && checksum == null) { - foreach(ISymUnmanagedDocument symDoc in symDocs) { - if (symDoc.GetURL().ToLower() == filename) return symDoc; - } - return null; // Not found - } - - // "c:\project\file.cs" 0123456789 - if (Path.IsPathRooted(filename) && checksum != null) { - foreach(ISymUnmanagedDocument symDoc in symDocs) { - if (symDoc.GetURL().ToLower() == filename) return symDoc; - } - // Not found - try to find using checksum - filename = Path.GetFileName(filename); - } + // Normalize input + bool filenameRooted; + filename = NormalizeFilename(filename, out filenameRooted); - // "file.cs" N/A - if (!Path.IsPathRooted(filename) && checksum == null) { - if (!filename.StartsWith(@"\")) { - filename = @"\" + filename; - } - foreach(ISymUnmanagedDocument symDoc in symDocs) { - if (symDoc.GetURL().ToLower().EndsWith(filename)) return symDoc; + // Exact match of all the data that is available + foreach(ISymUnmanagedDocument symDoc in symDocs) { + bool urlRooted; + string url = NormalizeFilename(symDoc.GetURL(), out urlRooted); + + if (filenameRooted && urlRooted) { + if (url == filename) return symDoc; + } else if (filenameRooted && !urlRooted) { + if (filename.EndsWith(url)) return symDoc; + } else if (!filenameRooted && urlRooted) { + if (url.EndsWith(filename)) return symDoc; + } else { + if (url == filename) return symDoc; } - return null; // Not found } - // "file.cs" 0123456789 - if (!Path.IsPathRooted(filename) && checksum != null) { - if (!filename.StartsWith(@"\")) { - filename = @"\" + filename; - } + // Relaxed matching if we have checksum + if (checksum != null) { foreach(ISymUnmanagedDocument symDoc in symDocs) { - if (!symDoc.GetURL().ToLower().EndsWith(filename)) continue; - byte[] symDocCheckSum = symDoc.GetCheckSum(); - if (symDocCheckSum.Length != checksum.Length) continue; - bool match = true; - for (int i = 0; i < checksum.Length; i++) { - if (symDocCheckSum[i] != checksum[i]) match = false; + if (Path.GetFileName(filename).ToLowerInvariant() == Path.GetFileName(symDoc.GetURL()).ToLowerInvariant()) { + byte[] symDocCheckSum = symDoc.GetCheckSum(); + if (symDocCheckSum.Length != checksum.Length) continue; + bool match = true; + for (int i = 0; i < checksum.Length; i++) { + if (symDocCheckSum[i] != checksum[i]) match = false; + } + if (!match) continue; + return symDoc; } - if (!match) continue; - return symDoc; } - return null; // Not found } return null; @@ -174,7 +173,7 @@ namespace Debugger segment.corFunction = module.CorModule.GetFunctionFromToken(symMethod.GetToken()); segment.ilStart = (int)sqPoint.Offset; segment.ilEnd = (int)sqPoint.Offset; - segment.stepRanges = null; + segment.stepRanges = null; return segment; } }