lldb can't debug string when compiled by clang++
Asked Answered
H

3

1

This is the test code.

#include <string>

int main(int argc, char const *argv[]) {
    std::string a = "hello";
    std::string b = "world";
    return 0;
}

I compile it by the command:

clang++ test.cpp -g

Then I try to debug it:

lldb a.out

I add break at 4th line, after the a = "hello" runs. I try to print the a by p a, it show me the following error:

error: incomplete type 'string' (aka 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >') where a complete type is requ
ired

note: forward declaration of 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >'
error: 1 errors parsing expression

I can't figure out.

Though when I try to compile by g++, it's OK.

Hypotenuse answered 1/9, 2016 at 3:3 Comment(2)
A wild guess - the compiler optimized it away, because it is unused, and then did not include the type definitions (as they are 'no longer needed'). Now the debugger cannot access them.Formerly
Have you tested on your computer? Is that just happen on me?Hypotenuse
H
2

This is because clang is not emitting debug information for std::string. Make sure that you installed debug info for libstdc++. See this invalid bug for more information:

Looks like you don't have debug information for libstdc++ installed:

Missing separate debuginfos, use: dnf debuginfo-install libgcc-5.1.1-4.fc22.x86_64 libstdc++-5.1.1-4.fc22.x86_64

Clang is not emitting debug information for std::string because it was told that libstdc++ provides it (but in your case, it's not installed); this is a debug size optimization that GCC apparently doesn't perform.

Hertha answered 3/2, 2017 at 21:33 Comment(0)
D
1

I was able to resolve the problem by adding -fstandalone-debug after clang++.

(lldb) r
Process 9391 launched: '/workspaces/cs15/hw4/CalcYouLater' (x86_64)
Process 9391 stopped
* thread #1, name = 'CalcYouLater', stop reason = breakpoint 1.1
    frame #0: 0x0000000000402ab7 CalcYouLater`RPNCalc::processCommand(this=0x00007fffffffd138, cmd="{") at RPNCalc.cpp:92:17
   89    */
   90   void RPNCalc::processCommand(string cmd) {
   91       int value;
-> 92       if (got_int(cmd, &value)) {
   93           processInt(value);
   94       } else if (cmd == "#t" or cmd == "#f") {
   95           processBool(cmd);
(lldb) p cmd
(std::string) $0 = "{"
(lldb) 

My testing environment is 22.04.1-Ubuntu SMP Wed Jan 10 22:57:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux.

Danaides answered 5/3 at 19:34 Comment(0)
M
0

Try compiling with -glldb instead of -g, it compiles with optimized degub information for lldb

Miscarriage answered 15/10, 2023 at 15:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.