[lldb-dev] Type information (methods, parameters etc.)

Jim Ingham jingham at apple.com
Mon May 7 11:21:59 PDT 2012


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:

size_t
SBCompileUnit::GetNumberOfTypes();

SBType
SBCompileUnit::GetTypeAtIndex(size_t idx);

and then to handle types that are defined in functions:

size_t
SBCompileUnit::GetNumberOfFunctions();

SBFunction::GetFunctionAtIndex(size_t idx);

and

size_t
SBFunction::GetNumberOfTypes ();

SBType
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!

Jim

On May 7, 2012, at 10:48 AM, Greg Clayton wrote:

> Yes it does. First create a debugger, then a target, then grab the types:
> 
> 
> using namespace lldb;
> 
> int
> main (int argc, char const *argv[])
> {
>    SBDebugger::Initialize();
>    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));
>                //....
>            }
>        }
>    }   
>    SBDebugger::Terminate();
> }
> 
> 
> Then at the "...." you can use the SBType interface:
> 
>    size_t
>    SBType::GetByteSize();
> 
>    const char*
>    SBType::GetName();
> 
>    lldb::TypeClass
>    SBType::GetTypeClass ();
> 
> 
> You can also see your fields, and base classes with:
> 
>    uint32_t
>    GetNumberOfFields ();
> 
>    uint32_t
>    GetNumberOfDirectBaseClasses ();
> 
>    uint32_t
>    GetNumberOfVirtualBaseClasses ();
> 
>    lldb::SBTypeMember
>    GetFieldAtIndex (uint32_t idx);
> 
>    lldb::SBTypeMember
>    GetDirectBaseClassAtIndex (uint32_t idx);
> 
>    lldb::SBTypeMember
>    GetVirtualBaseClassAtIndex (uint32_t idx);
> 
>    uint32_t
>    GetNumberOfTemplateArguments ();
> 
>    lldb::SBType
>    GetTemplateArgumentType (uint32_t idx);
> 
>    lldb::TemplateArgumentKind
>    GetTemplateArgumentKind (uint32_t idx);
> 
> 
> 
> 
> On May 5, 2012, at 10:25 AM, Magnus Holm wrote:
> 
>> 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
>> _______________________________________________
>> lldb-dev mailing list
>> lldb-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev
> 
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev




More information about the lldb-dev mailing list