internal MDbgDebuggerVar(string variableName, CorValue corValue) { // corValue can be null meaning that the variable is not available Debug.Assert(variableName!=null); m_name = variableName; m_corValue = corValue; }
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); }
/// <summary> /// Creates a new instance of the MDbgValue Object. /// This constructor is public so that applications can use this class to print values (CorValue). /// CorValue's can be returned for example by funceval(CorEval.Result). /// </summary> /// <param name="process">The Process that will own the Value.</param> /// <param name="value">The CorValue that this MDbgValue will start with.</param> public MDbgValue(MDbgProcess process, CorValue value) { // value can be null, but we should always know what process we are // looking at. Debug.Assert(process != null); Initialize(process, null, value); }
public void Reload () { if (loader != null) { // Obsolete value, get a new one CorValue v = loader (); version = CorDebuggerSession.EvaluationTimestamp; if (v != null) val = v; } }
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); }
internal CorHandleValue GetHandle (CorValue val) { CorHandleValue handleVal = null; if (!handles.TryGetValue (val.Address, out handleVal)) { handleVal = val.CastToHandleValue (); if (handleVal == null) { // Create a handle CorReferenceValue refVal = val.CastToReferenceValue (); CorHeapValue heapVal = refVal.Dereference ().CastToHeapValue (); handleVal = heapVal.CreateHandle (CorDebugHandleType.HANDLE_STRONG); } handles.Add (val.Address, handleVal); } return handleVal; }
/// <summary> /// Sets the EvalResult to the specified CorValue /// </summary> /// <param name="evalValue">What value to set the Result to.</param> /// <returns>Returns true on success else false.</returns> public bool SetEvalResult(CorValue evalValue) { Debug.Assert(evalValue!=null); if( evalValue==null ) throw new ArgumentException(); this["$result"].Value = evalValue; return true; }
public CorValRef (ValueLoader loader) { this.val = loader (); this.loader = loader; this.version = CorDebuggerSession.EvaluationTimestamp; }
public CorValRef (CorValue val) { this.val = val; this.version = CorDebuggerSession.EvaluationTimestamp; }
private void Unbox(ref CorValue value) { CorBoxValue boxVal = value.CastToBoxValue(); if (boxVal != null) value = boxVal.GetObject(); }
private object getValue(CorValue value) { var rv = value.CastToReferenceValue(); if (rv != null) { if (rv.IsNull) { _typename = rv.ExactType.Type; return null; } return getValue(rv.Dereference()); } var bv = value.CastToBoxValue(); if (bv != null) return getValue(bv.GetObject()); /*_type_map = { 'System.Boolean': ELEMENT_TYPE_BOOLEAN, 'System.SByte' : ELEMENT_TYPE_I1, 'System.Byte' : ELEMENT_TYPE_U1, 'System.Int16' : ELEMENT_TYPE_I2, 'System.UInt16' : ELEMENT_TYPE_U2, 'System.Int32' : ELEMENT_TYPE_I4, 'System.UInt32' : ELEMENT_TYPE_U4, 'System.IntPtr' : ELEMENT_TYPE_I, 'System.UIntPtr': ELEMENT_TYPE_U, 'System.Int64' : ELEMENT_TYPE_I8, 'System.UInt64' : ELEMENT_TYPE_U8, 'System.Single' : ELEMENT_TYPE_R4, 'System.Double' : ELEMENT_TYPE_R8, 'System.Char' : ELEMENT_TYPE_CHAR, }*/ var typeMap = new List<KeyValuePair<CorElementType, string>>(); typeMap.AddRange(new KeyValuePair<CorElementType, string>[] { new KeyValuePair<CorElementType, string>(CorElementType.ELEMENT_TYPE_BOOLEAN, "System.Boolean"), new KeyValuePair<CorElementType, string>(CorElementType.ELEMENT_TYPE_I1, "System.SByte"), new KeyValuePair<CorElementType, string>(CorElementType.ELEMENT_TYPE_U1, "System.Byte"), new KeyValuePair<CorElementType, string>(CorElementType.ELEMENT_TYPE_I2, "System.Int16"), new KeyValuePair<CorElementType, string>(CorElementType.ELEMENT_TYPE_U2, "System.UInt16"), new KeyValuePair<CorElementType, string>(CorElementType.ELEMENT_TYPE_I4, "System.Int32"), new KeyValuePair<CorElementType, string>(CorElementType.ELEMENT_TYPE_U4, "System.UInt32"), new KeyValuePair<CorElementType, string>(CorElementType.ELEMENT_TYPE_I, "System.IntPtr"), new KeyValuePair<CorElementType, string>(CorElementType.ELEMENT_TYPE_U, "System.UIntPtr"), new KeyValuePair<CorElementType, string>(CorElementType.ELEMENT_TYPE_I8, "System.Int64"), new KeyValuePair<CorElementType, string>(CorElementType.ELEMENT_TYPE_U8, "System.UInt64"), new KeyValuePair<CorElementType, string>(CorElementType.ELEMENT_TYPE_R4, "System.Single"), new KeyValuePair<CorElementType, string>(CorElementType.ELEMENT_TYPE_R8, "System.Double"), new KeyValuePair<CorElementType, string>(CorElementType.ELEMENT_TYPE_CHAR, "System.Char") }); if (typeMap.Exists(t => t.Key.Equals(value.Type))) return value.CastToGenericValue().GetValue(); else if (value.Type == CorElementType.ELEMENT_TYPE_STRING) return value.CastToStringValue().String; else if (value.Type == CorElementType.ELEMENT_TYPE_VALUETYPE) { var typeValue = value.ExactType.Type; if (typeMap.Exists(t => t.Value.Equals(_typename))) { var gv = value.CastToGenericValue(); return gv.UnsafeGetValueAsType(typeMap.Find(t => t.Value.Equals(_typename)).Key); } else return value.CastToObjectValue(); } else if (new CorElementType[] {CorElementType.ELEMENT_TYPE_CLASS, CorElementType.ELEMENT_TYPE_OBJECT}.Contains(value.Type)) return new object(); //value.CastToObjectValue(); else return "Unknown"; }
private void Initialize(MDbgProcess process, string name, CorValue value) { m_process = process; m_name = name; m_corValue = value; }
/// <summary> /// Recursively dereference the input value until we finally find a non-dereferenceable /// value. Along the way, optionally build up a "ptr string" that shows the addresses /// we dereference, separated by "->". /// </summary> /// <param name="value">Value to dereference</param> /// <param name="ptrStringBuilder">StringBuilder if caller wants us to generate /// a "ptr string" (in which case we'll stick it there). If caller doesn't want /// a ptr string, this can be null</param> /// <returns>CorValue we arrive at after dereferencing as many times as we can</returns> private CorValue Dereference(CorValue value, StringBuilder ptrStringBuilder) { while (true) { CorReferenceValue rv = value.CastToReferenceValue(); if (rv == null) break; // not a reference if (ptrStringBuilder != null) { if (ptrStringBuilder.Length > 0) { ptrStringBuilder.Append("->"); } ptrStringBuilder.Append("0x" + rv.Value.ToString("X", System.Globalization.CultureInfo.CurrentUICulture)); } // Bail as soon as we hit a reference to NULL if (rv.IsNull) return null; // reference to null CorValue newValue = null; try { newValue = rv.Dereference(); } catch (COMException ce) { // Check for any errors that are expected if (ce.ErrorCode != (int)HResult.CORDBG_E_VALUE_POINTS_TO_FUNCTION) { throw; // some other error } } if (newValue == null) break; // couldn't dereference the reference (eg. void*) value = newValue; } return value; }
public CorValue RuntimeInvoke (CorFunction function, CorType[] typeArgs, CorValue thisObj, CorValue[] arguments) { return Session.RuntimeInvoke (this, function, typeArgs, thisObj, arguments); }
private string MakePtrString(CorValue value) { StringBuilder sb = new StringBuilder(); while (true) { CorReferenceValue rv = value.CastToReferenceValue(); if (rv == null) break; // not a reference if (sb.Length > 0) { sb.Append("->"); } sb.Append("0x" + rv.Value.ToString("X", System.Globalization.CultureInfo.CurrentUICulture)); CorValue newValue = null; try { newValue = rv.Dereference(); } catch (COMException ce) { if (ce.ErrorCode != (int)HResult.CORDBG_E_BAD_REFERENCE_VALUE) { throw; // some other error } } if (newValue == null) break; // couldn't dereference the reference (eg. void* or invalid ref) value = newValue; } return sb.ToString(); }
private CorValue Dereference(CorValue value) { while (true) { CorReferenceValue rv = value.CastToReferenceValue(); if (rv == null) break; // not a reference if (rv.IsNull) return null; // reference to null CorValue newValue = rv.Dereference(); if (newValue == null) break; // couldn't dereference the reference (eg. void*) value = newValue; } return value; }
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; }
/// <summary> /// Creates a new instance of the MDbgValue Object. /// This constructor is public so that applications can use this class to print values (CorValue). /// CorValue's can be returned for example by funceval(CorEval.Result). /// </summary> /// <param name="process">The Process that will own the Value.</param> /// <param name="name">The name of the variable.</param> /// <param name="value">The CorValue that this MDbgValue will start with.</param> public MDbgValue(MDbgProcess process, string name, CorValue value) { Debug.Assert(process != null && name != null); // corValue can be null for native variables in MC++ Initialize(process, name, value); }