mono / sdb

A command line client for the Mono soft debugger.
https://www.mono-project.com
MIT License
116 stars 44 forks source link

Cannot debug fsharp program #55

Closed anquegi closed 5 years ago

anquegi commented 5 years ago

Sorry for writing a question, but I couldn't figure this out, I'm trying to debug a fsharp program or a dotnet core application but I cannot get it working, I read this two issues: https://github.com/mono/sdb/issues/42 and https://github.com/mono/sdb/issues/51

But I always get the same result nothing, this is my setup:

fsharp/learn-fsharp/RpnCalculator via .NET 2.2.300 took 35m 3s
➜ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.5
BuildVersion:   18F132

fsharp/learn-fsharp/RpnCalculator via .NET 2.2.300
➜ sdb --version
Mono soft debugger (sdb) 1.6.7116.16617

fsharp/learn-fsharp/RpnCalculator via .NET 2.2.300
➜ mono --version
Mono JIT compiler version 5.20.1.19 (2018-10/886c4901747 Tue Apr  9 12:37:29 EDT 2019)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:
    SIGSEGV:       altstack
    Notification:  kqueue
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug
    Interpreter:   yes
    LLVM:          yes(600)
    Suspend:       hybrid
    GC:            sgen (concurrent by default)

fsharp/learn-fsharp/RpnCalculator via .NET 2.2.300
➜ which mono
/Library/Frameworks/Mono.framework/Versions/Current/Commands/mono

And then I create a fsharp file like:

functional-programming/fsharp/temp took 11s
➜ cat Program.fs
namespace ABC
module DEF =
    let bar() =
        stdout.WriteLine("abc")

    let foo (str:string) =
        stdout.WriteLine(str)
        bar()

    [<EntryPointAttribute>]
    let main _ =
        let s = "Foo!"
        foo s
        stdout.WriteLine("callmekohei")
        0
functional-programming/fsharp/temp
➜ fsharpc --debug+ Program.fs
Microsoft (R) F# Compiler version 4.1
Copyright (c) Microsoft Corporation. All Rights Reserved.

functional-programming/fsharp/temp took 3s
➜ ls
FSharp.Core.dll Program.exe     Program.exe.mdb Program.fs

and then try to run sdb:

functional-programming/fsharp/temp
➜ fsharpc --debug+ Program.fs
Microsoft (R) F# Compiler version 4.1
Copyright (c) Microsoft Corporation. All Rights Reserved.

functional-programming/fsharp/temp took 3s
➜ ls
FSharp.Core.dll Program.exe     Program.exe.mdb Program.fs

functional-programming/fsharp/temp
➜ sdb
Welcome to the Mono soft debugger (sdb 1.6.7116.16617)
Type 'help' for a list of commands or 'quit' to exit

(sdb) cfg s RuntimePrefix /Library/Frameworks/Mono.framework/Versions/Current/Commands/
'RuntimePrefix' = '/Library/Frameworks/Mono.framework/Versions/Current/Commands/' (was '/Library/Frameworks/Mono.framework/Versions/Current/Commands/')
(sdb) bp add func ABC.DEF.foo
Breakpoint '0' added for method 'ABC.DEF.foo'
(sdb) r Program.exe
Failed to connect to 'Program.exe'
(sdb)

I do not know what to do now, or where to go,

anquegi commented 5 years ago

Sorry for that reading the readme part I read the RuntimePrefix, And is important that this expect a bin folder withi is not in my setup:

/Library/Frameworks/Mono.framework 
➜ ls -l
total 0
lrwxr-xr-x  1 root  admin   55 24 jun 23:49 Commands -> /Library/Frameworks/Mono.framework/Versions/Current/bin
lrwxr-xr-x  1 root  admin   59 24 jun 23:49 Headers -> /Library/Frameworks/Mono.framework/Versions/Current/include
lrwxr-xr-x  1 root  admin   52 24 jun 23:49 Home -> /Library/Frameworks/Mono.framework/Versions/Current/
lrwxr-xr-x  1 root  admin   55 24 jun 23:49 Libraries -> /Library/Frameworks/Mono.framework/Versions/Current/lib
lrwxr-xr-x  1 root  admin   73 24 jun 23:49 Mono -> /Library/Frameworks/Mono.framework/Versions/Current/lib/libmono-2.0.dylib
drwxr-xr-x  4 root  admin  128 24 jun 23:49 Versions

So I change the runtimeprefix to:


(sdb) cfg s RuntimePrefix /Library/Frameworks/Mono.framework/Versions/Current/
'RuntimePrefix' = '/Library/Frameworks/Mono.framework/Versions/Current/' (was '/Library/Frameworks/Mono.framework/Versions/Current/Commands/')

Then finally it worked:

functional-programming/fsharp/temp took 2m 38s ➜ ls FSharp.Core.dll Program.exe Program.exe.mdb Program.fs

functional-programming/fsharp/temp ➜ sdb Welcome to the Mono soft debugger (sdb 1.6.7116.16617) Type 'help' for a list of commands or 'quit' to exit


(sdb) bp add func ABC.DEF.foo
Breakpoint '0' added for method 'ABC.DEF.foo'
(sdb) run Program.exe
Inferior process '34612' ('Program.exe') started
Hit method breakpoint on 'ABC.DEF.foo'
#0 [0x00000000] ABC.DEF.main at /Users/toni/learn/functional-programming/fsharp/temp/Program.fs:16707566 (no source)
    call TextWriter System.Console:get_Out ()
(sdb)
anquegi commented 5 years ago

I will close this issue, but I think that this could help for documenting this setup

callmekohei commented 5 years ago

@anquegi

if you do trace source code , please add --optimize- :-)

https://qiita.com/callmekohei/items/8d3268f6905864de6717