无法检查 lldb 中的 std::string 变量

Muk*_*ayc 4 c++ clang lldb clang++

当我尝试使用 LLDB 检查 std::string 变量时,出现“错误:摘要字符串解析错误”。

#include <iostream>
#include <string>

int main() {
    std::string a{"123"};
    std::cout << a << std::endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)

附加信息:

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
Run Code Online (Sandbox Code Playgroud)
$ clang++ --version
clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Run Code Online (Sandbox Code Playgroud)
$ lldb --version
lldb version 8.0.1
Run Code Online (Sandbox Code Playgroud)

Nol*_*ght 7

尝试使用-fstandalone-debug标志重新编译源代码。我今天在使用 lldb 时遇到了同样的问题,当我尝试逐个字符访问字符串时,它抛出了一个错误,建议使用此标志进行编译。在我重新编译我的二进制文件后,lldb 处理字符串就好了。

注意:我不确定此标志是否适用于g++,但我假设clang++您使用 lldb 进行编译。

  • 谢谢。添加 `-D_GLIBCXX_DEBUG` 标志也适用于我。 (2认同)