Vs2013在Linux开发中的应用(19): 启动gdb
快乐虾
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及要调试的应用。
Vs2013在Linux开发中的应用(19): 启动gdb的更多相关文章
- Vs2012在Linux开发中的应用(1):开发环境
在Linux的开发过程中使用过多个IDE.code::blocks.eclipse.source insight.还有嵌入式厂商提供的各种IDE.如VisualDsp等,感觉总是不如vs强大好用.尽管 ...
- Vs2012在Linux开发中的应用(5):项目属性的定义
VS的项目属性表实际上是由一系列的XML文件定义的,都存放在C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\2052文件夹下.我们全然能够 ...
- 4、linux开发中常用指令
1.cat /proc/device 可以查看各个全部字符设备和块设备,在register_chrdev中设置的名字在打印出来的信息中可以看到:2.top 可以看各个应用程序占用CPU量及PID等信息 ...
- Vs2012在Linux开发中的应用(6):改写Makefile项目的Build过程
MSBUILD的编译过程实际上是依据一系列的targets文件定义的.当我们在IDE运行生成.批生成.清理命令的时候.VS会查找这些命令相应的Task并运行它,以下我们逐个分析这个过程. 当运行生成操 ...
- linux开发中常用的命令及技巧(连载)
1.在内核或uboot目录下搜索相关内容/文件名时:grep "USB" * -nR find -name "*USB*" 2.查看系统中设备 cat /pr ...
- 【Debug】Web开发中,Tomcat正常启动,访问欢迎页404,怎么办?
访问页面出现404是一个会经常遇到的问题.每次开发Web项目时总要掉这个坑里几次,而且还不长记性.今天来总结一下,开发时遇到这个问题的解决思路. 1. 查看访问地址是否正确,有无拼写错误. 越是低级的 ...
- Linux CentOS中使用SQL*Plus启动和关闭数据库
启动和关闭数据库的常用工具有三个 一.SQL*Plus 在SQL*Plus环境中,用户以SYSDBA身份连接到Oracle后,可以通过命令行方式启动或关闭数据库. 二.OEM(企业管理器) 利用OEM ...
- Windows10系统的Linux子系统中安装MySQL数据库心得
后端开发童鞋们, 自己开发机用的是Windows系统电脑(台式机或笔记本), 而开发的程序和使用的数据库等要运行在Linux服务器上, 这种情况有木有? 提前声明: 本文并不讨论操作系统的比较, 以及 ...
- 用VS2013+VELT进行Linux开发
快乐虾 http://blog.csdn.net/lights_joy/(QQ群:Visual EmbedLinux Tools 375515651) 欢迎转载,但请保留作者信息 1.1.1 什么是 ...
随机推荐
- 20道必须掌握的C++面试题
20道必须掌握的C++面试题 在面试C++方面的工作时,经常会遇到各种面试题,这对应聘人员的知识掌握能力要求较高.本文将为大家带来的就是20道必须掌握的C++面试题,不要错过哦! 问1:请用简单的语言 ...
- GetForgroundWindow函数的不确定性——BUG笔记
HWND GetForgoundWindows() 获取当前前置窗口在windows 7和windows 10下虚拟桌面切换后表现不同. 所以强烈不建议使用此函数!
- Hibernate5.x版本HQL限定查询 Legacy-style query parameters (`?`) are no longer supported
在此版本的限定查询和4.0版本的限定查询: 如果查询语句是: String hql = "select u from User u where u.gender = ?"; 会出现 ...
- 并发3-Volatile
Volatile关键字实现原理 1.认识volatile关键字 程序举例 用一个线程读数据,一个线程改数据 存在数据的不一致性 2.机器硬件CPU与JMM (1)CPU Cache模 (2)CPU缓存 ...
- python获取指定文件夹下的文件路径
#!/usr/bin/python# -*- coding: UTF-8 -*-# @date: 2018/1/6 23:08# @name: tmp2# @author:vickey-wu impo ...
- JavaScript中通过原型添加方法,解决数据共享问题,节省内存空间
涉及知识点:(1)原型的引入(2)构造函数.原型对象和实例对象之间的关系(3)__proto__和prototype的理解 直接举例:在自定义构造函数创建对象时,因为创建的对象使用的不是同一个方法,所 ...
- HDU-3746-Cyclic Nacklace(KMP,循环节)
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 10. GLOBAL_STATUS 与 SESSION_STATUS
10. GLOBAL_STATUS 与 SESSION_STATUS 注意 从MySQL 5.7.6开始,show_compatibility_56系统变量的值会影响此处描述的表中的可用信息. 有关详 ...
- DB2数据库在线备份还原
DB2在线备份设置方法: 第一步:开启归档日志 db2 update db cfg for TEST_DB using logretain on 第二步:重启数据库 第三步:进行一次离线备份 db2 ...
- 条款16:成对使用new和delete时要采取相同形式
NOTE: 1.如果你在new表达式中使用[],必须在相应的delete表达式中也使用[].如果你在new表达式中不使用[],一定不要在相应的delete表达式中使用[].