views:

56

answers:

1

Hello!

I've embedded mono in my application. The application is console application that supports plug-ins. Plug-ins are .NET assemblies. All work great, but i want to debug them. To enable debugging in my C-code i have:

mono_set_dirs (ASSEMBLIES_DIR_NAME, ASSEMBLIES_DIR_NAME);
assembly_add_to_bundle(API_ASSEMBLY);

soft_debug = getenv("MYAPP_SOFT_DEBUG");
if (soft_debug != NULL) {
   char *options; 
   options = malloc(17 + strlen(soft_debug));
   sprintf(options, "--debugger-agent=%s", soft_debug); 

   mono_jit_parse_options (1, &options); 
   free (options); 

   mono_debug_init (MONO_DEBUG_FORMAT_MONO);
}

domain = JIT_INIT();

...

The code above inits mono runtime and it's all i've done to enable debugging. To enable debugging at MonoDevelop side i've created an Add-in and implemented necessary classes. The one that starts debugging is derived from RemoteSoftDebuggerSession. Here is my OnRun method:

protected override void OnRun (DebuggerStartInfo startInfo)
{
   var dsi = (MyAppDebuggerStartInfo) startInfo;
   var procStartInfo = new ProcessStartInfo(@"C:\MyApp\myapp.exe") {                
    UseShellExecute = false,
    RedirectStandardOutput = true,
    RedirectStandardError = true,
    WorkingDirectory = @"C:\MyApp",
    Arguments = dsi.AppName
   };

   procStartInfo.EnvironmentVariables.Add("MYAPP_SOFT_DEBUG",                       
      String.Format("transport=dt_socket,address={0}:{1}", 
         dsi.Address, dsi.DebugPort));

   this._myapp = Process.Start(procStartInfo);
   this._runner.EnableRaisingEvents = true;
   base.ConnectOutput(this._runner.StandardOutput, false);
   base.ConnectOutput(this._runner.StandardError, true);

   this._runner.Exited += delegate { this.EndSession(); };
   base.StartListening(dsi);
}

The problem is when i start debugging myapp prints "debugger-agent: DWP handshake failed" and debugging ends. All i could figure out is that exactly 13 bytes are sent to myapp.exe and 13 bytes are recieved (the number of chars in "DWP-Handshake").

Anybady know smth about this issue?

A: 

Problem is solved. The trouble was in VirtualMachineManager.ListenInternal(2) method in this lines:

dbg_sock.Disconnect (false);
dbg_sock.Close ();

For some reason it was unhandled exception (on Disconnect) here. try-catch solved the problem. Now all works great!

ILya