blob: 7e122ab5bf9a20fc4e9cca3be5a148d0092527e1 [file] [log] [blame]
Greg Clayton1d3afba2010-10-05 00:00:42 +00001//===-- ValueObjectConstResult.cpp ------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/ValueObjectConstResult.h"
11
12#include "lldb/Core/DataExtractor.h"
13#include "lldb/Core/Module.h"
14#include "lldb/Core/ValueObjectList.h"
15
16#include "lldb/Symbol/ClangASTType.h"
17#include "lldb/Symbol/ObjectFile.h"
18#include "lldb/Symbol/SymbolContext.h"
19#include "lldb/Symbol/Type.h"
20#include "lldb/Symbol/Variable.h"
21
22#include "lldb/Target/ExecutionContext.h"
23#include "lldb/Target/Process.h"
24#include "lldb/Target/Target.h"
25
26using namespace lldb;
27using namespace lldb_private;
28
29ValueObjectConstResult::ValueObjectConstResult
30(
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000031 ByteOrder byte_order,
32 uint32_t addr_byte_size
33) :
34 ValueObject (NULL),
35 m_clang_ast (NULL),
36 m_type_name (),
37 m_byte_size (0)
38{
39 SetIsConstant ();
40 SetValueIsValid(true);
41 m_data.SetByteOrder(byte_order);
42 m_data.SetAddressByteSize(addr_byte_size);
43 m_pointers_point_to_load_addrs = true;
44}
45
46ValueObjectConstResult::ValueObjectConstResult
47(
48 clang::ASTContext *clang_ast,
49 void *clang_type,
50 const ConstString &name,
51 const DataExtractor &data
52) :
53 ValueObject (NULL),
54 m_clang_ast (clang_ast),
55 m_type_name (),
56 m_byte_size (0)
57{
58 m_data = data;
59 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
60 m_value.SetValueType(Value::eValueTypeHostAddress);
61 m_value.SetContext(Value::eContextTypeClangType, clang_type);
62 m_name = name;
63 SetIsConstant ();
64 SetValueIsValid(true);
65 m_pointers_point_to_load_addrs = true;
66}
67
68ValueObjectConstResult::ValueObjectConstResult
69(
Greg Clayton1d3afba2010-10-05 00:00:42 +000070 clang::ASTContext *clang_ast,
71 void *clang_type,
72 const ConstString &name,
73 const lldb::DataBufferSP &data_sp,
74 lldb::ByteOrder data_byte_order,
75 uint8_t data_addr_size
76) :
Greg Clayton8f92f0a2010-10-14 22:52:14 +000077 ValueObject (NULL),
Greg Clayton1d3afba2010-10-05 00:00:42 +000078 m_clang_ast (clang_ast),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000079 m_type_name (),
80 m_byte_size (0)
Greg Clayton1d3afba2010-10-05 00:00:42 +000081{
82 m_data.SetByteOrder(data_byte_order);
83 m_data.SetAddressByteSize(data_addr_size);
84 m_data.SetData(data_sp);
85 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
86 m_value.SetValueType(Value::eValueTypeHostAddress);
Greg Clayton526e5af2010-11-13 03:52:47 +000087 m_value.SetContext(Value::eContextTypeClangType, clang_type);
Greg Clayton1d3afba2010-10-05 00:00:42 +000088 m_name = name;
Greg Claytonb71f3842010-10-05 03:13:51 +000089 SetIsConstant ();
Jim Inghame2f88412010-10-15 22:47:36 +000090 SetValueIsValid(true);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000091 m_pointers_point_to_load_addrs = true;
92}
93
94ValueObjectConstResult::ValueObjectConstResult
95(
96 clang::ASTContext *clang_ast,
97 void *clang_type,
98 const ConstString &name,
99 lldb::addr_t address,
100 lldb::AddressType address_type,
101 uint8_t addr_byte_size
102) :
103 ValueObject (NULL),
104 m_clang_ast (clang_ast),
105 m_type_name (),
106 m_byte_size (0)
107{
108 m_value.GetScalar() = address;
109 m_data.SetAddressByteSize(addr_byte_size);
110 m_value.GetScalar().GetData (m_data, addr_byte_size);
111 //m_value.SetValueType(Value::eValueTypeHostAddress);
112 switch (address_type)
113 {
114 default:
115 case eAddressTypeInvalid: m_value.SetValueType(Value::eValueTypeScalar); break;
116 case eAddressTypeFile: m_value.SetValueType(Value::eValueTypeFileAddress); break;
117 case eAddressTypeLoad: m_value.SetValueType(Value::eValueTypeLoadAddress); break;
118 case eAddressTypeHost: m_value.SetValueType(Value::eValueTypeHostAddress); break;
119 }
120 m_value.SetContext(Value::eContextTypeClangType, clang_type);
121 m_name = name;
122 SetIsConstant ();
123 SetValueIsValid(true);
124 m_pointers_point_to_load_addrs = true;
Greg Claytonb71f3842010-10-05 03:13:51 +0000125}
126
127ValueObjectConstResult::ValueObjectConstResult (const Error& error) :
Greg Clayton8f92f0a2010-10-14 22:52:14 +0000128 ValueObject (NULL),
Greg Claytonb71f3842010-10-05 03:13:51 +0000129 m_clang_ast (NULL),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000130 m_type_name (),
131 m_byte_size (0)
Greg Claytonb71f3842010-10-05 03:13:51 +0000132{
133 m_error = error;
134 SetIsConstant ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000135 m_pointers_point_to_load_addrs = true;
Greg Clayton1d3afba2010-10-05 00:00:42 +0000136}
137
138ValueObjectConstResult::~ValueObjectConstResult()
139{
140}
141
142void *
143ValueObjectConstResult::GetClangType()
144{
145 return m_value.GetClangType();
146}
147
148lldb::ValueType
149ValueObjectConstResult::GetValueType() const
150{
151 return eValueTypeConstResult;
152}
153
154size_t
155ValueObjectConstResult::GetByteSize()
156{
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000157 if (m_byte_size == 0)
158 {
159 uint64_t bit_width = ClangASTType::GetClangTypeBitWidth (GetClangAST(), GetClangType());
160 m_byte_size = (bit_width + 7 ) / 8;
161 }
162 return m_byte_size;
163}
164
165void
166ValueObjectConstResult::SetByteSize (size_t size)
167{
168 m_byte_size = size;
Greg Clayton1d3afba2010-10-05 00:00:42 +0000169}
170
171uint32_t
172ValueObjectConstResult::CalculateNumChildren()
173{
174 return ClangASTContext::GetNumChildren (GetClangType(), true);
175}
176
177clang::ASTContext *
178ValueObjectConstResult::GetClangAST ()
179{
180 return m_clang_ast;
181}
182
183ConstString
184ValueObjectConstResult::GetTypeName()
185{
186 if (m_type_name.IsEmpty())
187 m_type_name = ClangASTType::GetClangTypeName (GetClangType());
188 return m_type_name;
189}
190
191void
192ValueObjectConstResult::UpdateValue (ExecutionContextScope *exe_scope)
193{
Greg Clayton1d3afba2010-10-05 00:00:42 +0000194 // Const value is always valid
195 SetValueIsValid (true);
196}
197
198
199bool
200ValueObjectConstResult::IsInScope (StackFrame *frame)
201{
202 // A const result value is always in scope since it serializes all
203 // information needed to contain the constant value.
204 return true;
205}