Example #1
0
 public StackFrame(Debugger debugger, CorFrame frame, int frameNo)
 {
     debugger.Dispatcher.VerifyAccess();
     this.debugger      = debugger;
     this.frame         = frame;
     this.frameNo       = frameNo;
     this.hashCode      = frame.GetHashCode();
     this.ilFrameIP     = new Contracts.Scripting.Debugger.ILFrameIP(frame.ILFrameIP.Offset, (MappingResult)frame.ILFrameIP.Mapping);
     this.nativeFrameIP = frame.NativeFrameIP;
     this.token         = frame.Token;
     this.stackStart    = frame.StackStart;
     this.stackEnd      = frame.StackEnd;
     this.sfFlags       = 0;
     if (frame.IsILFrame)
     {
         this.sfFlags |= SFFlags.ILFrame;
     }
     if (frame.IsInternalFrame)
     {
         this.sfFlags |= SFFlags.InternalFrame;
     }
     if (frame.IsNativeFrame)
     {
         this.sfFlags |= SFFlags.NativeFrame;
     }
     if (frame.IsRuntimeUnwindableFrame)
     {
         this.sfFlags |= SFFlags.RuntimeUnwindableFrame;
     }
 }
Example #2
0
        public static uint GetILOffset(this CorFrame frame)
        {
            var ip = frame.ILFrameIP;

            if (ip.IsExact || ip.IsApproximate)
            {
                return(ip.Offset);
            }
            if (ip.IsProlog)
            {
                return(0);
            }

            if (ip.IsEpilog)
            {
                var asm = frame.GetSerializedDnModuleWithAssembly();
                if (asm != null)
                {
                    var loadedAsm = MainWindow.Instance.LoadAssembly(asm.Value.Assembly, asm.Value.Module);
                    var mod       = loadedAsm == null ? null : loadedAsm.ModuleDefinition as ModuleDefMD;
                    var md        = mod == null ? null : mod.ResolveToken(frame.Token) as MethodDef;
                    if (md != null && md.Body != null && md.Body.Instructions.Count > 0)
                    {
                        return(md.Body.Instructions[md.Body.Instructions.Count - 1].Offset);
                    }
                }
            }

            return(uint.MaxValue);
        }
Example #3
0
        KeyValuePair <ModuleTokenId, uint>?GetModuleTokenId(CorFrame frame)
        {
            if (!frame.IsILFrame)
            {
                return(null);
            }
            var ip = frame.ILFrameIP;

            if (!ip.IsExact && !ip.IsApproximate && !ip.IsProlog && !ip.IsEpilog)
            {
                return(null);
            }
            uint token = frame.Token;

            if (token == 0)
            {
                return(null);
            }
            var mod = frame.DnModuleId;

            if (mod == null)
            {
                return(null);
            }
            return(new KeyValuePair <ModuleTokenId, uint>(new ModuleTokenId(mod.Value.ToModuleId(), frame.Token), ip.Offset));
        }
Example #4
0
        public static uint GetILOffset(this CorFrame frame, IModuleLoader moduleLoader)
        {
            var ip = frame.ILFrameIP;

            if (ip.IsExact || ip.IsApproximate)
            {
                return(ip.Offset);
            }
            if (ip.IsProlog)
            {
                return(0);
            }

            if (ip.IsEpilog)
            {
                var func = frame.Function;
                var file = func == null ? null : moduleLoader.LoadModule(func.Module, true);
                var mod  = file == null ? null : file.ModuleDef;
                var md   = mod == null ? null : mod.ResolveToken(frame.Token) as MethodDef;
                if (md != null && md.Body != null && md.Body.Instructions.Count > 0)
                {
                    return(md.Body.Instructions[md.Body.Instructions.Count - 1].Offset);
                }
            }

            return(uint.MaxValue);
        }
Example #5
0
        public static uint GetILOffset(this CorFrame frame, IModuleLoader moduleLoader)
        {
            var ip = frame.ILFrameIP;

            if (ip.IsExact || ip.IsApproximate)
            {
                return(ip.Offset);
            }
            if (ip.IsProlog)
            {
                return(0);
            }

            if (ip.IsEpilog)
            {
                var mod = moduleLoader.LoadModule(frame.Function?.Module, canLoadDynFile: true, isAutoLoaded: true)?.ModuleDef;
                var md  = mod?.ResolveToken(frame.Token) as MethodDef;
                if (md != null && md.Body != null && md.Body.Instructions.Count > 0)
                {
                    return(md.Body.Instructions[md.Body.Instructions.Count - 1].Offset);
                }
            }

            return(uint.MaxValue);
        }
Example #6
0
        public static CachedOutput Create(CorFrame frame, TypePrinterFlags flags)
        {
            var output = new TypeOutput();

            frame.Write(output, flags);
            return(output.cachedOutput);
        }
Example #7
0
 public CallStackFrameVM(ICallStackFrameContext context, int index, CorFrame frame, DnProcess process)
 {
     this.context = context;
     this.index   = index;
     this.frame   = frame;
     this.process = process;
 }
Example #8
0
        private void AddLocalVariablesToList(CorFrame frame, int ip, ArrayList listToAdd, ISymbolScope scope)
        {
            Debug.Assert(frame.FunctionToken == m_function.Token);

            foreach (ISymbolVariable isv in scope.GetLocals())
            {
                Debug.Assert(isv.AddressKind == SymAddressKind.ILOffset);
                CorValue v = null;
                try
                {
                    v = frame.GetLocalVariable(isv.AddressField1);
                }
                catch (System.Runtime.InteropServices.COMException e)
                {
                    if (e.ErrorCode != (int)Microsoft.Samples.Debugging.CorDebug.HResult.CORDBG_E_IL_VAR_NOT_AVAILABLE)
                    {
                        throw;
                    }
                }

                listToAdd.Add(new MDbgValue(m_module.Process, isv.Name, v));
            }

            foreach (ISymbolScope s in scope.GetChildren())
            {
                if (s.StartOffset <= ip && s.EndOffset >= ip)
                {
                    AddLocalVariablesToList(frame, ip, listToAdd, s);
                }
            }
        }
        DbgEngineStackFrame CreateEngineStackFrame(CorFrame corFrame)
        {
            engine.DebuggerThread.VerifyAccess();
            if (corFrame.IsILFrame)
            {
                var func = corFrame.Function;
                if (func is null)
                {
                    return(CreateErrorStackFrame());
                }
                var module = engine.TryGetModule(func.Module);
                if (module is null)
                {
                    return(CreateErrorStackFrame());
                }
                return(new ILDbgEngineStackFrame(engine, module, corFrame, dnThread, func, dbgDotNetNativeCodeLocationFactory, dbgDotNetCodeLocationFactory));
            }

            if (corFrame.IsInternalFrame)
            {
                return(engine.ObjectFactory.CreateSpecialStackFrame(GetInternalFrameTypeName(corFrame)));
            }

            if (corFrame.IsNativeFrame)
            {
                var name = string.Format(dnSpy_Debugger_DotNet_CorDebug_Resources.StackFrame_NativeFrame, "0x" + corFrame.NativeFrameIP.ToString("X8"));
                return(engine.ObjectFactory.CreateSpecialStackFrame(name));
            }

            return(CreateErrorStackFrame());
        }
Example #10
0
        void GotStepRanges(CorFrame frame, uint offset, object tag, bool isStepInto, GetCodeRangeResult result, uint continueCounter)
        {
            engine.VerifyCorDebugThread();
            if (IsClosed)
            {
                return;
            }
            if (stepData != null)
            {
                return;
            }
            if (continueCounter != dnThread.Debugger.ContinueCounter || frame.IsNeutered)
            {
                RaiseStepComplete(thread, tag, "Internal error");
                return;
            }
            // If we failed to find the statement ranges (result.Success == false), step anyway.
            // We'll just step until the next sequence point instead of not doing anything.
            var        ranges        = result.Success ? ToStepRanges(result.StatementRanges) : new StepRange[] { new StepRange(offset, offset + 1) };
            CorStepper newCorStepper = null;
            var        dbg           = dnThread.Debugger;

            if (isStepInto)
            {
                newCorStepper = dbg.StepInto(frame, ranges, (_, e) => StepCompleted(e, newCorStepper, tag));
            }
            else
            {
                newCorStepper = dbg.StepOver(frame, ranges, (_, e) => StepCompleted(e, newCorStepper, tag));
            }
            SaveStepper(newCorStepper, tag);
        }
Example #11
0
		public static bool CanGoToDisasm(CorFrame frame) {
			if (frame == null)
				return false;
			if (!frame.IsNativeFrame)
				return false;

			return false;//TODO:
		}
Example #12
0
		public static bool GoTo(IModuleIdProvider moduleIdProvider, IDocumentTabService documentTabService, IModuleLoader moduleLoader, CorFrame frame, bool newTab) {
			if (GoToIL(moduleIdProvider, documentTabService, moduleLoader, frame, newTab))
				return true;

			//TODO: eg. native frame or internal frame

			return false;
		}
Example #13
0
		public static bool GoTo(IFileTabManager fileTabManager, IModuleLoader moduleLoader, CorFrame frame, bool newTab) {
			if (GoToIL(fileTabManager, moduleLoader, frame, newTab))
				return true;

			//TODO: eg. native frame or internal frame

			return false;
		}
Example #14
0
		public static bool GoTo(CorFrame frame, bool newTab) {
			if (GoToIL(frame, newTab))
				return true;

			//TODO: eg. native frame or internal frame

			return false;
		}
Example #15
0
 DbgModule TryGetModule(CorFrame frame, CorThread thread)
 {
     if (frame == null)
     {
         frame = thread?.ActiveFrame ?? thread?.AllFrames.FirstOrDefault();
     }
     return(TryGetModule(frame?.Function?.Module));
 }
Example #16
0
        public static bool GoToDisasm(CorFrame frame)
        {
            if (!CanGoToDisasm(frame))
            {
                return(false);
            }

            return(false);           //TODO:
        }
Example #17
0
 void CheckTimestamp( )
 {
     if (evalTimestamp != CorDebuggerSession.EvaluationTimestamp)
     {
         thread  = null;
         frame   = null;
         corEval = null;
     }
 }
Example #18
0
 public override void CopyFrom(EvaluationContext ctx)
 {
     base.CopyFrom(ctx);
     frame         = ((CorEvaluationContext)ctx).frame;
     frameIndex    = ((CorEvaluationContext)ctx).frameIndex;
     evalTimestamp = ((CorEvaluationContext)ctx).evalTimestamp;
     Thread        = ((CorEvaluationContext)ctx).Thread;
     Session       = ((CorEvaluationContext)ctx).Session;
 }
Example #19
0
		public static bool GoToIL(IFileTabManager fileTabManager, IModuleLoader moduleLoader, CorFrame frame, bool newTab) {
			if (!CanGoToIL(frame))
				return false;

			var func = frame.Function;
			if (func == null)
				return false;

			return DebugUtils.GoToIL(fileTabManager, moduleLoader.LoadModule(func.Module, true), frame.Token, frame.GetILOffset(moduleLoader), newTab);
		}
Example #20
0
		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;
		}
Example #21
0
 public ExceptionThrownStopReason(CorAppDomain appDomain, CorThread thread, CorFrame frame,
                                  int offset, CorDebugExceptionCallbackType eventType, int flags)
 {
     m_appDomain = appDomain;
     m_thread    = thread;
     m_frame     = frame;
     m_offset    = offset;
     m_eventtype = eventType;
     m_flags     = flags;
 }
Example #22
0
		public static bool GoToIL(CorFrame frame, bool newTab) {
			if (!CanGoToIL(frame))
				return false;

			var func = frame.Function;
			if (func == null)
				return false;

			return DebugUtils.GoToIL(ModuleLoader.Instance.LoadModule(func.Module, true), frame.Token, frame.GetILOffset(), newTab);
		}
Example #23
0
		public static bool GoToIL(IModuleIdProvider moduleIdProvider, IDocumentTabService documentTabService, IModuleLoader moduleLoader, CorFrame frame, bool newTab) {
			if (!CanGoToIL(frame))
				return false;

			var func = frame.Function;
			if (func == null)
				return false;

			return DebugUtils.GoToIL(moduleIdProvider, documentTabService, moduleLoader.LoadModule(func.Module, canLoadDynFile: true, isAutoLoaded: true), frame.Token, frame.GetILOffset(moduleLoader), newTab);
		}
Example #24
0
		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;
		}
Example #25
0
        public static bool GoTo(CorFrame frame, bool newTab)
        {
            if (GoToIL(frame, newTab))
            {
                return(true);
            }

            //TODO: eg. native frame or internal frame

            return(false);
        }
 CorFrame?FindFrame(CorFrame frame)
 {
     foreach (var f in dnThread.AllFrames)
     {
         if (f.StackStart == frame.StackStart && f.StackEnd == frame.StackEnd)
         {
             return(f);
         }
     }
     return(null);
 }
Example #27
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="frame">The CorFrame frame object</param>
        /// <param name="importer">The meta data importer for the module this frame is contained within</param>
        internal FrameInfo(CorFrame frame, CorMetadataImport importer)
        {
            if (frame == null)
            {
                throw new ArgumentNullException("frame");
            }

            if (importer == null)
            {
                throw new ArgumentNullException("importer");
            }

            thisFrame          = frame;
            metaImporter       = importer;
            functionShortName  = "";
            functionFullName   = "";
            moduleShortName    = "";
            moduleFullName     = "";
            functionFileName   = null;
            functionLineNumber = -1;            //-1 is set by deafult which means no line number

            SourcePosition functionPos = null;  //position in this function where we are

            //make binder and reader for the metadata

            if (thisFrame.FrameType == CorFrameType.InternalFrame)
            {
                functionFullName = functionShortName = InternalFrameToString();
            }
            else
            {
                try
                {
                    functionPos = GetMetaDataInfo(importer);
                }
                catch (Exception e)
                {
                    // We are not able to find information about the source code
                    functionFileName = "unknown method: " + e.Message;
                }
            }

            if (functionPos != null)
            {
                functionLineNumber = functionPos.Line;
                functionFileName   = Path.GetFileName(functionPos.Path);
            }
            else
            {
                functionLineNumber = -1;                //no line number available
                functionFileName   = functionFileName ?? "source unavailable";
            }
        }
Example #28
0
        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;
        }
Example #29
0
        public static bool CanGoToDisasm(CorFrame frame)
        {
            if (frame == null)
            {
                return(false);
            }
            if (!frame.IsNativeFrame)
            {
                return(false);
            }

            return(false);           //TODO:
        }
Example #30
0
        /// <summary>
        /// Returns the caller of the frame.
        /// </summary>
        /// <param name="frame">frame to return the caller of</param>
        /// <returns>the caller of the frame or null if the frame is the last frame in the chain</returns>
        protected virtual MDbgFrame GetFrameCaller(MDbgFrame frame)
        {
            Debug.Assert(frame != null);

            CorFrame f = frame.CorFrame.Caller;

            if (f == null)
            {
                return(null);
            }

            return(new MDbgILFrame(Thread, f));
        }
Example #31
0
		public static bool CanGoToIL(CorFrame frame) {
			if (frame == null)
				return false;
			if (!frame.IsILFrame)
				return false;
			var ip = frame.ILFrameIP;
			if (!ip.IsExact && !ip.IsApproximate && !ip.IsProlog && !ip.IsEpilog)
				return false;
			if (frame.Token == 0)
				return false;

			return true;
		}
Example #32
0
        /// <summary>
        /// Creates a new V2 StackWalker.
        /// </summary>
        /// <param name="thread">a thread object associated with the stackwalker</param>
        /// <returns>object implementing MDbgStackWalker interface</returns>
        public IEnumerable <MDbgFrame> EnumerateFrames(MDbgThread thread)
        {
            // To do stackwalking using V2 ICorDebug, we enumerate through the chains,
            // and then enumerate each frame in every chain

            CorChain chain = null;

            try
            {
                chain = thread.CorThread.ActiveChain;
            }
            catch (System.Runtime.InteropServices.COMException ce)
            {
                // Sometimes we cannot get the callstack.  For example, the thread
                // may not be scheduled yet (CORDBG_E_THREAD_NOT_SCHEDULED),
                // or the debuggee may be corrupt (CORDBG_E_BAD_THREAD_STATE).
                // In either case, we'll ignore the problem and return an empty callstack.
                Debug.Assert(ce.ErrorCode == (int)HResult.CORDBG_E_BAD_THREAD_STATE ||
                             ce.ErrorCode == (int)HResult.CORDBG_E_THREAD_NOT_SCHEDULED);
            }

            while (chain != null)
            {
                if (chain.IsManaged)
                {
                    // Enumerate managed frames
                    // A chain may have 0 managed frames.
                    CorFrame f = chain.ActiveFrame;
                    while (f != null)
                    {
                        MDbgFrame frame = new MDbgILFrame(thread, f);
                        f = f.Caller;
                        yield return(frame);
                    }
                }
                else
                {
                    // ICorDebug doesn't unwind unmanaged frames. Need to let a native-debug component handle that.
                    foreach (MDbgFrame frame in UnwindNativeFrames(thread, chain))
                    {
                        yield return(frame);
                    }
                }

                // Move to next chain
                chain = chain.Caller;
            }
        }
Example #33
0
        public static bool GoToIL(CorFrame frame, bool newTab)
        {
            if (!CanGoToIL(frame))
            {
                return(false);
            }

            var func = frame.Function;

            if (func == null)
            {
                return(false);
            }

            return(DebugUtils.GoToIL(ModuleLoader.Instance.LoadModule(func.Module, true), frame.Token, frame.GetILOffset(), newTab));
        }
Example #34
0
        void GetStepRanges(CorFrame frame, object tag, bool isStepInto)
        {
            engine.VerifyCorDebugThread();
            var module = engine.TryGetModule(frame.Function?.Module);
            var offset = GetILOffset(frame);

            if (module == null || offset == null)
            {
                SaveStepper(null, tag);
            }
            else
            {
                uint continueCounter = dnThread.Debugger.ContinueCounter;
                dbgDotNetCodeRangeService.GetCodeRanges(module, frame.Token, offset.Value, result => engine.CorDebugThread(() => GotStepRanges(frame, tag, isStepInto, result, continueCounter)));
            }
        }
Example #35
0
        public static bool GoToIL(CorFrame frame, bool newTab)
        {
            if (!CanGoToIL(frame))
            {
                return(false);
            }

            var serAsm = frame.GetSerializedDnModuleWithAssembly();

            if (serAsm == null)
            {
                return(false);
            }

            return(DebugUtils.GoToIL(serAsm.Value, frame.Token, frame.GetILOffset(), newTab));
        }
Example #36
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="frame">The CorFrame frame object</param>
        /// <param name="importer">The meta data importer for the module this frame is contained within</param>
        internal FrameInfo(CorFrame frame, CorMetadataImport importer)
        {
            if (frame == null)
            {
                throw new ArgumentNullException("frame");
            }

            if (importer == null)
            {
                throw new ArgumentNullException("importer");
            }

            thisFrame          = frame;
            metaImporter       = importer;
            functionShortName  = "";
            functionFullName   = "";
            moduleShortName    = "";
            moduleFullName     = "";
            functionFileName   = "";
            functionLineNumber = -1;            //-1 is set by deafult which means no line number

            SourcePosition functionPos = null;  //position in this function where we are

            //make binder and reader for the metadata

            if (thisFrame.FrameType == CorFrameType.InternalFrame)
            {
                functionFullName = functionShortName = InternalFrameToString();
            }
            else
            {
                functionPos = GetMetaDataInfo(importer);
            }

            if (functionPos != null)
            {
                functionLineNumber = functionPos.Line;
                functionFileName   = Path.GetFileName(functionPos.Path);
            }
            else
            {
                ResourceManager stackStrings = new ResourceManager(typeof(Resources));
                functionLineNumber = -1;                //no line number available
                functionFileName   = stackStrings.GetString("sourceUnavailable");
            }
        }
Example #37
0
		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;
			}
		}
Example #38
0
        static uint?GetILOffset(CorFrame frame)
        {
            var ip = frame.ILFrameIP;

            if (ip.IsExact || ip.IsApproximate)
            {
                return(ip.Offset);
            }
            if (ip.IsProlog)
            {
                return(DbgDotNetCodeRangeService.PROLOG);
            }
            if (ip.IsEpilog)
            {
                return(DbgDotNetCodeRangeService.EPILOG);
            }
            return(null);
        }
        static string GetInternalFrameTypeName(CorFrame corFrame)
        {
            Debug.Assert(corFrame.IsInternalFrame);
            switch (corFrame.InternalFrameType)
            {
            case CorDebugInternalFrameType.STUBFRAME_M2U:
                return(dnSpy_Debugger_DotNet_CorDebug_Resources.StackFrame_ManagedToNativeTransition);

            case CorDebugInternalFrameType.STUBFRAME_U2M:
                return(dnSpy_Debugger_DotNet_CorDebug_Resources.StackFrame_NativeToManagedTransition);

            case CorDebugInternalFrameType.STUBFRAME_APPDOMAIN_TRANSITION:
                return(dnSpy_Debugger_DotNet_CorDebug_Resources.StackFrame_AppdomainTransition);

            case CorDebugInternalFrameType.STUBFRAME_LIGHTWEIGHT_FUNCTION:
                return(dnSpy_Debugger_DotNet_CorDebug_Resources.StackFrame_LightweightFunction);

            case CorDebugInternalFrameType.STUBFRAME_FUNC_EVAL:
                return(dnSpy_Debugger_DotNet_CorDebug_Resources.StackFrame_FunctionEvaluation);

            case CorDebugInternalFrameType.STUBFRAME_INTERNALCALL:
                return(dnSpy_Debugger_DotNet_CorDebug_Resources.StackFrame_InternalCall);

            case CorDebugInternalFrameType.STUBFRAME_CLASS_INIT:
                return(dnSpy_Debugger_DotNet_CorDebug_Resources.StackFrame_ClassInit);

            case CorDebugInternalFrameType.STUBFRAME_EXCEPTION:
                return(dnSpy_Debugger_DotNet_CorDebug_Resources.StackFrame_Exception);

            case CorDebugInternalFrameType.STUBFRAME_SECURITY:
                return(dnSpy_Debugger_DotNet_CorDebug_Resources.StackFrame_Security);

            case CorDebugInternalFrameType.STUBFRAME_JIT_COMPILATION:
                return(dnSpy_Debugger_DotNet_CorDebug_Resources.StackFrame_JITCompilation);

            case CorDebugInternalFrameType.STUBFRAME_NONE:
                Debug.Fail("Shouldn't be here");
                goto default;

            default:
                return(string.Format(dnSpy_Debugger_DotNet_CorDebug_Resources.StackFrame_InternalFrame, "0x" + ((int)corFrame.InternalFrameType).ToString("X8")));
            }
        }
Example #40
0
        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;
            }
        }
Example #41
0
        public void SetFrame(CorFrame frame, DnProcess process)
        {
            this.frame   = frame;
            this.process = process;

            if (cachedOutput == null || !HasPropertyChangedHandlers)
            {
                cachedOutput = null;
                OnPropertyChanged("NameObject");
            }
            else
            {
                var newCachedOutput = CachedOutput.Create(frame, Context.TypePrinterFlags);
                if (newCachedOutput.Equals(cachedOutput.Value))
                {
                    return;
                }

                cachedOutput = newCachedOutput;
                OnPropertyChanged("NameObject");
            }
        }
Example #42
0
 /// <summary>
 /// Step into
 /// </summary>
 /// <param name="frame">Frame</param>
 /// <param name="action">Delegate to call when completed or null</param>
 /// <returns></returns>
 public bool StepInto(CorFrame frame, Action<DnDebugger, StepCompleteDebugCallbackEventArgs> action = null)
 {
     DebugVerifyThread();
     return StepIntoOver(frame, true, action);
 }
Example #43
0
        public bool RunTo(CorFrame frame)
        {
            DebugVerifyThread();
            var callee = GetRunToCallee(frame);
            if (callee == null)
                return false;

            return StepOutInternal(callee, null);
        }
Example #44
0
 /// <summary>
 /// true if we can step into, step out or step over
 /// </summary>
 /// <param name="frame">Frame</param>
 public bool CanStep(CorFrame frame)
 {
     DebugVerifyThread();
     return ProcessState == DebuggerProcessState.Stopped && frame != null;
 }
Example #45
0
 public bool CanRunTo(CorFrame frame)
 {
     DebugVerifyThread();
     return GetRunToCallee(frame) != null;
 }
Example #46
0
        bool StepOutInternal(CorFrame frame, Action<DnDebugger, StepCompleteDebugCallbackEventArgs> action)
        {
            if (!CanStep(frame))
                return false;

            var stepper = CreateStepper(frame);
            if (stepper == null)
                return false;
            if (!stepper.StepOut())
                return false;

            stepInfos.Add(stepper, new StepInfo(action));
            Continue();
            return true;
        }
Example #47
0
 public bool CanRunTo(CorFrame frame)
 {
     return ProcessState == DebuggerProcessState.Stopped && Debugger.CanRunTo(frame);
 }
Example #48
0
		public CallStackFrameVM(ICallStackFrameContext context, int index, CorFrame frame, DnProcess process) {
			this.context = context;
			this.index = index;
			this.frame = frame;
			this.process = process;
		}
Example #49
0
        CorStepper CreateStepper(CorFrame frame)
        {
            if (frame == null)
                return null;

            var stepper = frame.CreateStepper();
            if (stepper == null)
                return null;
            if (!stepper.SetInterceptMask(debugOptions.StepperInterceptMask))
                return null;
            if (!stepper.SetUnmappedStopMask(debugOptions.StepperUnmappedStopMask))
                return null;
            if (!stepper.SetJMC(debugOptions.StepperJMC))
                return null;

            return stepper;
        }
Example #50
0
		public static bool GoToDisasm(CorFrame frame) {
			if (!CanGoToDisasm(frame))
				return false;

			return false;//TODO:
		}
Example #51
0
		public CallStackFrameVM(CallStackVM owner, int index, CorFrame frame) {
			this.owner = owner;
			this.index = index;
			this.frame = frame;
		}
Example #52
0
        static MethodKey? CreateMethodKey(DnDebugger debugger, CorFrame frame)
        {
            var sma = frame.GetSerializedDnModuleWithAssembly();
            if (sma == null)
                return null;

            return MethodKey.Create(frame.Token, sma.Value.Module);
        }
Example #53
0
        internal void UpdateCurrentLocation(CorFrame frame)
        {
            var newLoc = GetCodeLocation(frame);

            if (currentLocation == null || newLoc == null) {
                currentLocation = newLoc;
                UpdateCurrentMethod();
                return;
            }
            if (!CodeLocation.SameMethod(currentLocation.Value, newLoc.Value)) {
                currentLocation = newLoc;
                UpdateCurrentMethod();
                return;
            }

            currentLocation = newLoc;
        }
Example #54
0
        public void RunTo(CorFrame frame)
        {
            if (!CanRunTo(frame))
                return;

            Debugger.RunTo(frame);
        }
Example #55
0
 /// <summary>
 /// Step out of current method in the selected frame
 /// </summary>
 /// <param name="frame">Frame</param>
 /// <param name="action">Delegate to call when completed or null</param>
 /// <returns></returns>
 public bool StepOut(CorFrame frame, Action<DnDebugger, StepCompleteDebugCallbackEventArgs> action = null)
 {
     DebugVerifyThread();
     return StepOutInternal(frame, action);
 }
Example #56
0
        CorFrame GetRunToCallee(CorFrame frame)
        {
            if (!CanStep(frame))
                return null;
            if (frame == null)
                return null;
            if (!frame.IsILFrame)
                return null;
            var callee = frame.Callee;
            if (callee == null)
                return null;
            if (!callee.IsILFrame)
                return null;

            return callee;
        }
Example #57
0
 /// <summary>
 /// Step over
 /// </summary>
 /// <param name="frame">Frame</param>
 /// <param name="ranges">Ranges to step over</param>
 /// <param name="action">Delegate to call when completed or null</param>
 /// <returns></returns>
 public bool StepOver(CorFrame frame, StepRange[] ranges, Action<DnDebugger, StepCompleteDebugCallbackEventArgs> action = null)
 {
     DebugVerifyThread();
     return StepIntoOver(frame, ranges, false, action);
 }
Example #58
0
        bool StepIntoOver(CorFrame frame, StepRange[] ranges, bool stepInto, Action<DnDebugger, StepCompleteDebugCallbackEventArgs> action = null)
        {
            if (ranges == null)
                return StepIntoOver(frame, stepInto, action);
            if (!CanStep(frame))
                return false;

            var stepper = CreateStepper(frame);
            if (stepper == null)
                return false;
            if (!stepper.StepRange(stepInto, ranges))
                return false;

            stepInfos.Add(stepper, new StepInfo(action));
            Continue();
            return true;
        }
Example #59
0
        CodeLocation? GetCodeLocation(CorFrame frame)
        {
            if (ProcessState != DebuggerProcessState.Stopped)
                return null;
            if (frame == null)
                return null;
            var sma = frame.GetSerializedDnModuleWithAssembly();
            if (sma == null)
                return null;
            uint token = frame.Token;
            if (token == 0)
                return null;

            return new CodeLocation(sma.Value, token, frame.GetILOffset(), frame.ILFrameIP.Mapping);
        }
Example #60
0
        StepRange[] GetStepRanges(DnDebugger debugger, CorFrame frame, bool isStepInto)
        {
            if (frame == null)
                return null;
            if (!frame.IsILFrame)
                return null;
            if (frame.ILFrameIP.IsUnmappedAddress)
                return null;

            var key = CreateMethodKey(debugger, frame);
            if (key == null)
                return null;

            MemberMapping mapping;
            var textView = MainWindow.Instance.SafeActiveTextView;
            var cm = textView.CodeMappings;
            if (cm == null || !cm.TryGetValue(key.Value, out mapping)) {
                // User has decompiled some other code or switched to another tab
                UpdateCurrentMethod();
                JumpToCurrentStatement(textView);

                // It could be cached and immediately available. Check again
                cm = textView.CodeMappings;
                if (cm == null || !cm.TryGetValue(key.Value, out mapping))
                    return null;
            }

            bool isMatch;
            var scm = mapping.GetInstructionByOffset(frame.GetILOffset(), out isMatch);
            uint[] ilRanges;
            if (scm == null)
                ilRanges = mapping.ToArray(null, false);
            else
                ilRanges = scm.ToArray(isMatch);

            if (ilRanges.Length == 0)
                return null;
            return CreateStepRanges(ilRanges);
        }