How does one print out an expression with a std library function in lldb? For example, suppose I want to use std::string::c_str()
in an print expression. I can see the symbol and disassemble it just fine but cannot seem to use it in an expression call
(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
But cannot seem to use it in an expression. Seems to always choke on the std
namespace identifier
(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
That's an instance method, you have to call it on an object. In your case, it looks like you want to do something like:
(lldb) expr ((std::__1::string *) $rax)->c_str()
(const value_type *) $1 = 0x00007fff5fbff661 "some string here"
You really shouldn't have to explicitly name the __1, but lldb doesn't support "inline namespaces" yet (and the clang debug information doesn't say __1 IS an inline namespace, so for now you do.
User contributions licensed under CC BY-SA 3.0