快乐虾

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

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

1.1    载入调试引擎

因为我们无法干预VC的调试引擎载入。但能够侦听VC的调试引擎载入事件,在此事件处理中能够调用自己的调试引擎:

publicvoid LaunchDebugTarget(string filePath, string env)

{

varserver = (IDebugCoreServer3)GetService(typeof(IDebugCoreServer3));

vardebugger = (IVsDebugger3)GetService(typeof(IVsDebugger));

VsDebugTargetInfo3[] debugTargets = new VsDebugTargetInfo3[1];

debugTargets[0].dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;

debugTargets[0].bstrExe = filePath;

debugTargets[0].bstrEnv = env;

debugTargets[0].guidLaunchDebugEngine = new Guid(lights.EmbedLinux.Debugger.Engine.EngineConstants.EngineId);

VsDebugTargetProcessInfo[] processInfo = new VsDebugTargetProcessInfo[debugTargets.Length];

try

{

debugger.LaunchDebugTargets3(1, debugTargets, processInfo);

}

catch(Exceptione)

{

Debug.WriteLine("Exception when Launch debugger: " + e.Message);

}

}

在此使用了IVsDebugger.LaunchDebugTarget3。在此调用中,SDM将依据EngineId查找此Engine所在的文件并进行引擎的创建。

1.2    LaunchSuspended

在SDM创建引擎后调用的第一个函数是LauchSuspended:

// Launches a process by means of the debug engine.

// Normally, Visual Studio launches a program using theIDebugPortEx2::LaunchSuspended method and then attaches the debugger

// to the suspended program. However, there arecircumstances in which the debug engine may need to launch a program

// (for example, if the debug engine is part of aninterpreter and the program being debugged is an interpreted language),

// in which case Visual Studio uses theIDebugEngineLaunch2::LaunchSuspended method

// The IDebugEngineLaunch2::ResumeProcess method iscalled to start the process after the process has been successfully launched ina suspended state.

intIDebugEngineLaunch2.LaunchSuspended(string pszServer, IDebugPort2 port, string exe, string args, string dir, string env, string options, enum_LAUNCH_FLAGS launchFlags, uint hStdInput, uint hStdOutput, uint hStdError, IDebugEventCallback2 ad7Callback, out IDebugProcess2 process)

在此函数中,我们能够让python通过某个连接载入虚拟机里的gdb。再将python进程的ID号返回给SDM:

AD_PROCESS_ID adProcessId = new AD_PROCESS_ID();

adProcessId.ProcessIdType = (uint)enum_AD_PROCESS_ID.AD_PROCESS_ID_SYSTEM;

adProcessId.dwProcessId= (uint)_process.Id;

EngineUtils.RequireOk(port.GetProcess(adProcessId,out process));

1.3    ResumeProcess

SDM调用的第二个关键函数是ResumeProcess:

// Resume a process launched byIDebugEngineLaunch2.LaunchSuspended

intIDebugEngineLaunch2.ResumeProcess(IDebugProcess2 process)

这个函数感觉有点歧义,似乎应该在这里让gdb里载入的应用执行起来,但实际上,在这个函数里应该做的是创建ProgramNode:

// Send a program node to the SDM. This will cause theSDM to turn around and call IDebugEngine2.Attach

// which will complete the hookup with AD7

IDebugPort2port;

EngineUtils.RequireOk(process.GetPort(outport));

IDebugDefaultPort2 defaultPort = (IDebugDefaultPort2)port;

IDebugPortNotify2 portNotify;

EngineUtils.RequireOk(defaultPort.GetPortNotify(out portNotify));

EngineUtils.RequireOk(portNotify.AddProgramNode(new AD7ProgramNode(_process.Id)));

1.4    Attach

下一个关键函数:

// Attach the debug engine to a program.

intIDebugEngine2.Attach(IDebugProgram2[] rgpPrograms, IDebugProgramNode2[] rgpProgramNodes, uint celtPrograms, IDebugEventCallback2 ad7Callback, enum_ATTACH_REASON dwReason)

在这个函数中。我们须要发送两个事件给SDM:

AD7EngineCreateEvent.Send(this);

AD7ProgramCreateEvent.Send(this);

1.5    LoadComplete

当gdb成功载入应用程序后,我们须要发送LoadComplete通知SDM:

Send(newAD7LoadCompleteEvent(), AD7LoadCompleteEvent.IID, thread);

1.6    设置断点

设置断点的工作后面单独说,在此先跳过。

1.7    Continue

在断点设置完毕后,SDM将调用Continue:

// Continue is called from the SDM when it wantsexecution to continue in the debugee

// but have stepping state remain. An example is when atracepoint is executed,

// and the debugger does not want to actually enter breakmode.

publicint Continue(IDebugThread2 pThread)

在这个函数中就能够让gdb执行run命令了。

至此,SDM成功载入gdb及要调试的应用。



最新文章

  1. SpringMVC生成任意文件,访问链接即下载
  2. 创建Maven web项目时 出现 web.xml is missing and <failOnMissingWebXml> is set to true错误 pox.xml编译错误
  3. Spark Job的提交与task本地化分析(源码阅读八)
  4. php 之跨域上传图片
  5. webpack入坑之旅(一)不是开始的开始
  6. python中set使用
  7. Linux录屏软件
  8. Error 2147943712 during task creation
  9. CentOS安装vsftpd
  10. 【LeetCode】36 - Valid Sudoku
  11. [JS]九种网页弹窗代码
  12. tiny4412学习笔记-将uboot、zImage、文件系统烧到emmc中
  13. Swift学习之UI开发初探
  14. Usaco 1.3.2 修理牛棚(Barn Repair)
  15. 设计模式的征途—14.职责链(Chain of Responsibility)模式
  16. 如何从Eclipse 迁移到Android Studio 且保持Eclipse项目结构
  17. html学习中
  18. web前端关于html转义符的常用js函数
  19. Linux第三课——目录操作
  20. python描述符详解

热门文章

  1. python基础一 day2 数据类型
  2. ORA-03113: end-of-file on & ORA-07445
  3. Java ArrayList中去掉相同的元素并保留相同元素中的最后一个
  4. 使用html2canvas实现网页截图,并嵌入到PDF
  5. ç7—UIViewController
  6. Ubuntu下压缩与解压各种文件的命令
  7. poj1681 Painter's Problem
  8. URAL1966 Cipher Message 3
  9. nginx 配置虚拟主机访问PHP文件 502错误的解决方法
  10. Canvas标签