blob: fa2fa778fe3438375f3a9077b172164da12528c7 [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"
Enrico Granatad760907c2012-02-17 03:18:30 +000011
Caroline Tice98f930f2010-09-20 05:20:02 +000012#include "lldb/API/SBStream.h"
Enrico Granatad760907c2012-02-17 03:18:30 +000013#include "lldb/API/SBTypeFilter.h"
14#include "lldb/API/SBTypeFormat.h"
15#include "lldb/API/SBTypeSummary.h"
16#include "lldb/API/SBTypeSynthetic.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017
Johnny Chenecd4feb2011-10-14 00:42:25 +000018#include "lldb/Breakpoint/Watchpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019#include "lldb/Core/DataExtractor.h"
Enrico Granatad760907c2012-02-17 03:18:30 +000020#include "lldb/Core/DataVisualization.h"
Caroline Tice7826c882010-10-26 03:11:13 +000021#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Core/Module.h"
Greg Clayton0fb0bcc2011-08-03 22:57:10 +000023#include "lldb/Core/Scalar.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024#include "lldb/Core/Stream.h"
25#include "lldb/Core/StreamFile.h"
26#include "lldb/Core/Value.h"
27#include "lldb/Core/ValueObject.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000028#include "lldb/Core/ValueObjectConstResult.h"
Chris Lattner24943d22010-06-08 16:52:24 +000029#include "lldb/Symbol/Block.h"
30#include "lldb/Symbol/ObjectFile.h"
Greg Clayton0a19a1b2012-02-04 02:27:34 +000031#include "lldb/Symbol/Type.h"
Chris Lattner24943d22010-06-08 16:52:24 +000032#include "lldb/Symbol/Variable.h"
Johnny Chenecd4feb2011-10-14 00:42:25 +000033#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000034#include "lldb/Target/ExecutionContext.h"
35#include "lldb/Target/Process.h"
36#include "lldb/Target/StackFrame.h"
Greg Claytonbdcda462010-12-20 20:49:23 +000037#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000038#include "lldb/Target/Thread.h"
39
Eli Friedman7a62c8b2010-06-09 07:44:37 +000040#include "lldb/API/SBProcess.h"
41#include "lldb/API/SBTarget.h"
42#include "lldb/API/SBThread.h"
43#include "lldb/API/SBFrame.h"
44#include "lldb/API/SBDebugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000045
46using namespace lldb;
47using namespace lldb_private;
48
49SBValue::SBValue () :
Greg Clayton63094e02010-06-23 01:19:29 +000050 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000051{
52}
53
54SBValue::SBValue (const lldb::ValueObjectSP &value_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000055 m_opaque_sp (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000056{
57}
58
Greg Clayton538eb822010-11-05 23:17:00 +000059SBValue::SBValue(const SBValue &rhs) :
60 m_opaque_sp (rhs.m_opaque_sp)
61{
62}
63
Greg Claytond68e0892011-09-09 23:04:00 +000064SBValue &
Greg Clayton538eb822010-11-05 23:17:00 +000065SBValue::operator = (const SBValue &rhs)
66{
67 if (this != &rhs)
68 m_opaque_sp = rhs.m_opaque_sp;
69 return *this;
70}
71
Chris Lattner24943d22010-06-08 16:52:24 +000072SBValue::~SBValue()
73{
74}
75
76bool
Greg Claytond68e0892011-09-09 23:04:00 +000077SBValue::IsValid ()
Chris Lattner24943d22010-06-08 16:52:24 +000078{
Greg Clayton49ce6822010-10-31 03:01:06 +000079 // If this function ever changes to anything that does more than just
80 // check if the opaque shared pointer is non NULL, then we need to update
81 // all "if (m_opaque_sp)" code in this file.
82 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000083}
84
Jim Inghame0bd5712011-12-19 20:39:44 +000085void
86SBValue::Clear()
87{
88 m_opaque_sp.reset();
89}
90
Greg Claytonc5f728c2010-10-06 22:10:17 +000091SBError
92SBValue::GetError()
93{
94 SBError sb_error;
95
Greg Clayton0a19a1b2012-02-04 02:27:34 +000096 lldb::ValueObjectSP value_sp(GetSP());
97 if (value_sp)
98 sb_error.SetError(value_sp->GetError());
Greg Clayton334d33a2012-01-30 07:41:31 +000099 else
100 sb_error.SetErrorString("error: invalid value");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000101
102 return sb_error;
103}
104
Johnny Chen968958c2011-07-07 20:46:23 +0000105user_id_t
106SBValue::GetID()
107{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000108 lldb::ValueObjectSP value_sp(GetSP());
109 if (value_sp)
110 return value_sp->GetID();
Johnny Chen968958c2011-07-07 20:46:23 +0000111 return LLDB_INVALID_UID;
112}
113
Chris Lattner24943d22010-06-08 16:52:24 +0000114const char *
115SBValue::GetName()
116{
Greg Clayton49ce6822010-10-31 03:01:06 +0000117
118 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000119 lldb::ValueObjectSP value_sp(GetSP());
120 if (value_sp)
121 name = value_sp->GetName().GetCString();
Greg Clayton49ce6822010-10-31 03:01:06 +0000122
Greg Claytone005f2c2010-11-06 01:53:30 +0000123 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000124 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000125 {
126 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000127 log->Printf ("SBValue(%p)::GetName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000128 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000129 log->Printf ("SBValue(%p)::GetName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000130 }
Caroline Tice7826c882010-10-26 03:11:13 +0000131
Greg Clayton49ce6822010-10-31 03:01:06 +0000132 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000133}
134
135const char *
136SBValue::GetTypeName ()
137{
Greg Clayton49ce6822010-10-31 03:01:06 +0000138 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000139 lldb::ValueObjectSP value_sp(GetSP());
140 if (value_sp)
141 name = value_sp->GetTypeName().GetCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000142 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000143 if (log)
144 {
145 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000146 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000147 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000148 log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000149 }
150
151 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000152}
153
154size_t
155SBValue::GetByteSize ()
156{
157 size_t result = 0;
158
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000159 lldb::ValueObjectSP value_sp(GetSP());
160 if (value_sp)
161 result = value_sp->GetByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000162
Greg Claytone005f2c2010-11-06 01:53:30 +0000163 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000164 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000165 log->Printf ("SBValue(%p)::GetByteSize () => %zu", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000166
Chris Lattner24943d22010-06-08 16:52:24 +0000167 return result;
168}
169
170bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000171SBValue::IsInScope ()
172{
Chris Lattner24943d22010-06-08 16:52:24 +0000173 bool result = false;
174
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000175 lldb::ValueObjectSP value_sp(GetSP());
176 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000177 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000178 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000179 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000180 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000181 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000182 result = value_sp->IsInScope ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000183 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000184 }
Chris Lattner24943d22010-06-08 16:52:24 +0000185
Greg Claytone005f2c2010-11-06 01:53:30 +0000186 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000187 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000188 log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000189
Chris Lattner24943d22010-06-08 16:52:24 +0000190 return result;
191}
192
193const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000194SBValue::GetValue ()
195{
Greg Clayton49ce6822010-10-31 03:01:06 +0000196 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000197 lldb::ValueObjectSP value_sp(GetSP());
198 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000199 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000200 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000201 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000202 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000203 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000204 cstr = value_sp->GetValueAsCString ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000205 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000206 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000207 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000208 if (log)
209 {
210 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000211 log->Printf ("SBValue(%p)::GetValue => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000212 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000213 log->Printf ("SBValue(%p)::GetValue => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000214 }
215
216 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000217}
218
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000219ValueType
220SBValue::GetValueType ()
221{
Greg Clayton49ce6822010-10-31 03:01:06 +0000222 ValueType result = eValueTypeInvalid;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000223 lldb::ValueObjectSP value_sp(GetSP());
224 if (value_sp)
225 result = value_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000226 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000227 if (log)
228 {
229 switch (result)
230 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000231 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break;
232 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break;
233 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break;
234 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break;
235 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break;
236 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break;
237 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break;
238 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break;
239 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", value_sp.get(), result); break;
Greg Clayton49ce6822010-10-31 03:01:06 +0000240 }
241 }
242 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000243}
244
Jim Ingham4ae51962010-09-10 23:12:17 +0000245const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000246SBValue::GetObjectDescription ()
247{
Greg Clayton49ce6822010-10-31 03:01:06 +0000248 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000249 lldb::ValueObjectSP value_sp(GetSP());
250 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000251 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000252 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000253 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000254 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000255 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000256 cstr = value_sp->GetObjectDescription ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000257 }
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)
261 {
262 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000263 log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000264 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000265 log->Printf ("SBValue(%p)::GetObjectDescription => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000266 }
267 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000268}
269
Enrico Granata979e20d2011-07-29 19:53:35 +0000270SBType
271SBValue::GetType()
272{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000273 SBType sb_type;
274 lldb::ValueObjectSP value_sp(GetSP());
275 TypeImplSP type_sp;
276 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000277 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000278 type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType())));
279 sb_type.SetSP(type_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000280 }
281 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
282 if (log)
283 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000284 if (type_sp)
285 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000286 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000287 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000288 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000289 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000290}
291
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000292bool
293SBValue::GetValueDidChange ()
294{
Greg Clayton49ce6822010-10-31 03:01:06 +0000295 bool result = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000296 lldb::ValueObjectSP value_sp(GetSP());
297 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000298 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000299 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000300 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000301 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000302 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000303 result = value_sp->GetValueDidChange ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000304 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000305 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000306 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000307 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000308 log->Printf ("SBValue(%p)::GetValueDidChange => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000309
310 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000311}
312
Jason Molendac48ca822012-02-21 05:33:55 +0000313#ifndef LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000314const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000315SBValue::GetSummary ()
316{
Greg Clayton49ce6822010-10-31 03:01:06 +0000317 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000318 lldb::ValueObjectSP value_sp(GetSP());
319 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000320 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000321 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000322 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000323 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000324 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000325 cstr = value_sp->GetSummaryAsCString();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000326 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000327 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000328 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000329 if (log)
330 {
331 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000332 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000333 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000334 log->Printf ("SBValue(%p)::GetSummary => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000335 }
336 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000337}
Jason Molendac48ca822012-02-21 05:33:55 +0000338#endif // LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000339
340const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000341SBValue::GetLocation ()
342{
Greg Clayton49ce6822010-10-31 03:01:06 +0000343 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000344 lldb::ValueObjectSP value_sp(GetSP());
345 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000346 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000347 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000348 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000349 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000350 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000351 cstr = value_sp->GetLocationAsCString();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000352 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000353 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000354 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000355 if (log)
356 {
357 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000358 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000359 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000360 log->Printf ("SBValue(%p)::GetSummary => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000361 }
362 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000363}
364
365bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000366SBValue::SetValueFromCString (const char *value_str)
367{
Chris Lattner24943d22010-06-08 16:52:24 +0000368 bool success = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000369 lldb::ValueObjectSP value_sp(GetSP());
370 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000371 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000372 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000373 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000374 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000375 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000376 success = value_sp->SetValueFromCString (value_str);
Greg Claytonb9dcc512011-06-29 18:28:50 +0000377 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000378 }
Chris Lattner24943d22010-06-08 16:52:24 +0000379 return success;
380}
381
Enrico Granatad760907c2012-02-17 03:18:30 +0000382lldb::SBTypeFormat
383SBValue::GetTypeFormat ()
384{
385 lldb::SBTypeFormat format;
386 lldb::ValueObjectSP value_sp(GetSP());
387 if (value_sp)
388 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000389 TargetSP target_sp(value_sp->GetTargetSP());
390 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000391 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000392 Mutex::Locker api_locker (target_sp->GetAPIMutex());
393 if (value_sp->UpdateValueIfNeeded(true))
394 {
395 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
396 if (format_sp)
397 format.SetSP(format_sp);
398 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000399 }
400 }
401 return format;
402}
403
Jason Molendac48ca822012-02-21 05:33:55 +0000404#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000405lldb::SBTypeSummary
406SBValue::GetTypeSummary ()
407{
408 lldb::SBTypeSummary summary;
409 lldb::ValueObjectSP value_sp(GetSP());
410 if (value_sp)
411 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000412 TargetSP target_sp(value_sp->GetTargetSP());
413 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000414 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000415 Mutex::Locker api_locker (target_sp->GetAPIMutex());
416 if (value_sp->UpdateValueIfNeeded(true))
417 {
418 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
419 if (summary_sp)
420 summary.SetSP(summary_sp);
421 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000422 }
423 }
424 return summary;
425}
Jason Molendac48ca822012-02-21 05:33:55 +0000426#endif // LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000427
428lldb::SBTypeFilter
429SBValue::GetTypeFilter ()
430{
431 lldb::SBTypeFilter filter;
432 lldb::ValueObjectSP value_sp(GetSP());
433 if (value_sp)
434 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000435 TargetSP target_sp(value_sp->GetTargetSP());
436 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000437 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000438 Mutex::Locker api_locker (target_sp->GetAPIMutex());
439 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granatad760907c2012-02-17 03:18:30 +0000440 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000441 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
442
443 if (synthetic_sp && !synthetic_sp->IsScripted())
444 {
445 TypeFilterImplSP filter_sp = std::tr1::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
446 filter.SetSP(filter_sp);
447 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000448 }
449 }
450 }
451 return filter;
452}
453
Jason Molendac48ca822012-02-21 05:33:55 +0000454#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000455lldb::SBTypeSynthetic
456SBValue::GetTypeSynthetic ()
457{
458 lldb::SBTypeSynthetic synthetic;
459 lldb::ValueObjectSP value_sp(GetSP());
460 if (value_sp)
461 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000462 TargetSP target_sp(value_sp->GetTargetSP());
463 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000464 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000465 Mutex::Locker api_locker (target_sp->GetAPIMutex());
466 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granatad760907c2012-02-17 03:18:30 +0000467 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000468 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
469
470 if (children_sp && children_sp->IsScripted())
471 {
472 TypeSyntheticImplSP synth_sp = std::tr1::static_pointer_cast<TypeSyntheticImpl>(children_sp);
473 synthetic.SetSP(synth_sp);
474 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000475 }
476 }
477 }
478 return synthetic;
479}
Jason Molendac48ca822012-02-21 05:33:55 +0000480#endif
Enrico Granatad760907c2012-02-17 03:18:30 +0000481
Enrico Granata979e20d2011-07-29 19:53:35 +0000482lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000483SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000484{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000485 lldb::SBValue sb_value;
486 lldb::ValueObjectSP value_sp(GetSP());
487 lldb::ValueObjectSP new_value_sp;
488 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000489 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000490 TypeImplSP type_sp (type.GetSP());
Enrico Granata979e20d2011-07-29 19:53:35 +0000491 if (type.IsValid())
492 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000493 sb_value = SBValue(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true));
494 new_value_sp = sb_value.GetSP();
495 if (new_value_sp)
496 new_value_sp->SetName(ConstString(name));
Enrico Granata979e20d2011-07-29 19:53:35 +0000497 }
498 }
499 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
500 if (log)
501 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000502 if (new_value_sp)
503 log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000504 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000505 log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000506 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000507 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000508}
509
510lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000511SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000512{
Greg Clayton4eb01a72012-01-31 04:25:15 +0000513 lldb::SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000514 lldb::ValueObjectSP value_sp(GetSP());
515 TypeImplSP type_sp (type.GetSP());
516 if (value_sp && type_sp)
517 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()));
Greg Clayton4eb01a72012-01-31 04:25:15 +0000518 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000519}
520
521lldb::SBValue
522SBValue::CreateValueFromExpression (const char *name, const char* expression)
523{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000524 lldb::SBValue sb_value;
525 lldb::ValueObjectSP value_sp(GetSP());
526 lldb::ValueObjectSP new_value_sp;
527 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000528 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000529 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
530 Target* target = exe_ctx.GetTargetPtr();
531 if (target)
Johnny Chen9fd2e382011-12-20 01:52:44 +0000532 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000533 target->EvaluateExpression (expression,
534 exe_ctx.GetFramePtr(),
535 eExecutionPolicyOnlyWhenNeeded,
536 false, // coerce to id
537 true, // unwind on error
538 true, // keep in memory
539 eNoDynamicValues,
540 new_value_sp);
541 if (new_value_sp)
542 {
543 new_value_sp->SetName(ConstString(name));
544 sb_value.SetSP(new_value_sp);
545 }
Johnny Chen9fd2e382011-12-20 01:52:44 +0000546 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000547 }
548 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
549 if (log)
550 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000551 if (new_value_sp)
552 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000553 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000554 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000555 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000556 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000557}
558
559lldb::SBValue
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000560SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000561{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000562 lldb::SBValue sb_value;
563 lldb::ValueObjectSP value_sp(GetSP());
564 lldb::ValueObjectSP new_value_sp;
565 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
566 if (value_sp && type_impl_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000567 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000568 ClangASTType pointee_ast_type(type_impl_sp->GetASTContext(), type_impl_sp->GetClangASTType().GetPointerType ());
569 lldb::TypeImplSP pointee_type_impl_sp (new TypeImpl(pointee_ast_type));
570 if (pointee_type_impl_sp)
Enrico Granatac9310302011-08-04 17:07:02 +0000571 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000572
573 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
574
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000575 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
576 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000577 pointee_type_impl_sp->GetASTContext(),
578 pointee_type_impl_sp->GetOpaqueQualType(),
579 ConstString(name),
580 buffer,
581 lldb::endian::InlHostByteOrder(),
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000582 exe_ctx.GetAddressByteSize()));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000583
584 if (ptr_result_valobj_sp)
585 {
586 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
587 Error err;
588 new_value_sp = ptr_result_valobj_sp->Dereference(err);
589 if (new_value_sp)
590 new_value_sp->SetName(ConstString(name));
591 }
592 sb_value.SetSP(new_value_sp);
Enrico Granatac9310302011-08-04 17:07:02 +0000593 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000594 }
595 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
596 if (log)
597 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000598 if (new_value_sp)
599 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000600 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000601 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
Johnny Chena713b862011-08-09 22:38:07 +0000602 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000603 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000604}
605
Enrico Granata91544802011-09-06 19:20:51 +0000606lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000607SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000608{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000609 lldb::SBValue sb_value;
610 lldb::ValueObjectSP new_value_sp;
611 lldb::ValueObjectSP value_sp(GetSP());
612 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +0000613 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000614 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
615
616 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000617 type.m_opaque_sp->GetASTContext() ,
618 type.m_opaque_sp->GetOpaqueQualType(),
619 ConstString(name),
620 *data.m_opaque_sp,
621 LLDB_INVALID_ADDRESS);
622 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
623 sb_value.SetSP(new_value_sp);
Enrico Granata91544802011-09-06 19:20:51 +0000624 }
625 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
626 if (log)
627 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000628 if (new_value_sp)
629 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000630 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000631 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +0000632 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000633 return sb_value;
Enrico Granata91544802011-09-06 19:20:51 +0000634}
635
Chris Lattner24943d22010-06-08 16:52:24 +0000636SBValue
637SBValue::GetChildAtIndex (uint32_t idx)
638{
Greg Clayton8f64c472011-07-15 19:31:49 +0000639 const bool can_create_synthetic = false;
640 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000641 lldb::ValueObjectSP value_sp(GetSP());
642 if (value_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000643 {
644 TargetSP target_sp(value_sp->GetTargetSP());
645 if (target_sp)
646 use_dynamic = target_sp->GetPreferDynamicValue();
647 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000648 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000649}
650
651SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000652SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000653{
Chris Lattner24943d22010-06-08 16:52:24 +0000654 lldb::ValueObjectSP child_sp;
655
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000656 lldb::ValueObjectSP value_sp(GetSP());
657 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000658 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000659 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000660 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000661 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000662 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton8f64c472011-07-15 19:31:49 +0000663 const bool can_create = true;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000664 child_sp = value_sp->GetChildAtIndex (idx, can_create);
Greg Clayton8f64c472011-07-15 19:31:49 +0000665 if (can_create_synthetic && !child_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000666 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000667 if (value_sp->IsPointerType())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000668 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000669 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
Greg Clayton8f64c472011-07-15 19:31:49 +0000670 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000671 else if (value_sp->IsArrayType())
Greg Clayton8f64c472011-07-15 19:31:49 +0000672 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000673 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
Greg Clayton8f64c472011-07-15 19:31:49 +0000674 }
675 }
676
677 if (child_sp)
678 {
679 if (use_dynamic != lldb::eNoDynamicValues)
680 {
681 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000682 if (dynamic_sp)
683 child_sp = dynamic_sp;
684 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000685 }
Jim Inghame41494a2011-04-16 00:01:13 +0000686 }
687 }
688
Chris Lattner24943d22010-06-08 16:52:24 +0000689 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000690 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000691 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000692 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000693
Chris Lattner24943d22010-06-08 16:52:24 +0000694 return sb_value;
695}
696
697uint32_t
698SBValue::GetIndexOfChildWithName (const char *name)
699{
Greg Clayton49ce6822010-10-31 03:01:06 +0000700 uint32_t idx = UINT32_MAX;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000701 lldb::ValueObjectSP value_sp(GetSP());
702 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000703 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000704 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000705 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000706 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000707 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000708
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000709 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000710 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000711 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000712 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000713 if (log)
714 {
715 if (idx == UINT32_MAX)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000716 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000717 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000718 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
Greg Clayton49ce6822010-10-31 03:01:06 +0000719 }
720 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000721}
722
723SBValue
724SBValue::GetChildMemberWithName (const char *name)
725{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000726 lldb::ValueObjectSP value_sp(GetSP());
727 if (value_sp)
Johnny Chen446ccaa2011-06-29 21:19:39 +0000728 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000729 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000730 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000731 if (target_sp)
732 {
733 Mutex::Locker api_locker (target_sp->GetAPIMutex());
734 use_dynamic_value = target_sp->GetPreferDynamicValue();
735 }
Johnny Chen446ccaa2011-06-29 21:19:39 +0000736 return GetChildMemberWithName (name, use_dynamic_value);
737 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000738 return SBValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000739}
740
741SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000742SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000743{
Chris Lattner24943d22010-06-08 16:52:24 +0000744 lldb::ValueObjectSP child_sp;
745 const ConstString str_name (name);
746
Greg Clayton905acaf2011-05-20 22:07:17 +0000747
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000748 lldb::ValueObjectSP value_sp(GetSP());
749 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000750 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000751 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000752 if (target_sp)
Jim Inghame41494a2011-04-16 00:01:13 +0000753 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000754 Mutex::Locker api_locker (target_sp->GetAPIMutex());
755 child_sp = value_sp->GetChildMemberWithName (str_name, true);
Greg Claytonb9dcc512011-06-29 18:28:50 +0000756 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000757 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000758 if (child_sp)
759 {
760 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
761 if (dynamic_sp)
762 child_sp = dynamic_sp;
763 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000764 }
Jim Inghame41494a2011-04-16 00:01:13 +0000765 }
766 }
767
Chris Lattner24943d22010-06-08 16:52:24 +0000768 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000769
Greg Claytone005f2c2010-11-06 01:53:30 +0000770 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000771 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000772 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000773
Chris Lattner24943d22010-06-08 16:52:24 +0000774 return sb_value;
775}
776
Enrico Granataf7a9b142011-07-15 02:26:42 +0000777lldb::SBValue
Jim Ingham1b425752011-12-08 19:44:08 +0000778SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
779{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000780 lldb::ValueObjectSP value_sp(GetSP());
781 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000782 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000783 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000784 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000785 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000786 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000787 return SBValue (value_sp->GetDynamicValue(use_dynamic));
Jim Ingham1b425752011-12-08 19:44:08 +0000788 }
789 }
790
791 return SBValue();
792}
793
794lldb::SBValue
795SBValue::GetStaticValue ()
796{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000797 lldb::ValueObjectSP value_sp(GetSP());
798 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000799 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000800 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000801 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000802 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000803 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000804 return SBValue(value_sp->GetStaticValue());
Jim Ingham1b425752011-12-08 19:44:08 +0000805 }
806 }
807
808 return SBValue();
809}
810
811bool
812SBValue::IsDynamic()
813{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000814 lldb::ValueObjectSP value_sp(GetSP());
815 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000816 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000817 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000818 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000819 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000820 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000821 return value_sp->IsDynamic();
Jim Ingham1b425752011-12-08 19:44:08 +0000822 }
823 }
824 return false;
825}
826
827lldb::SBValue
Enrico Granataf7a9b142011-07-15 02:26:42 +0000828SBValue::GetValueForExpressionPath(const char* expr_path)
829{
830 lldb::ValueObjectSP child_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000831 lldb::ValueObjectSP value_sp(GetSP());
832 if (value_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +0000833 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000834 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000835 if (target_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +0000836 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000837 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granataf7a9b142011-07-15 02:26:42 +0000838 // using default values for all the fancy options, just do it if you can
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000839 child_sp = value_sp->GetValueForExpressionPath(expr_path);
Enrico Granataf7a9b142011-07-15 02:26:42 +0000840 }
841 }
842
843 SBValue sb_value (child_sp);
844
845 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
846 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000847 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", value_sp.get(), expr_path, value_sp.get());
Enrico Granataf7a9b142011-07-15 02:26:42 +0000848
849 return sb_value;
850}
Chris Lattner24943d22010-06-08 16:52:24 +0000851
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000852int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +0000853SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
854{
Jim Ingham574c3d62011-08-12 23:34:31 +0000855 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000856 lldb::ValueObjectSP value_sp(GetSP());
857 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000858 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000859 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000860 if (target_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000861 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000862 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granatac92eb402011-08-04 01:41:02 +0000863 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000864 if (value_sp->ResolveValue (scalar))
Enrico Granatac92eb402011-08-04 01:41:02 +0000865 return scalar.GetRawBits64(fail_value);
866 else
867 error.SetErrorString("could not get value");
868 }
869 else
870 error.SetErrorString("could not get target");
871 }
872 error.SetErrorString("invalid SBValue");
873 return fail_value;
874}
875
876uint64_t
877SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
878{
Jim Ingham574c3d62011-08-12 23:34:31 +0000879 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000880 lldb::ValueObjectSP value_sp(GetSP());
881 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000882 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000883 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000884 if (target_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000885 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000886 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granatac92eb402011-08-04 01:41:02 +0000887 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000888 if (value_sp->ResolveValue (scalar))
Enrico Granatac92eb402011-08-04 01:41:02 +0000889 return scalar.GetRawBits64(fail_value);
890 else
891 error.SetErrorString("could not get value");
892 }
893 else
894 error.SetErrorString("could not get target");
895 }
896 error.SetErrorString("invalid SBValue");
897 return fail_value;
898}
899
900int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000901SBValue::GetValueAsSigned(int64_t fail_value)
902{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000903 lldb::ValueObjectSP value_sp(GetSP());
904 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000905 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000906 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000907 if (target_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000908 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000909 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000910 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000911 if (value_sp->ResolveValue (scalar))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000912 return scalar.GetRawBits64(fail_value);
913 }
914 }
915 return fail_value;
916}
917
918uint64_t
919SBValue::GetValueAsUnsigned(uint64_t fail_value)
920{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000921 lldb::ValueObjectSP value_sp(GetSP());
922 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000923 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000924 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000925 if (target_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000926 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000927 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000928 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000929 if (value_sp->ResolveValue (scalar))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000930 return scalar.GetRawBits64(fail_value);
931 }
932 }
933 return fail_value;
934}
935
Chris Lattner24943d22010-06-08 16:52:24 +0000936uint32_t
937SBValue::GetNumChildren ()
938{
939 uint32_t num_children = 0;
940
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000941 lldb::ValueObjectSP value_sp(GetSP());
942 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000943 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000944 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000945 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000946 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000947 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000948
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000949 num_children = value_sp->GetNumChildren();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000950 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000951 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000952
Greg Claytone005f2c2010-11-06 01:53:30 +0000953 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000954 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000955 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000956
957 return num_children;
958}
959
Chris Lattner24943d22010-06-08 16:52:24 +0000960
961SBValue
962SBValue::Dereference ()
963{
Greg Clayton49ce6822010-10-31 03:01:06 +0000964 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000965 lldb::ValueObjectSP value_sp(GetSP());
966 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000967 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000968 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000969 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000970 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000971 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000972
Greg Claytonb9dcc512011-06-29 18:28:50 +0000973 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000974 sb_value = value_sp->Dereference (error);
Greg Claytonb9dcc512011-06-29 18:28:50 +0000975 }
Chris Lattner24943d22010-06-08 16:52:24 +0000976 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000977 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000978 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000979 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000980
981 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000982}
983
984bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000985SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000986{
987 bool is_ptr_type = false;
988
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000989 lldb::ValueObjectSP value_sp(GetSP());
990 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000991 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000992 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000993 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000994 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000995 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000996
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000997 is_ptr_type = value_sp->IsPointerType();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000998 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000999 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001000
Greg Claytone005f2c2010-11-06 01:53:30 +00001001 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001002 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001003 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
Greg Clayton49ce6822010-10-31 03:01:06 +00001004
Chris Lattner24943d22010-06-08 16:52:24 +00001005
1006 return is_ptr_type;
1007}
1008
Chris Lattner24943d22010-06-08 16:52:24 +00001009void *
1010SBValue::GetOpaqueType()
1011{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001012 lldb::ValueObjectSP value_sp(GetSP());
1013 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001014 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001015 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001016 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001017 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001018 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001019
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001020 return value_sp->GetClangType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001021 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001022 }
Chris Lattner24943d22010-06-08 16:52:24 +00001023 return NULL;
1024}
1025
Enrico Granata979e20d2011-07-29 19:53:35 +00001026lldb::SBTarget
1027SBValue::GetTarget()
1028{
Greg Clayton334d33a2012-01-30 07:41:31 +00001029 SBTarget sb_target;
1030 TargetSP target_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001031 lldb::ValueObjectSP value_sp(GetSP());
1032 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001033 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001034 target_sp = value_sp->GetTargetSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001035 sb_target.SetSP (target_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001036 }
1037 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1038 if (log)
1039 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001040 if (target_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001041 log->Printf ("SBValue(%p)::GetTarget () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001042 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001043 log->Printf ("SBValue(%p)::GetTarget () => %p", value_sp.get(), target_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001044 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001045 return sb_target;
Enrico Granata979e20d2011-07-29 19:53:35 +00001046}
1047
1048lldb::SBProcess
1049SBValue::GetProcess()
1050{
Greg Clayton334d33a2012-01-30 07:41:31 +00001051 SBProcess sb_process;
1052 ProcessSP process_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001053 lldb::ValueObjectSP value_sp(GetSP());
1054 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001055 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001056 process_sp = value_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001057 if (process_sp)
1058 sb_process.SetSP (process_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001059 }
1060 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1061 if (log)
1062 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001063 if (process_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001064 log->Printf ("SBValue(%p)::GetProcess () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001065 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001066 log->Printf ("SBValue(%p)::GetProcess () => %p", value_sp.get(), process_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001067 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001068 return sb_process;
Enrico Granata979e20d2011-07-29 19:53:35 +00001069}
1070
1071lldb::SBThread
1072SBValue::GetThread()
1073{
Greg Clayton90c52142012-01-30 02:53:15 +00001074 SBThread sb_thread;
1075 ThreadSP thread_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001076 lldb::ValueObjectSP value_sp(GetSP());
1077 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001078 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001079 thread_sp = value_sp->GetThreadSP();
1080 sb_thread.SetThread(thread_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001081 }
1082 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1083 if (log)
1084 {
Greg Clayton90c52142012-01-30 02:53:15 +00001085 if (thread_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001086 log->Printf ("SBValue(%p)::GetThread () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001087 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001088 log->Printf ("SBValue(%p)::GetThread () => %p", value_sp.get(), thread_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001089 }
Greg Clayton90c52142012-01-30 02:53:15 +00001090 return sb_thread;
Enrico Granata979e20d2011-07-29 19:53:35 +00001091}
1092
1093lldb::SBFrame
1094SBValue::GetFrame()
1095{
Greg Clayton334d33a2012-01-30 07:41:31 +00001096 SBFrame sb_frame;
1097 StackFrameSP frame_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001098 lldb::ValueObjectSP value_sp(GetSP());
1099 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001100 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001101 frame_sp = value_sp->GetFrameSP();
1102 sb_frame.SetFrameSP (frame_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001103 }
1104 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1105 if (log)
1106 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001107 if (frame_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001108 log->Printf ("SBValue(%p)::GetFrame () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001109 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001110 log->Printf ("SBValue(%p)::GetFrame () => %p", value_sp.get(), frame_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001111 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001112 return sb_frame;
Enrico Granata979e20d2011-07-29 19:53:35 +00001113}
1114
1115
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001116lldb::ValueObjectSP
1117SBValue::GetSP () const
Chris Lattner24943d22010-06-08 16:52:24 +00001118{
Greg Clayton63094e02010-06-23 01:19:29 +00001119 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001120}
1121
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001122void
1123SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001124{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001125 m_opaque_sp = sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001126}
Caroline Tice98f930f2010-09-20 05:20:02 +00001127
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001128
Caroline Tice98f930f2010-09-20 05:20:02 +00001129bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001130SBValue::GetExpressionPath (SBStream &description)
1131{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001132 lldb::ValueObjectSP value_sp(GetSP());
1133 if (value_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +00001134 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001135 value_sp->GetExpressionPath (description.ref(), false);
Greg Claytonb01000f2011-01-17 03:46:26 +00001136 return true;
1137 }
1138 return false;
1139}
1140
1141bool
1142SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1143{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001144 lldb::ValueObjectSP value_sp(GetSP());
1145 if (value_sp)
Greg Claytonb01000f2011-01-17 03:46:26 +00001146 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001147 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +00001148 return true;
1149 }
1150 return false;
1151}
1152
1153bool
Caroline Tice98f930f2010-09-20 05:20:02 +00001154SBValue::GetDescription (SBStream &description)
1155{
Greg Clayton96154be2011-11-13 06:57:31 +00001156 Stream &strm = description.ref();
1157
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001158 lldb::ValueObjectSP value_sp(GetSP());
1159 if (value_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +00001160 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001161 ValueObject::DumpValueObject (strm, value_sp.get());
Caroline Tice98f930f2010-09-20 05:20:02 +00001162 }
1163 else
Greg Clayton96154be2011-11-13 06:57:31 +00001164 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +00001165
1166 return true;
1167}
Greg Claytone179a582011-01-05 18:43:15 +00001168
1169lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +00001170SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +00001171{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001172 lldb::ValueObjectSP value_sp(GetSP());
1173 if (value_sp)
1174 return value_sp->GetFormat();
Greg Claytone179a582011-01-05 18:43:15 +00001175 return eFormatDefault;
1176}
1177
1178void
1179SBValue::SetFormat (lldb::Format format)
1180{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001181 lldb::ValueObjectSP value_sp(GetSP());
1182 if (value_sp)
1183 value_sp->SetFormat(format);
Greg Claytone179a582011-01-05 18:43:15 +00001184}
1185
Enrico Granata979e20d2011-07-29 19:53:35 +00001186lldb::SBValue
1187SBValue::AddressOf()
1188{
1189 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001190 lldb::ValueObjectSP value_sp(GetSP());
1191 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001192 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001193 TargetSP target_sp (value_sp->GetTargetSP());
1194 if (target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001195 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001196 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001197 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001198 sb_value = value_sp->AddressOf (error);
Enrico Granata979e20d2011-07-29 19:53:35 +00001199 }
1200 }
1201 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1202 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001203 log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", value_sp.get(), value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001204
1205 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001206}
Enrico Granata91544802011-09-06 19:20:51 +00001207
1208lldb::addr_t
1209SBValue::GetLoadAddress()
1210{
1211 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001212 lldb::ValueObjectSP value_sp(GetSP());
1213 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001214 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001215 TargetSP target_sp (value_sp->GetTargetSP());
1216 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001217 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001218 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001219 const bool scalar_is_load_address = true;
1220 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001221 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001222 if (addr_type == eAddressTypeFile)
1223 {
Greg Clayton3508c382012-02-24 01:59:29 +00001224 ModuleSP module_sp (value_sp->GetModule());
1225 if (!module_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001226 value = LLDB_INVALID_ADDRESS;
1227 else
1228 {
1229 Address addr;
Greg Clayton3508c382012-02-24 01:59:29 +00001230 module_sp->ResolveFileAddress(value, addr);
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001231 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001232 }
1233 }
1234 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1235 value = LLDB_INVALID_ADDRESS;
1236 }
1237 }
1238 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1239 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001240 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", value_sp.get(), value);
Enrico Granata91544802011-09-06 19:20:51 +00001241
1242 return value;
1243}
1244
1245lldb::SBAddress
1246SBValue::GetAddress()
1247{
1248 Address addr;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001249 lldb::ValueObjectSP value_sp(GetSP());
1250 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001251 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001252 TargetSP target_sp (value_sp->GetTargetSP());
1253 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001254 {
1255 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001256 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001257 const bool scalar_is_load_address = true;
1258 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001259 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001260 if (addr_type == eAddressTypeFile)
1261 {
Greg Clayton3508c382012-02-24 01:59:29 +00001262 ModuleSP module_sp (value_sp->GetModule());
1263 if (module_sp)
1264 module_sp->ResolveFileAddress(value, addr);
Enrico Granata91544802011-09-06 19:20:51 +00001265 }
1266 else if (addr_type == eAddressTypeLoad)
1267 {
1268 // no need to check the return value on this.. if it can actually do the resolve
1269 // addr will be in the form (section,offset), otherwise it will simply be returned
1270 // as (NULL, value)
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001271 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001272 }
1273 }
1274 }
1275 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1276 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001277 log->Printf ("SBValue(%p)::GetAddress () => (%s,%llu)", value_sp.get(), (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"), addr.GetOffset());
Enrico Granata91544802011-09-06 19:20:51 +00001278 return SBAddress(new Address(addr));
1279}
1280
1281lldb::SBData
1282SBValue::GetPointeeData (uint32_t item_idx,
1283 uint32_t item_count)
1284{
1285 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001286 lldb::ValueObjectSP value_sp(GetSP());
1287 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001288 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001289 TargetSP target_sp (value_sp->GetTargetSP());
1290 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001291 {
1292 DataExtractorSP data_sp(new DataExtractor());
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001293 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001294 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
Enrico Granata91544802011-09-06 19:20:51 +00001295 if (data_sp->GetByteSize() > 0)
1296 *sb_data = data_sp;
1297 }
1298 }
1299 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1300 if (log)
1301 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001302 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001303 item_idx,
1304 item_count,
1305 sb_data.get());
1306
1307 return sb_data;
1308}
1309
1310lldb::SBData
1311SBValue::GetData ()
1312{
1313 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001314 lldb::ValueObjectSP value_sp(GetSP());
1315 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001316 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001317 TargetSP target_sp (value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001318 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001319 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001320 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001321 DataExtractorSP data_sp(new DataExtractor());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001322 value_sp->GetData(*data_sp);
Enrico Granata91544802011-09-06 19:20:51 +00001323 if (data_sp->GetByteSize() > 0)
1324 *sb_data = data_sp;
1325 }
1326 }
1327 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1328 if (log)
1329 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001330 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001331 sb_data.get());
1332
1333 return sb_data;
1334}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001335
1336lldb::SBWatchpoint
1337SBValue::Watch (bool resolve_location, bool read, bool write)
1338{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001339 SBWatchpoint sb_watchpoint;
1340
1341 // If the SBValue is not valid, there's no point in even trying to watch it.
1342 lldb::ValueObjectSP value_sp(GetSP());
1343 TargetSP target_sp (GetTarget().GetSP());
1344 if (value_sp && target_sp)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001345 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001346 // Read and Write cannot both be false.
1347 if (!read && !write)
1348 return sb_watchpoint;
1349
1350 // If the value is not in scope, don't try and watch and invalid value
1351 if (!IsInScope())
1352 return sb_watchpoint;
1353
1354 addr_t addr = GetLoadAddress();
1355 if (addr == LLDB_INVALID_ADDRESS)
1356 return sb_watchpoint;
1357 size_t byte_size = GetByteSize();
1358 if (byte_size == 0)
1359 return sb_watchpoint;
1360
1361 uint32_t watch_type = 0;
1362 if (read)
1363 watch_type |= LLDB_WATCH_TYPE_READ;
1364 if (write)
1365 watch_type |= LLDB_WATCH_TYPE_WRITE;
1366
1367 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type);
1368
1369 if (watchpoint_sp)
1370 {
1371 sb_watchpoint.SetSP (watchpoint_sp);
1372 Declaration decl;
1373 if (value_sp->GetDeclaration (decl))
1374 {
1375 if (decl.GetFile())
1376 {
1377 StreamString ss;
1378 // True to show fullpath for declaration file.
1379 decl.DumpStopContext(&ss, true);
1380 watchpoint_sp->SetDeclInfo(ss.GetString());
1381 }
1382 }
1383 }
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001384 }
1385 return sb_watchpoint;
1386}
1387
1388lldb::SBWatchpoint
1389SBValue::WatchPointee (bool resolve_location, bool read, bool write)
1390{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001391 SBWatchpoint sb_watchpoint;
1392 if (IsInScope() && GetType().IsPointerType())
1393 sb_watchpoint = Dereference().Watch (resolve_location, read, write);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001394 return sb_watchpoint;
1395}
1396