1 //===-- ValueObjectVariable.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 11 #include "lldb/Core/ValueObjectVariable.h" 12 13 // C Includes 14 // C++ Includes 15 // Other libraries and framework includes 16 // Project includes 17 #include "lldb/Core/Module.h" 18 #include "lldb/Core/ValueObjectList.h" 19 #include "lldb/Core/Value.h" 20 21 #include "lldb/Symbol/ObjectFile.h" 22 #include "lldb/Symbol/SymbolContext.h" 23 #include "lldb/Symbol/Type.h" 24 #include "lldb/Symbol/Variable.h" 25 26 #include "lldb/Target/ExecutionContext.h" 27 #include "lldb/Target/Process.h" 28 #include "lldb/Target/RegisterContext.h" 29 #include "lldb/Target/Target.h" 30 #include "lldb/Target/Thread.h" 31 32 33 using namespace lldb_private; 34 35 ValueObjectVariable::ValueObjectVariable (lldb::VariableSP &var_sp) : 36 ValueObject(), 37 m_variable_sp(var_sp) 38 { 39 // Do not attempt to construct one of these objects with no variable! 40 assert (m_variable_sp.get() != NULL); 41 m_name = var_sp->GetName(); 42 } 43 44 ValueObjectVariable::~ValueObjectVariable() 45 { 46 } 47 48 void * 49 ValueObjectVariable::GetOpaqueClangQualType () 50 { 51 Type *var_type = m_variable_sp->GetType(); 52 if (var_type) 53 return var_type->GetOpaqueClangQualType(); 54 return NULL; 55 } 56 57 ConstString 58 ValueObjectVariable::GetTypeName() 59 { 60 Type * var_type = m_variable_sp->GetType(); 61 if (var_type) 62 return var_type->GetName(); 63 ConstString empty_type_name; 64 return empty_type_name; 65 } 66 67 uint32_t 68 ValueObjectVariable::CalculateNumChildren() 69 { 70 Type *var_type = m_variable_sp->GetType(); 71 if (var_type) 72 return var_type->GetNumChildren(true); 73 return 0; 74 } 75 76 clang::ASTContext * 77 ValueObjectVariable::GetClangAST () 78 { 79 return m_variable_sp->GetType()->GetClangAST(); 80 } 81 82 size_t 83 ValueObjectVariable::GetByteSize() 84 { 85 return m_variable_sp->GetType()->GetByteSize(); 86 } 87 88 lldb::ValueType 89 ValueObjectVariable::GetValueType() const 90 { 91 if (m_variable_sp) 92 return m_variable_sp->GetScope(); 93 return lldb::eValueTypeInvalid; 94 } 95 96 97 98 void 99 ValueObjectVariable::UpdateValue (ExecutionContextScope *exe_scope) 100 { 101 SetValueIsValid (false); 102 m_error.Clear(); 103 104 Variable *variable = m_variable_sp.get(); 105 DWARFExpression &expr = variable->LocationExpression(); 106 Value old_value(m_value); 107 ExecutionContext exe_ctx (exe_scope); 108 if (expr.Evaluate (&exe_ctx, GetClangAST(), NULL, m_value, &m_error)) 109 { 110 m_value.SetContext(Value::eContextTypeDCVariable, variable); 111 112 Value::ValueType value_type = m_value.GetValueType(); 113 114 switch (value_type) 115 { 116 default: 117 assert(!"Unhandled expression result value kind..."); 118 break; 119 120 case Value::eValueTypeScalar: 121 // The variable value is in the Scalar value inside the m_value. 122 // We can point our m_data right to it. 123 m_error = m_value.GetValueAsData (&exe_ctx, GetClangAST(), m_data, 0); 124 break; 125 126 case Value::eValueTypeFileAddress: 127 case Value::eValueTypeLoadAddress: 128 case Value::eValueTypeHostAddress: 129 // The DWARF expression result was an address in the inferior 130 // process. If this variable is an aggregate type, we just need 131 // the address as the main value as all child variable objects 132 // will rely upon this location and add an offset and then read 133 // their own values as needed. If this variable is a simple 134 // type, we read all data for it into m_data. 135 // Make sure this type has a value before we try and read it 136 if (ClangASTContext::IsAggregateType (GetOpaqueClangQualType())) 137 { 138 // this value object represents an aggregate type whose 139 // children have values, but this object does not. So we 140 // say we are changed if our location has changed. 141 SetValueDidChange (value_type != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar()); 142 } 143 else 144 { 145 // Copy the Value and set the context to use our Variable 146 // so it can extract read its value into m_data appropriately 147 Value value(m_value); 148 value.SetContext(Value::eContextTypeDCVariable, variable); 149 m_error = value.GetValueAsData(&exe_ctx, GetClangAST(), m_data, 0); 150 } 151 break; 152 } 153 154 SetValueIsValid (m_error.Success()); 155 } 156 } 157 158 159 160 bool 161 ValueObjectVariable::IsInScope (StackFrame *frame) 162 { 163 return m_variable_sp->IsInScope (frame); 164 } 165 166