快乐虾

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的更多相关文章

  1. Vs2012在Linux开发中的应用(1):开发环境

    在Linux的开发过程中使用过多个IDE.code::blocks.eclipse.source insight.还有嵌入式厂商提供的各种IDE.如VisualDsp等,感觉总是不如vs强大好用.尽管 ...

  2. Vs2012在Linux开发中的应用(5):项目属性的定义

    VS的项目属性表实际上是由一系列的XML文件定义的,都存放在C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\2052文件夹下.我们全然能够 ...

  3. 4、linux开发中常用指令

    1.cat /proc/device 可以查看各个全部字符设备和块设备,在register_chrdev中设置的名字在打印出来的信息中可以看到:2.top 可以看各个应用程序占用CPU量及PID等信息 ...

  4. Vs2012在Linux开发中的应用(6):改写Makefile项目的Build过程

    MSBUILD的编译过程实际上是依据一系列的targets文件定义的.当我们在IDE运行生成.批生成.清理命令的时候.VS会查找这些命令相应的Task并运行它,以下我们逐个分析这个过程. 当运行生成操 ...

  5. linux开发中常用的命令及技巧(连载)

    1.在内核或uboot目录下搜索相关内容/文件名时:grep "USB" * -nR find -name "*USB*" 2.查看系统中设备 cat  /pr ...

  6. 【Debug】Web开发中,Tomcat正常启动,访问欢迎页404,怎么办?

    访问页面出现404是一个会经常遇到的问题.每次开发Web项目时总要掉这个坑里几次,而且还不长记性.今天来总结一下,开发时遇到这个问题的解决思路. 1. 查看访问地址是否正确,有无拼写错误. 越是低级的 ...

  7. Linux CentOS中使用SQL*Plus启动和关闭数据库

    启动和关闭数据库的常用工具有三个 一.SQL*Plus 在SQL*Plus环境中,用户以SYSDBA身份连接到Oracle后,可以通过命令行方式启动或关闭数据库. 二.OEM(企业管理器) 利用OEM ...

  8. Windows10系统的Linux子系统中安装MySQL数据库心得

    后端开发童鞋们, 自己开发机用的是Windows系统电脑(台式机或笔记本), 而开发的程序和使用的数据库等要运行在Linux服务器上, 这种情况有木有? 提前声明: 本文并不讨论操作系统的比较, 以及 ...

  9. 用VS2013+VELT进行Linux开发

    快乐虾 http://blog.csdn.net/lights_joy/(QQ群:Visual EmbedLinux Tools 375515651) 欢迎转载,但请保留作者信息 1.1.1  什么是 ...

随机推荐

  1. https://www.runoob.com/python/python-variable-types.html

    https://www.runoob.com/python/python-variable-types.html

  2. CAD交互绘制带周长面积的矩形框(网页版)

    主要用到函数说明: _DMxDrawX::DrawLine 绘制一个直线.详细说明如下: 参数 说明 DOUBLE dX1 直线的开始点x坐标 DOUBLE dY1 直线的开始点y坐标 DOUBLE ...

  3. 安卓获取数据demo出现的问题

    时间戳是long型的数据,但其他数据都是float型,但AsyncTask要求是统一数据类型.这样我就不能把时间戳放进AsyncTask里面进行处理,我就在doInBackground中获取时间戳然后 ...

  4. JavaSE-29 Java8的Lambda表达式

    概念说明 Lambda表达式是Java8提供的新特性,支持将代码块作为方法的参数. Lambda表达式支持使用简洁的代码创建只有一个方法的接口(函数式接口). 只包含一个方法的接口也称为函数式接口. ...

  5. Java 编程下 Eclipse/myeclipse 如何设置单行代码显示的最大宽度

    http://www.cnblogs.com/sunzn/archive/2013/03/30/2990191.html 或 http://zhidao.baidu.com/link?url=67uy ...

  6. List<T>排序

    List<Student> studentList = new List<Student>(); Student s = new Student(); s.Name = &qu ...

  7. vs编译应用程序不依赖运行vs环境

    控制台应用程序不依赖VS运行环境就可以运行的设置: 1,使用release模式编译 2,项目属性中,“C/C++”,“代码生成”中的运行库改为“多线程(/MT)” 3,项目属性中,“链接器”,“系统” ...

  8. POI导出,开发中经常会遇到数据导出这样的问题,下面是我在开发中采用的解决方法,大家可以参考,具体的实现害的结合你自身的业务逻辑

    @RequestMapping(value = "/drawPayFailExport",method = RequestMethod.GET,produces = "a ...

  9. (2) LVS负载均衡:VS_TUN和VS_DR的arp问题

    1. ARP协议简介 ARP(Address Resolution Protocol)协议称为地址解析协议,用于将主机IP地址解析为主机的MAC地址,即IP-->MAC之间一一映射. RARP协 ...

  10. MySQL索引与Index Condition Pushdown(二)

    实验 先从一个简单的实验开始直观认识ICP的作用. 安装数据库 首先需要安装一个支持ICP的MariaDB或MySQL数据库.我使用的是MariaDB 5.5.34,如果是使用MySQL则需要5.6版 ...