blob: d6798f563cc94ba79c9e0b3e5de098203d2d5b90 [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),
32 m_index (0),
33 m_parser_vars(),
34 m_jit_vars (),
35 m_data_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000036{
37}
38
Greg Clayton66ed2fb2010-10-05 00:00:42 +000039void
40ClangExpressionVariable::DisableDataVars()
Chris Lattner24943d22010-06-08 16:52:24 +000041{
Greg Clayton66ed2fb2010-10-05 00:00:42 +000042 m_data_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +000043}
44
Jim Ingham324067b2010-09-30 00:54:27 +000045
Greg Clayton66ed2fb2010-10-05 00:00:42 +000046ClangExpressionVariable::ClangExpressionVariable(const ClangExpressionVariable &rhs) :
47 m_name(rhs.m_name),
48 m_user_type(rhs.m_user_type),
49 m_store(rhs.m_store),
50 m_index(rhs.m_index)
Chris Lattner24943d22010-06-08 16:52:24 +000051{
Greg Clayton66ed2fb2010-10-05 00:00:42 +000052 if (rhs.m_parser_vars.get())
Sean Callanana6223432010-08-20 01:02:30 +000053 {
Greg Clayton66ed2fb2010-10-05 00:00:42 +000054 // TODO: Sean, can m_parser_vars be a shared pointer??? We are copy
55 // constructing it here. That is ok if we need to, but do we really
56 // need to?
Sean Callanana6223432010-08-20 01:02:30 +000057 m_parser_vars.reset(new struct ParserVars);
Greg Clayton66ed2fb2010-10-05 00:00:42 +000058 *m_parser_vars.get() = *rhs.m_parser_vars.get();
Sean Callanana6223432010-08-20 01:02:30 +000059 }
Chris Lattner24943d22010-06-08 16:52:24 +000060
Greg Clayton66ed2fb2010-10-05 00:00:42 +000061 if (rhs.m_jit_vars.get())
Sean Callanana6223432010-08-20 01:02:30 +000062 {
Greg Clayton66ed2fb2010-10-05 00:00:42 +000063 // TODO: Sean, can m_jit_vars be a shared pointer??? We are copy
64 // constructing it here. That is ok if we need to, but do we really
65 // need to?
Sean Callanana6223432010-08-20 01:02:30 +000066 m_jit_vars.reset(new struct JITVars);
Greg Clayton66ed2fb2010-10-05 00:00:42 +000067 *m_jit_vars.get() = *rhs.m_jit_vars.get();
Sean Callanana6223432010-08-20 01:02:30 +000068 }
69
Greg Clayton66ed2fb2010-10-05 00:00:42 +000070 if (rhs.m_data_sp)
Sean Callanana6223432010-08-20 01:02:30 +000071 {
Greg Clayton66ed2fb2010-10-05 00:00:42 +000072 // TODO: Sean, does m_data_sp need to be copy constructed? Or can it
73 // shared the data?
74
75 m_data_sp.reset(new DataBufferHeap (rhs.m_data_sp->GetBytes(),
76 rhs.m_data_sp->GetByteSize()));
Sean Callanana6223432010-08-20 01:02:30 +000077 }
78}
79
80bool
Jim Ingham324067b2010-09-30 00:54:27 +000081ClangExpressionVariable::PointValueAtData(Value &value, ExecutionContext *exe_ctx)
Sean Callanana6223432010-08-20 01:02:30 +000082{
Greg Clayton66ed2fb2010-10-05 00:00:42 +000083 if (m_data_sp.get() == NULL)
Sean Callanana6223432010-08-20 01:02:30 +000084 return false;
85
86 value.SetContext(Value::eContextTypeOpaqueClangQualType, m_user_type.GetOpaqueQualType());
87 value.SetValueType(Value::eValueTypeHostAddress);
Greg Clayton66ed2fb2010-10-05 00:00:42 +000088 value.GetScalar() = (uintptr_t)m_data_sp->GetBytes();
Jim Ingham324067b2010-09-30 00:54:27 +000089 clang::ASTContext *ast_context = m_user_type.GetASTContext();
90
91 if (exe_ctx)
92 value.ResolveValue (exe_ctx, ast_context);
Sean Callanana6223432010-08-20 01:02:30 +000093
94 return true;
Chris Lattner24943d22010-06-08 16:52:24 +000095}
Greg Clayton66ed2fb2010-10-05 00:00:42 +000096
97void
98ClangExpressionVariable::EnableDataVars()
99{
100 if (!m_data_sp.get())
101 m_data_sp.reset(new DataBufferHeap);
102}
103
104lldb::ValueObjectSP
105ClangExpressionVariable::GetExpressionResult (ExecutionContext *exe_ctx)
106{
107 lldb::ValueObjectSP result_sp;
108 if (m_data_sp)
109 {
110 Target * target = NULL;
111 Process *process = NULL;
112 if (exe_ctx)
113 {
114 target = exe_ctx->target;
115 process = exe_ctx->process;
116 }
117
118 Value value;
119 if (PointValueAtData(value, exe_ctx))
120 {
121 lldb::ByteOrder byte_order = lldb::eByteOrderHost;
122 uint32_t addr_byte_size = 4;
123 if (process)
124 {
125 byte_order = process->GetByteOrder();
126 addr_byte_size = process->GetAddressByteSize();
127 }
128 result_sp.reset (new ValueObjectConstResult (m_user_type.GetASTContext(),
129 m_user_type.GetOpaqueQualType(),
130 ConstString (m_name.c_str()),
131 m_data_sp,// TODO: sean can you get this to be valid?
132 byte_order,
133 addr_byte_size));
134 }
135 }
136 return result_sp;
137}
138