Debug F# with sdb!

6728 단어 debugF#
This article is F# Advent Calendar2017 7th daysee : F# Advent Calendar2017

Summary



I just try to debug F# code with sdb!

Like this





What is mono/sdb?



A command line client for the Mono soft debugger.
mono/sdb

환경



$ sw_vers 
ProductName:    Mac OS X
ProductVersion: 10.13.1
BuildVersion:   17B1003

$ uname -a
Darwin callmekoheis-MacBook-Air.local
17.2.0 Darwin Kernel
Version 17.2.0:
Fri Sep 29 18:27:05 PDT 2017;
root:xnu-4570.20.62~3/RELEASE_X86_64 x86_64

$ mono --version
Mono JIT compiler version 5.0.1.1 (2017-02/5077205 Sun Sep 17 18:29:46 BST 2017)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           normal
    SIGSEGV:       altstack
    Notification:  kqueue
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug 
    LLVM:          supported, not enabled.
    GC:            sgen (concurrent by default)

Prepare



install mono/sdb
$ git clone https://github.com/mono/sdb

$ cd sdb

$ git submodule update --init --recursive

$ make

check

$ sdb --version
Mono soft debugger (sdb) 1.5.6503.20649

$ which sdb
/usr/local/bin/sdb

설정

$ which mono
/usr/local/bin/mono

// set location of mono
$ sdb
(sdb) cfg s RuntimePrefix /usr/local/ ( was /usr )

Debug



// write code
$ vim sample.fsx 

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

// compile
$ fsharpc -g --optimize- sample.fsx 

// launch sdb
$ sdb
Welcome to the Mono soft debugger (sdb 1.5.6548.37600)
Type 'help' for a list of commands or 'quit' to exit

// set break point
(sdb) bp add func ABC.DEF.foo
Breakpoint '0' added for method 'ABC.DEF.foo'

// run 
(sdb) r sample.exe
Inferior process '8743' ('sample.exe') started
Hit method breakpoint on 'ABC.DEF.foo'
#0 [0x00000000] ABC.DEF.foo at /Users/callmekohei/tmp/xxx/sample.fsx:8
        stdout.WriteLine(str)

// look source code
(sdb) src
       1:    namespace ABC
       2:    
       3:    module DEF =
       4:        let bar() =
       5:            stdout.WriteLine("abc")
       6:    
       7:        let foo (str:string) =
       8:            stdout.WriteLine(str)  // <--- color green!
       9:            bar()
      10:    
      11:        [<EntryPointAttribute>]
      12:        let main _ =
      13:            let s = "Foo!"
      14:            foo s
      15:            stdout.WriteLine("callmekohei")
      16:            0

// continue
(sdb) c
Inferior process '8743' ('sample.exe') resumed
Foo!
abc
callmekohei
Inferior process '8743' ('sample.exe') exited with code '0'

// quiet
(sdb) q
Bye

포인트



compile option --optimize-

$ fsharpc -g --optimize- sample.fsx 

좋은 웹페이지 즐겨찾기