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); }
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); }
public FieldReference (EvaluationContext ctx, CorValRef thisobj, CorType type, FieldInfo field) : base (ctx) { this.thisobj = thisobj; this.type = type; this.field = field; if (!field.IsStatic) this.thisobj = thisobj; loader = delegate { return ((CorValRef)Value).Val; }; }
public PropertyReference (EvaluationContext ctx, PropertyInfo prop, CorValRef thisobj, CorType declaringType, CorValRef[] index) : base (ctx) { this.prop = prop; this.declaringType = declaringType; this.module = declaringType.Class.Module; this.index = index; if (!prop.GetGetMethod (true).IsStatic) this.thisobj = thisobj; loader = delegate { return ((CorValRef)Value).Val; }; }
// // IEnumerator interface // public bool MoveNext () { if( m_enum==null ) return false; ICorDebugType[] a = new ICorDebugType[1]; uint c = 0; int r = m_enum.Next ((uint) a.Length, a, out c); if (r==0 && c==1) // S_OK && we got 1 new element m_ty = new CorType (a[0]); else m_ty = null; return m_ty != null; }
public FieldReference (EvaluationContext ctx, CorValRef thisobj, CorType type, FieldInfo field, string vname, ObjectValueFlags vflags) : base (ctx) { this.thisobj = thisobj; this.type = type; this.field = field; this.vname = vname; if (field.IsStatic) this.thisobj = null; flags = vflags | GetFlags (field); loader = delegate { return ((CorValRef)Value).Val; }; }
public CorType GetParameterizedType(CorElementType elementType, CorType[] typeArguments) { ICorDebugType[] types = null; uint length = 0; if (typeArguments != null) { types = new ICorDebugType[typeArguments.Length]; for (int i = 0; i < typeArguments.Length; i++) types[i] = typeArguments[i].m_type; length = (uint)typeArguments.Length; } ICorDebugType pType; (m_class as ICorDebugClass2).GetParameterizedType(elementType, length, types, out pType); return pType==null?null:new CorType (pType); }
public PropertyReference (EvaluationContext ctx, PropertyInfo prop, CorValRef thisobj, CorType declaringType, CorValRef[] index) : base (ctx) { this.prop = prop; this.declaringType = declaringType; if (declaringType.Type == CorElementType.ELEMENT_TYPE_ARRAY || declaringType.Type == CorElementType.ELEMENT_TYPE_SZARRAY) { this.module = ((CorType)((CorEvaluationContext)ctx).Adapter.GetType (ctx, "System.Object")).Class.Module; } else { this.module = declaringType.Class.Module; } this.index = index; if (!prop.GetGetMethod (true).IsStatic) this.thisobj = thisobj; flags = GetFlags (prop); loader = delegate { return ((CorValRef)Value).Val; }; }
/// <summary> /// Get a CorType that function for this frame is declared in. /// </summary> /// <returns>The cortype of the function</returns> private CorType GetClassType() { CorClass c = thisFrame.Function.Class; if (TokenUtils.RidFromToken(c.Token) != 1 && TokenUtils.RidFromToken(c.Token) != 0) { // ICorDebug API lets us always pass ET_Class CorElementType et = CorElementType.ELEMENT_TYPE_CLASS; // Get type parameters. IEnumerable typars = thisFrame.TypeParameters; //IEnumerator tyenum = typars.GetEnumerator(); int cNumTyParamsOnClass = metaImporter.CountGenericParams(c.Token); CorType[] types = new CorType[cNumTyParamsOnClass]; int it = 0; foreach (CorType arg in typars) { if (it == cNumTyParamsOnClass) { break; } types[it] = arg; it++; } return c.GetParameterizedType(et, types); } else return null; }
public FieldReference (EvaluationContext ctx, CorValRef thisobj, CorType type, FieldInfo field) : this (ctx, thisobj, type, field, null, ObjectValueFlags.Field) { }
public void NewParameterizedArray(CorType type, int rank, int dims, int lowBounds) { ICorDebugEval2 eval2 = (ICorDebugEval2) m_eval; uint udims = (uint)dims; uint ulowBounds = (uint)lowBounds; eval2.NewParameterizedArray(type.m_type, (uint)rank, ref udims, ref ulowBounds); }
public void NewParameterizedObjectNoConstructor(CorClass managedClass, CorType[] argumentTypes) { ICorDebugType[] types = null; int typesLength=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; } eval2.NewParameterizedObjectNoConstructor(managedClass.m_class, (uint)typesLength, types); }
/** Returns CorType object for an array of or pointer to the given type */ public CorType GetArrayOrPointerType(CorElementType elementType, int rank, CorType parameterTypes) { ICorDebugType ct = null; uint urank = (uint) rank; (_ad() as ICorDebugAppDomain2).GetArrayOrPointerType(elementType, urank, parameterTypes.m_type, out ct); return ct==null?null:new CorType (ct); }
/** Returns CorType object for a pointer to a function */ public CorType GetFunctionPointerType(CorType[] parameterTypes) { ICorDebugType[] types = null; if (parameterTypes != null) { types = new ICorDebugType[parameterTypes.Length]; for (int i = 0; i < parameterTypes.Length; i++) types[i] = parameterTypes[i].m_type; } ICorDebugType ct = null; (_ad() as ICorDebugAppDomain2).GetFunctionPointerType((uint)types.Length, types, out ct); return ct==null?null:new CorType (ct); }
/// <summary> /// Gets the full class path of the function /// </summary> /// <param name="sb">string builder to be used to create full class path</param> /// <param name="ct">The cortype of the function</param> // Ignore the complexity warning - don't want to rewrite it now. private void GetFunctionClassPath(StringBuilder sb, CorType ct) { //StringBuilder sb, CorType ct, CorMetadataImport importer switch (ct.Type) { case CorElementType.ELEMENT_TYPE_CLASS: case CorElementType.ELEMENT_TYPE_VALUETYPE: // We need to get the name from the metadata. We can get a cached metadata importer // from a MDbgModule, or we could get a new one from the CorModule directly. // Is this hash lookup to get a MDbgModule cheaper than just re-querying for the importer? CorClass cc = ct.Class; Type tn = metaImporter.GetType(cc.Token); sb.Append(tn.FullName); //AddGenericArgs(sb, proc, ct.TypeParameters); return; // Primitives case CorElementType.ELEMENT_TYPE_BOOLEAN: sb.Append("System.Boolean"); return; case CorElementType.ELEMENT_TYPE_CHAR: sb.Append("System.Char"); return; case CorElementType.ELEMENT_TYPE_I1: sb.Append("System.SByte"); return; case CorElementType.ELEMENT_TYPE_U1: sb.Append("System.Byte"); return; case CorElementType.ELEMENT_TYPE_I2: sb.Append("System.Int16"); return; case CorElementType.ELEMENT_TYPE_U2: sb.Append("System.UInt16"); return; case CorElementType.ELEMENT_TYPE_I4: sb.Append("System.Int32"); return; case CorElementType.ELEMENT_TYPE_U4: sb.Append("System.Uint32"); return; case CorElementType.ELEMENT_TYPE_I8: sb.Append("System.Int64"); return; case CorElementType.ELEMENT_TYPE_U8: sb.Append("System.UInt64"); return; case CorElementType.ELEMENT_TYPE_I: sb.Append("System.IntPtr"); return; case CorElementType.ELEMENT_TYPE_U: sb.Append("System.UIntPtr"); return; case CorElementType.ELEMENT_TYPE_R4: sb.Append("System.Single"); return; case CorElementType.ELEMENT_TYPE_R8: sb.Append("System.Double"); return; // Well known class-types. case CorElementType.ELEMENT_TYPE_OBJECT: sb.Append("System.Object"); return; case CorElementType.ELEMENT_TYPE_STRING: sb.Append("System.String"); return; // Special compound types. Based off first type-param case CorElementType.ELEMENT_TYPE_SZARRAY: case CorElementType.ELEMENT_TYPE_ARRAY: case CorElementType.ELEMENT_TYPE_BYREF: case CorElementType.ELEMENT_TYPE_PTR: CorType t = ct.FirstTypeParameter; GetFunctionClassPath(sb, t); switch (ct.Type) { case CorElementType.ELEMENT_TYPE_SZARRAY: sb.Append("[]"); return; case CorElementType.ELEMENT_TYPE_ARRAY: int rank = ct.Rank; sb.Append('['); for (int i = 0; i < rank - 1; i++) { // <strip>@todo- could we print out exact boundaries? // Probably would have to do some sort of func-eval on the array object.</strip> sb.Append(','); } sb.Append(']'); return; case CorElementType.ELEMENT_TYPE_BYREF: sb.Append("&"); return; case CorElementType.ELEMENT_TYPE_PTR: sb.Append("*"); return; } Debug.Assert(false); // shouldn't have gotten here. return; // <strip>Other wacky stuff. // @todo - can we do a better job of printing these?</strip> case CorElementType.ELEMENT_TYPE_FNPTR: sb.Append("*(...)"); return; case CorElementType.ELEMENT_TYPE_TYPEDBYREF: sb.Append("typedbyref"); return; default: sb.Append("<unknown>"); return; } }
public CorValue RuntimeInvoke (CorFunction function, CorType[] typeArgs, CorValue thisObj, CorValue[] arguments) { return Session.RuntimeInvoke (this, function, typeArgs, thisObj, arguments); }
// Return class as a string. /// <summary> /// Creates a string representation of CorType. /// </summary> /// <param name="proc">A debugged process.</param> /// <param name="ct">A CorType object representing a type in the debugged process.</param> /// <returns>String representaion of the passed in type.</returns> public static string PrintCorType(MDbgProcess proc, CorType ct) { StringBuilder sb = new StringBuilder(); PrintCorType(sb, proc, ct); return sb.ToString(); }
public void Reset () { if( m_enum!=null ) m_enum.Reset (); m_ty = null; }
public CorValue RuntimeInvoke (CorEvaluationContext ctx, CorFunction function, CorType[] typeArgs, CorValue thisObj, CorValue[] arguments) { if (!ctx.Thread.ActiveChain.IsManaged) throw new EvaluatorException ("Cannot evaluate expression because the thread is stopped in native code."); CorValue[] args; if (thisObj == null) args = arguments; else { args = new CorValue[arguments.Length + 1]; args[0] = thisObj; arguments.CopyTo (args, 1); } CorMethodCall mc = new CorMethodCall (); CorValue exception = null; CorEval eval = ctx.Eval; EvalEventHandler completeHandler = delegate (object o, CorEvalEventArgs eargs) { OnEndEvaluating (); mc.DoneEvent.Set (); eargs.Continue = false; }; EvalEventHandler exceptionHandler = delegate (object o, CorEvalEventArgs eargs) { OnEndEvaluating (); exception = eargs.Eval.Result; mc.DoneEvent.Set (); eargs.Continue = false; }; process.OnEvalComplete += completeHandler; process.OnEvalException += exceptionHandler; mc.OnInvoke = delegate { if (function.GetMethodInfo (this).Name == ".ctor") eval.NewParameterizedObject (function, typeArgs, args); else eval.CallParameterizedFunction (function, typeArgs, args); process.SetAllThreadsDebugState (CorDebugThreadState.THREAD_SUSPEND, ctx.Thread); ClearEvalStatus (); OnStartEvaluating (); process.Continue (false); }; mc.OnAbort = delegate { eval.Abort (); }; mc.OnGetDescription = delegate { System.Reflection.MethodInfo met = function.GetMethodInfo (ctx.Session); if (met != null) return met.Name; else return "<Unknown>"; }; try { ObjectAdapter.AsyncExecute (mc, ctx.Options.EvaluationTimeout); } finally { process.OnEvalComplete -= completeHandler; process.OnEvalException -= exceptionHandler; } if (exception != null) { /* ValueReference<CorValue, CorType> msg = ctx.Adapter.GetMember (ctx, val, "Message"); if (msg != null) { string s = msg.ObjectValue as string; mc.ExceptionMessage = s; } else mc.ExceptionMessage = "Evaluation failed.";*/ CorValRef vref = new CorValRef (exception); throw new EvaluatorException ("Evaluation failed: " + ObjectAdapter.GetValueTypeName (ctx, vref)); } return eval.Result; }
public void Reset() { if( m_enum!=null ) m_enum.Reset (); m_ty = null; }
bool IsNullableType(CorType ct) { if (ct.Type != CorElementType.ELEMENT_TYPE_VALUETYPE) return false; MDbgModule m = m_process.Modules.Lookup(ct.Class.Module); String name = m.Importer.GetType(ct.Class.Token).FullName; return name.Equals("System.Nullable`1"); }
public PropertyReference (EvaluationContext ctx, PropertyInfo prop, CorValRef thisobj, CorType declaringType) : this (ctx, prop, thisobj, declaringType, null) { }
public void Skip(int celt) { m_enum.Skip((uint)celt); m_ty = null; }
public void Skip(int celt) { m_enum.Skip ((uint)celt); m_ty = null; }
// Print CorType to the given string builder. // Will print generic info. internal static void PrintCorType(StringBuilder sb, MDbgProcess proc, CorType ct) { switch (ct.Type) { case CorElementType.ELEMENT_TYPE_CLASS: case CorElementType.ELEMENT_TYPE_VALUETYPE: // We need to get the name from the metadata. We can get a cached metadata importer // from a MDbgModule, or we could get a new one from the CorModule directly. // Is this hash lookup to get a MDbgModule cheaper than just re-querying for the importer? CorClass cc = ct.Class; MDbgModule m = proc.Modules.Lookup(cc.Module); Type tn = m.Importer.GetType(cc.Token); sb.Append(tn.FullName); AddGenericArgs(sb, proc, ct.TypeParameters); return; // Primitives case CorElementType.ELEMENT_TYPE_BOOLEAN: sb.Append("System.Boolean"); return; case CorElementType.ELEMENT_TYPE_CHAR: sb.Append("System.Char"); return; case CorElementType.ELEMENT_TYPE_I1: sb.Append("System.SByte"); return; case CorElementType.ELEMENT_TYPE_U1: sb.Append("System.Byte"); return; case CorElementType.ELEMENT_TYPE_I2: sb.Append("System.Int16"); return; case CorElementType.ELEMENT_TYPE_U2: sb.Append("System.UInt16"); return; case CorElementType.ELEMENT_TYPE_I4: sb.Append("System.Int32"); return; case CorElementType.ELEMENT_TYPE_U4: sb.Append("System.Uint32"); return; case CorElementType.ELEMENT_TYPE_I8: sb.Append("System.Int64"); return; case CorElementType.ELEMENT_TYPE_U8: sb.Append("System.UInt64"); return; case CorElementType.ELEMENT_TYPE_I: sb.Append("System.IntPtr"); return; case CorElementType.ELEMENT_TYPE_U: sb.Append("System.UIntPtr"); return; case CorElementType.ELEMENT_TYPE_R4: sb.Append("System.Single"); return; case CorElementType.ELEMENT_TYPE_R8: sb.Append("System.Double"); return; // Well known class-types. case CorElementType.ELEMENT_TYPE_OBJECT: sb.Append("System.Object"); return; case CorElementType.ELEMENT_TYPE_STRING: sb.Append("System.String"); return; // Special compound types. Based off first type-param case CorElementType.ELEMENT_TYPE_SZARRAY: case CorElementType.ELEMENT_TYPE_ARRAY: case CorElementType.ELEMENT_TYPE_BYREF: case CorElementType.ELEMENT_TYPE_PTR: CorType t = ct.FirstTypeParameter; PrintCorType(sb, proc, t); switch(ct.Type) { case CorElementType.ELEMENT_TYPE_SZARRAY: sb.Append("[]"); return; case CorElementType.ELEMENT_TYPE_ARRAY: int rank = ct.Rank; sb.Append('['); for(int i = 0; i < rank - 1; i++) { sb.Append(','); } sb.Append(']'); return; case CorElementType.ELEMENT_TYPE_BYREF: sb.Append("&"); return; case CorElementType.ELEMENT_TYPE_PTR: sb.Append("*"); return; } Debug.Assert(false); // shouldn't have gotten here. return; case CorElementType.ELEMENT_TYPE_FNPTR: sb.Append("*(...)"); return; case CorElementType.ELEMENT_TYPE_TYPEDBYREF: sb.Append("typedbyref"); return; default: sb.Append("<unknown>"); return; } } // end PrintClass
public CorValue NewArray (CorEvaluationContext ctx, CorType elemType, int size) { ManualResetEvent doneEvent = new ManualResetEvent (false); CorValue result = null; EvalEventHandler completeHandler = delegate (object o, CorEvalEventArgs eargs) { OnEndEvaluating (); result = eargs.Eval.Result; doneEvent.Set (); eargs.Continue = false; }; EvalEventHandler exceptionHandler = delegate (object o, CorEvalEventArgs eargs) { OnEndEvaluating (); result = eargs.Eval.Result; doneEvent.Set (); eargs.Continue = false; }; try { process.OnEvalComplete += completeHandler; process.OnEvalException += exceptionHandler; ctx.Eval.NewParameterizedArray (elemType, 1, 1, 0); process.SetAllThreadsDebugState (CorDebugThreadState.THREAD_SUSPEND, ctx.Thread); OnStartEvaluating (); ClearEvalStatus (); process.Continue (false); if (doneEvent.WaitOne (ctx.Options.EvaluationTimeout, false)) return result; else return null; } finally { process.OnEvalComplete -= completeHandler; process.OnEvalException -= exceptionHandler; } }
/// <summary> /// Resolves a type from a Variable Name. /// </summary> /// <param name="typeName">The name of the type to resolve.</param> /// <param name="appDomain">The AppDomain to resolve the type in or null if any /// AppDomain is acceptable</param> /// <returns>The CorType of that Variable.</returns> public CorType ResolveType(string typeName, CorAppDomain appDomain) { MDbgModule mod; CorClass cc = ResolveClass(typeName, appDomain, out mod); if (cc == null) { return null; } CorType[] cta = new CorType[0]; return cc.GetParameterizedType(CorElementType.ELEMENT_TYPE_CLASS, cta); }