如何在lldb中打印出带有std库函数的表达式?例如,假设我想在打印表达式中使用std::string::c_str()
。我可以看到符号并将其拆解得很好但似乎无法在表达式调用中使用它
(lldb) image lookup -v -r -n "c_str\("
2 matches found in /usr/lib/libc++.1.dylib:
Address: libc++.1.dylib[0x0000000000041da6] (libc++.1.dylib.__TEXT.__text + 264214)
Summary: libc++.1.dylib`std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::c_str() const
Module: file = "/usr/lib/libc++.1.dylib", arch = "x86_64"
Symbol: id = {0x000002ec}, range = [0x00007fff8ec8cda6-0x00007fff8ec8cdbe), name="std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::c_str() const", mangled="_ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE5c_strEv"
(lldb) dis -n "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::c_str()"
libc++.1.dylib`std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::c_str() const:
0x7fff8ec8cda6: pushq %rbp
0x7fff8ec8cda7: movq %rsp, %rbp
0x7fff8ec8cdaa: testb $0x1, (%rdi)
0x7fff8ec8cdad: je 0x7fff8ec8cdb5 ; std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::c_str() const + 15
0x7fff8ec8cdaf: movq 0x10(%rdi), %rdi
0x7fff8ec8cdb3: jmp 0x7fff8ec8cdb8 ; std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::c_str() const + 18
0x7fff8ec8cdb5: incq %rdi
0x7fff8ec8cdb8: movq %rdi, %rax
0x7fff8ec8cdbb: popq %rbp
0x7fff8ec8cdbc: retq
0x7fff8ec8cdbd: nop
但似乎无法在表达式中使用它。似乎总是阻塞std
命名空间标识符
(lldb) expr std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::c_str($rax)
error: use of undeclared identifier 'std'
error: expected unqualified-id
error: 2 errors parsing expression
答案 0 :(得分:0)
这是一个实例方法,你必须在一个对象上调用它。在您的情况下,看起来您想要执行以下操作:
(lldb) expr ((std::__1::string *) $rax)->c_str()
(const value_type *) $1 = 0x00007fff5fbff661 "some string here"
你真的不应该明确地命名__1,但是lldb还不支持“内联命名空间”(并且clang调试信息并不是说__1是一个内联命名空间,所以现在你可以这样做。