سؤال

I have the following C# program (test.cs) which I want to debug:

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");
    }
}

And below is the debug session using lldb and mono (I am in OSX). I can start the session and run the program however I am not able to setup any breakpoint. I guess that when using mono as the executable file things are different. How can I achieve this?

$ 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) 

I've tried with GBD as this old guide suggests but it is worse, apparently there is something broken in mono in OSX that makes it impossible to debug unless the soft debugger is used (which is exactly what I want to avoid. MonoDevelop debugger is really really unstable/unreliable/slow). This is what I have tried with GBD. No luck at all.

And help is appreciated.

هل كانت مفيدة؟

المحلول

Isn't mono the interpreter for your language and test.exe the binary? lldb only knows about mono -- any breakpoints you try to set would be in the mono interpreter. e.g. if you were debugging an issue with mono itself.

This is a unique enough environment that you'll need to do a little analysis to understand what lldb sees. What do you get for

(lldb) image list test.exe

? Of course if you do

(lldb) im li mono

You'll see mono listed -- because that's a binary that lldb knows about. (you can use plain image list aka im li to see all the binaries that lldb knows)

You can ask lldb to list all of the line table entries based on a source filename with a command line

(lldb) target modules dump line-table test.cs

if lldb has any debug information for a test.cs, you'll see a line table. Without a line table, file and line breakpoints (b test.cs:16) won't work.

For what it's worth, I don't think trying to use lldb (or gdb) to debug your C# program will work. You'll probably need to use some facility of the mono runtime itself to set breakpoints and examine program state.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top