diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -1641,33 +1641,6 @@ 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 --- a/lldb/test/API/functionalities/limit-debug-info/TestLimitDebugInfo.py +++ b/lldb/test/API/functionalities/limit-debug-info/TestLimitDebugInfo.py @@ -38,7 +38,8 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 --- a/lldb/test/API/functionalities/limit-debug-info/main.cpp +++ b/lldb/test/API/functionalities/limit-debug-info/main.cpp @@ -25,4 +25,7 @@ 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 --- 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 --- a/lldb/test/API/functionalities/limit-debug-info/onetwo.h +++ b/lldb/test/API/functionalities/limit-debug-info/onetwo.h @@ -39,3 +39,18 @@ 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 --- 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 --- /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,"",@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,"",@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: