problem with simple expr command


I’m debugging a C++ program and want to do some inspection by calling the toString() method of an object. I’m pretty sure I have the syntax of the command correct, but I get the error shown below:

(lldb) expr (string) query.toString()
error: call to a function ‘std::basic_string<char,std::char_traits,std::allocator >::~basic_string<char,std::char_traits,std::allocator >(int)’ that is not present in the target
error: The expression could not be prepared to run in the target

I interpret this error to mean that lldb is having trouble trying to deal with the lifecycle for the returned std::string (doesn’t know how to invoke the string destructor).

Version of lldb:
lldb --version

Any advice?


No, LLDB is actually complaining that it can't find the destructor for std::basic_string<char> in your program. This should be in your C++ standard library somewhere, but we aren't finding it when we do a function lookup...

LLDB 179.5 is pretty old, I would try a newer Xcode with a newer LLDB and see how things go.



a common problem with STL objects used in code is that all the accessor functions (and simple things like the destructor) is that they are inlined wherever they are used, so LLDB can’t find them when it wants to use them for expressions.
Eventually it’d be nice to generate them on demand, but we don’t currently do that – not least, because debug information doesn’t contain method definitions.

As you deduced, the function that we’re not finding here is the string destructor.

You could try rewriting your expression using “new” to leak a std::string and then assigning the string into the leaked std::string, avoiding the destructor, but if this is a common debugging technique for you you may want to consider having a dump() function on query that does the toString() work and either returns a const char* or simply dumps the string to stdout/stderr.