blob: 376bd624a547fee2c7d1eb52c2b183157aab13c8 [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{
Jim Ingham10de7d12011-05-04 03:43:18 +0000356 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000357 return GetChildAtIndex (idx, use_dynamic_value);
358}
359
360SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000361SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000362{
Chris Lattner24943d22010-06-08 16:52:24 +0000363 lldb::ValueObjectSP child_sp;
364
Greg Clayton49ce6822010-10-31 03:01:06 +0000365 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000366 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000367 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000368 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000369 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
370
Greg Claytonb9dcc512011-06-29 18:28:50 +0000371 child_sp = m_opaque_sp->GetChildAtIndex (idx, true);
372 if (use_dynamic != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000373 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000374 if (child_sp)
375 {
376 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic);
377 if (dynamic_sp)
378 child_sp = dynamic_sp;
379 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000380 }
Jim Inghame41494a2011-04-16 00:01:13 +0000381 }
382 }
383
Chris Lattner24943d22010-06-08 16:52:24 +0000384 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000385 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000386 if (log)
387 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get());
388
Chris Lattner24943d22010-06-08 16:52:24 +0000389 return sb_value;
390}
391
392uint32_t
393SBValue::GetIndexOfChildWithName (const char *name)
394{
Greg Clayton49ce6822010-10-31 03:01:06 +0000395 uint32_t idx = UINT32_MAX;
396 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000397 {
398 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000399 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000400 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
401
Greg Claytonb9dcc512011-06-29 18:28:50 +0000402 idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
403 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000404 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000405 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000406 if (log)
407 {
408 if (idx == UINT32_MAX)
409 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name, idx);
410 else
411 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx);
412 }
413 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000414}
415
416SBValue
417SBValue::GetChildMemberWithName (const char *name)
418{
Jim Ingham10de7d12011-05-04 03:43:18 +0000419 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000420 return GetChildMemberWithName (name, use_dynamic_value);
421}
422
423SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000424SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000425{
Chris Lattner24943d22010-06-08 16:52:24 +0000426 lldb::ValueObjectSP child_sp;
427 const ConstString str_name (name);
428
Greg Clayton905acaf2011-05-20 22:07:17 +0000429
Greg Clayton49ce6822010-10-31 03:01:06 +0000430 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000431 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000432 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Jim Inghame41494a2011-04-16 00:01:13 +0000433 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000434 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
435 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
436 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000437 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000438 if (child_sp)
439 {
440 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
441 if (dynamic_sp)
442 child_sp = dynamic_sp;
443 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000444 }
Jim Inghame41494a2011-04-16 00:01:13 +0000445 }
446 }
447
Chris Lattner24943d22010-06-08 16:52:24 +0000448 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000449
Greg Claytone005f2c2010-11-06 01:53:30 +0000450 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000451 if (log)
452 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get());
453
Chris Lattner24943d22010-06-08 16:52:24 +0000454 return sb_value;
455}
456
457
458uint32_t
459SBValue::GetNumChildren ()
460{
461 uint32_t num_children = 0;
462
Greg Clayton49ce6822010-10-31 03:01:06 +0000463 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000464 {
465 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000466 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000467 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
468
Greg Claytonb9dcc512011-06-29 18:28:50 +0000469 num_children = m_opaque_sp->GetNumChildren();
470 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000471 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000472
Greg Claytone005f2c2010-11-06 01:53:30 +0000473 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000474 if (log)
475 log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000476
477 return num_children;
478}
479
Chris Lattner24943d22010-06-08 16:52:24 +0000480
481SBValue
482SBValue::Dereference ()
483{
Greg Clayton49ce6822010-10-31 03:01:06 +0000484 SBValue sb_value;
485 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000486 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000487 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000488 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000489 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
490
Greg Claytonb9dcc512011-06-29 18:28:50 +0000491 Error error;
492 sb_value = m_opaque_sp->Dereference (error);
493 }
Chris Lattner24943d22010-06-08 16:52:24 +0000494 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000495 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000496 if (log)
497 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
498
499 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000500}
501
502bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000503SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000504{
505 bool is_ptr_type = false;
506
Greg Clayton49ce6822010-10-31 03:01:06 +0000507 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000508 {
509 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000510 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000511 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
512
Greg Claytonb9dcc512011-06-29 18:28:50 +0000513 is_ptr_type = m_opaque_sp->IsPointerType();
514 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000515 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000516
Greg Claytone005f2c2010-11-06 01:53:30 +0000517 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000518 if (log)
519 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type);
520
Chris Lattner24943d22010-06-08 16:52:24 +0000521
522 return is_ptr_type;
523}
524
Chris Lattner24943d22010-06-08 16:52:24 +0000525void *
526SBValue::GetOpaqueType()
527{
Greg Clayton63094e02010-06-23 01:19:29 +0000528 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000529 {
530 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000531 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000532 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
533
Greg Claytonb9dcc512011-06-29 18:28:50 +0000534 return m_opaque_sp->GetClangType();
535 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000536 }
Chris Lattner24943d22010-06-08 16:52:24 +0000537 return NULL;
538}
539
540// Mimic shared pointer...
541lldb_private::ValueObject *
542SBValue::get() const
543{
Greg Clayton63094e02010-06-23 01:19:29 +0000544 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000545}
546
547lldb_private::ValueObject *
548SBValue::operator->() const
549{
Greg Clayton63094e02010-06-23 01:19:29 +0000550 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000551}
552
553lldb::ValueObjectSP &
554SBValue::operator*()
555{
Greg Clayton63094e02010-06-23 01:19:29 +0000556 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000557}
558
559const lldb::ValueObjectSP &
560SBValue::operator*() const
561{
Greg Clayton63094e02010-06-23 01:19:29 +0000562 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000563}
Caroline Tice98f930f2010-09-20 05:20:02 +0000564
565bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000566SBValue::GetExpressionPath (SBStream &description)
567{
568 if (m_opaque_sp)
569 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000570 m_opaque_sp->GetExpressionPath (description.ref(), false);
571 return true;
572 }
573 return false;
574}
575
576bool
577SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
578{
579 if (m_opaque_sp)
580 {
581 m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +0000582 return true;
583 }
584 return false;
585}
586
587bool
Caroline Tice98f930f2010-09-20 05:20:02 +0000588SBValue::GetDescription (SBStream &description)
589{
590 if (m_opaque_sp)
591 {
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000592 // Don't call all these APIs and cause more logging!
593// const char *name = GetName();
594// const char *type_name = GetTypeName ();
595// size_t byte_size = GetByteSize ();
596// uint32_t num_children = GetNumChildren ();
597// bool is_stale = ValueIsStale ();
598// description.Printf ("name: '%s', type: %s, size: %d", (name != NULL ? name : "<unknown name>"),
599// (type_name != NULL ? type_name : "<unknown type name>"), (int) byte_size);
600// if (num_children > 0)
601// description.Printf (", num_children: %d", num_children);
602//
603// if (is_stale)
604// description.Printf (" [value is stale]");
605
606 description.Printf ("name: '%s'", m_opaque_sp->GetName().GetCString());
Caroline Tice98f930f2010-09-20 05:20:02 +0000607 }
608 else
609 description.Printf ("No value");
610
611 return true;
612}
Greg Claytone179a582011-01-05 18:43:15 +0000613
614lldb::Format
615SBValue::GetFormat () const
616{
617 if (m_opaque_sp)
618 return m_opaque_sp->GetFormat();
619 return eFormatDefault;
620}
621
622void
623SBValue::SetFormat (lldb::Format format)
624{
625 if (m_opaque_sp)
626 m_opaque_sp->SetFormat(format);
627}
628