Type information (methods, parameters etc.)

Hey folks,

I'm wondering if LLDB makes type information (class definitions,
methods, parameters etc.) available in the API. I guess you could just
parse the supported files using libclang, but LLDB might already be
doing something similar already?

// Magnus Holm

Yes it does. First create a debugger, then a target, then grab the types:

using namespace lldb;

main (int argc, char const *argv[])
    SBDebugger debugger (SBDebugger::Create());
    if (debugger.IsValid())
        // Create a target using the executable.
        SBTarget target (debugger.CreateTargetWithFileAndArch (exe_file_path, "x86_64-apple-macosx"));
        if (target.IsValid())
            SBTypeList type_list (target.FindTypes("MyClass"));
            const uint32_t num_matches = type_list.GetSize();
            for (uint32_t i=0; i<num_matches; ++i)
                SBType type (type_list.GetTypeAtIndex(i));

Then at the "...." you can use the SBType interface:


    const char*
    SBType::GetTypeClass ();

You can also see your fields, and base classes with:

    GetNumberOfFields ();
    GetNumberOfDirectBaseClasses ();

    GetNumberOfVirtualBaseClasses ();
    GetFieldAtIndex (uint32_t idx);
    GetDirectBaseClassAtIndex (uint32_t idx);

    GetVirtualBaseClassAtIndex (uint32_t idx);

    GetNumberOfTemplateArguments ();
    GetTemplateArgumentType (uint32_t idx);

    GetTemplateArgumentKind (uint32_t idx);

As Greg showed, provided you know the type you are looking for, lldb makes it easy to get and introspect types. What we are missing is an interface to enumerate all the types in the program. Probably something like:


SBCompileUnit::GetTypeAtIndex(size_t idx);

and then to handle types that are defined in functions:


SBFunction::GetFunctionAtIndex(size_t idx);


SBFunction::GetNumberOfTypes ();

SBFunction::GetTypeAtIndex (size_t idx)

and for extra credit asking the blocks for their types...

We haven't needed these for anything we are doing with lldb yet. But the API's should be pretty easy to add; there is support for getting this information from the lower level API's. So if you have need of them before we get around to adding these API's, please add them. We'd be happy to take the patch!