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 什么是 ...
随机推荐
- VR技术在数据中心3D机房中的应用(上)
VR技术在数据中心3D机房中的应用(上) 前两天跟朋友A吃饭,吃着吃着就说到了VR.近几年来,VR技术越来越火,感觉能跟VR沾点边的都特别高大上,朋友A也是,一提到VR,就怎么都掩盖不住他发自肺腑 ...
- maven构建springmvc项目
1.Eclipse中 NEW ->OTHER->Maven->maven project 2.选择项目路径 3.选择项目类型->next->输入groupid和artif ...
- 《C++专项练习》 — (2)
序 C++基础专项练习二,,,水平依然不到家! 错题分析与总结 1 . 有如下模板定义: template <class T> T fun(T x,T y){ return x*x+y*y ...
- Spring入门(1)——搭建简单的环境
步骤: 1.下载spring框架开发包. 2.创建web项目并引入开发包. 3.创建java接口和相应的实现类. 4.编写spring的配置文件. 5.编写 测试类,并进行测试. 1.下载spring ...
- 解决Can’t finish GitHub sharing process Successfully created project ‘GitHubDemo’ on GitHub
Can't finish GitHub sharing process Successfully created project 'KeyWordsFrameWork' on GitHu ...
- Flask 架构 --xunfeng实例研究
文件结构 │ Config.py # 配置文件 │ README.md # 说明文档 │ Run.bat # Windows启动服务 │ Run.py # webserver │ Run.sh # L ...
- BZOJ:[JSOI2009]游戏Game【二分图匹配乱搞】
题目大意:n*m的棋盘,其中有些区域是禁区,两个人在棋盘上进行博弈,后手选择棋子的初始位置,然后先后手轮流将棋子往上下左右移动,走过的区域不能再走,问能否有一个位置使得后手必胜 Input 输入数据首 ...
- POJ 2777 Count Color【线段树】
题目大意:要求完成以下两个操作:1.将一个区间刷上一种颜色2.询问一段区间上有多少种颜色 思路:这两个操作线段树都可以很迅速的完成,具体做法是:线段树上每个节点存这个线段上的颜色数量,由于颜色数很少, ...
- C++中,什么叫类,结构,联合?
在C++中 class 和 struct 本质上一样 可以互用class的成员默认是private的,struct的成员默认是public的但一般习惯把成员变量隐藏的用class申明, 成员变量可以公 ...
- Ubuntu启用IPv6上google的方法
Pv6就是我们通常所说的互联网协议,是TCP/IP的核心协议,那么在Linux下如何开启IPv6呢?下面以Ubuntu为例,给大家介绍下Ubuntu启用IPv6的方法. 方法: $sudo apt-g ...