blob: d4d2c06a448036377b7f3b2694a5b106dabccf57 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBValue.cpp ---------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Eli Friedman7a62c8b2010-06-09 07:44:37 +000010#include "lldb/API/SBValue.h"
Enrico Granatad760907c2012-02-17 03:18:30 +000011
Caroline Tice98f930f2010-09-20 05:20:02 +000012#include "lldb/API/SBStream.h"
Enrico Granatad760907c2012-02-17 03:18:30 +000013#include "lldb/API/SBTypeFilter.h"
14#include "lldb/API/SBTypeFormat.h"
15#include "lldb/API/SBTypeSummary.h"
16#include "lldb/API/SBTypeSynthetic.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017
Johnny Chenecd4feb2011-10-14 00:42:25 +000018#include "lldb/Breakpoint/Watchpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019#include "lldb/Core/DataExtractor.h"
Enrico Granatad760907c2012-02-17 03:18:30 +000020#include "lldb/Core/DataVisualization.h"
Caroline Tice7826c882010-10-26 03:11:13 +000021#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Core/Module.h"
Greg Clayton0fb0bcc2011-08-03 22:57:10 +000023#include "lldb/Core/Scalar.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024#include "lldb/Core/Stream.h"
25#include "lldb/Core/StreamFile.h"
26#include "lldb/Core/Value.h"
27#include "lldb/Core/ValueObject.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000028#include "lldb/Core/ValueObjectConstResult.h"
Chris Lattner24943d22010-06-08 16:52:24 +000029#include "lldb/Symbol/Block.h"
30#include "lldb/Symbol/ObjectFile.h"
Greg Clayton0a19a1b2012-02-04 02:27:34 +000031#include "lldb/Symbol/Type.h"
Chris Lattner24943d22010-06-08 16:52:24 +000032#include "lldb/Symbol/Variable.h"
Johnny Chenecd4feb2011-10-14 00:42:25 +000033#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000034#include "lldb/Target/ExecutionContext.h"
35#include "lldb/Target/Process.h"
36#include "lldb/Target/StackFrame.h"
Greg Claytonbdcda462010-12-20 20:49:23 +000037#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000038#include "lldb/Target/Thread.h"
39
Eli Friedman7a62c8b2010-06-09 07:44:37 +000040#include "lldb/API/SBProcess.h"
41#include "lldb/API/SBTarget.h"
42#include "lldb/API/SBThread.h"
43#include "lldb/API/SBFrame.h"
44#include "lldb/API/SBDebugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000045
46using namespace lldb;
47using namespace lldb_private;
48
49SBValue::SBValue () :
Greg Clayton63094e02010-06-23 01:19:29 +000050 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000051{
52}
53
54SBValue::SBValue (const lldb::ValueObjectSP &value_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000055 m_opaque_sp (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000056{
57}
58
Greg Clayton538eb822010-11-05 23:17:00 +000059SBValue::SBValue(const SBValue &rhs) :
60 m_opaque_sp (rhs.m_opaque_sp)
61{
62}
63
Greg Claytond68e0892011-09-09 23:04:00 +000064SBValue &
Greg Clayton538eb822010-11-05 23:17:00 +000065SBValue::operator = (const SBValue &rhs)
66{
67 if (this != &rhs)
68 m_opaque_sp = rhs.m_opaque_sp;
69 return *this;
70}
71
Chris Lattner24943d22010-06-08 16:52:24 +000072SBValue::~SBValue()
73{
74}
75
76bool
Greg Claytond68e0892011-09-09 23:04:00 +000077SBValue::IsValid ()
Chris Lattner24943d22010-06-08 16:52:24 +000078{
Greg Clayton49ce6822010-10-31 03:01:06 +000079 // If this function ever changes to anything that does more than just
80 // check if the opaque shared pointer is non NULL, then we need to update
81 // all "if (m_opaque_sp)" code in this file.
82 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000083}
84
Jim Inghame0bd5712011-12-19 20:39:44 +000085void
86SBValue::Clear()
87{
88 m_opaque_sp.reset();
89}
90
Greg Claytonc5f728c2010-10-06 22:10:17 +000091SBError
92SBValue::GetError()
93{
94 SBError sb_error;
95
Greg Clayton0a19a1b2012-02-04 02:27:34 +000096 lldb::ValueObjectSP value_sp(GetSP());
97 if (value_sp)
98 sb_error.SetError(value_sp->GetError());
Greg Clayton334d33a2012-01-30 07:41:31 +000099 else
100 sb_error.SetErrorString("error: invalid value");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000101
102 return sb_error;
103}
104
Johnny Chen968958c2011-07-07 20:46:23 +0000105user_id_t
106SBValue::GetID()
107{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000108 lldb::ValueObjectSP value_sp(GetSP());
109 if (value_sp)
110 return value_sp->GetID();
Johnny Chen968958c2011-07-07 20:46:23 +0000111 return LLDB_INVALID_UID;
112}
113
Chris Lattner24943d22010-06-08 16:52:24 +0000114const char *
115SBValue::GetName()
116{
Greg Clayton49ce6822010-10-31 03:01:06 +0000117
118 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000119 lldb::ValueObjectSP value_sp(GetSP());
120 if (value_sp)
121 name = value_sp->GetName().GetCString();
Greg Clayton49ce6822010-10-31 03:01:06 +0000122
Greg Claytone005f2c2010-11-06 01:53:30 +0000123 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000124 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000125 {
126 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000127 log->Printf ("SBValue(%p)::GetName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000128 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000129 log->Printf ("SBValue(%p)::GetName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000130 }
Caroline Tice7826c882010-10-26 03:11:13 +0000131
Greg Clayton49ce6822010-10-31 03:01:06 +0000132 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000133}
134
135const char *
136SBValue::GetTypeName ()
137{
Greg Clayton49ce6822010-10-31 03:01:06 +0000138 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000139 lldb::ValueObjectSP value_sp(GetSP());
140 if (value_sp)
141 name = value_sp->GetTypeName().GetCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000142 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000143 if (log)
144 {
145 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000146 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000147 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000148 log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000149 }
150
151 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000152}
153
154size_t
155SBValue::GetByteSize ()
156{
157 size_t result = 0;
158
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000159 lldb::ValueObjectSP value_sp(GetSP());
160 if (value_sp)
161 result = value_sp->GetByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000162
Greg Claytone005f2c2010-11-06 01:53:30 +0000163 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000164 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000165 log->Printf ("SBValue(%p)::GetByteSize () => %zu", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000166
Chris Lattner24943d22010-06-08 16:52:24 +0000167 return result;
168}
169
170bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000171SBValue::IsInScope ()
172{
Chris Lattner24943d22010-06-08 16:52:24 +0000173 bool result = false;
174
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000175 lldb::ValueObjectSP value_sp(GetSP());
176 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000177 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000178 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000179 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000180 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000181 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000182 result = value_sp->IsInScope ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000183 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000184 }
Chris Lattner24943d22010-06-08 16:52:24 +0000185
Greg Claytone005f2c2010-11-06 01:53:30 +0000186 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000187 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000188 log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000189
Chris Lattner24943d22010-06-08 16:52:24 +0000190 return result;
191}
192
193const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000194SBValue::GetValue ()
195{
Greg Clayton49ce6822010-10-31 03:01:06 +0000196 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000197 lldb::ValueObjectSP value_sp(GetSP());
198 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000199 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000200 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000201 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000202 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000203 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000204 cstr = value_sp->GetValueAsCString ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000205 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000206 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000207 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000208 if (log)
209 {
210 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000211 log->Printf ("SBValue(%p)::GetValue => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000212 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000213 log->Printf ("SBValue(%p)::GetValue => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000214 }
215
216 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000217}
218
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000219ValueType
220SBValue::GetValueType ()
221{
Greg Clayton49ce6822010-10-31 03:01:06 +0000222 ValueType result = eValueTypeInvalid;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000223 lldb::ValueObjectSP value_sp(GetSP());
224 if (value_sp)
225 result = value_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000226 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000227 if (log)
228 {
229 switch (result)
230 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000231 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break;
232 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break;
233 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break;
234 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break;
235 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break;
236 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break;
237 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break;
238 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break;
239 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", value_sp.get(), result); break;
Greg Clayton49ce6822010-10-31 03:01:06 +0000240 }
241 }
242 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000243}
244
Jim Ingham4ae51962010-09-10 23:12:17 +0000245const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000246SBValue::GetObjectDescription ()
247{
Greg Clayton49ce6822010-10-31 03:01:06 +0000248 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000249 lldb::ValueObjectSP value_sp(GetSP());
250 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000251 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000252 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000253 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000254 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000255 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000256 cstr = value_sp->GetObjectDescription ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000257 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000258 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000259 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000260 if (log)
261 {
262 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000263 log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000264 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000265 log->Printf ("SBValue(%p)::GetObjectDescription => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000266 }
267 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000268}
269
Enrico Granata979e20d2011-07-29 19:53:35 +0000270SBType
271SBValue::GetType()
272{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000273 SBType sb_type;
274 lldb::ValueObjectSP value_sp(GetSP());
275 TypeImplSP type_sp;
276 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000277 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000278 type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType())));
279 sb_type.SetSP(type_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000280 }
281 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
282 if (log)
283 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000284 if (type_sp)
285 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000286 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000287 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000288 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000289 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000290}
291
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000292bool
293SBValue::GetValueDidChange ()
294{
Greg Clayton49ce6822010-10-31 03:01:06 +0000295 bool result = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000296 lldb::ValueObjectSP value_sp(GetSP());
297 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000298 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000299 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000300 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000301 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000302 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000303 result = value_sp->GetValueDidChange ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000304 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000305 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000306 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000307 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000308 log->Printf ("SBValue(%p)::GetValueDidChange => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000309
310 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000311}
312
313const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000314SBValue::GetSummary ()
315{
Greg Clayton49ce6822010-10-31 03:01:06 +0000316 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000317 lldb::ValueObjectSP value_sp(GetSP());
318 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000319 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000320 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000321 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000322 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000323 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000324 cstr = value_sp->GetSummaryAsCString();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000325 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000326 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000327 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000328 if (log)
329 {
330 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000331 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000332 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000333 log->Printf ("SBValue(%p)::GetSummary => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000334 }
335 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000336}
337
338const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000339SBValue::GetLocation ()
340{
Greg Clayton49ce6822010-10-31 03:01:06 +0000341 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000342 lldb::ValueObjectSP value_sp(GetSP());
343 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000344 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000345 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000346 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000347 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000348 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000349 cstr = value_sp->GetLocationAsCString();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000350 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000351 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000352 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000353 if (log)
354 {
355 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000356 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000357 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000358 log->Printf ("SBValue(%p)::GetSummary => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000359 }
360 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000361}
362
363bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000364SBValue::SetValueFromCString (const char *value_str)
365{
Chris Lattner24943d22010-06-08 16:52:24 +0000366 bool success = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000367 lldb::ValueObjectSP value_sp(GetSP());
368 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000369 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000370 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000371 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000372 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000373 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000374 success = value_sp->SetValueFromCString (value_str);
Greg Claytonb9dcc512011-06-29 18:28:50 +0000375 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000376 }
Chris Lattner24943d22010-06-08 16:52:24 +0000377 return success;
378}
379
Enrico Granatad760907c2012-02-17 03:18:30 +0000380lldb::SBTypeFormat
381SBValue::GetTypeFormat ()
382{
383 lldb::SBTypeFormat format;
384 lldb::ValueObjectSP value_sp(GetSP());
385 if (value_sp)
386 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000387 TargetSP target_sp(value_sp->GetTargetSP());
388 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000389 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000390 Mutex::Locker api_locker (target_sp->GetAPIMutex());
391 if (value_sp->UpdateValueIfNeeded(true))
392 {
393 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
394 if (format_sp)
395 format.SetSP(format_sp);
396 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000397 }
398 }
399 return format;
400}
401
402lldb::SBTypeSummary
403SBValue::GetTypeSummary ()
404{
405 lldb::SBTypeSummary summary;
406 lldb::ValueObjectSP value_sp(GetSP());
407 if (value_sp)
408 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000409 TargetSP target_sp(value_sp->GetTargetSP());
410 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000411 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000412 Mutex::Locker api_locker (target_sp->GetAPIMutex());
413 if (value_sp->UpdateValueIfNeeded(true))
414 {
415 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
416 if (summary_sp)
417 summary.SetSP(summary_sp);
418 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000419 }
420 }
421 return summary;
422}
423
424lldb::SBTypeFilter
425SBValue::GetTypeFilter ()
426{
427 lldb::SBTypeFilter filter;
428 lldb::ValueObjectSP value_sp(GetSP());
429 if (value_sp)
430 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000431 TargetSP target_sp(value_sp->GetTargetSP());
432 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000433 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000434 Mutex::Locker api_locker (target_sp->GetAPIMutex());
435 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granatad760907c2012-02-17 03:18:30 +0000436 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000437 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
438
439 if (synthetic_sp && !synthetic_sp->IsScripted())
440 {
441 TypeFilterImplSP filter_sp = std::tr1::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
442 filter.SetSP(filter_sp);
443 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000444 }
445 }
446 }
447 return filter;
448}
449
450lldb::SBTypeSynthetic
451SBValue::GetTypeSynthetic ()
452{
453 lldb::SBTypeSynthetic synthetic;
454 lldb::ValueObjectSP value_sp(GetSP());
455 if (value_sp)
456 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000457 TargetSP target_sp(value_sp->GetTargetSP());
458 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000459 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000460 Mutex::Locker api_locker (target_sp->GetAPIMutex());
461 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granatad760907c2012-02-17 03:18:30 +0000462 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000463 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
464
465 if (children_sp && children_sp->IsScripted())
466 {
467 TypeSyntheticImplSP synth_sp = std::tr1::static_pointer_cast<TypeSyntheticImpl>(children_sp);
468 synthetic.SetSP(synth_sp);
469 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000470 }
471 }
472 }
473 return synthetic;
474}
475
Enrico Granata979e20d2011-07-29 19:53:35 +0000476lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000477SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000478{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000479 lldb::SBValue sb_value;
480 lldb::ValueObjectSP value_sp(GetSP());
481 lldb::ValueObjectSP new_value_sp;
482 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000483 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000484 TypeImplSP type_sp (type.GetSP());
Enrico Granata979e20d2011-07-29 19:53:35 +0000485 if (type.IsValid())
486 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000487 sb_value = SBValue(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true));
488 new_value_sp = sb_value.GetSP();
489 if (new_value_sp)
490 new_value_sp->SetName(ConstString(name));
Enrico Granata979e20d2011-07-29 19:53:35 +0000491 }
492 }
493 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
494 if (log)
495 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000496 if (new_value_sp)
497 log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000498 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000499 log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000500 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000501 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000502}
503
504lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000505SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000506{
Greg Clayton4eb01a72012-01-31 04:25:15 +0000507 lldb::SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000508 lldb::ValueObjectSP value_sp(GetSP());
509 TypeImplSP type_sp (type.GetSP());
510 if (value_sp && type_sp)
511 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()));
Greg Clayton4eb01a72012-01-31 04:25:15 +0000512 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000513}
514
515lldb::SBValue
516SBValue::CreateValueFromExpression (const char *name, const char* expression)
517{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000518 lldb::SBValue sb_value;
519 lldb::ValueObjectSP value_sp(GetSP());
520 lldb::ValueObjectSP new_value_sp;
521 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000522 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000523 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
524 Target* target = exe_ctx.GetTargetPtr();
525 if (target)
Johnny Chen9fd2e382011-12-20 01:52:44 +0000526 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000527 target->EvaluateExpression (expression,
528 exe_ctx.GetFramePtr(),
529 eExecutionPolicyOnlyWhenNeeded,
530 false, // coerce to id
531 true, // unwind on error
532 true, // keep in memory
533 eNoDynamicValues,
534 new_value_sp);
535 if (new_value_sp)
536 {
537 new_value_sp->SetName(ConstString(name));
538 sb_value.SetSP(new_value_sp);
539 }
Johnny Chen9fd2e382011-12-20 01:52:44 +0000540 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000541 }
542 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
543 if (log)
544 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000545 if (new_value_sp)
546 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000547 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000548 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000549 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000550 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000551}
552
553lldb::SBValue
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000554SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000555{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000556 lldb::SBValue sb_value;
557 lldb::ValueObjectSP value_sp(GetSP());
558 lldb::ValueObjectSP new_value_sp;
559 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
560 if (value_sp && type_impl_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000561 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000562 ClangASTType pointee_ast_type(type_impl_sp->GetASTContext(), type_impl_sp->GetClangASTType().GetPointerType ());
563 lldb::TypeImplSP pointee_type_impl_sp (new TypeImpl(pointee_ast_type));
564 if (pointee_type_impl_sp)
Enrico Granatac9310302011-08-04 17:07:02 +0000565 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000566
567 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
568
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000569 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
570 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000571 pointee_type_impl_sp->GetASTContext(),
572 pointee_type_impl_sp->GetOpaqueQualType(),
573 ConstString(name),
574 buffer,
575 lldb::endian::InlHostByteOrder(),
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000576 exe_ctx.GetAddressByteSize()));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000577
578 if (ptr_result_valobj_sp)
579 {
580 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
581 Error err;
582 new_value_sp = ptr_result_valobj_sp->Dereference(err);
583 if (new_value_sp)
584 new_value_sp->SetName(ConstString(name));
585 }
586 sb_value.SetSP(new_value_sp);
Enrico Granatac9310302011-08-04 17:07:02 +0000587 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000588 }
589 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
590 if (log)
591 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000592 if (new_value_sp)
593 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000594 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000595 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
Johnny Chena713b862011-08-09 22:38:07 +0000596 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000597 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000598}
599
Enrico Granata91544802011-09-06 19:20:51 +0000600lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000601SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000602{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000603 lldb::SBValue sb_value;
604 lldb::ValueObjectSP new_value_sp;
605 lldb::ValueObjectSP value_sp(GetSP());
606 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +0000607 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000608 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
609
610 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000611 type.m_opaque_sp->GetASTContext() ,
612 type.m_opaque_sp->GetOpaqueQualType(),
613 ConstString(name),
614 *data.m_opaque_sp,
615 LLDB_INVALID_ADDRESS);
616 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
617 sb_value.SetSP(new_value_sp);
Enrico Granata91544802011-09-06 19:20:51 +0000618 }
619 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
620 if (log)
621 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000622 if (new_value_sp)
623 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000624 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000625 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +0000626 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000627 return sb_value;
Enrico Granata91544802011-09-06 19:20:51 +0000628}
629
Chris Lattner24943d22010-06-08 16:52:24 +0000630SBValue
631SBValue::GetChildAtIndex (uint32_t idx)
632{
Greg Clayton8f64c472011-07-15 19:31:49 +0000633 const bool can_create_synthetic = false;
634 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000635 lldb::ValueObjectSP value_sp(GetSP());
636 if (value_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000637 {
638 TargetSP target_sp(value_sp->GetTargetSP());
639 if (target_sp)
640 use_dynamic = target_sp->GetPreferDynamicValue();
641 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000642 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000643}
644
645SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000646SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000647{
Chris Lattner24943d22010-06-08 16:52:24 +0000648 lldb::ValueObjectSP child_sp;
649
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000650 lldb::ValueObjectSP value_sp(GetSP());
651 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000652 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000653 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000654 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000655 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000656 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton8f64c472011-07-15 19:31:49 +0000657 const bool can_create = true;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000658 child_sp = value_sp->GetChildAtIndex (idx, can_create);
Greg Clayton8f64c472011-07-15 19:31:49 +0000659 if (can_create_synthetic && !child_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000660 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000661 if (value_sp->IsPointerType())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000662 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000663 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
Greg Clayton8f64c472011-07-15 19:31:49 +0000664 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000665 else if (value_sp->IsArrayType())
Greg Clayton8f64c472011-07-15 19:31:49 +0000666 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000667 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
Greg Clayton8f64c472011-07-15 19:31:49 +0000668 }
669 }
670
671 if (child_sp)
672 {
673 if (use_dynamic != lldb::eNoDynamicValues)
674 {
675 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000676 if (dynamic_sp)
677 child_sp = dynamic_sp;
678 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000679 }
Jim Inghame41494a2011-04-16 00:01:13 +0000680 }
681 }
682
Chris Lattner24943d22010-06-08 16:52:24 +0000683 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000684 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000685 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000686 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000687
Chris Lattner24943d22010-06-08 16:52:24 +0000688 return sb_value;
689}
690
691uint32_t
692SBValue::GetIndexOfChildWithName (const char *name)
693{
Greg Clayton49ce6822010-10-31 03:01:06 +0000694 uint32_t idx = UINT32_MAX;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000695 lldb::ValueObjectSP value_sp(GetSP());
696 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000697 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000698 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000699 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000700 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000701 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000702
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000703 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000704 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000705 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000706 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000707 if (log)
708 {
709 if (idx == UINT32_MAX)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000710 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000711 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000712 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
Greg Clayton49ce6822010-10-31 03:01:06 +0000713 }
714 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000715}
716
717SBValue
718SBValue::GetChildMemberWithName (const char *name)
719{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000720 lldb::ValueObjectSP value_sp(GetSP());
721 if (value_sp)
Johnny Chen446ccaa2011-06-29 21:19:39 +0000722 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000723 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000724 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000725 if (target_sp)
726 {
727 Mutex::Locker api_locker (target_sp->GetAPIMutex());
728 use_dynamic_value = target_sp->GetPreferDynamicValue();
729 }
Johnny Chen446ccaa2011-06-29 21:19:39 +0000730 return GetChildMemberWithName (name, use_dynamic_value);
731 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000732 return SBValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000733}
734
735SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000736SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000737{
Chris Lattner24943d22010-06-08 16:52:24 +0000738 lldb::ValueObjectSP child_sp;
739 const ConstString str_name (name);
740
Greg Clayton905acaf2011-05-20 22:07:17 +0000741
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000742 lldb::ValueObjectSP value_sp(GetSP());
743 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000744 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000745 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000746 if (target_sp)
Jim Inghame41494a2011-04-16 00:01:13 +0000747 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000748 Mutex::Locker api_locker (target_sp->GetAPIMutex());
749 child_sp = value_sp->GetChildMemberWithName (str_name, true);
Greg Claytonb9dcc512011-06-29 18:28:50 +0000750 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000751 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000752 if (child_sp)
753 {
754 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
755 if (dynamic_sp)
756 child_sp = dynamic_sp;
757 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000758 }
Jim Inghame41494a2011-04-16 00:01:13 +0000759 }
760 }
761
Chris Lattner24943d22010-06-08 16:52:24 +0000762 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000763
Greg Claytone005f2c2010-11-06 01:53:30 +0000764 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000765 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000766 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000767
Chris Lattner24943d22010-06-08 16:52:24 +0000768 return sb_value;
769}
770
Enrico Granataf7a9b142011-07-15 02:26:42 +0000771lldb::SBValue
Jim Ingham1b425752011-12-08 19:44:08 +0000772SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
773{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000774 lldb::ValueObjectSP value_sp(GetSP());
775 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000776 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000777 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000778 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000779 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000780 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000781 return SBValue (value_sp->GetDynamicValue(use_dynamic));
Jim Ingham1b425752011-12-08 19:44:08 +0000782 }
783 }
784
785 return SBValue();
786}
787
788lldb::SBValue
789SBValue::GetStaticValue ()
790{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000791 lldb::ValueObjectSP value_sp(GetSP());
792 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000793 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000794 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000795 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000796 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000797 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000798 return SBValue(value_sp->GetStaticValue());
Jim Ingham1b425752011-12-08 19:44:08 +0000799 }
800 }
801
802 return SBValue();
803}
804
805bool
806SBValue::IsDynamic()
807{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000808 lldb::ValueObjectSP value_sp(GetSP());
809 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000810 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000811 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000812 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000813 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000814 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000815 return value_sp->IsDynamic();
Jim Ingham1b425752011-12-08 19:44:08 +0000816 }
817 }
818 return false;
819}
820
821lldb::SBValue
Enrico Granataf7a9b142011-07-15 02:26:42 +0000822SBValue::GetValueForExpressionPath(const char* expr_path)
823{
824 lldb::ValueObjectSP child_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000825 lldb::ValueObjectSP value_sp(GetSP());
826 if (value_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +0000827 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000828 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000829 if (target_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +0000830 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000831 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granataf7a9b142011-07-15 02:26:42 +0000832 // using default values for all the fancy options, just do it if you can
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000833 child_sp = value_sp->GetValueForExpressionPath(expr_path);
Enrico Granataf7a9b142011-07-15 02:26:42 +0000834 }
835 }
836
837 SBValue sb_value (child_sp);
838
839 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
840 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000841 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 +0000842
843 return sb_value;
844}
Chris Lattner24943d22010-06-08 16:52:24 +0000845
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000846int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +0000847SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
848{
Jim Ingham574c3d62011-08-12 23:34:31 +0000849 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000850 lldb::ValueObjectSP value_sp(GetSP());
851 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000852 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000853 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000854 if (target_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000855 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000856 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granatac92eb402011-08-04 01:41:02 +0000857 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000858 if (value_sp->ResolveValue (scalar))
Enrico Granatac92eb402011-08-04 01:41:02 +0000859 return scalar.GetRawBits64(fail_value);
860 else
861 error.SetErrorString("could not get value");
862 }
863 else
864 error.SetErrorString("could not get target");
865 }
866 error.SetErrorString("invalid SBValue");
867 return fail_value;
868}
869
870uint64_t
871SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
872{
Jim Ingham574c3d62011-08-12 23:34:31 +0000873 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000874 lldb::ValueObjectSP value_sp(GetSP());
875 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000876 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000877 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000878 if (target_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000879 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000880 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granatac92eb402011-08-04 01:41:02 +0000881 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000882 if (value_sp->ResolveValue (scalar))
Enrico Granatac92eb402011-08-04 01:41:02 +0000883 return scalar.GetRawBits64(fail_value);
884 else
885 error.SetErrorString("could not get value");
886 }
887 else
888 error.SetErrorString("could not get target");
889 }
890 error.SetErrorString("invalid SBValue");
891 return fail_value;
892}
893
894int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000895SBValue::GetValueAsSigned(int64_t fail_value)
896{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000897 lldb::ValueObjectSP value_sp(GetSP());
898 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000899 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000900 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000901 if (target_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000902 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000903 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000904 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000905 if (value_sp->ResolveValue (scalar))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000906 return scalar.GetRawBits64(fail_value);
907 }
908 }
909 return fail_value;
910}
911
912uint64_t
913SBValue::GetValueAsUnsigned(uint64_t fail_value)
914{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000915 lldb::ValueObjectSP value_sp(GetSP());
916 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000917 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000918 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000919 if (target_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000920 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000921 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000922 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000923 if (value_sp->ResolveValue (scalar))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000924 return scalar.GetRawBits64(fail_value);
925 }
926 }
927 return fail_value;
928}
929
Chris Lattner24943d22010-06-08 16:52:24 +0000930uint32_t
931SBValue::GetNumChildren ()
932{
933 uint32_t num_children = 0;
934
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000935 lldb::ValueObjectSP value_sp(GetSP());
936 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000937 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000938 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000939 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000940 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000941 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000942
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000943 num_children = value_sp->GetNumChildren();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000944 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000945 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000946
Greg Claytone005f2c2010-11-06 01:53:30 +0000947 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000948 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000949 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000950
951 return num_children;
952}
953
Chris Lattner24943d22010-06-08 16:52:24 +0000954
955SBValue
956SBValue::Dereference ()
957{
Greg Clayton49ce6822010-10-31 03:01:06 +0000958 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000959 lldb::ValueObjectSP value_sp(GetSP());
960 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000961 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000962 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000963 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000964 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000965 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000966
Greg Claytonb9dcc512011-06-29 18:28:50 +0000967 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000968 sb_value = value_sp->Dereference (error);
Greg Claytonb9dcc512011-06-29 18:28:50 +0000969 }
Chris Lattner24943d22010-06-08 16:52:24 +0000970 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000971 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000972 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000973 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000974
975 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000976}
977
978bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000979SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000980{
981 bool is_ptr_type = false;
982
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000983 lldb::ValueObjectSP value_sp(GetSP());
984 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000985 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000986 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000987 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000988 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000989 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000990
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000991 is_ptr_type = value_sp->IsPointerType();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000992 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000993 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000994
Greg Claytone005f2c2010-11-06 01:53:30 +0000995 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000996 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000997 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
Greg Clayton49ce6822010-10-31 03:01:06 +0000998
Chris Lattner24943d22010-06-08 16:52:24 +0000999
1000 return is_ptr_type;
1001}
1002
Chris Lattner24943d22010-06-08 16:52:24 +00001003void *
1004SBValue::GetOpaqueType()
1005{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001006 lldb::ValueObjectSP value_sp(GetSP());
1007 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001008 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001009 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001010 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001011 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001012 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001013
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001014 return value_sp->GetClangType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001015 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001016 }
Chris Lattner24943d22010-06-08 16:52:24 +00001017 return NULL;
1018}
1019
Enrico Granata979e20d2011-07-29 19:53:35 +00001020lldb::SBTarget
1021SBValue::GetTarget()
1022{
Greg Clayton334d33a2012-01-30 07:41:31 +00001023 SBTarget sb_target;
1024 TargetSP target_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001025 lldb::ValueObjectSP value_sp(GetSP());
1026 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001027 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001028 target_sp = value_sp->GetTargetSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001029 sb_target.SetSP (target_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001030 }
1031 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1032 if (log)
1033 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001034 if (target_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001035 log->Printf ("SBValue(%p)::GetTarget () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001036 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001037 log->Printf ("SBValue(%p)::GetTarget () => %p", value_sp.get(), target_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001038 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001039 return sb_target;
Enrico Granata979e20d2011-07-29 19:53:35 +00001040}
1041
1042lldb::SBProcess
1043SBValue::GetProcess()
1044{
Greg Clayton334d33a2012-01-30 07:41:31 +00001045 SBProcess sb_process;
1046 ProcessSP process_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001047 lldb::ValueObjectSP value_sp(GetSP());
1048 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001049 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001050 process_sp = value_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001051 if (process_sp)
1052 sb_process.SetSP (process_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001053 }
1054 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1055 if (log)
1056 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001057 if (process_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001058 log->Printf ("SBValue(%p)::GetProcess () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001059 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001060 log->Printf ("SBValue(%p)::GetProcess () => %p", value_sp.get(), process_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001061 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001062 return sb_process;
Enrico Granata979e20d2011-07-29 19:53:35 +00001063}
1064
1065lldb::SBThread
1066SBValue::GetThread()
1067{
Greg Clayton90c52142012-01-30 02:53:15 +00001068 SBThread sb_thread;
1069 ThreadSP thread_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001070 lldb::ValueObjectSP value_sp(GetSP());
1071 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001072 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001073 thread_sp = value_sp->GetThreadSP();
1074 sb_thread.SetThread(thread_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001075 }
1076 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1077 if (log)
1078 {
Greg Clayton90c52142012-01-30 02:53:15 +00001079 if (thread_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001080 log->Printf ("SBValue(%p)::GetThread () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001081 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001082 log->Printf ("SBValue(%p)::GetThread () => %p", value_sp.get(), thread_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001083 }
Greg Clayton90c52142012-01-30 02:53:15 +00001084 return sb_thread;
Enrico Granata979e20d2011-07-29 19:53:35 +00001085}
1086
1087lldb::SBFrame
1088SBValue::GetFrame()
1089{
Greg Clayton334d33a2012-01-30 07:41:31 +00001090 SBFrame sb_frame;
1091 StackFrameSP frame_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001092 lldb::ValueObjectSP value_sp(GetSP());
1093 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001094 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001095 frame_sp = value_sp->GetFrameSP();
1096 sb_frame.SetFrameSP (frame_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001097 }
1098 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1099 if (log)
1100 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001101 if (frame_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001102 log->Printf ("SBValue(%p)::GetFrame () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001103 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001104 log->Printf ("SBValue(%p)::GetFrame () => %p", value_sp.get(), frame_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001105 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001106 return sb_frame;
Enrico Granata979e20d2011-07-29 19:53:35 +00001107}
1108
1109
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001110lldb::ValueObjectSP
1111SBValue::GetSP () const
Chris Lattner24943d22010-06-08 16:52:24 +00001112{
Greg Clayton63094e02010-06-23 01:19:29 +00001113 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001114}
1115
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001116void
1117SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001118{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001119 m_opaque_sp = sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001120}
Caroline Tice98f930f2010-09-20 05:20:02 +00001121
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001122
Caroline Tice98f930f2010-09-20 05:20:02 +00001123bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001124SBValue::GetExpressionPath (SBStream &description)
1125{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001126 lldb::ValueObjectSP value_sp(GetSP());
1127 if (value_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +00001128 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001129 value_sp->GetExpressionPath (description.ref(), false);
Greg Claytonb01000f2011-01-17 03:46:26 +00001130 return true;
1131 }
1132 return false;
1133}
1134
1135bool
1136SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1137{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001138 lldb::ValueObjectSP value_sp(GetSP());
1139 if (value_sp)
Greg Claytonb01000f2011-01-17 03:46:26 +00001140 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001141 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +00001142 return true;
1143 }
1144 return false;
1145}
1146
1147bool
Caroline Tice98f930f2010-09-20 05:20:02 +00001148SBValue::GetDescription (SBStream &description)
1149{
Greg Clayton96154be2011-11-13 06:57:31 +00001150 Stream &strm = description.ref();
1151
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001152 lldb::ValueObjectSP value_sp(GetSP());
1153 if (value_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +00001154 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001155 ValueObject::DumpValueObject (strm, value_sp.get());
Caroline Tice98f930f2010-09-20 05:20:02 +00001156 }
1157 else
Greg Clayton96154be2011-11-13 06:57:31 +00001158 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +00001159
1160 return true;
1161}
Greg Claytone179a582011-01-05 18:43:15 +00001162
1163lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +00001164SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +00001165{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001166 lldb::ValueObjectSP value_sp(GetSP());
1167 if (value_sp)
1168 return value_sp->GetFormat();
Greg Claytone179a582011-01-05 18:43:15 +00001169 return eFormatDefault;
1170}
1171
1172void
1173SBValue::SetFormat (lldb::Format format)
1174{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001175 lldb::ValueObjectSP value_sp(GetSP());
1176 if (value_sp)
1177 value_sp->SetFormat(format);
Greg Claytone179a582011-01-05 18:43:15 +00001178}
1179
Enrico Granata979e20d2011-07-29 19:53:35 +00001180lldb::SBValue
1181SBValue::AddressOf()
1182{
1183 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001184 lldb::ValueObjectSP value_sp(GetSP());
1185 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001186 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001187 TargetSP target_sp (value_sp->GetTargetSP());
1188 if (target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001189 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001190 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001191 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001192 sb_value = value_sp->AddressOf (error);
Enrico Granata979e20d2011-07-29 19:53:35 +00001193 }
1194 }
1195 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1196 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001197 log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", value_sp.get(), value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001198
1199 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001200}
Enrico Granata91544802011-09-06 19:20:51 +00001201
1202lldb::addr_t
1203SBValue::GetLoadAddress()
1204{
1205 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001206 lldb::ValueObjectSP value_sp(GetSP());
1207 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001208 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001209 TargetSP target_sp (value_sp->GetTargetSP());
1210 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001211 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001212 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001213 const bool scalar_is_load_address = true;
1214 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001215 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001216 if (addr_type == eAddressTypeFile)
1217 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001218 Module* module = value_sp->GetModule();
Enrico Granata91544802011-09-06 19:20:51 +00001219 if (!module)
1220 value = LLDB_INVALID_ADDRESS;
1221 else
1222 {
1223 Address addr;
1224 module->ResolveFileAddress(value, addr);
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001225 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001226 }
1227 }
1228 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1229 value = LLDB_INVALID_ADDRESS;
1230 }
1231 }
1232 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1233 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001234 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", value_sp.get(), value);
Enrico Granata91544802011-09-06 19:20:51 +00001235
1236 return value;
1237}
1238
1239lldb::SBAddress
1240SBValue::GetAddress()
1241{
1242 Address addr;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001243 lldb::ValueObjectSP value_sp(GetSP());
1244 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001245 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001246 TargetSP target_sp (value_sp->GetTargetSP());
1247 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001248 {
1249 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001250 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001251 const bool scalar_is_load_address = true;
1252 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001253 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001254 if (addr_type == eAddressTypeFile)
1255 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001256 Module* module = value_sp->GetModule();
Enrico Granata91544802011-09-06 19:20:51 +00001257 if (module)
1258 module->ResolveFileAddress(value, addr);
1259 }
1260 else if (addr_type == eAddressTypeLoad)
1261 {
1262 // no need to check the return value on this.. if it can actually do the resolve
1263 // addr will be in the form (section,offset), otherwise it will simply be returned
1264 // as (NULL, value)
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001265 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001266 }
1267 }
1268 }
1269 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1270 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001271 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 +00001272 return SBAddress(new Address(addr));
1273}
1274
1275lldb::SBData
1276SBValue::GetPointeeData (uint32_t item_idx,
1277 uint32_t item_count)
1278{
1279 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001280 lldb::ValueObjectSP value_sp(GetSP());
1281 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001282 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001283 TargetSP target_sp (value_sp->GetTargetSP());
1284 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001285 {
1286 DataExtractorSP data_sp(new DataExtractor());
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001287 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001288 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
Enrico Granata91544802011-09-06 19:20:51 +00001289 if (data_sp->GetByteSize() > 0)
1290 *sb_data = data_sp;
1291 }
1292 }
1293 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1294 if (log)
1295 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001296 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001297 item_idx,
1298 item_count,
1299 sb_data.get());
1300
1301 return sb_data;
1302}
1303
1304lldb::SBData
1305SBValue::GetData ()
1306{
1307 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001308 lldb::ValueObjectSP value_sp(GetSP());
1309 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001310 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001311 TargetSP target_sp (value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001312 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001313 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001314 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001315 DataExtractorSP data_sp(new DataExtractor());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001316 value_sp->GetData(*data_sp);
Enrico Granata91544802011-09-06 19:20:51 +00001317 if (data_sp->GetByteSize() > 0)
1318 *sb_data = data_sp;
1319 }
1320 }
1321 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1322 if (log)
1323 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001324 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001325 sb_data.get());
1326
1327 return sb_data;
1328}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001329
1330lldb::SBWatchpoint
1331SBValue::Watch (bool resolve_location, bool read, bool write)
1332{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001333 SBWatchpoint sb_watchpoint;
1334
1335 // If the SBValue is not valid, there's no point in even trying to watch it.
1336 lldb::ValueObjectSP value_sp(GetSP());
1337 TargetSP target_sp (GetTarget().GetSP());
1338 if (value_sp && target_sp)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001339 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001340 // Read and Write cannot both be false.
1341 if (!read && !write)
1342 return sb_watchpoint;
1343
1344 // If the value is not in scope, don't try and watch and invalid value
1345 if (!IsInScope())
1346 return sb_watchpoint;
1347
1348 addr_t addr = GetLoadAddress();
1349 if (addr == LLDB_INVALID_ADDRESS)
1350 return sb_watchpoint;
1351 size_t byte_size = GetByteSize();
1352 if (byte_size == 0)
1353 return sb_watchpoint;
1354
1355 uint32_t watch_type = 0;
1356 if (read)
1357 watch_type |= LLDB_WATCH_TYPE_READ;
1358 if (write)
1359 watch_type |= LLDB_WATCH_TYPE_WRITE;
1360
1361 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type);
1362
1363 if (watchpoint_sp)
1364 {
1365 sb_watchpoint.SetSP (watchpoint_sp);
1366 Declaration decl;
1367 if (value_sp->GetDeclaration (decl))
1368 {
1369 if (decl.GetFile())
1370 {
1371 StreamString ss;
1372 // True to show fullpath for declaration file.
1373 decl.DumpStopContext(&ss, true);
1374 watchpoint_sp->SetDeclInfo(ss.GetString());
1375 }
1376 }
1377 }
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001378 }
1379 return sb_watchpoint;
1380}
1381
1382lldb::SBWatchpoint
1383SBValue::WatchPointee (bool resolve_location, bool read, bool write)
1384{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001385 SBWatchpoint sb_watchpoint;
1386 if (IsInScope() && GetType().IsPointerType())
1387 sb_watchpoint = Dereference().Watch (resolve_location, read, write);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001388 return sb_watchpoint;
1389}
1390