blob: b28004ccf70442781c3d5d1f8bce6cbd98b85a3f [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
Enrico Granatadba1de82012-03-27 02:35:13 +000054SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000055{
Enrico Granatadba1de82012-03-27 02:35:13 +000056 SetSP(value_sp); // whenever setting the SP call SetSP() since it knows how to deal with synthetic values properly
Chris Lattner24943d22010-06-08 16:52:24 +000057}
58
Enrico Granatadba1de82012-03-27 02:35:13 +000059SBValue::SBValue(const SBValue &rhs)
Greg Clayton538eb822010-11-05 23:17:00 +000060{
Enrico Granatadba1de82012-03-27 02:35:13 +000061 SetSP(rhs.m_opaque_sp); // whenever setting the SP call SetSP() since it knows how to deal with synthetic values properly
Greg Clayton538eb822010-11-05 23:17:00 +000062}
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)
Enrico Granatadba1de82012-03-27 02:35:13 +000068 {
69 SetSP(rhs.m_opaque_sp); // whenever setting the SP call SetSP() since it knows how to deal with synthetic values properly
70 }
Greg Clayton538eb822010-11-05 23:17:00 +000071 return *this;
72}
73
Chris Lattner24943d22010-06-08 16:52:24 +000074SBValue::~SBValue()
75{
76}
77
78bool
Greg Claytond68e0892011-09-09 23:04:00 +000079SBValue::IsValid ()
Chris Lattner24943d22010-06-08 16:52:24 +000080{
Greg Clayton49ce6822010-10-31 03:01:06 +000081 // If this function ever changes to anything that does more than just
82 // check if the opaque shared pointer is non NULL, then we need to update
83 // all "if (m_opaque_sp)" code in this file.
84 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000085}
86
Jim Inghame0bd5712011-12-19 20:39:44 +000087void
88SBValue::Clear()
89{
90 m_opaque_sp.reset();
91}
92
Greg Claytonc5f728c2010-10-06 22:10:17 +000093SBError
94SBValue::GetError()
95{
96 SBError sb_error;
97
Greg Clayton0a19a1b2012-02-04 02:27:34 +000098 lldb::ValueObjectSP value_sp(GetSP());
99 if (value_sp)
100 sb_error.SetError(value_sp->GetError());
Greg Clayton334d33a2012-01-30 07:41:31 +0000101 else
102 sb_error.SetErrorString("error: invalid value");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000103
104 return sb_error;
105}
106
Johnny Chen968958c2011-07-07 20:46:23 +0000107user_id_t
108SBValue::GetID()
109{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000110 lldb::ValueObjectSP value_sp(GetSP());
111 if (value_sp)
112 return value_sp->GetID();
Johnny Chen968958c2011-07-07 20:46:23 +0000113 return LLDB_INVALID_UID;
114}
115
Chris Lattner24943d22010-06-08 16:52:24 +0000116const char *
117SBValue::GetName()
118{
Greg Clayton49ce6822010-10-31 03:01:06 +0000119
120 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000121 lldb::ValueObjectSP value_sp(GetSP());
122 if (value_sp)
123 name = value_sp->GetName().GetCString();
Greg Clayton49ce6822010-10-31 03:01:06 +0000124
Greg Claytone005f2c2010-11-06 01:53:30 +0000125 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000126 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000127 {
128 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000129 log->Printf ("SBValue(%p)::GetName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000130 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000131 log->Printf ("SBValue(%p)::GetName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000132 }
Caroline Tice7826c882010-10-26 03:11:13 +0000133
Greg Clayton49ce6822010-10-31 03:01:06 +0000134 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000135}
136
137const char *
138SBValue::GetTypeName ()
139{
Greg Clayton49ce6822010-10-31 03:01:06 +0000140 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000141 lldb::ValueObjectSP value_sp(GetSP());
142 if (value_sp)
Greg Claytondc0a38c2012-03-26 23:03:23 +0000143 //name = value_sp->GetTypeName().GetCString();
144 name = value_sp->GetQualifiedTypeName().GetCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000145 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000146 if (log)
147 {
148 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000149 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000150 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000151 log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000152 }
153
154 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000155}
156
157size_t
158SBValue::GetByteSize ()
159{
160 size_t result = 0;
161
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000162 lldb::ValueObjectSP value_sp(GetSP());
163 if (value_sp)
164 result = value_sp->GetByteSize();
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)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000168 log->Printf ("SBValue(%p)::GetByteSize () => %zu", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000169
Chris Lattner24943d22010-06-08 16:52:24 +0000170 return result;
171}
172
173bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000174SBValue::IsInScope ()
175{
Chris Lattner24943d22010-06-08 16:52:24 +0000176 bool result = false;
177
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000178 lldb::ValueObjectSP value_sp(GetSP());
179 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000180 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000181 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000182 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000183 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000184 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000185 result = value_sp->IsInScope ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000186 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000187 }
Chris Lattner24943d22010-06-08 16:52:24 +0000188
Greg Claytone005f2c2010-11-06 01:53:30 +0000189 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000190 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000191 log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000192
Chris Lattner24943d22010-06-08 16:52:24 +0000193 return result;
194}
195
196const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000197SBValue::GetValue ()
198{
Greg Clayton49ce6822010-10-31 03:01:06 +0000199 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000200 lldb::ValueObjectSP value_sp(GetSP());
201 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000202 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000203 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000204 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000205 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000206 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000207 cstr = value_sp->GetValueAsCString ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000208 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000209 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000210 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000211 if (log)
212 {
213 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000214 log->Printf ("SBValue(%p)::GetValue => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000215 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000216 log->Printf ("SBValue(%p)::GetValue => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000217 }
218
219 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000220}
221
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000222ValueType
223SBValue::GetValueType ()
224{
Greg Clayton49ce6822010-10-31 03:01:06 +0000225 ValueType result = eValueTypeInvalid;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000226 lldb::ValueObjectSP value_sp(GetSP());
227 if (value_sp)
228 result = value_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000229 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000230 if (log)
231 {
232 switch (result)
233 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000234 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break;
235 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break;
236 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break;
237 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break;
238 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break;
239 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break;
240 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break;
241 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break;
242 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", value_sp.get(), result); break;
Greg Clayton49ce6822010-10-31 03:01:06 +0000243 }
244 }
245 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000246}
247
Jim Ingham4ae51962010-09-10 23:12:17 +0000248const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000249SBValue::GetObjectDescription ()
250{
Greg Clayton49ce6822010-10-31 03:01:06 +0000251 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000252 lldb::ValueObjectSP value_sp(GetSP());
253 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000254 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000255 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000256 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000257 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000258 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000259 cstr = value_sp->GetObjectDescription ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000260 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000261 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000262 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000263 if (log)
264 {
265 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000266 log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000267 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000268 log->Printf ("SBValue(%p)::GetObjectDescription => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000269 }
270 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000271}
272
Enrico Granata979e20d2011-07-29 19:53:35 +0000273SBType
274SBValue::GetType()
275{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000276 SBType sb_type;
277 lldb::ValueObjectSP value_sp(GetSP());
278 TypeImplSP type_sp;
279 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000280 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000281 type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType())));
282 sb_type.SetSP(type_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000283 }
284 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
285 if (log)
286 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000287 if (type_sp)
288 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000289 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000290 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000291 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000292 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000293}
294
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000295bool
296SBValue::GetValueDidChange ()
297{
Greg Clayton49ce6822010-10-31 03:01:06 +0000298 bool result = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000299 lldb::ValueObjectSP value_sp(GetSP());
300 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000301 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000302 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000303 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000304 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000305 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000306 result = value_sp->GetValueDidChange ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000307 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000308 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000309 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000310 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000311 log->Printf ("SBValue(%p)::GetValueDidChange => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000312
313 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000314}
315
Jason Molendac48ca822012-02-21 05:33:55 +0000316#ifndef LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000317const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000318SBValue::GetSummary ()
319{
Greg Clayton49ce6822010-10-31 03:01:06 +0000320 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000321 lldb::ValueObjectSP value_sp(GetSP());
322 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000323 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000324 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000325 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000326 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000327 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000328 cstr = value_sp->GetSummaryAsCString();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000329 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000330 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000331 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000332 if (log)
333 {
334 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000335 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000336 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000337 log->Printf ("SBValue(%p)::GetSummary => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000338 }
339 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000340}
Jason Molendac48ca822012-02-21 05:33:55 +0000341#endif // LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000342
343const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000344SBValue::GetLocation ()
345{
Greg Clayton49ce6822010-10-31 03:01:06 +0000346 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000347 lldb::ValueObjectSP value_sp(GetSP());
348 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000349 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000350 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000351 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000352 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000353 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000354 cstr = value_sp->GetLocationAsCString();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000355 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000356 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000357 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000358 if (log)
359 {
360 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000361 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000362 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000363 log->Printf ("SBValue(%p)::GetSummary => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000364 }
365 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000366}
367
368bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000369SBValue::SetValueFromCString (const char *value_str)
370{
Chris Lattner24943d22010-06-08 16:52:24 +0000371 bool success = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000372 lldb::ValueObjectSP value_sp(GetSP());
373 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000374 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000375 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000376 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000377 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000378 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000379 success = value_sp->SetValueFromCString (value_str);
Greg Claytonb9dcc512011-06-29 18:28:50 +0000380 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000381 }
Chris Lattner24943d22010-06-08 16:52:24 +0000382 return success;
383}
384
Enrico Granatad760907c2012-02-17 03:18:30 +0000385lldb::SBTypeFormat
386SBValue::GetTypeFormat ()
387{
388 lldb::SBTypeFormat format;
389 lldb::ValueObjectSP value_sp(GetSP());
390 if (value_sp)
391 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000392 TargetSP target_sp(value_sp->GetTargetSP());
393 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000394 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000395 Mutex::Locker api_locker (target_sp->GetAPIMutex());
396 if (value_sp->UpdateValueIfNeeded(true))
397 {
398 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
399 if (format_sp)
400 format.SetSP(format_sp);
401 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000402 }
403 }
404 return format;
405}
406
Jason Molendac48ca822012-02-21 05:33:55 +0000407#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000408lldb::SBTypeSummary
409SBValue::GetTypeSummary ()
410{
411 lldb::SBTypeSummary summary;
412 lldb::ValueObjectSP value_sp(GetSP());
413 if (value_sp)
414 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000415 TargetSP target_sp(value_sp->GetTargetSP());
416 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000417 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000418 Mutex::Locker api_locker (target_sp->GetAPIMutex());
419 if (value_sp->UpdateValueIfNeeded(true))
420 {
421 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
422 if (summary_sp)
423 summary.SetSP(summary_sp);
424 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000425 }
426 }
427 return summary;
428}
Jason Molendac48ca822012-02-21 05:33:55 +0000429#endif // LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000430
431lldb::SBTypeFilter
432SBValue::GetTypeFilter ()
433{
434 lldb::SBTypeFilter filter;
435 lldb::ValueObjectSP value_sp(GetSP());
436 if (value_sp)
437 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000438 TargetSP target_sp(value_sp->GetTargetSP());
439 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000440 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000441 Mutex::Locker api_locker (target_sp->GetAPIMutex());
442 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granatad760907c2012-02-17 03:18:30 +0000443 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000444 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
445
446 if (synthetic_sp && !synthetic_sp->IsScripted())
447 {
Greg Clayton598df882012-03-14 03:07:05 +0000448 TypeFilterImplSP filter_sp = STD_STATIC_POINTER_CAST(TypeFilterImpl,synthetic_sp);
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000449 filter.SetSP(filter_sp);
450 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000451 }
452 }
453 }
454 return filter;
455}
456
Jason Molendac48ca822012-02-21 05:33:55 +0000457#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000458lldb::SBTypeSynthetic
459SBValue::GetTypeSynthetic ()
460{
461 lldb::SBTypeSynthetic synthetic;
462 lldb::ValueObjectSP value_sp(GetSP());
463 if (value_sp)
464 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000465 TargetSP target_sp(value_sp->GetTargetSP());
466 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000467 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000468 Mutex::Locker api_locker (target_sp->GetAPIMutex());
469 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granatad760907c2012-02-17 03:18:30 +0000470 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000471 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
472
473 if (children_sp && children_sp->IsScripted())
474 {
Greg Clayton598df882012-03-14 03:07:05 +0000475 TypeSyntheticImplSP synth_sp = STD_STATIC_POINTER_CAST(TypeSyntheticImpl,children_sp);
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000476 synthetic.SetSP(synth_sp);
477 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000478 }
479 }
480 }
481 return synthetic;
482}
Jason Molendac48ca822012-02-21 05:33:55 +0000483#endif
Enrico Granatad760907c2012-02-17 03:18:30 +0000484
Enrico Granata979e20d2011-07-29 19:53:35 +0000485lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000486SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000487{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000488 lldb::SBValue sb_value;
489 lldb::ValueObjectSP value_sp(GetSP());
490 lldb::ValueObjectSP new_value_sp;
491 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000492 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000493 TypeImplSP type_sp (type.GetSP());
Enrico Granata979e20d2011-07-29 19:53:35 +0000494 if (type.IsValid())
495 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000496 sb_value = SBValue(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true));
497 new_value_sp = sb_value.GetSP();
498 if (new_value_sp)
499 new_value_sp->SetName(ConstString(name));
Enrico Granata979e20d2011-07-29 19:53:35 +0000500 }
501 }
502 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
503 if (log)
504 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000505 if (new_value_sp)
506 log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000507 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000508 log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000509 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000510 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000511}
512
513lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000514SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000515{
Greg Clayton4eb01a72012-01-31 04:25:15 +0000516 lldb::SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000517 lldb::ValueObjectSP value_sp(GetSP());
518 TypeImplSP type_sp (type.GetSP());
519 if (value_sp && type_sp)
520 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()));
Greg Clayton4eb01a72012-01-31 04:25:15 +0000521 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000522}
523
524lldb::SBValue
525SBValue::CreateValueFromExpression (const char *name, const char* expression)
526{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000527 lldb::SBValue sb_value;
528 lldb::ValueObjectSP value_sp(GetSP());
529 lldb::ValueObjectSP new_value_sp;
530 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000531 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000532 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
533 Target* target = exe_ctx.GetTargetPtr();
534 if (target)
Johnny Chen9fd2e382011-12-20 01:52:44 +0000535 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000536 target->EvaluateExpression (expression,
537 exe_ctx.GetFramePtr(),
538 eExecutionPolicyOnlyWhenNeeded,
539 false, // coerce to id
540 true, // unwind on error
541 true, // keep in memory
542 eNoDynamicValues,
543 new_value_sp);
544 if (new_value_sp)
545 {
546 new_value_sp->SetName(ConstString(name));
547 sb_value.SetSP(new_value_sp);
548 }
Johnny Chen9fd2e382011-12-20 01:52:44 +0000549 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000550 }
551 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
552 if (log)
553 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000554 if (new_value_sp)
555 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000556 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000557 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000558 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000559 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000560}
561
562lldb::SBValue
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000563SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000564{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000565 lldb::SBValue sb_value;
566 lldb::ValueObjectSP value_sp(GetSP());
567 lldb::ValueObjectSP new_value_sp;
568 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
569 if (value_sp && type_impl_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000570 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000571 ClangASTType pointee_ast_type(type_impl_sp->GetASTContext(), type_impl_sp->GetClangASTType().GetPointerType ());
572 lldb::TypeImplSP pointee_type_impl_sp (new TypeImpl(pointee_ast_type));
573 if (pointee_type_impl_sp)
Enrico Granatac9310302011-08-04 17:07:02 +0000574 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000575
576 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
577
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000578 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
579 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000580 pointee_type_impl_sp->GetASTContext(),
581 pointee_type_impl_sp->GetOpaqueQualType(),
582 ConstString(name),
583 buffer,
584 lldb::endian::InlHostByteOrder(),
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000585 exe_ctx.GetAddressByteSize()));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000586
587 if (ptr_result_valobj_sp)
588 {
589 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
590 Error err;
591 new_value_sp = ptr_result_valobj_sp->Dereference(err);
592 if (new_value_sp)
593 new_value_sp->SetName(ConstString(name));
594 }
595 sb_value.SetSP(new_value_sp);
Enrico Granatac9310302011-08-04 17:07:02 +0000596 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000597 }
598 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
599 if (log)
600 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000601 if (new_value_sp)
602 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000603 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000604 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
Johnny Chena713b862011-08-09 22:38:07 +0000605 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000606 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000607}
608
Enrico Granata91544802011-09-06 19:20:51 +0000609lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000610SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000611{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000612 lldb::SBValue sb_value;
613 lldb::ValueObjectSP new_value_sp;
614 lldb::ValueObjectSP value_sp(GetSP());
615 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +0000616 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000617 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
618
619 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000620 type.m_opaque_sp->GetASTContext() ,
621 type.m_opaque_sp->GetOpaqueQualType(),
622 ConstString(name),
623 *data.m_opaque_sp,
624 LLDB_INVALID_ADDRESS);
625 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
626 sb_value.SetSP(new_value_sp);
Enrico Granata91544802011-09-06 19:20:51 +0000627 }
628 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
629 if (log)
630 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000631 if (new_value_sp)
632 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000633 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000634 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +0000635 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000636 return sb_value;
Enrico Granata91544802011-09-06 19:20:51 +0000637}
638
Chris Lattner24943d22010-06-08 16:52:24 +0000639SBValue
640SBValue::GetChildAtIndex (uint32_t idx)
641{
Greg Clayton8f64c472011-07-15 19:31:49 +0000642 const bool can_create_synthetic = false;
643 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000644 lldb::ValueObjectSP value_sp(GetSP());
645 if (value_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000646 {
647 TargetSP target_sp(value_sp->GetTargetSP());
648 if (target_sp)
649 use_dynamic = target_sp->GetPreferDynamicValue();
650 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000651 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000652}
653
654SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000655SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000656{
Chris Lattner24943d22010-06-08 16:52:24 +0000657 lldb::ValueObjectSP child_sp;
658
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000659 lldb::ValueObjectSP value_sp(GetSP());
660 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000661 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000662 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000663 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000664 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000665 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton8f64c472011-07-15 19:31:49 +0000666 const bool can_create = true;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000667 child_sp = value_sp->GetChildAtIndex (idx, can_create);
Greg Clayton8f64c472011-07-15 19:31:49 +0000668 if (can_create_synthetic && !child_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000669 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000670 if (value_sp->IsPointerType())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000671 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000672 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
Greg Clayton8f64c472011-07-15 19:31:49 +0000673 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000674 else if (value_sp->IsArrayType())
Greg Clayton8f64c472011-07-15 19:31:49 +0000675 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000676 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
Greg Clayton8f64c472011-07-15 19:31:49 +0000677 }
678 }
679
680 if (child_sp)
681 {
682 if (use_dynamic != lldb::eNoDynamicValues)
683 {
684 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000685 if (dynamic_sp)
686 child_sp = dynamic_sp;
687 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000688 }
Jim Inghame41494a2011-04-16 00:01:13 +0000689 }
690 }
691
Chris Lattner24943d22010-06-08 16:52:24 +0000692 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000693 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000694 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000695 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000696
Chris Lattner24943d22010-06-08 16:52:24 +0000697 return sb_value;
698}
699
700uint32_t
701SBValue::GetIndexOfChildWithName (const char *name)
702{
Greg Clayton49ce6822010-10-31 03:01:06 +0000703 uint32_t idx = UINT32_MAX;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000704 lldb::ValueObjectSP value_sp(GetSP());
705 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000706 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000707 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000708 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000709 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000710 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000711
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000712 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000713 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000714 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000715 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000716 if (log)
717 {
718 if (idx == UINT32_MAX)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000719 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000720 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000721 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
Greg Clayton49ce6822010-10-31 03:01:06 +0000722 }
723 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000724}
725
726SBValue
727SBValue::GetChildMemberWithName (const char *name)
728{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000729 lldb::ValueObjectSP value_sp(GetSP());
730 if (value_sp)
Johnny Chen446ccaa2011-06-29 21:19:39 +0000731 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000732 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000733 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000734 if (target_sp)
735 {
736 Mutex::Locker api_locker (target_sp->GetAPIMutex());
737 use_dynamic_value = target_sp->GetPreferDynamicValue();
738 }
Johnny Chen446ccaa2011-06-29 21:19:39 +0000739 return GetChildMemberWithName (name, use_dynamic_value);
740 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000741 return SBValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000742}
743
744SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000745SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000746{
Chris Lattner24943d22010-06-08 16:52:24 +0000747 lldb::ValueObjectSP child_sp;
748 const ConstString str_name (name);
749
Greg Clayton905acaf2011-05-20 22:07:17 +0000750
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000751 lldb::ValueObjectSP value_sp(GetSP());
752 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000753 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000754 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000755 if (target_sp)
Jim Inghame41494a2011-04-16 00:01:13 +0000756 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000757 Mutex::Locker api_locker (target_sp->GetAPIMutex());
758 child_sp = value_sp->GetChildMemberWithName (str_name, true);
Greg Claytonb9dcc512011-06-29 18:28:50 +0000759 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000760 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000761 if (child_sp)
762 {
763 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
764 if (dynamic_sp)
765 child_sp = dynamic_sp;
766 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000767 }
Jim Inghame41494a2011-04-16 00:01:13 +0000768 }
769 }
770
Chris Lattner24943d22010-06-08 16:52:24 +0000771 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000772
Greg Claytone005f2c2010-11-06 01:53:30 +0000773 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000774 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000775 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000776
Chris Lattner24943d22010-06-08 16:52:24 +0000777 return sb_value;
778}
779
Enrico Granataf7a9b142011-07-15 02:26:42 +0000780lldb::SBValue
Jim Ingham1b425752011-12-08 19:44:08 +0000781SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
782{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000783 lldb::ValueObjectSP value_sp(GetSP());
784 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000785 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000786 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000787 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000788 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000789 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000790 return SBValue (value_sp->GetDynamicValue(use_dynamic));
Jim Ingham1b425752011-12-08 19:44:08 +0000791 }
792 }
793
794 return SBValue();
795}
796
797lldb::SBValue
798SBValue::GetStaticValue ()
799{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000800 lldb::ValueObjectSP value_sp(GetSP());
801 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000802 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000803 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000804 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000805 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000806 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000807 return SBValue(value_sp->GetStaticValue());
Jim Ingham1b425752011-12-08 19:44:08 +0000808 }
809 }
810
811 return SBValue();
812}
813
Enrico Granatadba1de82012-03-27 02:35:13 +0000814lldb::SBValue
815SBValue::GetNonSyntheticValue ()
816{
817 SBValue sb_value;
818 lldb::ValueObjectSP value_sp(GetSP());
819 if (value_sp)
820 {
821 if (value_sp->IsSynthetic())
822 {
823 TargetSP target_sp(value_sp->GetTargetSP());
824 if (target_sp)
825 {
826 Mutex::Locker api_locker (target_sp->GetAPIMutex());
827 // deliberately breaking the rules here to optimize the case where we DO NOT want
828 // the synthetic value to be returned to the user - if we did not do this, we would have to tell
829 // the target to suppress the synthetic value, and then return the flag to its original value
830 if (value_sp->GetParent())
831 sb_value.m_opaque_sp = value_sp->GetParent()->GetSP();
832 }
833 }
834 }
835 return sb_value;
836}
837
Jim Ingham1b425752011-12-08 19:44:08 +0000838bool
839SBValue::IsDynamic()
840{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000841 lldb::ValueObjectSP value_sp(GetSP());
842 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000843 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000844 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000845 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000846 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000847 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000848 return value_sp->IsDynamic();
Jim Ingham1b425752011-12-08 19:44:08 +0000849 }
850 }
851 return false;
852}
853
854lldb::SBValue
Enrico Granataf7a9b142011-07-15 02:26:42 +0000855SBValue::GetValueForExpressionPath(const char* expr_path)
856{
857 lldb::ValueObjectSP child_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000858 lldb::ValueObjectSP value_sp(GetSP());
859 if (value_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +0000860 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000861 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000862 if (target_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +0000863 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000864 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granataf7a9b142011-07-15 02:26:42 +0000865 // using default values for all the fancy options, just do it if you can
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000866 child_sp = value_sp->GetValueForExpressionPath(expr_path);
Enrico Granataf7a9b142011-07-15 02:26:42 +0000867 }
868 }
869
870 SBValue sb_value (child_sp);
871
872 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
873 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000874 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 +0000875
876 return sb_value;
877}
Chris Lattner24943d22010-06-08 16:52:24 +0000878
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000879int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +0000880SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
881{
Jim Ingham574c3d62011-08-12 23:34:31 +0000882 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000883 lldb::ValueObjectSP value_sp(GetSP());
884 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000885 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000886 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000887 if (target_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000888 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000889 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granatac92eb402011-08-04 01:41:02 +0000890 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000891 if (value_sp->ResolveValue (scalar))
Enrico Granatac92eb402011-08-04 01:41:02 +0000892 return scalar.GetRawBits64(fail_value);
893 else
894 error.SetErrorString("could not get value");
895 }
896 else
897 error.SetErrorString("could not get target");
898 }
899 error.SetErrorString("invalid SBValue");
900 return fail_value;
901}
902
903uint64_t
904SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
905{
Jim Ingham574c3d62011-08-12 23:34:31 +0000906 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000907 lldb::ValueObjectSP value_sp(GetSP());
908 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000909 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000910 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000911 if (target_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000912 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000913 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granatac92eb402011-08-04 01:41:02 +0000914 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000915 if (value_sp->ResolveValue (scalar))
Enrico Granatac92eb402011-08-04 01:41:02 +0000916 return scalar.GetRawBits64(fail_value);
917 else
918 error.SetErrorString("could not get value");
919 }
920 else
921 error.SetErrorString("could not get target");
922 }
923 error.SetErrorString("invalid SBValue");
924 return fail_value;
925}
926
927int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000928SBValue::GetValueAsSigned(int64_t fail_value)
929{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000930 lldb::ValueObjectSP value_sp(GetSP());
931 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000932 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000933 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000934 if (target_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000935 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000936 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000937 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000938 if (value_sp->ResolveValue (scalar))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000939 return scalar.GetRawBits64(fail_value);
940 }
941 }
942 return fail_value;
943}
944
945uint64_t
946SBValue::GetValueAsUnsigned(uint64_t fail_value)
947{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000948 lldb::ValueObjectSP value_sp(GetSP());
949 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000950 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000951 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000952 if (target_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000953 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000954 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000955 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000956 if (value_sp->ResolveValue (scalar))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000957 return scalar.GetRawBits64(fail_value);
958 }
959 }
960 return fail_value;
961}
962
Chris Lattner24943d22010-06-08 16:52:24 +0000963uint32_t
964SBValue::GetNumChildren ()
965{
966 uint32_t num_children = 0;
967
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000968 lldb::ValueObjectSP value_sp(GetSP());
969 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000970 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000971 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000972 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000973 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000974 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000975
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000976 num_children = value_sp->GetNumChildren();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000977 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000978 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000979
Greg Claytone005f2c2010-11-06 01:53:30 +0000980 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000981 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000982 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000983
984 return num_children;
985}
986
Chris Lattner24943d22010-06-08 16:52:24 +0000987
988SBValue
989SBValue::Dereference ()
990{
Greg Clayton49ce6822010-10-31 03:01:06 +0000991 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000992 lldb::ValueObjectSP value_sp(GetSP());
993 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000994 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000995 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000996 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000997 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000998 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000999
Greg Claytonb9dcc512011-06-29 18:28:50 +00001000 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001001 sb_value = value_sp->Dereference (error);
Greg Claytonb9dcc512011-06-29 18:28:50 +00001002 }
Chris Lattner24943d22010-06-08 16:52:24 +00001003 }
Greg Claytone005f2c2010-11-06 01:53:30 +00001004 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001005 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001006 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +00001007
1008 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +00001009}
1010
1011bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001012SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +00001013{
1014 bool is_ptr_type = false;
1015
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001016 lldb::ValueObjectSP value_sp(GetSP());
1017 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001018 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001019 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001020 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001021 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001022 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001023
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001024 is_ptr_type = value_sp->IsPointerType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001025 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001026 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001027
Greg Claytone005f2c2010-11-06 01:53:30 +00001028 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001029 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001030 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
Greg Clayton49ce6822010-10-31 03:01:06 +00001031
Chris Lattner24943d22010-06-08 16:52:24 +00001032
1033 return is_ptr_type;
1034}
1035
Chris Lattner24943d22010-06-08 16:52:24 +00001036void *
1037SBValue::GetOpaqueType()
1038{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001039 lldb::ValueObjectSP value_sp(GetSP());
1040 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001041 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001042 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001043 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001044 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001045 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001046
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001047 return value_sp->GetClangType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001048 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001049 }
Chris Lattner24943d22010-06-08 16:52:24 +00001050 return NULL;
1051}
1052
Enrico Granata979e20d2011-07-29 19:53:35 +00001053lldb::SBTarget
1054SBValue::GetTarget()
1055{
Greg Clayton334d33a2012-01-30 07:41:31 +00001056 SBTarget sb_target;
1057 TargetSP target_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001058 lldb::ValueObjectSP value_sp(GetSP());
1059 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001060 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001061 target_sp = value_sp->GetTargetSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001062 sb_target.SetSP (target_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001063 }
1064 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1065 if (log)
1066 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001067 if (target_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001068 log->Printf ("SBValue(%p)::GetTarget () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001069 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001070 log->Printf ("SBValue(%p)::GetTarget () => %p", value_sp.get(), target_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001071 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001072 return sb_target;
Enrico Granata979e20d2011-07-29 19:53:35 +00001073}
1074
1075lldb::SBProcess
1076SBValue::GetProcess()
1077{
Greg Clayton334d33a2012-01-30 07:41:31 +00001078 SBProcess sb_process;
1079 ProcessSP process_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001080 lldb::ValueObjectSP value_sp(GetSP());
1081 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001082 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001083 process_sp = value_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001084 if (process_sp)
1085 sb_process.SetSP (process_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001086 }
1087 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1088 if (log)
1089 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001090 if (process_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001091 log->Printf ("SBValue(%p)::GetProcess () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001092 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001093 log->Printf ("SBValue(%p)::GetProcess () => %p", value_sp.get(), process_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001094 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001095 return sb_process;
Enrico Granata979e20d2011-07-29 19:53:35 +00001096}
1097
1098lldb::SBThread
1099SBValue::GetThread()
1100{
Greg Clayton90c52142012-01-30 02:53:15 +00001101 SBThread sb_thread;
1102 ThreadSP thread_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001103 lldb::ValueObjectSP value_sp(GetSP());
1104 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001105 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001106 thread_sp = value_sp->GetThreadSP();
1107 sb_thread.SetThread(thread_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001108 }
1109 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1110 if (log)
1111 {
Greg Clayton90c52142012-01-30 02:53:15 +00001112 if (thread_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001113 log->Printf ("SBValue(%p)::GetThread () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001114 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001115 log->Printf ("SBValue(%p)::GetThread () => %p", value_sp.get(), thread_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001116 }
Greg Clayton90c52142012-01-30 02:53:15 +00001117 return sb_thread;
Enrico Granata979e20d2011-07-29 19:53:35 +00001118}
1119
1120lldb::SBFrame
1121SBValue::GetFrame()
1122{
Greg Clayton334d33a2012-01-30 07:41:31 +00001123 SBFrame sb_frame;
1124 StackFrameSP frame_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001125 lldb::ValueObjectSP value_sp(GetSP());
1126 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001127 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001128 frame_sp = value_sp->GetFrameSP();
1129 sb_frame.SetFrameSP (frame_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001130 }
1131 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1132 if (log)
1133 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001134 if (frame_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001135 log->Printf ("SBValue(%p)::GetFrame () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001136 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001137 log->Printf ("SBValue(%p)::GetFrame () => %p", value_sp.get(), frame_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001138 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001139 return sb_frame;
Enrico Granata979e20d2011-07-29 19:53:35 +00001140}
1141
1142
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001143lldb::ValueObjectSP
1144SBValue::GetSP () const
Chris Lattner24943d22010-06-08 16:52:24 +00001145{
Greg Clayton63094e02010-06-23 01:19:29 +00001146 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001147}
1148
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001149void
1150SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001151{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001152 m_opaque_sp = sp;
Enrico Granatadba1de82012-03-27 02:35:13 +00001153 if (IsValid() && m_opaque_sp->HasSyntheticValue())
1154 m_opaque_sp = m_opaque_sp->GetSyntheticValue();
Chris Lattner24943d22010-06-08 16:52:24 +00001155}
Caroline Tice98f930f2010-09-20 05:20:02 +00001156
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001157
Caroline Tice98f930f2010-09-20 05:20:02 +00001158bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001159SBValue::GetExpressionPath (SBStream &description)
1160{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001161 lldb::ValueObjectSP value_sp(GetSP());
1162 if (value_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +00001163 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001164 value_sp->GetExpressionPath (description.ref(), false);
Greg Claytonb01000f2011-01-17 03:46:26 +00001165 return true;
1166 }
1167 return false;
1168}
1169
1170bool
1171SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1172{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001173 lldb::ValueObjectSP value_sp(GetSP());
1174 if (value_sp)
Greg Claytonb01000f2011-01-17 03:46:26 +00001175 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001176 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +00001177 return true;
1178 }
1179 return false;
1180}
1181
1182bool
Caroline Tice98f930f2010-09-20 05:20:02 +00001183SBValue::GetDescription (SBStream &description)
1184{
Greg Clayton96154be2011-11-13 06:57:31 +00001185 Stream &strm = description.ref();
1186
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001187 lldb::ValueObjectSP value_sp(GetSP());
1188 if (value_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +00001189 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001190 ValueObject::DumpValueObject (strm, value_sp.get());
Caroline Tice98f930f2010-09-20 05:20:02 +00001191 }
1192 else
Greg Clayton96154be2011-11-13 06:57:31 +00001193 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +00001194
1195 return true;
1196}
Greg Claytone179a582011-01-05 18:43:15 +00001197
1198lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +00001199SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +00001200{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001201 lldb::ValueObjectSP value_sp(GetSP());
1202 if (value_sp)
1203 return value_sp->GetFormat();
Greg Claytone179a582011-01-05 18:43:15 +00001204 return eFormatDefault;
1205}
1206
1207void
1208SBValue::SetFormat (lldb::Format format)
1209{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001210 lldb::ValueObjectSP value_sp(GetSP());
1211 if (value_sp)
1212 value_sp->SetFormat(format);
Greg Claytone179a582011-01-05 18:43:15 +00001213}
1214
Enrico Granata979e20d2011-07-29 19:53:35 +00001215lldb::SBValue
1216SBValue::AddressOf()
1217{
1218 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001219 lldb::ValueObjectSP value_sp(GetSP());
1220 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001221 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001222 TargetSP target_sp (value_sp->GetTargetSP());
1223 if (target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001224 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001225 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001226 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001227 sb_value = value_sp->AddressOf (error);
Enrico Granata979e20d2011-07-29 19:53:35 +00001228 }
1229 }
1230 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1231 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001232 log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", value_sp.get(), value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001233
1234 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001235}
Enrico Granata91544802011-09-06 19:20:51 +00001236
1237lldb::addr_t
1238SBValue::GetLoadAddress()
1239{
1240 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001241 lldb::ValueObjectSP value_sp(GetSP());
1242 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001243 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001244 TargetSP target_sp (value_sp->GetTargetSP());
1245 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001246 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001247 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001248 const bool scalar_is_load_address = true;
1249 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001250 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001251 if (addr_type == eAddressTypeFile)
1252 {
Greg Clayton3508c382012-02-24 01:59:29 +00001253 ModuleSP module_sp (value_sp->GetModule());
1254 if (!module_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001255 value = LLDB_INVALID_ADDRESS;
1256 else
1257 {
1258 Address addr;
Greg Clayton3508c382012-02-24 01:59:29 +00001259 module_sp->ResolveFileAddress(value, addr);
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001260 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001261 }
1262 }
1263 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1264 value = LLDB_INVALID_ADDRESS;
1265 }
1266 }
1267 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1268 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001269 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", value_sp.get(), value);
Enrico Granata91544802011-09-06 19:20:51 +00001270
1271 return value;
1272}
1273
1274lldb::SBAddress
1275SBValue::GetAddress()
1276{
1277 Address addr;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001278 lldb::ValueObjectSP value_sp(GetSP());
1279 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001280 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001281 TargetSP target_sp (value_sp->GetTargetSP());
1282 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001283 {
1284 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001285 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001286 const bool scalar_is_load_address = true;
1287 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001288 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001289 if (addr_type == eAddressTypeFile)
1290 {
Greg Clayton3508c382012-02-24 01:59:29 +00001291 ModuleSP module_sp (value_sp->GetModule());
1292 if (module_sp)
1293 module_sp->ResolveFileAddress(value, addr);
Enrico Granata91544802011-09-06 19:20:51 +00001294 }
1295 else if (addr_type == eAddressTypeLoad)
1296 {
1297 // no need to check the return value on this.. if it can actually do the resolve
1298 // addr will be in the form (section,offset), otherwise it will simply be returned
1299 // as (NULL, value)
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001300 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001301 }
1302 }
1303 }
1304 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1305 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001306 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 +00001307 return SBAddress(new Address(addr));
1308}
1309
1310lldb::SBData
1311SBValue::GetPointeeData (uint32_t item_idx,
1312 uint32_t item_count)
1313{
1314 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001315 lldb::ValueObjectSP value_sp(GetSP());
1316 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001317 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001318 TargetSP target_sp (value_sp->GetTargetSP());
1319 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001320 {
1321 DataExtractorSP data_sp(new DataExtractor());
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001322 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001323 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
Enrico Granata91544802011-09-06 19:20:51 +00001324 if (data_sp->GetByteSize() > 0)
1325 *sb_data = data_sp;
1326 }
1327 }
1328 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1329 if (log)
1330 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001331 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001332 item_idx,
1333 item_count,
1334 sb_data.get());
1335
1336 return sb_data;
1337}
1338
1339lldb::SBData
1340SBValue::GetData ()
1341{
1342 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001343 lldb::ValueObjectSP value_sp(GetSP());
1344 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001345 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001346 TargetSP target_sp (value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001347 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001348 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001349 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001350 DataExtractorSP data_sp(new DataExtractor());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001351 value_sp->GetData(*data_sp);
Enrico Granata91544802011-09-06 19:20:51 +00001352 if (data_sp->GetByteSize() > 0)
1353 *sb_data = data_sp;
1354 }
1355 }
1356 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1357 if (log)
1358 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001359 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001360 sb_data.get());
1361
1362 return sb_data;
1363}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001364
1365lldb::SBWatchpoint
1366SBValue::Watch (bool resolve_location, bool read, bool write)
1367{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001368 SBWatchpoint sb_watchpoint;
1369
1370 // If the SBValue is not valid, there's no point in even trying to watch it.
1371 lldb::ValueObjectSP value_sp(GetSP());
1372 TargetSP target_sp (GetTarget().GetSP());
1373 if (value_sp && target_sp)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001374 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001375 // Read and Write cannot both be false.
1376 if (!read && !write)
1377 return sb_watchpoint;
1378
1379 // If the value is not in scope, don't try and watch and invalid value
1380 if (!IsInScope())
1381 return sb_watchpoint;
1382
1383 addr_t addr = GetLoadAddress();
1384 if (addr == LLDB_INVALID_ADDRESS)
1385 return sb_watchpoint;
1386 size_t byte_size = GetByteSize();
1387 if (byte_size == 0)
1388 return sb_watchpoint;
1389
1390 uint32_t watch_type = 0;
1391 if (read)
1392 watch_type |= LLDB_WATCH_TYPE_READ;
1393 if (write)
1394 watch_type |= LLDB_WATCH_TYPE_WRITE;
1395
1396 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type);
1397
1398 if (watchpoint_sp)
1399 {
1400 sb_watchpoint.SetSP (watchpoint_sp);
1401 Declaration decl;
1402 if (value_sp->GetDeclaration (decl))
1403 {
1404 if (decl.GetFile())
1405 {
1406 StreamString ss;
1407 // True to show fullpath for declaration file.
1408 decl.DumpStopContext(&ss, true);
1409 watchpoint_sp->SetDeclInfo(ss.GetString());
1410 }
1411 }
1412 }
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001413 }
1414 return sb_watchpoint;
1415}
1416
1417lldb::SBWatchpoint
1418SBValue::WatchPointee (bool resolve_location, bool read, bool write)
1419{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001420 SBWatchpoint sb_watchpoint;
1421 if (IsInScope() && GetType().IsPointerType())
1422 sb_watchpoint = Dereference().Watch (resolve_location, read, write);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001423 return sb_watchpoint;
1424}
1425