Skip to content

[lldb] [Windows] Lldb-dap crashes when trying to step over breakpoint #133904

Open
@ktraunmueller

Description

@ktraunmueller

I have a swift-winrt based Windows desktop app.

Debugging works fine in the app executable, but when trying to step over (some, not all) breakpoints in other modules (see Package.swift below), the debugger crashes (reproducibly every time) with

Assertion failed: Out.empty(), file D:\r\_work\swift-build\swift-build\SourceCache\llvm-project\llvm\lib\Support\ConvertUTFWrapper.cpp, line 85
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: E:\\Swift\\Toolchains\\0.0.0+Asserts\\usr\\bin\\lldb-dap.exe
Exception Code: 0x80000003
 #0 0x00007ff7caa94b10 (E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\lldb-dap.exe+0x64b10)
 #1 0x00007ffb5b47b030 (C:\WINDOWS\System32\ucrtbase.dll+0x7b030)
 #2 0x00007ffb5b47bc3c (C:\WINDOWS\System32\ucrtbase.dll+0x7bc3c)
 #3 0x00007ffb5b47d5d4 (C:\WINDOWS\System32\ucrtbase.dll+0x7d5d4)
 #4 0x00007ffb5b47cbe0 (C:\WINDOWS\System32\ucrtbase.dll+0x7cbe0)
 #5 0x00007ffb5b47d70c (C:\WINDOWS\System32\ucrtbase.dll+0x7d70c)
 #6 0x00007ffa86d13628 (E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\liblldb.dll+0xcd3628)
 #7 0x00007ffa86a94108 (E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\liblldb.dll+0xa54108)
 #8 0x00007ffa862fc978 (E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\liblldb.dll+0x2bc978)
 #9 0x00007ff7caa6bfa0 (E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\lldb-dap.exe+0x3bfa0)
#10 0x00007ff7caa520bc (E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\lldb-dap.exe+0x220bc)
#11 0x00007ff7caa5be08 (E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\lldb-dap.exe+0x2be08)
#12 0x00007ff7caa5c220 (E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\lldb-dap.exe+0x2c220)
#13 0x00007ff7caa55240 (E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\lldb-dap.exe+0x25240)
#14 0x00007ff7caaa84e4 (E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\lldb-dap.exe+0x784e4)
#15 0x00007ff7caaa857c (E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\lldb-dap.exe+0x7857c)
#16 0x00007ffb5d4a8740 (C:\WINDOWS\System32\KERNEL32.DLL+0x8740)
#17 0x00007ffb600d0eb4 (C:\WINDOWS\SYSTEM32\ntdll.dll+0xd0eb4)

lldb command-line debugging is mostly working fine, so it looks this is an issue in the toolchain's lldb-dap debug adapter, not some general problem with my debugger setup.

Unfortunately I haven't found more clues on how to reproduce or narrow this down. I also can't share the source code, and I don't have a minimal reproducing example :(

Environment:

  • Windows 11 arm64
    • I also tested on an x64 machine (same Swift toolchain version), and it was exactly the same crash as on arm64.
  • VS Code with swiftlang.swift-vscode Version 2.0.2
  • current TBC Swift toolchain

I was searching for code in LLVM that calls the assertion-throwing convertUTF16ToUTF8String() function in ConvertUTFWrapper.cpp

Assertion failed: Out.empty(), file D:\r\_work\swift-build\swift-build\SourceCache\llvm-project\llvm\lib\Support\ConvertUTFWrapper.cpp, line 85

and found this candidate, where m_name may be the std::string that is expected to be empty (but is not) when convertUTF16ToUTF8String() is called:

llvm::convertUTF16ToUTF8String(
        llvm::ArrayRef(reinterpret_cast<char *>(pszThreadName),
                       wcslen(pszThreadName) * sizeof(wchar_t)),
        m_name);

Maybe a simple

m_name = "";

before the call to convertUTF16ToUTF8String() would fix the problem.

The app's Package.swift
// swift-tools-version: 6.2

import PackageDescription

let GUILinkerSettings: [LinkerSetting] = [
    .unsafeFlags(["-Xlinker", "/SUBSYSTEM:WINDOWS"], .when(configuration: .release)),
    // Update the entry point to point to the generated swift function, this lets us keep the same main method
    // for debug/release
    .unsafeFlags(["-Xlinker", "/ENTRY:mainCRTStartup"], .when(configuration: .release)),
]

let package = Package(
    name: "Compositor-Windows",
    products: [
        .executable(
            name: "Compositor",
            targets: ["Compositor"]),
    ],
    dependencies: [
        // .package(url: "https://github.com/ktraunmueller/swift-cwinrt", branch: "main"),
        // .package(url: "https://github.com/ktraunmueller/swift-uwp", branch: "main"),
        // .package(url: "https://github.com/ktraunmueller/swift-windowsfoundation", branch: "main"),
        // .package(url: "https://github.com/ktraunmueller/swift-windowsappsdk", branch: "main"),
        // .package(url: "https://github.com/ktraunmueller/swift-winui", branch: "main"),
        // .package(url: "https://github.com/ktraunmueller/swift-plugins", branch: "main")
        .package(path: "../../../winrt/swift-cwinrt"),
        .package(path: "../../../winrt/swift-uwp"),
        .package(path: "../../../winrt/swift-win2d"),
        .package(path: "../../../winrt/swift-windowsappsdk"),
        .package(path: "../../../winrt/swift-windowsfoundation"),
        .package(path: "../../../winrt/swift-winui"),
        .package(path: "../Core")
    ],
    targets: [
        .executableTarget(
            name: "Compositor",
            dependencies: [
                .product(name: "CompositorCore", package: "Core"),
                .product(name: "CWinRT", package: "swift-cwinrt"),
                .product(name: "UWP", package: "swift-uwp"),
                .product(name: "Win2D", package: "swift-win2d"),
                .product(name: "WinAppSDK", package: "swift-windowsappsdk"),
                .product(name: "WindowsFoundation", package: "swift-windowsfoundation"),
                .product(name: "WinUI", package: "swift-winui"),
            ],
            swiftSettings: [.interoperabilityMode(.Cxx)],
            linkerSettings: GUILinkerSettings
        ),
    ],
    swiftLanguageModes: [.v5]
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions