【发布时间】:2014-02-21 17:41:09
【问题描述】:
我有以下要调试的 C# 程序 (test.cs):
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
Console.WriteLine( "Hello, World!" );
List<int> list = new List<int>();
list.Add(123);
list.Add(234);
list.Add(345);
list.Add(456);
int number = 4;
++number;
Console.WriteLine(" number " + number); // <--- L:16 I want to set a breakpoint here :)
Console.WriteLine("Number of elements" + list.Count);
foreach (Object obj in list)
{
Console.WriteLine(" " + obj);
}
Console.WriteLine("Bye");
}
}
下面是使用 lldb 和 mono 的调试会话(我在 OSX 中)。我可以启动会话并运行程序,但是我无法设置任何断点。我猜当使用单声道作为可执行文件时,情况会有所不同。我怎样才能做到这一点?
$ mcs -debug test.cs
$ lldb
(lldb) target create mono
Current executable set to 'mono' (i386).
(lldb) b test.cs:16
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
(lldb) run --debug test.exe
Process 15191 launched: '/usr/bin/mono' (i386)
Hello, World!
number 5
Number of elements4
123
234
345
456
Bye
Process 15191 exited with status = 0 (0x00000000)
(lldb)
我已经尝试将 GBD 设置为 this old guide suggests,但更糟糕的是,显然存在 something broken in mono in OSX,除非使用软调试器,否则无法调试(这正是我想要避免的。MonoDevelop 调试器真的真的不稳定/不可靠/慢)。这是what I have tried with GBD。一点运气都没有。
感谢您的帮助。
【问题讨论】:
-
这似乎会受到 Mono 的执行环境工作方式的严重影响。您的进程是否作为单声道内的 dylib 加载? mono 是否对 .net 字节码进行 JIT 编译?假设是前者,你的 test.exe 是否有 DWARF 格式的调试信息?
-
我认为是后者。 JIT 是默认设置。当我做
mcs -debug test.cs时,除了 test.exe 还创建了 test.exe.mdb。这意味着在调试会话中使用。我想知道如何在 lldb 中使用这样的文件 -
这取决于 MDB 格式是什么。如果它是专有的 Microsoft 格式,则 LLDB 不太可能有解码器。如果 OTOH,它是一种开源格式,有足够动力的人可以为它编写解码器。
-
但这仍然不能给你完整的体验。例如,LLDB 不了解 C# 作为一种编写表达式的语言,所以你会发现自己在这方面受到严重限制。此外,LLDB 不理解 .net 类型 - 您必须将来自 MDB 调试信息的类型表示为 Clang 类型,就目前情况而言