• breakpoints
    • stepping
    • inspection of type information
    • variable inspection

    To produce binaries with the Kotlin/Native compiler it’s sufficient to use the option on the command line.
    Example:

    lldb

    • by name
    1. (lldb) b -n kfun:main(kotlin.Array<kotlin.String>)
    2. Breakpoint 4: where = terminator.kexe`kfun:main(kotlin.Array<kotlin.String>) + 4 at hello.kt:2, address = 0x00000001000012e4

    -n is optional, this flag is applied by default

    • by location (filename, line number)
    1. (lldb) b -f hello.kt -l 1
    2. Breakpoint 1: where = terminator.kexe`kfun:main(kotlin.Array<kotlin.String>) + 4 at hello.kt:2, address = 0x00000001000012e4
    • by address
    • by regex, you might find it useful for debugging generated artifacts, like lambda etc. (where used # symbol in name).
    1. 3: regex = 'main\(', locations = 1
    2. 3.1: where = terminator.kexe`kfun:main(kotlin.Array<kotlin.String>) + 4 at hello.kt:2, address = terminator.kexe[0x00000001000012e4], unresolved, hit count = 0

    gdb

    • by regex
    1. Breakpoint 1 at 0x1000109b4
    2. struct ktype:kotlin.Unit &kfun:main(kotlin.Array<kotlin.String>);
    • by name unusable, because : is a separator for the breakpoint by location
    • by location
    1. (gdb) b hello.kt:1
    2. Breakpoint 2 at 0x100001704: file /Users/minamoto/ws/.git-trees/hello.kt, line 1.
    • by address
    1. (gdb) b *0x100001704
    2. Note: breakpoint 2 also set at pc 0x100001704.
    3. Breakpoint 3 at 0x100001704: file /Users/minamoto/ws/.git-trees/hello.kt, line 2.

    Variable inspections for var variables works out of the box for primitive types. For non-primitive types there are custom pretty printers for lldb in :

    1. 0:b-debugger-fixes:minamoto@unit-703(0)# cat ../debugger-plugin/1.kt | nl -p
    2. 1 fun foo(a:String, b:Int) = a + b
    3. 2 fun one() = 1
    4. 3 fun main(arg:Array<String>) {
    5. 4 var a_variable = foo("(a_variable) one is ", 1)
    6. 5 var b_variable = foo("(b_variable) two is ", 2)
    7. 6 var c_variable = foo("(c_variable) two is ", 3)
    8. 7 var d_variable = foo("(d_variable) two is ", 4)
    9. 8 println(a_variable)
    10. 9 println(b_variable)
    11. 10 println(c_variable)
    12. 11 println(d_variable)
    13. 0:b-debugger-fixes:minamoto@unit-703(0)# lldb ./program.kexe -o 'b -f 1.kt -l 9' -o r
    14. (lldb) target create "./program.kexe"
    15. Current executable set to './program.kexe' (x86_64).
    16. Breakpoint 1: where = program.kexe`kfun:main(kotlin.Array<kotlin.String>) + 463 at 1.kt:9, address = 0x0000000100000dbf
    17. (lldb) r
    18. (a_variable) one is 1
    19. Process 80496 stopped
    20. * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    21. frame #0: 0x0000000100000dbf program.kexe`kfun:main(kotlin.Array<kotlin.String>) at 1.kt:9
    22. 6 var c_variable = foo("(c_variable) two is ", 3)
    23. 7 var d_variable = foo("(d_variable) two is ", 4)
    24. 8 println(a_variable)
    25. -> 9 println(b_variable)
    26. 10 println(c_variable)
    27. 11 println(d_variable)
    28. 12 }
    29. Process 80496 launched: './program.kexe' (x86_64)
    30. (lldb) expression -- Konan_DebugPrint(a_variable)
    31. (a_variable) one is 1(KInt) $0 = 0

    Note: Supporting the DWARF 2 specification means that the debugger tool recognizes Kotlin as C89, because before the DWARF 5 specification, there is no identifier for the Kotlin language type in specification.