blob: 156f918f3049711cf7f798b50e50f4c7ec8adb06 [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 Clayton49ce6822010-10-31 03:01:06 +0000351 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000352 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000353 if (m_opaque_sp->GetUpdatePoint().GetTarget())
354 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
355
Greg Clayton63094e02010-06-23 01:19:29 +0000356 child_sp = m_opaque_sp->GetChildAtIndex (idx, true);
Greg Claytonfab305b2011-05-20 23:51:26 +0000357 if (use_dynamic != lldb::eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +0000358 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000359 if (child_sp)
360 {
361 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic);
362 if (dynamic_sp)
363 child_sp = dynamic_sp;
364 }
Jim Inghame41494a2011-04-16 00:01:13 +0000365 }
366 }
367
Chris Lattner24943d22010-06-08 16:52:24 +0000368 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000369 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000370 if (log)
371 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get());
372
Chris Lattner24943d22010-06-08 16:52:24 +0000373 return sb_value;
374}
375
376uint32_t
377SBValue::GetIndexOfChildWithName (const char *name)
378{
Greg Clayton49ce6822010-10-31 03:01:06 +0000379 uint32_t idx = UINT32_MAX;
380 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000381 {
382 if (m_opaque_sp->GetUpdatePoint().GetTarget())
383 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
384
Greg Clayton49ce6822010-10-31 03:01:06 +0000385 idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
Greg Claytonfab305b2011-05-20 23:51:26 +0000386 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000387 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000388 if (log)
389 {
390 if (idx == UINT32_MAX)
391 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name, idx);
392 else
393 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx);
394 }
395 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000396}
397
398SBValue
399SBValue::GetChildMemberWithName (const char *name)
400{
Jim Ingham10de7d12011-05-04 03:43:18 +0000401 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000402 return GetChildMemberWithName (name, use_dynamic_value);
403}
404
405SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000406SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000407{
Chris Lattner24943d22010-06-08 16:52:24 +0000408 lldb::ValueObjectSP child_sp;
409 const ConstString str_name (name);
410
Greg Clayton905acaf2011-05-20 22:07:17 +0000411
Greg Clayton49ce6822010-10-31 03:01:06 +0000412 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000413 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000414 if (m_opaque_sp->GetUpdatePoint().GetTarget())
415 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Clayton63094e02010-06-23 01:19:29 +0000416 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
Greg Claytonfab305b2011-05-20 23:51:26 +0000417 if (use_dynamic_value != lldb::eNoDynamicValues)
Jim Inghame41494a2011-04-16 00:01:13 +0000418 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000419 if (child_sp)
420 {
421 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
422 if (dynamic_sp)
423 child_sp = dynamic_sp;
424 }
Jim Inghame41494a2011-04-16 00:01:13 +0000425 }
426 }
427
Chris Lattner24943d22010-06-08 16:52:24 +0000428 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000429
Greg Claytone005f2c2010-11-06 01:53:30 +0000430 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000431 if (log)
432 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get());
433
Chris Lattner24943d22010-06-08 16:52:24 +0000434 return sb_value;
435}
436
437
438uint32_t
439SBValue::GetNumChildren ()
440{
441 uint32_t num_children = 0;
442
Greg Clayton49ce6822010-10-31 03:01:06 +0000443 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000444 {
445 if (m_opaque_sp->GetUpdatePoint().GetTarget())
446 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
447
Greg Clayton63094e02010-06-23 01:19:29 +0000448 num_children = m_opaque_sp->GetNumChildren();
Greg Claytonfab305b2011-05-20 23:51:26 +0000449 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000450
Greg Claytone005f2c2010-11-06 01:53:30 +0000451 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000452 if (log)
453 log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000454
455 return num_children;
456}
457
Chris Lattner24943d22010-06-08 16:52:24 +0000458
459SBValue
460SBValue::Dereference ()
461{
Greg Clayton49ce6822010-10-31 03:01:06 +0000462 SBValue sb_value;
463 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000464 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000465 if (m_opaque_sp->GetUpdatePoint().GetTarget())
466 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
467
Greg Claytonbdcda462010-12-20 20:49:23 +0000468 Error error;
469 sb_value = m_opaque_sp->Dereference (error);
Chris Lattner24943d22010-06-08 16:52:24 +0000470 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000471 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000472 if (log)
473 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
474
475 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000476}
477
478bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000479SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000480{
481 bool is_ptr_type = false;
482
Greg Clayton49ce6822010-10-31 03:01:06 +0000483 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000484 {
485 if (m_opaque_sp->GetUpdatePoint().GetTarget())
486 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
487
Greg Clayton63094e02010-06-23 01:19:29 +0000488 is_ptr_type = m_opaque_sp->IsPointerType();
Greg Claytonfab305b2011-05-20 23:51:26 +0000489 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000490
Greg Claytone005f2c2010-11-06 01:53:30 +0000491 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000492 if (log)
493 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type);
494
Chris Lattner24943d22010-06-08 16:52:24 +0000495
496 return is_ptr_type;
497}
498
Chris Lattner24943d22010-06-08 16:52:24 +0000499void *
500SBValue::GetOpaqueType()
501{
Greg Clayton63094e02010-06-23 01:19:29 +0000502 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000503 {
504 if (m_opaque_sp->GetUpdatePoint().GetTarget())
505 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
506
Greg Clayton462d4142010-09-29 01:12:09 +0000507 return m_opaque_sp->GetClangType();
Greg Claytonfab305b2011-05-20 23:51:26 +0000508 }
Chris Lattner24943d22010-06-08 16:52:24 +0000509 return NULL;
510}
511
512// Mimic shared pointer...
513lldb_private::ValueObject *
514SBValue::get() const
515{
Greg Clayton63094e02010-06-23 01:19:29 +0000516 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000517}
518
519lldb_private::ValueObject *
520SBValue::operator->() const
521{
Greg Clayton63094e02010-06-23 01:19:29 +0000522 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000523}
524
525lldb::ValueObjectSP &
526SBValue::operator*()
527{
Greg Clayton63094e02010-06-23 01:19:29 +0000528 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000529}
530
531const lldb::ValueObjectSP &
532SBValue::operator*() const
533{
Greg Clayton63094e02010-06-23 01:19:29 +0000534 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000535}
Caroline Tice98f930f2010-09-20 05:20:02 +0000536
537bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000538SBValue::GetExpressionPath (SBStream &description)
539{
540 if (m_opaque_sp)
541 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000542 m_opaque_sp->GetExpressionPath (description.ref(), false);
543 return true;
544 }
545 return false;
546}
547
548bool
549SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
550{
551 if (m_opaque_sp)
552 {
553 m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +0000554 return true;
555 }
556 return false;
557}
558
559bool
Caroline Tice98f930f2010-09-20 05:20:02 +0000560SBValue::GetDescription (SBStream &description)
561{
562 if (m_opaque_sp)
563 {
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000564 // Don't call all these APIs and cause more logging!
565// const char *name = GetName();
566// const char *type_name = GetTypeName ();
567// size_t byte_size = GetByteSize ();
568// uint32_t num_children = GetNumChildren ();
569// bool is_stale = ValueIsStale ();
570// description.Printf ("name: '%s', type: %s, size: %d", (name != NULL ? name : "<unknown name>"),
571// (type_name != NULL ? type_name : "<unknown type name>"), (int) byte_size);
572// if (num_children > 0)
573// description.Printf (", num_children: %d", num_children);
574//
575// if (is_stale)
576// description.Printf (" [value is stale]");
577
578 description.Printf ("name: '%s'", m_opaque_sp->GetName().GetCString());
Caroline Tice98f930f2010-09-20 05:20:02 +0000579 }
580 else
581 description.Printf ("No value");
582
583 return true;
584}
Greg Claytone179a582011-01-05 18:43:15 +0000585
586lldb::Format
587SBValue::GetFormat () const
588{
589 if (m_opaque_sp)
590 return m_opaque_sp->GetFormat();
591 return eFormatDefault;
592}
593
594void
595SBValue::SetFormat (lldb::Format format)
596{
597 if (m_opaque_sp)
598 m_opaque_sp->SetFormat(format);
599}
600