Esempio n. 1
0
		internal static ICorDebugValue DereferenceUnbox(ICorDebugValue corValue)
		{
			// Method arguments can be passed 'by ref'
			if (corValue.Type == (uint)CorElementType.BYREF) {
				corValue = corValue.CastTo<ICorDebugReferenceValue>().Dereference();
			}
			// Pointers may be used in 'unsafe' code - CorElementType.PTR
			// Classes need to be dereferenced
			while (corValue.Is<ICorDebugReferenceValue>()) {
				ICorDebugReferenceValue refValue = corValue.CastTo<ICorDebugReferenceValue>();
				if (refValue.IsNull != 0) {
					return null; // Reference is null
				} else {
					try {
						corValue = refValue.Dereference();
						// TODO: Investigate: Must not acutally be null
						//       eg. Assembly.AssemblyHandle   See SD2-1117
						if (corValue == null) return null; // Dereference() returned null
					} catch {
						return null; // Error during dereferencing
					}
				}
			}
//			if (corValue.Is<ICorDebugHeapValue2>())
//			corValue = corValue.CastTo<ICorDebugHeapValue2>().CreateHandle(CorDebugHandleType.HANDLE_STRONG).CastTo<ICorDebugValue>();
			// Unbox value types
			if (corValue.Is<ICorDebugBoxValue>()) 
			{
				corValue = corValue.CastTo<ICorDebugBoxValue>().Object.CastTo<ICorDebugValue>();
			}
			
			return corValue;
		}
Esempio n. 2
0
        public void NewParameterizedObject(CorFunction managedFunction, CorType[] argumentTypes, CorValue[] arguments)
        {
            ICorDebugType[] types       = null;
            int             typesLength = 0;

            ICorDebugValue[] values     = null;
            int            valuesLength = 0;
            ICorDebugEval2 eval2        = (ICorDebugEval2)m_eval;

            if (argumentTypes != null)
            {
                types = new ICorDebugType[argumentTypes.Length];
                for (int i = 0; i < argumentTypes.Length; i++)
                {
                    types[i] = argumentTypes[i].m_type;
                }
                typesLength = types.Length;
            }
            if (arguments != null)
            {
                values = new ICorDebugValue[arguments.Length];
                for (int i = 0; i < arguments.Length; i++)
                {
                    values[i] = arguments[i].m_val;
                }
                valuesLength = values.Length;
            }
            eval2.NewParameterizedObject(managedFunction.m_function, (uint)typesLength, types, (uint)valuesLength, values);
        }
Esempio n. 3
0
        // The following function create values only for the purpuse of evalutaion
        // They actually do not allocate memory on the managed heap
        // The advantage is that it does not continue the process
        /// <exception cref="DebuggerException">Can not create string this way</exception>
        public static Value CreateValue(Process process, object value)
        {
            if (value is string)
            {
                throw new DebuggerException("Can not create string this way");
            }
            CorElementType corElemType;
            ICorDebugClass corClass = null;

            if (value != null)
            {
                corElemType = DebugType.TypeNameToCorElementType(value.GetType().FullName);
            }
            else
            {
                corElemType = CorElementType.CLASS;
                corClass    = DebugType.Create(process, null, typeof(object).FullName).CorType.Class;
            }
            ICorDebugEval  corEval  = CreateCorEval(process);
            ICorDebugValue corValue = corEval.CreateValue((uint)corElemType, corClass);
            Value          v        = new Value(process, new Expressions.PrimitiveExpression(value), corValue);

            if (value != null)
            {
                v.PrimitiveValue = value;
            }
            return(v);
        }
Esempio n. 4
0
 public Value GetPermanentReference(Thread evalThread)
 {
     if (this.CorValue is ICorDebugHandleValue)
     {
         return(this);
     }
     else if (this.CorValue is ICorDebugReferenceValue)
     {
         if (this.IsNull)
         {
             return(this);                    // ("null" expression) It isn't permanent
         }
         ICorDebugValue deRef = this.CorReferenceValue.Dereference();
         if (deRef is ICorDebugHeapValue2)
         {
             return(new Value(appDomain, ((ICorDebugHeapValue2)deRef).CreateHandle(CorDebugHandleType.HANDLE_STRONG)));
         }
         else
         {
             // For exampe int* is a reference not pointing to heap
             // TODO: It isn't permanent
             return(this);
         }
     }
     else
     {
         return(this.Box(evalThread));
     }
 }
Esempio n. 5
0
        /** Create a Value to use it in a Function Evaluation. */
        public Value CreateValue(uint type, DebuggedClass c)
        {
            ICorDebugValue v = null;

            m_eval.CreateValue(type, c.GetInterface(), out v);
            return(new Value(v));
        }
Esempio n. 6
0
        public CorValue GetStaticFieldValue(int fieldToken, CorFrame frame)
        {
            ICorDebugValue dv = null;

            m_type.GetStaticFieldValue((uint)fieldToken, frame.m_frame, out dv);
            return(dv == null?null:new CorValue(dv));
        }
Esempio n. 7
0
        /** get the value object for the given global variable. */
        public Value GetGlobalVariableValue(int fieldDef)
        {
            ICorDebugValue v = null;

            m_mod.GetGlobalVariableValue((uint)fieldDef, out v);
            return(new Value(v));
        }
Esempio n. 8
0
 public static Value CreateValue(AppDomain appDomain, object value)
 {
     if (value == null)
     {
         ICorDebugClass corClass = appDomain.ObjectType.CorType.GetClass();
         Thread         thread   = GetEvaluationThread(appDomain);
         ICorDebugEval  corEval  = thread.CorThread.CreateEval();
         ICorDebugValue corValue = corEval.CreateValue((uint)CorElementType.CLASS, corClass);
         return(new Value(appDomain, corValue));
     }
     else if (value is string)
     {
         return(Eval.NewString(appDomain, (string)value));
     }
     else
     {
         if (!value.GetType().IsPrimitive)
         {
             throw new DebuggerException("Value must be primitve type.  Seen " + value.GetType());
         }
         Value val = Eval.NewObjectNoConstructor(DebugType.CreateFromType(appDomain.Mscorlib, value.GetType()));
         val.PrimitiveValue = value;
         return(val);
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Gets all locals
        /// </summary>
        /// <param name="kind">Kind</param>
        public IEnumerable <CorValue> GetILLocals(ILCodeKind kind)
        {
            var ilf4 = obj as ICorDebugILFrame4;

            if (ilf4 == null)
            {
                yield break;
            }
            ICorDebugValueEnum valueEnum;
            int hr = ilf4.EnumerateLocalVariablesEx(kind, out valueEnum);

            if (hr < 0)
            {
                yield break;
            }
            for (;;)
            {
                ICorDebugValue value = null;
                uint           count;
                hr = valueEnum.Next(1, out value, out count);
                if (hr != 0 || value == null)
                {
                    break;
                }
                yield return(new CorValue(value));
            }
        }
Esempio n. 10
0
        /** get the value object for the given global variable. */
        public CorValue GetGlobalVariableValue(int fieldToken)
        {
            ICorDebugValue v = null;

            m_module.GetGlobalVariableValue((uint)fieldToken, out v);
            return(new CorValue(v));
        }
Esempio n. 11
0
        /** Create a Value to use it in a Function Evaluation. */
        public CorValue CreateValue(CorElementType type, CorClass managedClass)
        {
            ICorDebugValue v = null;

            m_eval.CreateValue(type, managedClass == null ? null : managedClass.m_class, out v);
            return((v == null) ? null : new CorValue(v));
        }
        int ICorDebugILFrame.GetStackValue(uint dwIndex, out ICorDebugValue ppValue)
        {
            ppValue = GetStackFrameValue(dwIndex, Engine.StackValueKind.EvalStack);
            Debug.Assert(false, "Not tested");

            return(COM_HResults.S_OK);
        }
Esempio n. 13
0
File: Eval.cs Progetto: Orvid/Cosmos
        public void CallParameterizedFunction (CorFunction managedFunction, CorType[] argumentTypes, CorValue[] arguments)
        {
            ICorDebugType[] types = null;
            int typesLength = 0;
            ICorDebugValue[] values = null;
            int valuesLength = 0;
            
            ICorDebugEval2 eval2 = (ICorDebugEval2) m_eval;

            if (argumentTypes != null)
            {
                types = new ICorDebugType[argumentTypes.Length];
                for (int i = 0; i < argumentTypes.Length; i++)
                    types[i] = argumentTypes[i].m_type;
                typesLength = types.Length;
            }
            if (arguments != null)
            {
                values = new ICorDebugValue[arguments.Length];
                for (int i = 0; i < arguments.Length; i++)
                    values[i] = arguments[i].m_val;
                valuesLength = values.Length;
            }
            eval2.CallParameterizedFunction(managedFunction.m_function, (uint)typesLength, types, (uint)valuesLength, values);
        }
Esempio n. 14
0
        int ICorDebugArrayValue.GetElementAtPosition(uint nPosition, out ICorDebugValue ppValue)
        {
            //Cache values?
            ppValue = CreateValue(_rtv.GetElement(nPosition));

            return(COM_HResults.S_OK);
        }
Esempio n. 15
0
        internal Value(Process process, Expression expression, ICorDebugValue corValue)
        {
            if (corValue == null)
            {
                throw new ArgumentNullException("corValue");
            }
            this.process               = process;
            this.expression            = expression;
            this.corValue              = corValue;
            this.corValue_pauseSession = process.PauseSession;

            if (corValue.Is <ICorDebugReferenceValue>() &&
                corValue.CastTo <ICorDebugReferenceValue>().Value == 0 &&
                corValue.CastTo <ICorDebugValue2>().ExactType == null)
            {
                // We were passed null reference and no metadata description
                // (happens during CreateThread callback for the thread object)
                this.type = DebugType.Create(this.Process, null, "System.Object");
            }
            else
            {
                ICorDebugType exactType = this.CorValue.CastTo <ICorDebugValue2>().ExactType;
                this.type = DebugType.Create(this.Process, exactType);
            }
        }
Esempio n. 16
0
 public static Value CreateValue(Thread evalThread, object value)
 {
     if (value == null)
     {
         ICorDebugClass corClass = evalThread.AppDomain.ObjectType.ToCorDebug().GetClass();
         ICorDebugEval  corEval  = evalThread.CorThread.CreateEval();
         ICorDebugValue corValue = corEval.CreateValue((uint)CorElementType.CLASS, corClass);
         return(new Value(evalThread.AppDomain, corValue));
     }
     else if (value is string)
     {
         return(Eval.NewString(evalThread, (string)value));
     }
     else
     {
         if (!value.GetType().IsPrimitive)
         {
             throw new DebuggerException("Value must be primitve type.  Seen " + value.GetType());
         }
         IType type = evalThread.AppDomain.Compilation.FindType(value.GetType());
         Value val  = Eval.NewObjectNoConstructor(evalThread, type);
         val.SetPrimitiveValue(evalThread, value);
         return(val);
     }
 }
Esempio n. 17
0
        internal Value(AppDomain appDomain, ICorDebugValue corValue)
        {
            if (corValue == null)
            {
                throw new ArgumentNullException("corValue");
            }
            this.appDomain             = appDomain;
            this.corValue              = corValue;
            this.corValue_pauseSession = this.Process.PauseSession;

            this.isNull = corValue is ICorDebugReferenceValue && ((ICorDebugReferenceValue)corValue).IsNull() != 0;

            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 = ((ICorDebugValue2)this.CorValue).GetExactType();
                this.type = appDomain.Compilation.Import(exactType);
            }
        }
Esempio n. 18
0
        public CorValue CreateValueForType(CorType type)
        {
            ICorDebugValue val   = null;
            ICorDebugEval2 eval2 = (ICorDebugEval2)m_eval;

            eval2.CreateValueForType(type.m_type, out val);
            return(val == null ? null : new CorValue(val));
        }
Esempio n. 19
0
        int ICorDebugObjectValue.GetFieldValue(ICorDebugClass pClass, uint fieldDef, out ICorDebugValue ppValue)
        {
            //cache fields?
            RuntimeValue rtv = _rtv.GetField(0, nanoCLR_TypeSystem.ClassMemberIndexFromCLRToken(fieldDef, ((CorDebugClass)pClass).Assembly));

            ppValue = CreateValue(rtv);

            return(COM_HResults.S_OK);
        }
Esempio n. 20
0
 static ICorDebugValue[] ValuesAsCorDebug(Value[] values)
 {
     ICorDebugValue[] valuesAsCorDebug = new ICorDebugValue[values.Length];
     for (int i = 0; i < values.Length; i++)
     {
         valuesAsCorDebug[i] = values[i].CorValue;
     }
     return(valuesAsCorDebug);
 }
Esempio n. 21
0
        int ICorDebugArrayValue.GetElement(uint cdim, uint[] indices, out ICorDebugValue ppValue)
        {
            //ask for several at once and cache?

            Debug.Assert(cdim == 1);

            ppValue = CreateValue(_rtv.GetElement(indices[0]));

            return(COM_HResults.S_OK);
        }
Esempio n. 22
0
        int ICorDebugEval2.CreateValueForType(ICorDebugType pType, out ICorDebugValue ppValue)
        {
            CorElementType type;
            ICorDebugClass cls;

            pType.GetType(out type);
            pType.GetClass(out cls);

            return(((ICorDebugEval)this).CreateValue(type, cls, out ppValue));
        }
Esempio n. 23
0
        int ICorDebugILFrame.GetArgument(uint dwIndex, out ICorDebugValue ppValue)
        {
#if ALL_VALUES
            ppValue = (CorDebugValue)this.Arguments[(int)dwIndex];
#else
            ppValue = GetStackFrameValue(dwIndex, Engine.StackValueKind.Argument);
#endif

            return(Utility.COM_HResults.S_OK);
        }
Esempio n. 24
0
        int ICorDebugArrayValue.GetElementAtPosition(uint nPosition, out ICorDebugValue ppValue)
        {
            var getElement = m_rtv.GetElementAsync(nPosition);

            getElement.Wait();

            //Cache values?
            ppValue = CreateValue(getElement.Result);

            return(COM_HResults.S_OK);
        }
Esempio n. 25
0
        int ICorDebugILFrame.GetLocalVariable(uint dwIndex, out ICorDebugValue ppValue)
        {
            //Does getting all locals at once provide any savings???
#if ALL_VALUES
            ppValue = (CorDebugValue)this.Locals[(int)dwIndex];
#else
            ppValue = GetStackFrameValue(dwIndex, Engine.StackValueKind.Local);
#endif

            return(Utility.COM_HResults.S_OK);
        }
        int ICorDebugType.GetStaticFieldValue(uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue)
        {
            uint fd = nanoCLR_TypeSystem.ClassMemberIndexFromCLRToken(fieldDef, this.Assembly);

            this.Process.SetCurrentAppDomain(this.AppDomain);
            RuntimeValue rtv = this.Engine.GetStaticFieldValue(fd);

            ppValue = CorDebugValue.CreateValue(rtv, this.AppDomain);

            return(COM_HResults.S_OK);
        }
        int ICorDebugClass.GetStaticFieldValue(uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue)
        {
            //Cache, and invalidate when necessary???
            uint fd = TinyCLR_TypeSystem.ClassMemberIndexFromCLRToken(fieldDef, this.Assembly);

            this.Process.SetCurrentAppDomain(this.AppDomain);
            RuntimeValue rtv = this.Engine.GetStaticFieldValue(fd);

            ppValue = CorDebugValue.CreateValue(rtv, this.AppDomain);

            return(Utility.COM_HResults.S_OK);
        }
Esempio n. 28
0
        internal Exception(Thread thread)
        {
            creationTime  = DateTime.Now;
            this.process  = thread.Process;
            this.thread   = thread;
            corValue      = thread.CorThread.CurrentException;
            exceptionType = thread.CurrentExceptionType;
            Value runtimeValue = new Value(process,
                                           new IExpirable[] { process.PauseSession },
                                           new IMutable[] {},
                                           delegate { return(corValue); });
            NamedValue nv = runtimeValue.GetMember("_message");

            if (!nv.IsNull)
            {
                message = nv.AsString;
            }
            else
            {
                message = runtimeValue.Type.FullName;
            }
            if (thread.LastFunctionWithLoadedSymbols != null)
            {
                location = thread.LastFunctionWithLoadedSymbols.NextStatement;
            }

            callstack = "";
            int callstackItems = 0;

            if (!nv.IsNull)
            {
                foreach (Function function in thread.Callstack)
                {
                    if (callstackItems >= 100)
                    {
                        callstack += "...\n";
                        break;
                    }

                    SourcecodeSegment loc = function.NextStatement;
                    callstack += function.Name + "()";
                    if (loc != null)
                    {
                        callstack += " - " + loc.SourceFullFilename + ":" + loc.StartLine + "," + loc.StartColumn;
                    }
                    callstack += "\n";
                    callstackItems++;
                }
            }

            type = runtimeValue.Type.FullName;
        }
Esempio n. 29
0
        public static Value NewObject(Process process, DebugType debugType)
        {
            ICorDebugType  ppTypeArgs = null;
            ICorDebugValue ppArgs     = null;
            Eval           e          = new Eval(
                process,
                "New object: " + debugType.Token,
                delegate(ICorDebugEval corEval) { corEval.CastTo <ICorDebugEval2>().NewParameterizedObject
                                                      (debugType.GetDefaultConstructor(), (uint)debugType.GenericArguments.Count, ref ppTypeArgs, 0, ref ppArgs); }
                );

            return(e.EvaluateNow());
        }
Esempio n. 30
0
 public void CallFunction(CorFunction managedFunction, CorValue[] arguments)
 {
     ICorDebugValue[] values = null;
     if(arguments!=null)
     {
         values = new ICorDebugValue[arguments.Length];
         for(int i=0;i<arguments.Length;i++)
             values[i] = arguments[i].m_val;
     }
     m_eval.CallFunction(managedFunction.m_function,
                         (uint) (arguments==null?0:arguments.Length),
                         values);
 }
Esempio n. 31
0
 public void CallFunction(CorFunction managedFunction, CorValue[] arguments)
 {
     ICorDebugValue[] values = null;
     if (arguments != null)
     {
         values = new ICorDebugValue[arguments.Length];
         for (int i = 0; i < arguments.Length; i++)
         {
             values[i] = arguments[i].m_val;
         }
     }
     m_eval.CallFunction(managedFunction.m_function,
                         (uint)(arguments == null ? 0 : arguments.Length),
                         values);
 }
Esempio n. 32
0
        int ICorDebugEval.GetResult(out ICorDebugValue ppResult)
        {
            switch (m_resultType)
            {
            case EvalResult.Exception:
            case EvalResult.Complete:
                ppResult = GetResultValue();
                break;

            default:
                ppResult = null;
                throw new ArgumentException();
            }

            return(Utility.COM_HResults.S_OK);
        }
Esempio n. 33
0
        /// <summary> Copy the acutal value from some other Value object </summary>
        public void SetValue(Thread evalThread, Value newValue)
        {
            ICorDebugValue newCorValue = newValue.CorValue;

            if (this.CorValue is ICorDebugReferenceValue)
            {
                if (!(newCorValue is ICorDebugReferenceValue))
                {
                    newCorValue = newValue.Box(evalThread).CorValue;
                }
                ((ICorDebugReferenceValue)this.CorValue).SetValue(((ICorDebugReferenceValue)newCorValue).GetValue());
            }
            else
            {
                this.CorGenericValue.SetRawValue(newValue.CorGenericValue.GetRawValue());
            }
        }
Esempio n. 34
0
        internal Value(AppDomain appDomain, ICorDebugValue corValue)
        {
            if (corValue == null)
                throw new ArgumentNullException("corValue");
            this.appDomain = appDomain;
            this.corValue = corValue;
            this.corValue_pauseSession = this.Process.PauseSession;

            this.isNull = corValue is ICorDebugReferenceValue && ((ICorDebugReferenceValue)corValue).IsNull() != 0;

            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 = ((ICorDebugValue2)this.CorValue).GetExactType();
                this.type = DebugType.CreateFromCorType(appDomain, exactType);
            }
        }
Esempio n. 35
0
		internal Exception(Thread thread)
		{
			creationTime = DateTime.Now;
			this.process = thread.Process;
			this.thread = thread;
			corValue = thread.CorThread.CurrentException;
			exceptionType = thread.CurrentExceptionType;
			Value runtimeValue = new Value(process,
			                               new IExpirable[] {process.PauseSession},
			                               new IMutable[] {},
			                               delegate { return corValue; } );
			NamedValue nv = runtimeValue.GetMember("_message");
			if (!nv.IsNull)
			message = nv.AsString;
			else message = runtimeValue.Type.FullName;
			if (thread.LastFunctionWithLoadedSymbols != null) {
				location = thread.LastFunctionWithLoadedSymbols.NextStatement;
			}
			
			callstack = "";
			int callstackItems = 0;
			if (!nv.IsNull)
			foreach(Function function in thread.Callstack) {
				if (callstackItems >= 100) {
					callstack += "...\n";
					break;
				}
				
				SourcecodeSegment loc = function.NextStatement;
				callstack += function.Name + "()";
				if (loc != null) {
					callstack += " - " + loc.SourceFullFilename + ":" + loc.StartLine + "," + loc.StartColumn;
				}
				callstack += "\n";
				callstackItems++;
			}
			
			type = runtimeValue.Type.FullName;
		}
Esempio n. 36
0
        int ICorDebugArrayValue.GetElement( uint cdim, uint[] indices, out ICorDebugValue ppValue )
        {
            //ask for several at once and cache?

            Debug.Assert( cdim == 1 );
            
            ppValue = CreateValue( m_rtv.GetElement( indices[0] ) );

            return Utility.COM_HResults.S_OK;   
        }
Esempio n. 37
0
        int ICorDebugArrayValue.GetElementAtPosition( uint nPosition, out ICorDebugValue ppValue )
        {
            //Cache values?
            ppValue = CreateValue( m_rtv.GetElement( nPosition ) );

            return Utility.COM_HResults.S_OK;
        }
 public static void NewObject(this ICorDebugEval instance, ICorDebugFunction pConstructor, uint nArgs, ref ICorDebugValue ppArgs)
 {
     instance.__NewObject(pConstructor, nArgs, ref ppArgs);
 }
Esempio n. 39
0
		static ICorDebugValue[] ValuesAsCorDebug(Value[] values)
		{
			ICorDebugValue[] valuesAsCorDebug = new ICorDebugValue[values.Length];
			for(int i = 0; i < values.Length; i++) {
				valuesAsCorDebug[i] = values[i].CorValue;
			}
			return valuesAsCorDebug;
		}
 public static void CallFunction(this ICorDebugEval instance, ICorDebugFunction pFunction, uint nArgs, ICorDebugValue[] ppArgs)
 {
     instance.__CallFunction(pFunction, nArgs, ppArgs);
 }
Esempio n. 41
0
 public static ICorDebugValue Dereference(ICorDebugValue pvalue)
 {
     for (; ; )
     {
         ICorDebugReferenceValue pref = pvalue as ICorDebugReferenceValue;
         if (null != pref)
         {
             int isnull;
             pref.IsNull(out isnull);
             if (0 != isnull)
             {
                 return null;
             }
             pref.Dereference(out pvalue);
             continue;
         }
         break;
     }
     return pvalue;
 }
        private static VARIABLE GetStringValue(ICorDebugValue value)
        {
            VARIABLE vari = new VARIABLE();
            ICorDebugReferenceValue refVal2 = value as ICorDebugReferenceValue;
            ICorDebugValue pDeRef2 = null;
            try{
                refVal2.Dereference(out pDeRef2);
                ICorDebugStringValue _msgString = pDeRef2 as ICorDebugStringValue;
                uint stringSize;
                uint length;
                _msgString.GetLength(out length);
                StringBuilder sb = new StringBuilder((int)length + 1); // we need one extra char for null
                _msgString.GetString((uint)sb.Capacity, out stringSize, sb);
                vari.innerValue = sb.ToString();
            }  catch (COMException e) {
                if ((uint)e.ErrorCode == 0x80131305)
                {
                    vari.innerValue = "<<Value Might be Null>>";
                }
                else {
                    vari.innerValue = "<<Error While getting value >> " + e.Message;
                }
            }

            vari.isArray = false;
            vari.isComplex = false;
            return vari;
        }
Esempio n. 43
0
 int ICorDebugHandleValue.DereferenceStrong( out ICorDebugValue ppValue )
 {
     return this.ICorDebugReferenceValue.DereferenceStrong( out ppValue );            
 }
Esempio n. 44
0
		public static List<AbstractNode> GetDebugInfo(Process process, ICorDebugValue corValue)
		{
			List<AbstractNode> items = new List<AbstractNode>();
			
			if (corValue.Is<ICorDebugValue>()) {
				InfoNode info = new InfoNode("ICorDebugValue", "");
				info.AddChild("Address", corValue.Address.ToString("X8"));
				info.AddChild("Type", ((CorElementType)corValue.Type).ToString());
				info.AddChild("Size", corValue.Size.ToString());
				items.Add(info);
			}
			if (corValue.Is<ICorDebugValue2>()) {
				InfoNode info = new InfoNode("ICorDebugValue2", "");
				ICorDebugValue2 corValue2 = corValue.CastTo<ICorDebugValue2>();
				string fullname;
				try {
					fullname = DebugType.Create(process, corValue2.ExactType).FullName;
				} catch (DebuggerException e) {
					fullname = e.Message;
				}
				info.AddChild("ExactType", fullname);
				items.Add(info);
			}
			if (corValue.Is<ICorDebugGenericValue>()) {
				InfoNode info = new InfoNode("ICorDebugGenericValue", "");
				try {
					byte[] bytes = corValue.CastTo<ICorDebugGenericValue>().RawValue;
					for(int i = 0; i < bytes.Length; i += 8) {
						string val = "";
						for(int j = i; j < bytes.Length && j < i + 8; j++) {
							val += bytes[j].ToString("X2") + " ";
						}
						info.AddChild("Value" + i.ToString("X2"), val);
					}
				} catch (ArgumentException) {
					info.AddChild("Value", "N/A");
				}
				items.Add(info);
			}
			if (corValue.Is<ICorDebugReferenceValue>()) {
				InfoNode info = new InfoNode("ICorDebugReferenceValue", "");
				ICorDebugReferenceValue refValue = corValue.CastTo<ICorDebugReferenceValue>();
				info.AddChild("IsNull", (refValue.IsNull != 0).ToString());
				if (refValue.IsNull == 0) {
					info.AddChild("Value", refValue.Value.ToString("X8"));
					if (refValue.Dereference() != null) {
						info.AddChild("Dereference", "", GetDebugInfo(process, refValue.Dereference()));
					} else {
						info.AddChild("Dereference", "N/A");
					}
					
				}
				items.Add(info);
			}
			if (corValue.Is<ICorDebugHeapValue>()) {
				InfoNode info = new InfoNode("ICorDebugHeapValue", "");
				items.Add(info);
			}
			if (corValue.Is<ICorDebugHeapValue2>()) {
				InfoNode info = new InfoNode("ICorDebugHeapValue2", "");
				items.Add(info);
			}
			if (corValue.Is<ICorDebugObjectValue>()) {
				InfoNode info = new InfoNode("ICorDebugObjectValue", "");
				ICorDebugObjectValue objValue = corValue.CastTo<ICorDebugObjectValue>();
				info.AddChild("Class", objValue.Class.Token.ToString("X8"));
				info.AddChild("IsValueClass", (objValue.IsValueClass != 0).ToString());
				items.Add(info);
			}
			if (corValue.Is<ICorDebugObjectValue2>()) {
				InfoNode info = new InfoNode("ICorDebugObjectValue2", "");
				items.Add(info);
			}
			if (corValue.Is<ICorDebugBoxValue>()) {
				InfoNode info = new InfoNode("ICorDebugBoxValue", "");
				ICorDebugBoxValue boxValue = corValue.CastTo<ICorDebugBoxValue>();
				info.AddChild("Object", "", GetDebugInfo(process, boxValue.Object.CastTo<ICorDebugValue>()));
				items.Add(info);
			}
			if (corValue.Is<ICorDebugStringValue>()) {
				InfoNode info = new InfoNode("ICorDebugStringValue", "");
				ICorDebugStringValue stringValue = corValue.CastTo<ICorDebugStringValue>();
				info.AddChild("Length", stringValue.Length.ToString());
				info.AddChild("String", stringValue.String);
				items.Add(info);
			}
			if (corValue.Is<ICorDebugArrayValue>()) {
				InfoNode info = new InfoNode("ICorDebugArrayValue", "");
				info.AddChild("...", "...");
				items.Add(info);
			}
			if (corValue.Is<ICorDebugHandleValue>()) {
				InfoNode info = new InfoNode("ICorDebugHandleValue", "");
				ICorDebugHandleValue handleValue = corValue.CastTo<ICorDebugHandleValue>();
				info.AddChild("HandleType", handleValue.HandleType.ToString());
				items.Add(info);
			}
			
			return items;
		}
 private static VARIABLE GetArrayItems(ICorDebugValue value)
 {
     VARIABLE vari = new VARIABLE();
     vari.isArray = true;
     vari.isComplex = false;
     var arrayReference = value as ICorDebugReferenceValue;
     ICorDebugValue arrayDereferenced;
     try{
         arrayReference.Dereference(out arrayDereferenced);
         ICorDebugArrayValue array = arrayDereferenced as ICorDebugArrayValue;
         IList<PARAMETER> members = new List<PARAMETER>();
         if (array != null) {
             uint noOfItems = 0;
             array.GetCount(out noOfItems);
             if (noOfItems == 0) vari.innerValue = "<<Zero Elements in this array>>";
             else{
             for (int index = 0; index < noOfItems; index++) {
                 ICorDebugValue elementVal = null;
                 array.GetElementAtPosition((uint)index, out elementVal);
                 MDbgValue mdgbVal = new MDbgValue(new CorValue(value));
                 DEBUGPARAM parm = GetParamInfo(elementVal);
                 parm.name = "Item[" + index.ToString() + "]";
                 members.Add(parm);
             }
             vari.parameters = members;
             }
         }
     }
     catch (Exception) {
         vari.innerValue = "<<Not able to get the value>>";
     }
     return vari;
 }
        public static DEBUGPARAM GetParamInfo(ICorDebugValue value)
        {
            DEBUGPARAM debugParam = new DEBUGPARAM();
            ICorDebugGenericValue gvalue = value as ICorDebugGenericValue;
            CorElementType type = CorElementType.ELEMENT_TYPE_VOID;
            value.GetType(out type);
            //debugParam.corType = type;
            debugParam.corValue = new MDbgValue(new CorValue(value));
            debugParam.isComplex = false;
            if (gvalue != null){
                switch (type){
                    case CorElementType.ELEMENT_TYPE_BOOLEAN:debugParam.type = "bool";break;
                    case CorElementType.ELEMENT_TYPE_CHAR: debugParam.type = "char";break;
                    case CorElementType.ELEMENT_TYPE_I1: debugParam.type = "sbyte";break;
                    case CorElementType.ELEMENT_TYPE_U1:debugParam.type = "byte";break;
                    case CorElementType.ELEMENT_TYPE_I2: debugParam.type = "Int16";break;
                    case CorElementType.ELEMENT_TYPE_U2: debugParam.type = "UInt16";break;
                    case CorElementType.ELEMENT_TYPE_I4: debugParam.type = "Int32";break;
                    case CorElementType.ELEMENT_TYPE_U4: debugParam.type = "UInt32";break;
                    case CorElementType.ELEMENT_TYPE_I8: debugParam.type = "Int64";break;
                    case CorElementType.ELEMENT_TYPE_U8: debugParam.type = "UIn64";break;
                    case CorElementType.ELEMENT_TYPE_R4: debugParam.type = "Single";break;
                    case CorElementType.ELEMENT_TYPE_R8: debugParam.type = "Double";break;
                    case CorElementType.ELEMENT_TYPE_PTR: debugParam.type = "IntPtr";break;
                    case CorElementType.ELEMENT_TYPE_U: debugParam.type = "IntPtr32";break;
                    default: debugParam.type = "***UNK***"; break;
                }
            } else if
            (
            (type == CorElementType.ELEMENT_TYPE_CLASS) ||
            (type == CorElementType.ELEMENT_TYPE_VALUETYPE)
            ){
                ICorDebugObjectValue objectValue = value as ICorDebugObjectValue;
                ICorDebugClass _class = null;
                ICorDebugReferenceValue refVal = value as ICorDebugReferenceValue;
                ICorDebugValue pDeRef = null;
                try {
                    refVal.Dereference(out pDeRef);
                    objectValue = pDeRef as ICorDebugObjectValue;
                    objectValue.GetClass(out _class);
                    MetaType metatype = MetaDataUtils.MetadataMgr.GetClass(new CorClass(_class));
                    debugParam.type = metatype.Name;
                    debugParam.isComplex = true;
                } catch (COMException e) {
                    if ((uint)e.ErrorCode == 0x80131305){
                        debugParam.type = "Value Might be Null";
                    }
                }

            }else if (type == CorElementType.ELEMENT_TYPE_STRING){
                debugParam.type = "System.String";
            }else if(type == CorElementType.ELEMENT_TYPE_SZARRAY ||
                    type == CorElementType.ELEMENT_TYPE_ARRAY){
                    var arrayReference = value as ICorDebugReferenceValue;
                    ICorDebugValue arrayDereferenced;
                    arrayReference.Dereference(out arrayDereferenced);
                    ICorDebugArrayValue array = arrayDereferenced as ICorDebugArrayValue;
                    CorElementType arraytype = CorElementType.ELEMENT_TYPE_VOID;
                    //array.GetElementType(out
                    ICorDebugObjectValue objectValue = arrayDereferenced as ICorDebugObjectValue;
                    ICorDebugClass _class = null;
                    objectValue.GetClass(out _class);
                    MetaType metatype = MetaDataUtils.MetadataMgr.GetClass(new CorClass(_class));
                    debugParam.type = metatype.Name;
                    debugParam.isComplex = true;
            }
            else{
                debugParam.type ="NotSupported for now";
            }
            return debugParam;
        }
        public static string GetCorValue2Text(ICorDebugValue value,int depth)
        {
            StringBuilder sb = new StringBuilder();
                ICorDebugGenericValue gvalue = value as ICorDebugGenericValue;
                CorElementType type = CorElementType.ELEMENT_TYPE_VOID;
                value.GetType(out type);
                if (gvalue != null)
                {
                    uint size = 0;
                    gvalue.GetSize(out size);
                    unsafe
                    {
                        byte[] corValue = new byte[size];
                        fixed (byte* pValue = corValue)
                        {
                            gvalue.GetValue(new IntPtr(pValue));
                            switch (type)
                            {
                                case CorElementType.ELEMENT_TYPE_BOOLEAN: sb.Append((*((System.Boolean*)pValue)).ToString()); break;
                                case CorElementType.ELEMENT_TYPE_CHAR: sb.Append((*((System.Char*)pValue)).ToString()); break;
                                case CorElementType.ELEMENT_TYPE_I1: sb.Append((*((System.SByte*)pValue)).ToString()); break;
                                case CorElementType.ELEMENT_TYPE_U1: sb.Append((*((System.Byte*)pValue)).ToString()); break;
                                case CorElementType.ELEMENT_TYPE_I2: sb.Append((*((System.Int16*)pValue)).ToString()); break;
                                case CorElementType.ELEMENT_TYPE_U2: sb.Append((*((System.UInt16*)pValue)).ToString()); break;
                                case CorElementType.ELEMENT_TYPE_I4: sb.Append((*((System.Int32*)pValue)).ToString()); break;
                                case CorElementType.ELEMENT_TYPE_U4: sb.Append((*((System.UInt32*)pValue)).ToString()); break;
                                case CorElementType.ELEMENT_TYPE_I8: sb.Append((*((System.Int64*)pValue)).ToString()); break;
                                case CorElementType.ELEMENT_TYPE_U8: sb.Append((*((System.UInt64*)pValue)).ToString()); break;
                                case CorElementType.ELEMENT_TYPE_R4: sb.Append((*((System.Single*)pValue)).ToString()); break;
                                case CorElementType.ELEMENT_TYPE_R8: sb.Append((*((System.Double*)pValue)).ToString()); break;
                                case CorElementType.ELEMENT_TYPE_PTR: sb.Append((*((System.IntPtr*)pValue)).ToString()); break;
                                case CorElementType.ELEMENT_TYPE_U: sb.Append((*((System.UIntPtr*)pValue)).ToString()); break;

                                default: sb.Append("Type is not known"); break;
                            }
                        }
                    }
                }
                else if((type == CorElementType.ELEMENT_TYPE_CLASS) || (type == CorElementType.ELEMENT_TYPE_VALUETYPE)){
                    ICorDebugObjectValue objectValue =  value as ICorDebugObjectValue;
                    if (objectValue == null)
                    {
                        ICorDebugReferenceValue refVal = value as ICorDebugReferenceValue;
                        ICorDebugValue pDeRef = null;
                        try
                        {
                            refVal.Dereference(out pDeRef);
                            objectValue = pDeRef as ICorDebugObjectValue;
                        }
                        catch (COMException e) {
                            if ((uint)e.ErrorCode == 0x80131305) {
                                sb.AppendLine("null");
                            }
                        }

                    }
                    if (objectValue != null) {
                        ICorDebugClass _class = null;
                        objectValue.GetClass(out _class);
                        MetaType metatype = MetaDataUtils.MetadataMgr.GetClass(new CorClass(_class));
                        sb.AppendLine("Type <" + metatype.Name + "> Begin");
                        List<FieldInfo> metadata = metatype.GetFieldInfo();
                        foreach (FieldInfo fi in metadata) {
                            ICorDebugValue exceptVal = null;
                            try{
                                objectValue.GetFieldValue(_class, (uint)fi.MetadataToken, out exceptVal);
                                DEBUGPARAM member = GetParamInfo(exceptVal);
                                member.name = fi.Name;
                            } catch (COMException e) {
                                //Need log
                                sb.AppendLine("Value : Not able to deduce");
                            }
                        }
                        sb.AppendLine("Type <" + metatype.Name + "> End");
                    }
                }
                else if (type == CorElementType.ELEMENT_TYPE_STRING)
                {
                    ICorDebugReferenceValue refVal2 = value as ICorDebugReferenceValue;
                    ICorDebugValue pDeRef2 = null;
                    refVal2.Dereference(out pDeRef2);
                    ICorDebugStringValue _msgString = pDeRef2 as ICorDebugStringValue;
                    uint stringSize;
                    uint length;
                    _msgString.GetLength(out length);
                    sb = new StringBuilder((int)length + 1); // we need one extra char for null
                    _msgString.GetString((uint)sb.Capacity, out stringSize, sb);
                }
                else {
                    sb.AppendLine("NotSupported for now");
                }
                return sb.ToString();
        }
 internal static IList<PARAMETER> GetObjectMembers(ICorDebugValue value)
 {
     IList<PARAMETER> members = new List<PARAMETER>();
     ICorDebugObjectValue objectValue = value as ICorDebugObjectValue;
     //incase of boxed senarion.
     if (objectValue == null){
         ICorDebugReferenceValue refVal = value as ICorDebugReferenceValue;
         ICorDebugValue pDeRef = null;
         try{
             refVal.Dereference(out pDeRef);
             objectValue = pDeRef as ICorDebugObjectValue;
         } catch (COMException e){
             if ((uint)e.ErrorCode == 0x80131305)  return null;
         }
     }
     if (objectValue != null){
         ICorDebugClass _class = null;
         objectValue.GetClass(out _class);
         MetaType metatype = MetaDataUtils.MetadataMgr.GetClass(new CorClass(_class));
         List<FieldInfo> metadata = metatype.GetFieldInfo();
         foreach (FieldInfo fi in metadata) {
             DEBUGPARAM arg = new DEBUGPARAM();
             ICorDebugValue exceptVal = null;
             try{
                 objectValue.GetFieldValue(_class, (uint)fi.MetadataToken, out exceptVal);
                 arg = GetParamInfo(exceptVal);
                 arg.name = fi.Name;
                 members.Add(arg);
             }catch (COMException) {
                 //sb.AppendLine("Value : Not able to deduce");
             }
         }
         List<MetadataMethodInfo> metas = metatype.GetProperties();
         ICorDebugModule module = null;
         _class.GetModule(out module);
         foreach (MetadataMethodInfo fi in metas) {
             DEBUGPARAM arg = new DEBUGPARAM();
             try
             {
                 //objectValue.GetFieldValue(_class, (uint)fi.MetadataToken, out exceptVal);
                 //arg = GetParamInfo(exceptVal);
                 arg.name = fi.Name;
                 arg.isProperty = true;
                 arg.type = fi.ReturnType;
                 if (!fi.IsStatic) {
                     ICorDebugReferenceValue hv = objectValue as ICorDebugReferenceValue;
                     if (hv != null){
                        // arg.corValue = hv;
                     }else{
                         //arg.corValue = value;
                     }
                 }
                 if (arg.name.Contains(".get_Item")) {
                     if (fi.Arguments.Count == 1 && fi.Arguments[0].name == "index") {
                         arg.isIndexProperty = true;
                     }
                 }
                 ICorDebugFunction fun = null;
                 module.GetFunctionFromToken((uint)fi.MetadataToken, out fun);
                 arg.property = new CorFunction(fun);
                 members.Add(arg);
             }
             catch (COMException)
             {
                 //sb.AppendLine("Value : Not able to deduce");
             }
         }
     }
     return members;
 }
        public static VARIABLE GetValue(ICorDebugValue value,CorElementType type)
        {
            if (type == CorElementType.ELEMENT_TYPE_VOID) {
                value.GetType(out type);
            }
            VARIABLE vari = new VARIABLE();
            ICorDebugGenericValue generic = value as ICorDebugGenericValue;
            if (generic != null) {
                vari.innerValue = GetGenericValue(generic,type);
                vari.isComplex = false;
            } else {
                switch (type) {
                    case CorElementType.ELEMENT_TYPE_CLASS:
                    case CorElementType.ELEMENT_TYPE_VALUETYPE:
                        vari.isComplex = true;
                        vari.isArray = false;
                        vari.parameters = GetObjectMembers(value);
                        break;
                    case CorElementType.ELEMENT_TYPE_STRING:
                        vari= GetStringValue(value);
                        break;
                    case CorElementType.ELEMENT_TYPE_SZARRAY:
                    case CorElementType.ELEMENT_TYPE_ARRAY:
                        vari = GetArrayItems(value);
                        break;
                    default:
                        break;
                }

            }
            return vari;
        }
Esempio n. 50
0
 internal CorValue(ICorDebugValue value)
     : base(value)
 {
     m_val = value;
 }
Esempio n. 51
0
        int ICorDebugClass. GetStaticFieldValue (uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue)
        {
            //Cache, and invalidate when necessary???
            uint fd = TinyCLR_TypeSystem.ClassMemberIndexFromCLRToken(fieldDef, this.Assembly);
            this.Process.SetCurrentAppDomain( this.AppDomain );
            RuntimeValue rtv = this.Engine.GetStaticFieldValue( fd );
            ppValue = CorDebugValue.CreateValue(rtv, this.AppDomain);

            return Utility.COM_HResults.S_OK;
        }
Esempio n. 52
0
		public static InfoNode GetDebugInfoRoot(Process process, ICorDebugValue corValue)
		{
			return new InfoNode("ICorDebug", "", GetDebugInfo(process, corValue));
		}
Esempio n. 53
0
		public static List<TreeNode> GetDebugInfo(AppDomain appDomain, ICorDebugValue corValue)
		{
			List<TreeNode> items = new List<TreeNode>();
			
			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) {
				InfoNode info = new InfoNode("ICorDebugValue2", "");
				ICorDebugValue2 corValue2 = (ICorDebugValue2)corValue;
				string fullname;
				try {
					fullname = DebugType.CreateFromCorType(appDomain, corValue2.GetExactType()).FullName;
				} catch (DebuggerException e) {
					fullname = e.Message;
				}
				info.AddChild("ExactType", fullname);
				items.Add(info);
			}
			if (corValue is ICorDebugGenericValue) {
				InfoNode info = new InfoNode("ICorDebugGenericValue", "");
				try {
					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++) {
							val += bytes[j].ToString("X2") + " ";
						}
						info.AddChild("Value" + i.ToString("X2"), val);
					}
				} catch (System.ArgumentException) {
					info.AddChild("Value", "N/A");
				}
				items.Add(info);
			}
			if (corValue is ICorDebugReferenceValue) {
				InfoNode info = new InfoNode("ICorDebugReferenceValue", "");
				ICorDebugReferenceValue refValue = (ICorDebugReferenceValue)corValue;
				info.AddChild("IsNull", (refValue.IsNull() != 0).ToString());
				if (refValue.IsNull() == 0) {
					info.AddChild("Value", refValue.GetValue().ToString("X8"));
					if (refValue.Dereference() != null) {
						info.AddChild("Dereference", "", GetDebugInfo(appDomain, refValue.Dereference()));
					} else {
						info.AddChild("Dereference", "N/A");
					}
				}
				items.Add(info);
			}
			if (corValue is ICorDebugHeapValue) {
				InfoNode info = new InfoNode("ICorDebugHeapValue", "");
				items.Add(info);
			}
			if (corValue is ICorDebugHeapValue2) {
				InfoNode info = new InfoNode("ICorDebugHeapValue2", "");
				items.Add(info);
			}
			if (corValue is ICorDebugObjectValue) {
				InfoNode info = new InfoNode("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) {
				InfoNode info = new InfoNode("ICorDebugObjectValue2", "");
				items.Add(info);
			}
			if (corValue is ICorDebugBoxValue) {
				InfoNode info = new InfoNode("ICorDebugBoxValue", "");
				ICorDebugBoxValue boxValue = (ICorDebugBoxValue)corValue;
				info.AddChild("Object", "", GetDebugInfo(appDomain, boxValue.GetObject()));
				items.Add(info);
			}
			if (corValue is ICorDebugStringValue) {
				InfoNode info = new InfoNode("ICorDebugStringValue", "");
				ICorDebugStringValue stringValue = (ICorDebugStringValue)corValue;
				info.AddChild("Length", stringValue.GetLength().ToString());
				info.AddChild("String", stringValue.GetString());
				items.Add(info);
			}
			if (corValue is ICorDebugArrayValue) {
				InfoNode info = new InfoNode("ICorDebugArrayValue", "");
				info.AddChild("...", "...");
				items.Add(info);
			}
			if (corValue is ICorDebugHandleValue) {
				InfoNode info = new InfoNode("ICorDebugHandleValue", "");
				ICorDebugHandleValue handleValue = (ICorDebugHandleValue)corValue;
				info.AddChild("HandleType", handleValue.GetHandleType().ToString());
				items.Add(info);
			}
			
			return items;
		}
Esempio n. 54
0
        int ICorDebugReferenceValue.Dereference( out ICorDebugValue ppValue )
        {
            ppValue = m_value;

            return Utility.COM_HResults.S_OK;            
        }
Esempio n. 55
0
		public static InfoNode GetDebugInfoRoot(AppDomain appDomain, ICorDebugValue corValue)
		{
			return new InfoNode("ICorDebug", "", GetDebugInfo(appDomain, corValue));
		}
Esempio n. 56
0
        int ICorDebugObjectValue.GetFieldValue( ICorDebugClass pClass, uint fieldDef, out ICorDebugValue ppValue )
        {
            //cache fields?
            RuntimeValue rtv = m_rtv.GetField( 0, TinyCLR_TypeSystem.ClassMemberIndexFromCLRToken( fieldDef, ((CorDebugClass)pClass).Assembly ) );

            ppValue = CreateValue( rtv );

            return Utility.COM_HResults.S_OK;                 
        }
Esempio n. 57
0
            public static string ToString(ICorDebugValue pvalue)
            {
                if (null == pvalue)
                {
                    return "<N/A>";
                }
                pvalue = Dereference(pvalue);
                if (null == pvalue)
                {
                    return "<null>";
                }
                uint type;
                pvalue.GetType(out type);
                CorElementType cortype = (CorElementType)type;
                switch (cortype)
                {
                    case CorElementType.ELEMENT_TYPE_ARRAY:
                    case CorElementType.ELEMENT_TYPE_SZARRAY:
                        return "array";

                    case CorElementType.ELEMENT_TYPE_I1:
                        unsafe
                        {
                            ICorDebugGenericValue pgen = (ICorDebugGenericValue)pvalue;
                            sbyte x = default(sbyte);
                            IntPtr px = new IntPtr(&x);
                            pgen.GetValue(px);
                            return x.ToString();
                        }
                    case CorElementType.ELEMENT_TYPE_U1:
                        unsafe
                        {
                            ICorDebugGenericValue pgen = (ICorDebugGenericValue)pvalue;
                            byte x = default(byte);
                            IntPtr px = new IntPtr(&x);
                            pgen.GetValue(px);
                            return x.ToString();
                        }
                    case CorElementType.ELEMENT_TYPE_I2:
                        unsafe
                        {
                            ICorDebugGenericValue pgen = (ICorDebugGenericValue)pvalue;
                            Int16 x = default(Int16);
                            IntPtr px = new IntPtr(&x);
                            pgen.GetValue(px);
                            return x.ToString();
                        }
                    case CorElementType.ELEMENT_TYPE_U2:
                        unsafe
                        {
                            ICorDebugGenericValue pgen = (ICorDebugGenericValue)pvalue;
                            UInt16 x = default(UInt16);
                            IntPtr px = new IntPtr(&x);
                            pgen.GetValue(px);
                            return x.ToString();
                        }
                    case CorElementType.ELEMENT_TYPE_I4:
                        unsafe
                        {
                            ICorDebugGenericValue pgen = (ICorDebugGenericValue)pvalue;
                            Int32 x = default(Int32);
                            IntPtr px = new IntPtr(&x);
                            pgen.GetValue(px);
                            return x.ToString();
                        }
                    case CorElementType.ELEMENT_TYPE_U4:
                        unsafe
                        {
                            ICorDebugGenericValue pgen = (ICorDebugGenericValue)pvalue;
                            UInt32 x = default(UInt32);
                            IntPtr px = new IntPtr(&x);
                            pgen.GetValue(px);
                            return x.ToString();
                        }
                    case CorElementType.ELEMENT_TYPE_I:
                        unsafe
                        {
                            ICorDebugGenericValue pgen = (ICorDebugGenericValue)pvalue;
                            IntPtr x = default(IntPtr);
                            IntPtr px = new IntPtr(&x);
                            pgen.GetValue(px);
                            return x.ToString();
                        }
                    case CorElementType.ELEMENT_TYPE_U:
                        unsafe
                        {
                            ICorDebugGenericValue pgen = (ICorDebugGenericValue)pvalue;
                            UIntPtr x = default(UIntPtr);
                            IntPtr px = new IntPtr(&x);
                            pgen.GetValue(px);
                            return x.ToString();
                        }
                    case CorElementType.ELEMENT_TYPE_I8:
                        unsafe
                        {
                            ICorDebugGenericValue pgen = (ICorDebugGenericValue)pvalue;
                            Int64 x = default(Int64);
                            IntPtr px = new IntPtr(&x);
                            pgen.GetValue(px);
                            return x.ToString();
                        }
                    case CorElementType.ELEMENT_TYPE_U8:
                        unsafe
                        {
                            ICorDebugGenericValue pgen = (ICorDebugGenericValue)pvalue;
                            UInt64 x = default(UInt64);
                            IntPtr px = new IntPtr(&x);
                            pgen.GetValue(px);
                            return x.ToString();
                        }
                    case CorElementType.ELEMENT_TYPE_R4:
                        unsafe
                        {
                            ICorDebugGenericValue pgen = (ICorDebugGenericValue)pvalue;
                            Single x = default(Single);
                            IntPtr px = new IntPtr(&x);
                            pgen.GetValue(px);
                            return x.ToString();
                        }
                    case CorElementType.ELEMENT_TYPE_R8:
                        unsafe
                        {
                            ICorDebugGenericValue pgen = (ICorDebugGenericValue)pvalue;
                            Double x = default(Double);
                            IntPtr px = new IntPtr(&x);
                            pgen.GetValue(px);
                            return x.ToString();
                        }

                    case CorElementType.ELEMENT_TYPE_BOOLEAN:
                        unsafe
                        {
                            ICorDebugGenericValue pgen = (ICorDebugGenericValue)pvalue;
                            byte x = default(byte);
                            IntPtr px = new IntPtr(&x);
                            pgen.GetValue(px);
                            return (0 != x) ? "true" : "false";
                        }

                    case CorElementType.ELEMENT_TYPE_CHAR:
                        unsafe
                        {
                            ICorDebugGenericValue pgen = (ICorDebugGenericValue)pvalue;
                            char x = default(char);
                            IntPtr px = new IntPtr(&x);
                            pgen.GetValue(px);
                            return "'" + x.ToString() + "'";
                        }

                    case CorElementType.ELEMENT_TYPE_PTR:
                        return "<non-null pointer>";

                    case CorElementType.ELEMENT_TYPE_BYREF:
                    case CorElementType.ELEMENT_TYPE_TYPEDBYREF:
                    case CorElementType.ELEMENT_TYPE_OBJECT:
                        return "<printing value of type: not implemented>";

                    case CorElementType.ELEMENT_TYPE_CLASS:
                    case CorElementType.ELEMENT_TYPE_VALUETYPE:
                        {
                            ICorDebugObjectValue pobj = pvalue as ICorDebugObjectValue;
                            if (null == pobj)
                            {
                                ICorDebugBoxValue pbox = pvalue as ICorDebugBoxValue;
                                if (null == pbox)
                                {
                                    goto default;
                                }
                                pbox.GetObject(out pobj);
                                if (null == pobj)
                                {
                                    goto default;
                                }
                            }
                            ICorDebugClass pclass;
                            pobj.GetClass(out pclass);
                            uint ctoken;
                            pclass.GetToken(out ctoken);
                            if (ctoken == 0) // Class of globals.
                            {
                                return "";
                            }
                            ICorDebugValue2 pvalue2 = pvalue as ICorDebugValue2;
                            if (null != pvalue2)
                            {
                                ICorDebugType ptype;
                                pvalue2.GetExactType(out ptype);
                                ICorDebugModule imod;
                                pclass.GetModule(out imod);


                                IMetaDataImport importer;
                                {
                                    object oimdi;
                                    Guid IMetaDataImportGUID = typeof(IMetaDataImport).GUID;
                                    imod.GetMetaDataInterface(ref IMetaDataImportGUID, out oimdi);
                                    importer = (IMetaDataImport)oimdi;
                                }

                                string TypeDef;
                                {
                                    uint chTypeDef;
                                    uint dwTypeDefFlags;
                                    uint tkExtends;
                                    importer.GetTypeDefProps(ctoken, null, 0, out chTypeDef, out dwTypeDefFlags, out tkExtends);
                                    char[] typedefchars = new char[chTypeDef];
                                    importer.GetTypeDefProps(ctoken, typedefchars, (uint)typedefchars.Length, out chTypeDef, out dwTypeDefFlags, out tkExtends);
                                    chTypeDef--; // Remove nul.
                                    TypeDef = new string(typedefchars, 0, (int)chTypeDef);
                                }

                                //return TypeDef;
                                return "<" + TypeDef + ">";

                            }
                            return "";
                        }

                    case CorElementType.ELEMENT_TYPE_STRING:
                        {
                            ICorDebugStringValue pstr = (ICorDebugStringValue)pvalue;
                            uint cchStrx;
                            pstr.GetLength(out cchStrx);
                            IntPtr pStrx = Marshal.AllocHGlobal((int)cchStrx * 2);
                            pstr.GetString(cchStrx, out cchStrx, pStrx);
                            string Strx = Marshal.PtrToStringUni(pStrx, (int)cchStrx);
                            Marshal.FreeHGlobal(pStrx);
                            return "\"" + Strx.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"";
                        }

                    default:
                        return "<" + cortype.ToString() + ">";
                }
            }
 public static void CallParameterizedFunction(this ICorDebugEval2 instance, ICorDebugFunction pFunction, uint nTypeArgs, ICorDebugType[] ppTypeArgs, uint nArgs, ICorDebugValue[] ppArgs)
 {
     instance.__CallParameterizedFunction(pFunction, nTypeArgs, ppTypeArgs, nArgs, ppArgs);
 }
 public static void NewParameterizedObject(this ICorDebugEval2 instance, ICorDebugFunction pConstructor, uint nTypeArgs, ICorDebugType[] ppTypeArgs, uint nArgs, ICorDebugValue[] ppArgs)
 {
     instance.__NewParameterizedObject(pConstructor, nTypeArgs, ppTypeArgs, nArgs, ppArgs);
 }
        int ICorDebugAppDomain.GetObject( out ICorDebugValue ppObject )
        {
            ppObject = null;

            return Utility.COM_HResults.S_OK;
        }