get function name from dwarf info

Hi,

I have a piece of debuginfo containing this subfunction :

DW_TAG_subprogram [6] *
   DW_AT_low_pc [DW_FORM_addr] (0x0000000000437020)
   DW_AT_high_pc [DW_FORM_data4] (0x0000001e)
   DW_AT_frame_base [DW_FORM_exprloc] (<0x1> 55 )
   DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x000000ae] = "mi_t11_issudebugtest.ABC2_AA")
   DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000cb] = "AA")
   DW_AT_decl_line [DW_FORM_data1] (16)
DW_AT_external [DW_FORM_flag_present] (true)

It's part (a member) of this type:
DW_TAG_structure_type [2] *
   DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000065] = "issudebugtest.ABC")
  DW_AT_byte_size [DW_FORM_data1] (0x08)

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)?

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.

From: lldb-dev [mailto:lldb-dev-bounces@lists.llvm.org] On Behalf Of Carlo
Kok via lldb-dev
Sent: 07 October 2016 14:29
To: lldb-dev@lists.llvm.org
Subject: [lldb-dev] get function name from dwarf info

Hi,

I have a piece of debuginfo containing this subfunction :

DW_TAG_subprogram [6] *
   DW_AT_low_pc [DW_FORM_addr] (0x0000000000437020)
   DW_AT_high_pc [DW_FORM_data4] (0x0000001e)
   DW_AT_frame_base [DW_FORM_exprloc] (<0x1> 55 )
   DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x000000ae] =
"mi_t11_issudebugtest.ABC2_AA")
   DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000cb] = "AA")
   DW_AT_decl_line [DW_FORM_data1] (16)
DW_AT_external [DW_FORM_flag_present] (true)

It's part (a member) of this type:
DW_TAG_structure_type [2] *
   DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000065] =
"issudebugtest.ABC")
  DW_AT_byte_size [DW_FORM_data1] (0x08)

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.

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.

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

Regards,
Abid

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:
     int INSTANCEFIELD;
     static int STATICFIELD;
     public:
     void INSTANCEMETHOD() {
         INSTANCEFIELD++;
     }
     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.

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.

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

Thanks.

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:
   int INSTANCEFIELD;
   static int STATICFIELD;
   public:
   void INSTANCEMETHOD() {
       INSTANCEFIELD++;
   }
   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.

Greg

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().

Shouldn't that be SBFunction::GetMemberFunction() ?

If you can hint at where this info is stored that would be great. I looked at Function but couldn't figure it out.

Besides that, happen to know how I can get the dw_at_name from dwarf function to SBFunction? Atm it seems to go through the demangler in Function, which fails (there isn't one) and just returns the symbol name even though the info is there.