Browse Source

Add maxLength parameter to Value.AsString() method.

pull/14/head
Daniel Grunwald 15 years ago
parent
commit
6dfa03cd02
  1. 4
      src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.xaml.cs
  2. 2
      src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs
  3. 2
      src/AddIns/Debugger/Debugger.AddIn/TreeModel/ExpressionNode.cs
  4. 4
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/DebuggerHelpers.cs
  5. 4
      src/AddIns/Debugger/Debugger.Core/Exception.cs
  6. 2
      src/AddIns/Debugger/Debugger.Core/Thread.cs
  7. 43
      src/AddIns/Debugger/Debugger.Core/Value.cs

4
src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.xaml.cs

@ -186,9 +186,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -186,9 +186,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
}
if (showArgumentValues) {
try {
argValue = frame.GetArgumentValue(i).AsString;
if (argValue != null && argValue.Length > 100)
argValue = argValue.Substring(0, 100) + "...";
argValue = frame.GetArgumentValue(i).AsString(100);
} catch { }
}
if (parameterName != null && argValue != null) {

2
src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs

@ -382,7 +382,7 @@ namespace ICSharpCode.SharpDevelop.Services @@ -382,7 +382,7 @@ namespace ICSharpCode.SharpDevelop.Services
try {
Value val = GetValueFromName(variableName);
if (val == null) return null;
return val.AsString;
return val.AsString();
} catch (GetValueException) {
return null;
}

2
src/AddIns/Debugger/Debugger.AddIn/TreeModel/ExpressionNode.cs

@ -195,7 +195,7 @@ namespace Debugger.AddIn.TreeModel @@ -195,7 +195,7 @@ namespace Debugger.AddIn.TreeModel
return;
}
} else {
fullText = val.AsString;
fullText = val.AsString();
}
this.Text = (fullText.Length > 256) ? fullText.Substring(0, 256) + "..." : fullText;

4
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/DebuggerHelpers.cs

@ -88,11 +88,11 @@ namespace Debugger.AddIn.Visualizers.Utils @@ -88,11 +88,11 @@ namespace Debugger.AddIn.Visualizers.Utils
// value.InvokeMethod is nice for instance methods.
// what about MethodInfo.Invoke() ?
// also, there could be an overload that takes 1 parameter instead of array
string defaultHashCode = Eval.InvokeMethod(DebuggerHelpers.hashCodeMethod, null, new Value[]{value}).AsString;
Value defaultHashCode = Eval.InvokeMethod(DebuggerHelpers.hashCodeMethod, null, new Value[]{value});
//MethodInfo method = value.Type.GetMember("GetHashCode", BindingFlags.Method | BindingFlags.IncludeSuperType) as MethodInfo;
//string hashCode = value.InvokeMethod(method, null).AsString;
return int.Parse(defaultHashCode);
return (int)defaultHashCode.PrimitiveValue;
}
public static Value EvalPermanentReference(this Expression expr)

4
src/AddIns/Debugger/Debugger.Core/Exception.cs

@ -33,7 +33,7 @@ namespace Debugger @@ -33,7 +33,7 @@ namespace Debugger
public string Message {
get {
Value message = exception.GetMemberValue("_message");
return message.IsNull ? string.Empty : message.AsString;
return message.IsNull ? string.Empty : message.AsString();
}
}
@ -86,7 +86,7 @@ namespace Debugger @@ -86,7 +86,7 @@ namespace Debugger
// Note that evaluation is not possible after a stackoverflow exception
Value stackTrace = exception.GetMemberValue("StackTrace");
if (!stackTrace.IsNull) {
sb.Append(stackTrace.AsString);
sb.Append(stackTrace.AsString());
sb.AppendLine();
}
return sb.ToString();

2
src/AddIns/Debugger/Debugger.Core/Thread.cs

@ -156,7 +156,7 @@ namespace Debugger @@ -156,7 +156,7 @@ namespace Debugger
if (runtimeValue.IsNull) return string.Empty;
Value runtimeName = runtimeValue.GetMemberValue("m_Name");
if (runtimeName.IsNull) return string.Empty;
return runtimeName.AsString.ToString();
return runtimeName.AsString(100);
}
}

43
src/AddIns/Debugger/Debugger.Core/Value.cs

@ -114,7 +114,7 @@ namespace Debugger @@ -114,7 +114,7 @@ namespace Debugger
public bool IsInvalid {
get {
return corValue_pauseSession != this.Process.PauseSession &&
!(corValue is ICorDebugHandleValue);
!(corValue is ICorDebugHandleValue);
}
}
@ -149,12 +149,23 @@ namespace Debugger @@ -149,12 +149,23 @@ namespace Debugger
}
/// <summary> Gets a string representation of the value </summary>
public string AsString {
get {
if (this.IsNull) return "null";
if (this.Type.IsPrimitive) return PrimitiveValue.ToString();
if (this.Type.FullName == typeof(string).FullName) return PrimitiveValue.ToString();
return "{" + this.Type.FullName + "}";
/// <param name="maxLength">
/// The maximum length of the result string.
/// </param>
public string AsString(int maxLength = int.MaxValue)
{
if (this.IsNull) return "null";
if (this.Type.IsPrimitive || this.Type.FullName == typeof(string).FullName) {
string text = PrimitiveValue.ToString();
if (text != null && text.Length > maxLength)
text = text.Substring(0, Math.Max(0, maxLength - 3)) + "...";
return text;
} else {
string name = this.Type.FullName;
if (name != null && name.Length > maxLength)
return "{" + name.Substring(0, Math.Max(0, maxLength - 5)) + "...}";
else
return "{" + name + "}";
}
}
@ -251,7 +262,7 @@ namespace Debugger @@ -251,7 +262,7 @@ namespace Debugger
///
/// If setting of a value fails, NotSupportedException is thrown.
/// </summary>
public object PrimitiveValue {
public object PrimitiveValue {
get {
if (this.Type.FullName == typeof(string).FullName) {
if (this.IsNull) return null;
@ -302,7 +313,7 @@ namespace Debugger @@ -302,7 +313,7 @@ namespace Debugger
/// eg new object[4,5] returns 2
/// </summary>
/// <returns> 0 for non-arrays </returns>
public int ArrayRank {
public int ArrayRank {
get {
if (!this.Type.IsArray) return 0;
return (int)CorArrayValue.GetRank();
@ -476,7 +487,7 @@ namespace Debugger @@ -476,7 +487,7 @@ namespace Debugger
ICorDebugFrame curFrame = null;
if (process.IsPaused &&
process.SelectedThread != null &&
process.SelectedThread.MostRecentStackFrame != null &&
process.SelectedThread.MostRecentStackFrame != null &&
process.SelectedThread.MostRecentStackFrame.CorILFrame != null)
{
curFrame = process.SelectedThread.MostRecentStackFrame.CorILFrame;
@ -600,14 +611,14 @@ namespace Debugger @@ -600,14 +611,14 @@ namespace Debugger
}
/// <summary> Invoke the ToString() method </summary>
public string InvokeToString()
public string InvokeToString(int maxLength = int.MaxValue)
{
if (this.Type.IsPrimitive) return AsString;
if (this.Type.FullName == typeof(string).FullName) return AsString;
if (this.Type.IsPrimitive) return AsString(maxLength);
if (this.Type.FullName == typeof(string).FullName) return AsString(maxLength);
if (this.Type.IsPointer) return "0x" + this.PointerAddress.ToString("X");
// if (!IsObject) // Can invoke on primitives
DebugMethodInfo methodInfo = (DebugMethodInfo)this.AppDomain.ObjectType.GetMethod("ToString", new DebugType[] {});
return Eval.InvokeMethod(methodInfo, this, new Value[] {}).AsString;
return Eval.InvokeMethod(methodInfo, this, new Value[] {}).AsString(maxLength);
}
#region Convenience overload methods
@ -636,9 +647,7 @@ namespace Debugger @@ -636,9 +647,7 @@ namespace Debugger
public override string ToString()
{
return this.AsString;
return this.AsString();
}
}
}

Loading…
Cancel
Save