Can't easily show a std::string in LLDB?

I don’t have much LLDB experience, but I’m trying to finally get it working in a visual debugger (VS Code at the moment). It seems like I should be able to look at a C++ string without much trouble. But…

(lldb) p name
(const std::string) $5 = Summary Unavailable
(lldb) po name
Summary Unavailable
(lldb) p *name.c_str()
(const std::basic_string<char, std::char_traits<char>, std::allocator<char> >::value_type) $14 = '+'

Is there something wrong with my setup? Should those first two print something nice? (The actually string is just "+" in this case.) I do have a custom built libc++, so the full namespace looks like: std::__myname::basic_string. I don’t know if that’s a problem.

Typing p foo.c_str() isn’t horrible, but in VS Code and I notice all strings in the “Variables” panel say “Summary Unavailable” and have a tree of gobblygook implementation details under them. I’d like it show the string’s value, of course.

▿ name: Summary Unavailable
  ▿ __r_ : { ... }
    ▿ std::__myname::__compressed_pair_elem<std::__myname...
       ▿ __value_ : { ... }           

About six levels down in that I finally find something that appears to be the string’s expected value.

How was your libc++ built? It seems like you are running into llvm-project/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp at 6685fd82391d3e654d3b05f2d54cdcdec6e6d887 · llvm/llvm-project · GitHub

I think the formatters are not detecting your custom namespace llvm-project/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp at main · llvm/llvm-project · GitHub

Are you using an lldb from Xcode 14 on an Intel mac? I think there was a problem with that lldb and printing short std::strings.

My namespace does match that regex I see there in the code: "^std::__[[:alnum:]]+::string$", so maybe I’ll try to build an LLDB like I’ve built LLVM, Clang, and libc++, and see if that helps. I’m currently using the one that came from Apple with Xcode.

These builds take forever on my poor MacBook Pro, so it’s hard to experiment and try things out. Maybe I can set up something on an AWS instance, so I can rebuild these things without tying up my laptop for 1-3 hours.

Yeah, that’s what I’m using. I’ll try getting or building a newer LLDB and see if that helps.

We changed how the data is represented in source a couple of months ago, which broke the LLDB formatter. That might be the reason your Xcode LLDB doesn’t recognize the string.

1 Like

Yup, I built LLDB from source (main branch) and now I can see the strings as expected. Both p str commands and the Variables panel in VS Code.