Browse Source

CopyToClipboard: don't truncate string to 256 characters

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4023 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
61e63ad4d2
  1. 15
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/ValueNode.cs
  2. 54
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/Util.cs

15
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/ValueNode.cs

@ -27,6 +27,7 @@ namespace Debugger.AddIn.TreeModel @@ -27,6 +27,7 @@ namespace Debugger.AddIn.TreeModel
{
Expression expression;
bool canSetText;
string fullText;
public Expression Expression {
get { return expression; }
@ -82,15 +83,13 @@ namespace Debugger.AddIn.TreeModel @@ -82,15 +83,13 @@ namespace Debugger.AddIn.TreeModel
this.Name = val.Expression.CodeTail;
if (DebuggingOptions.Instance.ShowValuesInHexadecimal && val.Type.IsInteger) {
this.Text = String.Format("0x{0:X}", val.PrimitiveValue);
fullText = String.Format("0x{0:X}", val.PrimitiveValue);
} else if (val.Type.IsPointer) {
this.Text = String.Format("0x{0:X}", val.PointerAddress);
fullText = String.Format("0x{0:X}", val.PointerAddress);
} else {
this.Text = val.AsString;
fullText = 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 {
@ -118,8 +117,10 @@ namespace Debugger.AddIn.TreeModel @@ -118,8 +117,10 @@ namespace Debugger.AddIn.TreeModel
// Do last since it may expire the object
if ((val.Type.IsClass || val.Type.IsValueType) && !val.IsNull) {
this.Text = val.InvokeToString();
fullText = val.InvokeToString();
}
this.Text = (fullText.Length > 256) ? fullText.Substring(0, 256) + "..." : fullText;
}
IEnumerable<AbstractNode> PrependNode(AbstractNode node, IEnumerable<AbstractNode> rest)
@ -225,7 +226,7 @@ namespace Debugger.AddIn.TreeModel @@ -225,7 +226,7 @@ namespace Debugger.AddIn.TreeModel
copyItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.LocalVariables.CopyToClipboard");
copyItem.Checked = false;
copyItem.Click += delegate {
ClipboardWrapper.SetText(this.Text);
ClipboardWrapper.SetText(fullText);
};
ToolStripMenuItem hexView;

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

@ -23,36 +23,44 @@ namespace Debugger.Wrappers @@ -23,36 +23,44 @@ namespace Debugger.Wrappers
public static string GetString(UnmanagedStringGetter getter, uint defaultLength, bool trim)
{
const uint MAX_LENGTH = 1024 * 1024;
// 8M characters ought to be enough for everyone...
// (we need some limit to avoid OutOfMemoryExceptions when trying to load extremely large
// strings - see SD2-1470).
const uint MAX_LENGTH = 8 * 1024 * 1024;
string managedString;
IntPtr unmanagedString;
uint exactLength;
if (defaultLength > MAX_LENGTH)
defaultLength = MAX_LENGTH;
// First attempt
unmanagedString = Marshal.AllocHGlobal((int)defaultLength * 2 + 2); // + 2 for terminating zero
getter(defaultLength, out exactLength, defaultLength > 0 ? unmanagedString : IntPtr.Zero);
exactLength = (exactLength > MAX_LENGTH) ? MAX_LENGTH : exactLength;
if(exactLength > defaultLength) {
// Second attempt
try {
getter(defaultLength, out exactLength, defaultLength > 0 ? unmanagedString : IntPtr.Zero);
exactLength = (exactLength > MAX_LENGTH) ? MAX_LENGTH : exactLength;
if(exactLength > defaultLength) {
// Second attempt
Marshal.FreeHGlobal(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)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) {
managedString = managedString.TrimEnd('\0');
}
} finally {
Marshal.FreeHGlobal(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)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) {
managedString = managedString.TrimEnd('\0');
}
Marshal.FreeHGlobal(unmanagedString);
return managedString;
}
}

Loading…
Cancel
Save