1 //===-- ValueObjectMemory.cpp ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "lldb/Core/ValueObjectMemory.h"
15 // Other libraries and framework includes
17 #include "lldb/Core/Module.h"
18 #include "lldb/Core/ValueObjectList.h"
19 #include "lldb/Core/Value.h"
20 #include "lldb/Core/ValueObject.h"
22 #include "lldb/Symbol/ObjectFile.h"
23 #include "lldb/Symbol/SymbolContext.h"
24 #include "lldb/Symbol/Type.h"
25 #include "lldb/Symbol/Variable.h"
27 #include "lldb/Target/ExecutionContext.h"
28 #include "lldb/Target/Process.h"
29 #include "lldb/Target/RegisterContext.h"
30 #include "lldb/Target/Target.h"
31 #include "lldb/Target/Thread.h"
34 using namespace lldb_private;
37 ValueObjectMemory::Create (ExecutionContextScope *exe_scope,
39 const Address &address,
40 lldb::TypeSP &type_sp)
42 return (new ValueObjectMemory (exe_scope, name, address, type_sp))->GetSP();
46 ValueObjectMemory::Create (ExecutionContextScope *exe_scope,
48 const Address &address,
49 const ClangASTType &ast_type)
51 return (new ValueObjectMemory (exe_scope, name, address, ast_type))->GetSP();
54 ValueObjectMemory::ValueObjectMemory (ExecutionContextScope *exe_scope,
56 const Address &address,
57 lldb::TypeSP &type_sp) :
58 ValueObject(exe_scope),
63 // Do not attempt to construct one of these objects with no variable!
64 assert (m_type_sp.get() != NULL);
65 SetName (ConstString(name));
66 m_value.SetContext(Value::eContextTypeLLDBType, m_type_sp.get());
67 TargetSP target_sp (GetTargetSP());
68 lldb::addr_t load_address = m_address.GetLoadAddress(target_sp.get());
69 if (load_address != LLDB_INVALID_ADDRESS)
71 m_value.SetValueType(Value::eValueTypeLoadAddress);
72 m_value.GetScalar() = load_address;
76 lldb::addr_t file_address = m_address.GetFileAddress();
77 if (file_address != LLDB_INVALID_ADDRESS)
79 m_value.SetValueType(Value::eValueTypeFileAddress);
80 m_value.GetScalar() = file_address;
84 m_value.GetScalar() = m_address.GetOffset();
85 m_value.SetValueType (Value::eValueTypeScalar);
90 ValueObjectMemory::ValueObjectMemory (ExecutionContextScope *exe_scope,
92 const Address &address,
93 const ClangASTType &ast_type) :
94 ValueObject(exe_scope),
97 m_clang_type(ast_type)
99 // Do not attempt to construct one of these objects with no variable!
100 assert (m_clang_type.GetASTContext());
101 assert (m_clang_type.GetOpaqueQualType());
103 TargetSP target_sp (GetTargetSP());
105 SetName (ConstString(name));
106 // m_value.SetContext(Value::eContextTypeClangType, m_clang_type.GetOpaqueQualType());
107 m_value.SetClangType(m_clang_type);
108 lldb::addr_t load_address = m_address.GetLoadAddress (target_sp.get());
109 if (load_address != LLDB_INVALID_ADDRESS)
111 m_value.SetValueType(Value::eValueTypeLoadAddress);
112 m_value.GetScalar() = load_address;
116 lldb::addr_t file_address = m_address.GetFileAddress();
117 if (file_address != LLDB_INVALID_ADDRESS)
119 m_value.SetValueType(Value::eValueTypeFileAddress);
120 m_value.GetScalar() = file_address;
124 m_value.GetScalar() = m_address.GetOffset();
125 m_value.SetValueType (Value::eValueTypeScalar);
130 ValueObjectMemory::~ValueObjectMemory()
135 ValueObjectMemory::GetClangTypeImpl ()
138 return m_type_sp->GetClangForwardType();
143 ValueObjectMemory::GetTypeName()
146 return m_type_sp->GetName();
147 return m_clang_type.GetConstTypeName();
151 ValueObjectMemory::GetDisplayTypeName()
154 return m_type_sp->GetClangForwardType().GetDisplayTypeName();
155 return m_clang_type.GetDisplayTypeName();
159 ValueObjectMemory::CalculateNumChildren()
162 return m_type_sp->GetNumChildren(true);
163 const bool omit_empty_base_classes = true;
164 return m_clang_type.GetNumChildren (omit_empty_base_classes);
168 ValueObjectMemory::GetByteSize()
171 return m_type_sp->GetByteSize();
172 return m_clang_type.GetByteSize (nullptr);
176 ValueObjectMemory::GetValueType() const
178 // RETHINK: Should this be inherited from somewhere?
179 return lldb::eValueTypeVariableGlobal;
183 ValueObjectMemory::UpdateValue ()
185 SetValueIsValid (false);
188 ExecutionContext exe_ctx (GetExecutionContextRef());
190 Target *target = exe_ctx.GetTargetPtr();
193 m_data.SetByteOrder(target->GetArchitecture().GetByteOrder());
194 m_data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize());
197 Value old_value(m_value);
198 if (m_address.IsValid())
200 Value::ValueType value_type = m_value.GetValueType();
205 assert(!"Unhandled expression result value kind...");
208 case Value::eValueTypeScalar:
209 // The variable value is in the Scalar value inside the m_value.
210 // We can point our m_data right to it.
211 m_error = m_value.GetValueAsData (&exe_ctx, m_data, 0, GetModule().get());
214 case Value::eValueTypeFileAddress:
215 case Value::eValueTypeLoadAddress:
216 case Value::eValueTypeHostAddress:
217 // The DWARF expression result was an address in the inferior
218 // process. If this variable is an aggregate type, we just need
219 // the address as the main value as all child variable objects
220 // will rely upon this location and add an offset and then read
221 // their own values as needed. If this variable is a simple
222 // type, we read all data for it into m_data.
223 // Make sure this type has a value before we try and read it
225 // If we have a file address, convert it to a load address if we can.
226 if (value_type == Value::eValueTypeFileAddress && exe_ctx.GetProcessPtr())
228 lldb::addr_t load_addr = m_address.GetLoadAddress(target);
229 if (load_addr != LLDB_INVALID_ADDRESS)
231 m_value.SetValueType(Value::eValueTypeLoadAddress);
232 m_value.GetScalar() = load_addr;
236 if (!CanProvideValue())
238 // this value object represents an aggregate type whose
239 // children have values, but this object does not. So we
240 // say we are changed if our location has changed.
241 SetValueDidChange (value_type != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar());
245 // Copy the Value and set the context to use our Variable
246 // so it can extract read its value into m_data appropriately
247 Value value(m_value);
249 value.SetContext(Value::eContextTypeLLDBType, m_type_sp.get());
252 //value.SetContext(Value::eContextTypeClangType, m_clang_type.GetOpaqueQualType());
253 value.SetClangType(m_clang_type);
256 m_error = value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get());
261 SetValueIsValid (m_error.Success());
263 return m_error.Success();
269 ValueObjectMemory::IsInScope ()
271 // FIXME: Maybe try to read the memory address, and if that works, then
278 ValueObjectMemory::GetModule()
280 return m_address.GetModule();