blob: c6a26d95c1d1259cf8fd341a6e712e487282cb01 [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
13#include "lldb/Core/DataExtractor.h"
Caroline Tice7826c882010-10-26 03:11:13 +000014#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015#include "lldb/Core/Module.h"
16#include "lldb/Core/Stream.h"
17#include "lldb/Core/StreamFile.h"
18#include "lldb/Core/Value.h"
19#include "lldb/Core/ValueObject.h"
20#include "lldb/Symbol/Block.h"
21#include "lldb/Symbol/ObjectFile.h"
22#include "lldb/Symbol/Variable.h"
23#include "lldb/Target/ExecutionContext.h"
24#include "lldb/Target/Process.h"
25#include "lldb/Target/StackFrame.h"
Greg Claytonbdcda462010-12-20 20:49:23 +000026#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000027#include "lldb/Target/Thread.h"
28
Eli Friedman7a62c8b2010-06-09 07:44:37 +000029#include "lldb/API/SBProcess.h"
30#include "lldb/API/SBTarget.h"
31#include "lldb/API/SBThread.h"
32#include "lldb/API/SBFrame.h"
33#include "lldb/API/SBDebugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000034
35using namespace lldb;
36using namespace lldb_private;
37
38SBValue::SBValue () :
Greg Clayton63094e02010-06-23 01:19:29 +000039 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000040{
41}
42
43SBValue::SBValue (const lldb::ValueObjectSP &value_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000044 m_opaque_sp (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000045{
46}
47
Greg Clayton538eb822010-11-05 23:17:00 +000048SBValue::SBValue(const SBValue &rhs) :
49 m_opaque_sp (rhs.m_opaque_sp)
50{
51}
52
53const SBValue &
54SBValue::operator = (const SBValue &rhs)
55{
56 if (this != &rhs)
57 m_opaque_sp = rhs.m_opaque_sp;
58 return *this;
59}
60
Chris Lattner24943d22010-06-08 16:52:24 +000061SBValue::~SBValue()
62{
63}
64
65bool
66SBValue::IsValid () const
67{
Greg Clayton49ce6822010-10-31 03:01:06 +000068 // If this function ever changes to anything that does more than just
69 // check if the opaque shared pointer is non NULL, then we need to update
70 // all "if (m_opaque_sp)" code in this file.
71 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000072}
73
Greg Claytonc5f728c2010-10-06 22:10:17 +000074SBError
75SBValue::GetError()
76{
77 SBError sb_error;
78
79 if (m_opaque_sp.get())
80 sb_error.SetError(m_opaque_sp->GetError());
81
82 return sb_error;
83}
84
Chris Lattner24943d22010-06-08 16:52:24 +000085const char *
86SBValue::GetName()
87{
Greg Clayton49ce6822010-10-31 03:01:06 +000088
89 const char *name = NULL;
90 if (m_opaque_sp)
91 name = m_opaque_sp->GetName().GetCString();
92
Greg Claytone005f2c2010-11-06 01:53:30 +000093 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +000094 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +000095 {
96 if (name)
97 log->Printf ("SBValue(%p)::GetName () => \"%s\"", m_opaque_sp.get(), name);
98 else
99 log->Printf ("SBValue(%p)::GetName () => NULL", m_opaque_sp.get(), name);
100 }
Caroline Tice7826c882010-10-26 03:11:13 +0000101
Greg Clayton49ce6822010-10-31 03:01:06 +0000102 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000103}
104
105const char *
106SBValue::GetTypeName ()
107{
Greg Clayton49ce6822010-10-31 03:01:06 +0000108 const char *name = NULL;
109 if (m_opaque_sp)
110 name = m_opaque_sp->GetTypeName().GetCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000111 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000112 if (log)
113 {
114 if (name)
115 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", m_opaque_sp.get(), name);
116 else
117 log->Printf ("SBValue(%p)::GetTypeName () => NULL", m_opaque_sp.get());
118 }
119
120 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000121}
122
123size_t
124SBValue::GetByteSize ()
125{
126 size_t result = 0;
127
Greg Clayton49ce6822010-10-31 03:01:06 +0000128 if (m_opaque_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000129 result = m_opaque_sp->GetByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000130
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 log->Printf ("SBValue(%p)::GetByteSize () => %zu", m_opaque_sp.get(), result);
134
Chris Lattner24943d22010-06-08 16:52:24 +0000135 return result;
136}
137
138bool
Greg Claytonbdcda462010-12-20 20:49:23 +0000139SBValue::IsInScope (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000140{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000141 return IsInScope();
142}
143
144bool
145SBValue::IsInScope ()
146{
Chris Lattner24943d22010-06-08 16:52:24 +0000147 bool result = false;
148
Greg Clayton49ce6822010-10-31 03:01:06 +0000149 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000150 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000151 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000152 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000153 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000154 result = m_opaque_sp->IsInScope ();
155 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000156 }
Chris Lattner24943d22010-06-08 16:52:24 +0000157
Greg Claytone005f2c2010-11-06 01:53:30 +0000158 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000159 if (log)
160 log->Printf ("SBValue(%p)::IsInScope () => %i", m_opaque_sp.get(), result);
161
Chris Lattner24943d22010-06-08 16:52:24 +0000162 return result;
163}
164
165const char *
Greg Claytonbdcda462010-12-20 20:49:23 +0000166SBValue::GetValue (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000167{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000168 return GetValue();
169}
170
171const char *
172SBValue::GetValue ()
173{
Greg Clayton49ce6822010-10-31 03:01:06 +0000174 const char *cstr = NULL;
Greg Claytonbdcda462010-12-20 20:49:23 +0000175 if (m_opaque_sp)
176 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000177 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000178 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000179 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000180 cstr = m_opaque_sp->GetValueAsCString ();
181 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000182 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000183 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000184 if (log)
185 {
186 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000187 log->Printf ("SBValue(%p)::GetValue => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000188 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000189 log->Printf ("SBValue(%p)::GetValue => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000190 }
191
192 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000193}
194
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000195ValueType
196SBValue::GetValueType ()
197{
Greg Clayton49ce6822010-10-31 03:01:06 +0000198 ValueType result = eValueTypeInvalid;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000199 if (m_opaque_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +0000200 result = m_opaque_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000201 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000202 if (log)
203 {
204 switch (result)
205 {
206 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", m_opaque_sp.get()); break;
207 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", m_opaque_sp.get()); break;
208 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", m_opaque_sp.get()); break;
209 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", m_opaque_sp.get()); break;
210 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", m_opaque_sp.get()); break;
211 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", m_opaque_sp.get()); break;
212 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", m_opaque_sp.get()); break;
213 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", m_opaque_sp.get()); break;
214 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", m_opaque_sp.get(), result); break;
215 }
216 }
217 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000218}
219
Jim Ingham4ae51962010-09-10 23:12:17 +0000220const char *
Greg Claytonbdcda462010-12-20 20:49:23 +0000221SBValue::GetObjectDescription (const SBFrame &sb_frame)
Jim Ingham4ae51962010-09-10 23:12:17 +0000222{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000223 return GetObjectDescription ();
224}
225
226const char *
227SBValue::GetObjectDescription ()
228{
Greg Clayton49ce6822010-10-31 03:01:06 +0000229 const char *cstr = NULL;
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000230 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000231 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000232 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000233 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000234 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000235 cstr = m_opaque_sp->GetObjectDescription ();
236 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000237 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000238 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000239 if (log)
240 {
241 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000242 log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000243 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000244 log->Printf ("SBValue(%p)::GetObjectDescription => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000245 }
246 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000247}
248
Chris Lattner24943d22010-06-08 16:52:24 +0000249bool
Greg Claytonbdcda462010-12-20 20:49:23 +0000250SBValue::GetValueDidChange (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000251{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000252 return GetValueDidChange ();
253}
254
255bool
256SBValue::GetValueDidChange ()
257{
Greg Clayton49ce6822010-10-31 03:01:06 +0000258 bool result = false;
259 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000260 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000261 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000262 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000263 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000264 result = m_opaque_sp->GetValueDidChange ();
265 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000266 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000267 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000268 if (log)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000269 log->Printf ("SBValue(%p)::GetValueDidChange => %i", m_opaque_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000270
271 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000272}
273
274const char *
Greg Claytonbdcda462010-12-20 20:49:23 +0000275SBValue::GetSummary (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000276{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000277 return GetSummary ();
278}
279
280const char *
281SBValue::GetSummary ()
282{
Greg Clayton49ce6822010-10-31 03:01:06 +0000283 const char *cstr = NULL;
284 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000285 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000286 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000287 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000288 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000289 cstr = m_opaque_sp->GetSummaryAsCString();
290 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000291 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000292 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000293 if (log)
294 {
295 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000296 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000297 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000298 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000299 }
300 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000301}
302
303const char *
Greg Claytonbdcda462010-12-20 20:49:23 +0000304SBValue::GetLocation (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000305{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000306 return GetLocation ();
307}
308
309const char *
310SBValue::GetLocation ()
311{
Greg Clayton49ce6822010-10-31 03:01:06 +0000312 const char *cstr = NULL;
313 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000314 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000315 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000316 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000317 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000318 cstr = m_opaque_sp->GetLocationAsCString();
319 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000320 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000321 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000322 if (log)
323 {
324 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000325 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000326 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000327 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000328 }
329 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000330}
331
332bool
Greg Claytonbdcda462010-12-20 20:49:23 +0000333SBValue::SetValueFromCString (const SBFrame &sb_frame, const char *value_str)
Chris Lattner24943d22010-06-08 16:52:24 +0000334{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000335 return SetValueFromCString (value_str);
336}
337
338bool
339SBValue::SetValueFromCString (const char *value_str)
340{
Chris Lattner24943d22010-06-08 16:52:24 +0000341 bool success = false;
Greg Clayton49ce6822010-10-31 03:01:06 +0000342 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000343 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000344 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000345 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000346 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000347 success = m_opaque_sp->SetValueFromCString (value_str);
348 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000349 }
Chris Lattner24943d22010-06-08 16:52:24 +0000350 return success;
351}
352
353SBValue
354SBValue::GetChildAtIndex (uint32_t idx)
355{
Johnny Chen446ccaa2011-06-29 21:19:39 +0000356 if (m_opaque_sp)
357 {
358 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue();
359 return GetChildAtIndex (idx, use_dynamic_value);
360 }
361 else
362 return GetChildAtIndex (idx, eNoDynamicValues);
Jim Inghame41494a2011-04-16 00:01:13 +0000363}
364
365SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000366SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000367{
Chris Lattner24943d22010-06-08 16:52:24 +0000368 lldb::ValueObjectSP child_sp;
369
Greg Clayton49ce6822010-10-31 03:01:06 +0000370 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000371 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000372 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000373 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000374 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
375
Greg Claytonb9dcc512011-06-29 18:28:50 +0000376 child_sp = m_opaque_sp->GetChildAtIndex (idx, true);
377 if (use_dynamic != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000378 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000379 if (child_sp)
380 {
381 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic);
382 if (dynamic_sp)
383 child_sp = dynamic_sp;
384 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000385 }
Jim Inghame41494a2011-04-16 00:01:13 +0000386 }
387 }
388
Chris Lattner24943d22010-06-08 16:52:24 +0000389 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000390 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000391 if (log)
392 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get());
393
Chris Lattner24943d22010-06-08 16:52:24 +0000394 return sb_value;
395}
396
397uint32_t
398SBValue::GetIndexOfChildWithName (const char *name)
399{
Greg Clayton49ce6822010-10-31 03:01:06 +0000400 uint32_t idx = UINT32_MAX;
401 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000402 {
403 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000404 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000405 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
406
Greg Claytonb9dcc512011-06-29 18:28:50 +0000407 idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
408 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000409 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000410 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000411 if (log)
412 {
413 if (idx == UINT32_MAX)
414 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name, idx);
415 else
416 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx);
417 }
418 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000419}
420
421SBValue
422SBValue::GetChildMemberWithName (const char *name)
423{
Johnny Chen446ccaa2011-06-29 21:19:39 +0000424 if (m_opaque_sp)
425 {
426 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue();
427 return GetChildMemberWithName (name, use_dynamic_value);
428 }
429 else
430 return GetChildMemberWithName (name, eNoDynamicValues);
Jim Inghame41494a2011-04-16 00:01:13 +0000431}
432
433SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000434SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000435{
Chris Lattner24943d22010-06-08 16:52:24 +0000436 lldb::ValueObjectSP child_sp;
437 const ConstString str_name (name);
438
Greg Clayton905acaf2011-05-20 22:07:17 +0000439
Greg Clayton49ce6822010-10-31 03:01:06 +0000440 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000441 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000442 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Jim Inghame41494a2011-04-16 00:01:13 +0000443 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000444 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
445 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
446 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000447 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000448 if (child_sp)
449 {
450 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
451 if (dynamic_sp)
452 child_sp = dynamic_sp;
453 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000454 }
Jim Inghame41494a2011-04-16 00:01:13 +0000455 }
456 }
457
Chris Lattner24943d22010-06-08 16:52:24 +0000458 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000459
Greg Claytone005f2c2010-11-06 01:53:30 +0000460 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000461 if (log)
462 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get());
463
Chris Lattner24943d22010-06-08 16:52:24 +0000464 return sb_value;
465}
466
467
468uint32_t
469SBValue::GetNumChildren ()
470{
471 uint32_t num_children = 0;
472
Greg Clayton49ce6822010-10-31 03:01:06 +0000473 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000474 {
475 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000476 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000477 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
478
Greg Claytonb9dcc512011-06-29 18:28:50 +0000479 num_children = m_opaque_sp->GetNumChildren();
480 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000481 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000482
Greg Claytone005f2c2010-11-06 01:53:30 +0000483 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000484 if (log)
485 log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000486
487 return num_children;
488}
489
Chris Lattner24943d22010-06-08 16:52:24 +0000490
491SBValue
492SBValue::Dereference ()
493{
Greg Clayton49ce6822010-10-31 03:01:06 +0000494 SBValue sb_value;
495 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000496 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000497 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000498 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000499 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
500
Greg Claytonb9dcc512011-06-29 18:28:50 +0000501 Error error;
502 sb_value = m_opaque_sp->Dereference (error);
503 }
Chris Lattner24943d22010-06-08 16:52:24 +0000504 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000505 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000506 if (log)
507 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
508
509 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000510}
511
512bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000513SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000514{
515 bool is_ptr_type = false;
516
Greg Clayton49ce6822010-10-31 03:01:06 +0000517 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000518 {
519 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000520 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000521 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
522
Greg Claytonb9dcc512011-06-29 18:28:50 +0000523 is_ptr_type = m_opaque_sp->IsPointerType();
524 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000525 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000526
Greg Claytone005f2c2010-11-06 01:53:30 +0000527 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000528 if (log)
529 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type);
530
Chris Lattner24943d22010-06-08 16:52:24 +0000531
532 return is_ptr_type;
533}
534
Chris Lattner24943d22010-06-08 16:52:24 +0000535void *
536SBValue::GetOpaqueType()
537{
Greg Clayton63094e02010-06-23 01:19:29 +0000538 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000539 {
540 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000541 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000542 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
543
Greg Claytonb9dcc512011-06-29 18:28:50 +0000544 return m_opaque_sp->GetClangType();
545 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000546 }
Chris Lattner24943d22010-06-08 16:52:24 +0000547 return NULL;
548}
549
550// Mimic shared pointer...
551lldb_private::ValueObject *
552SBValue::get() const
553{
Greg Clayton63094e02010-06-23 01:19:29 +0000554 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000555}
556
557lldb_private::ValueObject *
558SBValue::operator->() const
559{
Greg Clayton63094e02010-06-23 01:19:29 +0000560 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000561}
562
563lldb::ValueObjectSP &
564SBValue::operator*()
565{
Greg Clayton63094e02010-06-23 01:19:29 +0000566 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000567}
568
569const lldb::ValueObjectSP &
570SBValue::operator*() const
571{
Greg Clayton63094e02010-06-23 01:19:29 +0000572 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000573}
Caroline Tice98f930f2010-09-20 05:20:02 +0000574
575bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000576SBValue::GetExpressionPath (SBStream &description)
577{
578 if (m_opaque_sp)
579 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000580 m_opaque_sp->GetExpressionPath (description.ref(), false);
581 return true;
582 }
583 return false;
584}
585
586bool
587SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
588{
589 if (m_opaque_sp)
590 {
591 m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +0000592 return true;
593 }
594 return false;
595}
596
597bool
Caroline Tice98f930f2010-09-20 05:20:02 +0000598SBValue::GetDescription (SBStream &description)
599{
600 if (m_opaque_sp)
601 {
Greg Claytonbafc86e2011-07-06 16:49:27 +0000602 uint32_t ptr_depth = 0;
603 uint32_t curr_depth = 0;
604 uint32_t max_depth = UINT32_MAX;
605 bool show_types = false;
606 bool show_location = false;
607 bool use_objc = false;
608 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
609 bool scope_already_checked = false;
610 bool flat_output = false;
611 ValueObject::DumpValueObject (description.ref(),
612 m_opaque_sp.get(),
613 m_opaque_sp->GetName().GetCString(),
614 ptr_depth,
615 curr_depth,
616 max_depth,
617 show_types, show_location,
618 use_objc,
619 use_dynamic,
620 scope_already_checked,
621 flat_output);
Caroline Tice98f930f2010-09-20 05:20:02 +0000622 }
623 else
624 description.Printf ("No value");
625
626 return true;
627}
Greg Claytone179a582011-01-05 18:43:15 +0000628
629lldb::Format
630SBValue::GetFormat () const
631{
632 if (m_opaque_sp)
633 return m_opaque_sp->GetFormat();
634 return eFormatDefault;
635}
636
637void
638SBValue::SetFormat (lldb::Format format)
639{
640 if (m_opaque_sp)
641 m_opaque_sp->SetFormat(format);
642}
643