This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] While processing a struct die, store the method's address in its fn_field


[The tests in this patch depend on this patch:
https://sourceware.org/ml/gdb-patches/2014-11/msg00479.html.  Also, it
adds a new dwarf2 test which I am not very sure I got it right.]

While processing a struct die, store the method's address in its fn_field.

This enables calling the method when its physname is missing and its
minsym cannot be discovered, but its address (DW_AT_low_pc) is available.
For example, this happens for the operator() methods of c++11 lambdas.
Consider the following C++ code:

int
main ()
{
  auto lambda = [] (int j) { return j + 113; };
  return lambda (-113);
}

When compiled with g++, the DWARF corresponding to the lambda's operator()
shows up under the DWARF for the function main as follows:

DW_TAG_subprogram
  DW_AT_name                  "operator()"
  DW_AT_type                  <0x0000002d>
  DW_AT_artificial            yes(1)
  DW_AT_low_pc                0x00400566
  DW_AT_high_pc               <offset-from-lowpc>19
  DW_AT_frame_base            len 0x0001: 9c: DW_OP_call_frame_cfa
  DW_AT_object_pointer        <0x0000010f>
  DW_AT_GNU_all_call_sites    yes(1)
  DW_TAG_pointer_type
    DW_AT_byte_size             0x00000008
    DW_AT_type                  <0x000000b9>
  DW_TAG_formal_parameter
    DW_AT_name                  "__closure"
    DW_AT_type                  <0x0000011b>
    DW_AT_artificial            yes(1)
    DW_AT_location              len 0x0002: 9168: DW_OP_fbreg -24
  DW_TAG_const_type
    DW_AT_type                  <0x00000109>
  DW_TAG_formal_parameter
    DW_AT_name                  "j"
    DW_AT_decl_file             0x00000001
    DW_AT_decl_line             0x00000004
    DW_AT_type                  <0x0000002d>
    DW_AT_location              len 0x0002: 9164:DW_OP_fbreg -28

There is no physname and the minsym corresponding to the the operator()
method does not demangle to its qualified name as specified by the DWARF.
However, since DW_AT_low_pc is available, it can be used to create a value
corresponding to the method in value.c:value_fn_field and subsequently be
passed to call_function_by_hand to invoke it.

gdb/ChangeLog:

2014-11-24  Siva Chandra Reddy  <sivachandra@google.com>

        * dwarf2read.c (dwarf2_add_member_fn): Note the methods address
        if its DT_AT_low_pc is available.
        * gdbtypes.h (struct fn_field): New field ADDR.
        (TYPE_FN_FIELD_ADDR): New macro.
        * value.c (value_fn_field): Use address of the method if
        available.

gdb/testsuite/ChangeLog:

2014-11-24  Siva Chandra Reddy  <sivachandra@google.com>

        * gdb.dwarf2/dw2-member-function-addr.S: New file.
        * gdb.dwarf2/dw2-member-function-addr.exp: New file.

Attachment: member-function-addr-v1.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]