Browse Source

Changing Value class to work with the new metadata API.

Some bugfixes.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5108 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 17 years ago
parent
commit
33e0fbb591
  1. 1
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj
  2. 4
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/StackFrame.cs
  3. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Thread.cs
  4. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/Tests/IgnoreAttribute.cs
  5. 17
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/Tests/IgnoreOnExceptionAttribute.cs
  6. 20
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugMethodInfo.cs
  7. 10
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugPropertyInfo.cs
  8. 1
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugType.cs
  9. 1
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Values/Value.Array.cs
  10. 22
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Values/Value.Object.cs
  11. 17
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Values/Value.Primitive.cs
  12. 61
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Values/Value.cs

1
src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj

@ -90,6 +90,7 @@
<Compile Include="Src\Internal\MTA2STA.cs" /> <Compile Include="Src\Internal\MTA2STA.cs" />
<Compile Include="Src\Internal\Tests\ExpandAttribute.cs" /> <Compile Include="Src\Internal\Tests\ExpandAttribute.cs" />
<Compile Include="Src\Internal\Tests\IgnoreAttribute.cs" /> <Compile Include="Src\Internal\Tests\IgnoreAttribute.cs" />
<Compile Include="Src\Internal\Tests\IgnoreOnExceptionAttribute.cs" />
<Compile Include="Src\Interop\CorDebug\CorDebug.cs" /> <Compile Include="Src\Interop\CorDebug\CorDebug.cs" />
<Compile Include="Src\Interop\CorDebug\CorDebugChainReason.cs" /> <Compile Include="Src\Interop\CorDebug\CorDebugChainReason.cs" />
<Compile Include="Src\Interop\CorDebug\CorDebugClass.cs" /> <Compile Include="Src\Interop\CorDebug\CorDebugClass.cs" />

4
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/StackFrame.cs

@ -125,7 +125,8 @@ namespace Debugger
/// <summary> Returns diagnostic description of the frame </summary> /// <summary> Returns diagnostic description of the frame </summary>
public override string ToString() public override string ToString()
{ {
return this.MethodInfo.FullName; // TODO: Use full name
return this.MethodInfo.DeclaringType.FullName + "." + this.MethodInfo.Name;
} }
internal ICorDebugILFrame CorILFrame { internal ICorDebugILFrame CorILFrame {
@ -281,6 +282,7 @@ namespace Debugger
/// Gets the instance of the class asociated with the current frame. /// Gets the instance of the class asociated with the current frame.
/// That is, 'this' in C#. /// That is, 'this' in C#.
/// </summary> /// </summary>
[Debugger.Tests.Ignore]
public Value GetThisValue() public Value GetThisValue()
{ {
return new Value(appDomain, GetThisCorValue()); return new Value(appDomain, GetThisCorValue());

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Thread.cs

@ -269,6 +269,7 @@ namespace Debugger
/// <summary> Gets the whole callstack of the Thread. </summary> /// <summary> Gets the whole callstack of the Thread. </summary>
/// <remarks> If the thread is in invalid state returns empty array </remarks> /// <remarks> If the thread is in invalid state returns empty array </remarks>
[Debugger.Tests.Ignore]
public StackFrame[] GetCallstack() public StackFrame[] GetCallstack()
{ {
return new List<StackFrame>(CallstackEnum).ToArray(); return new List<StackFrame>(CallstackEnum).ToArray();
@ -332,6 +333,7 @@ namespace Debugger
return stackFrame; return stackFrame;
} }
[Debugger.Tests.Ignore]
public string GetStackTrace() public string GetStackTrace()
{ {
return GetStackTrace("at {0} in {1}:line {2}", "at {0}"); return GetStackTrace("at {0} in {1}:line {2}", "at {0}");

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/Tests/IgnoreAttribute.cs

@ -9,7 +9,7 @@ using System;
namespace Debugger.Tests namespace Debugger.Tests
{ {
[AttributeUsage(AttributeTargets.Property)] [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)]
public class IgnoreAttribute: Attribute public class IgnoreAttribute: Attribute
{ {

17
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/Tests/IgnoreOnExceptionAttribute.cs

@ -0,0 +1,17 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
// <version>$Revision$</version>
// </file>
using System;
namespace Debugger.Tests
{
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Method | AttributeTargets.Class)]
public class IgnoreOnExceptionAttribute: Attribute
{
}
}

20
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugMethodInfo.cs

@ -156,16 +156,17 @@ namespace Debugger.MetaData
// public virtual MethodInfo MakeGenericMethod(params Type[] typeArguments); // public virtual MethodInfo MakeGenericMethod(params Type[] typeArguments);
// public override bool ContainsGenericParameters { get; } // public override bool ContainsGenericParameters { get; }
public override Type ReturnType {
get {
if (this.MethodDefSig.RetType.Void) return null;
return DebugType.CreateFromSignature(this.DebugModule, this.MethodDefSig.RetType.Type, declaringType);
}
}
public override ParameterInfo ReturnParameter { public override ParameterInfo ReturnParameter {
get { get {
return new DebugParameterInfo( if (this.MethodDefSig.RetType.Void) return null;
this, return new DebugParameterInfo(this, string.Empty, this.ReturnType, -1);
string.Empty,
this.MethodDefSig.RetType.Void ?
null :
DebugType.CreateFromSignature(this.DebugModule, this.MethodDefSig.RetType.Type, declaringType),
-1
);
} }
} }
@ -596,7 +597,8 @@ namespace Debugger.MetaData
public override string ToString() public override string ToString()
{ {
return this.FullName; // TODO: Use full name
return this.Name;
} }
} }
} }

10
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugPropertyInfo.cs

@ -54,7 +54,7 @@ namespace Debugger.MetaData
[Debugger.Tests.Ignore] [Debugger.Tests.Ignore]
public override int MetadataToken { public override int MetadataToken {
get { return (getMethod ?? setMethod).MetadataToken; } get { return 0; }
} }
public override System.Reflection.Module Module { public override System.Reflection.Module Module {
@ -99,7 +99,13 @@ namespace Debugger.MetaData
} }
public override Type PropertyType { public override Type PropertyType {
get { return getMethod.ReturnType; } get {
if (getMethod != null) {
return getMethod.ReturnType;
} else {
return setMethod.GetParameters()[setMethod.GetParameters().Length - 1].ParameterType;
}
}
} }
public override MethodInfo[] GetAccessors(bool nonPublic) public override MethodInfo[] GetAccessors(bool nonPublic)

1
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/DebugType.cs

@ -26,6 +26,7 @@ namespace Debugger.MetaData
/// If two types are identical, the references to DebugType will also be identical /// If two types are identical, the references to DebugType will also be identical
/// Type will be loaded once per each appdomain. /// Type will be loaded once per each appdomain.
/// </remarks> /// </remarks>
[Debugger.Tests.IgnoreOnException]
public class DebugType: System.Type, IDebugMemberInfo public class DebugType: System.Type, IDebugMemberInfo
{ {
public const BindingFlags BindingFlagsAll = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance; public const BindingFlags BindingFlagsAll = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;

1
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Values/Value.Array.cs

@ -102,6 +102,7 @@ namespace Debugger
} }
/// <summary> Returns all elements in the array </summary> /// <summary> Returns all elements in the array </summary>
[Debugger.Tests.Ignore]
public Value[] GetArrayElements() public Value[] GetArrayElements()
{ {
List<Value> values = new List<Value>(); List<Value> values = new List<Value>();

22
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Values/Value.Object.cs

@ -21,19 +21,15 @@ namespace Debugger
get { get {
if (IsNull) throw new GetValueException("Value is null"); if (IsNull) throw new GetValueException("Value is null");
if (this.Type.IsClass) { ICorDebugValue corValue = this.CorValue;
return this.CorReferenceValue.Dereference().CastTo<ICorDebugObjectValue>(); // Dereference and unbox if necessary
} if (corValue.Is<ICorDebugReferenceValue>())
if (this.Type.IsValueType) { corValue = corValue.CastTo<ICorDebugReferenceValue>().Dereference();
if (this.CorValue.Is<ICorDebugReferenceValue>()) { if (corValue.Is<ICorDebugBoxValue>())
// Dereference and unbox return corValue.CastTo<ICorDebugBoxValue>().Object;
return this.CorReferenceValue.Dereference().CastTo<ICorDebugBoxValue>().Object; if (!corValue.Is<ICorDebugObjectValue>())
} else { throw new DebuggerException("Value is not an object");
return this.CorValue.CastTo<ICorDebugObjectValue>(); return corValue.CastTo<ICorDebugObjectValue>();
}
}
throw new DebuggerException("Value is not an object");
} }
} }

17
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Values/Value.Primitive.cs

@ -17,14 +17,17 @@ namespace Debugger
{ {
internal ICorDebugGenericValue CorGenericValue { internal ICorDebugGenericValue CorGenericValue {
get { get {
if (!this.Type.IsPrimitive && !this.Type.IsValueType) throw new DebuggerException("Value is not a 'generic'"); if (IsNull) throw new GetValueException("Value is null");
// Dereference and unbox ICorDebugValue corValue = this.CorValue;
if (this.CorValue.Is<ICorDebugReferenceValue>()) { // Dereference and unbox if necessary
return this.CorReferenceValue.Dereference().CastTo<ICorDebugBoxValue>().Object.CastTo<ICorDebugGenericValue>(); if (corValue.Is<ICorDebugReferenceValue>())
} else { corValue = corValue.CastTo<ICorDebugReferenceValue>().Dereference();
return this.CorValue.CastTo<ICorDebugGenericValue>(); if (corValue.Is<ICorDebugBoxValue>())
} corValue = corValue.CastTo<ICorDebugBoxValue>().Object.CastTo<ICorDebugValue>();
if (!corValue.Is<ICorDebugGenericValue>())
throw new DebuggerException("Value is not an generic value");
return corValue.CastTo<ICorDebugGenericValue>();
} }
} }

61
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Values/Value.cs

@ -24,7 +24,6 @@ namespace Debugger
public partial class Value: DebuggerObject public partial class Value: DebuggerObject
{ {
AppDomain appDomain; AppDomain appDomain;
Process process;
ICorDebugValue corValue; ICorDebugValue corValue;
PauseSession corValue_pauseSession; PauseSession corValue_pauseSession;
DebugType type; DebugType type;
@ -40,15 +39,9 @@ namespace Debugger
/// <summary> Gets a string representation of the value </summary> /// <summary> Gets a string representation of the value </summary>
public string AsString { public string AsString {
get { get {
if (this.IsNull) return "null"; if (this.IsNull) return "null";
if (this.Type.IsArray) return "{" + this.Type.FullName + "}";
if (this.Type.IsClass) return "{" + this.Type.FullName + "}";
if (this.Type.IsValueType) return "{" + this.Type.FullName + "}";
if (this.Type.IsPrimitive) return PrimitiveValue.ToString(); if (this.Type.IsPrimitive) return PrimitiveValue.ToString();
// Does not work well with unit tests: (variable value) return "{" + this.Type.FullName + "}";
// if (this.Type.IsPointer) return "0x" + this.CorValue.CastTo<ICorDebugReferenceValue>().Address.ToString("X8");
if (this.Type.IsPointer) return "{" + this.Type.FullName + "}";
throw new DebuggerException("Unknown type");
} }
} }
@ -60,14 +53,14 @@ namespace Debugger
[Debugger.Tests.Ignore] [Debugger.Tests.Ignore]
public Process Process { public Process Process {
get { return process; } get { return appDomain.Process; }
} }
/// <summary> Returns true if the Value can not be used anymore. /// <summary> Returns true if the Value can not be used anymore.
/// Value is valid only until the debuggee is resummed. </summary> /// Value is valid only until the debuggee is resummed. </summary>
public bool IsInvalid { public bool IsInvalid {
get { get {
return corValue_pauseSession != process.PauseSession && return corValue_pauseSession != this.Process.PauseSession &&
!corValue.Is<ICorDebugHandleValue>(); !corValue.Is<ICorDebugHandleValue>();
} }
} }
@ -75,18 +68,16 @@ namespace Debugger
[Tests.Ignore] [Tests.Ignore]
public ICorDebugValue CorValue { public ICorDebugValue CorValue {
get { get {
if (this.IsInvalid) { if (this.IsInvalid)
throw new GetValueException("Value is no longer valid"); throw new GetValueException("Value is no longer valid");
}
return corValue; return corValue;
} }
} }
ICorDebugReferenceValue CorReferenceValue { ICorDebugReferenceValue CorReferenceValue {
get { get {
if (!this.IsReference) throw new DebuggerException("Reference value expected"); if (!this.CorValue.Is<ICorDebugReferenceValue>())
throw new DebuggerException("Reference value expected");
return this.CorValue.CastTo<ICorDebugReferenceValue>(); return this.CorValue.CastTo<ICorDebugReferenceValue>();
} }
} }
@ -96,9 +87,7 @@ namespace Debugger
/// </summary> /// </summary>
[Debugger.Tests.IgnoreAttribute] [Debugger.Tests.IgnoreAttribute]
public ulong Address { public ulong Address {
get { get { return corValue.Address; }
return corValue.Address;
}
} }
/// <summary> Gets value indication whether the value is a reference </summary> /// <summary> Gets value indication whether the value is a reference </summary>
@ -129,32 +118,25 @@ namespace Debugger
return newValue; return newValue;
} }
[Debugger.Tests.Ignore]
public Value GetPermanentReference() public Value GetPermanentReference()
{ {
ICorDebugValue corValue = this.CorValue; if (this.CorValue.Is<ICorDebugHandleValue>()) {
if (this.Type.IsClass) { return this;
corValue = this.CorObjectValue.CastTo<ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo<ICorDebugValue>(); } else if (this.CorValue.Is<ICorDebugReferenceValue>()) {
} return new Value(appDomain, this.CorValue.CastTo<ICorDebugReferenceValue>().Dereference().CastTo<ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo<ICorDebugValue>());
if (this.Type.IsValueType || this.Type.IsPrimitive) { } else {
if (!corValue.Is<ICorDebugReferenceValue>()) { return this.Box();
return this.Box();
} else {
// Make the reference to box permanent
corValue = corValue.CastTo<ICorDebugReferenceValue>().Dereference().CastTo<ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo<ICorDebugValue>();
}
} }
return new Value(appDomain, corValue);
} }
internal Value(AppDomain appDomain, ICorDebugValue corValue) internal Value(AppDomain appDomain, ICorDebugValue corValue)
{ {
if (corValue == null) { if (corValue == null)
throw new ArgumentNullException("corValue"); throw new ArgumentNullException("corValue");
}
this.appDomain = appDomain; this.appDomain = appDomain;
this.process = appDomain.Process;
this.corValue = corValue; this.corValue = corValue;
this.corValue_pauseSession = process.PauseSession; this.corValue_pauseSession = this.Process.PauseSession;
if (corValue.Is<ICorDebugReferenceValue>() && if (corValue.Is<ICorDebugReferenceValue>() &&
corValue.CastTo<ICorDebugReferenceValue>().Value == 0 && corValue.CastTo<ICorDebugReferenceValue>().Value == 0 &&
@ -171,9 +153,7 @@ namespace Debugger
/// <summary> Returns the <see cref="Debugger.DebugType"/> of the value </summary> /// <summary> Returns the <see cref="Debugger.DebugType"/> of the value </summary>
public DebugType Type { public DebugType Type {
get { get { return type; }
return type;
}
} }
[Tests.Ignore] [Tests.Ignore]
@ -202,10 +182,9 @@ namespace Debugger
{ {
ICorDebugValue newCorValue = newValue.CorValue; ICorDebugValue newCorValue = newValue.CorValue;
if (this.IsReference) { if (this.CorValue.Is<ICorDebugReferenceValue>()) {
if (!newCorValue.Is<ICorDebugReferenceValue>()) { if (!newCorValue.Is<ICorDebugReferenceValue>())
newCorValue = newValue.Box().CorValue; newCorValue = newValue.Box().CorValue;
}
corValue.CastTo<ICorDebugReferenceValue>().SetValue(newCorValue.CastTo<ICorDebugReferenceValue>().Value); corValue.CastTo<ICorDebugReferenceValue>().SetValue(newCorValue.CastTo<ICorDebugReferenceValue>().Value);
} else { } else {
corValue.CastTo<ICorDebugGenericValue>().RawValue = newValue.CorGenericValue.RawValue; corValue.CastTo<ICorDebugGenericValue>().RawValue = newValue.CorGenericValue.RawValue;

Loading…
Cancel
Save