blob: f499fae145f2c8bb959147b183c65d9680cce9ea [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 Inghame41494a2011-04-16 00:01:13 +0000342 bool use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue();
343 return GetChildAtIndex (idx, use_dynamic_value);
344}
345
346SBValue
347SBValue::GetChildAtIndex (uint32_t idx, bool use_dynamic_value)
348{
Chris Lattner24943d22010-06-08 16:52:24 +0000349 lldb::ValueObjectSP child_sp;
350
Greg Clayton49ce6822010-10-31 03:01:06 +0000351 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000352 {
Greg Clayton63094e02010-06-23 01:19:29 +0000353 child_sp = m_opaque_sp->GetChildAtIndex (idx, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000354 }
355
Jim Inghame41494a2011-04-16 00:01:13 +0000356 if (use_dynamic_value)
357 {
358 if (child_sp)
359 {
Jim Inghamef80aab2011-05-02 18:13:59 +0000360 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (true);
Jim Inghame41494a2011-04-16 00:01:13 +0000361 if (dynamic_sp)
362 child_sp = dynamic_sp;
363 }
364 }
365
Chris Lattner24943d22010-06-08 16:52:24 +0000366 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000367 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000368 if (log)
369 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get());
370
Chris Lattner24943d22010-06-08 16:52:24 +0000371 return sb_value;
372}
373
374uint32_t
375SBValue::GetIndexOfChildWithName (const char *name)
376{
Greg Clayton49ce6822010-10-31 03:01:06 +0000377 uint32_t idx = UINT32_MAX;
378 if (m_opaque_sp)
379 idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
Greg Claytone005f2c2010-11-06 01:53:30 +0000380 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000381 if (log)
382 {
383 if (idx == UINT32_MAX)
384 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name, idx);
385 else
386 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx);
387 }
388 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000389}
390
391SBValue
392SBValue::GetChildMemberWithName (const char *name)
393{
Jim Inghame41494a2011-04-16 00:01:13 +0000394 bool use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue();
395 return GetChildMemberWithName (name, use_dynamic_value);
396}
397
398SBValue
399SBValue::GetChildMemberWithName (const char *name, bool use_dynamic_value)
400{
Chris Lattner24943d22010-06-08 16:52:24 +0000401 lldb::ValueObjectSP child_sp;
402 const ConstString str_name (name);
403
Greg Clayton49ce6822010-10-31 03:01:06 +0000404 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000405 {
Greg Clayton63094e02010-06-23 01:19:29 +0000406 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000407 }
408
Jim Inghame41494a2011-04-16 00:01:13 +0000409 if (use_dynamic_value)
410 {
411 if (child_sp)
412 {
Jim Inghamef80aab2011-05-02 18:13:59 +0000413 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (true);
Jim Inghame41494a2011-04-16 00:01:13 +0000414 if (dynamic_sp)
415 child_sp = dynamic_sp;
416 }
417 }
418
Chris Lattner24943d22010-06-08 16:52:24 +0000419 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000420
Greg Claytone005f2c2010-11-06 01:53:30 +0000421 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000422 if (log)
423 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get());
424
Chris Lattner24943d22010-06-08 16:52:24 +0000425 return sb_value;
426}
427
428
429uint32_t
430SBValue::GetNumChildren ()
431{
432 uint32_t num_children = 0;
433
Greg Clayton49ce6822010-10-31 03:01:06 +0000434 if (m_opaque_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000435 num_children = m_opaque_sp->GetNumChildren();
Greg Clayton49ce6822010-10-31 03:01:06 +0000436
Greg Claytone005f2c2010-11-06 01:53:30 +0000437 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000438 if (log)
439 log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000440
441 return num_children;
442}
443
Chris Lattner24943d22010-06-08 16:52:24 +0000444
445SBValue
446SBValue::Dereference ()
447{
Greg Clayton49ce6822010-10-31 03:01:06 +0000448 SBValue sb_value;
449 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000450 {
Greg Claytonbdcda462010-12-20 20:49:23 +0000451 Error error;
452 sb_value = m_opaque_sp->Dereference (error);
Chris Lattner24943d22010-06-08 16:52:24 +0000453 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000454 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000455 if (log)
456 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
457
458 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000459}
460
461bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000462SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000463{
464 bool is_ptr_type = false;
465
Greg Clayton49ce6822010-10-31 03:01:06 +0000466 if (m_opaque_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000467 is_ptr_type = m_opaque_sp->IsPointerType();
Greg Clayton49ce6822010-10-31 03:01:06 +0000468
Greg Claytone005f2c2010-11-06 01:53:30 +0000469 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000470 if (log)
471 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type);
472
Chris Lattner24943d22010-06-08 16:52:24 +0000473
474 return is_ptr_type;
475}
476
Chris Lattner24943d22010-06-08 16:52:24 +0000477void *
478SBValue::GetOpaqueType()
479{
Greg Clayton63094e02010-06-23 01:19:29 +0000480 if (m_opaque_sp)
Greg Clayton462d4142010-09-29 01:12:09 +0000481 return m_opaque_sp->GetClangType();
Chris Lattner24943d22010-06-08 16:52:24 +0000482 return NULL;
483}
484
485// Mimic shared pointer...
486lldb_private::ValueObject *
487SBValue::get() const
488{
Greg Clayton63094e02010-06-23 01:19:29 +0000489 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000490}
491
492lldb_private::ValueObject *
493SBValue::operator->() const
494{
Greg Clayton63094e02010-06-23 01:19:29 +0000495 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000496}
497
498lldb::ValueObjectSP &
499SBValue::operator*()
500{
Greg Clayton63094e02010-06-23 01:19:29 +0000501 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000502}
503
504const lldb::ValueObjectSP &
505SBValue::operator*() const
506{
Greg Clayton63094e02010-06-23 01:19:29 +0000507 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000508}
Caroline Tice98f930f2010-09-20 05:20:02 +0000509
510bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000511SBValue::GetExpressionPath (SBStream &description)
512{
513 if (m_opaque_sp)
514 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000515 m_opaque_sp->GetExpressionPath (description.ref(), false);
516 return true;
517 }
518 return false;
519}
520
521bool
522SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
523{
524 if (m_opaque_sp)
525 {
526 m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +0000527 return true;
528 }
529 return false;
530}
531
532bool
Caroline Tice98f930f2010-09-20 05:20:02 +0000533SBValue::GetDescription (SBStream &description)
534{
535 if (m_opaque_sp)
536 {
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000537 // Don't call all these APIs and cause more logging!
538// const char *name = GetName();
539// const char *type_name = GetTypeName ();
540// size_t byte_size = GetByteSize ();
541// uint32_t num_children = GetNumChildren ();
542// bool is_stale = ValueIsStale ();
543// description.Printf ("name: '%s', type: %s, size: %d", (name != NULL ? name : "<unknown name>"),
544// (type_name != NULL ? type_name : "<unknown type name>"), (int) byte_size);
545// if (num_children > 0)
546// description.Printf (", num_children: %d", num_children);
547//
548// if (is_stale)
549// description.Printf (" [value is stale]");
550
551 description.Printf ("name: '%s'", m_opaque_sp->GetName().GetCString());
Caroline Tice98f930f2010-09-20 05:20:02 +0000552 }
553 else
554 description.Printf ("No value");
555
556 return true;
557}
Greg Claytone179a582011-01-05 18:43:15 +0000558
559lldb::Format
560SBValue::GetFormat () const
561{
562 if (m_opaque_sp)
563 return m_opaque_sp->GetFormat();
564 return eFormatDefault;
565}
566
567void
568SBValue::SetFormat (lldb::Format format)
569{
570 if (m_opaque_sp)
571 m_opaque_sp->SetFormat(format);
572}
573