[Lldb-commits] [lldb] 1956cf1 - [lldb/DWARF] Don't treat class declarations with children as definitions

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 27 03:58:44 PDT 2020


Author: Pavel Labath
Date: 2020-07-27T12:58:22+02:00
New Revision: 1956cf1042d3c406d9e9cefe47d3b43adf2bdbe1

URL: https://github.com/llvm/llvm-project/commit/1956cf1042d3c406d9e9cefe47d3b43adf2bdbe1
DIFF: https://github.com/llvm/llvm-project/commit/1956cf1042d3c406d9e9cefe47d3b43adf2bdbe1.diff

LOG: [lldb/DWARF] Don't treat class declarations with children as definitions

Summary:
This effectively reverts r188124, which added code to handle
(DW_AT_)declarations of structures with some kinds of children as
definitions. The commit message claims this is a workaround for some
kind of debug info produced by gcc. However, it does not go into
specifics, so it's hard to reproduce or verify that this is indeed still a
problem.

Having this code is definitely a problem though, because it mistakenly
declares incomplete dwarf declarations to be complete. Both clang (with
-flimit-debug-info) and gcc (by default) generate DW_AT_declarations of
structs with children. This happens when full debug info for a class is
not emitted in a given compile unit (e.g. because of vtable homing), but
the class has inline methods which are used in the given compile unit.
In that case, the compilers emit a DW_AT_declaration of a class, but
add a DW_TAG_subprogram child to it to describe the inlined instance of
the method.

Even though the class tag has some children, it definitely does not
contain enough information to construct a full class definition (most
notably, it lacks any members). Keeping the class as incomplete allows
us to search for a real definition in other modules, helping the
-flimit-debug-info flow. And in case the definition is not found we can
display a error message saying that, instead of just showing an empty
struct.

Reviewers: clayborg, aprantl, JDevlieghere, shafik

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D83302

Added: 
    lldb/test/Shell/SymbolFile/DWARF/DW_AT_declaration-with-children.s

Modified: 
    lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
    lldb/test/API/functionalities/limit-debug-info/TestLimitDebugInfo.py
    lldb/test/API/functionalities/limit-debug-info/main.cpp
    lldb/test/API/functionalities/limit-debug-info/one.cpp
    lldb/test/API/functionalities/limit-debug-info/onetwo.h
    lldb/test/API/functionalities/limit-debug-info/two.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 35e7c34734e2..7e3628504727 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1641,33 +1641,6 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
   dwarf->GetUniqueDWARFASTTypeMap().Insert(unique_typename,
                                            *unique_ast_entry_up);
 
-  if (attrs.is_forward_declaration && die.HasChildren()) {
-    // Check to see if the DIE actually has a definition, some version of
-    // GCC will
-    // emit DIEs with DW_AT_declaration set to true, but yet still have
-    // subprogram, members, or inheritance, so we can't trust it
-    DWARFDIE child_die = die.GetFirstChild();
-    while (child_die) {
-      switch (child_die.Tag()) {
-      case DW_TAG_inheritance:
-      case DW_TAG_subprogram:
-      case DW_TAG_member:
-      case DW_TAG_APPLE_property:
-      case DW_TAG_class_type:
-      case DW_TAG_structure_type:
-      case DW_TAG_enumeration_type:
-      case DW_TAG_typedef:
-      case DW_TAG_union_type:
-        child_die.Clear();
-        attrs.is_forward_declaration = false;
-        break;
-      default:
-        child_die = child_die.GetSibling();
-        break;
-      }
-    }
-  }
-
   if (!attrs.is_forward_declaration) {
     // Always start the definition for a class type so that if the class
     // has child classes or types that require the class to be created

diff  --git a/lldb/test/API/functionalities/limit-debug-info/TestLimitDebugInfo.py b/lldb/test/API/functionalities/limit-debug-info/TestLimitDebugInfo.py
index 9408ad6eee1d..aa383d0005e4 100644
--- a/lldb/test/API/functionalities/limit-debug-info/TestLimitDebugInfo.py
+++ b/lldb/test/API/functionalities/limit-debug-info/TestLimitDebugInfo.py
@@ -38,7 +38,8 @@ def test_one_and_two_debug(self):
 
         self._check_debug_info_is_limited(target)
 
-        self.registerSharedLibrariesWithTarget(target, ["one", "two"])
+        lldbutil.run_to_name_breakpoint(self, "main",
+                extra_images=["one", "two"])
 
         # But when other shared libraries are loaded, we should be able to see
         # all members.
@@ -58,6 +59,10 @@ def test_one_and_two_debug(self):
         self.expect_expr("array_of_two[2].one[2].member", result_value="174")
         self.expect_expr("array_of_two[2].member", result_value="274")
 
+        self.expect_expr("get_one().member", result_value="124")
+        self.expect_expr("get_two().one().member", result_value="124")
+        self.expect_expr("get_two().member", result_value="224")
+
     @skipIf(bugnumber="pr46284", debug_info="gmodules")
     @skipIfWindows # Clang emits type info even with -flimit-debug-info
     def test_two_debug(self):
@@ -66,7 +71,8 @@ def test_two_debug(self):
 
         self._check_debug_info_is_limited(target)
 
-        self.registerSharedLibrariesWithTarget(target, ["one", "two"])
+        lldbutil.run_to_name_breakpoint(self, "main",
+                extra_images=["one", "two"])
 
         # This time, we should only see the members from the second library.
         self.expect_expr("inherits_from_one.member", result_value="47")
@@ -91,6 +97,12 @@ def test_two_debug(self):
                 substrs=["no member named 'member' in 'array::One'"])
         self.expect_expr("array_of_two[2].member", result_value="274")
 
+        self.expect("expr get_one().member", error=True,
+                substrs=["calling 'get_one' with incomplete return type 'result::One'"])
+        self.expect("expr get_two().one().member", error=True,
+                substrs=["calling 'one' with incomplete return type 'result::One'"])
+        self.expect_expr("get_two().member", result_value="224")
+
     @skipIf(bugnumber="pr46284", debug_info="gmodules")
     @skipIfWindows # Clang emits type info even with -flimit-debug-info
     def test_one_debug(self):
@@ -99,7 +111,8 @@ def test_one_debug(self):
 
         self._check_debug_info_is_limited(target)
 
-        self.registerSharedLibrariesWithTarget(target, ["one", "two"])
+        lldbutil.run_to_name_breakpoint(self, "main",
+                extra_images=["one", "two"])
 
         # In this case we should only see the members from the second library.
         # Note that we cannot see inherits_from_two.one because without debug
@@ -126,3 +139,9 @@ def test_one_debug(self):
                 substrs=["no member named 'one' in 'array::Two'"])
         self.expect("expr array_of_two[2].member", error=True,
                 substrs=["no member named 'member' in 'array::Two'"])
+
+        self.expect_expr("get_one().member", result_value="124")
+        self.expect("expr get_two().one().member", error=True,
+                substrs=["calling 'get_two' with incomplete return type 'result::Two'"])
+        self.expect("expr get_two().member", error=True,
+                substrs=["calling 'get_two' with incomplete return type 'result::Two'"])

diff  --git a/lldb/test/API/functionalities/limit-debug-info/main.cpp b/lldb/test/API/functionalities/limit-debug-info/main.cpp
index 0a25de13d9fb..1aad7e6f1e61 100644
--- a/lldb/test/API/functionalities/limit-debug-info/main.cpp
+++ b/lldb/test/API/functionalities/limit-debug-info/main.cpp
@@ -25,4 +25,7 @@ struct TwoAsMember {
 array::One array_of_one[3];
 array::Two array_of_two[3];
 
-int main() { return 0; }
+result::One get_one() { return result::One(124); }
+result::Two get_two() { return result::Two(224); }
+
+int main() { return get_one().member; }

diff  --git a/lldb/test/API/functionalities/limit-debug-info/one.cpp b/lldb/test/API/functionalities/limit-debug-info/one.cpp
index c1eb6310dd67..70353a084edc 100644
--- a/lldb/test/API/functionalities/limit-debug-info/one.cpp
+++ b/lldb/test/API/functionalities/limit-debug-info/one.cpp
@@ -3,3 +3,6 @@
 One::~One() = default;
 member::One::~One() = default;
 array::One::~One() = default;
+
+result::One::One(int member) : member(member) {}
+result::One::~One() = default;

diff  --git a/lldb/test/API/functionalities/limit-debug-info/onetwo.h b/lldb/test/API/functionalities/limit-debug-info/onetwo.h
index 67609dd7ff61..24a18f6a5dcc 100644
--- a/lldb/test/API/functionalities/limit-debug-info/onetwo.h
+++ b/lldb/test/API/functionalities/limit-debug-info/onetwo.h
@@ -39,3 +39,18 @@ struct Two {
   virtual ~Two();
 };
 } // namespace array
+
+namespace result {
+struct One {
+  int member;
+  One(int member);
+  virtual ~One();
+};
+
+struct Two {
+  int member;
+  Two(int member);
+  One one() const;
+  virtual ~Two();
+};
+} // namespace result

diff  --git a/lldb/test/API/functionalities/limit-debug-info/two.cpp b/lldb/test/API/functionalities/limit-debug-info/two.cpp
index 04683da6e9cc..468cb91f6a5c 100644
--- a/lldb/test/API/functionalities/limit-debug-info/two.cpp
+++ b/lldb/test/API/functionalities/limit-debug-info/two.cpp
@@ -3,3 +3,7 @@
 Two::~Two() = default;
 member::Two::~Two() = default;
 array::Two::~Two() = default;
+
+result::Two::Two(int member) : member(member) {}
+result::Two::~Two() = default;
+result::One result::Two::one() const { return One(member - 100); }

diff  --git a/lldb/test/Shell/SymbolFile/DWARF/DW_AT_declaration-with-children.s b/lldb/test/Shell/SymbolFile/DWARF/DW_AT_declaration-with-children.s
new file mode 100644
index 000000000000..7ed33ce50297
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/DW_AT_declaration-with-children.s
@@ -0,0 +1,160 @@
+# Test that a forward-declared (DW_AT_declaration) structure is treated as a
+# forward-declaration even if it has children. These types can be produced due
+# to vtable-based type homing, or other -flimit-debug-info optimizations.
+
+# REQUIRES: x86
+
+# RUN: llvm-mc --triple x86_64-pc-linux %s --filetype=obj > %t
+# RUN: %lldb %t -o "expr a" -o exit 2>&1 | FileCheck %s --check-prefix=EXPR
+# RUN: %lldb %t -o "target var a" -o exit 2>&1 | FileCheck %s --check-prefix=VAR
+
+# EXPR: incomplete type 'A' where a complete type is required
+
+# FIXME: This should also produce some kind of an error.
+# VAR: (A) a = {}
+
+        .text
+_ZN1AC2Ev:
+        retq
+.LZN1AC2Ev_end:
+
+        .data
+a:
+        .quad   $_ZTV1A+16
+        .quad   $0xdeadbeef
+
+        .section        .debug_abbrev,"", at progbits
+        .byte   1                               # Abbreviation Code
+        .byte   17                              # DW_TAG_compile_unit
+        .byte   1                               # DW_CHILDREN_yes
+        .byte   37                              # DW_AT_producer
+        .byte   8                               # DW_FORM_string
+        .byte   17                              # DW_AT_low_pc
+        .byte   1                               # DW_FORM_addr
+        .byte   18                              # DW_AT_high_pc
+        .byte   6                               # DW_FORM_data4
+        .byte   0                               # EOM(1)
+        .byte   0                               # EOM(2)
+        .byte   2                               # Abbreviation Code
+        .byte   52                              # DW_TAG_variable
+        .byte   0                               # DW_CHILDREN_no
+        .byte   3                               # DW_AT_name
+        .byte   8                               # DW_FORM_string
+        .byte   73                              # DW_AT_type
+        .byte   19                              # DW_FORM_ref4
+        .byte   2                               # DW_AT_location
+        .byte   24                              # DW_FORM_exprloc
+        .byte   0                               # EOM(1)
+        .byte   0                               # EOM(2)
+        .byte   3                               # Abbreviation Code
+        .byte   19                              # DW_TAG_structure_type
+        .byte   1                               # DW_CHILDREN_yes
+        .byte   3                               # DW_AT_name
+        .byte   8                               # DW_FORM_string
+        .byte   60                              # DW_AT_declaration
+        .byte   25                              # DW_FORM_flag_present
+        .byte   0                               # EOM(1)
+        .byte   0                               # EOM(2)
+        .byte   4                               # Abbreviation Code
+        .byte   46                              # DW_TAG_subprogram
+        .byte   1                               # DW_CHILDREN_yes
+        .byte   3                               # DW_AT_name
+        .byte   8                               # DW_FORM_string
+        .byte   60                              # DW_AT_declaration
+        .byte   25                              # DW_FORM_flag_present
+        .byte   0                               # EOM(1)
+        .byte   0                               # EOM(2)
+        .byte   5                               # Abbreviation Code
+        .byte   5                               # DW_TAG_formal_parameter
+        .byte   0                               # DW_CHILDREN_no
+        .byte   73                              # DW_AT_type
+        .byte   19                              # DW_FORM_ref4
+        .byte   52                              # DW_AT_artificial
+        .byte   25                              # DW_FORM_flag_present
+        .byte   0                               # EOM(1)
+        .byte   0                               # EOM(2)
+        .byte   8                               # Abbreviation Code
+        .byte   15                              # DW_TAG_pointer_type
+        .byte   0                               # DW_CHILDREN_no
+        .byte   73                              # DW_AT_type
+        .byte   19                              # DW_FORM_ref4
+        .byte   0                               # EOM(1)
+        .byte   0                               # EOM(2)
+        .byte   10                              # Abbreviation Code
+        .byte   46                              # DW_TAG_subprogram
+        .byte   1                               # DW_CHILDREN_yes
+        .byte   17                              # DW_AT_low_pc
+        .byte   1                               # DW_FORM_addr
+        .byte   18                              # DW_AT_high_pc
+        .byte   6                               # DW_FORM_data4
+        .byte   64                              # DW_AT_frame_base
+        .byte   24                              # DW_FORM_exprloc
+        .byte   100                             # DW_AT_object_pointer
+        .byte   19                              # DW_FORM_ref4
+        .byte   71                              # DW_AT_specification
+        .byte   19                              # DW_FORM_ref4
+        .byte   0                               # EOM(1)
+        .byte   0                               # EOM(2)
+        .byte   11                              # Abbreviation Code
+        .byte   5                               # DW_TAG_formal_parameter
+        .byte   0                               # DW_CHILDREN_no
+        .byte   2                               # DW_AT_location
+        .byte   24                              # DW_FORM_exprloc
+        .byte   3                               # DW_AT_name
+        .byte   8                               # DW_FORM_string
+        .byte   73                              # DW_AT_type
+        .byte   19                              # DW_FORM_ref4
+        .byte   52                              # DW_AT_artificial
+        .byte   25                              # DW_FORM_flag_present
+        .byte   0                               # EOM(1)
+        .byte   0                               # EOM(2)
+        .byte   0                               # EOM(3)
+        .section        .debug_info,"", at progbits
+.Lcu_begin0:
+        .long   .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
+.Ldebug_info_start0:
+        .short  4                               # DWARF version number
+        .long   .debug_abbrev                   # Offset Into Abbrev. Section
+        .byte   8                               # Address Size (in bytes)
+        .byte   1                               # Abbrev [1] DW_TAG_compile_unit
+        .asciz  "Hand-written DWARF"            # DW_AT_producer
+        .quad   _ZN1AC2Ev                       # DW_AT_low_pc
+        .long   .LZN1AC2Ev_end-_ZN1AC2Ev        # DW_AT_high_pc
+        .byte   2                               # Abbrev [2] DW_TAG_variable
+        .asciz  "a"                             # DW_AT_name
+        .long   .LA-.Lcu_begin0                 # DW_AT_type
+        .byte   9                               # DW_AT_location
+        .byte   3
+        .quad   a
+.LA:
+        .byte   3                               # Abbrev [3] DW_TAG_structure_type
+        .asciz  "A"                             # DW_AT_name
+                                                # DW_AT_declaration
+        .byte   4                               # Abbrev [4] DW_TAG_subprogram
+        .asciz  "A"                             # DW_AT_name
+                                                # DW_AT_declaration
+        .byte   5                               # Abbrev [5] DW_TAG_formal_parameter
+        .long   .LAptr-.Lcu_begin0              # DW_AT_type
+                                                # DW_AT_artificial
+        .byte   0                               # End Of Children Mark
+        .byte   0                               # End Of Children Mark
+.LAptr:
+        .byte   8                               # Abbrev [8] DW_TAG_pointer_type
+        .long   .LA-.Lcu_begin0                 # DW_AT_type
+        .byte   10                              # Abbrev [10] DW_TAG_subprogram
+        .quad   _ZN1AC2Ev                       # DW_AT_low_pc
+        .long   .LZN1AC2Ev_end-_ZN1AC2Ev        # DW_AT_high_pc
+        .byte   1                               # DW_AT_frame_base
+        .byte   86
+        .long   147                             # DW_AT_object_pointer
+        .long   68                              # DW_AT_specification
+        .byte   11                              # Abbrev [11] DW_TAG_formal_parameter
+        .byte   2                               # DW_AT_location
+        .byte   145
+        .byte   120
+        .asciz  "this"                          # DW_AT_name
+        .long   .LAptr-.Lcu_begin0              # DW_AT_type
+                                                # DW_AT_artificial
+        .byte   0                               # End Of Children Mark
+        .byte   0                               # End Of Children Mark
+.Ldebug_info_end0:


        


More information about the lldb-commits mailing list