[lldb-dev] lldb print c++ variables from dylib loaded in Swift application

David M. Lary via lldb-dev lldb-dev at lists.llvm.org
Sat Jan 26 18:41:11 PST 2019


I'm writing a Swift application for MacOS that makes use of a C/C++
dylib from a third party to interact with a film scanner.  The
application uses dlopen() & dlsym() to discover and call the C wrapper
function for the C++ implementation.  Overall this works, but I've run
into the following wall while debugging an issue within the dylib
itself.

While debugging I want to examine std::list <T> structures in memory
by address.  I am stopped deep inside the C++ code, and from what I've
googled, printing STL variables is possible through `frame variable`,
however for all of the functions within the dylib, `frame variable`
doesn't find any variables.

I've tried using `expr -l c++ --
reinterpret_cast<std::list<int>>($rdi)`, however this just returns the
error: "use of undeclared identifier 'std'".

Is there a way to cast an arbitrary address as an STL type, and print
it out in lldb?

I know it's possible to write a custom command in python to do this,
but I'd really rather not write something from scratch if the
functionality already exists in lldb.

Thank you,
-David M. Lary


More information about the lldb-dev mailing list