我已经在我的应用程序中嵌入了mono。该应用程序是支持插件的控制台应用程序。插件是.NET程序集。所有这些都运行得很好,但我想要调试它们。要在我的C代码中启用调试,我需要:
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();
...上面的代码初始化了mono运行时,这是我为启用调试所做的全部工作。为了能够在MonoDevelop端进行调试,我创建了一个插件并实现了必要的类。启动调试的那个是从RemoteSoftDebuggerSession派生的。下面是我的OnRun方法:
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);
}问题是,当我开始调试myapp时,会打印"debugger-agent: DWP握手失败“,调试结束。我所能弄清楚的是,发送到myapp.exe的恰好是13个字节,接收的是13个字节(“DWP-握手”中的字符数)。
有人知道这个问题吗?
发布于 2010-09-16 18:36:08
问题解决了。问题出在下面这几行中的VirtualMachineManager.ListenInternal(2)方法中:
dbg_sock.Disconnect (false);
dbg_sock.Close ();由于某些原因,这是未处理的异常(在断开连接时)。try-catch解决了这个问题。现在所有的工作都很棒!
https://stackoverflow.com/questions/3701211
复制相似问题