1 //===-- 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 26 using namespace lldb; 27 using namespace lldb_private; 28 29 ValueObjectSP 30 ValueObjectConstResult::Create 31 ( 32 ExecutionContextScope *exe_scope, 33 ByteOrder byte_order, 34 uint32_t addr_byte_size 35 ) 36 { 37 return (new ValueObjectConstResult (exe_scope, 38 byte_order, 39 addr_byte_size))->GetSP(); 40 } 41 42 ValueObjectConstResult::ValueObjectConstResult 43 ( 44 ExecutionContextScope *exe_scope, 45 ByteOrder byte_order, 46 uint32_t addr_byte_size 47 ) : 48 ValueObject (exe_scope), 49 m_clang_ast (NULL), 50 m_type_name (), 51 m_byte_size (0) 52 { 53 SetIsConstant (); 54 SetValueIsValid(true); 55 m_data.SetByteOrder(byte_order); 56 m_data.SetAddressByteSize(addr_byte_size); 57 m_pointers_point_to_load_addrs = true; 58 } 59 60 ValueObjectSP 61 ValueObjectConstResult::Create 62 ( 63 ExecutionContextScope *exe_scope, 64 clang::ASTContext *clang_ast, 65 void *clang_type, 66 const ConstString &name, 67 const DataExtractor &data 68 ) 69 { 70 return (new ValueObjectConstResult (exe_scope, 71 clang_ast, 72 clang_type, 73 name, 74 data))->GetSP(); 75 } 76 77 ValueObjectConstResult::ValueObjectConstResult 78 ( 79 ExecutionContextScope *exe_scope, 80 clang::ASTContext *clang_ast, 81 void *clang_type, 82 const ConstString &name, 83 const DataExtractor &data 84 ) : 85 ValueObject (exe_scope), 86 m_clang_ast (clang_ast), 87 m_type_name (), 88 m_byte_size (0) 89 { 90 m_data = data; 91 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart(); 92 m_value.SetValueType(Value::eValueTypeHostAddress); 93 m_value.SetContext(Value::eContextTypeClangType, clang_type); 94 m_name = name; 95 SetIsConstant (); 96 SetValueIsValid(true); 97 m_pointers_point_to_load_addrs = true; 98 } 99 100 ValueObjectSP 101 ValueObjectConstResult::Create 102 ( 103 ExecutionContextScope *exe_scope, 104 clang::ASTContext *clang_ast, 105 void *clang_type, 106 const ConstString &name, 107 const lldb::DataBufferSP &data_sp, 108 lldb::ByteOrder data_byte_order, 109 uint8_t data_addr_size 110 ) 111 { 112 return (new ValueObjectConstResult (exe_scope, 113 clang_ast, 114 clang_type, 115 name, 116 data_sp, 117 data_byte_order, 118 data_addr_size))->GetSP(); 119 } 120 121 ValueObjectConstResult::ValueObjectConstResult 122 ( 123 ExecutionContextScope *exe_scope, 124 clang::ASTContext *clang_ast, 125 void *clang_type, 126 const ConstString &name, 127 const lldb::DataBufferSP &data_sp, 128 lldb::ByteOrder data_byte_order, 129 uint8_t data_addr_size 130 ) : 131 ValueObject (exe_scope), 132 m_clang_ast (clang_ast), 133 m_type_name (), 134 m_byte_size (0) 135 { 136 m_data.SetByteOrder(data_byte_order); 137 m_data.SetAddressByteSize(data_addr_size); 138 m_data.SetData(data_sp); 139 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes(); 140 m_value.SetValueType(Value::eValueTypeHostAddress); 141 m_value.SetContext(Value::eContextTypeClangType, clang_type); 142 m_name = name; 143 SetIsConstant (); 144 SetValueIsValid(true); 145 m_pointers_point_to_load_addrs = true; 146 } 147 148 ValueObjectSP 149 ValueObjectConstResult::Create 150 ( 151 ExecutionContextScope *exe_scope, 152 clang::ASTContext *clang_ast, 153 void *clang_type, 154 const ConstString &name, 155 lldb::addr_t address, 156 AddressType address_type, 157 uint8_t addr_byte_size 158 ) 159 { 160 return (new ValueObjectConstResult (exe_scope, 161 clang_ast, 162 clang_type, 163 name, 164 address, 165 address_type, 166 addr_byte_size))->GetSP(); 167 } 168 169 ValueObjectConstResult::ValueObjectConstResult 170 ( 171 ExecutionContextScope *exe_scope, 172 clang::ASTContext *clang_ast, 173 void *clang_type, 174 const ConstString &name, 175 lldb::addr_t address, 176 AddressType address_type, 177 uint8_t addr_byte_size 178 ) : 179 ValueObject (exe_scope), 180 m_clang_ast (clang_ast), 181 m_type_name (), 182 m_byte_size (0) 183 { 184 m_value.GetScalar() = address; 185 m_data.SetAddressByteSize(addr_byte_size); 186 m_value.GetScalar().GetData (m_data, addr_byte_size); 187 //m_value.SetValueType(Value::eValueTypeHostAddress); 188 switch (address_type) 189 { 190 default: 191 case eAddressTypeInvalid: m_value.SetValueType(Value::eValueTypeScalar); break; 192 case eAddressTypeFile: m_value.SetValueType(Value::eValueTypeFileAddress); break; 193 case eAddressTypeLoad: m_value.SetValueType(Value::eValueTypeLoadAddress); break; 194 case eAddressTypeHost: m_value.SetValueType(Value::eValueTypeHostAddress); break; 195 } 196 m_value.SetContext(Value::eContextTypeClangType, clang_type); 197 m_name = name; 198 SetIsConstant (); 199 SetValueIsValid(true); 200 m_pointers_point_to_load_addrs = true; 201 } 202 203 ValueObjectSP 204 ValueObjectConstResult::Create 205 ( 206 ExecutionContextScope *exe_scope, 207 const Error& error 208 ) 209 { 210 return (new ValueObjectConstResult (exe_scope, 211 error))->GetSP(); 212 } 213 214 ValueObjectConstResult::ValueObjectConstResult ( 215 ExecutionContextScope *exe_scope, 216 const Error& error) : 217 ValueObject (exe_scope), 218 m_clang_ast (NULL), 219 m_type_name (), 220 m_byte_size (0) 221 { 222 m_error = error; 223 SetIsConstant (); 224 m_pointers_point_to_load_addrs = true; 225 } 226 227 ValueObjectConstResult::~ValueObjectConstResult() 228 { 229 } 230 231 lldb::clang_type_t 232 ValueObjectConstResult::GetClangType() 233 { 234 return m_value.GetClangType(); 235 } 236 237 lldb::ValueType 238 ValueObjectConstResult::GetValueType() const 239 { 240 return eValueTypeConstResult; 241 } 242 243 size_t 244 ValueObjectConstResult::GetByteSize() 245 { 246 if (m_byte_size == 0) 247 { 248 uint64_t bit_width = ClangASTType::GetClangTypeBitWidth (GetClangAST(), GetClangType()); 249 m_byte_size = (bit_width + 7 ) / 8; 250 } 251 return m_byte_size; 252 } 253 254 void 255 ValueObjectConstResult::SetByteSize (size_t size) 256 { 257 m_byte_size = size; 258 } 259 260 uint32_t 261 ValueObjectConstResult::CalculateNumChildren() 262 { 263 return ClangASTContext::GetNumChildren (GetClangAST (), GetClangType(), true); 264 } 265 266 clang::ASTContext * 267 ValueObjectConstResult::GetClangAST () 268 { 269 return m_clang_ast; 270 } 271 272 ConstString 273 ValueObjectConstResult::GetTypeName() 274 { 275 if (m_type_name.IsEmpty()) 276 m_type_name = ClangASTType::GetClangTypeName (GetClangType()); 277 return m_type_name; 278 } 279 280 bool 281 ValueObjectConstResult::UpdateValue () 282 { 283 // Const value is always valid 284 SetValueIsValid (true); 285 return true; 286 } 287 288 289 bool 290 ValueObjectConstResult::IsInScope () 291 { 292 // A const result value is always in scope since it serializes all 293 // information needed to contain the constant value. 294 return true; 295 } 296