blob: e9d970baf34965e0230eaf01c57b1d0ad3f786b9 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBValue.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
Eli Friedman7a62c8b2010-06-09 07:44:37 +000010#include "lldb/API/SBValue.h"
Chris Lattner24943d22010-06-08 16:52:24 +000011
12#include "lldb/Core/DataExtractor.h"
13#include "lldb/Core/Module.h"
14#include "lldb/Core/Stream.h"
15#include "lldb/Core/StreamFile.h"
16#include "lldb/Core/Value.h"
17#include "lldb/Core/ValueObject.h"
18#include "lldb/Symbol/Block.h"
19#include "lldb/Symbol/ObjectFile.h"
20#include "lldb/Symbol/Variable.h"
21#include "lldb/Target/ExecutionContext.h"
22#include "lldb/Target/Process.h"
23#include "lldb/Target/StackFrame.h"
24#include "lldb/Target/Thread.h"
25
Eli Friedman7a62c8b2010-06-09 07:44:37 +000026#include "lldb/API/SBProcess.h"
27#include "lldb/API/SBTarget.h"
28#include "lldb/API/SBThread.h"
29#include "lldb/API/SBFrame.h"
30#include "lldb/API/SBDebugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000031
32using namespace lldb;
33using namespace lldb_private;
34
35SBValue::SBValue () :
Greg Clayton63094e02010-06-23 01:19:29 +000036 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000037{
38}
39
40SBValue::SBValue (const lldb::ValueObjectSP &value_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000041 m_opaque_sp (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000042{
43}
44
45SBValue::~SBValue()
46{
47}
48
49bool
50SBValue::IsValid () const
51{
Greg Clayton63094e02010-06-23 01:19:29 +000052 return (m_opaque_sp.get() != NULL);
Chris Lattner24943d22010-06-08 16:52:24 +000053}
54
Chris Lattner24943d22010-06-08 16:52:24 +000055const char *
56SBValue::GetName()
57{
58 if (IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000059 return m_opaque_sp->GetName().AsCString();
Chris Lattner24943d22010-06-08 16:52:24 +000060 else
61 return NULL;
62}
63
64const char *
65SBValue::GetTypeName ()
66{
67 if (IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000068 return m_opaque_sp->GetTypeName().AsCString();
Chris Lattner24943d22010-06-08 16:52:24 +000069 else
70 return NULL;
71}
72
73size_t
74SBValue::GetByteSize ()
75{
76 size_t result = 0;
77
78 if (IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000079 result = m_opaque_sp->GetByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +000080
81 return result;
82}
83
84bool
85SBValue::IsInScope (const SBFrame &frame)
86{
87 bool result = false;
88
89 if (IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000090 result = m_opaque_sp->IsInScope (frame.get());
Chris Lattner24943d22010-06-08 16:52:24 +000091
92 return result;
93}
94
95const char *
96SBValue::GetValue (const SBFrame &frame)
97{
98 const char *value_string = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +000099 if ( m_opaque_sp)
Greg Clayton17dae082010-09-02 02:59:18 +0000100 value_string = m_opaque_sp->GetValueAsCString (frame.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000101 return value_string;
102}
103
Jim Ingham4ae51962010-09-10 23:12:17 +0000104const char *
105SBValue::GetObjectDescription (const SBFrame &frame)
106{
107 const char *value_string = NULL;
108 if ( m_opaque_sp)
109 value_string = m_opaque_sp->GetObjectDescription (frame.get());
110 return value_string;
111}
112
Chris Lattner24943d22010-06-08 16:52:24 +0000113bool
Greg Clayton17dae082010-09-02 02:59:18 +0000114SBValue::GetValueDidChange (const SBFrame &frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000115{
116 if (IsValid())
Greg Clayton17dae082010-09-02 02:59:18 +0000117 return m_opaque_sp->GetValueDidChange (frame.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000118 return false;
119}
120
121const char *
122SBValue::GetSummary (const SBFrame &frame)
123{
124 const char *value_string = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000125 if ( m_opaque_sp)
126 value_string = m_opaque_sp->GetSummaryAsCString(frame.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000127 return value_string;
128}
129
130const char *
131SBValue::GetLocation (const SBFrame &frame)
132{
133 const char *value_string = NULL;
134 if (IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +0000135 value_string = m_opaque_sp->GetLocationAsCString(frame.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000136 return value_string;
137}
138
139bool
140SBValue::SetValueFromCString (const SBFrame &frame, const char *value_str)
141{
142 bool success = false;
143 if (IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +0000144 success = m_opaque_sp->SetValueFromCString (frame.get(), value_str);
Chris Lattner24943d22010-06-08 16:52:24 +0000145 return success;
146}
147
148SBValue
149SBValue::GetChildAtIndex (uint32_t idx)
150{
151 lldb::ValueObjectSP child_sp;
152
153 if (IsValid())
154 {
Greg Clayton63094e02010-06-23 01:19:29 +0000155 child_sp = m_opaque_sp->GetChildAtIndex (idx, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000156 }
157
158 SBValue sb_value (child_sp);
159 return sb_value;
160}
161
162uint32_t
163SBValue::GetIndexOfChildWithName (const char *name)
164{
165 if (IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +0000166 return m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
Chris Lattner24943d22010-06-08 16:52:24 +0000167 return UINT32_MAX;
168}
169
170SBValue
171SBValue::GetChildMemberWithName (const char *name)
172{
173 lldb::ValueObjectSP child_sp;
174 const ConstString str_name (name);
175
176 if (IsValid())
177 {
Greg Clayton63094e02010-06-23 01:19:29 +0000178 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000179 }
180
181 SBValue sb_value (child_sp);
182 return sb_value;
183}
184
185
186uint32_t
187SBValue::GetNumChildren ()
188{
189 uint32_t num_children = 0;
190
191 if (IsValid())
192 {
Greg Clayton63094e02010-06-23 01:19:29 +0000193 num_children = m_opaque_sp->GetNumChildren();
Chris Lattner24943d22010-06-08 16:52:24 +0000194 }
195
196 return num_children;
197}
198
199bool
200SBValue::ValueIsStale ()
201{
202 bool result = true;
203
204 if (IsValid())
205 {
Greg Clayton63094e02010-06-23 01:19:29 +0000206 result = m_opaque_sp->GetValueIsValid();
Chris Lattner24943d22010-06-08 16:52:24 +0000207 }
208
209 return result;
210}
211
212
213SBValue
214SBValue::Dereference ()
215{
216 if (IsValid())
217 {
Greg Clayton63094e02010-06-23 01:19:29 +0000218 if (m_opaque_sp->IsPointerType())
Chris Lattner24943d22010-06-08 16:52:24 +0000219 {
220 return GetChildAtIndex(0);
221 }
222 }
223 return *this;
224}
225
226bool
227SBValue::TypeIsPtrType ()
228{
229 bool is_ptr_type = false;
230
231 if (IsValid())
232 {
Greg Clayton63094e02010-06-23 01:19:29 +0000233 is_ptr_type = m_opaque_sp->IsPointerType();
Chris Lattner24943d22010-06-08 16:52:24 +0000234 }
235
236 return is_ptr_type;
237}
238
Chris Lattner24943d22010-06-08 16:52:24 +0000239void *
240SBValue::GetOpaqueType()
241{
Greg Clayton63094e02010-06-23 01:19:29 +0000242 if (m_opaque_sp)
243 return m_opaque_sp->GetOpaqueClangQualType();
Chris Lattner24943d22010-06-08 16:52:24 +0000244 return NULL;
245}
246
247// Mimic shared pointer...
248lldb_private::ValueObject *
249SBValue::get() const
250{
Greg Clayton63094e02010-06-23 01:19:29 +0000251 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000252}
253
254lldb_private::ValueObject *
255SBValue::operator->() const
256{
Greg Clayton63094e02010-06-23 01:19:29 +0000257 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000258}
259
260lldb::ValueObjectSP &
261SBValue::operator*()
262{
Greg Clayton63094e02010-06-23 01:19:29 +0000263 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000264}
265
266const lldb::ValueObjectSP &
267SBValue::operator*() const
268{
Greg Clayton63094e02010-06-23 01:19:29 +0000269 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000270}