Skip to content

Commit e337350

Browse files
committed
This is a refinement on 96601ec. The intent of that change was to do the same work for the computation of the locations of the children of ValueObjectVariable as was done for the root ValueObjectVariable. This original patch did that by moving the computation from ValueObjectVariable to ValueObject. That fixed the problem but caused a handful of swift-lldb testsuite failures and a crash or two.
The problem is that synthetic value objects can sometimes represent objects in target memory, and other times they might be made up wholly in lldb memory, with pointers from one synthetic object to another, and so the ValueObjectVariable computation was not appropriate. This patch delegates the computation to the root of the ValueObject in question. That solves the problem for ValueObjectVariable while not messing up the computation for ValueObjectConstResult or ValueObjectSynthetic. Differential Revision: https://reviews.llvm.org/D83450
1 parent 8c8a2fd commit e337350

File tree

4 files changed

+63
-53
lines changed

4 files changed

+63
-53
lines changed

lldb/include/lldb/Core/ValueObject.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,9 +963,14 @@ class ValueObject : public UserID {
963963

964964
void SetPreferredDisplayLanguageIfNeeded(lldb::LanguageType);
965965

966+
protected:
967+
virtual void DoUpdateChildrenAddressType(ValueObject &valobj) { return; };
968+
966969
private:
967970
virtual CompilerType MaybeCalculateCompleteType();
968-
void UpdateChildrenAddressType();
971+
void UpdateChildrenAddressType() {
972+
GetRoot()->DoUpdateChildrenAddressType(*this);
973+
}
969974

970975
lldb::ValueObjectSP GetValueForExpressionPath_Impl(
971976
llvm::StringRef expression_cstr,

lldb/include/lldb/Core/ValueObjectVariable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class ValueObjectVariable : public ValueObject {
6767

6868
protected:
6969
bool UpdateValue() override;
70+
71+
void DoUpdateChildrenAddressType(ValueObject &valobj) override;
7072

7173
CompilerType GetCompilerTypeImpl() override;
7274

lldb/source/Core/ValueObject.cpp

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -140,58 +140,6 @@ ValueObject::ValueObject(ExecutionContextScope *exe_scope,
140140
// Destructor
141141
ValueObject::~ValueObject() {}
142142

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

197145
bool did_change_formats = false;

lldb/source/Core/ValueObjectVariable.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,64 @@ bool ValueObjectVariable::UpdateValue() {
242242
m_resolved_value.SetContext(Value::eContextTypeInvalid, nullptr);
243243
}
244244
}
245+
245246
return m_error.Success();
246247
}
247248

249+
void ValueObjectVariable::DoUpdateChildrenAddressType(ValueObject &valobj) {
250+
Value::ValueType value_type = valobj.GetValue().GetValueType();
251+
ExecutionContext exe_ctx(GetExecutionContextRef());
252+
Process *process = exe_ctx.GetProcessPtr();
253+
const bool process_is_alive = process && process->IsAlive();
254+
const uint32_t type_info = valobj.GetCompilerType().GetTypeInfo();
255+
const bool is_pointer_or_ref =
256+
(type_info & (lldb::eTypeIsPointer | lldb::eTypeIsReference)) != 0;
257+
258+
switch (value_type) {
259+
case Value::eValueTypeFileAddress:
260+
// If this type is a pointer, then its children will be considered load
261+
// addresses if the pointer or reference is dereferenced, but only if
262+
// the process is alive.
263+
//
264+
// There could be global variables like in the following code:
265+
// struct LinkedListNode { Foo* foo; LinkedListNode* next; };
266+
// Foo g_foo1;
267+
// Foo g_foo2;
268+
// LinkedListNode g_second_node = { &g_foo2, NULL };
269+
// LinkedListNode g_first_node = { &g_foo1, &g_second_node };
270+
//
271+
// When we aren't running, we should be able to look at these variables
272+
// using the "target variable" command. Children of the "g_first_node"
273+
// always will be of the same address type as the parent. But children
274+
// of the "next" member of LinkedListNode will become load addresses if
275+
// we have a live process, or remain a file address if it was a file
276+
// address.
277+
if (process_is_alive && is_pointer_or_ref)
278+
valobj.SetAddressTypeOfChildren(eAddressTypeLoad);
279+
else
280+
valobj.SetAddressTypeOfChildren(eAddressTypeFile);
281+
break;
282+
case Value::eValueTypeHostAddress:
283+
// Same as above for load addresses, except children of pointer or refs
284+
// are always load addresses. Host addresses are used to store freeze
285+
// dried variables. If this type is a struct, the entire struct
286+
// contents will be copied into the heap of the
287+
// LLDB process, but we do not currently follow any pointers.
288+
if (is_pointer_or_ref)
289+
valobj.SetAddressTypeOfChildren(eAddressTypeLoad);
290+
else
291+
valobj.SetAddressTypeOfChildren(eAddressTypeHost);
292+
break;
293+
case Value::eValueTypeLoadAddress:
294+
case Value::eValueTypeScalar:
295+
case Value::eValueTypeVector:
296+
valobj.SetAddressTypeOfChildren(eAddressTypeLoad);
297+
break;
298+
}
299+
}
300+
301+
302+
248303
bool ValueObjectVariable::IsInScope() {
249304
const ExecutionContextRef &exe_ctx_ref = GetExecutionContextRef();
250305
if (exe_ctx_ref.HasFrameRef()) {

0 commit comments

Comments
 (0)