codelldb icon indicating copy to clipboard operation
codelldb copied to clipboard

Included LLDB segfault when SBTypeSynthetic.IsClassCode is called

Open chase opened this issue 1 year ago • 2 comments

OS: Pop!_OS 22.04 LTS Linux VSCode version: 1.70.1 CodeLLDB version: 1.10.0 Compiler: Ubuntu clang version 14.0.0-1ubuntu1.1 Target: x86_64-pc-linux-gnu Thread model: posix Debuggee: C++, trivial example

Included version of LLDB segfaults when running a Python script that calls IsClassCode. This does not crash on LLDB 15.0.7 that I installed through my package manager.

Code under debug (test.cc):

#include <string_view>
#include <unordered_map>
#include <string>
#include <iostream>
std::string g_s;
std::unordered_map<std::string,std::string_view> g_m;
int main() {
	g_s = "hello";
	g_m.emplace("world", g_s);
	std::cout << g_s << g_m["world"];
}

Compiled with: clang++ --std=c++20 test.cc -o simple-ex

Example script

import lldb


def find_synths(debugger):
    original_category: lldb.SBTypeCategory = debugger.GetCategory("cplusplus")

    if not original_category:
        print("C++ category not available")
        return

    for i in range(original_category.GetNumSynthetics()):
        synthetic: lldb.SBTypeSynthetic = original_category.GetSyntheticAtIndex(i)
        specifier: lldb.SBTypeNameSpecifier = (
            original_category.GetTypeNameSpecifierForSyntheticAtIndex(i)
        )
        if not specifier.IsValid():
            continue
        name = str(specifier.name)
        if not name:
            continue

        modified_typename = name.replace("std::__1", "std::Cr").replace(
            "std::__[[:alnum:]]+", "std::Cr"
        )

        if name == modified_typename:
            continue

        if synthetic.contains_code:
            print(name, "Contains code")
            continue

def __lldb_init_module(debugger, internal_dict):
    find_synths(debugger)

Switching CodeLLDB to use my local lldb causes this to no longer crash:

  "lldb.library": "/usr/lib/x86_64-linux-gnu/liblldb-15.so",
  "lldb.adapterEnv": {"LLDB_DEBUGSERVER_PATH": "/usr/bin/lldb-server-15"}
Verbose log

nitial debug configuration: {
  type: 'lldb',
  request: 'launch',
  name: 'Launch',
  program: '${workspaceFolder}/simple-ex',
  args: [],
  cwd: '${workspaceFolder}',
  postRunCommands: [
    "br set -o true -f test.cc -l 10 -C 'print g_m' -C 'print g_s' -C 'type category list' -C 'command script import ${workspaceFolder}/find_synths.py'"
  ],
  __configurationTarget: 6
}
Resolved debug configuration: {
  type: 'lldb',
  request: 'launch',
  name: 'Launch',
  program: '${workspaceFolder}/simple-ex',
  args: [],
  cwd: '${workspaceFolder}',
  postRunCommands: [
    "br set -o true -f test.cc -l 10 -C 'print g_m' -C 'print g_s' -C 'type category list' -C 'command script import ${workspaceFolder}/find_synths.py'"
  ],
  __configurationTarget: 6,
  relativePathBase: '/next/simple-ex',
  _adapterSettings: {
    displayFormat: 'auto',
    showDisassembly: 'auto',
    dereferencePointers: true,
    suppressMissingSourceFiles: true,
    evaluationTimeout: 5,
    consoleMode: 'commands',
    sourceLanguages: null,
    terminalPromptClear: null,
    evaluateForHovers: true,
    commandCompletions: true,
    reproducer: false
  }
}
[DEBUG codelldb::dap_codec] --> {"command":"disconnect","arguments":{"restart":true,"terminateDebuggee":true},"type":"request","seq":20}
[DEBUG codelldb::debug_session] Debug event: 0x55c52fe6d6f0 Event: broadcaster = 0x55c52ed389d8 (lldb.process), type = 0x00000001 (state-changed), data = { process = 0x55c52ed389a0 (pid = 1971722), state = exited}
[DEBUG codelldb::dap_codec]  {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"lldb","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en-us","supportsProgressReporting":true,"supportsInvalidatedEvent":true,"supportsMemoryReferences":true,"supportsArgsCanBeInterpretedByShell":true},"type":"request","seq":1}
[DEBUG codelldb::dap_codec]  {"command":"launch","arguments":{"type":"lldb","request":"launch","name":"Launch","program":"/next/simple/simple-ex","args":[],"cwd":"/next/simple","postRunCommands":["br set -o true -f test.cc -l 10 -C 'print g_m' -C 'print g_s' -C 'type category list' -C 'command script import /next/simple/find_synths.py'"],"__configurationTarget":6,"relativePathBase":"/next/simple","_adapterSettings":{"displayFormat":"auto","showDisassembly":"auto","dereferencePointers":true,"suppressMissingSourceFiles":true,"evaluationTimeout":5,"consoleMode":"commands","sourceLanguages":null,"terminalPromptClear":null,"evaluateForHovers":true,"commandCompletions":true,"reproducer":false},"__sessionId":"a4f1d838-5263-4dec-a721-b70176bc5710"},"type":"request","seq":2}
[DEBUG codelldb::dap_codec]  {"command":"setBreakpoints","arguments":{"source":{"name":"test.cc","path":"/next/simple/test.cc"},"lines":[10],"breakpoints":[{"line":10}],"sourceModified":false},"type":"request","seq":4}
[DEBUG codelldb::debug_session] Debug event: 0x55f06c9469c8 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 2 type: breakpoint added}
[DEBUG codelldb::debug_session] Debug event: 0x55f06b98d9b8 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 2 type: breakpoint disabled}
[DEBUG codelldb::debug_session] Debug event: 0x55f06c938228 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 2 type: breakpoint removed}
[DEBUG codelldb::dap_codec]  {"command":"setFunctionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":5}
[DEBUG codelldb::dap_codec]  {"command":"setDataBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":6}
[DEBUG codelldb::dap_codec]  {"type":"response","seq":7,"command":"runInTerminal","request_seq":5,"success":true,"body":{"shellProcessId":1955090}}
[DEBUG codelldb::dap_codec] --> {"command":"setInstructionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":8}
[DEBUG codelldb::dap_codec]  {"command":"setExceptionBreakpoints","arguments":{"filters":[],"filterOptions":[{"filterId":"cpp_throw"}]},"type":"request","seq":9}
[DEBUG codelldb::dap_codec]  {"command":"configurationDone","type":"request","seq":10}
[DEBUG codelldb::dap_codec]  SuccessFinishResult, Error:  Success
    Output Message:
    Breakpoint 5: where = simple-ex`main + 72 at test.cc:10:12, address = 0x00005555555563b8

[DEBUG codelldb::dap_codec] <-- {"seq":15,"type":"event","event":"output","body":{"category":"console","output":"Breakpoint 5: where = simple-exmain + 72 at test.cc:10:12, address = 0x00005555555563b8\n\n"}} [DEBUG codelldb::dap_codec] <-- {"seq":16,"type":"response","request_seq":2,"success":true,"command":"launch"} [DEBUG codelldb::debug_session] Debug event: 0x55f06c8df1f8 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000002 (modules-loaded), data = {ld-linux-x86-64.so.2} [DEBUG codelldb::dap_codec] <-- {"seq":17,"type":"response","request_seq":10,"success":true,"command":"configurationDone"} [DEBUG codelldb::dap_codec] <-- {"seq":18,"type":"event","event":"module","body":{"module":{"addressRange":"7FFFF7FC3000","id":"7FFFF7FC3000","name":"ld-linux-x86-64.so.2","path":"/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2","symbolFilePath":"/usr/lib/debug/.build-id/97/18d3757f00d2366056830aae09698dbd35e32c.debug","symbolStatus":"Symbols loaded."},"reason":"new"}} [DEBUG codelldb::debug_session] Debug event: 0x55f06c7baa08 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000002 (modules-loaded), data = {[vdso](0x00007ffff7fc1000)} [DEBUG codelldb::dap_codec] <-- {"seq":19,"type":"event","event":"module","body":{"module":{"addressRange":"7FFFF7FC1000","id":"7FFFF7FC1000","name":"[vdso]","path":"[vdso]","symbolStatus":"Symbols not found"},"reason":"new"}} [DEBUG codelldb::debug_session] Debug event: 0x55f06c7babb8 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 3 type: locations resolved} [DEBUG codelldb::debug_session] Debug event: 0x55f06c7bac08 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000002 (modules-loaded), data = {simple-ex} [DEBUG codelldb::dap_codec] <-- {"seq":20,"type":"event","event":"breakpoint","body":{"breakpoint":{"id":3,"line":10,"message":"Resolved locations: 1","verified":true},"reason":"changed"}} [DEBUG codelldb::dap_codec] <-- {"seq":21,"type":"event","event":"module","body":{"module":{"addressRange":"555555554000","id":"555555554000","name":"simple-ex","path":"/next/simple/simple-ex","symbolFilePath":"/next/simple/simple-ex","symbolStatus":"Symbols loaded."},"reason":"new"}} [DEBUG codelldb::debug_session] Debug event: 0x55f06c7bb970 Event: broadcaster = 0x55f06b9a9408 (lldb.process), type = 0x00000001 (state-changed), data = { process = 0x55f06b9a93d0 (pid = 1972224), state = running} [DEBUG codelldb::dap_codec] <-- {"seq":22,"type":"event","event":"continued","body":{"allThreadsContinued":true,"threadId":1972224}} [DEBUG codelldb::debug_session] Debug event: 0x55f06ca72518 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 5 type: breakpoint added} [DEBUG codelldb::dap_codec] <-- {"seq":23,"type":"event","event":"breakpoint","body":{"breakpoint":{"id":5,"line":10,"message":"Resolved locations: 1","source":{"name":"test.cc","path":"/next/simple/test.cc"},"verified":true},"reason":"new"}} [DEBUG codelldb::debug_session] Debug event: 0x55f06b92a748 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 5 type: locations resolved} [DEBUG codelldb::dap_codec] <-- {"seq":24,"type":"event","event":"breakpoint","body":{"breakpoint":{"id":5,"line":10,"message":"Resolved locations: 1","verified":true},"reason":"changed"}} [DEBUG codelldb::dap_codec] --> {"command":"threads","type":"request","seq":11} [DEBUG codelldb::dap_codec] <-- {"seq":25,"type":"response","request_seq":11,"success":true,"command":"threads","body":{"threads":[{"id":1972224,"name":"1: tid=1972224"}]}} [DEBUG codelldb::debug_session] Debug event: 0x7f49b00f3198 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000004 (modules-unloaded), data = {ld-linux-x86-64.so.2} [DEBUG codelldb::dap_codec] <-- {"seq":26,"type":"event","event":"module","body":{"module":{"id":"FFFFFFFFFFFFFFFF","name":""},"reason":"removed"}} [DEBUG codelldb::debug_session] Debug event: 0x7f497857dfd8 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 1 type: locations removed} [DEBUG codelldb::debug_session] Debug event: 0x7f4978807cf8 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 3 type: locations removed} [DEBUG codelldb::debug_session] Debug event: 0x7f497808cd38 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 4 type: locations removed} [DEBUG codelldb::debug_session] Debug event: 0x7f4979b53ef8 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 5 type: locations removed} [DEBUG codelldb::debug_session] Debug event: 0x7f497808cd38 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 4 type: locations resolved} [DEBUG codelldb::debug_session] Debug event: 0x7f4979b65958 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 4 type: locations resolved} [DEBUG codelldb::dap_codec] <-- {"seq":27,"type":"event","event":"breakpoint","body":{"breakpoint":{"id":4,"message":"Resolved locations: 2","verified":true},"reason":"changed"}} [DEBUG codelldb::debug_session] Debug event: 0x7f4979b54468 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 4 type: locations added} [DEBUG codelldb::dap_codec] <-- {"seq":28,"type":"event","event":"breakpoint","body":{"breakpoint":{"id":4,"message":"Resolved locations: 2","verified":true},"reason":"changed"}} [DEBUG codelldb::dap_codec] <-- {"seq":29,"type":"event","event":"breakpoint","body":{"breakpoint":{"id":4,"message":"Resolved locations: 2","verified":true},"reason":"changed"}} [DEBUG codelldb::debug_session] Debug event: 0x7f497880e378 Event: broadcaster = 0x55f06b7ed980 (lldb.target), type = 0x00000002 (modules-loaded), data = {libstdc++.so.6, libm.so.6, libgcc_s.so.1, libc.so.6} [DEBUG codelldb::dap_codec] <-- {"seq":30,"type":"event","event":"module","body":{"module":{"addressRange":"7FFFF7C00000","id":"7FFFF7C00000","name":"libstdc++.so.6","path":"/lib/x86_64-linux-gnu/libstdc++.so.6","symbolFilePath":"/lib/x86_64-linux-gnu/libstdc++.so.6","symbolStatus":"Symbols loaded."},"reason":"new"}} [DEBUG codelldb::dap_codec] <-- {"seq":31,"type":"event","event":"module","body":{"module":{"addressRange":"7FFFF7EAE000","id":"7FFFF7EAE000","name":"libm.so.6","path":"/lib/x86_64-linux-gnu/libm.so.6","symbolFilePath":"/usr/lib/debug/.build-id/d2/c7d1fdefc7a876b6017c090ccd55fb21e8d77f.debug","symbolStatus":"Symbols loaded."},"reason":"new"}} [DEBUG codelldb::dap_codec] <-- {"seq":32,"type":"event","event":"module","body":{"module":{"addressRange":"7FFFF7E8E000","id":"7FFFF7E8E000","name":"libgcc_s.so.1","path":"/lib/x86_64-linux-gnu/libgcc_s.so.1","symbolFilePath":"/lib/x86_64-linux-gnu/libgcc_s.so.1","symbolStatus":"Symbols loaded."},"reason":"new"}} [DEBUG codelldb::dap_codec] <-- {"seq":33,"type":"event","event":"module","body":{"module":{"addressRange":"7FFFF7800000","id":"7FFFF7800000","name":"libc.so.6","path":"/lib/x86_64-linux-gnu/libc.so.6","symbolFilePath":"/usr/lib/debug/.build-id/a4/3bfc8428df6623cd498c9c0caeb91aec9be4f9.debug","symbolStatus":"Symbols loaded."},"reason":"new"}} [DEBUG codelldb::debug_session::breakpoints] Callback for breakpoint location 3.1: where = simple-exmain + 72 at test.cc:10:12, address = 0x00005555555563b8, resolved, hit count = 1

[DEBUG codelldb::dap_codec] <-- {"seq":34,"type":"event","event":"output","body":{"category":"console","output":"(lldb) print g_m\n(std::unordered_map<std::basic_string<char, std::char_traits, std::allocator >, std::basic_string_view<char, std::char_traits >, std::hash<std::basic_string<char, std::char_traits, std::allocator > >, std::equal_to<std::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits, std::allocator >, std::basic_string_view<char, std::char_traits > > > >) size=1 {\n [0] = {\n first = "world"\n second = (_M_len = 5, _M_str = "hello")\n }\n}\n"}} [DEBUG codelldb::dap_codec] <-- {"seq":35,"type":"event","event":"output","body":{"category":"console","output":"(lldb) print g_s\n(std::string) "hello"\n"}} [DEBUG codelldb::dap_codec] <-- {"seq":36,"type":"event","event":"output","body":{"category":"console","output":"(lldb) type category list\nCategory: default (enabled)\nCategory: Rust (enabled)\nCategory: VectorTypes (enabled, applicable for language(s): objective-c++)\nCategory: system (enabled, applicable for language(s): objective-c++)\nCategory: cplusplus (enabled)\nCategory: objc (enabled)\n"}} Received signal: SIGSEGV 0: codelldb::hook_crashes::handler 1: 2: _ZN4lldb15SBTypeSynthetic11IsClassCodeEv 3: 4: 5: _PyObject_MakeTpCall 6: 7: _PyEval_EvalFrameDefault 8: _PyFunction_Vectorcall 9: 10: _PyObject_GenericGetAttrWithDict 11: 12: _PyEval_EvalFrameDefault 13: _PyFunction_Vectorcall 14: 15: _PyEval_EvalFrameDefault 16: _PyFunction_Vectorcall 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: _ZN4lldb10SBListener12WaitForEventEjRNS_7SBEventE 33: __cpp_closure_1725553361688648134 34: lldb::sb::sblistener::SBListener::wait_for_event 35: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll 36: tokio::runtime::task::core::Core<T,S>::poll 37: tokio::runtime::task::harness::Harness<T,S>::poll 38: tokio::runtime::blocking::pool::Inner::run 39: std::sys_common::backtrace::__rust_begin_short_backtrace 40: core::ops::function::FnOnce::call_once{{vtable.shim}} 41: std::sys::unix::thread::Thread::new::thread_start 42: start_thread at ./nptl/pthread_create.c:442:8 43: clone3 at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

Debug adapter exit code=255 (0xff), signal=null.

chase avatar Nov 03 '23 08:11 chase

@vadimcn Is the source available for your LLDB fork? I'd like to fix this for you, if possible. It would help my team since it doesn't require additional setup on their part if the pre-built binaries for LLDB work out of the box.

chase avatar Nov 12 '23 22:11 chase

It's in this branch. However, since you are having this problem with c++ code, I think it's likely that it exists in the mainline lldb-16 as well.

vadimcn avatar Nov 13 '23 16:11 vadimcn