From a0320660b3c1cb6f58a0885a53a479dc42ea0d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Tue, 24 Jun 2008 11:16:11 +0000 Subject: [PATCH] Breakpoints: Do not use ISymUnmanagedReader.GetDocument. It is broken if two files have the same name. Do not use ISymUnmanagedMethod.GetOffset. It sometimes returns negative offset. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3135 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Control/Module.cs | 15 +++++++ .../Project/Src/Control/Thread.cs | 4 +- .../Project/Src/Debugger/SourcecodeSegment.cs | 41 +++++++++++++------ .../Interop/CorSym/CorSymReader_SxSClass.cs | 2 +- .../CorSym/CorSymReader_deprecatedClass.cs | 2 +- .../Src/Interop/CorSym/ISymUnmanagedReader.cs | 2 +- .../Autogenerated/CorDebugThreadState.cs | 8 ++-- .../Autogenerated/CorSymReader_SxSClass.cs | 22 +++++++++- .../CorSymReader_deprecatedClass.cs | 22 +++++++++- .../Autogenerated/ISymUnmanagedReader.cs | 22 +++++++++- .../Src/Wrappers/CorSym/SequencePoint.cs | 12 +++++- 11 files changed, 124 insertions(+), 28 deletions(-) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs index 61e853ae2e..4ab6b53996 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs @@ -52,6 +52,21 @@ namespace Debugger } } + public ISymUnmanagedDocument[] SymDocuments { + get { + ISymUnmanagedDocument[] docs; + uint maxCount = 2; + uint fetched; + do { + maxCount *= 8; + docs = new ISymUnmanagedDocument[maxCount]; + symReader.GetDocuments(maxCount, out fetched, docs); + } while (fetched == maxCount); + Array.Resize(ref docs, (int)fetched); + return docs; + } + } + public ICorDebugModule CorModule { get { return corModule; diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Thread.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Thread.cs index 0ad35b6998..e8baa741a6 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Thread.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Thread.cs @@ -122,10 +122,10 @@ namespace Debugger if (!IsInValidState) return false; - return (CorThread.DebugState == CorDebugThreadState.Suspend); + return (CorThread.DebugState == CorDebugThreadState.THREAD_SUSPEND); } set { - CorThread.SetDebugState((value==true) ? CorDebugThreadState.Suspend : CorDebugThreadState.Run); + CorThread.SetDebugState((value==true) ? CorDebugThreadState.THREAD_SUSPEND : CorDebugThreadState.THREAD_RUN); } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/SourcecodeSegment.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/SourcecodeSegment.cs index e06111a40e..eea76c885e 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/SourcecodeSegment.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/SourcecodeSegment.cs @@ -6,6 +6,7 @@ // using System; +using System.Collections.Generic; using Debugger.Wrappers.CorDebug; using Debugger.Wrappers.CorSym; @@ -163,8 +164,15 @@ namespace Debugger return false; // No symbols } + // Do not use ISymUnmanagedReader.GetDocument! It is broken if two files have the same name + + ISymUnmanagedDocument[] symDocs = module.SymDocuments; ISymUnmanagedDocument symDoc = null; - symDoc = symReader.GetDocument(SourceFullFilename, Guid.Empty, Guid.Empty, Guid.Empty); + foreach(ISymUnmanagedDocument d in symDocs) { + if (d.URL.ToLower() == this.SourceFullFilename.ToLower()) { + symDoc = d; + } + } if (symDoc == null) { return false; // Does not use source file } @@ -189,19 +197,26 @@ namespace Debugger return false; //Not found } - // Check that StartLine is within the method - uint start = uint.MaxValue; - uint end = uint.MinValue; - foreach(SequencePoint sqPoint in symMethod.SequencePoints) { - if (sqPoint.Line == 0xFEEFEE) continue; - start = Math.Min(start, sqPoint.Line); - end = Math.Max(end, sqPoint.EndLine); - } - if (StartLine < start || StartLine > end) return false; + // Do not use ISymUnmanagedMethod.GetOffset! It sometimes returns negative offset - function = module.CorModule.GetFunctionFromToken(symMethod.Token); - ilOffset = (int)symMethod.GetOffset(symDoc, validLine, 0); - return true; + SequencePoint[] seqPoints = symMethod.SequencePoints; + Array.Sort(seqPoints); + if (seqPoints.Length == 0) return false; + if (this.StartLine < seqPoints[0].Line) return false; + foreach(SequencePoint sqPoint in seqPoints) { + if (sqPoint.Line == 0xFEEFEE) continue; + // If the desired breakpoint position is before the end of the sequence point + if (this.StartLine < sqPoint.EndLine || (this.StartLine == sqPoint.EndLine && this.StartColumn < sqPoint.EndColumn)) { + function = module.CorModule.GetFunctionFromToken(symMethod.Token); + ilOffset = (int)sqPoint.Offset; + startLine = (int)sqPoint.Line; + startColumn = (int)sqPoint.Column; + endLine = (int)sqPoint.EndLine; + endColumn = (int)sqPoint.EndColumn; + return true; + } + } + return false; } public override string ToString() diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/CorSym/CorSymReader_SxSClass.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/CorSym/CorSymReader_SxSClass.cs index 5f5e515ae7..cecf9a9355 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/CorSym/CorSymReader_SxSClass.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/CorSym/CorSymReader_SxSClass.cs @@ -22,7 +22,7 @@ namespace Debugger.Interop.CorSym public virtual extern ISymUnmanagedDocument GetDocument([In] IntPtr url, [In] Guid language, [In] Guid languageVendor, [In] Guid documentType); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - public virtual extern void GetDocuments([In] uint cDocs, out uint pcDocs, [Out] IntPtr pDocs); + public virtual extern void GetDocuments([In] uint cDocs, out uint pcDocs, [Out, MarshalAs(UnmanagedType.LPArray)] ISymUnmanagedDocument[] pDocs); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] public virtual extern void GetDocumentVersion([In, MarshalAs(UnmanagedType.Interface)] ISymUnmanagedDocument pDoc, out int version, out int pbCurrent); diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/CorSym/CorSymReader_deprecatedClass.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/CorSym/CorSymReader_deprecatedClass.cs index 8241f57d73..7a806aade7 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/CorSym/CorSymReader_deprecatedClass.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/CorSym/CorSymReader_deprecatedClass.cs @@ -22,7 +22,7 @@ namespace Debugger.Interop.CorSym public virtual extern ISymUnmanagedDocument GetDocument([In] IntPtr url, [In] Guid language, [In] Guid languageVendor, [In] Guid documentType); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - public virtual extern void GetDocuments([In] uint cDocs, out uint pcDocs, [Out] IntPtr pDocs); + public virtual extern void GetDocuments([In] uint cDocs, out uint pcDocs, [Out, MarshalAs(UnmanagedType.LPArray)] ISymUnmanagedDocument[] pDocs); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] public virtual extern void GetDocumentVersion([In, MarshalAs(UnmanagedType.Interface)] ISymUnmanagedDocument pDoc, out int version, out int pbCurrent); diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/CorSym/ISymUnmanagedReader.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/CorSym/ISymUnmanagedReader.cs index 5bab571c77..986b05d67e 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/CorSym/ISymUnmanagedReader.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/CorSym/ISymUnmanagedReader.cs @@ -20,7 +20,7 @@ namespace Debugger.Interop.CorSym [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] ISymUnmanagedDocument GetDocument([In] IntPtr url, [In] Guid language, [In] Guid languageVendor, [In] Guid documentType); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] - void GetDocuments([In] uint cDocs, out uint pcDocs, [Out] IntPtr pDocs); + void GetDocuments([In] uint cDocs, out uint pcDocs, [Out, MarshalAs(UnmanagedType.LPArray)] ISymUnmanagedDocument[] pDocs); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)] uint GetUserEntryPoint(); [return: MarshalAs(UnmanagedType.Interface)] diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/Autogenerated/CorDebugThreadState.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/Autogenerated/CorDebugThreadState.cs index 0cf8aafaa9..bba55bb2b7 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/Autogenerated/CorDebugThreadState.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/Autogenerated/CorDebugThreadState.cs @@ -1,4 +1,4 @@ -// +// // // // @@ -16,8 +16,10 @@ namespace Debugger.Wrappers.CorDebug public enum CorDebugThreadState : int { - Run = 0, - Suspend = 1, + + THREAD_RUN = 0, + + THREAD_SUSPEND = 1, } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/Autogenerated/CorSymReader_SxSClass.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/Autogenerated/CorSymReader_SxSClass.cs index ea65f542fb..c645ea5baa 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/Autogenerated/CorSymReader_SxSClass.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/Autogenerated/CorSymReader_SxSClass.cs @@ -100,9 +100,27 @@ namespace Debugger.Wrappers.CorSym return ISymUnmanagedDocument.Wrap(this.WrappedObject.GetDocument(url, language, languageVendor, documentType)); } - public void GetDocuments(uint cDocs, out uint pcDocs, System.IntPtr pDocs) + public void GetDocuments(uint cDocs, out uint pcDocs, ISymUnmanagedDocument[] pDocs) { - this.WrappedObject.GetDocuments(cDocs, out pcDocs, pDocs); + Debugger.Interop.CorSym.ISymUnmanagedDocument[] array_pDocs = new Debugger.Interop.CorSym.ISymUnmanagedDocument[pDocs.Length]; + for (int i = 0; (i < pDocs.Length); i = (i + 1)) + { + if ((pDocs[i] != null)) + { + array_pDocs[i] = pDocs[i].WrappedObject; + } + } + this.WrappedObject.GetDocuments(cDocs, out pcDocs, array_pDocs); + for (int i = 0; (i < pDocs.Length); i = (i + 1)) + { + if ((array_pDocs[i] != null)) + { + pDocs[i] = ISymUnmanagedDocument.Wrap(array_pDocs[i]); + } else + { + pDocs[i] = null; + } + } } public int GetDocumentVersion(ISymUnmanagedDocument pDoc, out int version) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/Autogenerated/CorSymReader_deprecatedClass.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/Autogenerated/CorSymReader_deprecatedClass.cs index ba796e3f12..b5ccf9c65a 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/Autogenerated/CorSymReader_deprecatedClass.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/Autogenerated/CorSymReader_deprecatedClass.cs @@ -100,9 +100,27 @@ namespace Debugger.Wrappers.CorSym return ISymUnmanagedDocument.Wrap(this.WrappedObject.GetDocument(url, language, languageVendor, documentType)); } - public void GetDocuments(uint cDocs, out uint pcDocs, System.IntPtr pDocs) + public void GetDocuments(uint cDocs, out uint pcDocs, ISymUnmanagedDocument[] pDocs) { - this.WrappedObject.GetDocuments(cDocs, out pcDocs, pDocs); + Debugger.Interop.CorSym.ISymUnmanagedDocument[] array_pDocs = new Debugger.Interop.CorSym.ISymUnmanagedDocument[pDocs.Length]; + for (int i = 0; (i < pDocs.Length); i = (i + 1)) + { + if ((pDocs[i] != null)) + { + array_pDocs[i] = pDocs[i].WrappedObject; + } + } + this.WrappedObject.GetDocuments(cDocs, out pcDocs, array_pDocs); + for (int i = 0; (i < pDocs.Length); i = (i + 1)) + { + if ((array_pDocs[i] != null)) + { + pDocs[i] = ISymUnmanagedDocument.Wrap(array_pDocs[i]); + } else + { + pDocs[i] = null; + } + } } public int GetDocumentVersion(ISymUnmanagedDocument pDoc, out int version) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/Autogenerated/ISymUnmanagedReader.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/Autogenerated/ISymUnmanagedReader.cs index 1dbd703114..c9453852d6 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/Autogenerated/ISymUnmanagedReader.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/Autogenerated/ISymUnmanagedReader.cs @@ -100,9 +100,27 @@ namespace Debugger.Wrappers.CorSym return ISymUnmanagedDocument.Wrap(this.WrappedObject.GetDocument(url, language, languageVendor, documentType)); } - public void GetDocuments(uint cDocs, out uint pcDocs, System.IntPtr pDocs) + public void GetDocuments(uint cDocs, out uint pcDocs, ISymUnmanagedDocument[] pDocs) { - this.WrappedObject.GetDocuments(cDocs, out pcDocs, pDocs); + Debugger.Interop.CorSym.ISymUnmanagedDocument[] array_pDocs = new Debugger.Interop.CorSym.ISymUnmanagedDocument[pDocs.Length]; + for (int i = 0; (i < pDocs.Length); i = (i + 1)) + { + if ((pDocs[i] != null)) + { + array_pDocs[i] = pDocs[i].WrappedObject; + } + } + this.WrappedObject.GetDocuments(cDocs, out pcDocs, array_pDocs); + for (int i = 0; (i < pDocs.Length); i = (i + 1)) + { + if ((array_pDocs[i] != null)) + { + pDocs[i] = ISymUnmanagedDocument.Wrap(array_pDocs[i]); + } else + { + pDocs[i] = null; + } + } } public uint UserEntryPoint diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/SequencePoint.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/SequencePoint.cs index 4bf1ba7d8a..fd3c85353a 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/SequencePoint.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorSym/SequencePoint.cs @@ -10,9 +10,10 @@ namespace Debugger.Wrappers.CorSym { using System; + using System.Collections; - public class SequencePoint + public class SequencePoint: IComparable { ISymUnmanagedDocument document; uint offset; @@ -66,6 +67,15 @@ namespace Debugger.Wrappers.CorSym this.endLine = endLine; this.endColumn = endColumn; } + + public int CompareTo(SequencePoint other) + { + if (this.Line == other.Line) { + return this.Column.CompareTo(other.Column); + } else { + return this.Line.CompareTo(other.Line); + } + } } }