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="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进行单步调试了!
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。