Browse Source

implemented the real fix for SD2-1470

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3788 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
e00e699899
  1. 2
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/ValueNode.cs
  2. 25
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/Util.cs
  3. 6
      src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs

2
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 = val.AsString;
} }
this.Text = (this.Text.Length > 256) ? this.Text.Substring(0, 256) + "..." : this.Text;
if (val.Type != null) { if (val.Type != null) {
this.Type = val.Type.Name; this.Type = val.Type.Name;
} else { } else {

25
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/Util.cs

@ -12,7 +12,7 @@ using System.Runtime.InteropServices;
namespace Debugger.Wrappers 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 public static class Util
{ {
@ -21,25 +21,32 @@ namespace Debugger.Wrappers
return GetString(getter, 64, true); 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; string managedString;
IntPtr unmanagedString; IntPtr unmanagedString;
uint exactLenght; uint exactLength;
// First attempt // First attempt
unmanagedString = Marshal.AllocHGlobal((int)defaultLenght * 2 + 2); // + 2 for terminating zero unmanagedString = Marshal.AllocHGlobal((int)defaultLength * 2 + 2); // + 2 for terminating zero
getter(defaultLenght, out exactLenght, defaultLenght > 0 ? unmanagedString : IntPtr.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 // Second attempt
Marshal.FreeHGlobal(unmanagedString); Marshal.FreeHGlobal(unmanagedString);
unmanagedString = Marshal.AllocHGlobal((int)exactLenght * 2 + 2); // + 2 for terminating zero // TODO: Consider removing "+ 2" for the zero
getter(exactLenght, out exactLenght, unmanagedString); 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 // 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); //Console.WriteLine("Marshaled string from COM: \"" + managedString + "\" lenght=" + managedString.Length + " arrayLenght=" + exactLenght);
// The API might or might not include terminating null at the end // The API might or might not include terminating null at the end
if (trim) { if (trim) {

6
src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs

@ -442,10 +442,8 @@ namespace ICSharpCode.SharpDevelop.Debugging
if (currentValue != null) { if (currentValue != null) {
debuggerCanShowValue = true; debuggerCanShowValue = true;
b.Append(" = "); b.Append(" = ");
if (currentValue.Length > 256) { if (currentValue.Length > 256)
b.Append(currentValue.Substring(0, 256)); currentValue = currentValue.Substring(0, 256) + "...";
b.Append("...");
} else
b.Append(currentValue); b.Append(currentValue);
} }
} }

Loading…
Cancel
Save