Skip to content

Commit eef7a76

Browse files
authored
[lldb][DWARFASTParserClang] Simplify obsolete error condition for malformed array member type offsets (llvm#160132)
First time check was introduced in `fa3ab4599d717feedbb83e08e7f654913942520b` to work around a debug-info generation bug in Clang. This bug was fixed in Clang-4. The check has since been adjusted (first in `808ff186f6a6ba1fd38cc7e00697cd82f4afe540`, and then most recently in `370db9c62910195e664e82dde6f0adb3e255a4fd`). This check is getting quite convoluted, and all it does is turn an `array[1]` into an `array[0]` type when it is deemed correct. At this point the workaround probably never fires, apart from actually valid codegen. This patch removes the special conditions and emits the error specifically in those cases where we know the DWARF is malformed. Added some shell tests for the error case.
1 parent 2936a2c commit eef7a76

File tree

6 files changed

+427
-41
lines changed

6 files changed

+427
-41
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3126,43 +3126,6 @@ void DWARFASTParserClang::ParseSingleMember(
31263126
if (!member_clang_type.IsCompleteType())
31273127
member_clang_type.GetCompleteType();
31283128

3129-
{
3130-
// Older versions of clang emit the same DWARF for array[0] and array[1]. If
3131-
// the current field is at the end of the structure, then there is
3132-
// definitely no room for extra elements and we override the type to
3133-
// array[0]. This was fixed by f454dfb6b5af.
3134-
CompilerType member_array_element_type;
3135-
uint64_t member_array_size;
3136-
bool member_array_is_incomplete;
3137-
3138-
if (member_clang_type.IsArrayType(&member_array_element_type,
3139-
&member_array_size,
3140-
&member_array_is_incomplete) &&
3141-
!member_array_is_incomplete) {
3142-
uint64_t parent_byte_size =
3143-
parent_die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX);
3144-
3145-
// If the attrs.member_byte_offset is still set to UINT32_MAX this means
3146-
// that the DW_TAG_member didn't have a DW_AT_data_member_location, so
3147-
// don't emit an error if this is the case.
3148-
if (attrs.member_byte_offset != UINT32_MAX &&
3149-
attrs.member_byte_offset >= parent_byte_size) {
3150-
if (member_array_size != 1 &&
3151-
(member_array_size != 0 ||
3152-
attrs.member_byte_offset > parent_byte_size)) {
3153-
module_sp->ReportError(
3154-
"{0:x8}: DW_TAG_member '{1}' refers to type {2:x16}"
3155-
" which extends beyond the bounds of {3:x8}",
3156-
die.GetID(), attrs.name,
3157-
attrs.encoding_form.Reference().GetOffset(), parent_die.GetID());
3158-
}
3159-
3160-
member_clang_type =
3161-
m_ast.CreateArrayType(member_array_element_type, 0, false);
3162-
}
3163-
}
3164-
}
3165-
31663129
TypeSystemClang::RequireCompleteType(member_clang_type);
31673130

31683131
clang::FieldDecl *field_decl = TypeSystemClang::AddFieldToRecordType(
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# This is DWARF where we placed an incomplete type
2+
# at an offset that is the parent DW_AT_byte_size. Check
3+
# that we don't report an error in such cases.
4+
#
5+
# DW_TAG_compile_unit
6+
# DW_AT_name ("main.cpp")
7+
# DW_AT_language (DW_LANG_C)
8+
#
9+
# DW_TAG_structure_type
10+
# DW_AT_name ("Incomplete")
11+
# DW_AT_external (true)
12+
#
13+
# DW_TAG_structure_type
14+
# DW_AT_name ("Foo")
15+
# DW_AT_byte_size (0x04)
16+
#
17+
# DW_TAG_member
18+
# DW_AT_name ("mem")
19+
# DW_AT_data_member_location ("0x04")
20+
# DW_AT_type (0x00000011 "Incomplete")
21+
#
22+
# NULL
23+
#
24+
# NULL
25+
26+
# RUN: yaml2obj %s > %t
27+
# RUN: lldb-test symbols --name=Foo --find=type %t 2>&1 | FileCheck %s
28+
29+
# CHECK: Found 1 types:
30+
31+
--- !ELF
32+
FileHeader:
33+
Class: ELFCLASS64
34+
Data: ELFDATA2LSB
35+
Type: ET_EXEC
36+
Machine: EM_X86_64
37+
DWARF:
38+
debug_str:
39+
- main.cpp
40+
- Incomplete
41+
- Foo
42+
- mem
43+
debug_abbrev:
44+
- ID: 0
45+
Table:
46+
- Code: 0x1
47+
Tag: DW_TAG_compile_unit
48+
Children: DW_CHILDREN_yes
49+
Attributes:
50+
- Attribute: DW_AT_name
51+
Form: DW_FORM_strp
52+
- Attribute: DW_AT_language
53+
Form: DW_FORM_udata
54+
- Code: 0x2
55+
Tag: DW_TAG_structure_type
56+
Children: DW_CHILDREN_no
57+
Attributes:
58+
- Attribute: DW_AT_name
59+
Form: DW_FORM_strp
60+
- Attribute: DW_AT_external
61+
Form: DW_FORM_flag_present
62+
- Code: 0x3
63+
Tag: DW_TAG_structure_type
64+
Children: DW_CHILDREN_yes
65+
Attributes:
66+
- Attribute: DW_AT_name
67+
Form: DW_FORM_strp
68+
- Attribute: DW_AT_byte_size
69+
Form: DW_FORM_data1
70+
- Code: 0x4
71+
Tag: DW_TAG_member
72+
Children: DW_CHILDREN_no
73+
Attributes:
74+
- Attribute: DW_AT_name
75+
Form: DW_FORM_strp
76+
- Attribute: DW_AT_type
77+
Form: DW_FORM_ref4
78+
- Attribute: DW_AT_data_member_location
79+
Form: DW_FORM_data1
80+
debug_info:
81+
- Version: 4
82+
AbbrevTableID: 0
83+
AbbrOffset: 0x0
84+
AddrSize: 8
85+
Entries:
86+
- AbbrCode: 0x1
87+
Values:
88+
- Value: 0x0
89+
- Value: 0x2
90+
- AbbrCode: 0x2
91+
Values:
92+
- Value: 0x9
93+
- AbbrCode: 0x3
94+
Values:
95+
- Value: 0x14
96+
- Value: 0x04
97+
- AbbrCode: 0x4
98+
Values:
99+
- Value: 0x18
100+
- Value: 0x11
101+
- Value: 0x04
102+
- AbbrCode: 0x0
103+
- AbbrCode: 0x0
104+
...
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# This is malformed DWARF where we placed a non-zero sized type
2+
# at an offset that is larger the parent DW_AT_byte_size. Check
3+
# that we report an error in such cases.
4+
#
5+
# DW_TAG_compile_unit
6+
# DW_AT_name ("main.cpp")
7+
# DW_AT_language (DW_LANG_C)
8+
#
9+
# DW_TAG_base_type
10+
# DW_AT_name ("int")
11+
# DW_AT_encoding (DW_ATE_signed)
12+
# DW_AT_byte_size (0x04)
13+
#
14+
# DW_TAG_structure_type
15+
# DW_AT_name ("Foo")
16+
# DW_AT_byte_size (0x04)
17+
#
18+
# DW_TAG_member
19+
# DW_AT_name ("mem")
20+
# DW_AT_data_member_location ("0x05")
21+
# DW_AT_type (0x00000011 "int")
22+
#
23+
# NULL
24+
#
25+
# NULL
26+
27+
# RUN: yaml2obj %s > %t
28+
# RUN: lldb-test symbols --name=Foo --find=type %t 2>&1 | FileCheck %s
29+
30+
# CHECK: Found 1 types:
31+
32+
--- !ELF
33+
FileHeader:
34+
Class: ELFCLASS64
35+
Data: ELFDATA2LSB
36+
Type: ET_EXEC
37+
Machine: EM_X86_64
38+
DWARF:
39+
debug_str:
40+
- main.cpp
41+
- int
42+
- Foo
43+
- mem
44+
debug_abbrev:
45+
- ID: 0
46+
Table:
47+
- Code: 0x1
48+
Tag: DW_TAG_compile_unit
49+
Children: DW_CHILDREN_yes
50+
Attributes:
51+
- Attribute: DW_AT_name
52+
Form: DW_FORM_strp
53+
- Attribute: DW_AT_language
54+
Form: DW_FORM_udata
55+
- Code: 0x2
56+
Tag: DW_TAG_base_type
57+
Children: DW_CHILDREN_no
58+
Attributes:
59+
- Attribute: DW_AT_name
60+
Form: DW_FORM_strp
61+
- Attribute: DW_AT_encoding
62+
Form: DW_FORM_data1
63+
- Attribute: DW_AT_byte_size
64+
Form: DW_FORM_data1
65+
- Code: 0x3
66+
Tag: DW_TAG_structure_type
67+
Children: DW_CHILDREN_yes
68+
Attributes:
69+
- Attribute: DW_AT_name
70+
Form: DW_FORM_strp
71+
- Attribute: DW_AT_byte_size
72+
Form: DW_FORM_data1
73+
- Code: 0x4
74+
Tag: DW_TAG_member
75+
Children: DW_CHILDREN_no
76+
Attributes:
77+
- Attribute: DW_AT_name
78+
Form: DW_FORM_strp
79+
- Attribute: DW_AT_type
80+
Form: DW_FORM_ref4
81+
- Attribute: DW_AT_data_member_location
82+
Form: DW_FORM_data1
83+
debug_info:
84+
- Version: 4
85+
AbbrevTableID: 0
86+
AbbrOffset: 0x0
87+
AddrSize: 8
88+
Entries:
89+
- AbbrCode: 0x1
90+
Values:
91+
- Value: 0x0
92+
- Value: 0x2
93+
- AbbrCode: 0x2
94+
Values:
95+
- Value: 0x9
96+
- Value: 0x5
97+
- Value: 0x4
98+
- AbbrCode: 0x3
99+
Values:
100+
- Value: 0x0d
101+
- Value: 0x04
102+
- AbbrCode: 0x4
103+
Values:
104+
- Value: 0x11
105+
- Value: 0x11
106+
- Value: 0x05
107+
- AbbrCode: 0x0
108+
- AbbrCode: 0x0
109+
...
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# This is malformed DWARF where we placed a non-zero sized type
2+
# at an offset that is the parent DW_AT_byte_size. Check
3+
# that we report an error in such cases.
4+
#
5+
# DW_TAG_compile_unit
6+
# DW_AT_name ("main.cpp")
7+
# DW_AT_language (DW_LANG_C)
8+
#
9+
# DW_TAG_base_type
10+
# DW_AT_name ("int")
11+
# DW_AT_encoding (DW_ATE_signed)
12+
# DW_AT_byte_size (0x04)
13+
#
14+
# DW_TAG_structure_type
15+
# DW_AT_name ("Foo")
16+
# DW_AT_byte_size (0x04)
17+
#
18+
# DW_TAG_member
19+
# DW_AT_name ("mem")
20+
# DW_AT_data_member_location ("0x04")
21+
# DW_AT_type (0x00000011 "int")
22+
#
23+
# NULL
24+
#
25+
# NULL
26+
27+
# RUN: yaml2obj %s > %t
28+
# RUN: lldb-test symbols --name=Foo --find=type %t 2>&1 | FileCheck %s
29+
30+
# CHECK: Found 1 types:
31+
32+
--- !ELF
33+
FileHeader:
34+
Class: ELFCLASS64
35+
Data: ELFDATA2LSB
36+
Type: ET_EXEC
37+
Machine: EM_X86_64
38+
DWARF:
39+
debug_str:
40+
- main.cpp
41+
- int
42+
- Foo
43+
- mem
44+
debug_abbrev:
45+
- ID: 0
46+
Table:
47+
- Code: 0x1
48+
Tag: DW_TAG_compile_unit
49+
Children: DW_CHILDREN_yes
50+
Attributes:
51+
- Attribute: DW_AT_name
52+
Form: DW_FORM_strp
53+
- Attribute: DW_AT_language
54+
Form: DW_FORM_udata
55+
- Code: 0x2
56+
Tag: DW_TAG_base_type
57+
Children: DW_CHILDREN_no
58+
Attributes:
59+
- Attribute: DW_AT_name
60+
Form: DW_FORM_strp
61+
- Attribute: DW_AT_encoding
62+
Form: DW_FORM_data1
63+
- Attribute: DW_AT_byte_size
64+
Form: DW_FORM_data1
65+
- Code: 0x3
66+
Tag: DW_TAG_structure_type
67+
Children: DW_CHILDREN_yes
68+
Attributes:
69+
- Attribute: DW_AT_name
70+
Form: DW_FORM_strp
71+
- Attribute: DW_AT_byte_size
72+
Form: DW_FORM_data1
73+
- Code: 0x4
74+
Tag: DW_TAG_member
75+
Children: DW_CHILDREN_no
76+
Attributes:
77+
- Attribute: DW_AT_name
78+
Form: DW_FORM_strp
79+
- Attribute: DW_AT_type
80+
Form: DW_FORM_ref4
81+
- Attribute: DW_AT_data_member_location
82+
Form: DW_FORM_data1
83+
debug_info:
84+
- Version: 4
85+
AbbrevTableID: 0
86+
AbbrOffset: 0x0
87+
AddrSize: 8
88+
Entries:
89+
- AbbrCode: 0x1
90+
Values:
91+
- Value: 0x0
92+
- Value: 0x2
93+
- AbbrCode: 0x2
94+
Values:
95+
- Value: 0x9
96+
- Value: 0x5
97+
- Value: 0x4
98+
- AbbrCode: 0x3
99+
Values:
100+
- Value: 0x0d
101+
- Value: 0x04
102+
- AbbrCode: 0x4
103+
Values:
104+
- Value: 0x11
105+
- Value: 0x11
106+
- Value: 0x04
107+
- AbbrCode: 0x0
108+
- AbbrCode: 0x0
109+
...

lldb/test/Shell/SymbolFile/DWARF/union-types-no-member-location.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,10 @@
4848
# RUN: yaml2obj %s > %t
4949
# RUN: lldb-test symbols --name=UnionType --find=type %t > %t.stdout
5050
# RUN: cat %t.stdout | FileCheck --check-prefix=STDOUT %s
51-
# RUN: lldb-test symbols --name=UnionType --find=type %t 2> %t.stderr
52-
# RUN: cat %t.stderr | FileCheck --allow-empty --check-prefix=STDERR %s
5351

5452
# STDOUT: Found 1 types:
5553
# STDOUT: {{(0x)?[0-9a-fA-F]+}}: Type{0x0000002b} , name = "UnionType", size = 32, compiler_type = 0x{{[0-9a-fA-F]+}} union UnionType {
5654

57-
# STDERR-NOT: error: union-types-no-member-location.yaml.tmp 0x00000031: DW_TAG_member 'array' refers to type 0x000000000000001f which extends beyond the bounds of 0x0000002b
58-
5955
--- !ELF
6056
FileHeader:
6157
Class: ELFCLASS64

0 commit comments

Comments
 (0)