[lldb-dev] RTTI does not work stable in LLDB.

Greg Clayton via lldb-dev lldb-dev at lists.llvm.org
Wed Feb 8 17:04:59 PST 2017


> On Feb 6, 2017, at 5:58 PM, Roman Popov <ripopov at gmail.com> wrote:
> 
> Hello, 
> I just found out that sometimes I don't get correct dynamic type in LLDB even if I compile with g++.  How can I get typeinfo/vtable dump from LLDB to check if it is still the same name matching issue? 


Stop where dynamic typing fails, and take the pointer that is failing to be properly typed and do:

(lldb) memory read --format address my_ptr

Then look at the first entry that is in the output and it should be "vtable for " and take all the characters that follow this and are before the " + XXX" and check to see if LLDB knows about this type. 

If we use your previous source:

#include <iostream>
#include <typeinfo>

using namespace std;

struct base_type {  virtual ~base_type(){} };

template <class T1, class T2, unsigned SIZE>
struct derived0 : base_type {};

template <class T1, class T2>
struct derived1 : base_type {};

int main(int argc, char ** argv) {

    base_type * bptr0 = new derived0<int, int, 1024>();
    base_type * bptr1 = new derived1<int, int >();

    cout << typeid(*bptr0).name() << endl;
    cout << typeid(*bptr1).name() << endl;

    return 0;
}




If we compile this into "a.out":

% lldb a.out
(lldb) b /return 0/
(lldb) r
(lldb) memory read --format address bptr0
0x1001002f0: 0x0000000100002120 vtable for derived0<int, int, 1024u> + 16
....

We now take all text past the "vtable for " and before the " + 16" and lookup the type by name:

(lldb) image lookup -t "derived0<int, int, 1024u>"

Note this doesn't work, but if we remove the 'u' from 1024 it does work:

(lldb) image lookup -t "derived0<int, int, 1024>"
Best match found in /tmp/a.out:
id = {0x000065da}, name = "derived0<int, int, 1024>", byte-size = 8, decl = main.cpp:9, compiler_type = "class derived0 : public base_type {
}"





More information about the lldb-dev mailing list