Ejemplo n.º 1
0
        public CorValue GetStaticFieldValue(int fieldToken, CorFrame managedFrame)
        {
            ICorDebugValue pValue;

            m_class.GetStaticFieldValue((uint)fieldToken, (managedFrame == null) ? null : managedFrame.m_frame, out pValue);
            return(pValue == null ? null : new CorValue(pValue));
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
		void CheckTimestamp ( )
		{
			if (evalTimestamp != CorDebuggerSession.EvaluationTimestamp) {
				thread = null;
				frame = null;
				corEval = null;
			}
		}
Ejemplo n.º 4
0
		internal static StackFrame CreateFrame (CorDebuggerSession session, CorFrame frame)
		{
			uint address = 0;
			string file = "";
			int line = 0;
			string method = "";
			string lang = "";
			string module = "";
			string type = "";

			if (frame.FrameType == CorFrameType.ILFrame) {
				if (frame.Function != null) {
					module = frame.Function.Module.Name;
					CorMetadataImport importer = new CorMetadataImport (frame.Function.Module);
					MethodInfo mi = importer.GetMethodInfo (frame.Function.Token);
					method = mi.DeclaringType.FullName + "." + mi.Name;
					type = mi.DeclaringType.FullName;
					ISymbolReader reader = session.GetReaderForModule (frame.Function.Module.Name);
					if (reader != null) {
						ISymbolMethod met = reader.GetMethod (new SymbolToken (frame.Function.Token));
						if (met != null) {
							uint offset;
							CorDebugMappingResult mappingResult;
							frame.GetIP (out offset, out mappingResult);
							SequencePoint prevSp = null;
							foreach (SequencePoint sp in met.GetSequencePoints ()) {
								if (sp.Offset > offset)
									break;
								prevSp = sp;
							}
							if (prevSp != null) {
								line = prevSp.Line;
								file = prevSp.Document.URL;
							}
						}
					}
				}
				lang = "Managed";
			}
			else if (frame.FrameType == CorFrameType.NativeFrame) {
				frame.GetNativeIP (out address);
				method = "<Unknown>";
				lang = "Native";
			}
			else if (frame.FrameType == CorFrameType.InternalFrame) {
				switch (frame.InternalFrameType) {
					case CorDebugInternalFrameType.STUBFRAME_M2U: method = "[Managed to Native Transition]"; break;
					case CorDebugInternalFrameType.STUBFRAME_U2M: method = "[Native to Managed Transition]"; break;
					case CorDebugInternalFrameType.STUBFRAME_LIGHTWEIGHT_FUNCTION: method = "[Lightweight Method Call]"; break;
					case CorDebugInternalFrameType.STUBFRAME_APPDOMAIN_TRANSITION: method = "[Application Domain Transition]"; break;
					case CorDebugInternalFrameType.STUBFRAME_FUNC_EVAL: method = "[Function Evaluation]"; break;
				}
			}
			if (method == null)
				method = "<Unknown>";
			var loc = new SourceLocation (method, file, line);
			return new StackFrame ((long) address, loc, lang);
		}
Ejemplo n.º 5
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;
		}
Ejemplo n.º 6
0
 private COR_DEBUG_STEP_RANGE[] getStepRanges(CorFrame frame, ISymbolReader reader, uint offset)
 {
     var method = reader.GetMethod(new SymbolToken(frame.FunctionToken));
     foreach (var sp in new SequencePointFactory().Generate(method))
     {
         if (sp.Offset > offset)
             return createStepRange(offset, sp.Offset);
     }
     return null;
 }
        public bool IsCloserToLeaf(CorFrame frameToCompare)
        {
            ICorDebugInternalFrame2 iFrame2 = m_frame as ICorDebugInternalFrame2;

            if (iFrame2 == null)
            {
                throw new ArgumentException("The this object is not an ICorDebugInternalFrame");
            }

            int isCloser = 0;

            iFrame2.IsCloserToLeaf(frameToCompare.m_frame, out isCloser);
            return(isCloser == 0 ? false : true);
        }
Ejemplo n.º 8
0
        //
        // IEnumerator interface
        //
        public override bool MoveNext()
        {
            // This variable is used to store the child frame we are currently skipping for.  It's also
            // used as a flag to indicate whether this method should return or continue to the next frame.
            CorFrame childFrame = null;

            bool bMoreToWalk = false;

            while (true)
            {
                // Check to see if the frame we have just given back is a child frame.
                if (m_init)
                {
                    CorFrame prevFrame = this.Current;
                    if ((prevFrame != null) && prevFrame.IsChild)
                    {
                        childFrame = prevFrame;
                    }
                }

                bMoreToWalk = MoveNextWorker();
                if (!bMoreToWalk)
                {
                    // Unless there is a catastrophic failure, we should always find the parent frame for any
                    // child frame.
                    Debug.Assert(childFrame == null);
                    break;
                }

                if (childFrame != null)
                {
                    // We are currently skipping frames due to a child frame.

                    // Check whether the current frame is the parent frame.
                    CorFrame currentFrame = this.Current;
                    if ((currentFrame != null) && childFrame.IsMatchingParentFrame(currentFrame))
                    {
                        // We have reached the parent frame.  We should skip the parent frame as well, so clear
                        // childFrame and unwind to the caller of the parent frame.  We will break out of the
                        // loop on the next iteration.
                        childFrame = null;
                    }
                    continue;
                }
                break;
            }
            return(bMoreToWalk);
        }
Ejemplo n.º 9
0
        //
        // IEnumerator interface
        //
        public bool MoveNext()
        {
            ICorDebugFrame[] a = new ICorDebugFrame[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_frame = new CorFrame(a[0]);
            }
            else
            {
                m_frame = null;
            }
            return(m_frame != null);
        }
Ejemplo n.º 10
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");
            }
        }
Ejemplo n.º 11
0
        public void SetThreadContext(CorDebugSetContextFlag flag, int contextSize, IntPtr contextBuffer)
        {
            m_sw.SetContext(flag, (uint)contextSize, contextBuffer);

            // update the current frame
            ICorDebugFrame frame;

            m_sw.GetFrame(out frame);

            if (frame == null)
            {
                m_frame = null;
            }
            else
            {
                m_frame = new CorFrame(frame);
            }
        }
Ejemplo n.º 12
0
        public CorFrame[] GetActiveInternalFrames()
        {
            ICorDebugThread3 th3 = (ICorDebugThread3)m_th;

            UInt32 cInternalFrames = 0;

            th3.GetActiveInternalFrames(0, out cInternalFrames, null);

            ICorDebugInternalFrame2[] ppInternalFrames = new ICorDebugInternalFrame2[cInternalFrames];
            th3.GetActiveInternalFrames(cInternalFrames, out cInternalFrames, ppInternalFrames);

            CorFrame[] corFrames = new CorFrame[cInternalFrames];
            for (int i = 0; i < cInternalFrames; i++)
            {
                corFrames[i] = new CorFrame(ppInternalFrames[i] as ICorDebugFrame);
            }
            return(corFrames);
        }
Ejemplo n.º 13
0
        private static bool IsV3InternalFrameType(CorFrame internalFrame)
        {
            // CorStackWalkEx wants to expose V2 behaviour.  The following frame types are new in V3.
            // This function checks whether the specified internal frame is a V3 frame type and returns
            // true if it is.  CorStackWalkEx uses this function to decide whether it should expose
            // an internal frame.
            CorDebugInternalFrameType type = internalFrame.InternalFrameType;

            if ((type == CorDebugInternalFrameType.STUBFRAME_INTERNALCALL) ||
                (type == CorDebugInternalFrameType.STUBFRAME_CLASS_INIT) ||
                (type == CorDebugInternalFrameType.STUBFRAME_EXCEPTION) ||
                (type == CorDebugInternalFrameType.STUBFRAME_SECURITY) ||
                (type == CorDebugInternalFrameType.STUBFRAME_JIT_COMPILATION))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 14
0
        public bool IsMatchingParentFrame(CorFrame parentFrame)
        {
            if (!this.IsChild)
            {
                return(false);
            }
            ICorDebugNativeFrame2 nativeFrame2 = m_frame as ICorDebugNativeFrame2;

            Debug.Assert(nativeFrame2 != null);

            ICorDebugNativeFrame2 nativeParentFrame2 = parentFrame.m_frame as ICorDebugNativeFrame2;

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

            int isParent = 0;

            nativeFrame2.IsMatchingParentFrame(nativeParentFrame2, out isParent);
            return(isParent == 0 ? false : true);
        }
Ejemplo n.º 15
0
        //
        // IEnumerator interface
        //
        public virtual bool MoveNext()
        {
            int hr;

            if (m_init)
            {
                hr = m_sw.Next();
            }
            else
            {
                m_init = true;
                hr     = (int)HResult.S_OK;
            }

            if (HRUtils.IsFailingHR(hr))
            {
                Marshal.ThrowExceptionForHR(hr);
            }
            if (hr == (int)HResult.S_OK)
            {
                ICorDebugFrame frame;
                m_sw.GetFrame(out frame);

                if (frame == null)
                {
                    m_frame = null;
                    return(true);
                }

                m_frame = new CorFrame(frame);
                return(true);
            }
            else
            {
                Debug.Assert(hr == (int)HResult.CORDBG_S_AT_END_OF_STACK);
                return(false);
            }
        }
        //
        // IEnumerator interface
        //
        public virtual bool MoveNext()
        {
            int hr;
            if (m_init)
            {
                hr = m_sw.Next();
            }
            else
            {
                m_init = true;
                hr = (int)HResult.S_OK;
            }

            if (HRUtils.IsFailingHR(hr))
            {
                Marshal.ThrowExceptionForHR(hr);
            }
            if (hr == (int)HResult.S_OK)
            {
                ICorDebugFrame frame;
                m_sw.GetFrame(out frame);

                if (frame == null)
                {
                    m_frame = null;
                    return true;
                }

                m_frame = new CorFrame(frame);
                return true;
            }
            else
            {
                Debug.Assert(hr == (int)HResult.CORDBG_S_AT_END_OF_STACK);
                return false;
            }
        }
Ejemplo n.º 17
0
        public bool IsCloserToLeaf(CorFrame frameToCompare)
        {
            ICorDebugInternalFrame2 iFrame2 = m_frame as ICorDebugInternalFrame2;
            if (iFrame2 == null)
            {
                throw new ArgumentException("The this object is not an ICorDebugInternalFrame");
            }

            int isCloser = 0;
            iFrame2.IsCloserToLeaf(frameToCompare.m_frame, out isCloser);
            return (isCloser == 0 ? false : true);
        }
Ejemplo n.º 18
0
        public CorFrame[] GetActiveInternalFrames()
        {
            ICorDebugThread3 th3 = (ICorDebugThread3)m_th;

            UInt32 cInternalFrames = 0;
            th3.GetActiveInternalFrames(0, out cInternalFrames, null);

            ICorDebugInternalFrame2[] ppInternalFrames = new ICorDebugInternalFrame2[cInternalFrames];
            th3.GetActiveInternalFrames(cInternalFrames, out cInternalFrames, ppInternalFrames);

            CorFrame[] corFrames = new CorFrame[cInternalFrames];
            for (int i = 0; i < cInternalFrames; i++)
            {
                corFrames[i] = new CorFrame(ppInternalFrames[i] as ICorDebugFrame);
            }
            return corFrames;
        }
Ejemplo n.º 19
0
 /** 
  * Intercept the current exception.
  */
 public void InterceptCurrentException(CorFrame frame)
 {
     ICorDebugThread2 m_th2 = (ICorDebugThread2)m_th;
     m_th2.InterceptCurrentException(frame.m_frame);
 }
Ejemplo n.º 20
0
 //
 // IEnumerator interface
 //
 public bool MoveNext()
 {
     ICorDebugFrame[] a = new ICorDebugFrame[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_frame = new CorFrame(a[0]);
     else
         m_frame = null;
     return m_frame != null;
 }
Ejemplo n.º 21
0
 public void Reset()
 {
     m_enum.Reset ();
     m_frame = null;
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Gets the MDbgSourcePosition from a given CorFrame.
        /// </summary>
        /// <param name="frame">The CorFrame.</param>
        /// <returns>The MDbgSourcePosition of the given frame.</returns>
        public MDbgSourcePosition GetSourcePositionFromFrame(CorFrame frame)
        {
            // EnsureIsUpToDate is called from GetSourcePositionFromIP

            // we only support this, when the frame is our function
            Debug.Assert(frame.FunctionToken == m_function.Token);

            uint ip;
            CorDebugMappingResult mappingResult;
            frame.GetIP(out ip, out mappingResult);

            // MAPPING_APPROXIMATE, MAPPING_EXACT, MAPPING_PROLOG, or MAPPING_EPILOG are all ok and we should show sources.
            // But these two indicate that something went wrong and nothing is available.
            if (mappingResult == CorDebugMappingResult.MAPPING_NO_INFO ||
               mappingResult == CorDebugMappingResult.MAPPING_UNMAPPED_ADDRESS)
                return null;

            return GetSourcePositionFromIP((int)ip);
        }
Ejemplo n.º 23
0
 public CorValue GetStaticFieldValue(int fieldToken, CorFrame managedFrame)
 {
     ICorDebugValue pValue;
     m_class.GetStaticFieldValue((uint)fieldToken, (managedFrame==null)?null:managedFrame.m_frame, out pValue);
     return pValue==null?null:new CorValue(pValue);
 }
 private static bool IsV3InternalFrameType(CorFrame internalFrame)
 {
     // CorStackWalkEx wants to expose V2 behaviour.  The following frame types are new in V3.
     // This function checks whether the specified internal frame is a V3 frame type and returns
     // true if it is.  CorStackWalkEx uses this function to decide whether it should expose
     // an internal frame.
     CorDebugInternalFrameType type = internalFrame.InternalFrameType;
     if ((type == CorDebugInternalFrameType.STUBFRAME_INTERNALCALL) ||
         (type == CorDebugInternalFrameType.STUBFRAME_CLASS_INIT) ||
         (type == CorDebugInternalFrameType.STUBFRAME_EXCEPTION) ||
         (type == CorDebugInternalFrameType.STUBFRAME_SECURITY) ||
         (type == CorDebugInternalFrameType.STUBFRAME_JIT_COMPILATION))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
        // This method handles internal frames but no child frames.
        private bool MoveNextWorker()
        {
            if (m_bEndOfStackFrame)
            {
                return false;
            }

            bool fIsLeafFrame = false;
            bool fIsFuncEvalFrame = false;

            int hr;
            if (m_init)
            {
                // this the 2nd or more call to MoveNext() and MoveNextWorker()

                if ((m_frame != null) && (m_frame.FrameType == CorFrameType.InternalFrame))
                {
                    // We have just handed out an internal frame, so we need to start looking at the next
                    // internal frame AND we don't call m_sw.Next() to preserve the previous managed frame
                    if (m_internalFrameIndex < m_internalFrames.Length)
                    {
                        m_internalFrameIndex++;
                    }

                    fIsFuncEvalFrame = (m_frame.InternalFrameType == CorDebugInternalFrameType.STUBFRAME_FUNC_EVAL);
                    
                    hr = (int)HResult.S_OK;
                }
                else
                {
                    // We just handed out a managed or native frame.
                    // In any case, use the managed unwinder to unwind.
                    hr = m_sw.Next();

                    // Check for end-of-stack condition.
                    if (hr == (int)HResult.CORDBG_S_AT_END_OF_STACK)
                    {
                        m_bEndOfStackFrame = true;
                    }
                }
            }
            else
            {
                // this is the initial call to MoveNext() and MoveNextWorker() that validates the enumeration
                // after we return from MoveNext(), .Current will point to the leaf-most frame
                m_init = true;
                fIsLeafFrame = true;
                hr = (int)HResult.S_OK;
            }

            // Check for errors.
            if (HRUtils.IsFailingHR(hr))
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            if (!m_bEndOfStackFrame)
            {
                // Now we need to do a comparison between the current stack frame and the internal frame (if any)
                // to figure out which one to give back first.
                ICorDebugFrame frame;
                m_sw.GetFrame(out frame);

                if (frame == null)
                {
                    // this represents native frame(s) to managed code, we return true because there may be more
                    // managed frames beneath
                    m_frame = null;
                    return true;
                }

                // we compare the current managed frame with the internal frame
                CorFrame currentFrame = new CorFrame(frame);
                for (; m_internalFrameIndex < m_internalFrames.Length; m_internalFrameIndex++)
                {
                    CorFrame internalFrame = m_internalFrames[m_internalFrameIndex];

                    // Check for internal frame types which are not exposed in V2.
                    if (IsV3InternalFrameType(internalFrame))
                    {
                        continue;
                    }
                    if (internalFrame.IsCloserToLeaf(currentFrame))
                    {
                        currentFrame = internalFrame;
                    }
                    else if (internalFrame.InternalFrameType == CorDebugInternalFrameType.STUBFRAME_M2U)
                    {
                        // we need to look at the caller stack frame's SP

                        INativeContext ctx = this.GetContext();
                        CorStackWalk tStack = m_th.CreateStackWalk(CorStackWalkType.PureV3StackWalk);
                        CorDebugSetContextFlag flag = ((fIsFuncEvalFrame || fIsLeafFrame) ? 
                            CorDebugSetContextFlag.SET_CONTEXT_FLAG_ACTIVE_FRAME :
                            CorDebugSetContextFlag.SET_CONTEXT_FLAG_UNWIND_FRAME);
                        tStack.SetContext(flag, ctx);

                        //tStack now points to the "previous" managed frame, not the managed frame we're looking at
                        //the first MoveNext call moves the temporary stackwalker to the "current" frame and the next
                        //MoveNext call moves the temporary stackwalker to the "caller" frame
                        Int64 current = 0, caller = 0;
                        if (tStack.MoveNext())
                        {
                            if (tStack.Current != null)
                            {
                                current = tStack.GetContext().StackPointer.ToInt64();
                            }
                        }
                        if (tStack.MoveNext())
                        {
                            if (tStack.Current != null)
                            {
                                caller = tStack.GetContext().StackPointer.ToInt64();
                            }
                        }
                        if (current == 0 || caller == 0)
                        {
                            //we've hit a native frame somewhere, we shouldn't be doing anything with this
                            break;
                        }
                        if (current < caller && internalFrame.IsCloserToLeaf(tStack.Current))
                        {
                            // if there is no caller frame or the current managed frame is closer to the leaf frame
                            // than the next managed frame on the stack (the caller frame), then we must be in the case
                            // where:
                            //          [IL frame without metadata]
                            //          [Internal frame, 'M --> U']
                            //          Caller frame (managed)
                            // We need to flip the internal and IL frames, so we hand back the internal frame first
                            currentFrame = internalFrame;
                        }
                    }
                    
                    break;
                }

                m_frame = currentFrame;
                return true;


               
            }
            else
            {
                // We have reached the end of the managed stack.
                // Check to see if we have any internal frames left.

                for (; m_internalFrameIndex < m_internalFrames.Length; m_internalFrameIndex++)
                {
                    CorFrame internalFrame = m_internalFrames[m_internalFrameIndex];
                    if (IsV3InternalFrameType(internalFrame))
                    {
                        continue;
                    }
                    m_frame = internalFrame;
                    return true;
                }

                return false;
            }
        }
		public static SequencePoint GetSequencePoint(CorDebuggerSession session, CorFrame frame)
		{
			ISymbolReader reader = session.GetReaderForModule (frame.Function.Module.Name);
			if (reader == null)
				return null;

			ISymbolMethod met = reader.GetMethod (new SymbolToken (frame.Function.Token));
			if (met == null)
				return null;

			int SequenceCount = met.SequencePointCount;
			if (SequenceCount <= 0)
				return null;

			CorDebugMappingResult mappingResult;
			uint ip;
			frame.GetIP (out ip, out mappingResult);
			if (mappingResult == CorDebugMappingResult.MAPPING_NO_INFO || mappingResult == CorDebugMappingResult.MAPPING_UNMAPPED_ADDRESS)
				return null;

			int[] offsets = new int[SequenceCount];
			int[] lines = new int[SequenceCount];
			int[] endLines = new int[SequenceCount];
			int[] columns = new int[SequenceCount];
			int[] endColumns = new int[SequenceCount];
			ISymbolDocument[] docs = new ISymbolDocument[SequenceCount];
			met.GetSequencePoints (offsets, docs, lines, columns, endLines, endColumns);

			if ((SequenceCount > 0) && (offsets [0] <= ip)) {
				int i;
				for (i = 0; i < SequenceCount; ++i) {
					if (offsets [i] >= ip) {
						break;
					}
				}

				if ((i == SequenceCount) || (offsets [i] != ip)) {
					--i;
				}

				if (lines [i] == SpecialSequencePoint) {
					int j = i;
					// let's try to find a sequence point that is not special somewhere earlier in the code
					// stream.
					while (j > 0) {
						--j;
						if (lines [j] != SpecialSequencePoint) {
							return new SequencePoint () {
								IsSpecial = true,
								Offset = offsets [j],
								StartLine = lines [j],
								EndLine = endLines [j],
								StartColumn = columns [j],
								EndColumn = endColumns [j],
								Document = docs [j]
							};
						}
					}
					// we didn't find any non-special seqeunce point before current one, let's try to search
					// after.
					j = i;
					while (++j < SequenceCount) {
						if (lines [j] != SpecialSequencePoint) {
							return new SequencePoint () {
								IsSpecial = true,
								Offset = offsets [j],
								StartLine = lines [j],
								EndLine = endLines [j],
								StartColumn = columns [j],
								EndColumn = endColumns [j],
								Document = docs [j]
							};
						}
					}

					// Even if sp is null at this point, it's a valid scenario to have only special sequence 
					// point in a function.  For example, we can have a compiler-generated default ctor which
					// doesn't have any source.
					return null;
				} else {
					return new SequencePoint () {
						IsSpecial = false,
						Offset = offsets [i],
						StartLine = lines [i],
						EndLine = endLines [i],
						StartColumn = columns [i],
						EndColumn = endColumns [i],
						Document = docs [i]
					};
				}
			}
			return null;
		}
Ejemplo n.º 27
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);
 }
Ejemplo n.º 28
0
 internal MDbgILFrame(MDbgThread thread, CorFrame frame)
     : base(thread)
 {
     Debug.Assert(frame != null);
     m_frame = frame;
 }
Ejemplo n.º 29
0
 /// <summary>
 /// This will return an MDbgFrame for the corresponding CorFrame.
 /// Note (the frame needs to correspond to this thread!!!!)
 /// </summary>
 /// <param name="f">The CorFrame to look up.</param>
 /// <returns>The coresponding MDbgFrame.</returns>
 public MDbgFrame LookupFrame(CorFrame f)
 {
     Debug.Assert(f != null);
     return new MDbgILFrame(this, f);
 }
Ejemplo n.º 30
0
        public bool IsMatchingParentFrame(CorFrame parentFrame)
        {
            if (!this.IsChild)
            {
                return false;
            }
            ICorDebugNativeFrame2 nativeFrame2 = m_frame as ICorDebugNativeFrame2;
            Debug.Assert(nativeFrame2 != null);

            ICorDebugNativeFrame2 nativeParentFrame2 = parentFrame.m_frame as ICorDebugNativeFrame2;
            if (nativeParentFrame2 == null)
            {
                return false;
            }

            int isParent = 0;
            nativeFrame2.IsMatchingParentFrame(nativeParentFrame2, out isParent);
            return (isParent == 0 ? false : true);
        }
Ejemplo n.º 31
0
        // This method handles internal frames but no child frames.
        private bool MoveNextWorker()
        {
            if (m_bEndOfStackFrame)
            {
                return(false);
            }

            bool fIsLeafFrame     = false;
            bool fIsFuncEvalFrame = false;

            int hr;

            if (m_init)
            {
                // this the 2nd or more call to MoveNext() and MoveNextWorker()

                if ((m_frame != null) && (m_frame.FrameType == CorFrameType.InternalFrame))
                {
                    // We have just handed out an internal frame, so we need to start looking at the next
                    // internal frame AND we don't call m_sw.Next() to preserve the previous managed frame
                    if (m_internalFrameIndex < m_internalFrames.Length)
                    {
                        m_internalFrameIndex++;
                    }

                    fIsFuncEvalFrame = (m_frame.InternalFrameType == CorDebugInternalFrameType.STUBFRAME_FUNC_EVAL);

                    hr = (int)HResult.S_OK;
                }
                else
                {
                    // We just handed out a managed or native frame.
                    // In any case, use the managed unwinder to unwind.
                    hr = m_sw.Next();

                    // Check for end-of-stack condition.
                    if (hr == (int)HResult.CORDBG_S_AT_END_OF_STACK)
                    {
                        m_bEndOfStackFrame = true;
                    }
                }
            }
            else
            {
                // this is the initial call to MoveNext() and MoveNextWorker() that validates the enumeration
                // after we return from MoveNext(), .Current will point to the leaf-most frame
                m_init       = true;
                fIsLeafFrame = true;
                hr           = (int)HResult.S_OK;
            }

            // Check for errors.
            if (HRUtils.IsFailingHR(hr))
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            if (!m_bEndOfStackFrame)
            {
                // Now we need to do a comparison between the current stack frame and the internal frame (if any)
                // to figure out which one to give back first.
                ICorDebugFrame frame;
                m_sw.GetFrame(out frame);

                if (frame == null)
                {
                    // this represents native frame(s) to managed code, we return true because there may be more
                    // managed frames beneath
                    m_frame = null;
                    return(true);
                }

                // we compare the current managed frame with the internal frame
                CorFrame currentFrame = new CorFrame(frame);
                for (; m_internalFrameIndex < m_internalFrames.Length; m_internalFrameIndex++)
                {
                    CorFrame internalFrame = m_internalFrames[m_internalFrameIndex];

                    // Check for internal frame types which are not exposed in V2.
                    if (IsV3InternalFrameType(internalFrame))
                    {
                        continue;
                    }
                    if (internalFrame.IsCloserToLeaf(currentFrame))
                    {
                        currentFrame = internalFrame;
                    }
                    else if (internalFrame.InternalFrameType == CorDebugInternalFrameType.STUBFRAME_M2U)
                    {
                        // we need to look at the caller stack frame's SP

                        INativeContext         ctx    = this.GetContext();
                        CorStackWalk           tStack = m_th.CreateStackWalk(CorStackWalkType.PureV3StackWalk);
                        CorDebugSetContextFlag flag   = ((fIsFuncEvalFrame || fIsLeafFrame) ?
                                                         CorDebugSetContextFlag.SET_CONTEXT_FLAG_ACTIVE_FRAME :
                                                         CorDebugSetContextFlag.SET_CONTEXT_FLAG_UNWIND_FRAME);
                        tStack.SetContext(flag, ctx);

                        //tStack now points to the "previous" managed frame, not the managed frame we're looking at
                        //the first MoveNext call moves the temporary stackwalker to the "current" frame and the next
                        //MoveNext call moves the temporary stackwalker to the "caller" frame
                        Int64 current = 0, caller = 0;
                        if (tStack.MoveNext())
                        {
                            if (tStack.Current != null)
                            {
                                current = tStack.GetContext().StackPointer.ToInt64();
                            }
                        }
                        if (tStack.MoveNext())
                        {
                            if (tStack.Current != null)
                            {
                                caller = tStack.GetContext().StackPointer.ToInt64();
                            }
                        }
                        if (current == 0 || caller == 0)
                        {
                            //we've hit a native frame somewhere, we shouldn't be doing anything with this
                            break;
                        }
                        if (current < caller && internalFrame.IsCloserToLeaf(tStack.Current))
                        {
                            // if there is no caller frame or the current managed frame is closer to the leaf frame
                            // than the next managed frame on the stack (the caller frame), then we must be in the case
                            // where:
                            //          [IL frame without metadata]
                            //          [Internal frame, 'M --> U']
                            //          Caller frame (managed)
                            // We need to flip the internal and IL frames, so we hand back the internal frame first
                            currentFrame = internalFrame;
                        }
                    }

                    break;
                }

                m_frame = currentFrame;
                return(true);
            }
            else
            {
                // We have reached the end of the managed stack.
                // Check to see if we have any internal frames left.

                for (; m_internalFrameIndex < m_internalFrames.Length; m_internalFrameIndex++)
                {
                    CorFrame internalFrame = m_internalFrames[m_internalFrameIndex];
                    if (IsV3InternalFrameType(internalFrame))
                    {
                        continue;
                    }
                    m_frame = internalFrame;
                    return(true);
                }

                return(false);
            }
        }
Ejemplo n.º 32
0
 public ExceptionThrownStopReason(CorAppDomain appDomain, CorThread thread, CorFrame frame,
                                    int offset, CorDebugExceptionCallbackType eventType, int flags,
                                    bool exceptionEnhancedOn)
 {
     m_appDomain = appDomain;
     m_thread = thread;
     m_frame = frame;
     m_offset = offset;
     m_eventtype = eventType;
     m_flags = flags;
     m_exceptionEnhancedOn = exceptionEnhancedOn;
 }
Ejemplo n.º 33
0
        private SequencePoint get_location(CorFrame frame, out uint offset)
        {
            CorDebugMappingResult mapping_result;
            frame.GetIP(out offset, out mapping_result);

            if (frame.FrameType != CorFrameType.ILFrame)
                return null;
            return get_location(frame.Function, offset);
        }
Ejemplo n.º 34
0
 public UnhandledExceptionThrownStopReason(CorAppDomain appDomain, CorThread thread, CorFrame frame,
                                             int offset, CorDebugExceptionCallbackType eventType, int flags)
     : base(appDomain, thread, frame, offset, eventType, flags)
 {
 }
Ejemplo n.º 35
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);
            }
        }
Ejemplo n.º 36
0
		internal static StackFrame CreateFrame (CorDebuggerSession session, CorFrame frame)
		{
			// TODO: Fix remaining.
			uint address = 0;
			//string typeFQN;
			//string typeFullName;
			string addressSpace = "";
			string file = "";
			int line = 0;
			int column = 0;
			string method = "";
			string lang = "";
			string module = "";
			string type = "";
			bool hasDebugInfo = false;
			bool hidden = false;
			bool external = true;

			if (frame.FrameType == CorFrameType.ILFrame) {
				if (frame.Function != null) {
					module = frame.Function.Module.Name;
					CorMetadataImport importer = new CorMetadataImport (frame.Function.Module);
					MethodInfo mi = importer.GetMethodInfo (frame.Function.Token);
					method = mi.DeclaringType.FullName + "." + mi.Name;
					type = mi.DeclaringType.FullName;
					addressSpace = mi.Name;
					ISymbolReader reader = session.GetReaderForModule (frame.Function.Module.Name);
					if (reader != null) {
						ISymbolMethod met = reader.GetMethod (new SymbolToken (frame.Function.Token));
						if (met != null) {
							CorDebugMappingResult mappingResult;
							frame.GetIP (out address, out mappingResult);
							SequencePoint prevSp = null;
							foreach (SequencePoint sp in met.GetSequencePoints ()) {
								if (sp.Offset > address)
									break;
								prevSp = sp;
							}
							if (prevSp != null) {
								line = prevSp.Line;
								column = prevSp.Offset;
								file = prevSp.Document.URL;
								address = (uint)prevSp.Offset;
							}
						}
					}
					// FIXME: Still steps into.
					//hidden = mi.GetCustomAttributes (true).Any (v => v is System.Diagnostics.DebuggerHiddenAttribute);
				}
				lang = "Managed";
				hasDebugInfo = true;
			}
			else if (frame.FrameType == CorFrameType.NativeFrame) {
				frame.GetNativeIP (out address);
				method = "<Unknown>";
				lang = "Native";
			}
			else if (frame.FrameType == CorFrameType.InternalFrame) {
				switch (frame.InternalFrameType) {
					case CorDebugInternalFrameType.STUBFRAME_M2U: method = "[Managed to Native Transition]"; break;
					case CorDebugInternalFrameType.STUBFRAME_U2M: method = "[Native to Managed Transition]"; break;
					case CorDebugInternalFrameType.STUBFRAME_LIGHTWEIGHT_FUNCTION: method = "[Lightweight Method Call]"; break;
					case CorDebugInternalFrameType.STUBFRAME_APPDOMAIN_TRANSITION: method = "[Application Domain Transition]"; break;
					case CorDebugInternalFrameType.STUBFRAME_FUNC_EVAL: method = "[Function Evaluation]"; break;
				}
			}

			if (method == null)
				method = "<Unknown>";

			var loc = new SourceLocation (method, file, line, column);
			return new StackFrame ((long) address, addressSpace, loc, lang, external, hasDebugInfo, hidden, null, null);
		}
Ejemplo n.º 37
0
        /**
         * Intercept the current exception.
         */
        public void InterceptCurrentException(CorFrame frame)
        {
            ICorDebugThread2 m_th2 = (ICorDebugThread2)m_th;

            m_th2.InterceptCurrentException(frame.m_frame);
        }
        public void SetThreadContext ( CorDebugSetContextFlag flag, int contextSize, IntPtr contextBuffer)
        {
            m_sw.SetContext(flag, (uint)contextSize, contextBuffer);

            // update the current frame
            ICorDebugFrame frame;
            m_sw.GetFrame(out frame);

            if (frame == null)
            {
                m_frame = null;
            }
            else
            {
                m_frame = new CorFrame(frame);
            }
        }
Ejemplo n.º 39
0
 public CorException2EventArgs(CorAppDomain appDomain,
                               CorThread thread,
                               CorFrame frame,
                               int offset,
                               CorDebugExceptionCallbackType eventType,
                               int flags,
                               ManagedCallbackType callbackType)
     : base(appDomain, thread, callbackType)
 {
     m_frame = frame;
     m_offset = offset;
     m_eventType = eventType;
     m_flags = flags;
 }
		internal static StackFrame CreateFrame (CorDebuggerSession session, CorFrame frame)
		{
			// TODO: Fix remaining.
			uint address = 0;
			//string typeFQN;
			//string typeFullName;
			string addressSpace = "";
			string file = "";
			int line = 0;
			int endLine = 0;
			int column = 0;
			int endColumn = 0;
			string method = "";
			string lang = "";
			string module = "";
			string type = "";
			bool hasDebugInfo = false;
			bool hidden = false;
			bool external = true;

			if (frame.FrameType == CorFrameType.ILFrame) {
				if (frame.Function != null) {
					module = frame.Function.Module.Name;
					CorMetadataImport importer = new CorMetadataImport (frame.Function.Module);
					MethodInfo mi = importer.GetMethodInfo (frame.Function.Token);
					method = mi.DeclaringType.FullName + "." + mi.Name;
					type = mi.DeclaringType.FullName;
					addressSpace = mi.Name;
					
					var sp = GetSequencePoint (session, frame);
					if (sp != null) {
						line = sp.StartLine;
						column = sp.StartColumn;
						endLine = sp.EndLine;
						endColumn = sp.EndColumn;
						file = sp.Document.URL;
						address = (uint)sp.Offset;
					}

					if (session.IsExternalCode (file)) {
						external = true;
					} else {
						if (session.Options.ProjectAssembliesOnly) {
							external = mi.GetCustomAttributes (true).Any (v => 
								v is System.Diagnostics.DebuggerHiddenAttribute ||
							v is System.Diagnostics.DebuggerNonUserCodeAttribute);
						} else {
							external = mi.GetCustomAttributes (true).Any (v => 
								v is System.Diagnostics.DebuggerHiddenAttribute);
						}
					}
					hidden = mi.GetCustomAttributes (true).Any (v => v is System.Diagnostics.DebuggerHiddenAttribute);
				}
				lang = "Managed";
				hasDebugInfo = true;
			} else if (frame.FrameType == CorFrameType.NativeFrame) {
				frame.GetNativeIP (out address);
				method = "<Unknown>";
				lang = "Native";
			} else if (frame.FrameType == CorFrameType.InternalFrame) {
				switch (frame.InternalFrameType) {
				case CorDebugInternalFrameType.STUBFRAME_M2U:
					method = "[Managed to Native Transition]";
					break;
				case CorDebugInternalFrameType.STUBFRAME_U2M:
					method = "[Native to Managed Transition]";
					break;
				case CorDebugInternalFrameType.STUBFRAME_LIGHTWEIGHT_FUNCTION:
					method = "[Lightweight Method Call]";
					break;
				case CorDebugInternalFrameType.STUBFRAME_APPDOMAIN_TRANSITION:
					method = "[Application Domain Transition]";
					break;
				case CorDebugInternalFrameType.STUBFRAME_FUNC_EVAL:
					method = "[Function Evaluation]";
					break;
				}
			}

			if (method == null)
				method = "<Unknown>";

			var loc = new SourceLocation (method, file, line, column, endLine, endColumn);
			return new StackFrame ((long)address, addressSpace, loc, lang, external, hasDebugInfo, hidden, null, null);
		}