Пример #1
0
 public int EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 ppEnum)
 {
     StackFrame[] stackFrames = ThreadMirror.GetFrames();
     ppEnum =
         new MonoFrameInfoEnum(
             stackFrames.Select(x => new MonoStackFrame(this, debuggedMonoProcess, x).GetFrameInfo(dwFieldSpec)));
     return VSConstants.S_OK;
 }
Пример #2
0
        int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 ppEnum) {
            ThrowIfDisposed();

            var fi = new FRAMEINFO[1];
            var fis = _stackFrames.Value.Select(f => {
                var frame = (IDebugStackFrame2)new AD7StackFrame(Engine, f);
                Marshal.ThrowExceptionForHR(frame.GetInfo(dwFieldSpec, nRadix, fi));
                return fi[0];
            }).ToArray();
            ppEnum = new AD7FrameInfoEnum(fis);
            return VSConstants.S_OK;
        }
Пример #3
0
        // Retrieves a list of the stack frames for this thread.
        // For the sample engine, enumerating the stack frames requires walking the callstack in the debuggee for this thread
        // and coverting that to an implementation of IEnumDebugFrameInfo2.
        // Real engines will most likely want to cache this information to avoid recomputing it each time it is asked for,
        // and or construct it on demand instead of walking the entire stack.
        int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 enumObject)
        {
            enumObject = null;
            try
            {
                // get the thread's stack frames
                System.Collections.Generic.List<ThreadContext> stackFrames = null;
                _engine.DebuggedProcess.WorkerThread.RunOperation(async () => stackFrames = await _engine.DebuggedProcess.ThreadCache.StackFrames(_debuggedThread));
                int numStackFrames = stackFrames != null ? stackFrames.Count : 0;
                FRAMEINFO[] frameInfoArray;

                if (numStackFrames == 0)
                {
                    // failed to walk any frames. Return an empty stack.
                    frameInfoArray = new FRAMEINFO[0];
                }
                else
                {
                    uint low = stackFrames[0].Level;
                    uint high = stackFrames[stackFrames.Count - 1].Level;
                    FilterUnknownFrames(stackFrames);
                    numStackFrames = stackFrames.Count;
                    frameInfoArray = new FRAMEINFO[numStackFrames];
                    List<ArgumentList> parameters = null;

                    if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_ARGS) != 0)
                    {
                        _engine.DebuggedProcess.WorkerThread.RunOperation(async () => parameters = await _engine.DebuggedProcess.GetParameterInfoOnly(this, (dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_ARGS_VALUES) != 0,
                            (dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_ARGS_TYPES) != 0, low, high));
                    }

                    for (int i = 0; i < numStackFrames; i++)
                    {
                        var p = parameters != null ? parameters.Find((ArgumentList t) => t.Item1 == stackFrames[i].Level) : null;
                        AD7StackFrame frame = new AD7StackFrame(_engine, this, stackFrames[i]);
                        frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[i], p != null ? p.Item2 : null);
                    }
                }

                enumObject = new AD7FrameInfoEnum(frameInfoArray);
                return Constants.S_OK;
            }
            catch (MIException e)
            {
                return e.HResult;
            }
            catch (Exception e)
            {
                return EngineUtils.UnexpectedException(e);
            }
        }
Пример #4
0
        /// <summary>
        /// Load call stack
        /// </summary>
        public int EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 ppEnum)
        {
            DLog.Debug(DContext.VSDebuggerComCall, "IDebugThread2.EnumFrameInfo");

            // Get frames
            var frameInfos = new List<FRAMEINFO>();
            foreach (var stackFrame in GetCallStack())
            {
                FRAMEINFO info;
                ((DebugStackFrame)stackFrame).SetFrameInfo(dwFieldSpec, out info);
                frameInfos.Add(info);
            }

            ppEnum = new FrameInfoEnum(frameInfos);
            return VSConstants.S_OK;
        }
        // Retrieves a list of the stack frames for this thread.
        // We currently call into the process and get the frames.  We might want to cache the frame info.
        int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 enumObject) {
            var stackFrames = _debuggedThread.Frames;
            if (stackFrames == null) {
                enumObject = null;
                return VSConstants.E_FAIL;
            }

            int numStackFrames = stackFrames.Count;
            var frameInfoArray = new FRAMEINFO[numStackFrames];

            for (int i = 0; i < numStackFrames; i++) {
                var frame = new AD7StackFrame(_engine, this, stackFrames[i]);
                frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[i]);
            }

            enumObject = new AD7FrameInfoEnum(frameInfoArray);
            return VSConstants.S_OK;
        }
Пример #6
0
    // Retrieves a list of the stack frames for this thread.
    // For the sample engine, enumerating the stack frames requires walking the callstack in the debuggee for this thread
    // and coverting that to an implementation of IEnumDebugFrameInfo2. 
    // Real engines will most likely want to cache this information to avoid recomputing it each time it is asked for,
    // and or construct it on demand instead of walking the entire stack.
    int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS aFieldSpec, uint aRadix, out IEnumDebugFrameInfo2 oEnumObject) {
      // Check mStackFrame, not address because it is possible for 2 sequential breaks to be on the same address
      // but in that case we would need a new stack frame.
      //
      // EnumFrameInfo is called several times on each break becuase "different callers can call with different flags".
      // We ignore flags through and always return full, but EnumFrameInfo gets called half a dozen times which is slow
      // if we refresh each and every time. So we cache our info.
      if (mProcess.mStackFrame == null || true) {
        // Ask the lower-level to perform a stack walk on this thread
        //m_engine.DebuggedProcess.DoStackWalk(this.m_debuggedThread);
        oEnumObject = null;
        try {
          //System.Collections.Generic.List<X86ThreadContext> stackFrames = this.m_debuggedThread.StackFrames;
          //int numStackFrames = stackFrames.Count;
          FRAMEINFO[] xFrameInfoArray;

          //if (numStackFrames == 0) {
          // failed to walk any frames. Only return the top frame.

          xFrameInfoArray = new FRAMEINFO[1];
          var xFrame = new AD7StackFrame(mEngine, this, mProcess);
          xFrame.SetFrameInfo((enum_FRAMEINFO_FLAGS)aFieldSpec, out xFrameInfoArray[0]);

          //} else {
          //frameInfoArray = new FRAMEINFO[numStackFrames];
          //for (int i = 0; i < numStackFrames; i++) {
          //AD7StackFrame frame = new AD7StackFrame(m_engine, this, stackFrames[i]);
          //frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[i]);
          //}
          //}

          mProcess.mStackFrame = new AD7FrameInfoEnum(xFrameInfoArray);
        } catch (Exception e) {
          //catch (ComponentException e) {
          //    return e.HResult;
          //}
          return EngineUtils.UnexpectedException(e);
        }
      }
      oEnumObject = mProcess.mStackFrame;
      return VSConstants.S_OK;
    }
Пример #7
0
        public int EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 ppEnum)
        {
            FRAMEINFO[] frameInfoArray = new FRAMEINFO[FrameCount];

            // Only top frame
            if(FrameCount == 1)
            {
                AD7StackFrame frame = new AD7StackFrame(m_engine, this);
                frame.SetFrameInfo(dwFieldSpec, 0, out frameInfoArray[0]);
            }
            else
            {
                for(int i =0; i<FrameCount;i++)
                {
                    AD7StackFrame frame = new AD7StackFrame(m_engine, this); // stackframe[]
                    frame.SetFrameInfo(dwFieldSpec, i, out frameInfoArray[i]);
                }
            }

            ppEnum = new AD7FrameInfoEnum(frameInfoArray);

            return VSConstants.S_OK;
        }
Пример #8
0
 /// <summary>
 /// Retrieves a list of the stack frames for this thread.
 /// </summary>
 /// <param name="dwFieldSpec">A combination of flags from the FRAMEINFO_FLAGS enumeration that specifies which fields of the FRAMEINFO structures are to be filled out. Specify the FIF_FUNCNAME_FORMAT flag to format the function name into a single string.</param>
 /// <param name="nRadix">Radix used in formatting numerical information in the enumerator.</param>
 /// <param name="ppEnum">Returns an IEnumDebugFrameInfo2 object that contains a list of FRAMEINFO structures describing the stack frame.</param>
 /// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns>
 /// <remarks>The thread's frames are enumerated in order, with the current frame enumerated first and the oldest frame enumerated last.</remarks>
 public virtual int EnumFrameInfo( enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 ppEnum )
 {
     Logger.Debug( string.Empty );
     ppEnum = null;
     return VSConstants.E_NOTIMPL;
 }
Пример #9
0
        // Retrieves a list of the stack frames for this thread.
        // For the sample engine, enumerating the stack frames requires walking the callstack in the debuggee for this thread
        // and coverting that to an implementation of IEnumDebugFrameInfo2.
        // Real engines will most likely want to cache this information to avoid recomputing it each time it is asked for,
        // and or construct it on demand instead of walking the entire stack.
        int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 enumObject)
        {
            // Ask the lower-level to perform a stack walk on this thread
            m_engine.DebuggedProcess.DoStackWalk(this.m_debuggedThread);
            enumObject = null;

            try {
                enumObject = new AD7FrameInfoEnum(m_debuggedThread.StackFrames
                    .Select(f => new AD7StackFrame(m_engine, this, f).GetFrameInfo(dwFieldSpec))
                    .ToArray());
                return Constants.S_OK;
            } catch (Exception e) {
                return EngineUtils.UnexpectedException(e);
            }
        }
 int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 ppEnum)
 {
   // TODO: Get the real callstack here.
   Debug.WriteLine("AD7ProgramNode: Entering EnumFrameInfo");
   ppEnum = new AD7StackFrameCollection(this);
   return VSConstants.S_OK;
 }
Пример #11
0
 int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 ppEnum)
 {
     // TODO: Get the real callstack here.
     Debug.WriteLine("AD7ProgramNode: Entering EnumFrameInfo");
     ppEnum = new AD7StackFrameCollection(this);
     return(VSConstants.S_OK);
 }
Пример #12
0
        int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 ppEnum)
        {
            ThrowIfDisposed();

            var fi  = new FRAMEINFO[1];
            var fis = _stackFrames.Value.Select(f => {
                var frame = (IDebugStackFrame2) new AD7StackFrame(Engine, f);
                Marshal.ThrowExceptionForHR(frame.GetInfo(dwFieldSpec, nRadix, fi));
                return(fi[0]);
            }).ToArray();

            ppEnum = new AD7FrameInfoEnum(fis);
            return(VSConstants.S_OK);
        }
Пример #13
0
 public int EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 ppEnum)
 {
     Log.Debug("Thread: EnumFrameInfo");
     ppEnum = new ScriptStackFrameCollection(Debugger.CallStack, this);
     return VSConstants.S_OK;
 }
Пример #14
0
 public int Clone(out IEnumDebugFrameInfo2 ppEnum)
 {
     Log.Debug("ScriptStackFrameCollection: Clone");
     ppEnum = null;
     return(VSConstants.E_NOTIMPL);
 }
Пример #15
0
        /// <summary>
        /// Retrieves a list of the stack frames for this thread. (http://msdn.microsoft.com/en-ca/library/bb145138.aspx)
        /// </summary>
        /// <param name="dwFieldSpec"> A combination of flags from the FRAMEINFO_FLAGS enumeration that specifies which fields of the
        /// FRAMEINFO structures are to be filled out. </param>
        /// <param name="nRadix"> Radix used in formatting numerical information in the enumerator. </param>
        /// <param name="ppEnum"> Returns an IEnumDebugFrameInfo2 object that contains a list of FRAMEINFO structures describing the
        /// stack frame. </param>
        /// <returns> If successful, returns S_OK; otherwise, returns an error code. </returns>
        int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 ppEnum)
        {
            if (this._id == "")
            {
                ppEnum = null;
                return(Constants.S_FALSE);
            }

            if (this._engine.evaluatedTheseFlags(this._id, dwFieldSpec))
            {
                ppEnum = new AD7FrameInfoEnum(previousFrameInfoArray);
                return(Constants.S_OK);
            }

            // Ask for general stack information.
            if ((this._id != "") && (this._id != this._engine.currentThread()._id))
            {
                _engine.eDispatcher.selectThread(this._id);
            }

            string stackResponse = _engine.eDispatcher.getStackFrames().Replace("#;;;;", "");

            if (stackResponse == "")
            {
                ppEnum = null;
                return(Constants.S_FALSE);
            }
            string[] frameStrings = stackResponse.Split('#');

            // Query the stack depth without inquiring GDB.
            int numStackFrames = frameStrings.Length;

            if (numStackFrames > 30) // limiting the amount of stackFrames to avoid VS crashing.
            {
                numStackFrames = 30;
            }

            ppEnum = null;
            try
            {
                bool        created        = false;
                FRAMEINFO[] frameInfoArray = new FRAMEINFO[numStackFrames];
                for (int i = 0; i < numStackFrames; i++)
                {
                    string[] frameInfo = frameStrings[i].Split(';');
                    if (frameInfo.Length >= 3)
                    {
                        if (frameInfo[3].Contains("~"))
                        {
                            // Need to lengthen the path used by Visual Studio.
                            StringBuilder longPathName = new StringBuilder(1024);
                            GetLongPathName(frameInfo[3], longPathName, longPathName.Capacity);
                            frameInfo[3] = longPathName.ToString();
                        }
                        AD7StackFrame frame = AD7StackFrame.create(_engine, this, frameInfo, ref created);
                        if (frame.m_thread.__stackFrames == null) // that's weird, but sometimes VS is not initializing __stackFrames, so I added this loop to avoid other problems.
                        {
                            while (frame.m_thread.__stackFrames == null)
                            {
                                frame.m_thread.__stackFrames = new ArrayList()
                                {
                                    frame
                                }
                            }
                            ;
                        }
                        frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[i]);
                    }
                }
                if ((previousFrameInfoArray.Length != frameInfoArray.Length) || (created == true))
                {
                    previousFrameInfoArray = frameInfoArray;
                    ppEnum = new AD7FrameInfoEnum(frameInfoArray);
                }
                else
                {
                    bool isEqual = true;
                    for (int i = 0; i < frameInfoArray.Length; i++)
                    {
                        if (frameInfoArray[i].m_bstrFuncName != previousFrameInfoArray[i].m_bstrFuncName)
                        {
                            isEqual = false;
                            break;
                        }
                        if (frameInfoArray[i].m_dwValidFields != previousFrameInfoArray[i].m_dwValidFields)
                        {
                            isEqual = false;
                            break;
                        }
                        if (frameInfoArray[i].m_bstrLanguage != previousFrameInfoArray[i].m_bstrLanguage)
                        {
                            isEqual = false;
                            break;
                        }
                    }
                    if (!isEqual)
                    {
                        previousFrameInfoArray = frameInfoArray;
                        ppEnum = new AD7FrameInfoEnum(frameInfoArray);
                    }
                    else
                    {
                        ppEnum = new AD7FrameInfoEnum(previousFrameInfoArray);
                    }
                }

                if ((this._id != "") && (this._id != this._engine.currentThread()._id))
                {
                    _engine.eDispatcher.selectThread(this._engine.currentThread()._id);
                }

                return(Constants.S_OK);
            }
            catch (ComponentException e)
            {
                if ((this._id != "") && (this._id != this._engine.currentThread()._id))
                {
                    _engine.eDispatcher.selectThread(this._engine.currentThread()._id);
                }
                return(e.HResult);
            }
            catch (Exception e)
            {
                if ((this._id != "") && (this._id != this._engine.currentThread()._id))
                {
                    _engine.eDispatcher.selectThread(this._engine.currentThread()._id);
                }
                return(EngineUtils.UnexpectedException(e));
            }
        }
Пример #16
0
        void DbgCmdBreak(UInt32 aAddress)
        {
            // aAddress will be actual address. Call and other methods push return to (after op), but DS
            // corrects for us and sends us actual op address.
            DebugMsg("DbgCmdBreak " + aAddress + " / " + aAddress.ToString("X8").ToUpper());

            if (mASMSteppingOut)
            {
                string[] currentASMLabels = mDebugInfoDb.GetLabels(aAddress);
                foreach (string aLabel in currentASMLabels)
                {
                    if (aLabel.Contains("END__OF__METHOD_EXCEPTION__2"))
                    {
                        mASMSteppingOut_NumEndMethodLabelsPassed++;
                        break;
                    }
                }
                if (mASMSteppingOut_NumEndMethodLabelsPassed >= 2)
                {
                    mASMSteppingOut = false;
                }
                new System.Threading.Tasks.Task(() =>
                {
                    mDbgConnector.SendCmd(Vs2Ds.AsmStepInto);
                }).Start();
            }
            else
            {
                bool fullUpdate = true;


                var xActionPoints     = new List <object>();
                var xBoundBreakpoints = new List <IDebugBoundBreakpoint2>();

                if (!mBreaking)
                {
                    // Search the BPs and find ones that match our address.
                    foreach (var xBP in mEngine.BPMgr.mPendingBPs)
                    {
                        foreach (var xBBP in xBP.mBoundBPs)
                        {
                            if (xBBP.mAddress == aAddress)
                            {
                                xBoundBreakpoints.Add(xBBP);
                            }
                        }
                    }
                }

                mStackFrame     = null;
                mCurrentAddress = aAddress;
                mCurrentASMLine = null;
                if (xBoundBreakpoints.Count == 0)
                {
                    // If no matching breakpoints are found then its one of the following:
                    //   - VS Break
                    //   - Stepping operation
                    //   - Asm break


                    //We _must_ respond to the VS commands via callback if VS is waiting on one so check this first...
                    if (mBreaking)
                    {
                        mCallback.OnBreak(mThread);
                        mBreaking = false;
                    }
                    else if (mStepping)
                    {
                        mCallback.OnStepComplete();
                        mStepping = false;
                    }
                    else
                    {
                        //Check if current address is the ASM BP we might be looking for
                        if (ASMBPToStepTo != null && ASMBPToStepTo.Item2 == aAddress)
                        {
                            //There is an ASM BP at this address so break
                            mCallback.OnBreak(mThread);
                            //Clear what we are stepping towards
                            ASMBPToStepTo = null;
                        }
                        else
                        {
                            fullUpdate = false;

                            //Check we aren't already stepping towards an ASM BP
                            if (ASMBPToStepTo == null)
                            {
                                //Check for future ASM breakpoints...

                                //Since we got this far, we know this must be an INT3 for a future ASM BP that has to be in current C# line.
                                //So get the ASM BP based off current address
                                var bp = GetASMBreakpointInfoFromCSAddress(aAddress).First();
                                //Set it as address we are looking for
                                ASMBPToStepTo = bp;
                            }

                            //Step towards the ASM BP(step-over since we don't want to go through calls or anything)

                            //We must check we haven't just stepped and address jumped wildely out of range (e.g. conditional jumps)
                            if (aAddress < ASMBPToStepTo.Item1 || aAddress > ASMBPToStepTo.Item2)
                            {
                                //If we have, just continue execution as this BP won't be hit.
                                mDbgConnector.Continue();
                                ASMBPToStepTo = null;
                            }
                            else
                            {
                                //We must do an update of ASM window so Step-Over can function properly
                                SendAssembly(true);
                                //Delay / wait for asm window to update
                                WaitForAssemblyUpdate();
                                //Do the step-over
                                ASMStepOver();
                            }
                        }
                    }
                }
                else
                {
                    // Found a bound breakpoint
                    mCallback.OnBreakpoint(mThread, xBoundBreakpoints.AsReadOnly());
                }
                if (fullUpdate)
                {
                    RequestFullDebugStubUpdate();
                }
            }
        }
Пример #17
0
 public virtual int EnumFrameInfo(enum_FRAMEINFO_FLAGS fieldSpec, uint radix,
                                  out IEnumDebugFrameInfo2 frameInfoEnum)
 {
     frameInfoEnum = _frameEnumFactory.Create(_stackFramesProvider, fieldSpec, Self);
     return(VSConstants.S_OK);
 }
Пример #18
0
        // Retrieves a list of the stack frames for this thread.
        // We currently call into the process and get the frames.  We might want to cache the frame info.
        int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 enumObject)
        {
            var stackFrames = _debuggedThread.Frames;

            if (stackFrames == null)
            {
                enumObject = null;
                return(VSConstants.E_FAIL);
            }

            int numStackFrames = stackFrames.Count;

            var frameInfoArray = new FRAMEINFO[numStackFrames];

            for (int i = 0; i < numStackFrames; i++)
            {
                AD7StackFrame frame = new AD7StackFrame(_engine, this, stackFrames[i]);
                frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[i]);
            }

            enumObject = new AD7FrameInfoEnum(frameInfoArray);
            return(VSConstants.S_OK);
        }
 public int EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 ppEnum)
 {
     Log.Debug("Thread: EnumFrameInfo");
     ppEnum = new ScriptStackFrameCollection(Debugger.CallStack, this);
     return(VSConstants.S_OK);
 }
Пример #20
0
        // Retrieves a list of the stack frames for this thread.
        // For the sample engine, enumerating the stack frames requires walking the callstack in the debuggee for this thread
        // and coverting that to an implementation of IEnumDebugFrameInfo2.
        // Real engines will most likely want to cache this information to avoid recomputing it each time it is asked for,
        // and or construct it on demand instead of walking the entire stack.
        int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 enumObject)
        {
            // Ask the lower-level to perform a stack walk on this thread
            m_engine.DebuggedProcess.DoStackWalk(this.m_debuggedThread);
            enumObject = null;

            try
            {
                System.Collections.Generic.List<X86ThreadContext> stackFrames = this.m_debuggedThread.StackFrames;
                int numStackFrames = stackFrames.Count;
                FRAMEINFO[] frameInfoArray;

                if (numStackFrames == 0)
                {
                    // failed to walk any frames. Only return the top frame.
                    frameInfoArray = new FRAMEINFO[1];
                    AD7StackFrame frame = new AD7StackFrame(m_engine, this, GetThreadContext());
                    frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[0]);
                }
                else
                {
                    frameInfoArray = new FRAMEINFO[numStackFrames];

                    for (int i = 0; i < numStackFrames; i++)
                    {
                        AD7StackFrame frame = new AD7StackFrame(m_engine, this, stackFrames[i]);
                        frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[i]);
                    }
                }

                enumObject = new AD7FrameInfoEnum(frameInfoArray);
                return Constants.S_OK;
            }
            catch (ComponentException e)
            {
                return e.HResult;
            }
            catch (Exception e)
            {
                return EngineUtils.UnexpectedException(e);
            }
        }
Пример #21
0
        // Retrieves a list of the stack frames for this thread.
        // For the sample engine, enumerating the stack frames requires walking the callstack in the debuggee for this thread
        // and coverting that to an implementation of IEnumDebugFrameInfo2.
        // Real engines will most likely want to cache this information to avoid recomputing it each time it is asked for,
        // and or construct it on demand instead of walking the entire stack.
        int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS aFieldSpec, uint aRadix, out IEnumDebugFrameInfo2 oEnumObject)
        {
            // Check mStackFrame, not address because it is possible for 2 sequential breaks to be on the same address
            // but in that case we would need a new stack frame.
            //
            // EnumFrameInfo is called several times on each break becuase "different callers can call with different flags".
            // We ignore flags through and always return full, but EnumFrameInfo gets called half a dozen times which is slow
            // if we refresh each and every time. So we cache our info.
            if (mProcess.mStackFrame == null || true)
            {
                // Ask the lower-level to perform a stack walk on this thread
                //m_engine.DebuggedProcess.DoStackWalk(this.m_debuggedThread);
                oEnumObject = null;
                try {
                    //System.Collections.Generic.List<X86ThreadContext> stackFrames = this.m_debuggedThread.StackFrames;
                    //int numStackFrames = stackFrames.Count;
                    FRAMEINFO[] xFrameInfoArray;

                    //if (numStackFrames == 0) {
                    // failed to walk any frames. Only return the top frame.

                    xFrameInfoArray = new FRAMEINFO[1];
                    var xFrame = new AD7StackFrame(mEngine, this, mProcess);
                    xFrame.SetFrameInfo(aFieldSpec, out xFrameInfoArray[0]);

                    //} else {
                    //frameInfoArray = new FRAMEINFO[numStackFrames];
                    //for (int i = 0; i < numStackFrames; i++) {
                    //AD7StackFrame frame = new AD7StackFrame(m_engine, this, stackFrames[i]);
                    //frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[i]);
                    //}
                    //}

                    mProcess.mStackFrame = new AD7FrameInfoEnum(xFrameInfoArray);
                } catch (Exception e) {
                    //catch (ComponentException e) {
                    //    return e.HResult;
                    //}
                    return(EngineUtils.UnexpectedException(e));
                }
            }
            oEnumObject = mProcess.mStackFrame;
            return(VSConstants.S_OK);
        }
Пример #22
0
        void DbgCmdBreak(UInt32 aAddress)
        {
            // aAddress will be actual address. Call and other methods push return to (after op), but DS
            // corrects for us and sends us actual op address.
            DebugMsg("DbgCmdBreak " + aAddress + " / " + aAddress.ToString("X8").ToUpper());

            if (mASMSteppingOut)
            {
                string[] currentASMLabels = mDebugInfoDb.GetLabels(aAddress);
                foreach (string aLabel in currentASMLabels)
                {
                    if (aLabel.Contains("END__OF__METHOD_EXCEPTION__2"))
                    {
                        mASMSteppingOut_NumEndMethodLabelsPassed++;
                        break;
                    }
                }
                if (mASMSteppingOut_NumEndMethodLabelsPassed >= 2)
                {
                    mASMSteppingOut = false;
                }
                new System.Threading.Tasks.Task(() =>
                {
                    mDbgConnector.SendCmd(Vs2Ds.AsmStepInto);
                }).Start();
            }
            else
            {
                bool fullUpdate = true;


                var xActionPoints = new List<object>();
                var xBoundBreakpoints = new List<IDebugBoundBreakpoint2>();

                if (!mBreaking)
                {
                    // Search the BPs and find ones that match our address.
                    foreach (var xBP in mEngine.BPMgr.mPendingBPs)
                    {
                        foreach (var xBBP in xBP.mBoundBPs)
                        {
                            if (xBBP.mAddress == aAddress)
                            {
                                xBoundBreakpoints.Add(xBBP);
                            }
                        }
                    }
                }

                mStackFrame = null;
                mCurrentAddress = aAddress;
                mCurrentASMLine = null;
                if (xBoundBreakpoints.Count == 0)
                {
                    // If no matching breakpoints are found then its one of the following:
                    //   - VS Break
                    //   - Stepping operation
                    //   - Asm break


                    //We _must_ respond to the VS commands via callback if VS is waiting on one so check this first...
                    if (mBreaking)
                    {
                        mCallback.OnBreak(mThread);
                        mBreaking = false;
                    }
                    else if (mStepping)
                    {
                        mCallback.OnStepComplete();
                        mStepping = false;
                    }
                    else
                    {
                        //Check if current address is the ASM BP we might be looking for
                        if (ASMBPToStepTo != null && ASMBPToStepTo.Item2 == aAddress)
                        {
                            //There is an ASM BP at this address so break
                            mCallback.OnBreak(mThread);
                            //Clear what we are stepping towards
                            ASMBPToStepTo = null;
                        }
                        else
                        {
                            fullUpdate = false;

                            //Check we aren't already stepping towards an ASM BP
                            if (ASMBPToStepTo == null)
                            {
                                //Check for future ASM breakpoints...

                                //Since we got this far, we know this must be an INT3 for a future ASM BP that has to be in current C# line.
                                //So get the ASM BP based off current address
                                var bp = GetASMBreakpointInfoFromCSAddress(aAddress).First();
                                //Set it as address we are looking for
                                ASMBPToStepTo = bp;
                            }

                            //Step towards the ASM BP(step-over since we don't want to go through calls or anything)

                            //We must check we haven't just stepped and address jumped wildely out of range (e.g. conditional jumps)
                            if (aAddress < ASMBPToStepTo.Item1 || aAddress > ASMBPToStepTo.Item2)
                            {
                                //If we have, just continue execution as this BP won't be hit.
                                mDbgConnector.Continue();
                                ASMBPToStepTo = null;
                            }
                            else
                            {
                                //We must do an update of ASM window so Step-Over can function properly
                                SendAssembly(true);
                                //Delay / wait for asm window to update
                                WaitForAssemblyUpdate();
                                //Do the step-over
                                ASMStepOver();
                            }
                        }
                    }
                }
                else
                {
                    // Found a bound breakpoint
                    mCallback.OnBreakpoint(mThread, xBoundBreakpoints.AsReadOnly());
                }
                if (fullUpdate)
                {
                    RequestFullDebugStubUpdate();
                }
            }
        }
Пример #23
0
 public int Clone(out IEnumDebugFrameInfo2 ppEnum)
 {
     ppEnum = null;
     return(VSConstants.E_NOTIMPL);
 }
Пример #24
0
 public int EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 ppEnum)
 {
     StackFrame[] stackFrames = ThreadMirror.GetFrames();
     ppEnum = new AD7FrameInfoEnum(stackFrames.Select(x => new AD7StackFrame(_engine, this, x).GetFrameInfo(dwFieldSpec)).ToArray());
     return VSConstants.S_OK;
 }
Пример #25
0
        /// <summary>
        /// Retrieves a list of the stack frames for this thread. (http://msdn.microsoft.com/en-ca/library/bb145138.aspx)
        /// </summary>
        /// <param name="dwFieldSpec"> A combination of flags from the FRAMEINFO_FLAGS enumeration that specifies which fields of the 
        /// FRAMEINFO structures are to be filled out. </param>
        /// <param name="nRadix"> Radix used in formatting numerical information in the enumerator. </param>
        /// <param name="ppEnum"> Returns an IEnumDebugFrameInfo2 object that contains a list of FRAMEINFO structures describing the 
        /// stack frame. </param>
        /// <returns> If successful, returns S_OK; otherwise, returns an error code. </returns>
        int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 ppEnum)
        {
            if (this._id == "")
            {
                ppEnum = null;
                return Constants.S_FALSE;
            }

            if (this._engine.evaluatedTheseFlags(this._id, dwFieldSpec))
            {
                ppEnum = new AD7FrameInfoEnum(previousFrameInfoArray);
                return Constants.S_OK;
            }

            // Ask for general stack information.
            if ((this._id != "") && (this._id != this._engine.currentThread()._id))
                _engine.eDispatcher.selectThread(this._id);

            string stackResponse = _engine.eDispatcher.getStackFrames().Replace("#;;;;", "");
            if (stackResponse == "")
            {
                ppEnum = null;
                return Constants.S_FALSE;
            }
            string[] frameStrings = stackResponse.Split('#');

            // Query the stack depth without inquiring GDB.
            int numStackFrames = frameStrings.Length;

            if (numStackFrames > 30) // limiting the amount of stackFrames to avoid VS crashing.
                numStackFrames = 30;

            ppEnum = null;
            try
            {
                bool created = false;
                FRAMEINFO[] frameInfoArray = new FRAMEINFO[numStackFrames];
                for (int i = 0; i < numStackFrames; i++)
                {
                    string[] frameInfo = frameStrings[i].Split(';');
                    if (frameInfo.Length >= 3)
                    {
                        if (frameInfo[3].Contains("~"))
                        {
                            // Need to lengthen the path used by Visual Studio.
                            StringBuilder longPathName = new StringBuilder(1024);
                            GetLongPathName(frameInfo[3], longPathName, longPathName.Capacity);
                            frameInfo[3] = longPathName.ToString();
                        }
                        AD7StackFrame frame = AD7StackFrame.create(_engine, this, frameInfo, ref created);
                        frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[i]);
                    }
                }
                if ((previousFrameInfoArray.Length != frameInfoArray.Length) || (created == true))
                {
                    previousFrameInfoArray = frameInfoArray;
                    ppEnum = new AD7FrameInfoEnum(frameInfoArray);
                }
                else
                {
                    bool isEqual = true;
                    for (int i = 0; i < frameInfoArray.Length; i++)
                    {
                        if (frameInfoArray[i].m_bstrFuncName != previousFrameInfoArray[i].m_bstrFuncName)
                        {
                            isEqual = false;
                            break;
                        }
                        if (frameInfoArray[i].m_dwValidFields != previousFrameInfoArray[i].m_dwValidFields)
                        {
                            isEqual = false;
                            break;
                        }
                        if (frameInfoArray[i].m_bstrLanguage != previousFrameInfoArray[i].m_bstrLanguage)
                        {
                            isEqual = false;
                            break;
                        }
                    }
                    if (!isEqual)
                    {
                        previousFrameInfoArray = frameInfoArray;
                        ppEnum = new AD7FrameInfoEnum(frameInfoArray);
                    }
                    else
                    {
                        ppEnum = new AD7FrameInfoEnum(previousFrameInfoArray);
                    }
                }

                if ((this._id != "") && (this._id != this._engine.currentThread()._id))
                    _engine.eDispatcher.selectThread(this._engine.currentThread()._id);

                return Constants.S_OK;
            }
            catch (ComponentException e)
            {
                if ((this._id != "") && (this._id != this._engine.currentThread()._id))
                    _engine.eDispatcher.selectThread(this._engine.currentThread()._id);
                return e.HResult;
            }
            catch (Exception e)
            {
                if ((this._id != "") && (this._id != this._engine.currentThread()._id))
                    _engine.eDispatcher.selectThread(this._engine.currentThread()._id);
                return EngineUtils.UnexpectedException(e);
            }
        }
Пример #26
0
        int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 ppEnum)
        {
            // Query the stack depth inquiring GDB.
            //            int numStackFrames = _engine.eDispatcher.getStackDepth();
            if (this._id == "")
            {
                ppEnum = null;
                return Constants.S_FALSE;
            }

            if (this._engine.evaluatedTheseFlags(this._id, dwFieldSpec))
            {
                ppEnum = new AD7FrameInfoEnum(previousFrameInfoArray);
                return Constants.S_OK;
            }

            // Ask for general stack information.
            if ((this._id != "") && (this._id != this._engine.currentThread()._id))
                _engine.eDispatcher.selectThread(this._id);

            string stackResponse = _engine.eDispatcher.getStackFrames().Replace("#;;;;", "");
            if (stackResponse == "")
            {
                ppEnum = null;
                return Constants.S_FALSE;
            }
            string[] frameStrings = stackResponse.Split('#');

            // Query the stack depth without inquiring GDB.
            int numStackFrames = frameStrings.Length;

            if (numStackFrames > 30) // limiting the amount of stackFrames to avoid VS crashing.
                numStackFrames = 30;

            ppEnum = null;
            try
            {
                bool created = false;
                FRAMEINFO[] frameInfoArray = new FRAMEINFO[numStackFrames];
                for (int i = 0; i < numStackFrames; i++)
                {
                    string[] frameInfo = frameStrings[i].Split(';');
                    if (frameInfo.Length >= 3)
                    {
                        if (frameInfo[3].Contains("~"))
                        {
                            // Need to lengthen the path used by Visual Studio.
                            StringBuilder longPathName = new StringBuilder(1024);
                            GetLongPathName(frameInfo[3], longPathName, longPathName.Capacity);
                            frameInfo[3] = longPathName.ToString();
                        }
                        AD7StackFrame frame = AD7StackFrame.create(_engine, this, frameInfo, ref created);
                        if (frame.m_thread.__stackFrames == null) // that's weird, but sometimes VS is not initializing __stackFrames, so I added this loop to avoid other problems.
                        {
                            while (frame.m_thread.__stackFrames == null)
                                frame.m_thread.__stackFrames = new ArrayList() { frame };
                            //                        frame.m_thread.__stackFrames.Add(frame);
                        }
                        //                    if ((_filename != "") || (created == true))
                        frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[i]);
                    }
                }
                // Ignoring when _filename is null to avoid duplicate entries in Call Stack Window.
            //                if ((_filename == "")  && (created == false))
            //                {
            //                    ppEnum = null;
            //                    if (this._id != "")
            //                        _engine.eDispatcher.selectThread(this._engine.currentThread()._id);
            //                    return Constants.S_FALSE;
            //                }
                if ((previousFrameInfoArray.Length != frameInfoArray.Length) || (created == true))
                {
                    previousFrameInfoArray = frameInfoArray;
                    ppEnum = new AD7FrameInfoEnum(frameInfoArray);
                }
                else
                {
                    bool isEqual = true;
                    for (int i = 0; i < frameInfoArray.Length; i++)
                    {
                        if (frameInfoArray[i].m_bstrFuncName != previousFrameInfoArray[i].m_bstrFuncName)
                        {
                            isEqual = false;
                            break;
                        }
                        if (frameInfoArray[i].m_dwValidFields != previousFrameInfoArray[i].m_dwValidFields)
                        {
                            isEqual = false;
                            break;
                        }
                        if (frameInfoArray[i].m_bstrLanguage != previousFrameInfoArray[i].m_bstrLanguage)
                        {
                            isEqual = false;
                            break;
                        }
                    }
                    if (!isEqual)
                    {
                        previousFrameInfoArray = frameInfoArray;
                        ppEnum = new AD7FrameInfoEnum(frameInfoArray);
                    }
                    else
                    {
                        ppEnum = new AD7FrameInfoEnum(previousFrameInfoArray);
                    }
                }
            //                GDBParser.parseCommand("-stack-select-frame 0", 17);

                if ((this._id != "") && (this._id != this._engine.currentThread()._id))
                    _engine.eDispatcher.selectThread(this._engine.currentThread()._id);

                return Constants.S_OK;
            }
            catch (ComponentException e)
            {
                if ((this._id != "") && (this._id != this._engine.currentThread()._id))
                    _engine.eDispatcher.selectThread(this._engine.currentThread()._id);
                return e.HResult;
            }
            catch (Exception e)
            {
                if ((this._id != "") && (this._id != this._engine.currentThread()._id))
                    _engine.eDispatcher.selectThread(this._engine.currentThread()._id);
                return EngineUtils.UnexpectedException(e);
            }
        }
Пример #27
0
        public int EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 ppEnum)
        {
            ppEnum = null;
            List<FRAMEINFO> frames = new List<FRAMEINFO>();

#if !HIDE_THREADS
            ReadOnlyCollection<IStackFrame> stackFrames = _thread.GetFrames();

            FRAMEINFO[] frameInfo = new FRAMEINFO[1];
            foreach (var stackFrame in stackFrames)
            {
                JavaDebugStackFrame javaStackFrame = new JavaDebugStackFrame(this, stackFrame);
                int result = javaStackFrame.GetInfo(dwFieldSpec, nRadix, frameInfo);
                if (!ErrorHandler.Succeeded(result))
                    return result;

                frames.Add(frameInfo[0]);
            }
#endif

            ppEnum = new EnumDebugFrameInfo(frames);
            return VSConstants.S_OK;
        }
Пример #28
0
        // Retrieves a list of the stack frames for this thread.
        // For the sample engine, enumerating the stack frames requires walking the callstack in the debuggee for this thread
        // and coverting that to an implementation of IEnumDebugFrameInfo2.
        // Real engines will most likely want to cache this information to avoid recomputing it each time it is asked for,
        // and or construct it on demand instead of walking the entire stack.
        int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 enumObject)
        {
            // Ask the lower-level to perform a stack walk on this thread
            var stackFrames = debuggedThread.Backtrace;

            enumObject = null;

            try
            {
                int         numStackFrames = stackFrames.FrameCount;
                FRAMEINFO[] frameInfoArray;

                if (numStackFrames == 0)
                {
                    // failed to walk any frames. Only return the top frame.
                    frameInfoArray = new FRAMEINFO[0];
//                    MonoStackFrame frame = new MonoStackFrame(engine, this, debuggedThread);
//                    frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[0]);
                }
                else
                {
                    frameInfoArray = new FRAMEINFO[numStackFrames];

                    for (int i = 0; i < numStackFrames; i++)
                    {
                        MonoStackFrame frame = new MonoStackFrame(engine, this, stackFrames.GetFrame(i));
                        frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[i]);
                    }
                }

                enumObject = new MonoFrameInfoEnum(frameInfoArray);
                return(VSConstants.S_OK);
            }
            catch (ComponentException e)
            {
                return(e.HResult);
            }
            catch (Exception e)
            {
                return(EngineUtils.UnexpectedException(e));
            }
        }
Пример #29
0
        // Retrieves a list of the stack frames for this thread.
        // For the sample engine, enumerating the stack frames requires walking the callstack in the debuggee for this thread
        // and coverting that to an implementation of IEnumDebugFrameInfo2.
        // Real engines will most likely want to cache this information to avoid recomputing it each time it is asked for,
        // and or construct it on demand instead of walking the entire stack.
        int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 enumObject)
        {
            // Ask the lower-level to perform a stack walk on this thread
            // m_engine.DebuggedProcess.DoStackWalk(this.m_debuggedThread);
            enumObject = null;

            try
            {
                //AD7StackFrame[] stackFrames = this.stackFrames;
                //System.Collections.Generic.List<X86ThreadContext> stackFrames = this.m_debuggedThread.StackFrames;
                int         numStackFrames = sqframes.Count;
                FRAMEINFO[] frameInfoArray;

                if (numStackFrames == 0)
                {
                    // failed to walk any frames. Only return the top frame.
                    frameInfoArray = new FRAMEINFO[1];
                    AD7StackFrame frame = new AD7StackFrame(engine, this, ctx, new SquirrelStackFrame());
                    frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[0]);
                    return(EngineConstants.E_FAIL);
                }
                else
                {
                    frameInfoArray = new FRAMEINFO[numStackFrames];

                    for (int i = 0; i < numStackFrames; i++)
                    {
                        AD7StackFrame frame = new AD7StackFrame(engine, this, ctx, sqframes[i]);
                        frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[i]);
                    }
                }

                enumObject = new AD7FrameInfoEnum(frameInfoArray);
                return(EngineConstants.S_OK);
            }
            catch (ComponentException e)
            {
                return(e.HRESULT);
            }
            catch (Exception e)
            {
                return(EngineUtils.UnexpectedException(e));
            }
            throw new NotImplementedException();
        }