Debugging C# assembly launched by embedded mono runtime?

前端 未结 2 1835
孤街浪徒
孤街浪徒 2021-02-10 14:14

I am talking about a small game engine using C# for game programming. So, I have a C++ app embedding mono runtime (I call it \'launcher\'). And I have an assembly written in C#

相关标签:
2条回答
  • 2021-02-10 14:45

    I recommend using the Mono Soft Debugger. It's been included in the Mono runtime since Mono 2.6, and is more reliable than the old hard debugger, and also much more portable.

    The Mono soft debugger can be started by passing options using the --debugger-agent commandline argument to the Mono runtime. This can be done from an embedding host by constructing a fake set of commandline arguments and passing it to mono_jit_parse_options. For example, the Moonlight browser plugin uses the debugger agent values from MOON_SOFT_DEBUG environment variable if it is set.

    Typically debugger options are something like

    --debugger-agent="transport=dt_socket,address=$ADDRESS:$PORT"
    

    which will cause the app to try to connect to debugger listening on the given address, and pause until it establishes a connection. Note that the connection is established over TCP/IP, which means remote debugging is very easy to set up, and even on the local machine you would use localhost. Additional options are documented on Mono's man page.

    The other piece you need is the debugger GUI/controller, to listen for the connection from your app, and handle stepping/visualizing, etc. I would suggest using MonoDevelop. There's a library for the debugger wire protocol called Mono.Debugger.Soft.dll, but it's fairly low-level, and although Mono Tools for Visual Studio supports connecting to the soft debugger, it's not yet extensible in a way that would allow debugging Mono embedding hosts.

    Using MonoDevelop to accept debugger connections from embedding hosts currently requires creating an addin, but this is fairly straightforward. Take a look at the Moonlight debugger addin for an example. For simple use cases I would suggest that you don't define a whole new project type but just create a debug handler that handles existing DotNetExecutionCommand projects, so you can run->run with...->your custom debugger.

    The monodevelop-list mailing list is a good resource if you have more questions.

    0 讨论(0)
  • 2021-02-10 15:05

    Make use of network debugging.

    You could use the Soft Debugger to debug the Mono parts, and then use remote debugging for the C++ parts.

    0 讨论(0)
提交回复
热议问题