blob: 6a78363c2bef7a7dbf6bada2f569f613460719df [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),
50 m_store(rhs.m_store),
51 m_index(rhs.m_index)
Chris Lattner24943d22010-06-08 16:52:24 +000052{
Greg Clayton66ed2fb2010-10-05 00:00:42 +000053 if (rhs.m_parser_vars.get())
Sean Callanana6223432010-08-20 01:02:30 +000054 {
Greg Clayton66ed2fb2010-10-05 00:00:42 +000055 // TODO: Sean, can m_parser_vars be a shared pointer??? We are copy
56 // constructing it here. That is ok if we need to, but do we really
57 // need to?
Sean Callanana6223432010-08-20 01:02:30 +000058 m_parser_vars.reset(new struct ParserVars);
Greg Clayton66ed2fb2010-10-05 00:00:42 +000059 *m_parser_vars.get() = *rhs.m_parser_vars.get();
Sean Callanana6223432010-08-20 01:02:30 +000060 }
Chris Lattner24943d22010-06-08 16:52:24 +000061
Greg Clayton66ed2fb2010-10-05 00:00:42 +000062 if (rhs.m_jit_vars.get())
Sean Callanana6223432010-08-20 01:02:30 +000063 {
Greg Clayton66ed2fb2010-10-05 00:00:42 +000064 // TODO: Sean, can m_jit_vars be a shared pointer??? We are copy
65 // constructing it here. That is ok if we need to, but do we really
66 // need to?
Sean Callanana6223432010-08-20 01:02:30 +000067 m_jit_vars.reset(new struct JITVars);
Greg Clayton66ed2fb2010-10-05 00:00:42 +000068 *m_jit_vars.get() = *rhs.m_jit_vars.get();
Sean Callanana6223432010-08-20 01:02:30 +000069 }
70
Greg Clayton66ed2fb2010-10-05 00:00:42 +000071 if (rhs.m_data_sp)
Sean Callanana6223432010-08-20 01:02:30 +000072 {
Greg Clayton66ed2fb2010-10-05 00:00:42 +000073 // TODO: Sean, does m_data_sp need to be copy constructed? Or can it
74 // shared the data?
75
76 m_data_sp.reset(new DataBufferHeap (rhs.m_data_sp->GetBytes(),
77 rhs.m_data_sp->GetByteSize()));
Sean Callanana6223432010-08-20 01:02:30 +000078 }
79}
80
81bool
Jim Ingham324067b2010-09-30 00:54:27 +000082ClangExpressionVariable::PointValueAtData(Value &value, ExecutionContext *exe_ctx)
Sean Callanana6223432010-08-20 01:02:30 +000083{
Greg Clayton66ed2fb2010-10-05 00:00:42 +000084 if (m_data_sp.get() == NULL)
Sean Callanana6223432010-08-20 01:02:30 +000085 return false;
86
Greg Clayton6916e352010-11-13 03:52:47 +000087 value.SetContext(Value::eContextTypeClangType, m_user_type.GetOpaqueQualType());
Sean Callanana6223432010-08-20 01:02:30 +000088 value.SetValueType(Value::eValueTypeHostAddress);
Greg Clayton66ed2fb2010-10-05 00:00:42 +000089 value.GetScalar() = (uintptr_t)m_data_sp->GetBytes();
Jim Ingham324067b2010-09-30 00:54:27 +000090 clang::ASTContext *ast_context = m_user_type.GetASTContext();
91
92 if (exe_ctx)
93 value.ResolveValue (exe_ctx, ast_context);
Sean Callanana6223432010-08-20 01:02:30 +000094
95 return true;
Chris Lattner24943d22010-06-08 16:52:24 +000096}
Greg Clayton66ed2fb2010-10-05 00:00:42 +000097
98void
99ClangExpressionVariable::EnableDataVars()
100{
101 if (!m_data_sp.get())
102 m_data_sp.reset(new DataBufferHeap);
103}
104
105lldb::ValueObjectSP
106ClangExpressionVariable::GetExpressionResult (ExecutionContext *exe_ctx)
107{
108 lldb::ValueObjectSP result_sp;
109 if (m_data_sp)
110 {
111 Target * target = NULL;
112 Process *process = NULL;
113 if (exe_ctx)
114 {
115 target = exe_ctx->target;
116 process = exe_ctx->process;
117 }
118
119 Value value;
120 if (PointValueAtData(value, exe_ctx))
121 {
122 lldb::ByteOrder byte_order = lldb::eByteOrderHost;
123 uint32_t addr_byte_size = 4;
124 if (process)
125 {
126 byte_order = process->GetByteOrder();
127 addr_byte_size = process->GetAddressByteSize();
128 }
129 result_sp.reset (new ValueObjectConstResult (m_user_type.GetASTContext(),
130 m_user_type.GetOpaqueQualType(),
Greg Clayton8de27c72010-10-15 22:48:33 +0000131 m_name,
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000132 m_data_sp,// TODO: sean can you get this to be valid?
133 byte_order,
134 addr_byte_size));
135 }
136 }
137 return result_sp;
138}
139