首页 > 代码库 > Vs2013在Linux开发中的应用(28):单步执行

Vs2013在Linux开发中的应用(28):单步执行

快乐虾

http://blog.csdn.net/lights_joy/

欢迎转载,但请保留作者信息

VS调试时,有三种类型的单步操作逐语句,逐过程和跳出,当进行这三种操作时,SDM调用的其实是同一个回调:

        // This method is deprecated. Use the IDebugProcess3::Step method instead.

        /// <summary>
        /// Performs a step. 
        /// 
        /// In case there is any thread synchronization or communication between threads, other threads in the program should run when a particular thread is stepping.
        /// </summary>
        public int Step(IDebugThread2 pThread, enum_STEPKIND sk, enum_STEPUNIT Step)
        {
            if (_mixedMode)
            {
                return Constants.E_NOTIMPL;
            }

            var thread = ((AD7Thread)pThread).GetDebuggedThread();
            switch (sk)
            {
                case enum_STEPKIND.STEP_INTO: thread.StepInto(); break;
                case enum_STEPKIND.STEP_OUT: thread.StepOut(); break;
                case enum_STEPKIND.STEP_OVER: thread.StepOver(); break;
            }
            return Constants.S_OK;
        }

我们将之转换为gdb的命令:

        internal void SendStepOut(long threadId) {
            DebugWriteCommand("StepOut");
            ExecDone("-exec-return");
            var stepComp = StepComplete;
            PythonThread trd = _threads[threadId];
            if (stepComp != null)
            {
                stepComp(this, new ThreadEventArgs(trd));
            }
        }

        internal void SendStepOver(long threadId) {
            DebugWriteCommand("StepOver");
            ExecCommand("-exec-next");
        }

        internal void SendStepInto(long threadId) {
            DebugWriteCommand("StepInto");
            ExecCommand("-exec-step");
        }

这里需要注意的是gdb执行StepOut时与其它两个操作略微有点差异,当执行StepOut

-exec-return

^done,frame={level="0",func="callee3",

args=[{name="strarg",

value=http://www.mamicode.com/"0x11940 /"A string argument./""}],

file="../../../devo/gdb/testsuite/gdb.mi/basics.c",

fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"}

也就是说它直接输出了^done信息,而其它两个操作则使用了*stopped信息:

-exec-step

^running

(gdb)

*stopped,reason="end-stepping-range",line="14",file="recursive2.c"

相同的一点是,在这三种操作结束后都必须发送事件通知SDM

        private void OnStepComplete(object sender, ThreadEventArgs e)
        {
            Send(new AD7SteppingCompleteEvent(), AD7SteppingCompleteEvent.IID, _threads[e.Thread]);
        }

搞定!

现在我们就可以在VS中使用gdb进行单步调试了!









??

Vs2013在Linux开发中的应用(28):单步执行