[Lldb-commits] [PATCH] D13224: [DWARFASTParserClang] Strengthen incomplete type handling.

Siva Chandra via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 7 09:07:08 PDT 2015


sivachandra added a comment.

I will use an example to explain the problem that this patch is trying to solve.

class.h:

  class C
  {
  public:
      C () {
          c = 0;
      }
  
      virtual int method();
  
  private:
      int c;
  };

class.cpp:

  #include "class.h"
  
  int
  C::method ()
  {
      return c;
  }

main.cpp:

  #include "class.h"
  
  int
  main ()
  {
    C c;
  
    return c.method();
  }

Compile as follows:

  g++|clang++ -g class.cpp main.cpp # on mac you will require -flimit-debug-info

The interesting DWARF for the CU main.cpp is here:

  < 1><0x00000029>    DW_TAG_class_type
                      DW_AT_name                  "C"
                      DW_AT_declaration           yes(1)
                      DW_AT_sibling               <0x00000041>
  < 2><0x00000030>      DW_TAG_subprogram
                        DW_AT_external              yes(1)
                        DW_AT_name                  "C"
                        DW_AT_decl_file             0x00000001 class.h
                        DW_AT_decl_line             0x00000005
                        DW_AT_accessibility         DW_ACCESS_public
                        DW_AT_declaration           yes(1)
                        DW_AT_object_pointer        <0x0000003a>
  < 3><0x0000003a>        DW_TAG_formal_parameter
                          DW_AT_type                  <0x00000041>
                          DW_AT_artificial            yes(1)

As you can see, there is a method declaration under a class declaration (not definition). The same CU also has subprogram DIEs as follows:

  < 1><0x00000047>    DW_TAG_subprogram
                      DW_AT_specification         <0x00000030>
                      DW_AT_inline                DW_INL_declared_not_inlined
                      DW_AT_object_pointer        <0x00000055>
                      DW_AT_sibling               <0x0000005f>
  < 2><0x00000055>      DW_TAG_formal_parameter
                        DW_AT_name                  "this"
                        DW_AT_type                  <0x0000005f>
                        DW_AT_artificial            yes(1)
  < 1><0x0000005f>    DW_TAG_const_type
                      DW_AT_type                  <0x00000041>
  < 1><0x00000064>    DW_TAG_subprogram
                      DW_AT_abstract_origin       <0x00000047>
                      DW_AT_linkage_name          "_ZN1CC2Ev"
                      DW_AT_low_pc                0x00400640
                      DW_AT_high_pc               <offset-from-lowpc>32
                      DW_AT_frame_base            len 0x0001: 9c: DW_OP_call_frame_cfa
                      DW_AT_object_pointer        <0x00000087>
                      DW_AT_GNU_all_call_sites    yes(1)
                      DW_AT_sibling               <0x00000090>
  < 2><0x00000087>      DW_TAG_formal_parameter
                        DW_AT_abstract_origin       <0x00000055>
                        DW_AT_location              len 0x0002: 9168: DW_OP_fbreg -24

The DWARF for the CU class.cpp has the full definition of the class (with all its methods), but does not have subprogram DIEs which refer to the methods in the class definition. So, when stopped in C::C, the context resolves to an incomplete class for which a full definition also exists. This patch is essentially saying, "use the complete definition of the class when you find its incomplete definition."


http://reviews.llvm.org/D13224





More information about the lldb-commits mailing list