blob: a85bc2498790ef23900083e7eb048829f4201db1 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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"
Sean Callanana6223432010-08-20 01:02:30 +000017#include "lldb/Core/ConstString.h"
18#include "lldb/Core/DataExtractor.h"
19#include "lldb/Core/Stream.h"
20#include "lldb/Core/Value.h"
Greg Clayton66ed2fb2010-10-05 00:00:42 +000021#include "lldb/Core/ValueObjectConstResult.h"
Sean Callanane8a59a82010-09-13 21:34:21 +000022#include "lldb/Target/ExecutionContext.h"
23#include "lldb/Target/Process.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024
25using namespace lldb_private;
26using namespace clang;
27
Greg Clayton66ed2fb2010-10-05 00:00:42 +000028ClangExpressionVariable::ClangExpressionVariable() :
29 m_name(),
30 m_user_type (TypeFromUser(NULL, NULL)),
31 m_store (NULL),
Sean Callanan1ddd9fe2010-11-30 00:27:43 +000032 m_register_info (NULL),
Greg Clayton66ed2fb2010-10-05 00:00:42 +000033 m_index (0),
34 m_parser_vars(),
35 m_jit_vars (),
36 m_data_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000037{
38}
39
Greg Clayton66ed2fb2010-10-05 00:00:42 +000040void
41ClangExpressionVariable::DisableDataVars()
Chris Lattner24943d22010-06-08 16:52:24 +000042{
Greg Clayton66ed2fb2010-10-05 00:00:42 +000043 m_data_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +000044}
45
Jim Ingham324067b2010-09-30 00:54:27 +000046
Greg Clayton66ed2fb2010-10-05 00:00:42 +000047ClangExpressionVariable::ClangExpressionVariable(const ClangExpressionVariable &rhs) :
48 m_name(rhs.m_name),
49 m_user_type(rhs.m_user_type),
Sean Callanan1e61a632010-11-30 22:01:58 +000050 m_store(rhs.m_store),
51 m_register_info(rhs.m_register_info),
Greg Clayton66ed2fb2010-10-05 00:00:42 +000052 m_index(rhs.m_index)
Chris Lattner24943d22010-06-08 16:52:24 +000053{
Greg Clayton66ed2fb2010-10-05 00:00:42 +000054 if (rhs.m_parser_vars.get())
Sean Callanana6223432010-08-20 01:02:30 +000055 {
Greg Clayton66ed2fb2010-10-05 00:00:42 +000056 // TODO: Sean, can m_parser_vars be a shared pointer??? We are copy
57 // constructing it here. That is ok if we need to, but do we really
58 // need to?
Sean Callanana6223432010-08-20 01:02:30 +000059 m_parser_vars.reset(new struct ParserVars);
Greg Clayton66ed2fb2010-10-05 00:00:42 +000060 *m_parser_vars.get() = *rhs.m_parser_vars.get();
Sean Callanana6223432010-08-20 01:02:30 +000061 }
Chris Lattner24943d22010-06-08 16:52:24 +000062
Greg Clayton66ed2fb2010-10-05 00:00:42 +000063 if (rhs.m_jit_vars.get())
Sean Callanana6223432010-08-20 01:02:30 +000064 {
Greg Clayton66ed2fb2010-10-05 00:00:42 +000065 // TODO: Sean, can m_jit_vars be a shared pointer??? We are copy
66 // constructing it here. That is ok if we need to, but do we really
67 // need to?
Sean Callanana6223432010-08-20 01:02:30 +000068 m_jit_vars.reset(new struct JITVars);
Greg Clayton66ed2fb2010-10-05 00:00:42 +000069 *m_jit_vars.get() = *rhs.m_jit_vars.get();
Sean Callanana6223432010-08-20 01:02:30 +000070 }
71
Greg Clayton66ed2fb2010-10-05 00:00:42 +000072 if (rhs.m_data_sp)
Sean Callanana6223432010-08-20 01:02:30 +000073 {
Greg Clayton66ed2fb2010-10-05 00:00:42 +000074 // TODO: Sean, does m_data_sp need to be copy constructed? Or can it
75 // shared the data?
76
77 m_data_sp.reset(new DataBufferHeap (rhs.m_data_sp->GetBytes(),
78 rhs.m_data_sp->GetByteSize()));
Sean Callanana6223432010-08-20 01:02:30 +000079 }
80}
81
82bool
Jim Ingham324067b2010-09-30 00:54:27 +000083ClangExpressionVariable::PointValueAtData(Value &value, ExecutionContext *exe_ctx)
Sean Callanana6223432010-08-20 01:02:30 +000084{
Greg Clayton66ed2fb2010-10-05 00:00:42 +000085 if (m_data_sp.get() == NULL)
Sean Callanana6223432010-08-20 01:02:30 +000086 return false;
87
Greg Clayton6916e352010-11-13 03:52:47 +000088 value.SetContext(Value::eContextTypeClangType, m_user_type.GetOpaqueQualType());
Sean Callanana6223432010-08-20 01:02:30 +000089 value.SetValueType(Value::eValueTypeHostAddress);
Greg Clayton66ed2fb2010-10-05 00:00:42 +000090 value.GetScalar() = (uintptr_t)m_data_sp->GetBytes();
Jim Ingham324067b2010-09-30 00:54:27 +000091 clang::ASTContext *ast_context = m_user_type.GetASTContext();
92
93 if (exe_ctx)
94 value.ResolveValue (exe_ctx, ast_context);
Sean Callanana6223432010-08-20 01:02:30 +000095
96 return true;
Chris Lattner24943d22010-06-08 16:52:24 +000097}
Greg Clayton66ed2fb2010-10-05 00:00:42 +000098
99void
100ClangExpressionVariable::EnableDataVars()
101{
102 if (!m_data_sp.get())
103 m_data_sp.reset(new DataBufferHeap);
104}
105
106lldb::ValueObjectSP
107ClangExpressionVariable::GetExpressionResult (ExecutionContext *exe_ctx)
108{
109 lldb::ValueObjectSP result_sp;
110 if (m_data_sp)
111 {
112 Target * target = NULL;
113 Process *process = NULL;
114 if (exe_ctx)
115 {
116 target = exe_ctx->target;
117 process = exe_ctx->process;
118 }
119
120 Value value;
121 if (PointValueAtData(value, exe_ctx))
122 {
123 lldb::ByteOrder byte_order = lldb::eByteOrderHost;
124 uint32_t addr_byte_size = 4;
125 if (process)
126 {
127 byte_order = process->GetByteOrder();
128 addr_byte_size = process->GetAddressByteSize();
129 }
130 result_sp.reset (new ValueObjectConstResult (m_user_type.GetASTContext(),
131 m_user_type.GetOpaqueQualType(),
Greg Clayton8de27c72010-10-15 22:48:33 +0000132 m_name,
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000133 m_data_sp,// TODO: sean can you get this to be valid?
134 byte_order,
135 addr_byte_size));
136 }
137 }
138 return result_sp;
139}
140