/// <summary> /// Gets the MDbgFunction for a given Function Token. /// </summary> /// <param name="functionToken">The Function Token to lookup.</param> /// <returns>The coresponding MDbgFunction.</returns> public MDbgFunction GetFunction(int functionToken) { CorFunction f = m_module.GetFunctionFromToken(functionToken); Debug.Assert(f != null); return(GetFunction(f)); }
public CorValue CreateCorValue(EvaluationContext ctx, CorType type, params CorValRef[] args) { CorEvaluationContext cctx = (CorEvaluationContext)ctx; CorValue[] vargs = new CorValue [args.Length]; for (int n = 0; n < args.Length; n++) { vargs [n] = args [n].Val; } Type t = type.GetTypeInfo(cctx.Session); MethodInfo ctor = null; foreach (MethodInfo met in t.GetMethods()) { if (met.IsSpecialName && met.Name == ".ctor") { ParameterInfo[] pinfos = met.GetParameters(); if (pinfos.Length == 1) { ctor = met; break; } } } if (ctor == null) { return(null); } CorFunction func = type.Class.Module.GetFunctionFromToken(ctor.MetadataToken); return(cctx.RuntimeInvoke(func, type.TypeParameters, null, vargs)); }
public CorMethodCall(CorEvaluationContext context, CorFunction function, CorType[] typeArgs, CorValue[] args) { this.context = context; this.function = function; this.typeArgs = typeArgs; this.args = args; eval = context.Eval; }
protected override BreakEventInfo OnInsertBreakEvent(BreakEvent be) { BreakEventInfo binfo = new BreakEventInfo(); lock (documents) { Breakpoint bp = be as Breakpoint; if (bp != null) { DocInfo doc; if (!documents.TryGetValue(System.IO.Path.GetFullPath(bp.FileName), out doc)) { binfo.SetStatus(BreakEventStatus.NotBound, null); return(binfo); } int line; try { line = doc.Document.FindClosestLine(bp.Line); } catch { // Invalid line binfo.SetStatus(BreakEventStatus.Invalid, null); return(binfo); } ISymbolMethod met = doc.Reader.GetMethodFromDocumentPosition(doc.Document, line, 0); if (met == null) { binfo.SetStatus(BreakEventStatus.Invalid, null); return(binfo); } int offset = -1; foreach (SequencePoint sp in met.GetSequencePoints()) { if (sp.Line == line && sp.Document.URL == doc.Document.URL) { offset = sp.Offset; break; } } if (offset == -1) { binfo.SetStatus(BreakEventStatus.Invalid, null); return(binfo); } CorFunction func = doc.Module.GetFunctionFromToken(met.Token.GetToken()); CorFunctionBreakpoint corBp = func.ILCode.CreateBreakpoint(offset); corBp.Activate(bp.Enabled); breakpoints[corBp] = binfo; binfo.Handle = corBp; binfo.SetStatus(BreakEventStatus.Bound, null); return(binfo); } } return(null); }
public override object RuntimeInvoke(EvaluationContext gctx, object gtargetType, object gtarget, string methodName, object[] ggenericArgTypes, object[] gargTypes, object[] gargValues) { // FIXME: support generic methods by using the genericArgTypes parameter CorType targetType = (CorType)gtargetType; CorValRef target = (CorValRef)gtarget; CorType[] argTypes = CastArray <CorType> (gargTypes); CorValRef[] argValues = CastArray <CorValRef> (gargValues); BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic; if (target != null) { flags |= BindingFlags.Instance; } else { flags |= BindingFlags.Static; } CorEvaluationContext ctx = (CorEvaluationContext)gctx; MethodInfo method = OverloadResolve(ctx, methodName, targetType, argTypes, flags, true); ParameterInfo[] parameters = method.GetParameters(); for (int n = 0; n < parameters.Length; n++) { if (parameters[n].ParameterType == typeof(object) && (IsValueType(ctx, argValues[n]))) { argValues[n] = Box(ctx, argValues[n]); } } if (method != null) { CorValRef v = new CorValRef(delegate { CorFunction func = targetType.Class.Module.GetFunctionFromToken(method.MetadataToken); CorValue[] args = new CorValue[argValues.Length]; for (int n = 0; n < args.Length; n++) { args[n] = argValues[n].Val; } return(ctx.RuntimeInvoke(func, new CorType[0], target != null ? target.Val : null, args)); }); if (v.Val == null) { return(null); } else { return(v); } } else { throw new EvaluatorException("Invalid method name or incompatible arguments."); } }
internal MDbgFunction(MDbgModule managedModule, CorFunction managedFunction) { Debug.Assert(managedModule != null); Debug.Assert(managedFunction != null); Debug.Assert(managedFunction.Version >= 0 && managedFunction.Version - 1 <= managedModule.EditsCounter); // version numbers starts with 1 m_module = managedModule; m_function = managedFunction; EnsureIsUpToDate(); }
public DebuggerMethod(Debugger debugger, CorFunction func) { debugger.Dispatcher.VerifyAccess(); this.debugger = debugger; CorFunction = func; hashCode = func.GetHashCode(); LocalVarSigToken = func.LocalVarSigToken; Token = func.Token; func.GetAttributes(out implAttributes, out attributes); }
public static ISymbolMethod GetSymbolMethod(this CorFunction func, CorDebuggerSession session) { ISymbolReader reader = session.GetReaderForModule(func.Module.Name); if (reader == null) { return(null); } return(reader.GetMethod(new SymbolToken(func.Token))); }
public ValueContext(ILocalsOwner localsOwner, CorFrame frame, DnThread thread) { this.LocalsOwner = localsOwner; this.Thread = thread; this.Process = thread.Process; // Read everything immediately since the frame will be neutered when Continue() is called this.FrameCouldBeNeutered = frame; frame.GetTypeAndMethodGenericParameters(out genericTypeArguments, out genericMethodArguments); this.Function = frame.Function; }
public ValueContext(ILocalsOwner localsOwner, CorFrame frame, DnThread thread, IList<CorType> genericTypeArguments) { this.LocalsOwner = localsOwner; this.Thread = thread; this.Process = thread.Process; // Read everything immediately since the frame will be neutered when Continue() is called this.FrameCouldBeNeutered = frame; this.genericTypeArguments = genericTypeArguments; this.genericMethodArguments = new CorType[0]; this.Function = frame == null ? null : frame.Function; }
/// <summary> /// Looks up a CorFunction. /// </summary> /// <param name="managedFunction">Which CorFunction to lookup.</param> /// <returns>The coresponding MDbgFunction.</returns> public MDbgFunction LookupFunction(CorFunction managedFunction) { if (managedFunction != null) { return(this.Lookup(managedFunction.Module).GetFunction(managedFunction)); } else { return(null); } }
/// <summary> /// Create a new instance of the FunctionRemapCompleteStopReason class. /// </summary> /// <param name="appDomain">The appDomain where remapping is occuring.</param> /// <param name="thread">The thread on which the remapping is occuring.</param> /// <param name="managedFunction">The version of function the debugger remapped to.</param> public FunctionRemapCompleteStopReason(CorAppDomain appDomain, CorThread thread, CorFunction managedFunction) { Debug.Assert(appDomain != null); Debug.Assert(thread != null); Debug.Assert(managedFunction != null); m_appDomain = appDomain; m_thread = thread; m_function = managedFunction; }
public ValueContext(ILocalsOwner localsOwner, CorFrame frame, DnThread thread, List <CorType> genericTypeArguments) { this.LocalsOwner = localsOwner; this.Thread = thread; this.Process = thread.Process; // Read everything immediately since the frame will be neutered when Continue() is called this.FrameCouldBeNeutered = frame; this.genericTypeArguments = genericTypeArguments; this.genericMethodArguments = new List <CorType>(); this.Function = frame?.Function; }
static void ProcessCommand(CorProcess process) { Task.Run(() => { while (true) { Console.Write("> "); String command = Console.ReadLine(); if (command.StartsWith("set-break", StringComparison.Ordinal)) { // setting breakpoint command = command.Remove(0, "set-break".Length).Trim(); // try module!type.method location (simple regex used) Match match = methodBreakpointRegex.Match(command); if (match.Groups["method"].Length > 0) { Console.Write("Setting method breakpoint... "); CorFunction func = process.ResolveFunctionName(match.Groups["module"].Value, match.Groups["class"].Value, match.Groups["method"].Value); func.CreateBreakpoint().Activate(true); Console.WriteLine("done."); continue; } // try file code:line location match = codeBreakpointRegex.Match(command); if (match.Groups["filepath"].Length > 0) { Console.Write("Setting code breakpoint..."); int offset; CorCode code = process.ResolveCodeLocation(match.Groups["filepath"].Value, Int32.Parse(match.Groups["linenum"].Value), out offset); code.CreateBreakpoint(offset).Activate(true); Console.WriteLine("done."); continue; } } else if (command.StartsWith("go", StringComparison.Ordinal)) { process.Continue(false); ProcessCommand(process); break; } } }); }
public static System.Reflection.MethodInfo GetMethodInfo(this CorFunction func, CorDebuggerSession session) { CorMetadataImport mi = session.GetMetadataForModule(func.Module.Name); if (mi != null) { return(mi.GetMethodInfo(func.Token)); } else { return(null); } }
public static MDbgEngine invoke_Method(this MDbgEngine engine, CorFunction function, CorValue[] parameters) { try { var eval = engine.corEval(); eval.CallFunction(function, parameters); engine.goAndWait(); } catch (Exception ex) { "[MDbgEngine] invoke_Method: {0}".error(ex.Message); } return(engine); }
protected override object OnInsertBreakEvent(BreakEvent be, bool activate) { lock (documents) { Breakpoint bp = be as Breakpoint; if (bp != null) { DocInfo doc; if (!documents.TryGetValue(System.IO.Path.GetFullPath(bp.FileName), out doc)) { return(null); } int line; try { line = doc.Document.FindClosestLine(bp.Line); } catch { // Invalid line return(null); } ISymbolMethod met = doc.Reader.GetMethodFromDocumentPosition(doc.Document, line, 0); if (met == null) { return(null); } int offset = -1; foreach (SequencePoint sp in met.GetSequencePoints()) { if (sp.Line == line && sp.Document.URL == doc.Document.URL) { offset = sp.Offset; break; } } if (offset == -1) { return(null); } CorFunction func = doc.Module.GetFunctionFromToken(met.Token.GetToken()); CorFunctionBreakpoint corBp = func.ILCode.CreateBreakpoint(offset); corBp.Activate(activate); return(corBp); } } return(null); }
public RemapOpportunityReachedStopReason(CorAppDomain appDomain, CorThread thread, CorFunction oldFunction, CorFunction newFunction, int oldILOffset) { Debug.Assert(appDomain != null); Debug.Assert(thread != null); Debug.Assert(oldFunction != null); Debug.Assert(newFunction != null); m_appDomain = appDomain; m_thread = thread; m_oldFunction = oldFunction; m_newFunction = newFunction; m_oldILOffset = oldILOffset; }
public MDbgFunction Get(CorFunction managedFunction) { int funcVersion; funcVersion = managedFunction.Version; // now get version from our cache. MDbgFunction mdbgFunction = RetrieveFromCache(managedFunction.Token, funcVersion); if (mdbgFunction == null) { mdbgFunction = new MDbgFunction(m_module, managedFunction); AddToCache(managedFunction.Token, funcVersion, mdbgFunction); } return(mdbgFunction); }
public ValueContext(ILocalsOwner localsOwner, CorFrame frame, DnThread thread, DnProcess process) { this.LocalsOwner = localsOwner; this.Thread = thread; this.Process = process; Debug.Assert(thread == null || thread.Process == process); // Read everything immediately since the frame will be neutered when Continue() is called this.FrameCouldBeNeutered = frame; if (frame == null) { genericTypeArguments = genericMethodArguments = new List<CorType>(); this.Function = null; } else { frame.GetTypeAndMethodGenericParameters(out genericTypeArguments, out genericMethodArguments); this.Function = frame.Function; } }
public ValueContext(ILocalsOwner localsOwner, CorFrame frame, DnThread thread, DnProcess process) { this.LocalsOwner = localsOwner; this.Thread = thread; this.Process = process; Debug.Assert(thread == null || thread.Process == process); // Read everything immediately since the frame will be neutered when Continue() is called this.FrameCouldBeNeutered = frame; if (frame == null) { genericTypeArguments = genericMethodArguments = new List <CorType>(); this.Function = null; } else { frame.GetTypeAndMethodGenericParameters(out genericTypeArguments, out genericMethodArguments); this.Function = frame.Function; } }
public EvalResult Call(CorFunction func, CorValue[] args) { return Call(func, null, args); }
internal override CorCode GetCode(CorFunction func) => func.NativeCode;
public CorValue RuntimeInvoke(CorFunction function, CorType[] typeArgs, CorValue thisObj, CorValue[] arguments) { return(Session.RuntimeInvoke(this, function, typeArgs, thisObj, arguments)); }
/// <summary> /// Gets the MDbgFunction for a given CorFunction. /// </summary> /// <param name="managedFunction">The CorFunction to lookup.</param> /// <returns>The coresponding MDbgFunction.</returns> public MDbgFunction GetFunction(CorFunction managedFunction) { return(m_functions.Get(managedFunction)); }
public CodeLocation(CorFunction func, uint offset, CorDebugMappingResult mapping) { Function = func; Offset = offset; Mapping = mapping; }
/// <summary> /// Looks up a CorFunction. /// </summary> /// <param name="managedFunction">Which CorFunction to lookup.</param> /// <returns>The coresponding MDbgFunction.</returns> public MDbgFunction LookupFunction(CorFunction managedFunction) { return(this.Lookup(managedFunction.Module).GetFunction(managedFunction)); }
public ValueContext(ILocalsOwner localsOwner, CorFrame frame, DnThread thread, List<CorType> genericTypeArguments) { LocalsOwner = localsOwner; Thread = thread; Process = thread.Process; // Read everything immediately since the frame will be neutered when Continue() is called FrameCouldBeNeutered = frame; this.genericTypeArguments = genericTypeArguments; genericMethodArguments = new List<CorType>(); Function = frame?.Function; }
internal override CorCode GetCode(CorFunction func) { return func.NativeCode; }
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 EvalResult? Call(CorFunction func, CorType[] typeArgs, CorValue[] args, out int hr) { return WaitForResult(hr = eval.CallParameterizedFunction(func, typeArgs, args)); }
public CorValueResult CallResult(CorFunction func, CorType[] typeArgs, CorValue[] args, out int hr) { var res = Call(func, typeArgs, args, out hr); if (res == null || res.Value.WasException || res.Value.ResultOrException == null) return new CorValueResult(); return res.Value.ResultOrException.Value; }
internal abstract CorCode GetCode(CorFunction func);
public EvalResult Call(CorFunction func, CorType[] typeArgs, CorValue[] args) { int hr; var res = Call(func, typeArgs, args, out hr); if (res != null) return res.Value; throw new EvalException(hr, string.Format("Could not call method {0:X8}, HR=0x{1:X8}", func.Token, hr)); }
public EvalResult CallConstructor(CorFunction ctor, CorValue[] args) => CallConstructor(ctor, null, args);
public CorValueResult CallResult(CorFunction func, CorValue[] args) { return CallResult(func, null, args); }
public EvalResult CallConstructor(CorFunction ctor, CorType[] typeArgs, CorValue[] args) { int hr; var res = CallConstructor(ctor, typeArgs, args, out hr); if (res != null) return res.Value; throw new EvalException(hr, string.Format("Could not call .ctor {0:X8}, HR=0x{1:X8}", ctor.Token, hr)); }
public static MDbgEngine invoke_Method(this MDbgEngine engine, CorFunction function, params string[] stringValues) { var corValues = engine.corValues(stringValues); return(engine.invoke_Method(function, corValues)); }
public EvalResult? CallConstructor(CorFunction func, CorType[] typeArgs, CorValue[] args, out int hr) => WaitForResult(hr = eval.NewParameterizedObject(func, typeArgs, args));
public ILDbgEngineStackFrame(DbgEngineImpl engine, DbgModule module, CorFrame corFrame, DnThread dnThread, CorFunction corFunction, Lazy <DbgDotNetNativeCodeLocationFactory> dbgDotNetNativeCodeLocationFactory, Lazy <DbgDotNetCodeLocationFactory> dbgDotNetCodeLocationFactory) { Debug.Assert(!corFrame.IsNeutered); this.engine = engine ?? throw new ArgumentNullException(nameof(engine)); Module = module ?? throw new ArgumentNullException(nameof(module)); __corFrame_DONT_USE = corFrame ?? throw new ArgumentNullException(nameof(corFrame)); this.dnThread = dnThread ?? throw new ArgumentNullException(nameof(dnThread)); FunctionToken = corFunction?.Token ?? throw new ArgumentNullException(nameof(corFunction)); uint functionOffset; DbgILOffsetMapping ilOffsetMapping; Debug.Assert(corFrame.IsILFrame); var ip = corFrame.ILFrameIP; if (ip.IsExact) { functionOffset = ip.Offset; ilOffsetMapping = DbgILOffsetMapping.Exact; } else if (ip.IsApproximate) { functionOffset = ip.Offset; ilOffsetMapping = DbgILOffsetMapping.Approximate; } else if (ip.IsProlog) { Debug.Assert(ip.Offset == 0); functionOffset = ip.Offset; // 0 ilOffsetMapping = DbgILOffsetMapping.Prolog; } else if (ip.IsEpilog) { functionOffset = ip.Offset; // end of method == DebuggerJitInfo.m_lastIL ilOffsetMapping = DbgILOffsetMapping.Epilog; } else if (ip.HasNoInfo) { functionOffset = uint.MaxValue; ilOffsetMapping = DbgILOffsetMapping.NoInfo; } else if (ip.IsUnmappedAddress) { functionOffset = uint.MaxValue; ilOffsetMapping = DbgILOffsetMapping.UnmappedAddress; } else { Debug.Fail($"Unknown mapping: {ip.Mapping}"); functionOffset = uint.MaxValue; ilOffsetMapping = DbgILOffsetMapping.Unknown; } FunctionOffset = functionOffset; var moduleId = engine.TryGetModuleId(corFrame).GetValueOrDefault().ToModuleId(); var nativeCode = corFrame.Code; Debug.Assert(nativeCode?.IsIL == false); if (nativeCode?.IsIL == false) { var corCode = engine.CreateDnDebuggerObjectHolder(nativeCode); Location = dbgDotNetNativeCodeLocationFactory.Value.Create(module, moduleId, FunctionToken, FunctionOffset, ilOffsetMapping, corCode.Object?.Address ?? 0, corFrame.NativeFrameIP, corCode); } else { Location = dbgDotNetCodeLocationFactory.Value.Create(moduleId, FunctionToken, FunctionOffset, ilOffsetMapping); } }