Skip to content

Commit 25bbceb

Browse files
committed
[LLDB] Fix how ValueObjectChild handles bit-fields stored in a Scalar in UpdateValue()
When bit-field data was stored in a Scalar in ValueObjectChild during UpdateValue() it was extracting the bit-field value. Later on in lldb_private::DumpDataExtractor(…) we were again attempting to extract the bit-field. Which would then not obtain the correct value. This will remove the extra extraction in UpdateValue(). We hit this specific case when values are passed in registers, which we could only reproduce in an optimized build. Differential Revision: https://reviews.llvm.org/D85376
1 parent d650cbc commit 25bbceb

File tree

2 files changed

+313
-5
lines changed

2 files changed

+313
-5
lines changed

lldb/source/Core/ValueObjectChild.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,7 @@ bool ValueObjectChild::UpdateValue() {
199199
// try to extract the child value from the parent's scalar value
200200
{
201201
Scalar scalar(m_value.GetScalar());
202-
if (m_bitfield_bit_size)
203-
scalar.ExtractBitfield(m_bitfield_bit_size,
204-
m_bitfield_bit_offset);
205-
else
206-
scalar.ExtractBitfield(8 * m_byte_size, 8 * m_byte_offset);
202+
scalar.ExtractBitfield(8 * m_byte_size, 8 * m_byte_offset);
207203
m_value.GetScalar() = scalar;
208204
}
209205
break;
Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
1+
# RUN: llvm-mc -filetype=obj -o %t -triple x86_64-apple-macosx10.15.0 %s
2+
# RUN: %lldb %t -o "target variable ug" -b | FileCheck %s
3+
4+
# CHECK: (lldb) target variable ug
5+
# CHECK: (U) ug = {
6+
# CHECK: raw = 1688469761
7+
# CHECK: = (a = 1, b = 1, c = 36, d = 2, e = 36, f = 1)
8+
# CHECK: }
9+
10+
# We are testing how ValueObject deals with bit-fields when an argument is
11+
# passed by register. Compiling at -O1 allows us to capture this case and
12+
# test it.
13+
#
14+
# typedef union {
15+
# unsigned raw;
16+
# struct {
17+
# unsigned a : 8;
18+
# unsigned b : 8;
19+
# unsigned c : 6;
20+
# unsigned d : 2;
21+
# unsigned e : 6;
22+
# unsigned f : 2;
23+
# };
24+
# } U;
25+
#
26+
# // This appears first in the debug info and pulls the type definition in...
27+
# static U __attribute__((used)) _type_anchor;
28+
# // ... then our useful variable appears last in the debug info and we can
29+
# // tweak the assembly without needing to edit a lot of offsets by hand.
30+
# static U ug;
31+
#
32+
# extern void f(U);
33+
#
34+
# // Omit debug info for main.
35+
# __attribute__((nodebug))
36+
# int main() {
37+
# ug.raw = 0x64A40101;
38+
# f(ug);
39+
# f((U)ug.raw);
40+
# }
41+
#
42+
# Compiled as follows:
43+
#
44+
# clang -O1 -gdwarf-4 weird.c -S -o weird.s
45+
#
46+
# Then the DWARF was hand modified to get DW_AT_LOCATION for ug from:
47+
#
48+
# DW_AT_location (DW_OP_addr 0x3f8, DW_OP_deref, DW_OP_constu 0x64a40101, DW_OP_mul, DW_OP_lit0, DW_OP_plus, DW_OP_stack_value)
49+
#
50+
# to this:
51+
#
52+
# DW_AT_location (DW_OP_constu 0x64a40101, DW_OP_stack_value)
53+
#
54+
# to work-around a seperate bug.
55+
56+
.zerofill __DATA,__bss,__type_anchor,4,2 ## @_type_anchor
57+
.zerofill __DATA,__bss,_ug.0,1,2 ## @ug.0
58+
.no_dead_strip __type_anchor
59+
.section __DWARF,__debug_str,regular,debug
60+
Linfo_string:
61+
.zero 138
62+
.asciz "_type_anchor" ## string offset=138
63+
.asciz "U" ## string offset=151
64+
.asciz "raw" ## string offset=153
65+
.asciz "unsigned int" ## string offset=157
66+
.asciz "a" ## string offset=170
67+
.asciz "b" ## string offset=172
68+
.asciz "c" ## string offset=174
69+
.asciz "d" ## string offset=176
70+
.asciz "e" ## string offset=178
71+
.asciz "f" ## string offset=180
72+
.asciz "ug" ## string offset=182
73+
.section __DWARF,__debug_abbrev,regular,debug
74+
Lsection_abbrev:
75+
.byte 1 ## Abbreviation Code
76+
.byte 17 ## DW_TAG_compile_unit
77+
.byte 1 ## DW_CHILDREN_yes
78+
.byte 37 ## DW_AT_producer
79+
.byte 14 ## DW_FORM_strp
80+
.byte 19 ## DW_AT_language
81+
.byte 5 ## DW_FORM_data2
82+
.byte 3 ## DW_AT_name
83+
.byte 14 ## DW_FORM_strp
84+
.ascii "\202|" ## DW_AT_LLVM_sysroot
85+
.byte 14 ## DW_FORM_strp
86+
.ascii "\357\177" ## DW_AT_APPLE_sdk
87+
.byte 14 ## DW_FORM_strp
88+
.byte 16 ## DW_AT_stmt_list
89+
.byte 23 ## DW_FORM_sec_offset
90+
.byte 27 ## DW_AT_comp_dir
91+
.byte 14 ## DW_FORM_strp
92+
.ascii "\341\177" ## DW_AT_APPLE_optimized
93+
.byte 25 ## DW_FORM_flag_present
94+
.byte 0 ## EOM(1)
95+
.byte 0 ## EOM(2)
96+
.byte 2 ## Abbreviation Code
97+
.byte 52 ## DW_TAG_variable
98+
.byte 0 ## DW_CHILDREN_no
99+
.byte 3 ## DW_AT_name
100+
.byte 14 ## DW_FORM_strp
101+
.byte 73 ## DW_AT_type
102+
.byte 19 ## DW_FORM_ref4
103+
.byte 58 ## DW_AT_decl_file
104+
.byte 11 ## DW_FORM_data1
105+
.byte 59 ## DW_AT_decl_line
106+
.byte 11 ## DW_FORM_data1
107+
.byte 2 ## DW_AT_location
108+
.byte 24 ## DW_FORM_exprloc
109+
.byte 0 ## EOM(1)
110+
.byte 0 ## EOM(2)
111+
.byte 3 ## Abbreviation Code
112+
.byte 22 ## DW_TAG_typedef
113+
.byte 0 ## DW_CHILDREN_no
114+
.byte 73 ## DW_AT_type
115+
.byte 19 ## DW_FORM_ref4
116+
.byte 3 ## DW_AT_name
117+
.byte 14 ## DW_FORM_strp
118+
.byte 58 ## DW_AT_decl_file
119+
.byte 11 ## DW_FORM_data1
120+
.byte 59 ## DW_AT_decl_line
121+
.byte 11 ## DW_FORM_data1
122+
.byte 0 ## EOM(1)
123+
.byte 0 ## EOM(2)
124+
.byte 4 ## Abbreviation Code
125+
.byte 23 ## DW_TAG_union_type
126+
.byte 1 ## DW_CHILDREN_yes
127+
.byte 11 ## DW_AT_byte_size
128+
.byte 11 ## DW_FORM_data1
129+
.byte 58 ## DW_AT_decl_file
130+
.byte 11 ## DW_FORM_data1
131+
.byte 59 ## DW_AT_decl_line
132+
.byte 11 ## DW_FORM_data1
133+
.byte 0 ## EOM(1)
134+
.byte 0 ## EOM(2)
135+
.byte 5 ## Abbreviation Code
136+
.byte 13 ## DW_TAG_member
137+
.byte 0 ## DW_CHILDREN_no
138+
.byte 3 ## DW_AT_name
139+
.byte 14 ## DW_FORM_strp
140+
.byte 73 ## DW_AT_type
141+
.byte 19 ## DW_FORM_ref4
142+
.byte 58 ## DW_AT_decl_file
143+
.byte 11 ## DW_FORM_data1
144+
.byte 59 ## DW_AT_decl_line
145+
.byte 11 ## DW_FORM_data1
146+
.byte 56 ## DW_AT_data_member_location
147+
.byte 11 ## DW_FORM_data1
148+
.byte 0 ## EOM(1)
149+
.byte 0 ## EOM(2)
150+
.byte 6 ## Abbreviation Code
151+
.byte 13 ## DW_TAG_member
152+
.byte 0 ## DW_CHILDREN_no
153+
.byte 73 ## DW_AT_type
154+
.byte 19 ## DW_FORM_ref4
155+
.byte 58 ## DW_AT_decl_file
156+
.byte 11 ## DW_FORM_data1
157+
.byte 59 ## DW_AT_decl_line
158+
.byte 11 ## DW_FORM_data1
159+
.byte 56 ## DW_AT_data_member_location
160+
.byte 11 ## DW_FORM_data1
161+
.byte 0 ## EOM(1)
162+
.byte 0 ## EOM(2)
163+
.byte 7 ## Abbreviation Code
164+
.byte 19 ## DW_TAG_structure_type
165+
.byte 1 ## DW_CHILDREN_yes
166+
.byte 11 ## DW_AT_byte_size
167+
.byte 11 ## DW_FORM_data1
168+
.byte 58 ## DW_AT_decl_file
169+
.byte 11 ## DW_FORM_data1
170+
.byte 59 ## DW_AT_decl_line
171+
.byte 11 ## DW_FORM_data1
172+
.byte 0 ## EOM(1)
173+
.byte 0 ## EOM(2)
174+
.byte 8 ## Abbreviation Code
175+
.byte 13 ## DW_TAG_member
176+
.byte 0 ## DW_CHILDREN_no
177+
.byte 3 ## DW_AT_name
178+
.byte 14 ## DW_FORM_strp
179+
.byte 73 ## DW_AT_type
180+
.byte 19 ## DW_FORM_ref4
181+
.byte 58 ## DW_AT_decl_file
182+
.byte 11 ## DW_FORM_data1
183+
.byte 59 ## DW_AT_decl_line
184+
.byte 11 ## DW_FORM_data1
185+
.byte 13 ## DW_AT_bit_size
186+
.byte 11 ## DW_FORM_data1
187+
.byte 107 ## DW_AT_data_bit_offset
188+
.byte 11 ## DW_FORM_data1
189+
.byte 0 ## EOM(1)
190+
.byte 0 ## EOM(2)
191+
.byte 9 ## Abbreviation Code
192+
.byte 36 ## DW_TAG_base_type
193+
.byte 0 ## DW_CHILDREN_no
194+
.byte 3 ## DW_AT_name
195+
.byte 14 ## DW_FORM_strp
196+
.byte 62 ## DW_AT_encoding
197+
.byte 11 ## DW_FORM_data1
198+
.byte 11 ## DW_AT_byte_size
199+
.byte 11 ## DW_FORM_data1
200+
.byte 0 ## EOM(1)
201+
.byte 0 ## EOM(2)
202+
.byte 0 ## EOM(3)
203+
.section __DWARF,__debug_info,regular,debug
204+
Lsection_info:
205+
Lcu_begin0:
206+
.set Lset0, Ldebug_info_end0-Ldebug_info_start0 ## Length of Unit
207+
.long Lset0
208+
Ldebug_info_start0:
209+
.short 4 ## DWARF version number
210+
.set Lset1, Lsection_abbrev-Lsection_abbrev ## Offset Into Abbrev. Section
211+
.long Lset1
212+
.byte 8 ## Address Size (in bytes)
213+
.byte 1 ## Abbrev [1] 0xb:0xd0 DW_TAG_compile_unit
214+
.long 0 ## DW_AT_producer
215+
.short 12 ## DW_AT_language
216+
.long 47 ## DW_AT_name
217+
.long 60 ## DW_AT_LLVM_sysroot
218+
.long 117 ## DW_AT_APPLE_sdk
219+
.long 0 ## DW_AT_stmt_list
220+
.long 133 ## DW_AT_comp_dir
221+
## DW_AT_APPLE_optimized
222+
.byte 2 ## Abbrev [2] 0x26:0x15 DW_TAG_variable
223+
.long 138 ## DW_AT_name
224+
.long 59 ## DW_AT_type
225+
.byte 1 ## DW_AT_decl_file
226+
.byte 14 ## DW_AT_decl_line
227+
.byte 9 ## DW_AT_location
228+
.byte 3
229+
.quad __type_anchor
230+
.byte 3 ## Abbrev [3] 0x3b:0xb DW_TAG_typedef
231+
.long 70 ## DW_AT_type
232+
.long 151 ## DW_AT_name
233+
.byte 1 ## DW_AT_decl_file
234+
.byte 11 ## DW_AT_decl_line
235+
.byte 4 ## Abbrev [4] 0x46:0x6c DW_TAG_union_type
236+
.byte 4 ## DW_AT_byte_size
237+
.byte 1 ## DW_AT_decl_file
238+
.byte 1 ## DW_AT_decl_line
239+
.byte 5 ## Abbrev [5] 0x4a:0xc DW_TAG_member
240+
.long 153 ## DW_AT_name
241+
.long 178 ## DW_AT_type
242+
.byte 1 ## DW_AT_decl_file
243+
.byte 2 ## DW_AT_decl_line
244+
.byte 0 ## DW_AT_data_member_location
245+
.byte 6 ## Abbrev [6] 0x56:0x8 DW_TAG_member
246+
.long 94 ## DW_AT_type
247+
.byte 1 ## DW_AT_decl_file
248+
.byte 3 ## DW_AT_decl_line
249+
.byte 0 ## DW_AT_data_member_location
250+
.byte 7 ## Abbrev [7] 0x5e:0x53 DW_TAG_structure_type
251+
.byte 4 ## DW_AT_byte_size
252+
.byte 1 ## DW_AT_decl_file
253+
.byte 3 ## DW_AT_decl_line
254+
.byte 8 ## Abbrev [8] 0x62:0xd DW_TAG_member
255+
.long 170 ## DW_AT_name
256+
.long 178 ## DW_AT_type
257+
.byte 1 ## DW_AT_decl_file
258+
.byte 4 ## DW_AT_decl_line
259+
.byte 8 ## DW_AT_bit_size
260+
.byte 0 ## DW_AT_data_bit_offset
261+
.byte 8 ## Abbrev [8] 0x6f:0xd DW_TAG_member
262+
.long 172 ## DW_AT_name
263+
.long 178 ## DW_AT_type
264+
.byte 1 ## DW_AT_decl_file
265+
.byte 5 ## DW_AT_decl_line
266+
.byte 8 ## DW_AT_bit_size
267+
.byte 8 ## DW_AT_data_bit_offset
268+
.byte 8 ## Abbrev [8] 0x7c:0xd DW_TAG_member
269+
.long 174 ## DW_AT_name
270+
.long 178 ## DW_AT_type
271+
.byte 1 ## DW_AT_decl_file
272+
.byte 6 ## DW_AT_decl_line
273+
.byte 6 ## DW_AT_bit_size
274+
.byte 16 ## DW_AT_data_bit_offset
275+
.byte 8 ## Abbrev [8] 0x89:0xd DW_TAG_member
276+
.long 176 ## DW_AT_name
277+
.long 178 ## DW_AT_type
278+
.byte 1 ## DW_AT_decl_file
279+
.byte 7 ## DW_AT_decl_line
280+
.byte 2 ## DW_AT_bit_size
281+
.byte 22 ## DW_AT_data_bit_offset
282+
.byte 8 ## Abbrev [8] 0x96:0xd DW_TAG_member
283+
.long 178 ## DW_AT_name
284+
.long 178 ## DW_AT_type
285+
.byte 1 ## DW_AT_decl_file
286+
.byte 8 ## DW_AT_decl_line
287+
.byte 6 ## DW_AT_bit_size
288+
.byte 24 ## DW_AT_data_bit_offset
289+
.byte 8 ## Abbrev [8] 0xa3:0xd DW_TAG_member
290+
.long 180 ## DW_AT_name
291+
.long 178 ## DW_AT_type
292+
.byte 1 ## DW_AT_decl_file
293+
.byte 9 ## DW_AT_decl_line
294+
.byte 2 ## DW_AT_bit_size
295+
.byte 30 ## DW_AT_data_bit_offset
296+
.byte 0 ## End Of Children Mark
297+
.byte 0 ## End Of Children Mark
298+
.byte 9 ## Abbrev [9] 0xb2:0x7 DW_TAG_base_type
299+
.long 157 ## DW_AT_name
300+
.byte 7 ## DW_AT_encoding
301+
.byte 4 ## DW_AT_byte_size
302+
.byte 2 ## Abbrev [2] 0xb9:0x21 DW_TAG_variable
303+
.long 182 ## DW_AT_name
304+
.long 59 ## DW_AT_type
305+
.byte 1 ## DW_AT_decl_file
306+
.byte 17 ## DW_AT_decl_line
307+
.byte 7 ## DW_AT_location
308+
.byte 16
309+
.ascii "\201\202\220\245\006"
310+
.byte 159
311+
.byte 0 ## End Of Children Mark
312+
Ldebug_info_end0:

0 commit comments

Comments
 (0)