[lldb-dev] get function name from dwarf info

Greg Clayton via lldb-dev lldb-dev at lists.llvm.org
Wed Oct 12 10:10:32 PDT 2016

> On Oct 7, 2016, at 7:32 AM, Carlo Kok via lldb-dev <lldb-dev at lists.llvm.org> wrote:
>>> How do I get the dw_at_name field? I don't need lldb to decypher the
>>> mangling I use, I just want access to the linkage name and real encoded
>>> name?
>>> Also how do I get the type this is contained in (presuming there is one
>>> ofc)?
>> I am not sure what you are trying to do. Can you elaborate a little.
> I have a custom language where it's ~ equivalent to the c++ class:
> class TEST{
>    private:
>    static int STATICFIELD;
>    public:
>    void INSTANCEMETHOD() {
>    }
>    static void STATICMETHOD() {
>        STATICFIELD++;
>    }
> };
> the name "STATICMETHOD" is properly encoded in the dwarf debug info (where linkage name is the mangled name). I want "STATICMETHOD" back as it would be encoded in DW_AT_NAME.
> I also want to get the SBType for "TEST" when I have the SBFunction for INSTANCEMETHOD/STATICMETHOD.
> Both things are properly encoded in dwarf (as matching the c++ output), however I can't seem to find the right SB method to get it.

We currently have a way for you to find the SBType for "TEST" and then ask that type for its member functions:

SBType test_type = module.FindFirstType("TEST");
const uint32_t num_member_functions = test_type.GetNumberOfMemberFunctions();
for (uint32_t i=0; i<num_member_functions; ++i)
  SBTypeMemberFunction member_function = test_type.GetMemberFunctionAtIndex(i);

When using a SBFunction, you can easily get its function type:

SBFunction function = ...;
SBType function_type = function.GetType();

But there isn't a way to get directly from a SBFunction's type to SBTypeMemberFunction. Seems like this can be fixed by adding the following functions:

  lldb::SBTypeMemberFunction lldb::SBType::GetMemberFunction();

lldb::SBTypeMemberFunction might come back invalid if the type wasn't a member function, but if it is, then this would work.

We would also need to add a way to get the class type from the member function:

lldb::SBType lldb::SBTypeMemberFunction::GetContainingType();

This would return the class/struct that owns the member function.

So if we just add:

  lldb::SBTypeMemberFunction lldb::SBType::GetMemberFunction();
  lldb::SBType lldb::SBTypeMemberFunction::GetContainingType();

Then you should be able to do what you want. Let me know if you need help with this.


>>> Lastly: How do I encode if a method is static or not, I couldn't find
>>> any difference in what C++ does for instance vs static.

You can already ask a member function for its kind:

  lldb::MemberFunctionKind lldb::SBTypeMemberFunction::GetKind();

This should help for member functions.

>> There is  "DW_AT_object_pointer". Debuggers can also make that decision
>> based on presence of "this" parameter.

The member function type should be correctly encoded and can be accessed by lldb::SBTypeMemberFunction::GetKind(). 

> Thanks.
> -- 
> Carlo Kok
> RemObjects Software
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev

More information about the lldb-dev mailing list