mono可以让.net程序运行在linux平台上。于是.net程序员有了mono之后就转身跨平台了。但开放环境往往还是在windows下,于是有了这样的需求,是否可以用windows下的源码来实机调试linux下的程序呢?

如今Xamarin已经被广泛地使用在移动平台的应用开发上,当然也能够支持实机调试。

大概是内部维护一个TCP连接,传递调用堆栈信息。

查阅了一些文档和stackoverflow搜索结果之后看到下面这样的描述:

Remote debugging is actually really easy with the Mono soft debugger. The IDE sends commands over TCP/IP to the Mono Soft Debugger agent inside the runtime. Depending how you launch the debuggee, you can either have it connect to the IDE over TCP, or have it open a port and wait for the IDE to connect to it.

For simple prototyping purposes, you can just set the MONODEVELOP_SDB_TEST env var, and a new "Run->Run With->Custom Soft Debugger" command will show up in Xamarin Studio / MonoDevelop, and you can specify an arbitrary IP and port or connect or or listen on, and optionally a command to run. Then you just have to start the debuggee with the correct --debugger-agentarguments (see the Mono manpage for details), start the connection, and start debugging.

For a production workflow, you'd typically create a MonoDevelop addin with a debugger engine and session subclassing the soft debugger classes, and overriding how to launch the app and set up the connection parameters. You'd typically have a custom project type too subclassing the DotNetProject, so you could override how the project was built and executed, and so that the new debugger engine could be the primary debugger for projects of that type. You'd get all the default .NET/Mono project and debugger functionality "for free".

恩,就和手机调试一样,linux上运行mono,远程使用XamarinStudio调试也非常方便。

我的测试代码如下

public static void Main (string[] args)

{
Console.WriteLine ("Hello World!");
while (true) {
string input =Console.ReadLine ();
Console.WriteLine (input);//此处可做断点
if (input == "q") {
break;
}
}
Console.WriteLine ("byebye");
Console.ReadKey ();
}

首先,在mono运行的时候带上参数

  例如:mono --debug --debugger-agent=transport=dt_socket,address=127.0.0.1:8088,server=y,suspend=y MyApp.exe

因为我设置了server参数为y,表示这里是socket的监听方,然后suspend=y。之后MyApp.exe并没开始运行,而是等待连接。

然后,在另一端,比如windows下,安装monodevelop(XamarinStudio), 配置环境变量

  MONODEVELOP_SDB_TEST=1

启动monodevelop,打开项目,设置默认F5(Run)为"Run->Run With->Custom Soft Debugger"

会打开一个对话框,在对话框中输入需要连接的mono运行机器的ip和端口,因为是linux端监听,所以选择connect(当然如果mono运行时的参数server是n,那就是相反啦)。

连接成功,linux界面输出hello world,然后随意输入字符串,回车,windows下获得断点,检查变量值调用堆栈ok数据获取成功。

远程调试测试成功。

怎么样,是不是觉得很像使用Unity的感觉呢?

是的,看这个:相关的情报

另外,如果想要mono运行MyApp.exe不等待连接,设置suspend为n即可,程序将先运行而不阻塞等待连接。

但是,我仍然不知道连接之后如何断开调试而不结束进程,希望知道的朋友能够给予帮助。

注意,还有一个--debug的参数非常重要,与之配套的是exe(dll)程序集配套生成的.mdb文件。mono的调试信息中包括源代码的路径、对应的代码在几行等等信息都在里面,远程调试的时候都需要这些信息。

不然即使连接建立,mono也不知道如何将数据和本地代码联系起来。所以源码也不要轻易地移动目录哦。

.mdb文件可以用monodevelop生成,也可以到mono安装目录下的bin文件夹中找到mdb生成工具生成。

mono的远程调试的更多相关文章

  1. 在windows通过visual studio远程调试linux mono程序

    本文参考文章 https://github.com/techl/MonoRemoteDebugger 1.通过连接https://github.com/techl/MonoRemoteDebugger ...

  2. 微信公众号开发之VS远程调试

    目录 (一)微信公众号开发之VS远程调试 (二)微信公众号开发之基础梳理 (三)微信公众号开发之自动消息回复和自定义菜单 前言 微信公众平台消息接口的工作原理大概可以这样理解:从用户端到公众号端一个流 ...

  3. tomcat开发远程调试端口以及利用eclipse进行远程调试

    一.tomcat开发远程调试端口 方法1 WIN系统 在catalina.bat里:  SET CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compi ...

  4. Visual Studio 2012远程调试中遇到的问题

    有的时候开发环境没问题的代码在生产环境中会某些开发环境无法重现的问题,或者需要对生产环境代码进行远程调试该怎么办? Vs已经提供给开发者远程调试的工具 下面简单讲讲该怎么用,前期准备:1.本地登录账户 ...

  5. 使用Eclipse进行远程调试

    转自:http://blog.csdn.net/sunyujia/article/details/2614614 今天决定做件有意义的事,写篇图文并茂的blog,为什么要图文并茂?因为很多事可能用语言 ...

  6. 微信公众号开发系列教程一(调试环境部署续:vs远程调试)

    http://www.cnblogs.com/zskbll/p/4080328.html 目录 C#微信公众号开发系列教程一(调试环境部署) C#微信公众号开发系列教程一(调试环境部署续:vs远程调试 ...

  7. tomcat 远程调试

    1.服务端查看cataline.sh 中的描述  cataline jpda start 开启服务端远程调试 远程调试端口JPDA_ADDRESS="8000" 2.本地代码参考  ...

  8. 在Visual Studio上开发Node.js程序(2)——远程调试及发布到Azure

    [题外话] 上次介绍了VS上开发Node.js的插件Node.js Tools for Visual Studio(NTVS),其提供了非常方便的开发和调试功能,当然很多情况下由于平台限制等原因需要在 ...

  9. [教学] Delphi Berlin 10.1 开发 Windows 10 平板 App 远程调试

    Delphi Berlin 10.1 开发 Windows 10 平板 App 远程调试安装步骤: 准备电脑: 一台开发电脑,安装 Delphi 开发环境 一台平板电脑,安装 PAServer,安装方 ...

随机推荐

  1. Android进程间的通信之AIDL

    Android服务被设计用来执行很多操作,比如说,可以执行运行时间长的耗时操作,比较耗时的网络操作,甚至是在一个单独进程中的永不会结束的操作.实现这些操作之一是通过Android接口定义语言(AIDL ...

  2. C#邮箱发送验证码

    public static void SendTo(string mailAddress, string subject, string body)        { //mailAddress 所要 ...

  3. 使用Axis2 插件 报错"An error occurred while completing process -java.lang.reflect.InvocationTargetException"

    参考 http://blog.csdn.net/sunitjy/article/details/6793654

  4. win2008 IIS与tomcat整合

    1.在tomcat目录下新建jk文件夹 2. Copy isapi_redirect.dll到jk,并新建一个isapi_redirect.properties配置文件,内容如下: extension ...

  5. 20151208Study

    20151208-----------------------------------------------------* Her main interest now is raising her ...

  6. c++内存分布

    http://www.oschina.net/translate/cpp-virtual-inheritance 编译器会加入一些代码, 指针的转换操作编译器会自动加偏移

  7. Tp field 字段是可以添加函数的

    $info = M('Order')->alias('a') ->field('count(DISTINCT(a.order_user_id)) as buy_user_num,count ...

  8. [python]自动化将markdown文件转成html文件

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  9. jQuery.ajaxSetup() 函数详解

    该函数用于更改jQuery中AJAX请求的默认设置选项.之后执行的所有AJAX请求,如果对应的选项参数没有设置, 将使用更改后的默认设置. //设置AJAX的全局默认选项$.ajaxSetup( {  ...

  10. VMware Linux Guest 增加磁盘无需重启的方法

    摘要     常常需要需要给VMware Linux Guest增加磁盘适配一些测试场景,而又不想花费时间重启Guest,查找文档,发现一种简单的方法,记录一下操作步骤. 操作步骤 1 编辑Linux ...