7

When I try to inspect std::string variable using LLDB, I get "error: summary string parsing error".

#include <iostream>
#include <string>

int main() {
    std::string a{"123"};
    std::cout << a << std::endl;
    return 0;
}
Process 4492 stopped
* thread #1, name = 'main', stop reason = breakpoint 1.1
    frame #0: 0x00005555555551e9 main`main at main.cpp:6:1
   3    
   4    int main() {
   5        std::string a{"123"};
-> 6        std::cout << a << std::endl;
   7        return 0;
   8    }
(lldb) v a
(std::string) a = error: summary string parsing error

Additional information:

$ clang++ --version
clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ lldb --version
lldb version 8.0.1
uname -s -r -m -o
Linux 5.3.5-arch1-1-ARCH x86_64 GNU/Linux
mukkumayc
  • 130
  • 1
  • 7
  • Does the problem persist even if you change the variable's name? – BiagioF Oct 27 '19 at 11:38
  • Even if I change name it does. – mukkumayc Oct 27 '19 at 13:07
  • what do you get for `frame variable -R a`. This will show the implementation details of your std::string. Your lldb should have built in formatters for libc++ and libstdc++ std::string's, it depends on which c++ library your binary is linked against which is used. All of this should happen seamlessly though. – Jason Molenda Oct 27 '19 at 22:09
  • When I write `frame variable -R a` I get `(std::string) a = {}` – mukkumayc Oct 28 '19 at 10:04
  • [That](https://stackoverflow.com/a/47045466/12288259) answer should resolve your problem. – Dmitriy Kuklin Oct 28 '19 at 21:39
  • Does this answer your question? [lldb can't debug string when compiled by clang++](https://stackoverflow.com/questions/39262055/lldb-cant-debug-string-when-compiled-by-clang) – emmenlau Oct 11 '21 at 12:49

1 Answers1

11

Try recompiling your source code with the -fstandalone-debug flag. I had this same problem when I was using lldb today and when I tried accessing the string character-by-character it threw an error that recommended compiling with this flag. After I had recompiled my binary files lldb handled strings just fine.

Note: I'm unsure if this flag works with g++, but I'm assuming that you compile with clang++ if you're using lldb.

Nolan Faught
  • 406
  • 3
  • 13
  • 2
    Thank you. It also works for me to add `-D_GLIBCXX_DEBUG` flag. – mukkumayc Nov 16 '19 at 23:12
  • 1
    It is a rather bad idea to add the `-D_GLIBCXX_DEBUG` compiler flag, see https://bugs.llvm.org/show_bug.cgi?id=24202#c9. Much better is to use either `-fstandalone-debug` or `-fno-limit-debug-info` or install and link the debug stl for your platform. – emmenlau Oct 11 '21 at 12:48