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 什么是 ...
随机推荐
- json-server && axios
json-server && axios vue2.0项目实战(3)使用axios发送请求 https://www.cnblogs.com/zhouyangla/p/6753673.h ...
- 关于sigleton模式
单例模式的要点有三个:一是某个类只能有一个实例:二是它必须自行创建这个实例:三是它必须自行向整个系统提供这个实例. 从具体实现角度来说,就是以下三点:一是单例模式的类只提供私有的构造函数,二是类定义中 ...
- QT_2
1.默认生成代码的含义(.pro)
- 5. 在Datadir目录外创建单独表空间
5. 在Datadir目录外创建单独表空间 要在MySQL dadadir之外的位置创建单独表空间,请使用该子句: DATA DIRECTORY = '/path' 在目标目录中,MySQL会创建一个 ...
- Go:类型断言
一.基本介绍 类型断言:由于接口是一般类型,不知道具体类型,如果要转成具体类型,就需要使用类型断言. 如果希望将一个空接口类型重新转换成对应的类型,那么需要使用类型断言,能转换成功是因为这个空接口原先 ...
- INFO main org.springframework.context.support.AbstractApplicationContext
原因, spring-framework-5.0.2.RELEASE 需要使用 jdk8.
- server中intersect的用法
intersect 就像数学中的交集一样, select nam from tb_table1 intersect select name from tb_table2 查询的是两个数据集的交集 ...
- 【数学】codeforces C. Maximal GCD
http://codeforces.com/contest/803/problem/C [题意] 给定两个数n,k(1 ≤ n, k ≤ 10^10) 要你输出k个数,满足以下条件: ①这k个数之和等 ...
- Python的另一种开发环境--Anaconda中的Spyder
本文作者LucyGill,转载请注明出处(虽然我觉得并不会有人转载). 刚开始学Python的时候,我用的是其自带的idle(安装Python后,在开始菜单里可以找到),后来发现在eclipse中设置 ...
- 普通平衡树(bzoj 3224)
Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除一个)3. 查询x数的排名(若有多个相同的数 ...