blob: 5956784bbc76f9f11c2da45005256df726d23516 [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{
Greg Clayton8f64c472011-07-15 19:31:49 +0000364 const bool can_create_synthetic = false;
365 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Johnny Chen446ccaa2011-06-29 21:19:39 +0000366 if (m_opaque_sp)
Greg Clayton8f64c472011-07-15 19:31:49 +0000367 use_dynamic = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue();
368 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000369}
370
371SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000372SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000373{
Chris Lattner24943d22010-06-08 16:52:24 +0000374 lldb::ValueObjectSP child_sp;
375
Greg Clayton49ce6822010-10-31 03:01:06 +0000376 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000377 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000378 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000379 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000380 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
Greg Clayton8f64c472011-07-15 19:31:49 +0000381 const bool can_create = true;
382 child_sp = m_opaque_sp->GetChildAtIndex (idx, can_create);
383 if (can_create_synthetic && !child_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000384 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000385 if (m_opaque_sp->IsPointerType())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000386 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000387 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
388 }
389 else if (m_opaque_sp->IsArrayType())
390 {
391 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
392 }
393 }
394
395 if (child_sp)
396 {
397 if (use_dynamic != lldb::eNoDynamicValues)
398 {
399 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000400 if (dynamic_sp)
401 child_sp = dynamic_sp;
402 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000403 }
Jim Inghame41494a2011-04-16 00:01:13 +0000404 }
405 }
406
Chris Lattner24943d22010-06-08 16:52:24 +0000407 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000408 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000409 if (log)
410 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get());
411
Chris Lattner24943d22010-06-08 16:52:24 +0000412 return sb_value;
413}
414
415uint32_t
416SBValue::GetIndexOfChildWithName (const char *name)
417{
Greg Clayton49ce6822010-10-31 03:01:06 +0000418 uint32_t idx = UINT32_MAX;
419 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000420 {
421 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000422 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000423 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
424
Greg Claytonb9dcc512011-06-29 18:28:50 +0000425 idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
426 }
Greg Claytonfab305b2011-05-20 23:51:26 +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 {
431 if (idx == UINT32_MAX)
432 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name, idx);
433 else
434 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx);
435 }
436 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000437}
438
439SBValue
440SBValue::GetChildMemberWithName (const char *name)
441{
Johnny Chen446ccaa2011-06-29 21:19:39 +0000442 if (m_opaque_sp)
443 {
444 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue();
445 return GetChildMemberWithName (name, use_dynamic_value);
446 }
447 else
448 return GetChildMemberWithName (name, eNoDynamicValues);
Jim Inghame41494a2011-04-16 00:01:13 +0000449}
450
451SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000452SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000453{
Chris Lattner24943d22010-06-08 16:52:24 +0000454 lldb::ValueObjectSP child_sp;
455 const ConstString str_name (name);
456
Greg Clayton905acaf2011-05-20 22:07:17 +0000457
Greg Clayton49ce6822010-10-31 03:01:06 +0000458 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000459 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000460 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Jim Inghame41494a2011-04-16 00:01:13 +0000461 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000462 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
463 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
464 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000465 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000466 if (child_sp)
467 {
468 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
469 if (dynamic_sp)
470 child_sp = dynamic_sp;
471 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000472 }
Jim Inghame41494a2011-04-16 00:01:13 +0000473 }
474 }
475
Chris Lattner24943d22010-06-08 16:52:24 +0000476 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000477
Greg Claytone005f2c2010-11-06 01:53:30 +0000478 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000479 if (log)
480 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get());
481
Chris Lattner24943d22010-06-08 16:52:24 +0000482 return sb_value;
483}
484
Enrico Granataf7a9b142011-07-15 02:26:42 +0000485lldb::SBValue
486SBValue::GetValueForExpressionPath(const char* expr_path)
487{
488 lldb::ValueObjectSP child_sp;
489 if (m_opaque_sp)
490 {
491 if (m_opaque_sp->GetUpdatePoint().GetTarget())
492 {
493 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
494 // using default values for all the fancy options, just do it if you can
495 child_sp = m_opaque_sp->GetValueForExpressionPath(expr_path);
496 }
497 }
498
499 SBValue sb_value (child_sp);
500
501 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
502 if (log)
503 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", m_opaque_sp.get(), expr_path, sb_value.get());
504
505 return sb_value;
506}
Chris Lattner24943d22010-06-08 16:52:24 +0000507
508uint32_t
509SBValue::GetNumChildren ()
510{
511 uint32_t num_children = 0;
512
Greg Clayton49ce6822010-10-31 03:01:06 +0000513 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000514 {
515 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000516 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000517 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
518
Greg Claytonb9dcc512011-06-29 18:28:50 +0000519 num_children = m_opaque_sp->GetNumChildren();
520 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000521 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000522
Greg Claytone005f2c2010-11-06 01:53:30 +0000523 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000524 if (log)
525 log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000526
527 return num_children;
528}
529
Chris Lattner24943d22010-06-08 16:52:24 +0000530
531SBValue
532SBValue::Dereference ()
533{
Greg Clayton49ce6822010-10-31 03:01:06 +0000534 SBValue sb_value;
535 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000536 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000537 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000538 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000539 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
540
Greg Claytonb9dcc512011-06-29 18:28:50 +0000541 Error error;
542 sb_value = m_opaque_sp->Dereference (error);
543 }
Chris Lattner24943d22010-06-08 16:52:24 +0000544 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000545 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000546 if (log)
547 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
548
549 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000550}
551
552bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000553SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000554{
555 bool is_ptr_type = false;
556
Greg Clayton49ce6822010-10-31 03:01:06 +0000557 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000558 {
559 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000560 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000561 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
562
Greg Claytonb9dcc512011-06-29 18:28:50 +0000563 is_ptr_type = m_opaque_sp->IsPointerType();
564 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000565 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000566
Greg Claytone005f2c2010-11-06 01:53:30 +0000567 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000568 if (log)
569 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type);
570
Chris Lattner24943d22010-06-08 16:52:24 +0000571
572 return is_ptr_type;
573}
574
Chris Lattner24943d22010-06-08 16:52:24 +0000575void *
576SBValue::GetOpaqueType()
577{
Greg Clayton63094e02010-06-23 01:19:29 +0000578 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000579 {
580 if (m_opaque_sp->GetUpdatePoint().GetTarget())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000581 {
Greg Claytonfab305b2011-05-20 23:51:26 +0000582 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTarget()->GetAPIMutex());
583
Greg Claytonb9dcc512011-06-29 18:28:50 +0000584 return m_opaque_sp->GetClangType();
585 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000586 }
Chris Lattner24943d22010-06-08 16:52:24 +0000587 return NULL;
588}
589
590// Mimic shared pointer...
591lldb_private::ValueObject *
592SBValue::get() const
593{
Greg Clayton63094e02010-06-23 01:19:29 +0000594 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000595}
596
597lldb_private::ValueObject *
598SBValue::operator->() const
599{
Greg Clayton63094e02010-06-23 01:19:29 +0000600 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000601}
602
603lldb::ValueObjectSP &
604SBValue::operator*()
605{
Greg Clayton63094e02010-06-23 01:19:29 +0000606 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000607}
608
609const lldb::ValueObjectSP &
610SBValue::operator*() const
611{
Greg Clayton63094e02010-06-23 01:19:29 +0000612 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000613}
Caroline Tice98f930f2010-09-20 05:20:02 +0000614
615bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000616SBValue::GetExpressionPath (SBStream &description)
617{
618 if (m_opaque_sp)
619 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000620 m_opaque_sp->GetExpressionPath (description.ref(), false);
621 return true;
622 }
623 return false;
624}
625
626bool
627SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
628{
629 if (m_opaque_sp)
630 {
631 m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +0000632 return true;
633 }
634 return false;
635}
636
637bool
Caroline Tice98f930f2010-09-20 05:20:02 +0000638SBValue::GetDescription (SBStream &description)
639{
640 if (m_opaque_sp)
641 {
Greg Claytonbafc86e2011-07-06 16:49:27 +0000642 uint32_t ptr_depth = 0;
643 uint32_t curr_depth = 0;
644 uint32_t max_depth = UINT32_MAX;
645 bool show_types = false;
646 bool show_location = false;
647 bool use_objc = false;
648 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
649 bool scope_already_checked = false;
650 bool flat_output = false;
651 ValueObject::DumpValueObject (description.ref(),
652 m_opaque_sp.get(),
653 m_opaque_sp->GetName().GetCString(),
654 ptr_depth,
655 curr_depth,
656 max_depth,
657 show_types, show_location,
658 use_objc,
659 use_dynamic,
660 scope_already_checked,
661 flat_output);
Caroline Tice98f930f2010-09-20 05:20:02 +0000662 }
663 else
664 description.Printf ("No value");
665
666 return true;
667}
Greg Claytone179a582011-01-05 18:43:15 +0000668
669lldb::Format
670SBValue::GetFormat () const
671{
672 if (m_opaque_sp)
673 return m_opaque_sp->GetFormat();
674 return eFormatDefault;
675}
676
677void
678SBValue::SetFormat (lldb::Format format)
679{
680 if (m_opaque_sp)
681 m_opaque_sp->SetFormat(format);
682}
683