blob: 03ac1273b7352e0772dd602c7b01ef9528256054 [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())
152 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
153 result = m_opaque_sp->IsInScope ();
Greg Claytonbdcda462010-12-20 20:49:23 +0000154 }
Chris Lattner24943d22010-06-08 16:52:24 +0000155
Greg Claytone005f2c2010-11-06 01:53:30 +0000156 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000157 if (log)
158 log->Printf ("SBValue(%p)::IsInScope () => %i", m_opaque_sp.get(), result);
159
Chris Lattner24943d22010-06-08 16:52:24 +0000160 return result;
161}
162
163const char *
Greg Claytonbdcda462010-12-20 20:49:23 +0000164SBValue::GetValue (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000165{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000166 return GetValue();
167}
168
169const char *
170SBValue::GetValue ()
171{
Greg Clayton49ce6822010-10-31 03:01:06 +0000172 const char *cstr = NULL;
Greg Claytonbdcda462010-12-20 20:49:23 +0000173 if (m_opaque_sp)
174 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000175 if (m_opaque_sp->GetUpdatePoint().GetTarget())
176 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
177 cstr = m_opaque_sp->GetValueAsCString ();
Greg Claytonbdcda462010-12-20 20:49:23 +0000178 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000179 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000180 if (log)
181 {
182 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000183 log->Printf ("SBValue(%p)::GetValue => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000184 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000185 log->Printf ("SBValue(%p)::GetValue => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000186 }
187
188 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000189}
190
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000191ValueType
192SBValue::GetValueType ()
193{
Greg Clayton49ce6822010-10-31 03:01:06 +0000194 ValueType result = eValueTypeInvalid;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000195 if (m_opaque_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +0000196 result = m_opaque_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000197 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000198 if (log)
199 {
200 switch (result)
201 {
202 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", m_opaque_sp.get()); break;
203 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", m_opaque_sp.get()); break;
204 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", m_opaque_sp.get()); break;
205 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", m_opaque_sp.get()); break;
206 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", m_opaque_sp.get()); break;
207 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", m_opaque_sp.get()); break;
208 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", m_opaque_sp.get()); break;
209 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", m_opaque_sp.get()); break;
210 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", m_opaque_sp.get(), result); break;
211 }
212 }
213 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000214}
215
Jim Ingham4ae51962010-09-10 23:12:17 +0000216const char *
Greg Claytonbdcda462010-12-20 20:49:23 +0000217SBValue::GetObjectDescription (const SBFrame &sb_frame)
Jim Ingham4ae51962010-09-10 23:12:17 +0000218{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000219 return GetObjectDescription ();
220}
221
222const char *
223SBValue::GetObjectDescription ()
224{
Greg Clayton49ce6822010-10-31 03:01:06 +0000225 const char *cstr = NULL;
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000226 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000227 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000228 if (m_opaque_sp->GetUpdatePoint().GetTarget())
229 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
230 cstr = m_opaque_sp->GetObjectDescription ();
Greg Claytonbdcda462010-12-20 20:49:23 +0000231 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000232 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000233 if (log)
234 {
235 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000236 log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000237 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000238 log->Printf ("SBValue(%p)::GetObjectDescription => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000239 }
240 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000241}
242
Chris Lattner24943d22010-06-08 16:52:24 +0000243bool
Greg Claytonbdcda462010-12-20 20:49:23 +0000244SBValue::GetValueDidChange (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000245{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000246 return GetValueDidChange ();
247}
248
249bool
250SBValue::GetValueDidChange ()
251{
Greg Clayton49ce6822010-10-31 03:01:06 +0000252 bool result = false;
253 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000254 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000255 if (m_opaque_sp->GetUpdatePoint().GetTarget())
256 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
257 result = m_opaque_sp->GetValueDidChange ();
Greg Claytonbdcda462010-12-20 20:49:23 +0000258 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000259 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000260 if (log)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000261 log->Printf ("SBValue(%p)::GetValueDidChange => %i", m_opaque_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000262
263 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000264}
265
266const char *
Greg Claytonbdcda462010-12-20 20:49:23 +0000267SBValue::GetSummary (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000268{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000269 return GetSummary ();
270}
271
272const char *
273SBValue::GetSummary ()
274{
Greg Clayton49ce6822010-10-31 03:01:06 +0000275 const char *cstr = NULL;
276 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000277 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000278 if (m_opaque_sp->GetUpdatePoint().GetTarget())
279 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
280 cstr = m_opaque_sp->GetSummaryAsCString();
Greg Claytonbdcda462010-12-20 20:49:23 +0000281 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000282 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000283 if (log)
284 {
285 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000286 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000287 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000288 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000289 }
290 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000291}
292
293const char *
Greg Claytonbdcda462010-12-20 20:49:23 +0000294SBValue::GetLocation (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000295{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000296 return GetLocation ();
297}
298
299const char *
300SBValue::GetLocation ()
301{
Greg Clayton49ce6822010-10-31 03:01:06 +0000302 const char *cstr = NULL;
303 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000304 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000305 if (m_opaque_sp->GetUpdatePoint().GetTarget())
306 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
307 cstr = m_opaque_sp->GetLocationAsCString();
Greg Claytonbdcda462010-12-20 20:49:23 +0000308 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000309 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000310 if (log)
311 {
312 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000313 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000314 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000315 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000316 }
317 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000318}
319
320bool
Greg Claytonbdcda462010-12-20 20:49:23 +0000321SBValue::SetValueFromCString (const SBFrame &sb_frame, const char *value_str)
Chris Lattner24943d22010-06-08 16:52:24 +0000322{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000323 return SetValueFromCString (value_str);
324}
325
326bool
327SBValue::SetValueFromCString (const char *value_str)
328{
Chris Lattner24943d22010-06-08 16:52:24 +0000329 bool success = false;
Greg Clayton49ce6822010-10-31 03:01:06 +0000330 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000331 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000332 if (m_opaque_sp->GetUpdatePoint().GetTarget())
333 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
334 success = m_opaque_sp->SetValueFromCString (value_str);
Greg Claytonbdcda462010-12-20 20:49:23 +0000335 }
Chris Lattner24943d22010-06-08 16:52:24 +0000336 return success;
337}
338
339SBValue
340SBValue::GetChildAtIndex (uint32_t idx)
341{
Jim Ingham10de7d12011-05-04 03:43:18 +0000342 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000343 return GetChildAtIndex (idx, use_dynamic_value);
344}
345
346SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000347SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000348{
Chris Lattner24943d22010-06-08 16:52:24 +0000349 lldb::ValueObjectSP child_sp;
350
Greg Clayton905acaf2011-05-20 22:07:17 +0000351 if (m_opaque_sp->GetUpdatePoint().GetTarget())
352 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
353
Greg Clayton49ce6822010-10-31 03:01:06 +0000354 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000355 {
Greg Clayton63094e02010-06-23 01:19:29 +0000356 child_sp = m_opaque_sp->GetChildAtIndex (idx, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000357 }
358
Jim Ingham10de7d12011-05-04 03:43:18 +0000359 if (use_dynamic != lldb::eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +0000360 {
361 if (child_sp)
362 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000363 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic);
Jim Inghame41494a2011-04-16 00:01:13 +0000364 if (dynamic_sp)
365 child_sp = dynamic_sp;
366 }
367 }
368
Chris Lattner24943d22010-06-08 16:52:24 +0000369 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000370 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000371 if (log)
372 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get());
373
Chris Lattner24943d22010-06-08 16:52:24 +0000374 return sb_value;
375}
376
377uint32_t
378SBValue::GetIndexOfChildWithName (const char *name)
379{
Greg Clayton49ce6822010-10-31 03:01:06 +0000380 uint32_t idx = UINT32_MAX;
381 if (m_opaque_sp)
382 idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
Greg Claytone005f2c2010-11-06 01:53:30 +0000383 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000384 if (log)
385 {
386 if (idx == UINT32_MAX)
387 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name, idx);
388 else
389 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx);
390 }
391 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000392}
393
394SBValue
395SBValue::GetChildMemberWithName (const char *name)
396{
Jim Ingham10de7d12011-05-04 03:43:18 +0000397 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000398 return GetChildMemberWithName (name, use_dynamic_value);
399}
400
401SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000402SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000403{
Chris Lattner24943d22010-06-08 16:52:24 +0000404 lldb::ValueObjectSP child_sp;
405 const ConstString str_name (name);
406
Greg Clayton905acaf2011-05-20 22:07:17 +0000407 if (m_opaque_sp->GetUpdatePoint().GetTarget())
408 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
409
410
Greg Clayton49ce6822010-10-31 03:01:06 +0000411 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000412 {
Greg Clayton63094e02010-06-23 01:19:29 +0000413 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000414 }
415
Jim Ingham10de7d12011-05-04 03:43:18 +0000416 if (use_dynamic_value != lldb::eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +0000417 {
418 if (child_sp)
419 {
Jim Ingham10de7d12011-05-04 03:43:18 +0000420 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
Jim Inghame41494a2011-04-16 00:01:13 +0000421 if (dynamic_sp)
422 child_sp = dynamic_sp;
423 }
424 }
425
Chris Lattner24943d22010-06-08 16:52:24 +0000426 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000427
Greg Claytone005f2c2010-11-06 01:53:30 +0000428 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000429 if (log)
430 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get());
431
Chris Lattner24943d22010-06-08 16:52:24 +0000432 return sb_value;
433}
434
435
436uint32_t
437SBValue::GetNumChildren ()
438{
439 uint32_t num_children = 0;
440
Greg Clayton49ce6822010-10-31 03:01:06 +0000441 if (m_opaque_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000442 num_children = m_opaque_sp->GetNumChildren();
Greg Clayton49ce6822010-10-31 03:01:06 +0000443
Greg Claytone005f2c2010-11-06 01:53:30 +0000444 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000445 if (log)
446 log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000447
448 return num_children;
449}
450
Chris Lattner24943d22010-06-08 16:52:24 +0000451
452SBValue
453SBValue::Dereference ()
454{
Greg Clayton49ce6822010-10-31 03:01:06 +0000455 SBValue sb_value;
456 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000457 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000458 Error error;
459 sb_value = m_opaque_sp->Dereference (error);
Chris Lattner24943d22010-06-08 16:52:24 +0000460 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000461 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000462 if (log)
463 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
464
465 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000466}
467
468bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000469SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000470{
471 bool is_ptr_type = false;
472
Greg Clayton49ce6822010-10-31 03:01:06 +0000473 if (m_opaque_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000474 is_ptr_type = m_opaque_sp->IsPointerType();
Greg Clayton49ce6822010-10-31 03:01:06 +0000475
Greg Claytone005f2c2010-11-06 01:53:30 +0000476 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000477 if (log)
478 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type);
479
Chris Lattner24943d22010-06-08 16:52:24 +0000480
481 return is_ptr_type;
482}
483
Chris Lattner24943d22010-06-08 16:52:24 +0000484void *
485SBValue::GetOpaqueType()
486{
Greg Clayton63094e02010-06-23 01:19:29 +0000487 if (m_opaque_sp)
Greg Clayton462d4142010-09-29 01:12:09 +0000488 return m_opaque_sp->GetClangType();
Chris Lattner24943d22010-06-08 16:52:24 +0000489 return NULL;
490}
491
492// Mimic shared pointer...
493lldb_private::ValueObject *
494SBValue::get() const
495{
Greg Clayton63094e02010-06-23 01:19:29 +0000496 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000497}
498
499lldb_private::ValueObject *
500SBValue::operator->() const
501{
Greg Clayton63094e02010-06-23 01:19:29 +0000502 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000503}
504
505lldb::ValueObjectSP &
506SBValue::operator*()
507{
Greg Clayton63094e02010-06-23 01:19:29 +0000508 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000509}
510
511const lldb::ValueObjectSP &
512SBValue::operator*() const
513{
Greg Clayton63094e02010-06-23 01:19:29 +0000514 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000515}
Caroline Tice98f930f2010-09-20 05:20:02 +0000516
517bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000518SBValue::GetExpressionPath (SBStream &description)
519{
520 if (m_opaque_sp)
521 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000522 m_opaque_sp->GetExpressionPath (description.ref(), false);
523 return true;
524 }
525 return false;
526}
527
528bool
529SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
530{
531 if (m_opaque_sp)
532 {
533 m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +0000534 return true;
535 }
536 return false;
537}
538
539bool
Caroline Tice98f930f2010-09-20 05:20:02 +0000540SBValue::GetDescription (SBStream &description)
541{
542 if (m_opaque_sp)
543 {
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000544 // Don't call all these APIs and cause more logging!
545// const char *name = GetName();
546// const char *type_name = GetTypeName ();
547// size_t byte_size = GetByteSize ();
548// uint32_t num_children = GetNumChildren ();
549// bool is_stale = ValueIsStale ();
550// description.Printf ("name: '%s', type: %s, size: %d", (name != NULL ? name : "<unknown name>"),
551// (type_name != NULL ? type_name : "<unknown type name>"), (int) byte_size);
552// if (num_children > 0)
553// description.Printf (", num_children: %d", num_children);
554//
555// if (is_stale)
556// description.Printf (" [value is stale]");
557
558 description.Printf ("name: '%s'", m_opaque_sp->GetName().GetCString());
Caroline Tice98f930f2010-09-20 05:20:02 +0000559 }
560 else
561 description.Printf ("No value");
562
563 return true;
564}
Greg Claytone179a582011-01-05 18:43:15 +0000565
566lldb::Format
567SBValue::GetFormat () const
568{
569 if (m_opaque_sp)
570 return m_opaque_sp->GetFormat();
571 return eFormatDefault;
572}
573
574void
575SBValue::SetFormat (lldb::Format format)
576{
577 if (m_opaque_sp)
578 m_opaque_sp->SetFormat(format);
579}
580