microsoft / vscode-mono-debug

A simple VS Code debug adapter for mono
Other
163 stars 174 forks source link

How to debug embedded mono? #73

Closed SquareRoundCurly closed 3 years ago

SquareRoundCurly commented 3 years ago

I have a barebones C++ project, in which I have embedded Mono according to the documentation.

I have then created a simple .cs file with a class with a couple of test functions that print some strings. I compile this file with the this command:

mcs SomeClass.cs -debug -target:library

As expected, I get a C# SomeClass.dll and a debug symbol file SomeClass.dll.mbd.

I can load the dll assembly from C++ (from the embedded Mono runtime) and call the functions inside the dll. I can step through the native code (C++) in VS Code. However, I can't figure it out how to step through/debug the managed C# code.

Here's the meat of my launch.json file:

{
            "name": "Launch",
            "type": "lldb",
            "request": "launch",
            "program": "path/to/EmbeddedMono.exe",
            "args": [],
            "cwd": "${workspaceFolder}",
            "console": "externalTerminal"
},
{
            "name": "Attach to Mono",
            "request": "attach",
            "type": "mono",
            "address": "localhost",
            "port": 55555
 }

I also pass some command line options to the embedded Mono runtime:

    static const char* options[] = {
          "--soft-breakpoints",
          "--debugger-agent=transport=dt_socket,address=127.0.0.1:55555"
        };
    mono_jit_parse_options(sizeof(options)/sizeof(char*), (char**)options);
    mono_debug_init(MONO_DEBUG_FORMAT_MONO);

I imagined that I could launch the program, step through native code, then attach to Mono and step through managed C# code. However, the embedded Mono runtime always terminates the native program with this error message:

debugger-agent: Unable to connect to 127.0.0.1:55555

I am at a total loss. I can debug pure C# code, without any embedded Mono runtime, I can debug native code. However, I can not debug any C# code that is executed in a embedded Mono runtime.

Ideally I would like to step through both C++ & C# seamlessly, just like how Visual Studio can. However, I would be quite content if I could at least be able to debug either native code or managed C# code, one at a time. Unfortunately the latter doesn't seem to be working.

abhiss commented 3 years ago

Was the issue closed because you found a solution?