blob: e51919caccaec16f8f86c86d420020f80702e13f [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
Johnny Chen968958c2011-07-07 20:46:23 +000085user_id_t
86SBValue::GetID()
87{
88 if (m_opaque_sp)
89 return m_opaque_sp->GetID();
90 return LLDB_INVALID_UID;
91}
92
Chris Lattner24943d22010-06-08 16:52:24 +000093const char *
94SBValue::GetName()
95{
Greg Clayton49ce6822010-10-31 03:01:06 +000096
97 const char *name = NULL;
98 if (m_opaque_sp)
99 name = m_opaque_sp->GetName().GetCString();
100
Greg Claytone005f2c2010-11-06 01:53:30 +0000101 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000102 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000103 {
104 if (name)
105 log->Printf ("SBValue(%p)::GetName () => \"%s\"", m_opaque_sp.get(), name);
106 else
107 log->Printf ("SBValue(%p)::GetName () => NULL", m_opaque_sp.get(), name);
108 }
Caroline Tice7826c882010-10-26 03:11:13 +0000109
Greg Clayton49ce6822010-10-31 03:01:06 +0000110 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000111}
112
113const char *
114SBValue::GetTypeName ()
115{
Greg Clayton49ce6822010-10-31 03:01:06 +0000116 const char *name = NULL;
117 if (m_opaque_sp)
118 name = m_opaque_sp->GetTypeName().GetCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000119 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000120 if (log)
121 {
122 if (name)
123 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", m_opaque_sp.get(), name);
124 else
125 log->Printf ("SBValue(%p)::GetTypeName () => NULL", m_opaque_sp.get());
126 }
127
128 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000129}
130
131size_t
132SBValue::GetByteSize ()
133{
134 size_t result = 0;
135
Greg Clayton49ce6822010-10-31 03:01:06 +0000136 if (m_opaque_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000137 result = m_opaque_sp->GetByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000138
Greg Claytone005f2c2010-11-06 01:53:30 +0000139 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000140 if (log)
141 log->Printf ("SBValue(%p)::GetByteSize () => %zu", m_opaque_sp.get(), result);
142
Chris Lattner24943d22010-06-08 16:52:24 +0000143 return result;
144}
145
146bool
Greg Claytonbdcda462010-12-20 20:49:23 +0000147SBValue::IsInScope (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000148{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000149 return IsInScope();
150}
151
152bool
153SBValue::IsInScope ()
154{
Chris Lattner24943d22010-06-08 16:52:24 +0000155 bool result = false;
156
Greg Clayton49ce6822010-10-31 03:01:06 +0000157 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000158 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000159 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000160 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000161 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000162 result = m_opaque_sp->IsInScope ();
163 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000164 }
Chris Lattner24943d22010-06-08 16:52:24 +0000165
Greg Claytone005f2c2010-11-06 01:53:30 +0000166 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000167 if (log)
168 log->Printf ("SBValue(%p)::IsInScope () => %i", m_opaque_sp.get(), result);
169
Chris Lattner24943d22010-06-08 16:52:24 +0000170 return result;
171}
172
173const char *
Greg Claytonbdcda462010-12-20 20:49:23 +0000174SBValue::GetValue (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000175{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000176 return GetValue();
177}
178
179const char *
180SBValue::GetValue ()
181{
Greg Clayton49ce6822010-10-31 03:01:06 +0000182 const char *cstr = NULL;
Greg Claytonbdcda462010-12-20 20:49:23 +0000183 if (m_opaque_sp)
184 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000185 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000186 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000187 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000188 cstr = m_opaque_sp->GetValueAsCString ();
189 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000190 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000191 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000192 if (log)
193 {
194 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000195 log->Printf ("SBValue(%p)::GetValue => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000196 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000197 log->Printf ("SBValue(%p)::GetValue => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000198 }
199
200 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000201}
202
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000203ValueType
204SBValue::GetValueType ()
205{
Greg Clayton49ce6822010-10-31 03:01:06 +0000206 ValueType result = eValueTypeInvalid;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000207 if (m_opaque_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +0000208 result = m_opaque_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000209 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000210 if (log)
211 {
212 switch (result)
213 {
214 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", m_opaque_sp.get()); break;
215 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", m_opaque_sp.get()); break;
216 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", m_opaque_sp.get()); break;
217 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", m_opaque_sp.get()); break;
218 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", m_opaque_sp.get()); break;
219 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", m_opaque_sp.get()); break;
220 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", m_opaque_sp.get()); break;
221 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", m_opaque_sp.get()); break;
222 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", m_opaque_sp.get(), result); break;
223 }
224 }
225 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000226}
227
Jim Ingham4ae51962010-09-10 23:12:17 +0000228const char *
Greg Claytonbdcda462010-12-20 20:49:23 +0000229SBValue::GetObjectDescription (const SBFrame &sb_frame)
Jim Ingham4ae51962010-09-10 23:12:17 +0000230{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000231 return GetObjectDescription ();
232}
233
234const char *
235SBValue::GetObjectDescription ()
236{
Greg Clayton49ce6822010-10-31 03:01:06 +0000237 const char *cstr = NULL;
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000238 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000239 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000240 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000241 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000242 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000243 cstr = m_opaque_sp->GetObjectDescription ();
244 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000245 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000246 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000247 if (log)
248 {
249 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000250 log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000251 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000252 log->Printf ("SBValue(%p)::GetObjectDescription => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000253 }
254 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000255}
256
Chris Lattner24943d22010-06-08 16:52:24 +0000257bool
Greg Claytonbdcda462010-12-20 20:49:23 +0000258SBValue::GetValueDidChange (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000259{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000260 return GetValueDidChange ();
261}
262
263bool
264SBValue::GetValueDidChange ()
265{
Greg Clayton49ce6822010-10-31 03:01:06 +0000266 bool result = false;
267 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000268 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000269 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000270 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000271 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000272 result = m_opaque_sp->GetValueDidChange ();
273 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000274 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000275 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000276 if (log)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000277 log->Printf ("SBValue(%p)::GetValueDidChange => %i", m_opaque_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000278
279 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000280}
281
282const char *
Greg Claytonbdcda462010-12-20 20:49:23 +0000283SBValue::GetSummary (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000284{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000285 return GetSummary ();
286}
287
288const char *
289SBValue::GetSummary ()
290{
Greg Clayton49ce6822010-10-31 03:01:06 +0000291 const char *cstr = NULL;
292 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000293 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000294 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000295 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000296 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000297 cstr = m_opaque_sp->GetSummaryAsCString();
298 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000299 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000300 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000301 if (log)
302 {
303 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000304 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000305 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000306 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000307 }
308 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000309}
310
311const char *
Greg Claytonbdcda462010-12-20 20:49:23 +0000312SBValue::GetLocation (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000313{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000314 return GetLocation ();
315}
316
317const char *
318SBValue::GetLocation ()
319{
Greg Clayton49ce6822010-10-31 03:01:06 +0000320 const char *cstr = NULL;
321 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000322 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000323 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000324 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000325 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000326 cstr = m_opaque_sp->GetLocationAsCString();
327 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000328 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000329 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000330 if (log)
331 {
332 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000333 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000334 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000335 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000336 }
337 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000338}
339
340bool
Greg Claytonbdcda462010-12-20 20:49:23 +0000341SBValue::SetValueFromCString (const SBFrame &sb_frame, const char *value_str)
Chris Lattner24943d22010-06-08 16:52:24 +0000342{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000343 return SetValueFromCString (value_str);
344}
345
346bool
347SBValue::SetValueFromCString (const char *value_str)
348{
Chris Lattner24943d22010-06-08 16:52:24 +0000349 bool success = false;
Greg Clayton49ce6822010-10-31 03:01:06 +0000350 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000351 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000352 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000353 {
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000354 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000355 success = m_opaque_sp->SetValueFromCString (value_str);
356 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000357 }
Chris Lattner24943d22010-06-08 16:52:24 +0000358 return success;
359}
360
361SBValue
362SBValue::GetChildAtIndex (uint32_t idx)
363{
Johnny Chen446ccaa2011-06-29 21:19:39 +0000364 if (m_opaque_sp)
365 {
366 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue();
367 return GetChildAtIndex (idx, use_dynamic_value);
368 }
369 else
370 return GetChildAtIndex (idx, eNoDynamicValues);
Jim Inghame41494a2011-04-16 00:01:13 +0000371}
372
373SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000374SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic)
Jim Inghame41494a2011-04-16 00:01:13 +0000375{
Chris Lattner24943d22010-06-08 16:52:24 +0000376 lldb::ValueObjectSP child_sp;
377
Greg Clayton49ce6822010-10-31 03:01:06 +0000378 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000379 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000380 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000381 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000382 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
383
Greg Claytonb9dcc512011-06-29 18:28:50 +0000384 child_sp = m_opaque_sp->GetChildAtIndex (idx, true);
385 if (use_dynamic != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000386 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000387 if (child_sp)
388 {
389 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic);
390 if (dynamic_sp)
391 child_sp = dynamic_sp;
392 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000393 }
Jim Inghame41494a2011-04-16 00:01:13 +0000394 }
395 }
396
Chris Lattner24943d22010-06-08 16:52:24 +0000397 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000398 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000399 if (log)
400 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get());
401
Chris Lattner24943d22010-06-08 16:52:24 +0000402 return sb_value;
403}
404
405uint32_t
406SBValue::GetIndexOfChildWithName (const char *name)
407{
Greg Clayton49ce6822010-10-31 03:01:06 +0000408 uint32_t idx = UINT32_MAX;
409 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000410 {
411 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000412 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000413 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
414
Greg Claytonb9dcc512011-06-29 18:28:50 +0000415 idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
416 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000417 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000418 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000419 if (log)
420 {
421 if (idx == UINT32_MAX)
422 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name, idx);
423 else
424 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx);
425 }
426 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000427}
428
429SBValue
430SBValue::GetChildMemberWithName (const char *name)
431{
Johnny Chen446ccaa2011-06-29 21:19:39 +0000432 if (m_opaque_sp)
433 {
434 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue();
435 return GetChildMemberWithName (name, use_dynamic_value);
436 }
437 else
438 return GetChildMemberWithName (name, eNoDynamicValues);
Jim Inghame41494a2011-04-16 00:01:13 +0000439}
440
441SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000442SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000443{
Chris Lattner24943d22010-06-08 16:52:24 +0000444 lldb::ValueObjectSP child_sp;
445 const ConstString str_name (name);
446
Greg Clayton905acaf2011-05-20 22:07:17 +0000447
Greg Clayton49ce6822010-10-31 03:01:06 +0000448 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000449 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000450 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Jim Inghame41494a2011-04-16 00:01:13 +0000451 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000452 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
453 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
454 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000455 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000456 if (child_sp)
457 {
458 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
459 if (dynamic_sp)
460 child_sp = dynamic_sp;
461 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000462 }
Jim Inghame41494a2011-04-16 00:01:13 +0000463 }
464 }
465
Chris Lattner24943d22010-06-08 16:52:24 +0000466 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000467
Greg Claytone005f2c2010-11-06 01:53:30 +0000468 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000469 if (log)
470 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get());
471
Chris Lattner24943d22010-06-08 16:52:24 +0000472 return sb_value;
473}
474
475
476uint32_t
477SBValue::GetNumChildren ()
478{
479 uint32_t num_children = 0;
480
Greg Clayton49ce6822010-10-31 03:01:06 +0000481 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000482 {
483 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000484 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000485 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
486
Greg Claytonb9dcc512011-06-29 18:28:50 +0000487 num_children = m_opaque_sp->GetNumChildren();
488 }
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)::GetNumChildren () => %u", m_opaque_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000494
495 return num_children;
496}
497
Chris Lattner24943d22010-06-08 16:52:24 +0000498
499SBValue
500SBValue::Dereference ()
501{
Greg Clayton49ce6822010-10-31 03:01:06 +0000502 SBValue sb_value;
503 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000504 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000505 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000506 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000507 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
508
Greg Claytonb9dcc512011-06-29 18:28:50 +0000509 Error error;
510 sb_value = m_opaque_sp->Dereference (error);
511 }
Chris Lattner24943d22010-06-08 16:52:24 +0000512 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000513 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000514 if (log)
515 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
516
517 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000518}
519
520bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000521SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000522{
523 bool is_ptr_type = false;
524
Greg Clayton49ce6822010-10-31 03:01:06 +0000525 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000526 {
527 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000528 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000529 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
530
Greg Claytonb9dcc512011-06-29 18:28:50 +0000531 is_ptr_type = m_opaque_sp->IsPointerType();
532 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000533 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000534
Greg Claytone005f2c2010-11-06 01:53:30 +0000535 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000536 if (log)
537 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type);
538
Chris Lattner24943d22010-06-08 16:52:24 +0000539
540 return is_ptr_type;
541}
542
Chris Lattner24943d22010-06-08 16:52:24 +0000543void *
544SBValue::GetOpaqueType()
545{
Greg Clayton63094e02010-06-23 01:19:29 +0000546 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000547 {
548 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000549 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000550 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
551
Greg Claytonb9dcc512011-06-29 18:28:50 +0000552 return m_opaque_sp->GetClangType();
553 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000554 }
Chris Lattner24943d22010-06-08 16:52:24 +0000555 return NULL;
556}
557
558// Mimic shared pointer...
559lldb_private::ValueObject *
560SBValue::get() const
561{
Greg Clayton63094e02010-06-23 01:19:29 +0000562 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000563}
564
565lldb_private::ValueObject *
566SBValue::operator->() const
567{
Greg Clayton63094e02010-06-23 01:19:29 +0000568 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000569}
570
571lldb::ValueObjectSP &
572SBValue::operator*()
573{
Greg Clayton63094e02010-06-23 01:19:29 +0000574 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000575}
576
577const lldb::ValueObjectSP &
578SBValue::operator*() const
579{
Greg Clayton63094e02010-06-23 01:19:29 +0000580 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000581}
Caroline Tice98f930f2010-09-20 05:20:02 +0000582
583bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000584SBValue::GetExpressionPath (SBStream &description)
585{
586 if (m_opaque_sp)
587 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000588 m_opaque_sp->GetExpressionPath (description.ref(), false);
589 return true;
590 }
591 return false;
592}
593
594bool
595SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
596{
597 if (m_opaque_sp)
598 {
599 m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +0000600 return true;
601 }
602 return false;
603}
604
605bool
Caroline Tice98f930f2010-09-20 05:20:02 +0000606SBValue::GetDescription (SBStream &description)
607{
608 if (m_opaque_sp)
609 {
Greg Claytonbafc86e2011-07-06 16:49:27 +0000610 uint32_t ptr_depth = 0;
611 uint32_t curr_depth = 0;
612 uint32_t max_depth = UINT32_MAX;
613 bool show_types = false;
614 bool show_location = false;
615 bool use_objc = false;
616 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
617 bool scope_already_checked = false;
618 bool flat_output = false;
619 ValueObject::DumpValueObject (description.ref(),
620 m_opaque_sp.get(),
621 m_opaque_sp->GetName().GetCString(),
622 ptr_depth,
623 curr_depth,
624 max_depth,
625 show_types, show_location,
626 use_objc,
627 use_dynamic,
628 scope_already_checked,
629 flat_output);
Caroline Tice98f930f2010-09-20 05:20:02 +0000630 }
631 else
632 description.Printf ("No value");
633
634 return true;
635}
Greg Claytone179a582011-01-05 18:43:15 +0000636
637lldb::Format
638SBValue::GetFormat () const
639{
640 if (m_opaque_sp)
641 return m_opaque_sp->GetFormat();
642 return eFormatDefault;
643}
644
645void
646SBValue::SetFormat (lldb::Format format)
647{
648 if (m_opaque_sp)
649 m_opaque_sp->SetFormat(format);
650}
651