llvm.org GIT mirror llvm / 95621c2
[DWARF] Fixing a bug with processing of DWARF v5 indexed strings in Mach-O objects. Code to convert MachO - specific section debug section names to standard DWARF v5 section names was in the wrong place. Differential Revision: https://reviews.llvm.org/D35321 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307872 91177308-0d34-0410-b5e6-96231b3b80d8 Wolfgang Pieb 2 years ago
4 changed file(s) with 280 addition(s) and 77 deletion(s). Raw diff Collapse all Expand all
963963 Name = Name.substr(
964964 Name.find_first_not_of("._z")); // Skip ".", "z" and "_" prefixes.
965965
966 // Map platform specific debug section names to DWARF standard section
967 // names.
968 Name = Obj.mapDebugSectionName(Name);
969
966970 if (StringRef *SectionData = mapSectionToMember(Name)) {
967971 *SectionData = Data;
968972 if (Name == "debug_ranges") {
976980 } else if (Name == "debug_types.dwo") {
977981 TypesDWOSections[Section].Data = Data;
978982 }
979
980 // Map platform specific debug section names to DWARF standard section
981 // names.
982 Name = Obj.mapDebugSectionName(Name);
983983
984984 if (RelocatedSection == Obj.section_end())
985985 continue;
0 # Test object to verify dwarfdump handles v5 string offset tables in Mach-O.
1 # This is similar to dwarfdump-str-offsets.s with 2 CUs and 1 TU, but no
2 # split sections.
3 #
4 # To generate the test object:
5 # llvm-mc -triple i386-apple-darwin9 dwarfdump-str-offsets-macho.s -filetype=obj \
6 # -o dwarfdump-str-offsets-macho.o
7
8 .section __DWARF,__debug_str,regular,debug
9 Linfo_string:
10 .asciz "Handmade DWARF producer"
11 str_CU1:
12 .asciz "Compile_Unit_1"
13 str_CU1_dir:
14 .asciz "/home/test/CU1"
15 str_CU2:
16 .asciz "Compile_Unit_2"
17 str_CU2_dir:
18 .asciz "/home/test/CU2"
19 str_TU:
20 .asciz "Type_Unit"
21 str_TU_type:
22 .asciz "MyStruct"
23 str_Subprogram:
24 .asciz "MyFunc"
25 str_Variable1:
26 .asciz "MyVar1"
27 str_Variable2:
28 .asciz "MyVar2"
29 str_Variable3:
30 .asciz "MyVar3"
31
32 .section __DWARF,__debug_str_offs,regular,debug
33 Ldebug_str_offsets:
34 .long Ldebug_str_offsets_segment0_end-Ldebug_str_offsets_base0
35 .short 5 # DWARF version
36 .short 0 # Padding
37 Ldebug_str_offsets_base0:
38 .long str_producer
39 .long str_CU1
40 .long str_CU1_dir
41 .long str_Subprogram
42 .long str_Variable1
43 .long str_Variable2
44 .long str_Variable3
45 Ldebug_str_offsets_segment0_end:
46 # CU2's contribution
47 .long Ldebug_str_offsets_segment1_end-Ldebug_str_offsets_base1
48 .short 5 # DWARF version
49 .short 0 # Padding
50 Ldebug_str_offsets_base1:
51 .long str_producer
52 .long str_CU2
53 .long str_CU2_dir
54 Ldebug_str_offsets_segment1_end:
55 # The TU's contribution
56 .long Ldebug_str_offsets_segment2_end-Ldebug_str_offsets_base2
57 .short 5 # DWARF version
58 .short 0 # Padding
59 Ldebug_str_offsets_base2:
60 .long str_TU
61 .long str_TU_type
62 Ldebug_str_offsets_segment2_end:
63
64 .section __DWARF,__debug_abbrev,regular,debug
65 Lsection_abbrev:
66 .byte 0x01 # Abbrev code
67 .byte 0x11 # DW_TAG_compile_unit
68 .byte 0x01 # DW_CHILDREN_yes
69 .byte 0x25 # DW_AT_producer
70 .byte 0x1a # DW_FORM_strx
71 .byte 0x03 # DW_AT_name
72 .byte 0x1a # DW_FORM_strx
73 .byte 0x72 # DW_AT_str_offsets_base
74 .byte 0x17 # DW_FORM_sec_offset
75 .byte 0x1b # DW_AT_comp_dir
76 .byte 0x1a # DW_FORM_strx
77 .byte 0x00 # EOM(1)
78 .byte 0x00 # EOM(2)
79 .byte 0x02 # Abbrev code
80 .byte 0x41 # DW_TAG_type_unit
81 .byte 0x01 # DW_CHILDREN_yes
82 .byte 0x03 # DW_AT_name
83 .byte 0x1a # DW_FORM_strx
84 .byte 0x72 # DW_AT_str_offsets_base
85 .byte 0x17 # DW_FORM_sec_offset
86 .byte 0x00 # EOM(1)
87 .byte 0x00 # EOM(2)
88 .byte 0x03 # Abbrev code
89 .byte 0x13 # DW_TAG_structure_type
90 .byte 0x00 # DW_CHILDREN_no (no members)
91 .byte 0x03 # DW_AT_name
92 .byte 0x1a # DW_FORM_strx
93 .byte 0x00 # EOM(1)
94 .byte 0x00 # EOM(2)
95 .byte 0x04 # Abbrev code
96 .byte 0x2e # DW_TAG_subprogram
97 .byte 0x01 # DW_CHILDREN_yes
98 .byte 0x03 # DW_AT_name
99 .byte 0x25 # DW_FORM_strx1
100 .byte 0x00 # EOM(1)
101 .byte 0x00 # EOM(2)
102 .byte 0x05 # Abbrev code
103 .byte 0x34 # DW_TAG_variable
104 .byte 0x00 # DW_CHILDREN_no
105 .byte 0x03 # DW_AT_name
106 .byte 0x26 # DW_FORM_strx2
107 .byte 0x00 # EOM(1)
108 .byte 0x00 # EOM(2)
109 .byte 0x06 # Abbrev code
110 .byte 0x34 # DW_TAG_variable
111 .byte 0x00 # DW_CHILDREN_no
112 .byte 0x03 # DW_AT_name
113 .byte 0x27 # DW_FORM_strx3
114 .byte 0x00 # EOM(1)
115 .byte 0x00 # EOM(2)
116 .byte 0x07 # Abbrev code
117 .byte 0x34 # DW_TAG_variable
118 .byte 0x00 # DW_CHILDREN_no
119 .byte 0x03 # DW_AT_name
120 .byte 0x28 # DW_FORM_strx4
121 .byte 0x00 # EOM(1)
122 .byte 0x00 # EOM(2)
123 .byte 0x00 # EOM(3)
124
125 .section __DWARF,__debug_info,regular,debug
126 Lsection_info:
127 # DWARF v5 CU header.
128 .long CU1_5_end-CU1_5_version # Length of Unit
129 CU1_5_version:
130 .short 5 # DWARF version number
131 .byte 1 # DWARF Unit Type
132 .byte 8 # Address Size (in bytes)
133 .long 0 # Offset Into Abbrev. Section
134 # The compile-unit DIE, which has a DW_AT_producer, DW_AT_name,
135 # DW_AT_str_offsets and DW_AT_compdir.
136 .byte 1 # Abbreviation code
137 .byte 0 # The index of the producer string
138 .byte 1 # The index of the CU name string
139 .long Ldebug_str_offsets_base0-Ldebug_str_offsets
140 .byte 2 # The index of the comp dir string
141 # A subprogram DIE with DW_AT_name, using DW_FORM_strx1.
142 .byte 4 # Abbreviation code
143 .byte 3 # Subprogram name string (DW_FORM_strx1)
144 # A variable DIE with DW_AT_name, using DW_FORM_strx2.
145 .byte 5 # Abbreviation code
146 .short 0x0004 # Subprogram name string (DW_FORM_strx2)
147 # A variable DIE with DW_AT_name, using DW_FORM_strx3.
148 .byte 6 # Abbreviation code
149 .byte 5 # Subprogram name string (DW_FORM_strx3)
150 .short 0 # Subprogram name string (DW_FORM_strx3)
151 # A variable DIE with DW_AT_name, using DW_FORM_strx4.
152 .byte 7 # Abbreviation code
153 .quad 0x00000006 # Subprogram name string (DW_FORM_strx4)
154 .byte 0 # NULL
155 .byte 0 # NULL
156 .byte 0 # NULL
157 CU1_5_end:
158
159 # DWARF v5 CU header
160 .long CU2_5_end-CU2_5_version # Length of Unit
161 CU2_5_version:
162 .short 5 # DWARF version number
163 .byte 1 # DWARF Unit Type
164 .byte 8 # Address Size (in bytes)
165 .long 0 # Offset Into Abbrev. Section
166 # The compile-unit DIE, which has a DW_AT_producer, DW_AT_name,
167 # DW_AT_str_offsets and DW_AT_compdir.
168 .byte 1 # Abbreviation code
169 .byte 0 # The index of the producer string
170 .byte 1 # The index of the CU name string
171 .long Ldebug_str_offsets_base1-Ldebug_str_offsets
172 .byte 2 # The index of the comp dir string
173 .byte 0 # NULL
174 CU2_5_end:
175
176 .section __DWARF,__debug_types,regular,debug
177 # DWARF v5 Type unit header.
178 TU_5_start:
179 .long TU_5_end-TU_5_version # Length of Unit
180 TU_5_version:
181 .short 5 # DWARF version number
182 .byte 2 # DWARF Unit Type
183 .byte 8 # Address Size (in bytes)
184 .long 0 # Offset Into Abbrev. Section
185 .quad 0x0011223344556677 # Type Signature
186 .long TU_5_type-TU_5_start # Type offset
187 # The type-unit DIE, which has a name.
188 .byte 2 # Abbreviation code
189 .byte 0 # Index of the unit type name string
190 .long Ldebug_str_offsets_base2-Ldebug_str_offsets # offset into the str_offsets section
191 # The type DIE, which has a name.
192 TU_5_type:
193 .byte 3 # Abbreviation code
194 .byte 1 # Index of the type name string
195 .byte 0 # NULL
196 .byte 0 # NULL
197 TU_5_end:
198
199
200 .subsections_via_symbols
None RUN: llvm-dwarfdump %p/Inputs/dwarfdump-str-offsets.x86_64.o | FileCheck %s
0 RUN: llvm-dwarfdump %p/Inputs/dwarfdump-str-offsets.x86_64.o | FileCheck --check-prefix=COMMON \
1 RUN: --check-prefix=SPLIT %s
2 RUN: llvm-dwarfdump %p/Inputs/dwarfdump-str-offsets-macho.o | FileCheck --check-prefix=COMMON %s
13
24 ; We are using a hand-constructed object file and are interest in the correct
35 ; diplay of the DW_str_offsetsbase attribute, the correct display of strings
46 ; and the dump of the .debug_str_offsets[.dwo] table.
57 ;
68 ; Abbreviation for DW_AT_str_offsets_base
7 CHECK: .debug_abbrev contents:
8 CHECK-NOT: contents:
9 CHECK: DW_TAG_compile_unit
10 CHECK-NOT: DW_TAG
11 CHECK: DW_AT_str_offsets_base DW_FORM_sec_offset
9 COMMON: .debug_abbrev contents:
10 COMMON-NOT: contents:
11 COMMON: DW_TAG_compile_unit
12 COMMON-NOT: DW_TAG
13 COMMON: DW_AT_str_offsets_base DW_FORM_sec_offset
1214
1315 ; Verify that strings are displayed correctly as indexed strings
14 CHECK: .debug_info contents:
15 CHECK-NOT: contents:
16 CHECK: DW_TAG_compile_unit
17 CHECK-NEXT: DW_AT_producer [DW_FORM_strx] ( indexed (00000000) string = "Handmade DWARF producer")
18 CHECK-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "Compile_Unit_1")
19 CHECK-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000008)
20 CHECK-NEXT: DW_AT_comp_dir [DW_FORM_strx] ( indexed (00000002) string = "/home/test/CU1")
21 CHECK-NOT: NULL
22 CHECK: DW_TAG_subprogram
23 CHECK-NEXT: DW_AT_name [DW_FORM_strx1] ( indexed (00000003) string = "MyFunc")
24 CHECK-NOT: NULL
25 CHECK: DW_TAG_variable
26 CHECK-NEXT: DW_AT_name [DW_FORM_strx2] ( indexed (00000004) string = "MyVar1")
27 CHECK-NOT: NULL
28 CHECK: DW_TAG_variable
29 CHECK-NEXT: DW_AT_name [DW_FORM_strx3] ( indexed (00000005) string = "MyVar2")
30 CHECK-NOT: NULL
31 CHECK: DW_TAG_variable
32 CHECK-NEXT: DW_AT_name [DW_FORM_strx4] ( indexed (00000006) string = "MyVar3")
16 COMMON: .debug_info contents:
17 COMMON-NOT: contents:
18 COMMON: DW_TAG_compile_unit
19 COMMON-NEXT: DW_AT_producer [DW_FORM_strx] ( indexed (00000000) string = "Handmade DWARF producer")
20 COMMON-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "Compile_Unit_1")
21 COMMON-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000008)
22 COMMON-NEXT: DW_AT_comp_dir [DW_FORM_strx] ( indexed (00000002) string = "/home/test/CU1")
23 COMMON-NOT: NULL
24 COMMON: DW_TAG_subprogram
25 COMMON-NEXT: DW_AT_name [DW_FORM_strx1] ( indexed (00000003) string = "MyFunc")
26 COMMON-NOT: NULL
27 COMMON: DW_TAG_variable
28 COMMON-NEXT: DW_AT_name [DW_FORM_strx2] ( indexed (00000004) string = "MyVar1")
29 COMMON-NOT: NULL
30 COMMON: DW_TAG_variable
31 COMMON-NEXT: DW_AT_name [DW_FORM_strx3] ( indexed (00000005) string = "MyVar2")
32 COMMON-NOT: NULL
33 COMMON: DW_TAG_variable
34 COMMON-NEXT: DW_AT_name [DW_FORM_strx4] ( indexed (00000006) string = "MyVar3")
3335
3436 ; Second compile unit (b.cpp)
35 CHECK: DW_TAG_compile_unit
36 CHECK-NEXT: DW_AT_producer [DW_FORM_strx] ( indexed (00000000) string = "Handmade DWARF producer")
37 CHECK-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "Compile_Unit_2")
38 CHECK-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x0000002c)
39 CHECK-NEXT: DW_AT_comp_dir [DW_FORM_strx] ( indexed (00000002) string = "/home/test/CU2")
37 COMMON: DW_TAG_compile_unit
38 COMMON-NEXT: DW_AT_producer [DW_FORM_strx] ( indexed (00000000) string = "Handmade DWARF producer")
39 COMMON-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "Compile_Unit_2")
40 COMMON-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x0000002c)
41 COMMON-NEXT: DW_AT_comp_dir [DW_FORM_strx] ( indexed (00000002) string = "/home/test/CU2")
4042
4143 ; The split CU
42 CHECK: .debug_info.dwo contents:
43 CHECK-NOT: contents:
44 CHECK: DW_TAG_compile_unit
45 CHECK-NEXT: DW_AT_producer [DW_FORM_strx] ( indexed (00000000) string = "Handmade split DWARF producer")
46 CHECK-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "V5_split_compile_unit")
47 CHECK-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000008)
48 CHECK-NEXT: DW_AT_comp_dir [DW_FORM_strx] ( indexed (00000002) string = "/home/test/splitCU")
44 SPLIT: .debug_info.dwo contents:
45 SPLIT-NOT: contents:
46 SPLIT: DW_TAG_compile_unit
47 SPLIT-NEXT: DW_AT_producer [DW_FORM_strx] ( indexed (00000000) string = "Handmade split DWARF producer")
48 SPLIT-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "V5_split_compile_unit")
49 SPLIT-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000008)
50 SPLIT-NEXT: DW_AT_comp_dir [DW_FORM_strx] ( indexed (00000002) string = "/home/test/splitCU")
4951
5052 ; The type unit
51 CHECK: .debug_types contents:
52 CHECK: DW_TAG_type_unit
53 CHECK-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000000) string = "Type_Unit")
54 CHECK-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000040)
55 CHECK: DW_TAG_structure_type
56 CHECK-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "MyStruct")
53 COMMON: .debug_types contents:
54 COMMON: DW_TAG_type_unit
55 COMMON-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000000) string = "Type_Unit")
56 COMMON-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000040)
57 COMMON: DW_TAG_structure_type
58 COMMON-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "MyStruct")
5759
5860 ; The split type unit
59 CHECK: .debug_types.dwo contents:
60 CHECK: DW_TAG_type_unit
61 CHECK-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000000) string = "V5_split_type_unit")
62 CHECK-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x0000001c)
63 CHECK: DW_TAG_structure_type
64 CHECK-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "V5_split_Mystruct")
61 SPLIT: .debug_types.dwo contents:
62 SPLIT: DW_TAG_type_unit
63 SPLIT-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000000) string = "V5_split_type_unit")
64 SPLIT-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x0000001c)
65 SPLIT: DW_TAG_structure_type
66 SPLIT-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "V5_split_Mystruct")
6567
6668 ; The .debug_str_offsets section
67 CHECK: .debug_str_offsets contents:
68 CHECK-NEXT: 0x00000000: Contribution size = 28, Version = 5
69 CHECK-NEXT: 0x00000008: 00000000 "Handmade DWARF producer"
70 CHECK-NEXT: 0x0000000c: 00000018 "Compile_Unit_1"
71 CHECK-NEXT: 0x00000010: 00000027 "/home/test/CU1"
72 CHECK-NEXT: 0x00000014: 00000067 "MyFunc"
73 CHECK-NEXT: 0x00000018: 0000006e "MyVar1"
74 CHECK-NEXT: 0x0000001c: 00000075 "MyVar2"
75 CHECK-NEXT: 0x00000020: 0000007c "MyVar3"
76 CHECK-NEXT: 0x00000024: Contribution size = 12, Version = 5
77 CHECK-NEXT: 0x0000002c: 00000000 "Handmade DWARF producer"
78 CHECK-NEXT: 0x00000030: 00000036 "Compile_Unit_2"
79 CHECK-NEXT: 0x00000034: 00000045 "/home/test/CU2"
80 CHECK-NEXT: 0x00000038: Contribution size = 8, Version = 5
81 CHECK-NEXT: 0x00000040: 00000054 "Type_Unit"
82 CHECK-NEXT: 0x00000044: 0000005e "MyStruct"
69 COMMON: .debug_str_offsets contents:
70 COMMON-NEXT: 0x00000000: Contribution size = 28, Version = 5
71 COMMON-NEXT: 0x00000008: 00000000 "Handmade DWARF producer"
72 COMMON-NEXT: 0x0000000c: 00000018 "Compile_Unit_1"
73 COMMON-NEXT: 0x00000010: 00000027 "/home/test/CU1"
74 COMMON-NEXT: 0x00000014: 00000067 "MyFunc"
75 COMMON-NEXT: 0x00000018: 0000006e "MyVar1"
76 COMMON-NEXT: 0x0000001c: 00000075 "MyVar2"
77 COMMON-NEXT: 0x00000020: 0000007c "MyVar3"
78 COMMON-NEXT: 0x00000024: Contribution size = 12, Version = 5
79 COMMON-NEXT: 0x0000002c: 00000000 "Handmade DWARF producer"
80 COMMON-NEXT: 0x00000030: 00000036 "Compile_Unit_2"
81 COMMON-NEXT: 0x00000034: 00000045 "/home/test/CU2"
82 COMMON-NEXT: 0x00000038: Contribution size = 8, Version = 5
83 COMMON-NEXT: 0x00000040: 00000054 "Type_Unit"
84 COMMON-NEXT: 0x00000044: 0000005e "MyStruct"
8385
84 CHECK: .debug_str_offsets.dwo contents:
85 CHECK-NEXT: 0x00000000: Contribution size = 12, Version = 5
86 CHECK-NEXT: 0x00000008: 00000000 "Handmade split DWARF producer"
87 CHECK-NEXT: 0x0000000c: 0000001e "V5_split_compile_unit"
88 CHECK-NEXT: 0x00000010: 00000034 "/home/test/splitCU"
89 CHECK-NEXT: 0x00000014: Contribution size = 8, Version = 5
90 CHECK-NEXT: 0x0000001c: 00000047 "V5_split_type_unit"
91 CHECK-NEXT: 0x00000020: 0000005a "V5_split_Mystruct"
86 SPLIT: .debug_str_offsets.dwo contents:
87 SPLIT-NEXT: 0x00000000: Contribution size = 12, Version = 5
88 SPLIT-NEXT: 0x00000008: 00000000 "Handmade split DWARF producer"
89 SPLIT-NEXT: 0x0000000c: 0000001e "V5_split_compile_unit"
90 SPLIT-NEXT: 0x00000010: 00000034 "/home/test/splitCU"
91 SPLIT-NEXT: 0x00000014: Contribution size = 8, Version = 5
92 SPLIT-NEXT: 0x0000001c: 00000047 "V5_split_type_unit"
93 SPLIT-NEXT: 0x00000020: 0000005a "V5_split_Mystruct"