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::CalculateNumChildren()
154 return m_type_sp->GetNumChildren(true);
155 const bool omit_empty_base_classes = true;
156 return m_clang_type.GetNumChildren (omit_empty_base_classes);
160 ValueObjectMemory::GetByteSize()
163 return m_type_sp->GetByteSize();
164 return m_clang_type.GetByteSize ();
168 ValueObjectMemory::GetValueType() const
170 // RETHINK: Should this be inherited from somewhere?
171 return lldb::eValueTypeVariableGlobal;
175 ValueObjectMemory::UpdateValue ()
177 SetValueIsValid (false);
180 ExecutionContext exe_ctx (GetExecutionContextRef());
182 Target *target = exe_ctx.GetTargetPtr();
185 m_data.SetByteOrder(target->GetArchitecture().GetByteOrder());
186 m_data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize());
189 Value old_value(m_value);
190 if (m_address.IsValid())
192 Value::ValueType value_type = m_value.GetValueType();
197 assert(!"Unhandled expression result value kind...");
200 case Value::eValueTypeScalar:
201 // The variable value is in the Scalar value inside the m_value.
202 // We can point our m_data right to it.
203 m_error = m_value.GetValueAsData (&exe_ctx, m_data, 0, GetModule().get());
206 case Value::eValueTypeFileAddress:
207 case Value::eValueTypeLoadAddress:
208 case Value::eValueTypeHostAddress:
209 // The DWARF expression result was an address in the inferior
210 // process. If this variable is an aggregate type, we just need
211 // the address as the main value as all child variable objects
212 // will rely upon this location and add an offset and then read
213 // their own values as needed. If this variable is a simple
214 // type, we read all data for it into m_data.
215 // Make sure this type has a value before we try and read it
217 // If we have a file address, convert it to a load address if we can.
218 if (value_type == Value::eValueTypeFileAddress && exe_ctx.GetProcessPtr())
220 lldb::addr_t load_addr = m_address.GetLoadAddress(target);
221 if (load_addr != LLDB_INVALID_ADDRESS)
223 m_value.SetValueType(Value::eValueTypeLoadAddress);
224 m_value.GetScalar() = load_addr;
228 if (GetClangType().IsAggregateType())
230 // this value object represents an aggregate type whose
231 // children have values, but this object does not. So we
232 // say we are changed if our location has changed.
233 SetValueDidChange (value_type != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar());
237 // Copy the Value and set the context to use our Variable
238 // so it can extract read its value into m_data appropriately
239 Value value(m_value);
241 value.SetContext(Value::eContextTypeLLDBType, m_type_sp.get());
244 //value.SetContext(Value::eContextTypeClangType, m_clang_type.GetOpaqueQualType());
245 value.SetClangType(m_clang_type);
248 m_error = value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get());
253 SetValueIsValid (m_error.Success());
255 return m_error.Success();
261 ValueObjectMemory::IsInScope ()
263 // FIXME: Maybe try to read the memory address, and if that works, then
270 ValueObjectMemory::GetModule()
272 return m_address.GetModule();