1 //===-- ClangExpressionVariable.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/Expression/ClangExpressionVariable.h"
11
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 #include "clang/AST/ASTContext.h"
17 #include "lldb/Core/ConstString.h"
18 #include "lldb/Core/DataExtractor.h"
19 #include "lldb/Core/Stream.h"
20 #include "lldb/Core/Value.h"
21 #include "lldb/Core/ValueObjectConstResult.h"
22 #include "lldb/Target/ExecutionContext.h"
23 #include "lldb/Target/Process.h"
24
25 using namespace lldb_private;
26 using namespace clang;
27
ClangExpressionVariable(ExecutionContextScope * exe_scope,lldb::ByteOrder byte_order,uint32_t addr_byte_size)28 ClangExpressionVariable::ClangExpressionVariable(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size) :
29 m_parser_vars(),
30 m_jit_vars (),
31 m_flags (EVNone),
32 m_frozen_sp (ValueObjectConstResult::Create (exe_scope, byte_order, addr_byte_size))
33 {
34 }
35
ClangExpressionVariable(const lldb::ValueObjectSP & valobj_sp)36 ClangExpressionVariable::ClangExpressionVariable (const lldb::ValueObjectSP &valobj_sp) :
37 m_parser_vars(),
38 m_jit_vars (),
39 m_flags (EVNone),
40 m_frozen_sp (valobj_sp)
41 {
42 }
43
44 //----------------------------------------------------------------------
45 /// Return the variable's size in bytes
46 //----------------------------------------------------------------------
47 size_t
GetByteSize()48 ClangExpressionVariable::GetByteSize ()
49 {
50 return m_frozen_sp->GetByteSize();
51 }
52
53 const ConstString &
GetName()54 ClangExpressionVariable::GetName ()
55 {
56 return m_frozen_sp->GetName();
57 }
58
59 lldb::ValueObjectSP
GetValueObject()60 ClangExpressionVariable::GetValueObject()
61 {
62 return m_frozen_sp;
63 }
64
65 RegisterInfo *
GetRegisterInfo()66 ClangExpressionVariable::GetRegisterInfo()
67 {
68 return m_frozen_sp->GetValue().GetRegisterInfo();
69 }
70
71 void
SetRegisterInfo(const RegisterInfo * reg_info)72 ClangExpressionVariable::SetRegisterInfo (const RegisterInfo *reg_info)
73 {
74 return m_frozen_sp->GetValue().SetContext (Value::eContextTypeRegisterInfo, const_cast<RegisterInfo *>(reg_info));
75 }
76
77 ClangASTType
GetClangType()78 ClangExpressionVariable::GetClangType()
79 {
80 return m_frozen_sp->GetClangType();
81 }
82
83 void
SetClangType(const ClangASTType & clang_type)84 ClangExpressionVariable::SetClangType(const ClangASTType &clang_type)
85 {
86 m_frozen_sp->GetValue().SetClangType(clang_type);
87 }
88
89
90 TypeFromUser
GetTypeFromUser()91 ClangExpressionVariable::GetTypeFromUser()
92 {
93 TypeFromUser tfu (m_frozen_sp->GetClangType());
94 return tfu;
95 }
96
97 uint8_t *
GetValueBytes()98 ClangExpressionVariable::GetValueBytes()
99 {
100 const size_t byte_size = m_frozen_sp->GetByteSize();
101 if (byte_size > 0)
102 {
103 if (m_frozen_sp->GetDataExtractor().GetByteSize() < byte_size)
104 {
105 m_frozen_sp->GetValue().ResizeData(byte_size);
106 m_frozen_sp->GetValue().GetData (m_frozen_sp->GetDataExtractor());
107 }
108 return const_cast<uint8_t *>(m_frozen_sp->GetDataExtractor().GetDataStart());
109 }
110 return NULL;
111 }
112
113 void
SetName(const ConstString & name)114 ClangExpressionVariable::SetName (const ConstString &name)
115 {
116 m_frozen_sp->SetName (name);
117 }
118
119 void
ValueUpdated()120 ClangExpressionVariable::ValueUpdated ()
121 {
122 m_frozen_sp->ValueUpdated ();
123 }
124
125 void
TransferAddress(bool force)126 ClangExpressionVariable::TransferAddress (bool force)
127 {
128 if (m_live_sp.get() == NULL)
129 return;
130
131 if (m_frozen_sp.get() == NULL)
132 return;
133
134 if (force || (m_frozen_sp->GetLiveAddress() == LLDB_INVALID_ADDRESS))
135 m_frozen_sp->SetLiveAddress(m_live_sp->GetLiveAddress());
136 }
137