blob: c5a5fd27294c52354d8a908ee1e0eae09a1402d0 [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)
Greg Claytondc0a38c2012-03-26 23:03:23 +0000141 //name = value_sp->GetTypeName().GetCString();
142 name = value_sp->GetQualifiedTypeName().GetCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000143 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000144 if (log)
145 {
146 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000147 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000148 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000149 log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000150 }
151
152 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000153}
154
155size_t
156SBValue::GetByteSize ()
157{
158 size_t result = 0;
159
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000160 lldb::ValueObjectSP value_sp(GetSP());
161 if (value_sp)
162 result = value_sp->GetByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000163
Greg Claytone005f2c2010-11-06 01:53:30 +0000164 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000165 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000166 log->Printf ("SBValue(%p)::GetByteSize () => %zu", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000167
Chris Lattner24943d22010-06-08 16:52:24 +0000168 return result;
169}
170
171bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000172SBValue::IsInScope ()
173{
Chris Lattner24943d22010-06-08 16:52:24 +0000174 bool result = false;
175
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000176 lldb::ValueObjectSP value_sp(GetSP());
177 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000178 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000179 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000180 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000181 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000182 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000183 result = value_sp->IsInScope ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000184 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000185 }
Chris Lattner24943d22010-06-08 16:52:24 +0000186
Greg Claytone005f2c2010-11-06 01:53:30 +0000187 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000188 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000189 log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000190
Chris Lattner24943d22010-06-08 16:52:24 +0000191 return result;
192}
193
194const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000195SBValue::GetValue ()
196{
Greg Clayton49ce6822010-10-31 03:01:06 +0000197 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000198 lldb::ValueObjectSP value_sp(GetSP());
199 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000200 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000201 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000202 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000203 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000204 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000205 cstr = value_sp->GetValueAsCString ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000206 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000207 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000208 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000209 if (log)
210 {
211 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000212 log->Printf ("SBValue(%p)::GetValue => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000213 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000214 log->Printf ("SBValue(%p)::GetValue => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000215 }
216
217 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000218}
219
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000220ValueType
221SBValue::GetValueType ()
222{
Greg Clayton49ce6822010-10-31 03:01:06 +0000223 ValueType result = eValueTypeInvalid;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000224 lldb::ValueObjectSP value_sp(GetSP());
225 if (value_sp)
226 result = value_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000227 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000228 if (log)
229 {
230 switch (result)
231 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000232 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break;
233 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break;
234 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break;
235 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break;
236 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break;
237 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break;
238 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break;
239 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break;
240 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", value_sp.get(), result); break;
Greg Clayton49ce6822010-10-31 03:01:06 +0000241 }
242 }
243 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000244}
245
Jim Ingham4ae51962010-09-10 23:12:17 +0000246const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000247SBValue::GetObjectDescription ()
248{
Greg Clayton49ce6822010-10-31 03:01:06 +0000249 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000250 lldb::ValueObjectSP value_sp(GetSP());
251 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000252 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000253 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000254 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000255 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000256 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000257 cstr = value_sp->GetObjectDescription ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000258 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000259 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000260 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000261 if (log)
262 {
263 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000264 log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000265 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000266 log->Printf ("SBValue(%p)::GetObjectDescription => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000267 }
268 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000269}
270
Enrico Granata979e20d2011-07-29 19:53:35 +0000271SBType
272SBValue::GetType()
273{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000274 SBType sb_type;
275 lldb::ValueObjectSP value_sp(GetSP());
276 TypeImplSP type_sp;
277 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000278 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000279 type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType())));
280 sb_type.SetSP(type_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000281 }
282 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
283 if (log)
284 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000285 if (type_sp)
286 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000287 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000288 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000289 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000290 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000291}
292
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000293bool
294SBValue::GetValueDidChange ()
295{
Greg Clayton49ce6822010-10-31 03:01:06 +0000296 bool result = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000297 lldb::ValueObjectSP value_sp(GetSP());
298 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000299 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000300 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000301 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000302 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000303 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000304 result = value_sp->GetValueDidChange ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000305 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000306 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000307 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000308 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000309 log->Printf ("SBValue(%p)::GetValueDidChange => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000310
311 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000312}
313
Jason Molendac48ca822012-02-21 05:33:55 +0000314#ifndef LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000315const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000316SBValue::GetSummary ()
317{
Greg Clayton49ce6822010-10-31 03:01:06 +0000318 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000319 lldb::ValueObjectSP value_sp(GetSP());
320 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000321 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000322 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000323 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000324 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000325 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000326 cstr = value_sp->GetSummaryAsCString();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000327 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000328 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000329 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000330 if (log)
331 {
332 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000333 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000334 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000335 log->Printf ("SBValue(%p)::GetSummary => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000336 }
337 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000338}
Jason Molendac48ca822012-02-21 05:33:55 +0000339#endif // LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000340
341const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000342SBValue::GetLocation ()
343{
Greg Clayton49ce6822010-10-31 03:01:06 +0000344 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000345 lldb::ValueObjectSP value_sp(GetSP());
346 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000347 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000348 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000349 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000350 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000351 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000352 cstr = value_sp->GetLocationAsCString();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000353 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000354 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000355 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000356 if (log)
357 {
358 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000359 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000360 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000361 log->Printf ("SBValue(%p)::GetSummary => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000362 }
363 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000364}
365
366bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000367SBValue::SetValueFromCString (const char *value_str)
368{
Chris Lattner24943d22010-06-08 16:52:24 +0000369 bool success = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000370 lldb::ValueObjectSP value_sp(GetSP());
371 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000372 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000373 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000374 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000375 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000376 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000377 success = value_sp->SetValueFromCString (value_str);
Greg Claytonb9dcc512011-06-29 18:28:50 +0000378 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000379 }
Chris Lattner24943d22010-06-08 16:52:24 +0000380 return success;
381}
382
Enrico Granatad760907c2012-02-17 03:18:30 +0000383lldb::SBTypeFormat
384SBValue::GetTypeFormat ()
385{
386 lldb::SBTypeFormat format;
387 lldb::ValueObjectSP value_sp(GetSP());
388 if (value_sp)
389 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000390 TargetSP target_sp(value_sp->GetTargetSP());
391 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000392 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000393 Mutex::Locker api_locker (target_sp->GetAPIMutex());
394 if (value_sp->UpdateValueIfNeeded(true))
395 {
396 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
397 if (format_sp)
398 format.SetSP(format_sp);
399 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000400 }
401 }
402 return format;
403}
404
Jason Molendac48ca822012-02-21 05:33:55 +0000405#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000406lldb::SBTypeSummary
407SBValue::GetTypeSummary ()
408{
409 lldb::SBTypeSummary summary;
410 lldb::ValueObjectSP value_sp(GetSP());
411 if (value_sp)
412 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000413 TargetSP target_sp(value_sp->GetTargetSP());
414 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000415 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000416 Mutex::Locker api_locker (target_sp->GetAPIMutex());
417 if (value_sp->UpdateValueIfNeeded(true))
418 {
419 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
420 if (summary_sp)
421 summary.SetSP(summary_sp);
422 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000423 }
424 }
425 return summary;
426}
Jason Molendac48ca822012-02-21 05:33:55 +0000427#endif // LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000428
429lldb::SBTypeFilter
430SBValue::GetTypeFilter ()
431{
432 lldb::SBTypeFilter filter;
433 lldb::ValueObjectSP value_sp(GetSP());
434 if (value_sp)
435 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000436 TargetSP target_sp(value_sp->GetTargetSP());
437 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000438 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000439 Mutex::Locker api_locker (target_sp->GetAPIMutex());
440 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granatad760907c2012-02-17 03:18:30 +0000441 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000442 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
443
444 if (synthetic_sp && !synthetic_sp->IsScripted())
445 {
Greg Clayton598df882012-03-14 03:07:05 +0000446 TypeFilterImplSP filter_sp = STD_STATIC_POINTER_CAST(TypeFilterImpl,synthetic_sp);
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000447 filter.SetSP(filter_sp);
448 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000449 }
450 }
451 }
452 return filter;
453}
454
Jason Molendac48ca822012-02-21 05:33:55 +0000455#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000456lldb::SBTypeSynthetic
457SBValue::GetTypeSynthetic ()
458{
459 lldb::SBTypeSynthetic synthetic;
460 lldb::ValueObjectSP value_sp(GetSP());
461 if (value_sp)
462 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000463 TargetSP target_sp(value_sp->GetTargetSP());
464 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000465 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000466 Mutex::Locker api_locker (target_sp->GetAPIMutex());
467 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granatad760907c2012-02-17 03:18:30 +0000468 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000469 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
470
471 if (children_sp && children_sp->IsScripted())
472 {
Greg Clayton598df882012-03-14 03:07:05 +0000473 TypeSyntheticImplSP synth_sp = STD_STATIC_POINTER_CAST(TypeSyntheticImpl,children_sp);
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000474 synthetic.SetSP(synth_sp);
475 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000476 }
477 }
478 }
479 return synthetic;
480}
Jason Molendac48ca822012-02-21 05:33:55 +0000481#endif
Enrico Granatad760907c2012-02-17 03:18:30 +0000482
Enrico Granata979e20d2011-07-29 19:53:35 +0000483lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000484SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000485{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000486 lldb::SBValue sb_value;
487 lldb::ValueObjectSP value_sp(GetSP());
488 lldb::ValueObjectSP new_value_sp;
489 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000490 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000491 TypeImplSP type_sp (type.GetSP());
Enrico Granata979e20d2011-07-29 19:53:35 +0000492 if (type.IsValid())
493 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000494 sb_value = SBValue(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true));
495 new_value_sp = sb_value.GetSP();
496 if (new_value_sp)
497 new_value_sp->SetName(ConstString(name));
Enrico Granata979e20d2011-07-29 19:53:35 +0000498 }
499 }
500 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
501 if (log)
502 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000503 if (new_value_sp)
504 log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000505 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000506 log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000507 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000508 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000509}
510
511lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000512SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000513{
Greg Clayton4eb01a72012-01-31 04:25:15 +0000514 lldb::SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000515 lldb::ValueObjectSP value_sp(GetSP());
516 TypeImplSP type_sp (type.GetSP());
517 if (value_sp && type_sp)
518 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()));
Greg Clayton4eb01a72012-01-31 04:25:15 +0000519 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000520}
521
522lldb::SBValue
523SBValue::CreateValueFromExpression (const char *name, const char* expression)
524{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000525 lldb::SBValue sb_value;
526 lldb::ValueObjectSP value_sp(GetSP());
527 lldb::ValueObjectSP new_value_sp;
528 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000529 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000530 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
531 Target* target = exe_ctx.GetTargetPtr();
532 if (target)
Johnny Chen9fd2e382011-12-20 01:52:44 +0000533 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000534 target->EvaluateExpression (expression,
535 exe_ctx.GetFramePtr(),
536 eExecutionPolicyOnlyWhenNeeded,
537 false, // coerce to id
538 true, // unwind on error
539 true, // keep in memory
540 eNoDynamicValues,
541 new_value_sp);
542 if (new_value_sp)
543 {
544 new_value_sp->SetName(ConstString(name));
545 sb_value.SetSP(new_value_sp);
546 }
Johnny Chen9fd2e382011-12-20 01:52:44 +0000547 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000548 }
549 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
550 if (log)
551 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000552 if (new_value_sp)
553 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000554 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000555 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000556 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000557 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000558}
559
560lldb::SBValue
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000561SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000562{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000563 lldb::SBValue sb_value;
564 lldb::ValueObjectSP value_sp(GetSP());
565 lldb::ValueObjectSP new_value_sp;
566 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
567 if (value_sp && type_impl_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000568 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000569 ClangASTType pointee_ast_type(type_impl_sp->GetASTContext(), type_impl_sp->GetClangASTType().GetPointerType ());
570 lldb::TypeImplSP pointee_type_impl_sp (new TypeImpl(pointee_ast_type));
571 if (pointee_type_impl_sp)
Enrico Granatac9310302011-08-04 17:07:02 +0000572 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000573
574 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
575
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000576 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
577 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000578 pointee_type_impl_sp->GetASTContext(),
579 pointee_type_impl_sp->GetOpaqueQualType(),
580 ConstString(name),
581 buffer,
582 lldb::endian::InlHostByteOrder(),
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000583 exe_ctx.GetAddressByteSize()));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000584
585 if (ptr_result_valobj_sp)
586 {
587 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
588 Error err;
589 new_value_sp = ptr_result_valobj_sp->Dereference(err);
590 if (new_value_sp)
591 new_value_sp->SetName(ConstString(name));
592 }
593 sb_value.SetSP(new_value_sp);
Enrico Granatac9310302011-08-04 17:07:02 +0000594 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000595 }
596 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
597 if (log)
598 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000599 if (new_value_sp)
600 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000601 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000602 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
Johnny Chena713b862011-08-09 22:38:07 +0000603 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000604 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000605}
606
Enrico Granata91544802011-09-06 19:20:51 +0000607lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000608SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000609{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000610 lldb::SBValue sb_value;
611 lldb::ValueObjectSP new_value_sp;
612 lldb::ValueObjectSP value_sp(GetSP());
613 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +0000614 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000615 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
616
617 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000618 type.m_opaque_sp->GetASTContext() ,
619 type.m_opaque_sp->GetOpaqueQualType(),
620 ConstString(name),
621 *data.m_opaque_sp,
622 LLDB_INVALID_ADDRESS);
623 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
624 sb_value.SetSP(new_value_sp);
Enrico Granata91544802011-09-06 19:20:51 +0000625 }
626 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
627 if (log)
628 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000629 if (new_value_sp)
630 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000631 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000632 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +0000633 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000634 return sb_value;
Enrico Granata91544802011-09-06 19:20:51 +0000635}
636
Chris Lattner24943d22010-06-08 16:52:24 +0000637SBValue
638SBValue::GetChildAtIndex (uint32_t idx)
639{
Greg Clayton8f64c472011-07-15 19:31:49 +0000640 const bool can_create_synthetic = false;
641 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000642 lldb::ValueObjectSP value_sp(GetSP());
643 if (value_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000644 {
645 TargetSP target_sp(value_sp->GetTargetSP());
646 if (target_sp)
647 use_dynamic = target_sp->GetPreferDynamicValue();
648 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000649 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000650}
651
652SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000653SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000654{
Chris Lattner24943d22010-06-08 16:52:24 +0000655 lldb::ValueObjectSP child_sp;
656
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000657 lldb::ValueObjectSP value_sp(GetSP());
658 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000659 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000660 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000661 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000662 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000663 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton8f64c472011-07-15 19:31:49 +0000664 const bool can_create = true;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000665 child_sp = value_sp->GetChildAtIndex (idx, can_create);
Greg Clayton8f64c472011-07-15 19:31:49 +0000666 if (can_create_synthetic && !child_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000667 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000668 if (value_sp->IsPointerType())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000669 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000670 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
Greg Clayton8f64c472011-07-15 19:31:49 +0000671 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000672 else if (value_sp->IsArrayType())
Greg Clayton8f64c472011-07-15 19:31:49 +0000673 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000674 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
Greg Clayton8f64c472011-07-15 19:31:49 +0000675 }
676 }
677
678 if (child_sp)
679 {
680 if (use_dynamic != lldb::eNoDynamicValues)
681 {
682 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000683 if (dynamic_sp)
684 child_sp = dynamic_sp;
685 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000686 }
Jim Inghame41494a2011-04-16 00:01:13 +0000687 }
688 }
689
Chris Lattner24943d22010-06-08 16:52:24 +0000690 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000691 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000692 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000693 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000694
Chris Lattner24943d22010-06-08 16:52:24 +0000695 return sb_value;
696}
697
698uint32_t
699SBValue::GetIndexOfChildWithName (const char *name)
700{
Greg Clayton49ce6822010-10-31 03:01:06 +0000701 uint32_t idx = UINT32_MAX;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000702 lldb::ValueObjectSP value_sp(GetSP());
703 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000704 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000705 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000706 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000707 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000708 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000709
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000710 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000711 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000712 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000713 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000714 if (log)
715 {
716 if (idx == UINT32_MAX)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000717 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000718 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000719 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
Greg Clayton49ce6822010-10-31 03:01:06 +0000720 }
721 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000722}
723
724SBValue
725SBValue::GetChildMemberWithName (const char *name)
726{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000727 lldb::ValueObjectSP value_sp(GetSP());
728 if (value_sp)
Johnny Chen446ccaa2011-06-29 21:19:39 +0000729 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000730 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000731 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000732 if (target_sp)
733 {
734 Mutex::Locker api_locker (target_sp->GetAPIMutex());
735 use_dynamic_value = target_sp->GetPreferDynamicValue();
736 }
Johnny Chen446ccaa2011-06-29 21:19:39 +0000737 return GetChildMemberWithName (name, use_dynamic_value);
738 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000739 return SBValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000740}
741
742SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000743SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000744{
Chris Lattner24943d22010-06-08 16:52:24 +0000745 lldb::ValueObjectSP child_sp;
746 const ConstString str_name (name);
747
Greg Clayton905acaf2011-05-20 22:07:17 +0000748
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000749 lldb::ValueObjectSP value_sp(GetSP());
750 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000751 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000752 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000753 if (target_sp)
Jim Inghame41494a2011-04-16 00:01:13 +0000754 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000755 Mutex::Locker api_locker (target_sp->GetAPIMutex());
756 child_sp = value_sp->GetChildMemberWithName (str_name, true);
Greg Claytonb9dcc512011-06-29 18:28:50 +0000757 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000758 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000759 if (child_sp)
760 {
761 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
762 if (dynamic_sp)
763 child_sp = dynamic_sp;
764 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000765 }
Jim Inghame41494a2011-04-16 00:01:13 +0000766 }
767 }
768
Chris Lattner24943d22010-06-08 16:52:24 +0000769 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000770
Greg Claytone005f2c2010-11-06 01:53:30 +0000771 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000772 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000773 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000774
Chris Lattner24943d22010-06-08 16:52:24 +0000775 return sb_value;
776}
777
Enrico Granataf7a9b142011-07-15 02:26:42 +0000778lldb::SBValue
Jim Ingham1b425752011-12-08 19:44:08 +0000779SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
780{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000781 lldb::ValueObjectSP value_sp(GetSP());
782 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000783 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000784 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000785 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000786 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000787 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000788 return SBValue (value_sp->GetDynamicValue(use_dynamic));
Jim Ingham1b425752011-12-08 19:44:08 +0000789 }
790 }
791
792 return SBValue();
793}
794
795lldb::SBValue
796SBValue::GetStaticValue ()
797{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000798 lldb::ValueObjectSP value_sp(GetSP());
799 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000800 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000801 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000802 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000803 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000804 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000805 return SBValue(value_sp->GetStaticValue());
Jim Ingham1b425752011-12-08 19:44:08 +0000806 }
807 }
808
809 return SBValue();
810}
811
812bool
813SBValue::IsDynamic()
814{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000815 lldb::ValueObjectSP value_sp(GetSP());
816 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000817 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000818 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000819 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000820 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000821 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000822 return value_sp->IsDynamic();
Jim Ingham1b425752011-12-08 19:44:08 +0000823 }
824 }
825 return false;
826}
827
828lldb::SBValue
Enrico Granataf7a9b142011-07-15 02:26:42 +0000829SBValue::GetValueForExpressionPath(const char* expr_path)
830{
831 lldb::ValueObjectSP child_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000832 lldb::ValueObjectSP value_sp(GetSP());
833 if (value_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +0000834 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000835 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000836 if (target_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +0000837 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000838 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granataf7a9b142011-07-15 02:26:42 +0000839 // using default values for all the fancy options, just do it if you can
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000840 child_sp = value_sp->GetValueForExpressionPath(expr_path);
Enrico Granataf7a9b142011-07-15 02:26:42 +0000841 }
842 }
843
844 SBValue sb_value (child_sp);
845
846 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
847 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000848 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 +0000849
850 return sb_value;
851}
Chris Lattner24943d22010-06-08 16:52:24 +0000852
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000853int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +0000854SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
855{
Jim Ingham574c3d62011-08-12 23:34:31 +0000856 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000857 lldb::ValueObjectSP value_sp(GetSP());
858 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000859 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000860 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000861 if (target_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000862 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000863 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granatac92eb402011-08-04 01:41:02 +0000864 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000865 if (value_sp->ResolveValue (scalar))
Enrico Granatac92eb402011-08-04 01:41:02 +0000866 return scalar.GetRawBits64(fail_value);
867 else
868 error.SetErrorString("could not get value");
869 }
870 else
871 error.SetErrorString("could not get target");
872 }
873 error.SetErrorString("invalid SBValue");
874 return fail_value;
875}
876
877uint64_t
878SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
879{
Jim Ingham574c3d62011-08-12 23:34:31 +0000880 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000881 lldb::ValueObjectSP value_sp(GetSP());
882 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000883 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000884 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000885 if (target_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000886 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000887 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granatac92eb402011-08-04 01:41:02 +0000888 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000889 if (value_sp->ResolveValue (scalar))
Enrico Granatac92eb402011-08-04 01:41:02 +0000890 return scalar.GetRawBits64(fail_value);
891 else
892 error.SetErrorString("could not get value");
893 }
894 else
895 error.SetErrorString("could not get target");
896 }
897 error.SetErrorString("invalid SBValue");
898 return fail_value;
899}
900
901int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000902SBValue::GetValueAsSigned(int64_t fail_value)
903{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000904 lldb::ValueObjectSP value_sp(GetSP());
905 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000906 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000907 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000908 if (target_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000909 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000910 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000911 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000912 if (value_sp->ResolveValue (scalar))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000913 return scalar.GetRawBits64(fail_value);
914 }
915 }
916 return fail_value;
917}
918
919uint64_t
920SBValue::GetValueAsUnsigned(uint64_t fail_value)
921{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000922 lldb::ValueObjectSP value_sp(GetSP());
923 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000924 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000925 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000926 if (target_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000927 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000928 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000929 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000930 if (value_sp->ResolveValue (scalar))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000931 return scalar.GetRawBits64(fail_value);
932 }
933 }
934 return fail_value;
935}
936
Chris Lattner24943d22010-06-08 16:52:24 +0000937uint32_t
938SBValue::GetNumChildren ()
939{
940 uint32_t num_children = 0;
941
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000942 lldb::ValueObjectSP value_sp(GetSP());
943 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000944 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000945 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000946 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000947 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000948 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000949
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000950 num_children = value_sp->GetNumChildren();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000951 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000952 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000953
Greg Claytone005f2c2010-11-06 01:53:30 +0000954 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000955 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000956 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000957
958 return num_children;
959}
960
Chris Lattner24943d22010-06-08 16:52:24 +0000961
962SBValue
963SBValue::Dereference ()
964{
Greg Clayton49ce6822010-10-31 03:01:06 +0000965 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000966 lldb::ValueObjectSP value_sp(GetSP());
967 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000968 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000969 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000970 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000971 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000972 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000973
Greg Claytonb9dcc512011-06-29 18:28:50 +0000974 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000975 sb_value = value_sp->Dereference (error);
Greg Claytonb9dcc512011-06-29 18:28:50 +0000976 }
Chris Lattner24943d22010-06-08 16:52:24 +0000977 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000978 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000979 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000980 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000981
982 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000983}
984
985bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000986SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000987{
988 bool is_ptr_type = false;
989
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000990 lldb::ValueObjectSP value_sp(GetSP());
991 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000992 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000993 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000994 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000995 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000996 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000997
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000998 is_ptr_type = value_sp->IsPointerType();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000999 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001000 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001001
Greg Claytone005f2c2010-11-06 01:53:30 +00001002 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001003 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001004 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
Greg Clayton49ce6822010-10-31 03:01:06 +00001005
Chris Lattner24943d22010-06-08 16:52:24 +00001006
1007 return is_ptr_type;
1008}
1009
Chris Lattner24943d22010-06-08 16:52:24 +00001010void *
1011SBValue::GetOpaqueType()
1012{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001013 lldb::ValueObjectSP value_sp(GetSP());
1014 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001015 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001016 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001017 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001018 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001019 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001020
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001021 return value_sp->GetClangType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001022 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001023 }
Chris Lattner24943d22010-06-08 16:52:24 +00001024 return NULL;
1025}
1026
Enrico Granata979e20d2011-07-29 19:53:35 +00001027lldb::SBTarget
1028SBValue::GetTarget()
1029{
Greg Clayton334d33a2012-01-30 07:41:31 +00001030 SBTarget sb_target;
1031 TargetSP target_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001032 lldb::ValueObjectSP value_sp(GetSP());
1033 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001034 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001035 target_sp = value_sp->GetTargetSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001036 sb_target.SetSP (target_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001037 }
1038 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1039 if (log)
1040 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001041 if (target_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001042 log->Printf ("SBValue(%p)::GetTarget () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001043 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001044 log->Printf ("SBValue(%p)::GetTarget () => %p", value_sp.get(), target_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001045 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001046 return sb_target;
Enrico Granata979e20d2011-07-29 19:53:35 +00001047}
1048
1049lldb::SBProcess
1050SBValue::GetProcess()
1051{
Greg Clayton334d33a2012-01-30 07:41:31 +00001052 SBProcess sb_process;
1053 ProcessSP process_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001054 lldb::ValueObjectSP value_sp(GetSP());
1055 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001056 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001057 process_sp = value_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001058 if (process_sp)
1059 sb_process.SetSP (process_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001060 }
1061 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1062 if (log)
1063 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001064 if (process_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001065 log->Printf ("SBValue(%p)::GetProcess () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001066 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001067 log->Printf ("SBValue(%p)::GetProcess () => %p", value_sp.get(), process_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001068 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001069 return sb_process;
Enrico Granata979e20d2011-07-29 19:53:35 +00001070}
1071
1072lldb::SBThread
1073SBValue::GetThread()
1074{
Greg Clayton90c52142012-01-30 02:53:15 +00001075 SBThread sb_thread;
1076 ThreadSP thread_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001077 lldb::ValueObjectSP value_sp(GetSP());
1078 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001079 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001080 thread_sp = value_sp->GetThreadSP();
1081 sb_thread.SetThread(thread_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001082 }
1083 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1084 if (log)
1085 {
Greg Clayton90c52142012-01-30 02:53:15 +00001086 if (thread_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001087 log->Printf ("SBValue(%p)::GetThread () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001088 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001089 log->Printf ("SBValue(%p)::GetThread () => %p", value_sp.get(), thread_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001090 }
Greg Clayton90c52142012-01-30 02:53:15 +00001091 return sb_thread;
Enrico Granata979e20d2011-07-29 19:53:35 +00001092}
1093
1094lldb::SBFrame
1095SBValue::GetFrame()
1096{
Greg Clayton334d33a2012-01-30 07:41:31 +00001097 SBFrame sb_frame;
1098 StackFrameSP frame_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001099 lldb::ValueObjectSP value_sp(GetSP());
1100 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001101 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001102 frame_sp = value_sp->GetFrameSP();
1103 sb_frame.SetFrameSP (frame_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001104 }
1105 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1106 if (log)
1107 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001108 if (frame_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001109 log->Printf ("SBValue(%p)::GetFrame () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001110 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001111 log->Printf ("SBValue(%p)::GetFrame () => %p", value_sp.get(), frame_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001112 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001113 return sb_frame;
Enrico Granata979e20d2011-07-29 19:53:35 +00001114}
1115
1116
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001117lldb::ValueObjectSP
1118SBValue::GetSP () const
Chris Lattner24943d22010-06-08 16:52:24 +00001119{
Greg Clayton63094e02010-06-23 01:19:29 +00001120 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001121}
1122
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001123void
1124SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001125{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001126 m_opaque_sp = sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001127}
Caroline Tice98f930f2010-09-20 05:20:02 +00001128
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001129
Caroline Tice98f930f2010-09-20 05:20:02 +00001130bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001131SBValue::GetExpressionPath (SBStream &description)
1132{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001133 lldb::ValueObjectSP value_sp(GetSP());
1134 if (value_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +00001135 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001136 value_sp->GetExpressionPath (description.ref(), false);
Greg Claytonb01000f2011-01-17 03:46:26 +00001137 return true;
1138 }
1139 return false;
1140}
1141
1142bool
1143SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1144{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001145 lldb::ValueObjectSP value_sp(GetSP());
1146 if (value_sp)
Greg Claytonb01000f2011-01-17 03:46:26 +00001147 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001148 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +00001149 return true;
1150 }
1151 return false;
1152}
1153
1154bool
Caroline Tice98f930f2010-09-20 05:20:02 +00001155SBValue::GetDescription (SBStream &description)
1156{
Greg Clayton96154be2011-11-13 06:57:31 +00001157 Stream &strm = description.ref();
1158
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001159 lldb::ValueObjectSP value_sp(GetSP());
1160 if (value_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +00001161 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001162 ValueObject::DumpValueObject (strm, value_sp.get());
Caroline Tice98f930f2010-09-20 05:20:02 +00001163 }
1164 else
Greg Clayton96154be2011-11-13 06:57:31 +00001165 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +00001166
1167 return true;
1168}
Greg Claytone179a582011-01-05 18:43:15 +00001169
1170lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +00001171SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +00001172{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001173 lldb::ValueObjectSP value_sp(GetSP());
1174 if (value_sp)
1175 return value_sp->GetFormat();
Greg Claytone179a582011-01-05 18:43:15 +00001176 return eFormatDefault;
1177}
1178
1179void
1180SBValue::SetFormat (lldb::Format format)
1181{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001182 lldb::ValueObjectSP value_sp(GetSP());
1183 if (value_sp)
1184 value_sp->SetFormat(format);
Greg Claytone179a582011-01-05 18:43:15 +00001185}
1186
Enrico Granata979e20d2011-07-29 19:53:35 +00001187lldb::SBValue
1188SBValue::AddressOf()
1189{
1190 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001191 lldb::ValueObjectSP value_sp(GetSP());
1192 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001193 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001194 TargetSP target_sp (value_sp->GetTargetSP());
1195 if (target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001196 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001197 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001198 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001199 sb_value = value_sp->AddressOf (error);
Enrico Granata979e20d2011-07-29 19:53:35 +00001200 }
1201 }
1202 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1203 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001204 log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", value_sp.get(), value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001205
1206 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001207}
Enrico Granata91544802011-09-06 19:20:51 +00001208
1209lldb::addr_t
1210SBValue::GetLoadAddress()
1211{
1212 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001213 lldb::ValueObjectSP value_sp(GetSP());
1214 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001215 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001216 TargetSP target_sp (value_sp->GetTargetSP());
1217 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001218 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001219 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001220 const bool scalar_is_load_address = true;
1221 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001222 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001223 if (addr_type == eAddressTypeFile)
1224 {
Greg Clayton3508c382012-02-24 01:59:29 +00001225 ModuleSP module_sp (value_sp->GetModule());
1226 if (!module_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001227 value = LLDB_INVALID_ADDRESS;
1228 else
1229 {
1230 Address addr;
Greg Clayton3508c382012-02-24 01:59:29 +00001231 module_sp->ResolveFileAddress(value, addr);
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001232 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001233 }
1234 }
1235 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1236 value = LLDB_INVALID_ADDRESS;
1237 }
1238 }
1239 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1240 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001241 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", value_sp.get(), value);
Enrico Granata91544802011-09-06 19:20:51 +00001242
1243 return value;
1244}
1245
1246lldb::SBAddress
1247SBValue::GetAddress()
1248{
1249 Address addr;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001250 lldb::ValueObjectSP value_sp(GetSP());
1251 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001252 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001253 TargetSP target_sp (value_sp->GetTargetSP());
1254 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001255 {
1256 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001257 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001258 const bool scalar_is_load_address = true;
1259 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001260 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001261 if (addr_type == eAddressTypeFile)
1262 {
Greg Clayton3508c382012-02-24 01:59:29 +00001263 ModuleSP module_sp (value_sp->GetModule());
1264 if (module_sp)
1265 module_sp->ResolveFileAddress(value, addr);
Enrico Granata91544802011-09-06 19:20:51 +00001266 }
1267 else if (addr_type == eAddressTypeLoad)
1268 {
1269 // no need to check the return value on this.. if it can actually do the resolve
1270 // addr will be in the form (section,offset), otherwise it will simply be returned
1271 // as (NULL, value)
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001272 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001273 }
1274 }
1275 }
1276 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1277 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001278 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 +00001279 return SBAddress(new Address(addr));
1280}
1281
1282lldb::SBData
1283SBValue::GetPointeeData (uint32_t item_idx,
1284 uint32_t item_count)
1285{
1286 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001287 lldb::ValueObjectSP value_sp(GetSP());
1288 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001289 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001290 TargetSP target_sp (value_sp->GetTargetSP());
1291 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001292 {
1293 DataExtractorSP data_sp(new DataExtractor());
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001294 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001295 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
Enrico Granata91544802011-09-06 19:20:51 +00001296 if (data_sp->GetByteSize() > 0)
1297 *sb_data = data_sp;
1298 }
1299 }
1300 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1301 if (log)
1302 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001303 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001304 item_idx,
1305 item_count,
1306 sb_data.get());
1307
1308 return sb_data;
1309}
1310
1311lldb::SBData
1312SBValue::GetData ()
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());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001319 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001320 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001321 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001322 DataExtractorSP data_sp(new DataExtractor());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001323 value_sp->GetData(*data_sp);
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)::GetData () => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001331 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001332 sb_data.get());
1333
1334 return sb_data;
1335}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001336
1337lldb::SBWatchpoint
1338SBValue::Watch (bool resolve_location, bool read, bool write)
1339{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001340 SBWatchpoint sb_watchpoint;
1341
1342 // If the SBValue is not valid, there's no point in even trying to watch it.
1343 lldb::ValueObjectSP value_sp(GetSP());
1344 TargetSP target_sp (GetTarget().GetSP());
1345 if (value_sp && target_sp)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001346 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001347 // Read and Write cannot both be false.
1348 if (!read && !write)
1349 return sb_watchpoint;
1350
1351 // If the value is not in scope, don't try and watch and invalid value
1352 if (!IsInScope())
1353 return sb_watchpoint;
1354
1355 addr_t addr = GetLoadAddress();
1356 if (addr == LLDB_INVALID_ADDRESS)
1357 return sb_watchpoint;
1358 size_t byte_size = GetByteSize();
1359 if (byte_size == 0)
1360 return sb_watchpoint;
1361
1362 uint32_t watch_type = 0;
1363 if (read)
1364 watch_type |= LLDB_WATCH_TYPE_READ;
1365 if (write)
1366 watch_type |= LLDB_WATCH_TYPE_WRITE;
1367
1368 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type);
1369
1370 if (watchpoint_sp)
1371 {
1372 sb_watchpoint.SetSP (watchpoint_sp);
1373 Declaration decl;
1374 if (value_sp->GetDeclaration (decl))
1375 {
1376 if (decl.GetFile())
1377 {
1378 StreamString ss;
1379 // True to show fullpath for declaration file.
1380 decl.DumpStopContext(&ss, true);
1381 watchpoint_sp->SetDeclInfo(ss.GetString());
1382 }
1383 }
1384 }
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001385 }
1386 return sb_watchpoint;
1387}
1388
1389lldb::SBWatchpoint
1390SBValue::WatchPointee (bool resolve_location, bool read, bool write)
1391{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001392 SBWatchpoint sb_watchpoint;
1393 if (IsInScope() && GetType().IsPointerType())
1394 sb_watchpoint = Dereference().Watch (resolve_location, read, write);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001395 return sb_watchpoint;
1396}
1397