Skip to content

Commit 4b22b09

Browse files
author
Davide Italiano
committed
Merge commit 'refs/am/changes/f77138b0bbc2f9f8da3c4d275ebe27ba09b2834f_swift/master' into HEAD
Conflicts: lldb/source/Core/ValueObjectVariable.cpp
2 parents 16fe853 + f77138b commit 4b22b09

File tree

4 files changed

+167
-46
lines changed

4 files changed

+167
-46
lines changed

lldb/include/lldb/Core/ValueObject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ class ValueObject : public UserID {
990990

991991
private:
992992
virtual CompilerType MaybeCalculateCompleteType();
993+
void UpdateChildrenAddressType();
993994

994995
lldb::ValueObjectSP GetValueForExpressionPath_Impl(
995996
llvm::StringRef expression_cstr,
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# RUN: llvm-mc -filetype=obj -o %t -triple x86_64-pc-linux %s
2+
# RUN: %lldb %t -o "target variable reset" -b | FileCheck %s
3+
4+
# CHECK: (lldb) target variable reset
5+
# CHECK: (auto_reset) reset = {
6+
# CHECK: ptr = 0xdeadbeefbaadf00d
7+
# CHECK: prev = false
8+
# CHECK: }
9+
10+
.section .debug_abbrev,"",@progbits
11+
.byte 1 # Abbreviation Code
12+
.byte 17 # DW_TAG_compile_unit
13+
.byte 1 # DW_CHILDREN_yes
14+
.byte 0 # EOM(1)
15+
.byte 0 # EOM(2)
16+
.byte 2 # Abbreviation Code
17+
.byte 52 # DW_TAG_variable
18+
.byte 0 # DW_CHILDREN_no
19+
.byte 3 # DW_AT_name
20+
.byte 8 # DW_FORM_string
21+
.byte 73 # DW_AT_type
22+
.byte 19 # DW_FORM_ref4
23+
.byte 2 # DW_AT_location
24+
.byte 24 # DW_FORM_exprloc
25+
.byte 0 # EOM(1)
26+
.byte 0 # EOM(2)
27+
.byte 3 # Abbreviation Code
28+
.byte 36 # DW_TAG_base_type
29+
.byte 0 # DW_CHILDREN_no
30+
.byte 3 # DW_AT_name
31+
.byte 8 # DW_FORM_string
32+
.byte 62 # DW_AT_encoding
33+
.byte 11 # DW_FORM_data1
34+
.byte 11 # DW_AT_byte_size
35+
.byte 11 # DW_FORM_data1
36+
.byte 0 # EOM(1)
37+
.byte 0 # EOM(2)
38+
.byte 4 # Abbreviation Code
39+
.byte 19 # DW_TAG_structure_type
40+
.byte 1 # DW_CHILDREN_yes
41+
.byte 3 # DW_AT_name
42+
.byte 8 # DW_FORM_string
43+
.byte 11 # DW_AT_byte_size
44+
.byte 11 # DW_FORM_data1
45+
.byte 0 # EOM(1)
46+
.byte 0 # EOM(2)
47+
.byte 5 # Abbreviation Code
48+
.byte 13 # DW_TAG_member
49+
.byte 0 # DW_CHILDREN_no
50+
.byte 3 # DW_AT_name
51+
.byte 8 # DW_FORM_string
52+
.byte 73 # DW_AT_type
53+
.byte 19 # DW_FORM_ref4
54+
.byte 56 # DW_AT_data_member_location
55+
.byte 11 # DW_FORM_data1
56+
.byte 0 # EOM(1)
57+
.byte 0 # EOM(2)
58+
.byte 6 # Abbreviation Code
59+
.byte 15 # DW_TAG_pointer_type
60+
.byte 0 # DW_CHILDREN_no
61+
.byte 73 # DW_AT_type
62+
.byte 19 # DW_FORM_ref4
63+
.byte 0 # EOM(1)
64+
.byte 0 # EOM(2)
65+
.byte 0 # EOM(3)
66+
67+
.section .debug_info,"",@progbits
68+
.Lcu_begin0:
69+
.long .Lcu_end-.Lcu_start # Length of Unit
70+
.Lcu_start:
71+
.short 4 # DWARF version number
72+
.long .debug_abbrev # Offset Into Abbrev. Section
73+
.byte 8 # Address Size (in bytes)
74+
.byte 1 # Abbrev [1] 0xb:0x6c DW_TAG_compile_unit
75+
.Lbool:
76+
.byte 3 # Abbrev [3] 0x33:0x7 DW_TAG_base_type
77+
.asciz "bool" # DW_AT_name
78+
.byte 2 # DW_AT_encoding
79+
.byte 1 # DW_AT_byte_size
80+
.byte 2 # Abbrev [2] 0x3a:0x15 DW_TAG_variable
81+
.asciz "reset" # DW_AT_name
82+
.long .Lstruct # DW_AT_type
83+
.byte 2f-1f # DW_AT_location
84+
1:
85+
.byte 0xe # DW_OP_constu
86+
.quad 0xdeadbeefbaadf00d
87+
.byte 0x9f # DW_OP_stack_value
88+
.byte 0x93 # DW_OP_piece
89+
.uleb128 8
90+
.byte 0xe # DW_OP_constu
91+
.quad 0
92+
.byte 0x9f # DW_OP_stack_value
93+
.byte 0x93 # DW_OP_piece
94+
.uleb128 8
95+
2:
96+
.Lstruct:
97+
.byte 4 # Abbrev [4] 0x4f:0x22 DW_TAG_structure_type
98+
.asciz "auto_reset" # DW_AT_name
99+
.byte 16 # DW_AT_byte_size
100+
.byte 5 # Abbrev [5] 0x58:0xc DW_TAG_member
101+
.asciz "ptr" # DW_AT_name
102+
.long .Lbool_ptr # DW_AT_type
103+
.byte 0 # DW_AT_data_member_location
104+
.byte 5 # Abbrev [5] 0x64:0xc DW_TAG_member
105+
.asciz "prev" # DW_AT_name
106+
.long .Lbool # DW_AT_type
107+
.byte 8 # DW_AT_data_member_location
108+
.byte 0 # End Of Children Mark
109+
.Lbool_ptr:
110+
.byte 6 # Abbrev [6] 0x71:0x5 DW_TAG_pointer_type
111+
.long .Lbool # DW_AT_type
112+
.byte 0 # End Of Children Mark
113+
.Lcu_end:

lldb/source/Core/ValueObject.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,58 @@ ValueObject::ValueObject(ExecutionContextScope *exe_scope,
152152
// Destructor
153153
ValueObject::~ValueObject() {}
154154

155+
void ValueObject::UpdateChildrenAddressType() {
156+
Value::ValueType value_type = m_value.GetValueType();
157+
ExecutionContext exe_ctx(GetExecutionContextRef());
158+
Process *process = exe_ctx.GetProcessPtr();
159+
const bool process_is_alive = process && process->IsAlive();
160+
const uint32_t type_info = GetCompilerType().GetTypeInfo();
161+
const bool is_pointer_or_ref =
162+
(type_info & (lldb::eTypeIsPointer | lldb::eTypeIsReference)) != 0;
163+
164+
switch (value_type) {
165+
case Value::eValueTypeFileAddress:
166+
// If this type is a pointer, then its children will be considered load
167+
// addresses if the pointer or reference is dereferenced, but only if
168+
// the process is alive.
169+
//
170+
// There could be global variables like in the following code:
171+
// struct LinkedListNode { Foo* foo; LinkedListNode* next; };
172+
// Foo g_foo1;
173+
// Foo g_foo2;
174+
// LinkedListNode g_second_node = { &g_foo2, NULL };
175+
// LinkedListNode g_first_node = { &g_foo1, &g_second_node };
176+
//
177+
// When we aren't running, we should be able to look at these variables
178+
// using the "target variable" command. Children of the "g_first_node"
179+
// always will be of the same address type as the parent. But children
180+
// of the "next" member of LinkedListNode will become load addresses if
181+
// we have a live process, or remain a file address if it was a file
182+
// address.
183+
if (process_is_alive && is_pointer_or_ref)
184+
SetAddressTypeOfChildren(eAddressTypeLoad);
185+
else
186+
SetAddressTypeOfChildren(eAddressTypeFile);
187+
break;
188+
case Value::eValueTypeHostAddress:
189+
// Same as above for load addresses, except children of pointer or refs
190+
// are always load addresses. Host addresses are used to store freeze
191+
// dried variables. If this type is a struct, the entire struct
192+
// contents will be copied into the heap of the
193+
// LLDB process, but we do not currently follow any pointers.
194+
if (is_pointer_or_ref)
195+
SetAddressTypeOfChildren(eAddressTypeLoad);
196+
else
197+
SetAddressTypeOfChildren(eAddressTypeHost);
198+
break;
199+
case Value::eValueTypeLoadAddress:
200+
case Value::eValueTypeScalar:
201+
case Value::eValueTypeVector:
202+
SetAddressTypeOfChildren(eAddressTypeLoad);
203+
break;
204+
}
205+
}
206+
155207
bool ValueObject::UpdateValueIfNeeded(bool update_format) {
156208

157209
bool did_change_formats = false;
@@ -223,6 +275,7 @@ bool ValueObject::UpdateValueIfNeeded(bool update_format) {
223275
SetValueIsValid(success);
224276

225277
if (success) {
278+
UpdateChildrenAddressType();
226279
const uint64_t max_checksum_size = 128;
227280
m_data.Checksum(m_value_checksum, max_checksum_size);
228281
} else {

lldb/source/Core/ValueObjectVariable.cpp

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,6 @@ bool ValueObjectVariable::UpdateValue() {
190190

191191
Process *process = exe_ctx.GetProcessPtr();
192192
const bool process_is_alive = process && process->IsAlive();
193-
const uint32_t type_info =
194-
compiler_type.IsValid() ? compiler_type.GetTypeInfo() : 0;
195-
const bool is_pointer_or_ref =
196-
(type_info & (lldb::eTypeIsPointer | lldb::eTypeIsReference)) != 0;
197193

198194
// BEGIN Swift
199195
if (variable->GetType() && variable->GetType()->IsSwiftFixedValueBuffer())
@@ -214,48 +210,6 @@ bool ValueObjectVariable::UpdateValue() {
214210
}
215211
// END Swift
216212

217-
switch (value_type) {
218-
case Value::eValueTypeFileAddress:
219-
// If this type is a pointer, then its children will be considered load
220-
// addresses if the pointer or reference is dereferenced, but only if
221-
// the process is alive.
222-
//
223-
// There could be global variables like in the following code:
224-
// struct LinkedListNode { Foo* foo; LinkedListNode* next; };
225-
// Foo g_foo1;
226-
// Foo g_foo2;
227-
// LinkedListNode g_second_node = { &g_foo2, NULL };
228-
// LinkedListNode g_first_node = { &g_foo1, &g_second_node };
229-
//
230-
// When we aren't running, we should be able to look at these variables
231-
// using the "target variable" command. Children of the "g_first_node"
232-
// always will be of the same address type as the parent. But children
233-
// of the "next" member of LinkedListNode will become load addresses if
234-
// we have a live process, or remain what a file address if it what a
235-
// file address.
236-
if (process_is_alive && is_pointer_or_ref)
237-
SetAddressTypeOfChildren(eAddressTypeLoad);
238-
else
239-
SetAddressTypeOfChildren(eAddressTypeFile);
240-
break;
241-
case Value::eValueTypeHostAddress:
242-
// Same as above for load addresses, except children of pointer or refs
243-
// are always load addresses. Host addresses are used to store freeze
244-
// dried variables. If this type is a struct, the entire struct
245-
// contents will be copied into the heap of the
246-
// LLDB process, but we do not currently follow any pointers.
247-
if (is_pointer_or_ref)
248-
SetAddressTypeOfChildren(eAddressTypeLoad);
249-
else
250-
SetAddressTypeOfChildren(eAddressTypeHost);
251-
break;
252-
case Value::eValueTypeLoadAddress:
253-
case Value::eValueTypeScalar:
254-
case Value::eValueTypeVector:
255-
SetAddressTypeOfChildren(eAddressTypeLoad);
256-
break;
257-
}
258-
259213
switch (value_type) {
260214
case Value::eValueTypeVector:
261215
// fall through

0 commit comments

Comments
 (0)