blob: b72c8f181b89d0e73cbef9a98a60b70c0beb59df [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"
Caroline Tice98f930f2010-09-20 05:20:02 +000011#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000012
Johnny Chenecd4feb2011-10-14 00:42:25 +000013#include "lldb/Breakpoint/Watchpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000014#include "lldb/Core/DataExtractor.h"
Caroline Tice7826c882010-10-26 03:11:13 +000015#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/Core/Module.h"
Greg Clayton0fb0bcc2011-08-03 22:57:10 +000017#include "lldb/Core/Scalar.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/Core/Stream.h"
19#include "lldb/Core/StreamFile.h"
20#include "lldb/Core/Value.h"
21#include "lldb/Core/ValueObject.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000022#include "lldb/Core/ValueObjectConstResult.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Symbol/Block.h"
24#include "lldb/Symbol/ObjectFile.h"
25#include "lldb/Symbol/Variable.h"
Johnny Chenecd4feb2011-10-14 00:42:25 +000026#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000027#include "lldb/Target/ExecutionContext.h"
28#include "lldb/Target/Process.h"
29#include "lldb/Target/StackFrame.h"
Greg Claytonbdcda462010-12-20 20:49:23 +000030#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000031#include "lldb/Target/Thread.h"
32
Eli Friedman7a62c8b2010-06-09 07:44:37 +000033#include "lldb/API/SBProcess.h"
34#include "lldb/API/SBTarget.h"
35#include "lldb/API/SBThread.h"
36#include "lldb/API/SBFrame.h"
37#include "lldb/API/SBDebugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000038
39using namespace lldb;
40using namespace lldb_private;
41
42SBValue::SBValue () :
Greg Clayton63094e02010-06-23 01:19:29 +000043 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000044{
45}
46
47SBValue::SBValue (const lldb::ValueObjectSP &value_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000048 m_opaque_sp (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000049{
50}
51
Greg Clayton538eb822010-11-05 23:17:00 +000052SBValue::SBValue(const SBValue &rhs) :
53 m_opaque_sp (rhs.m_opaque_sp)
54{
55}
56
Greg Claytond68e0892011-09-09 23:04:00 +000057SBValue &
Greg Clayton538eb822010-11-05 23:17:00 +000058SBValue::operator = (const SBValue &rhs)
59{
60 if (this != &rhs)
61 m_opaque_sp = rhs.m_opaque_sp;
62 return *this;
63}
64
Chris Lattner24943d22010-06-08 16:52:24 +000065SBValue::~SBValue()
66{
67}
68
69bool
Greg Claytond68e0892011-09-09 23:04:00 +000070SBValue::IsValid ()
Chris Lattner24943d22010-06-08 16:52:24 +000071{
Greg Clayton49ce6822010-10-31 03:01:06 +000072 // If this function ever changes to anything that does more than just
73 // check if the opaque shared pointer is non NULL, then we need to update
74 // all "if (m_opaque_sp)" code in this file.
75 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000076}
77
Jim Inghame0bd5712011-12-19 20:39:44 +000078void
79SBValue::Clear()
80{
81 m_opaque_sp.reset();
82}
83
Greg Claytonc5f728c2010-10-06 22:10:17 +000084SBError
85SBValue::GetError()
86{
87 SBError sb_error;
88
89 if (m_opaque_sp.get())
90 sb_error.SetError(m_opaque_sp->GetError());
Greg Clayton334d33a2012-01-30 07:41:31 +000091 else
92 sb_error.SetErrorString("error: invalid value");
Greg Claytonc5f728c2010-10-06 22:10:17 +000093
94 return sb_error;
95}
96
Johnny Chen968958c2011-07-07 20:46:23 +000097user_id_t
98SBValue::GetID()
99{
100 if (m_opaque_sp)
101 return m_opaque_sp->GetID();
102 return LLDB_INVALID_UID;
103}
104
Chris Lattner24943d22010-06-08 16:52:24 +0000105const char *
106SBValue::GetName()
107{
Greg Clayton49ce6822010-10-31 03:01:06 +0000108
109 const char *name = NULL;
110 if (m_opaque_sp)
111 name = m_opaque_sp->GetName().GetCString();
112
Greg Claytone005f2c2010-11-06 01:53:30 +0000113 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000114 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000115 {
116 if (name)
117 log->Printf ("SBValue(%p)::GetName () => \"%s\"", m_opaque_sp.get(), name);
118 else
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000119 log->Printf ("SBValue(%p)::GetName () => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000120 }
Caroline Tice7826c882010-10-26 03:11:13 +0000121
Greg Clayton49ce6822010-10-31 03:01:06 +0000122 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000123}
124
125const char *
126SBValue::GetTypeName ()
127{
Greg Clayton49ce6822010-10-31 03:01:06 +0000128 const char *name = NULL;
129 if (m_opaque_sp)
130 name = m_opaque_sp->GetTypeName().GetCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000131 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000132 if (log)
133 {
134 if (name)
135 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", m_opaque_sp.get(), name);
136 else
137 log->Printf ("SBValue(%p)::GetTypeName () => NULL", m_opaque_sp.get());
138 }
139
140 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000141}
142
143size_t
144SBValue::GetByteSize ()
145{
146 size_t result = 0;
147
Greg Clayton49ce6822010-10-31 03:01:06 +0000148 if (m_opaque_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000149 result = m_opaque_sp->GetByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000150
Greg Claytone005f2c2010-11-06 01:53:30 +0000151 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000152 if (log)
153 log->Printf ("SBValue(%p)::GetByteSize () => %zu", m_opaque_sp.get(), result);
154
Chris Lattner24943d22010-06-08 16:52:24 +0000155 return result;
156}
157
158bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000159SBValue::IsInScope ()
160{
Chris Lattner24943d22010-06-08 16:52:24 +0000161 bool result = false;
162
Greg Clayton49ce6822010-10-31 03:01:06 +0000163 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000164 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000165 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000166 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000167 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000168 result = m_opaque_sp->IsInScope ();
169 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000170 }
Chris Lattner24943d22010-06-08 16:52:24 +0000171
Greg Claytone005f2c2010-11-06 01:53:30 +0000172 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000173 if (log)
174 log->Printf ("SBValue(%p)::IsInScope () => %i", m_opaque_sp.get(), result);
175
Chris Lattner24943d22010-06-08 16:52:24 +0000176 return result;
177}
178
179const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000180SBValue::GetValue ()
181{
Greg Clayton49ce6822010-10-31 03:01:06 +0000182 const char *cstr = NULL;
Greg Claytonbdcda462010-12-20 20:49:23 +0000183 if (m_opaque_sp)
184 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000185 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000186 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000187 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000188 cstr = m_opaque_sp->GetValueAsCString ();
189 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000190 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000191 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000192 if (log)
193 {
194 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000195 log->Printf ("SBValue(%p)::GetValue => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000196 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000197 log->Printf ("SBValue(%p)::GetValue => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000198 }
199
200 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000201}
202
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000203ValueType
204SBValue::GetValueType ()
205{
Greg Clayton49ce6822010-10-31 03:01:06 +0000206 ValueType result = eValueTypeInvalid;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000207 if (m_opaque_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +0000208 result = m_opaque_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000209 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000210 if (log)
211 {
212 switch (result)
213 {
214 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", m_opaque_sp.get()); break;
215 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", m_opaque_sp.get()); break;
216 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", m_opaque_sp.get()); break;
217 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", m_opaque_sp.get()); break;
218 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", m_opaque_sp.get()); break;
219 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", m_opaque_sp.get()); break;
220 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", m_opaque_sp.get()); break;
221 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", m_opaque_sp.get()); break;
222 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", m_opaque_sp.get(), result); break;
223 }
224 }
225 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000226}
227
Jim Ingham4ae51962010-09-10 23:12:17 +0000228const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000229SBValue::GetObjectDescription ()
230{
Greg Clayton49ce6822010-10-31 03:01:06 +0000231 const char *cstr = NULL;
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000232 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000233 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000234 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000235 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000236 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000237 cstr = m_opaque_sp->GetObjectDescription ();
238 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000239 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000240 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000241 if (log)
242 {
243 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000244 log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000245 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000246 log->Printf ("SBValue(%p)::GetObjectDescription => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000247 }
248 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000249}
250
Enrico Granata979e20d2011-07-29 19:53:35 +0000251SBType
252SBValue::GetType()
253{
254 SBType result;
255 if (m_opaque_sp)
256 {
257 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
258 {
259 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000260 result = SBType(ClangASTType (m_opaque_sp->GetClangAST(), m_opaque_sp->GetClangType()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000261 }
262 }
263 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
264 if (log)
265 {
266 if (result.IsValid())
267 log->Printf ("SBValue(%p)::GetType => %p", m_opaque_sp.get(), &result);
268 else
269 log->Printf ("SBValue(%p)::GetType => NULL", m_opaque_sp.get());
270 }
271 return result;
272}
273
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000274bool
275SBValue::GetValueDidChange ()
276{
Greg Clayton49ce6822010-10-31 03:01:06 +0000277 bool result = false;
278 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000279 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000280 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000281 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000282 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000283 result = m_opaque_sp->GetValueDidChange ();
284 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000285 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000286 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000287 if (log)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000288 log->Printf ("SBValue(%p)::GetValueDidChange => %i", m_opaque_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000289
290 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000291}
292
293const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000294SBValue::GetSummary ()
295{
Greg Clayton49ce6822010-10-31 03:01:06 +0000296 const char *cstr = NULL;
297 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000298 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000299 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000300 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000301 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000302 cstr = m_opaque_sp->GetSummaryAsCString();
303 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000304 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000305 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000306 if (log)
307 {
308 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000309 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000310 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000311 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000312 }
313 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000314}
315
316const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000317SBValue::GetLocation ()
318{
Greg Clayton49ce6822010-10-31 03:01:06 +0000319 const char *cstr = NULL;
320 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000321 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000322 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000323 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000324 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000325 cstr = m_opaque_sp->GetLocationAsCString();
326 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000327 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000328 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000329 if (log)
330 {
331 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000332 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000333 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000334 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000335 }
336 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000337}
338
339bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000340SBValue::SetValueFromCString (const char *value_str)
341{
Chris Lattner24943d22010-06-08 16:52:24 +0000342 bool success = false;
Greg Clayton49ce6822010-10-31 03:01:06 +0000343 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000344 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000345 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000346 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000347 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000348 success = m_opaque_sp->SetValueFromCString (value_str);
349 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000350 }
Chris Lattner24943d22010-06-08 16:52:24 +0000351 return success;
352}
353
Enrico Granata979e20d2011-07-29 19:53:35 +0000354lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000355SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000356{
357 lldb::SBValue result;
358 if (m_opaque_sp)
359 {
360 if (type.IsValid())
361 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000362 result = SBValue(m_opaque_sp->GetSyntheticChildAtOffset(offset, type.m_opaque_sp->GetClangASTType(), true));
Enrico Granata979e20d2011-07-29 19:53:35 +0000363 result.m_opaque_sp->SetName(ConstString(name));
364 }
365 }
366 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
367 if (log)
368 {
369 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000370 log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000371 else
372 log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", m_opaque_sp.get());
373 }
374 return result;
375}
376
377lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000378SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000379{
380 return CreateChildAtOffset(m_opaque_sp->GetName().GetCString(), 0, type);
381}
382
383lldb::SBValue
384SBValue::CreateValueFromExpression (const char *name, const char* expression)
385{
386 lldb::SBValue result;
387 if (m_opaque_sp)
388 {
389 ValueObjectSP result_valobj_sp;
Greg Claytond68e0892011-09-09 23:04:00 +0000390 m_opaque_sp->GetUpdatePoint().GetTargetSP()->EvaluateExpression (expression,
Jim Ingham1586d972011-12-17 01:35:57 +0000391 m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame(),
Sean Callanana8428a42011-09-22 00:41:11 +0000392 eExecutionPolicyOnlyWhenNeeded,
Sean Callanandaa6efe2011-12-21 22:22:58 +0000393 false, // coerce to id
Sean Callanan47dc4572011-09-15 02:13:07 +0000394 true, // unwind on error
395 true, // keep in memory
396 eNoDynamicValues,
Greg Claytond68e0892011-09-09 23:04:00 +0000397 result_valobj_sp);
Johnny Chen9fd2e382011-12-20 01:52:44 +0000398 if (result_valobj_sp)
399 {
400 result_valobj_sp->SetName(ConstString(name));
401 result = SBValue(result_valobj_sp);
402 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000403 }
404 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
405 if (log)
406 {
407 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000408 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000409 else
410 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get());
411 }
412 return result;
413}
414
415lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000416SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000417{
418 lldb::SBValue result;
Johnny Chen943485c2011-12-15 01:55:36 +0000419 if (m_opaque_sp && type.IsValid() && type.GetPointerType().IsValid())
Enrico Granata979e20d2011-07-29 19:53:35 +0000420 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000421 SBType real_type(type.GetPointerType());
422
423 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
424
Jim Ingham1586d972011-12-17 01:35:57 +0000425 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (m_opaque_sp->GetExecutionContextScope(),
Greg Claytond68e0892011-09-09 23:04:00 +0000426 real_type.m_opaque_sp->GetASTContext(),
427 real_type.m_opaque_sp->GetOpaqueQualType(),
428 ConstString(name),
429 buffer,
430 lldb::endian::InlHostByteOrder(),
431 GetTarget().GetProcess().GetAddressByteSize()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000432
Enrico Granatac9310302011-08-04 17:07:02 +0000433 ValueObjectSP result_valobj_sp;
434
435 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
436 if (ptr_result_valobj_sp)
437 {
438 Error err;
439 result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
440 if (result_valobj_sp)
441 result_valobj_sp->SetName(ConstString(name));
442 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000443 result = SBValue(result_valobj_sp);
444 }
445 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
446 if (log)
447 {
448 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000449 log->Printf ("SBValue(%p)::GetChildFromAddress => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000450 else
451 log->Printf ("SBValue(%p)::GetChildFromAddress => NULL", m_opaque_sp.get());
452 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000453 return result;
454}
455
Enrico Granata91544802011-09-06 19:20:51 +0000456lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000457SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000458{
459 SBValue result;
460
461 AddressType addr_of_children_priv = eAddressTypeLoad;
462
463 if (m_opaque_sp)
464 {
465 ValueObjectSP valobj_sp;
466 valobj_sp = ValueObjectConstResult::Create (m_opaque_sp->GetExecutionContextScope(),
467 type.m_opaque_sp->GetASTContext() ,
468 type.m_opaque_sp->GetOpaqueQualType(),
469 ConstString(name),
470 *data.m_opaque_sp,
471 LLDB_INVALID_ADDRESS);
472 valobj_sp->SetAddressTypeOfChildren(addr_of_children_priv);
473 result = SBValue(valobj_sp);
474 }
475 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
476 if (log)
477 {
478 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000479 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000480 else
481 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get());
482 }
483 return result;
484}
485
Chris Lattner24943d22010-06-08 16:52:24 +0000486SBValue
487SBValue::GetChildAtIndex (uint32_t idx)
488{
Greg Clayton8f64c472011-07-15 19:31:49 +0000489 const bool can_create_synthetic = false;
490 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Johnny Chen446ccaa2011-06-29 21:19:39 +0000491 if (m_opaque_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000492 use_dynamic = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
Greg Clayton8f64c472011-07-15 19:31:49 +0000493 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000494}
495
496SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000497SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000498{
Chris Lattner24943d22010-06-08 16:52:24 +0000499 lldb::ValueObjectSP child_sp;
500
Greg Clayton49ce6822010-10-31 03:01:06 +0000501 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000502 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000503 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000504 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000505 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton8f64c472011-07-15 19:31:49 +0000506 const bool can_create = true;
507 child_sp = m_opaque_sp->GetChildAtIndex (idx, can_create);
508 if (can_create_synthetic && !child_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000509 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000510 if (m_opaque_sp->IsPointerType())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000511 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000512 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
513 }
514 else if (m_opaque_sp->IsArrayType())
515 {
516 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
517 }
518 }
519
520 if (child_sp)
521 {
522 if (use_dynamic != lldb::eNoDynamicValues)
523 {
524 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000525 if (dynamic_sp)
526 child_sp = dynamic_sp;
527 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000528 }
Jim Inghame41494a2011-04-16 00:01:13 +0000529 }
530 }
531
Chris Lattner24943d22010-06-08 16:52:24 +0000532 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000533 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000534 if (log)
535 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get());
536
Chris Lattner24943d22010-06-08 16:52:24 +0000537 return sb_value;
538}
539
540uint32_t
541SBValue::GetIndexOfChildWithName (const char *name)
542{
Greg Clayton49ce6822010-10-31 03:01:06 +0000543 uint32_t idx = UINT32_MAX;
544 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000545 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000546 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000547 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000548 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000549
Greg Claytonb9dcc512011-06-29 18:28:50 +0000550 idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
551 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000552 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000553 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000554 if (log)
555 {
556 if (idx == UINT32_MAX)
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000557 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000558 else
559 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx);
560 }
561 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000562}
563
564SBValue
565SBValue::GetChildMemberWithName (const char *name)
566{
Johnny Chen446ccaa2011-06-29 21:19:39 +0000567 if (m_opaque_sp)
568 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000569 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
Johnny Chen446ccaa2011-06-29 21:19:39 +0000570 return GetChildMemberWithName (name, use_dynamic_value);
571 }
572 else
573 return GetChildMemberWithName (name, eNoDynamicValues);
Jim Inghame41494a2011-04-16 00:01:13 +0000574}
575
576SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000577SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000578{
Chris Lattner24943d22010-06-08 16:52:24 +0000579 lldb::ValueObjectSP child_sp;
580 const ConstString str_name (name);
581
Greg Clayton905acaf2011-05-20 22:07:17 +0000582
Greg Clayton49ce6822010-10-31 03:01:06 +0000583 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000584 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000585 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Jim Inghame41494a2011-04-16 00:01:13 +0000586 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000587 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000588 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
589 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000590 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000591 if (child_sp)
592 {
593 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
594 if (dynamic_sp)
595 child_sp = dynamic_sp;
596 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000597 }
Jim Inghame41494a2011-04-16 00:01:13 +0000598 }
599 }
600
Chris Lattner24943d22010-06-08 16:52:24 +0000601 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000602
Greg Claytone005f2c2010-11-06 01:53:30 +0000603 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000604 if (log)
605 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get());
606
Chris Lattner24943d22010-06-08 16:52:24 +0000607 return sb_value;
608}
609
Enrico Granataf7a9b142011-07-15 02:26:42 +0000610lldb::SBValue
Jim Ingham1b425752011-12-08 19:44:08 +0000611SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
612{
613 if (m_opaque_sp)
614 {
615 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
616 {
617 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
618 return SBValue (m_opaque_sp->GetDynamicValue(use_dynamic));
619 }
620 }
621
622 return SBValue();
623}
624
625lldb::SBValue
626SBValue::GetStaticValue ()
627{
628 if (m_opaque_sp)
629 {
630 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
631 {
632 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
633 return SBValue(m_opaque_sp->GetStaticValue());
634 }
635 }
636
637 return SBValue();
638}
639
640bool
641SBValue::IsDynamic()
642{
643 if (m_opaque_sp)
644 {
645 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
646 {
647 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
648 return m_opaque_sp->IsDynamic();
649 }
650 }
651 return false;
652}
653
654lldb::SBValue
Enrico Granataf7a9b142011-07-15 02:26:42 +0000655SBValue::GetValueForExpressionPath(const char* expr_path)
656{
657 lldb::ValueObjectSP child_sp;
658 if (m_opaque_sp)
659 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000660 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Enrico Granataf7a9b142011-07-15 02:26:42 +0000661 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000662 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Enrico Granataf7a9b142011-07-15 02:26:42 +0000663 // using default values for all the fancy options, just do it if you can
664 child_sp = m_opaque_sp->GetValueForExpressionPath(expr_path);
665 }
666 }
667
668 SBValue sb_value (child_sp);
669
670 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
671 if (log)
672 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", m_opaque_sp.get(), expr_path, sb_value.get());
673
674 return sb_value;
675}
Chris Lattner24943d22010-06-08 16:52:24 +0000676
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000677int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +0000678SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
679{
Jim Ingham574c3d62011-08-12 23:34:31 +0000680 error.Clear();
Enrico Granatac92eb402011-08-04 01:41:02 +0000681 if (m_opaque_sp)
682 {
683 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
684 {
685 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
686 Scalar scalar;
687 if (m_opaque_sp->ResolveValue (scalar))
688 return scalar.GetRawBits64(fail_value);
689 else
690 error.SetErrorString("could not get value");
691 }
692 else
693 error.SetErrorString("could not get target");
694 }
695 error.SetErrorString("invalid SBValue");
696 return fail_value;
697}
698
699uint64_t
700SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
701{
Jim Ingham574c3d62011-08-12 23:34:31 +0000702 error.Clear();
Enrico Granatac92eb402011-08-04 01:41:02 +0000703 if (m_opaque_sp)
704 {
705 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
706 {
707 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
708 Scalar scalar;
709 if (m_opaque_sp->ResolveValue (scalar))
710 return scalar.GetRawBits64(fail_value);
711 else
712 error.SetErrorString("could not get value");
713 }
714 else
715 error.SetErrorString("could not get target");
716 }
717 error.SetErrorString("invalid SBValue");
718 return fail_value;
719}
720
721int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000722SBValue::GetValueAsSigned(int64_t fail_value)
723{
724 if (m_opaque_sp)
725 {
726 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
727 {
728 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
729 Scalar scalar;
730 if (m_opaque_sp->ResolveValue (scalar))
731 return scalar.GetRawBits64(fail_value);
732 }
733 }
734 return fail_value;
735}
736
737uint64_t
738SBValue::GetValueAsUnsigned(uint64_t fail_value)
739{
740 if (m_opaque_sp)
741 {
742 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
743 {
744 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
745 Scalar scalar;
746 if (m_opaque_sp->ResolveValue (scalar))
747 return scalar.GetRawBits64(fail_value);
748 }
749 }
750 return fail_value;
751}
752
Chris Lattner24943d22010-06-08 16:52:24 +0000753uint32_t
754SBValue::GetNumChildren ()
755{
756 uint32_t num_children = 0;
757
Greg Clayton49ce6822010-10-31 03:01:06 +0000758 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000759 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000760 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000761 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000762 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000763
Greg Claytonb9dcc512011-06-29 18:28:50 +0000764 num_children = m_opaque_sp->GetNumChildren();
765 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000766 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000767
Greg Claytone005f2c2010-11-06 01:53:30 +0000768 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000769 if (log)
770 log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000771
772 return num_children;
773}
774
Chris Lattner24943d22010-06-08 16:52:24 +0000775
776SBValue
777SBValue::Dereference ()
778{
Greg Clayton49ce6822010-10-31 03:01:06 +0000779 SBValue sb_value;
780 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000781 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000782 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000783 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000784 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000785
Greg Claytonb9dcc512011-06-29 18:28:50 +0000786 Error error;
787 sb_value = m_opaque_sp->Dereference (error);
788 }
Chris Lattner24943d22010-06-08 16:52:24 +0000789 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000790 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000791 if (log)
792 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
793
794 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000795}
796
797bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000798SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000799{
800 bool is_ptr_type = false;
801
Greg Clayton49ce6822010-10-31 03:01:06 +0000802 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000803 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000804 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000805 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000806 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000807
Greg Claytonb9dcc512011-06-29 18:28:50 +0000808 is_ptr_type = m_opaque_sp->IsPointerType();
809 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000810 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000811
Greg Claytone005f2c2010-11-06 01:53:30 +0000812 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000813 if (log)
814 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type);
815
Chris Lattner24943d22010-06-08 16:52:24 +0000816
817 return is_ptr_type;
818}
819
Chris Lattner24943d22010-06-08 16:52:24 +0000820void *
821SBValue::GetOpaqueType()
822{
Greg Clayton63094e02010-06-23 01:19:29 +0000823 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000824 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000825 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000826 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000827 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000828
Greg Claytonb9dcc512011-06-29 18:28:50 +0000829 return m_opaque_sp->GetClangType();
830 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000831 }
Chris Lattner24943d22010-06-08 16:52:24 +0000832 return NULL;
833}
834
Enrico Granata979e20d2011-07-29 19:53:35 +0000835lldb::SBTarget
836SBValue::GetTarget()
837{
Greg Clayton334d33a2012-01-30 07:41:31 +0000838 SBTarget sb_target;
839 TargetSP target_sp;
Enrico Granata979e20d2011-07-29 19:53:35 +0000840 if (m_opaque_sp)
841 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000842 target_sp = m_opaque_sp->GetUpdatePoint().GetTargetSP();
843 sb_target.SetSP (target_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000844 }
845 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
846 if (log)
847 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000848 if (target_sp.get() == NULL)
Enrico Granata979e20d2011-07-29 19:53:35 +0000849 log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get());
850 else
Greg Clayton334d33a2012-01-30 07:41:31 +0000851 log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), target_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000852 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000853 return sb_target;
Enrico Granata979e20d2011-07-29 19:53:35 +0000854}
855
856lldb::SBProcess
857SBValue::GetProcess()
858{
Greg Clayton334d33a2012-01-30 07:41:31 +0000859 SBProcess sb_process;
860 ProcessSP process_sp;
Enrico Granata979e20d2011-07-29 19:53:35 +0000861 if (m_opaque_sp)
862 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000863 process_sp = m_opaque_sp->GetUpdatePoint().GetProcessSP();
864 if (process_sp)
865 sb_process.SetSP (process_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000866 }
867 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
868 if (log)
869 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000870 if (process_sp.get() == NULL)
Enrico Granata979e20d2011-07-29 19:53:35 +0000871 log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get());
872 else
Greg Clayton334d33a2012-01-30 07:41:31 +0000873 log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), process_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000874 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000875 return sb_process;
Enrico Granata979e20d2011-07-29 19:53:35 +0000876}
877
878lldb::SBThread
879SBValue::GetThread()
880{
Greg Clayton90c52142012-01-30 02:53:15 +0000881 SBThread sb_thread;
882 ThreadSP thread_sp;
Enrico Granata979e20d2011-07-29 19:53:35 +0000883 if (m_opaque_sp)
884 {
Jim Ingham1586d972011-12-17 01:35:57 +0000885 if (m_opaque_sp->GetExecutionContextScope())
Enrico Granata979e20d2011-07-29 19:53:35 +0000886 {
Greg Clayton90c52142012-01-30 02:53:15 +0000887 thread_sp = m_opaque_sp->GetExecutionContextScope()->CalculateThread()->shared_from_this();
888 sb_thread.SetThread(thread_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000889 }
890 }
891 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
892 if (log)
893 {
Greg Clayton90c52142012-01-30 02:53:15 +0000894 if (thread_sp.get() == NULL)
Enrico Granata979e20d2011-07-29 19:53:35 +0000895 log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get());
896 else
Greg Clayton90c52142012-01-30 02:53:15 +0000897 log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), thread_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000898 }
Greg Clayton90c52142012-01-30 02:53:15 +0000899 return sb_thread;
Enrico Granata979e20d2011-07-29 19:53:35 +0000900}
901
902lldb::SBFrame
903SBValue::GetFrame()
904{
Greg Clayton334d33a2012-01-30 07:41:31 +0000905 SBFrame sb_frame;
906 StackFrameSP frame_sp;
Enrico Granata979e20d2011-07-29 19:53:35 +0000907 if (m_opaque_sp)
908 {
Jim Ingham1586d972011-12-17 01:35:57 +0000909 if (m_opaque_sp->GetExecutionContextScope())
Enrico Granata979e20d2011-07-29 19:53:35 +0000910 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000911 frame_sp = m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame()->shared_from_this();
912 sb_frame.SetFrameSP (frame_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000913 }
914 }
915 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
916 if (log)
917 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000918 if (frame_sp.get() == NULL)
Enrico Granata979e20d2011-07-29 19:53:35 +0000919 log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get());
920 else
Greg Clayton334d33a2012-01-30 07:41:31 +0000921 log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), frame_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000922 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000923 return sb_frame;
Enrico Granata979e20d2011-07-29 19:53:35 +0000924}
925
926
Chris Lattner24943d22010-06-08 16:52:24 +0000927// Mimic shared pointer...
928lldb_private::ValueObject *
929SBValue::get() const
930{
Greg Clayton63094e02010-06-23 01:19:29 +0000931 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000932}
933
934lldb_private::ValueObject *
935SBValue::operator->() const
936{
Greg Clayton63094e02010-06-23 01:19:29 +0000937 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000938}
939
940lldb::ValueObjectSP &
941SBValue::operator*()
942{
Greg Clayton63094e02010-06-23 01:19:29 +0000943 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000944}
945
946const lldb::ValueObjectSP &
947SBValue::operator*() const
948{
Greg Clayton63094e02010-06-23 01:19:29 +0000949 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000950}
Caroline Tice98f930f2010-09-20 05:20:02 +0000951
952bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000953SBValue::GetExpressionPath (SBStream &description)
954{
955 if (m_opaque_sp)
956 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000957 m_opaque_sp->GetExpressionPath (description.ref(), false);
958 return true;
959 }
960 return false;
961}
962
963bool
964SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
965{
966 if (m_opaque_sp)
967 {
968 m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +0000969 return true;
970 }
971 return false;
972}
973
974bool
Caroline Tice98f930f2010-09-20 05:20:02 +0000975SBValue::GetDescription (SBStream &description)
976{
Greg Clayton96154be2011-11-13 06:57:31 +0000977 Stream &strm = description.ref();
978
Caroline Tice98f930f2010-09-20 05:20:02 +0000979 if (m_opaque_sp)
980 {
Greg Clayton96154be2011-11-13 06:57:31 +0000981 ValueObject::DumpValueObject (strm, m_opaque_sp.get());
Caroline Tice98f930f2010-09-20 05:20:02 +0000982 }
983 else
Greg Clayton96154be2011-11-13 06:57:31 +0000984 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +0000985
986 return true;
987}
Greg Claytone179a582011-01-05 18:43:15 +0000988
989lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +0000990SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +0000991{
992 if (m_opaque_sp)
993 return m_opaque_sp->GetFormat();
994 return eFormatDefault;
995}
996
997void
998SBValue::SetFormat (lldb::Format format)
999{
1000 if (m_opaque_sp)
1001 m_opaque_sp->SetFormat(format);
1002}
1003
Enrico Granata979e20d2011-07-29 19:53:35 +00001004lldb::SBValue
1005SBValue::AddressOf()
1006{
1007 SBValue sb_value;
1008 if (m_opaque_sp)
1009 {
Enrico Granata91544802011-09-06 19:20:51 +00001010 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1011 if (target)
Enrico Granata979e20d2011-07-29 19:53:35 +00001012 {
Enrico Granata91544802011-09-06 19:20:51 +00001013 Mutex::Locker api_locker (target->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001014 Error error;
1015 sb_value = m_opaque_sp->AddressOf (error);
1016 }
1017 }
1018 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1019 if (log)
1020 log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
1021
1022 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001023}
Enrico Granata91544802011-09-06 19:20:51 +00001024
1025lldb::addr_t
1026SBValue::GetLoadAddress()
1027{
1028 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1029 if (m_opaque_sp)
1030 {
1031 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1032 if (target)
1033 {
1034 Mutex::Locker api_locker (target->GetAPIMutex());
1035 const bool scalar_is_load_address = true;
1036 AddressType addr_type;
1037 value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1038 if (addr_type == eAddressTypeFile)
1039 {
1040 Module* module = m_opaque_sp->GetModule();
1041 if (!module)
1042 value = LLDB_INVALID_ADDRESS;
1043 else
1044 {
1045 Address addr;
1046 module->ResolveFileAddress(value, addr);
1047 value = addr.GetLoadAddress(m_opaque_sp->GetUpdatePoint().GetTargetSP().get());
1048 }
1049 }
1050 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1051 value = LLDB_INVALID_ADDRESS;
1052 }
1053 }
1054 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1055 if (log)
1056 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", m_opaque_sp.get(), value);
1057
1058 return value;
1059}
1060
1061lldb::SBAddress
1062SBValue::GetAddress()
1063{
1064 Address addr;
1065 if (m_opaque_sp)
1066 {
1067 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1068 if (target)
1069 {
1070 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1071 Mutex::Locker api_locker (target->GetAPIMutex());
1072 const bool scalar_is_load_address = true;
1073 AddressType addr_type;
1074 value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1075 if (addr_type == eAddressTypeFile)
1076 {
1077 Module* module = m_opaque_sp->GetModule();
1078 if (module)
1079 module->ResolveFileAddress(value, addr);
1080 }
1081 else if (addr_type == eAddressTypeLoad)
1082 {
1083 // no need to check the return value on this.. if it can actually do the resolve
1084 // addr will be in the form (section,offset), otherwise it will simply be returned
1085 // as (NULL, value)
1086 addr.SetLoadAddress(value, target);
1087 }
1088 }
1089 }
1090 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1091 if (log)
1092 log->Printf ("SBValue(%p)::GetAddress () => (%s,%llu)", m_opaque_sp.get(), (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"), addr.GetOffset());
1093 return SBAddress(new Address(addr));
1094}
1095
1096lldb::SBData
1097SBValue::GetPointeeData (uint32_t item_idx,
1098 uint32_t item_count)
1099{
1100 lldb::SBData sb_data;
1101 if (m_opaque_sp)
1102 {
1103 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1104 if (target)
1105 {
1106 DataExtractorSP data_sp(new DataExtractor());
1107 Mutex::Locker api_locker (target->GetAPIMutex());
1108 m_opaque_sp->GetPointeeData(*data_sp, item_idx, item_count);
1109 if (data_sp->GetByteSize() > 0)
1110 *sb_data = data_sp;
1111 }
1112 }
1113 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1114 if (log)
1115 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
1116 m_opaque_sp.get(),
1117 item_idx,
1118 item_count,
1119 sb_data.get());
1120
1121 return sb_data;
1122}
1123
1124lldb::SBData
1125SBValue::GetData ()
1126{
1127 lldb::SBData sb_data;
1128 if (m_opaque_sp)
1129 {
1130 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1131 if (target)
1132 {
1133 DataExtractorSP data_sp(new DataExtractor());
1134 Mutex::Locker api_locker (target->GetAPIMutex());
1135 m_opaque_sp->GetData(*data_sp);
1136 if (data_sp->GetByteSize() > 0)
1137 *sb_data = data_sp;
1138 }
1139 }
1140 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1141 if (log)
1142 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
1143 m_opaque_sp.get(),
1144 sb_data.get());
1145
1146 return sb_data;
1147}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001148
1149lldb::SBWatchpoint
1150SBValue::Watch (bool resolve_location, bool read, bool write)
1151{
1152 lldb::SBWatchpoint sb_watchpoint;
Johnny Chenecd4feb2011-10-14 00:42:25 +00001153 if (!m_opaque_sp)
1154 return sb_watchpoint;
1155
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001156 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1157 if (target)
1158 {
1159 Mutex::Locker api_locker (target->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001160 sb_watchpoint = WatchValue(read, write, false);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001161 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001162 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1163 if (log)
1164 log->Printf ("SBValue(%p)::Watch (resolve_location=%i, read=%i, write=%i) => wp(%p)",
1165 m_opaque_sp.get(), resolve_location, read, write, sb_watchpoint.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001166 return sb_watchpoint;
1167}
1168
1169lldb::SBWatchpoint
1170SBValue::WatchPointee (bool resolve_location, bool read, bool write)
1171{
1172 lldb::SBWatchpoint sb_watchpoint;
Johnny Chenecd4feb2011-10-14 00:42:25 +00001173 if (!m_opaque_sp)
1174 return sb_watchpoint;
1175
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001176 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1177 if (target)
1178 {
1179 Mutex::Locker api_locker (target->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001180 sb_watchpoint = WatchValue(read, write, true);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001181 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001182 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1183 if (log)
1184 log->Printf ("SBValue(%p)::WatchPointee (resolve_location=%i, read=%i, write=%i) => wp(%p)",
1185 m_opaque_sp.get(), resolve_location, read, write, sb_watchpoint.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001186 return sb_watchpoint;
1187}
1188
Johnny Chenecd4feb2011-10-14 00:42:25 +00001189// Helper function for SBValue::Watch() and SBValue::WatchPointee().
1190SBWatchpoint
1191SBValue::WatchValue(bool read, bool write, bool watch_pointee)
1192{
1193 SBWatchpoint sb_wp_empty;
1194
1195 // If the SBValue is not valid, there's no point in even trying to watch it.
Greg Clayton334d33a2012-01-30 07:41:31 +00001196 if (!IsValid())
Johnny Chenecd4feb2011-10-14 00:42:25 +00001197 return sb_wp_empty;
1198
1199 // Read and Write cannot both be false.
1200 if (!read && !write)
1201 return sb_wp_empty;
Greg Clayton334d33a2012-01-30 07:41:31 +00001202
Johnny Chenecd4feb2011-10-14 00:42:25 +00001203 // If we are watching the pointee, check that the SBValue is a pointer type.
1204 if (watch_pointee && !GetType().IsPointerType())
1205 return sb_wp_empty;
1206
Greg Clayton334d33a2012-01-30 07:41:31 +00001207 TargetSP target_sp (GetTarget().GetSP());
1208 if (!target_sp)
1209 return sb_wp_empty;
1210
1211 StackFrameSP frame_sp (GetFrame().GetFrameSP());
1212 if (!frame_sp)
1213 return sb_wp_empty;
1214
Johnny Chenecd4feb2011-10-14 00:42:25 +00001215 addr_t addr;
1216 size_t size;
1217 if (watch_pointee) {
1218 addr = GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
1219 size = GetType().GetPointeeType().GetByteSize();
1220 } else {
1221 addr = GetLoadAddress();
1222 size = GetByteSize();
1223 }
1224
1225 // Sanity check the address and the size before calling Target::CreateWatchpoint().
1226 if (addr == LLDB_INVALID_ADDRESS || size == 0)
1227 return sb_wp_empty;
1228
1229 uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) |
1230 (write ? LLDB_WATCH_TYPE_WRITE : 0);
Greg Clayton334d33a2012-01-30 07:41:31 +00001231 WatchpointSP wp_sp = target_sp->CreateWatchpoint(addr, size, watch_type);
Johnny Chenecd4feb2011-10-14 00:42:25 +00001232
1233 if (wp_sp) {
1234 // StackFrame::GetInScopeVariableList(true) to get file globals as well.
Greg Clayton334d33a2012-01-30 07:41:31 +00001235 VariableListSP var_list_sp(frame_sp->GetInScopeVariableList(true));
Johnny Chenecd4feb2011-10-14 00:42:25 +00001236 VariableSP var_sp = var_list_sp->FindVariable(ConstString(GetName()));
1237 if (var_sp && var_sp->GetDeclaration().GetFile()) {
1238 StreamString ss;
1239 // True to show fullpath for declaration file.
1240 var_sp->GetDeclaration().DumpStopContext(&ss, true);
1241 wp_sp->SetDeclInfo(ss.GetString());
1242 }
1243 }
1244 return wp_sp;
1245}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001246