vadimcn / codelldb

A native debugger extension for VSCode based on LLDB
https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb
MIT License
2.42k stars 237 forks source link

Debugger stops after the application is launched #1083

Open wojciech-kulik opened 3 months ago

wojciech-kulik commented 3 months ago

OS: macOS 14.2.1 Neovim: 0.9.5 Compiler: Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4) Debuggee: iOS application

Hello,

I'm using nvim-dap plugin to debug iOS applications using codelldb. In one project, I've got this weird issue that every time I run the app it stops twice after starting. Of course, stopOnEntry = false.

My configuration for nvim-dap:

    {
      name = "iOS App Debugger",
      type = "codelldb",
      request = "attach",
      program = M.get_program_path,
      cwd = "${workspaceFolder}",
      stopOnEntry = false,
      waitFor = true,
    },

and my adapter:

  return {
    type = "server",
    port = "13000",
    executable = {
      command = codelldbPath,
      args = {
        "--port",
        port or "13000",
        "--liblldb",
        lldbPath or "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/LLDB",
      },
    },
  }

here is the disassembly:

; Symbol: __cxa_throw, mangled name=__cxa_throw
; Source: unknown
1802A9818: F8 5F BC A9                stp    x24, x23, [sp, #-0x40]!
1802A981C: F6 57 01 A9                stp    x22, x21, [sp, #0x10]
1802A9820: F4 4F 02 A9                stp    x20, x19, [sp, #0x20]
1802A9824: FD 7B 03 A9                stp    x29, x30, [sp, #0x30]
1802A9828: FD C3 00 91                add    x29, sp, #0x30
1802A982C: F3 03 02 AA                mov    x19, x2
1802A9830: F4 03 01 AA                mov    x20, x1
1802A9834: F5 03 00 AA                mov    x21, x0
1802A9838: 8B F4 FF 97                bl     0x1802a6a64  ; __cxa_get_globals
1802A983C: F6 03 00 AA                mov    x22, x0
1802A9840: E7 F4 FF 97                bl     0x1802a6bdc  ; std::get_unexpected()
1802A9844: A0 02 1A F8                stur   x0, [x21, #-0x60]
1802A9848: 03 F5 FF 97                bl     0x1802a6c54  ; std::get_terminate()
1802A984C: 08 60 85 D2                mov    x8, #0x2b00
1802A9850: 68 65 A8 F2                movk   x8, #0x432b, lsl #16
1802A9854: E8 C8 C9 F2                movk   x8, #0x4e47, lsl #32
1802A9858: 88 69 E8 F2                movk   x8, #0x434c, lsl #48
1802A985C: A8 0E 1E F8                str    x8, [x21, #-0x20]!
1802A9860: B7 82 01 D1                sub    x23, x21, #0x60
1802A9864: A0 82 1C F8                stur   x0, [x21, #-0x38]
1802A9868: B4 4E 3B A9                stp    x20, x19, [x21, #-0x50]
1802A986C: 28 00 80 52                mov    w8, #0x1
1802A9870: A8 82 1A F8                stur   x8, [x21, #-0x58]
1802A9874: C8 0A 40 B9                ldr    w8, [x22, #0x8]
1802A9878: 08 05 00 11                add    w8, w8, #0x1
1802A987C: C8 0A 00 B9                str    w8, [x22, #0x8]
1802A9880: 08 00 00 90                adrp   x8, 0
1802A9884: 08 71 22 91                add    x8, x8, #0x89c  ; __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*)
1802A9888: A8 06 00 F9                str    x8, [x21, #0x8]
1802A988C: E0 03 15 AA                mov    x0, x21
1802A9890: 3C 04 00 94                bl     0x1802aa980  ; symbol stub for: _Unwind_RaiseException
1802A9894: E0 03 17 AA                mov    x0, x23
1802A9898: 09 00 00 94                bl     0x1802a98bc  ; __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*)

I managed to figure out that it happens only for incremental builds. I'm not sure what could be the root cause but I switched to lldb-vscode from llvm repository and it doesn't occur then. Also, I connected manually using lldb directly and it doesn't happen either. From Xcode it doesn't occur as well. This leads me to codelldb.

Could you investigate this issue?

wojciech-kulik commented 3 months ago

I think I found the root cause. Codelldb adds some breakpoints automatically: https://github.com/vadimcn/codelldb/blob/05502bf75e4e7878a99b0bf0a7a81bba2922cbe3/adapter/codelldb/src/debug_session/breakpoints.rs#L427-L438

wojciech-kulik commented 3 months ago

I prepared a workaround, but it's very annoying behavior:

require("dap").configurations.swift[1].postRunCommands = {
      "breakpoint delete cpp_exception",
}