[英]How set std::string type on lldb?
I have the following code:我有以下代码:
#include <iostream>
#include <string>
int main() {
std::string name = "Foo";
return 0;
}
When i will debug with lldb
i want set a std::string
like i set this int
:当我使用
lldb
调试时,我想设置一个std::string
就像我设置这个int
:
expr int $num = 4
I try:我尝试:
expr std::string $name = "Foo"
And i got:我得到了:
error: no type named 'string' in namespace 'std'
Does anyone understand what is going on?有谁明白发生了什么? How can i create a
std::string
on lldb
?如何在
lldb
上创建std::string
?
Obs:观察:
When i print name
, lldb give me this type std::__1::string
for std::string
:当我打印
name
,lldb 为std::string
给我这种类型的std::__1::string
std::string
:
p foo
(std::__1::string) $2 = "foo"
std::string looks simple from the outside but it's actually a quite complex little beast... std::string 从外面看起来很简单,但它实际上是一个相当复杂的小野兽......
For instance, all the std::string constructors except the copy constructors take defaulted arguments (allocators and the like) that most normal C++ users never override, and so don't know about.例如,除复制构造函数之外的所有 std::string 构造函数都采用大多数普通 C++ 用户从未覆盖的默认参数(分配器等),因此不知道。 Since we are getting our information about the type from the DWARF debug info, we are restricted by what it represents.
由于我们是从 DWARF 调试信息中获取有关类型的信息,因此我们受到它所代表的内容的限制。 It doesn't represent the values of defaulted arguments, however, so we don't know how to fill them in.
然而,它不代表默认参数的值,所以我们不知道如何填写它们。
You can try a little harder by reading the string header, and you figure out you need to provide a size and an allocator, and get to something like:您可以通过阅读字符串标头更努力地尝试,并且您发现您需要提供大小和分配器,并获得如下内容:
expr std::string $myStr("Foo", 4, std::allocator<char>())
error: Couldn't lookup symbols:
__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC1EPKcmRKS4_
That fails because the allocator is everywhere inlined, so lldb can't find a constructor to call for it.那失败了,因为分配器到处都是内联的,所以 lldb 找不到调用它的构造函数。
The real solution to this is to have lldb rebuild the std module from headers, import the resultant clang module into lldb's compiler and use that to create these values.真正的解决方案是让 lldb 从头文件重建 std 模块,将生成的 clang 模块导入 lldb 的编译器并使用它来创建这些值。 At that point we'd have the information needed to do this job.
那时,我们将拥有完成这项工作所需的信息。 For instance we would know about defaulted arguments, and could instantiate the missing allocator from the module.
例如,我们会知道默认参数,并且可以从模块中实例化丢失的分配器。
But building a Clang Module from the c++ std headers turns out not to be entirely trivial, so we're still working on that...但是从 c++ 标准头文件构建一个 Clang 模块结果证明并不是完全微不足道的,所以我们仍在努力......
You can use alternatively:您可以选择使用:
expr const char * $foo
expr const char $foo[]
expr const char $foo[4]
Obviously the last one can be used only if you know the dimension of the char-array显然只有在知道字符数组的维数时才能使用最后一个
What kind of a compiler are you using?您使用的是哪种编译器? From what I found this issue exists with clang 5.0.1 but not with clang 7.0.0.
从我发现这个问题存在于 clang 5.0.1 但不存在于 clang 7.0.0。 It could be an issue linked to the address sanitizer.
这可能是与地址清理程序相关的问题。
Try brew install llvm --with-toolchain --with-lldb
尝试
brew install llvm --with-toolchain --with-lldb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.