Browse Source

Removed the Is<T>, As<T> and CastTo<T> helper methods

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5144 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 16 years ago
parent
commit
4c8be8219e
  1. 41
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/ICorDebug.cs
  2. 2
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Utils/DebuggerHelpers.cs
  3. 8
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/AppDomain.cs
  4. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoint.cs
  5. 20
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Eval.cs
  6. 8
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs
  7. 8
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs
  8. 18
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/CorDebugExtensionMethods.cs
  9. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/MetaData/DebugMethodInfo.cs
  10. 10
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/MetaData/DebugType.cs
  11. 37
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Module.cs
  12. 6
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/StackFrame.cs
  13. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Stepper.cs
  14. 12
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Thread.cs
  15. 91
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Value.cs

41
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/ICorDebug.cs

@ -58,16 +58,16 @@ namespace Debugger.AddIn.TreeModel @@ -58,16 +58,16 @@ namespace Debugger.AddIn.TreeModel
{
List<TreeNode> items = new List<TreeNode>();
if (corValue.Is<ICorDebugValue>()) {
if (corValue is ICorDebugValue) {
InfoNode info = new InfoNode("ICorDebugValue", "");
info.AddChild("Address", corValue.GetAddress().ToString("X8"));
info.AddChild("Type", ((CorElementType)corValue.GetTheType()).ToString());
info.AddChild("Size", corValue.GetSize().ToString());
items.Add(info);
}
if (corValue.Is<ICorDebugValue2>()) {
if (corValue is ICorDebugValue2) {
InfoNode info = new InfoNode("ICorDebugValue2", "");
ICorDebugValue2 corValue2 = corValue.CastTo<ICorDebugValue2>();
ICorDebugValue2 corValue2 = (ICorDebugValue2)corValue;
string fullname;
try {
fullname = DebugType.CreateFromCorType(appDomain, corValue2.GetExactType()).FullName;
@ -77,10 +77,10 @@ namespace Debugger.AddIn.TreeModel @@ -77,10 +77,10 @@ namespace Debugger.AddIn.TreeModel
info.AddChild("ExactType", fullname);
items.Add(info);
}
if (corValue.Is<ICorDebugGenericValue>()) {
if (corValue is ICorDebugGenericValue) {
InfoNode info = new InfoNode("ICorDebugGenericValue", "");
try {
byte[] bytes = corValue.CastTo<ICorDebugGenericValue>().GetRawValue();
byte[] bytes = ((ICorDebugGenericValue)corValue).GetRawValue();
for(int i = 0; i < bytes.Length; i += 8) {
string val = "";
for(int j = i; j < bytes.Length && j < i + 8; j++) {
@ -93,9 +93,9 @@ namespace Debugger.AddIn.TreeModel @@ -93,9 +93,9 @@ namespace Debugger.AddIn.TreeModel
}
items.Add(info);
}
if (corValue.Is<ICorDebugReferenceValue>()) {
if (corValue is ICorDebugReferenceValue) {
InfoNode info = new InfoNode("ICorDebugReferenceValue", "");
ICorDebugReferenceValue refValue = corValue.CastTo<ICorDebugReferenceValue>();
ICorDebugReferenceValue refValue = (ICorDebugReferenceValue)corValue;
info.AddChild("IsNull", (refValue.IsNull() != 0).ToString());
if (refValue.IsNull() == 0) {
info.AddChild("Value", refValue.GetValue().ToString("X8"));
@ -104,50 +104,49 @@ namespace Debugger.AddIn.TreeModel @@ -104,50 +104,49 @@ namespace Debugger.AddIn.TreeModel
} else {
info.AddChild("Dereference", "N/A");
}
}
items.Add(info);
}
if (corValue.Is<ICorDebugHeapValue>()) {
if (corValue is ICorDebugHeapValue) {
InfoNode info = new InfoNode("ICorDebugHeapValue", "");
items.Add(info);
}
if (corValue.Is<ICorDebugHeapValue2>()) {
if (corValue is ICorDebugHeapValue2) {
InfoNode info = new InfoNode("ICorDebugHeapValue2", "");
items.Add(info);
}
if (corValue.Is<ICorDebugObjectValue>()) {
if (corValue is ICorDebugObjectValue) {
InfoNode info = new InfoNode("ICorDebugObjectValue", "");
ICorDebugObjectValue objValue = corValue.CastTo<ICorDebugObjectValue>();
ICorDebugObjectValue objValue = (ICorDebugObjectValue)corValue;
info.AddChild("Class", objValue.GetClass().GetToken().ToString("X8"));
info.AddChild("IsValueClass", (objValue.IsValueClass() != 0).ToString());
items.Add(info);
}
if (corValue.Is<ICorDebugObjectValue2>()) {
if (corValue is ICorDebugObjectValue2) {
InfoNode info = new InfoNode("ICorDebugObjectValue2", "");
items.Add(info);
}
if (corValue.Is<ICorDebugBoxValue>()) {
if (corValue is ICorDebugBoxValue) {
InfoNode info = new InfoNode("ICorDebugBoxValue", "");
ICorDebugBoxValue boxValue = corValue.CastTo<ICorDebugBoxValue>();
info.AddChild("Object", "", GetDebugInfo(appDomain, boxValue.GetObject().CastTo<ICorDebugValue>()));
ICorDebugBoxValue boxValue = (ICorDebugBoxValue)corValue;
info.AddChild("Object", "", GetDebugInfo(appDomain, boxValue.GetObject()));
items.Add(info);
}
if (corValue.Is<ICorDebugStringValue>()) {
if (corValue is ICorDebugStringValue) {
InfoNode info = new InfoNode("ICorDebugStringValue", "");
ICorDebugStringValue stringValue = corValue.CastTo<ICorDebugStringValue>();
ICorDebugStringValue stringValue = (ICorDebugStringValue)corValue;
info.AddChild("Length", stringValue.GetLength().ToString());
info.AddChild("String", stringValue.GetString());
items.Add(info);
}
if (corValue.Is<ICorDebugArrayValue>()) {
if (corValue is ICorDebugArrayValue) {
InfoNode info = new InfoNode("ICorDebugArrayValue", "");
info.AddChild("...", "...");
items.Add(info);
}
if (corValue.Is<ICorDebugHandleValue>()) {
if (corValue is ICorDebugHandleValue) {
InfoNode info = new InfoNode("ICorDebugHandleValue", "");
ICorDebugHandleValue handleValue = corValue.CastTo<ICorDebugHandleValue>();
ICorDebugHandleValue handleValue = (ICorDebugHandleValue)corValue;
info.AddChild("HandleType", handleValue.GetHandleType().ToString());
items.Add(info);
}

2
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Visualizers/Utils/DebuggerHelpers.cs

@ -39,7 +39,7 @@ namespace Debugger.AddIn.Visualizers.Utils @@ -39,7 +39,7 @@ namespace Debugger.AddIn.Visualizers.Utils
/// </summary>
public static ulong GetObjectAddress(this Value val)
{
ICorDebugReferenceValue refVal = val.CorValue.CastTo<ICorDebugReferenceValue>();
ICorDebugReferenceValue refVal = val.CorReferenceValue;
return refVal.GetValue();
}

8
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/AppDomain.cs

@ -74,9 +74,11 @@ namespace Debugger @@ -74,9 +74,11 @@ namespace Debugger
}
internal ICorDebugAppDomain CorAppDomain {
get {
return corAppDomain;
}
get { return corAppDomain; }
}
internal ICorDebugAppDomain2 CorAppDomain2 {
get { return (ICorDebugAppDomain2)corAppDomain; }
}
public AppDomain(Process process, ICorDebugAppDomain corAppDomain)

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoint.cs

@ -103,7 +103,7 @@ namespace Debugger @@ -103,7 +103,7 @@ namespace Debugger
internal bool IsOwnerOf(ICorDebugBreakpoint breakpoint)
{
foreach(ICorDebugFunctionBreakpoint corFunBreakpoint in corBreakpoints) {
if (corFunBreakpoint.CastTo<ICorDebugBreakpoint>().Equals(breakpoint)) return true;
if (((ICorDebugBreakpoint)corFunBreakpoint).Equals(breakpoint)) return true;
}
return false;
}

20
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Eval.cs

@ -49,9 +49,13 @@ namespace Debugger @@ -49,9 +49,13 @@ namespace Debugger
get { return description; }
}
ICorDebugEval CorEval {
public ICorDebugEval CorEval {
get { return corEval; }
}
public ICorDebugEval2 CorEval2 {
get { return (ICorDebugEval2)corEval; }
}
/// <exception cref="GetValueException">Evaluating...</exception>
public Value Result {
@ -153,11 +157,11 @@ namespace Debugger @@ -153,11 +157,11 @@ namespace Debugger
if (!Evaluated) {
state = EvalState.EvaluatedTimeOut;
process.TraceMessage("Aboring eval: " + Description);
corEval.Abort();
this.CorEval.Abort();
process.WaitForPause(TimeSpan.FromMilliseconds(500));
if (!Evaluated) {
process.TraceMessage("Rude aboring eval: " + Description);
corEval.CastTo<ICorDebugEval2>().RudeAbort();
this.CorEval2.RudeAbort();
process.WaitForPause(TimeSpan.FromMilliseconds(500));
if (!Evaluated) {
throw new DebuggerException("Evaluation can not be stopped");
@ -231,7 +235,7 @@ namespace Debugger @@ -231,7 +235,7 @@ namespace Debugger
for(int i = 0; i < args.Length; i++) {
// It is importatnt to pass the parameted in the correct form (boxed/unboxed)
if (method.GetParameters()[i].ParameterType.IsValueType) {
corArgs.Add(args[i].CorGenericValue.CastTo<ICorDebugValue>());
corArgs.Add(args[i].CorGenericValue);
} else {
if (args[i].Type.IsValueType) {
corArgs.Add(args[i].Box().CorValue);
@ -242,7 +246,7 @@ namespace Debugger @@ -242,7 +246,7 @@ namespace Debugger
}
ICorDebugType[] genericArgs = ((DebugType)method.DeclaringType).GenericArgumentsAsCorDebugType;
eval.CorEval.CastTo<ICorDebugEval2>().CallParameterizedFunction(
eval.CorEval2.CallParameterizedFunction(
method.CorFunction,
(uint)genericArgs.Length, genericArgs,
(uint)corArgs.Count, corArgs.ToArray()
@ -307,7 +311,7 @@ namespace Debugger @@ -307,7 +311,7 @@ namespace Debugger
appDomain,
"New string: " + textToCreate,
delegate(Eval eval) {
eval.CorEval.CastTo<ICorDebugEval2>().NewStringWithLength(textToCreate, (uint)textToCreate.Length);
eval.CorEval2.NewStringWithLength(textToCreate, (uint)textToCreate.Length);
}
);
}
@ -337,7 +341,7 @@ namespace Debugger @@ -337,7 +341,7 @@ namespace Debugger
debugType.AppDomain,
"New object: " + debugType.FullName,
delegate(Eval eval) {
eval.CorEval.CastTo<ICorDebugEval2>().NewParameterizedObject(
eval.CorEval2.NewParameterizedObject(
constructor.CorFunction, (uint)debugType.GetGenericArguments().Length, debugType.GenericArgumentsAsCorDebugType,
(uint)constructorArgsCorDebug.Length, constructorArgsCorDebug);
}
@ -350,7 +354,7 @@ namespace Debugger @@ -350,7 +354,7 @@ namespace Debugger
debugType.AppDomain,
"New object: " + debugType.FullName,
delegate(Eval eval) {
eval.CorEval.CastTo<ICorDebugEval2>().NewParameterizedObjectNoConstructor(debugType.CorType.GetClass(), (uint)debugType.GetGenericArguments().Length, debugType.GenericArgumentsAsCorDebugType);
eval.CorEval2.NewParameterizedObjectNoConstructor(debugType.CorType.GetClass(), (uint)debugType.GetGenericArguments().Length, debugType.GenericArgumentsAsCorDebugType);
}
);
}

8
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs

@ -522,10 +522,10 @@ namespace Debugger.Internal @@ -522,10 +522,10 @@ namespace Debugger.Internal
/// <exception cref="Exception">Unknown callback argument</exception>
public void MDANotification(ICorDebugController c, ICorDebugThread t, ICorDebugMDA mda)
{
if (c.Is<ICorDebugAppDomain>()) {
EnterCallback(PausedReason.Other, "MDANotification", c.CastTo<ICorDebugAppDomain>());
} else if (c.Is<ICorDebugProcess>()){
EnterCallback(PausedReason.Other, "MDANotification", c.CastTo<ICorDebugProcess>());
if (c is ICorDebugAppDomain) {
EnterCallback(PausedReason.Other, "MDANotification", (ICorDebugAppDomain)c);
} else if (c is ICorDebugProcess){
EnterCallback(PausedReason.Other, "MDANotification", (ICorDebugProcess)c);
} else {
throw new System.Exception("Unknown callback argument");
}

8
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs

@ -39,10 +39,10 @@ namespace Debugger.Internal @@ -39,10 +39,10 @@ namespace Debugger.Internal
public ManagedCallback GetProcessCallbackInterface(string name, ICorDebugController c)
{
if (c.Is<ICorDebugAppDomain>()) {
return GetProcessCallbackInterface(name, c.CastTo<ICorDebugAppDomain>());
} else if (c.Is<ICorDebugProcess>()){
return GetProcessCallbackInterface(name, c.CastTo<ICorDebugProcess>());
if (c is ICorDebugAppDomain) {
return GetProcessCallbackInterface(name, (ICorDebugAppDomain)c);
} else if (c is ICorDebugProcess){
return GetProcessCallbackInterface(name, (ICorDebugProcess)c);
} else {
throw new System.Exception("Unknown callback argument");
}

18
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Interop/CorDebugExtensionMethods.cs

@ -13,24 +13,6 @@ namespace Debugger.Interop.CorDebug @@ -13,24 +13,6 @@ namespace Debugger.Interop.CorDebug
{
public static partial class CorDebugExtensionMethods
{
// TODO: Remove
public static T CastTo<T>(this object obj)
{
return (T)obj;
}
// TODO: Remove
public static bool Is<T>(this object obj)
{
return obj is T;
}
// TODO: Remove
public static T As<T>(this object obj) where T:class
{
return obj as T;
}
static void ProcessOutParameter(object parameter)
{
TrackedComObjects.ProcessOutParameter(parameter);

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/MetaData/DebugMethodInfo.cs

@ -449,7 +449,7 @@ namespace Debugger.MetaData @@ -449,7 +449,7 @@ namespace Debugger.MetaData
internal void MarkAsNonUserCode()
{
this.CorFunction.CastTo<ICorDebugFunction2>().SetJMCStatus(0 /* false */);
((ICorDebugFunction2)this.CorFunction).SetJMCStatus(0 /* false */);
if (this.Process.Options.Verbose) {
this.Process.TraceMessage("Funciton {0} marked as non-user code", this.FullName);

10
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/MetaData/DebugType.cs

@ -886,28 +886,28 @@ namespace Debugger.MetaData @@ -886,28 +886,28 @@ namespace Debugger.MetaData
/// <inheritdoc/>
public override Type MakeArrayType(int rank)
{
ICorDebugType res = this.AppDomain.CorAppDomain.CastTo<ICorDebugAppDomain2>().GetArrayOrPointerType((uint)CorElementType.ARRAY, (uint)rank, this.CorType);
ICorDebugType res = this.AppDomain.CorAppDomain2.GetArrayOrPointerType((uint)CorElementType.ARRAY, (uint)rank, this.CorType);
return CreateFromCorType(this.AppDomain, res);
}
/// <inheritdoc/>
public override Type MakeArrayType()
{
ICorDebugType res = this.AppDomain.CorAppDomain.CastTo<ICorDebugAppDomain2>().GetArrayOrPointerType((uint)CorElementType.SZARRAY, 1, this.CorType);
ICorDebugType res = this.AppDomain.CorAppDomain2.GetArrayOrPointerType((uint)CorElementType.SZARRAY, 1, this.CorType);
return CreateFromCorType(this.AppDomain, res);
}
/// <inheritdoc/>
public override Type MakePointerType()
{
ICorDebugType res = this.AppDomain.CorAppDomain.CastTo<ICorDebugAppDomain2>().GetArrayOrPointerType((uint)CorElementType.PTR, 0, this.CorType);
ICorDebugType res = this.AppDomain.CorAppDomain2.GetArrayOrPointerType((uint)CorElementType.PTR, 0, this.CorType);
return CreateFromCorType(this.AppDomain, res);
}
/// <inheritdoc/>
public override Type MakeByRefType()
{
ICorDebugType res = this.AppDomain.CorAppDomain.CastTo<ICorDebugAppDomain2>().GetArrayOrPointerType((uint)CorElementType.BYREF, 0, this.CorType);
ICorDebugType res = this.AppDomain.CorAppDomain2.GetArrayOrPointerType((uint)CorElementType.BYREF, 0, this.CorType);
return CreateFromCorType(this.AppDomain, res);
}
@ -940,7 +940,7 @@ namespace Debugger.MetaData @@ -940,7 +940,7 @@ namespace Debugger.MetaData
corGenArgs.Add(genAgr.CorType);
}
ICorDebugType corType = corClass.CastTo<ICorDebugClass2>().GetParameterizedType((uint)(valueType.Value ? CorElementType.VALUETYPE : CorElementType.CLASS), corGenArgs.ToArray());
ICorDebugType corType = ((ICorDebugClass2)corClass).GetParameterizedType((uint)(valueType.Value ? CorElementType.VALUETYPE : CorElementType.CLASS), corGenArgs.ToArray());
return CreateFromCorType(appDomain, corType);
}

37
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Module.cs

@ -82,27 +82,31 @@ namespace Debugger @@ -82,27 +82,31 @@ namespace Debugger
}
}
[Debugger.Tests.Ignore]
public ICorDebugModule CorModule {
get {
return corModule;
}
get { return corModule; }
}
[Debugger.Tests.Ignore]
public ICorDebugModule2 CorModule2 {
get { return (ICorDebugModule2)corModule; }
}
public ulong BaseAdress {
get {
return corModule.GetBaseAddress();
return this.CorModule.GetBaseAddress();
}
}
public bool IsDynamic {
get {
return corModule.IsDynamic() == 1;
return this.CorModule.IsDynamic() == 1;
}
}
public bool IsInMemory {
get {
return corModule.IsInMemory() == 1;
return this.CorModule.IsInMemory() == 1;
}
}
@ -172,16 +176,15 @@ namespace Debugger @@ -172,16 +176,15 @@ namespace Debugger
return names;
}
internal Module(AppDomain appDomain, ICorDebugModule pModule)
internal Module(AppDomain appDomain, ICorDebugModule corModule)
{
this.appDomain = appDomain;
this.process = appDomain.Process;
this.corModule = corModule;
corModule = pModule;
metaData = new MetaDataImport(corModule);
metaData = new MetaDataImport(pModule);
fullPath = pModule.GetName();
fullPath = corModule.GetName();
LoadSymbols(process.Options.SymbolsSearchPaths);
@ -202,7 +205,7 @@ namespace Debugger @@ -202,7 +205,7 @@ namespace Debugger
public void UpdateSymbolsFromStream(IStream pSymbolStream)
{
if (symReader != null) {
symReader.As<ISymUnmanagedDispose>().Destroy();
((ISymUnmanagedDispose)symReader).Destroy();
}
symReader = metaData.GetSymReader(pSymbolStream);
@ -218,24 +221,22 @@ namespace Debugger @@ -218,24 +221,22 @@ namespace Debugger
uint unused = 0;
if (process.Options.StepOverNoSymbols && !this.HasSymbols) {
// Optimization - set the code as non-user right away
corModule.CastTo<ICorDebugModule2>().SetJMCStatus(0, 0, ref unused);
this.CorModule2.SetJMCStatus(0, 0, ref unused);
return;
}
corModule.CastTo<ICorDebugModule2>().SetJMCStatus(1, 0, ref unused);
this.CorModule2.SetJMCStatus(1, 0, ref unused);
}
public void ApplyChanges(byte[] metadata, byte[] il)
{
if (corModule.Is<ICorDebugModule2>()) { // Is the debuggee .NET 2.0?
(corModule.CastTo<ICorDebugModule2>()).ApplyChanges((uint)metadata.Length, metadata, (uint)il.Length, il);
}
this.CorModule2.ApplyChanges((uint)metadata.Length, metadata, (uint)il.Length, il);
}
public void Dispose()
{
metaData.Dispose();
if (symReader != null) {
symReader.As<ISymUnmanagedDispose>().Destroy();
((ISymUnmanagedDispose)symReader).Destroy();
}
unloaded = true;

6
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/StackFrame.cs

@ -97,7 +97,7 @@ namespace Debugger @@ -97,7 +97,7 @@ namespace Debugger
MetaDataImport metaData = thread.Process.Modules[corFunction.GetClass().GetModule()].MetaData;
int methodGenArgs = metaData.GetGenericParamCount(corFunction.GetToken());
// Class parameters are first, then the method ones
List<ICorDebugType> corGenArgs = corILFrame.CastTo<ICorDebugILFrame2>().EnumerateTypeParameters().ToList();
List<ICorDebugType> corGenArgs = ((ICorDebugILFrame2)corILFrame).EnumerateTypeParameters().ToList();
// Remove method parametrs at the end
corGenArgs.RemoveRange(corGenArgs.Count - methodGenArgs, methodGenArgs);
List<DebugType> genArgs = new List<DebugType>(corGenArgs.Count);
@ -293,7 +293,7 @@ namespace Debugger @@ -293,7 +293,7 @@ namespace Debugger
}
// This can be 'by ref' for value types
if (corValue.GetTheType() == (uint)CorElementType.BYREF) {
corValue = corValue.CastTo<ICorDebugReferenceValue>().Dereference();
corValue = ((ICorDebugReferenceValue)corValue).Dereference();
}
return corValue;
}
@ -342,7 +342,7 @@ namespace Debugger @@ -342,7 +342,7 @@ namespace Debugger
// Method arguments can be passed 'by ref'
if (corValue.GetTheType() == (uint)CorElementType.BYREF) {
try {
corValue = corValue.CastTo<ICorDebugReferenceValue>().Dereference();
corValue = ((ICorDebugReferenceValue)corValue).Dereference();
} catch (COMException e) {
if ((uint)e.ErrorCode == 0x80131305) {
// A reference value was found to be bad during dereferencing.

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Stepper.cs

@ -62,7 +62,7 @@ namespace Debugger @@ -62,7 +62,7 @@ namespace Debugger
if (justMyCode) {
corStepper.SetUnmappedStopMask(CorDebugUnmappedStop.STOP_NONE);
corStepper.CastTo<ICorDebugStepper2>().SetJMC(1);
((ICorDebugStepper2)corStepper).SetJMC(1);
}
}

12
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Thread.cs

@ -221,14 +221,14 @@ namespace Debugger @@ -221,14 +221,14 @@ namespace Debugger
/// if it can not be intercepted. </returns>
public bool InterceptCurrentException()
{
if (!this.CorThread.Is<ICorDebugThread2>()) return false; // Is the debuggee .NET 2.0?
if (!(this.CorThread is ICorDebugThread2)) return false; // Is the debuggee .NET 2.0?
if (this.CorThread.GetCurrentException() == null) return false; // Is there any exception
if (this.MostRecentStackFrame == null) return false; // Is frame available? It is not at StackOverflow
try {
// Interception will expire the CorValue so keep permanent reference
currentException.MakeValuePermanent();
this.CorThread.CastTo<ICorDebugThread2>().InterceptCurrentException(this.MostRecentStackFrame.CorILFrame.CastTo<ICorDebugFrame>());
((ICorDebugThread2)this.CorThread).InterceptCurrentException(this.MostRecentStackFrame.CorILFrame);
} catch (COMException e) {
// 0x80131C02: Cannot intercept this exception
if ((uint)e.ErrorCode == 0x80131C02) {
@ -299,10 +299,10 @@ namespace Debugger @@ -299,10 +299,10 @@ namespace Debugger
uint corFrameIndex = corChain.EnumerateFrames().GetCount();
foreach(ICorDebugFrame corFrame in corChain.EnumerateFrames().GetEnumerator()) {
corFrameIndex--;
if (!corFrame.Is<ICorDebugILFrame>()) continue; // Only IL frames
if (!(corFrame is ICorDebugILFrame)) continue; // Only IL frames
StackFrame stackFrame;
try {
stackFrame = new StackFrame(this, corFrame.CastTo<ICorDebugILFrame>(), corChainIndex, corFrameIndex);
stackFrame = new StackFrame(this, (ICorDebugILFrame)corFrame, corChainIndex, corFrameIndex);
} catch (COMException) { // TODO
continue;
};
@ -328,9 +328,9 @@ namespace Debugger @@ -328,9 +328,9 @@ namespace Debugger
corFrameEnum.Skip(corFrameEnum.GetCount() - frameIndex - 1);
ICorDebugFrame corFrame = corFrameEnum.Next();
if (!corFrame.Is<ICorDebugILFrame>()) throw new DebuggerException("The rquested frame is not IL frame");
if (!(corFrame is ICorDebugILFrame)) throw new DebuggerException("The rquested frame is not IL frame");
StackFrame stackFrame = new StackFrame(this, corFrame.CastTo<ICorDebugILFrame>(), chainIndex, frameIndex);
StackFrame stackFrame = new StackFrame(this, (ICorDebugILFrame)corFrame, chainIndex, frameIndex);
return stackFrame;
}

91
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Value.cs

@ -47,52 +47,56 @@ namespace Debugger @@ -47,52 +47,56 @@ namespace Debugger
}
}
ICorDebugReferenceValue CorReferenceValue {
[Debugger.Tests.Ignore]
public ICorDebugReferenceValue CorReferenceValue {
get {
if (!this.CorValue.Is<ICorDebugReferenceValue>())
if (!(this.CorValue is ICorDebugReferenceValue))
throw new DebuggerException("Reference value expected");
return this.CorValue.CastTo<ICorDebugReferenceValue>();
return (ICorDebugReferenceValue)this.CorValue;
}
}
internal ICorDebugGenericValue CorGenericValue {
[Debugger.Tests.Ignore]
public ICorDebugGenericValue CorGenericValue {
get {
if (IsNull) throw new GetValueException("Value is null");
ICorDebugValue corValue = this.CorValue;
// Dereference and unbox if necessary
if (corValue.Is<ICorDebugReferenceValue>())
corValue = corValue.CastTo<ICorDebugReferenceValue>().Dereference();
if (corValue.Is<ICorDebugBoxValue>())
corValue = corValue.CastTo<ICorDebugBoxValue>().GetObject().CastTo<ICorDebugValue>();
if (!corValue.Is<ICorDebugGenericValue>())
if (corValue is ICorDebugReferenceValue)
corValue = ((ICorDebugReferenceValue)corValue).Dereference();
if (corValue is ICorDebugBoxValue)
corValue = ((ICorDebugBoxValue)corValue).GetObject();
if (!(corValue is ICorDebugGenericValue))
throw new DebuggerException("Value is not an generic value");
return corValue.CastTo<ICorDebugGenericValue>();
return (ICorDebugGenericValue)corValue;
}
}
ICorDebugArrayValue CorArrayValue {
[Debugger.Tests.Ignore]
public ICorDebugArrayValue CorArrayValue {
get {
if (IsNull) throw new GetValueException("Value is null");
if (!this.Type.IsArray) throw new DebuggerException("Value is not an array");
return this.CorReferenceValue.Dereference().CastTo<ICorDebugArrayValue>();
return (ICorDebugArrayValue)this.CorReferenceValue.Dereference();
}
}
internal ICorDebugObjectValue CorObjectValue {
[Debugger.Tests.Ignore]
public ICorDebugObjectValue CorObjectValue {
get {
if (IsNull) throw new GetValueException("Value is null");
ICorDebugValue corValue = this.CorValue;
// Dereference and unbox if necessary
if (corValue.Is<ICorDebugReferenceValue>())
corValue = corValue.CastTo<ICorDebugReferenceValue>().Dereference();
if (corValue.Is<ICorDebugBoxValue>())
return corValue.CastTo<ICorDebugBoxValue>().GetObject();
if (!corValue.Is<ICorDebugObjectValue>())
if (corValue is ICorDebugReferenceValue)
corValue = ((ICorDebugReferenceValue)corValue).Dereference();
if (corValue is ICorDebugBoxValue)
return ((ICorDebugBoxValue)corValue).GetObject();
if (!(corValue is ICorDebugObjectValue))
throw new DebuggerException("Value is not an object");
return corValue.CastTo<ICorDebugObjectValue>();
return (ICorDebugObjectValue)corValue;
}
}
@ -106,7 +110,7 @@ namespace Debugger @@ -106,7 +110,7 @@ namespace Debugger
public bool IsInvalid {
get {
return corValue_pauseSession != this.Process.PauseSession &&
!corValue.Is<ICorDebugHandleValue>();
!(corValue is ICorDebugHandleValue);
}
}
@ -114,15 +118,15 @@ namespace Debugger @@ -114,15 +118,15 @@ namespace Debugger
/// <remarks> Value types also return true if they are boxed </remarks>
public bool IsReference {
get {
return this.CorValue.Is<ICorDebugReferenceValue>();
return this.CorValue is ICorDebugReferenceValue;
}
}
/// <summary> Returns true if the value is null </summary>
public bool IsNull {
get {
return this.CorValue.Is<ICorDebugReferenceValue>() &&
this.CorValue.CastTo<ICorDebugReferenceValue>().IsNull() != 0;
return this.CorValue is ICorDebugReferenceValue &&
((ICorDebugReferenceValue)this.CorValue).IsNull() != 0;
}
}
@ -137,8 +141,9 @@ namespace Debugger @@ -137,8 +141,9 @@ namespace Debugger
[Debugger.Tests.Ignore]
public ulong PointerAddress {
get {
if (!this.Type.IsPointer) throw new DebuggerException("Not a pointer");
return this.CorValue.CastTo<ICorDebugReferenceValue>().GetValue();
if (!(this.CorValue is ICorDebugReferenceValue))
throw new DebuggerException("Not a pointer");
return ((ICorDebugReferenceValue)this.CorValue).GetValue();
}
}
@ -159,15 +164,15 @@ namespace Debugger @@ -159,15 +164,15 @@ namespace Debugger
this.corValue = corValue;
this.corValue_pauseSession = this.Process.PauseSession;
if (corValue.Is<ICorDebugReferenceValue>() &&
corValue.CastTo<ICorDebugReferenceValue>().GetValue() == 0 &&
corValue.CastTo<ICorDebugValue2>().GetExactType() == null)
if (corValue is ICorDebugReferenceValue &&
((ICorDebugReferenceValue)corValue).GetValue() == 0 &&
((ICorDebugValue2)corValue).GetExactType() == null)
{
// We were passed null reference and no metadata description
// (happens during CreateThread callback for the thread object)
this.type = appDomain.ObjectType;
} else {
ICorDebugType exactType = this.CorValue.CastTo<ICorDebugValue2>().GetExactType();
ICorDebugType exactType = ((ICorDebugValue2)this.CorValue).GetExactType();
this.type = DebugType.CreateFromCorType(appDomain, exactType);
}
}
@ -177,11 +182,11 @@ namespace Debugger @@ -177,11 +182,11 @@ namespace Debugger
{
byte[] rawValue = this.CorGenericValue.GetRawValue();
// The type must not be a primive type (always true in current design)
ICorDebugValue corValue = Eval.NewObjectNoConstructor(this.Type).CorValue;
ICorDebugReferenceValue corRefValue = Eval.NewObjectNoConstructor(this.Type).CorReferenceValue;
// Make the reference to box permanent
corValue = corValue.CastTo<ICorDebugReferenceValue>().Dereference().CastTo<ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo<ICorDebugValue>();
corRefValue = ((ICorDebugHeapValue2)corRefValue.Dereference()).CreateHandle(CorDebugHandleType.HANDLE_STRONG);
// Create new value
Value newValue = new Value(appDomain, corValue);
Value newValue = new Value(appDomain, corRefValue);
// Copy the data inside the box
newValue.CorGenericValue.SetRawValue(rawValue);
return newValue;
@ -190,10 +195,10 @@ namespace Debugger @@ -190,10 +195,10 @@ namespace Debugger
[Debugger.Tests.Ignore]
public Value GetPermanentReference()
{
if (this.CorValue.Is<ICorDebugHandleValue>()) {
if (this.CorValue is ICorDebugHandleValue) {
return this;
} else if (this.CorValue.Is<ICorDebugReferenceValue>()) {
return new Value(appDomain, this.CorValue.CastTo<ICorDebugReferenceValue>().Dereference().CastTo<ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo<ICorDebugValue>());
} else if (this.CorValue is ICorDebugReferenceValue) {
return new Value(appDomain, ((ICorDebugHeapValue2)this.CorReferenceValue.Dereference()).CreateHandle(CorDebugHandleType.HANDLE_STRONG));
} else {
return this.Box();
}
@ -204,7 +209,7 @@ namespace Debugger @@ -204,7 +209,7 @@ namespace Debugger
public Value Dereference()
{
if (!this.Type.IsPointer) throw new DebuggerException("Not a pointer");
ICorDebugReferenceValue corRef = this.CorValue.CastTo<ICorDebugReferenceValue>();
ICorDebugReferenceValue corRef = (ICorDebugReferenceValue)this.CorValue;
if (corRef.GetValue() == 0 || corRef.Dereference() == null) {
return null;
} else {
@ -217,12 +222,12 @@ namespace Debugger @@ -217,12 +222,12 @@ namespace Debugger
{
ICorDebugValue newCorValue = newValue.CorValue;
if (this.CorValue.Is<ICorDebugReferenceValue>()) {
if (!newCorValue.Is<ICorDebugReferenceValue>())
if (this.CorValue is ICorDebugReferenceValue) {
if (!(newCorValue is ICorDebugReferenceValue))
newCorValue = newValue.Box().CorValue;
corValue.CastTo<ICorDebugReferenceValue>().SetValue(newCorValue.CastTo<ICorDebugReferenceValue>().GetValue());
this.CorReferenceValue.SetValue(((ICorDebugReferenceValue)newCorValue).GetValue());
} else {
corValue.CastTo<ICorDebugGenericValue>().SetRawValue(newValue.CorGenericValue.GetRawValue());
this.CorGenericValue.SetRawValue(newValue.CorGenericValue.GetRawValue());
}
}
@ -238,7 +243,7 @@ namespace Debugger @@ -238,7 +243,7 @@ namespace Debugger
if (this.Type.PrimitiveType == null) throw new DebuggerException("Value is not a primitive type");
if (this.Type.FullName == typeof(string).FullName) {
if (this.IsNull) return null;
return this.CorReferenceValue.Dereference().CastTo<ICorDebugStringValue>().GetString();
return ((ICorDebugStringValue)this.CorReferenceValue.Dereference()).GetString();
} else {
return CorGenericValue.GetValue(this.Type.PrimitiveType);
}
@ -255,7 +260,7 @@ namespace Debugger @@ -255,7 +260,7 @@ namespace Debugger
} catch {
throw new NotSupportedException("Can not convert " + value.GetType().ToString() + " to " + this.Type.PrimitiveType.ToString());
}
CorGenericValue.SetValue(this.Type.PrimitiveType, newValue);
CorGenericValue.SetValue(newValue);
}
}
}
@ -438,7 +443,7 @@ namespace Debugger @@ -438,7 +443,7 @@ namespace Debugger
process.SelectedThread.MostRecentStackFrame != null &&
process.SelectedThread.MostRecentStackFrame.CorILFrame != null)
{
curFrame = process.SelectedThread.MostRecentStackFrame.CorILFrame.CastTo<ICorDebugFrame>();
curFrame = process.SelectedThread.MostRecentStackFrame.CorILFrame;
}
try {

Loading…
Cancel
Save