[lldb-dev] Navigating STL types
Greg Clayton via lldb-dev
lldb-dev at lists.llvm.org
Thu Feb 2 14:42:13 PST 2017
You could add an explicit instantiation of your template for C++ types you need.
Example without:
#include <cstdio>
#include <vector>
int main (int argc, char const *argv[])
{
std::vector<int> ints = { 1,2,3,4 };
for (auto i: ints)
printf("%i\n", i);
return 0;
}
(lldb) target create "a.out"
(lldb) b /auto i/
(lldb) r
(lldb) p ints.size()
error: Couldn't lookup symbols:
__ZNKSt3__16vectorIiNS_9allocatorIiEEE4sizeEv
But add the explicit instantiation:
#include <cstdio>
#include <vector>
template class std::vector<int>; /// <<<<<<<<<
int main (int argc, char const *argv[])
{
std::vector<int> ints = { 1,2,3,4 };
for (auto i: ints)
printf("%i\n", i);
return 0;
}
(lldb) target create "a.out"
(lldb) b /auto i/
(lldb) r
(lldb) p ints.size()
(std::__1::vector<int, std::__1::allocator<int> >::size_type) $0 = 4
So you could have some piece of code somewhere in your project:
#ifndef NDEBUG
/// Explicitly instantiate any STL stuff you need in order to debug
#endif
GDB is probably working around this by doing things for you without running the code that doesn’t exist.
Greg
> On Jan 23, 2017, at 3:58 PM, Andreas Yankopolus via lldb-dev <lldb-dev at lists.llvm.org> wrote:
>
> How can I navigate STL types using their overloaded operators and member functions (e.g., “[]” and “.first()” for vectors) ? For example, take a C++ source file with:
>
> std::vector<std::string> v;
> v.push_back("foo”);
>
> Breaking after this statement in lldb and typing "p v[0]" would be reasonably expected to return "foo", but it gives a symbol lookup error. Similarly, “p v.first()” gives an error that there’s no member named “first”. I’m seeing this issue with clang/llvm 3.9 and 4.0 nightlies on Ubuntu 16.10 and with Apple’s versions on MacOS Sierra.
>
> Internet rumor (e.g., this discussion <http://stackoverflow.com/questions/39680320/printing-debugging-libc-stl-with-xcode-lldb/39731933>) says this is aggressive inlining of STL code. I’m compiling in clang++ with “-O0 -g -glldb”.
>
> In comparison, gdb prints the value of v[0] just fine when compiled with gdb.
>
> What am I doing wrong?
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20170202/ed1334d0/attachment-0001.html>
More information about the lldb-dev
mailing list