快乐虾

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. 获取指定点的RGB值

    实现效果: 知识运用: Color对象的RGB属性 实现代码: private void button1_Click(object sender, EventArgs e) { OpenFileDia ...

  2. 1.1 Qt入门

    学习Qt的前提是学好C++. 我刚入门Qt,打算趁着暑假2个月时间来学习<C++ GUI Qt 4>这本书. 现在有Qt4和Qt5,似乎很多公司都还是在使用Qt4,所以我也就选择了学习Qt ...

  3. Vickers Vane Pump - How To Choose Vane Pump Parameter Specifications?

    1 rated pressure selection. The rated pressure of the vane pump products is 7MPa, 1OMPa, 16MPa, 2lMP ...

  4. Springboot 图标更换

    1.将自己的logo图片转为.ico格式的,命名必须为[favicon.ico] 2.将该图片直接放在src/main/resourecs目录下 3.重启项目,刷新一下浏览器缓存,就会发现图标更换了

  5. ios之coredata

    Core Data数据持久化是对SQLite的一个升级,它是ios集成的,在说Core Data之前,我们先说说在CoreData中使用的几个类. (1)NSManagedObjectModel(被管 ...

  6. C指针类型转换问题

    先看下面的代码: #include<stdio.h> int main () { int a; char *x; x = (char *) &a; a = 512; x[0] = ...

  7. spoj-TSUM Triple Sums

    题目描述 题解: 很吊的容斥+$FFT$,但是并不难. 首先,由于有重复,我们要容斥. 怎么办? 记录三个多项式, 只取一个:$w1$; 相同物体拿两个:$w2$; 相同物体拿三个:$w3$; 然后答 ...

  8. [LUOGU] P2886 [USACO07NOV]牛继电器Cow Relays

    https://www.luogu.org/problemnew/show/P2886 给定无向连通图,求经过k条边,s到t的最短路 Floyd形式的矩阵乘法,同样满足结合律,所以可以进行快速幂. 离 ...

  9. mysql查询表中最小可用id值

    今天在看实验室的项目时,碰到的一个问题,.先把sql语句扔出来 // 这条语句在id没有1时,不能得到正确的查询结果. select min(id+1) from oslist c where not ...

  10. 7. 配置undo表空间

    7. 配置undo表空间 undo日志可以存储在一个或多个undo表空间中,无需存储在系统表空间中. 要为MySQL实例配置单独的undo表空间,请执行以下步骤 [重要]: 只能在初始化新MySQL实 ...