From e00e6998998b9194c142f7896e1a474e8061402a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 2 Feb 2009 20:12:04 +0000 Subject: [PATCH] implemented the real fix for SD2-1470 git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3788 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/TreeModel/ValueNode.cs | 2 ++ .../Project/Src/Wrappers/Util.cs | 25 ++++++++++++------- .../Src/Services/Debugger/DebuggerService.cs | 8 +++--- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/ValueNode.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/ValueNode.cs index af43744872..a66ef87d53 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/ValueNode.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/ValueNode.cs @@ -88,6 +88,8 @@ namespace Debugger.AddIn.TreeModel this.Text = val.AsString; } + this.Text = (this.Text.Length > 256) ? this.Text.Substring(0, 256) + "..." : this.Text; + if (val.Type != null) { this.Type = val.Type.Name; } else { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/Util.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/Util.cs index d14d0d382b..2faa745c7a 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/Util.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/Util.cs @@ -12,7 +12,7 @@ using System.Runtime.InteropServices; namespace Debugger.Wrappers { - public delegate void UnmanagedStringGetter(uint pStringLenght, out uint stringLenght, System.IntPtr pString); + public delegate void UnmanagedStringGetter(uint pStringLength, out uint stringLength, System.IntPtr pString); public static class Util { @@ -21,25 +21,32 @@ namespace Debugger.Wrappers return GetString(getter, 64, true); } - public static string GetString(UnmanagedStringGetter getter, uint defaultLenght, bool trim) + public static string GetString(UnmanagedStringGetter getter, uint defaultLength, bool trim) { + const uint MAX_LENGTH = 1024 * 1024; string managedString; IntPtr unmanagedString; - uint exactLenght; + uint exactLength; // First attempt - unmanagedString = Marshal.AllocHGlobal((int)defaultLenght * 2 + 2); // + 2 for terminating zero - getter(defaultLenght, out exactLenght, defaultLenght > 0 ? unmanagedString : IntPtr.Zero); + unmanagedString = Marshal.AllocHGlobal((int)defaultLength * 2 + 2); // + 2 for terminating zero + getter(defaultLength, out exactLength, defaultLength > 0 ? unmanagedString : IntPtr.Zero); - if(exactLenght > defaultLenght) { + exactLength = (exactLength > MAX_LENGTH) ? MAX_LENGTH : exactLength; + + if(exactLength > defaultLength) { // Second attempt Marshal.FreeHGlobal(unmanagedString); - unmanagedString = Marshal.AllocHGlobal((int)exactLenght * 2 + 2); // + 2 for terminating zero - getter(exactLenght, out exactLenght, unmanagedString); + // TODO: Consider removing "+ 2" for the zero + unmanagedString = Marshal.AllocHGlobal((int)exactLength * 2 + 2); // + 2 for terminating zero + uint unused; + getter(exactLength, out unused, unmanagedString); } + // TODO: Check how the trimming and the last 0 charater works + // Return managed string and free unmanaged memory - managedString = Marshal.PtrToStringUni(unmanagedString, (int)exactLenght); + managedString = Marshal.PtrToStringUni(unmanagedString, (int)exactLength); //Console.WriteLine("Marshaled string from COM: \"" + managedString + "\" lenght=" + managedString.Length + " arrayLenght=" + exactLenght); // The API might or might not include terminating null at the end if (trim) { diff --git a/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs b/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs index ef33be57b6..6f13e73551 100644 --- a/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs +++ b/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs @@ -442,11 +442,9 @@ namespace ICSharpCode.SharpDevelop.Debugging if (currentValue != null) { debuggerCanShowValue = true; b.Append(" = "); - if (currentValue.Length > 256) { - b.Append(currentValue.Substring(0, 256)); - b.Append("..."); - } else - b.Append(currentValue); + if (currentValue.Length > 256) + currentValue = currentValue.Substring(0, 256) + "..."; + b.Append(currentValue); } } return b.ToString();