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 17 years ago
parent
commit
61e63ad4d2
  1. 15
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/TreeModel/ValueNode.cs
  2. 10
      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
{ {
Expression expression; Expression expression;
bool canSetText; bool canSetText;
string fullText;
public Expression Expression { public Expression Expression {
get { return expression; } get { return expression; }
@ -82,15 +83,13 @@ namespace Debugger.AddIn.TreeModel
this.Name = val.Expression.CodeTail; this.Name = val.Expression.CodeTail;
if (DebuggingOptions.Instance.ShowValuesInHexadecimal && val.Type.IsInteger) { 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) { } else if (val.Type.IsPointer) {
this.Text = String.Format("0x{0:X}", val.PointerAddress); fullText = String.Format("0x{0:X}", val.PointerAddress);
} else { } 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) { if (val.Type != null) {
this.Type = val.Type.Name; this.Type = val.Type.Name;
} else { } else {
@ -118,8 +117,10 @@ namespace Debugger.AddIn.TreeModel
// Do last since it may expire the object // Do last since it may expire the object
if ((val.Type.IsClass || val.Type.IsValueType) && !val.IsNull) { 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) IEnumerable<AbstractNode> PrependNode(AbstractNode node, IEnumerable<AbstractNode> rest)
@ -225,7 +226,7 @@ namespace Debugger.AddIn.TreeModel
copyItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.LocalVariables.CopyToClipboard"); copyItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.LocalVariables.CopyToClipboard");
copyItem.Checked = false; copyItem.Checked = false;
copyItem.Click += delegate { copyItem.Click += delegate {
ClipboardWrapper.SetText(this.Text); ClipboardWrapper.SetText(fullText);
}; };
ToolStripMenuItem hexView; ToolStripMenuItem hexView;

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

@ -23,13 +23,19 @@ namespace Debugger.Wrappers
public static string GetString(UnmanagedStringGetter getter, uint defaultLength, bool trim) 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; string managedString;
IntPtr unmanagedString; IntPtr unmanagedString;
uint exactLength; uint exactLength;
if (defaultLength > MAX_LENGTH)
defaultLength = MAX_LENGTH;
// First attempt // First attempt
unmanagedString = Marshal.AllocHGlobal((int)defaultLength * 2 + 2); // + 2 for terminating zero unmanagedString = Marshal.AllocHGlobal((int)defaultLength * 2 + 2); // + 2 for terminating zero
try {
getter(defaultLength, out exactLength, defaultLength > 0 ? unmanagedString : IntPtr.Zero); getter(defaultLength, out exactLength, defaultLength > 0 ? unmanagedString : IntPtr.Zero);
exactLength = (exactLength > MAX_LENGTH) ? MAX_LENGTH : exactLength; exactLength = (exactLength > MAX_LENGTH) ? MAX_LENGTH : exactLength;
@ -52,7 +58,9 @@ namespace Debugger.Wrappers
if (trim) { if (trim) {
managedString = managedString.TrimEnd('\0'); managedString = managedString.TrimEnd('\0');
} }
} finally {
Marshal.FreeHGlobal(unmanagedString); Marshal.FreeHGlobal(unmanagedString);
}
return managedString; return managedString;
} }
} }

Loading…
Cancel
Save