blob: bdf21f21f91246a873e5448d097684aba95788d6 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBValue.cpp ---------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Eli Friedman7a62c8b2010-06-09 07:44:37 +000010#include "lldb/API/SBValue.h"
Enrico Granatad760907c2012-02-17 03:18:30 +000011
Caroline Tice98f930f2010-09-20 05:20:02 +000012#include "lldb/API/SBStream.h"
Enrico Granatad760907c2012-02-17 03:18:30 +000013#include "lldb/API/SBTypeFilter.h"
14#include "lldb/API/SBTypeFormat.h"
15#include "lldb/API/SBTypeSummary.h"
16#include "lldb/API/SBTypeSynthetic.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017
Johnny Chenecd4feb2011-10-14 00:42:25 +000018#include "lldb/Breakpoint/Watchpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019#include "lldb/Core/DataExtractor.h"
Enrico Granatad760907c2012-02-17 03:18:30 +000020#include "lldb/Core/DataVisualization.h"
Caroline Tice7826c882010-10-26 03:11:13 +000021#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Core/Module.h"
Greg Clayton0fb0bcc2011-08-03 22:57:10 +000023#include "lldb/Core/Scalar.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024#include "lldb/Core/Stream.h"
25#include "lldb/Core/StreamFile.h"
26#include "lldb/Core/Value.h"
27#include "lldb/Core/ValueObject.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000028#include "lldb/Core/ValueObjectConstResult.h"
Chris Lattner24943d22010-06-08 16:52:24 +000029#include "lldb/Symbol/Block.h"
30#include "lldb/Symbol/ObjectFile.h"
Greg Clayton0a19a1b2012-02-04 02:27:34 +000031#include "lldb/Symbol/Type.h"
Chris Lattner24943d22010-06-08 16:52:24 +000032#include "lldb/Symbol/Variable.h"
Johnny Chenecd4feb2011-10-14 00:42:25 +000033#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000034#include "lldb/Target/ExecutionContext.h"
35#include "lldb/Target/Process.h"
36#include "lldb/Target/StackFrame.h"
Greg Claytonbdcda462010-12-20 20:49:23 +000037#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000038#include "lldb/Target/Thread.h"
39
Eli Friedman7a62c8b2010-06-09 07:44:37 +000040#include "lldb/API/SBProcess.h"
41#include "lldb/API/SBTarget.h"
42#include "lldb/API/SBThread.h"
43#include "lldb/API/SBFrame.h"
44#include "lldb/API/SBDebugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000045
46using namespace lldb;
47using namespace lldb_private;
48
49SBValue::SBValue () :
Greg Clayton63094e02010-06-23 01:19:29 +000050 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000051{
52}
53
Enrico Granatadba1de82012-03-27 02:35:13 +000054SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000055{
Enrico Granatadba1de82012-03-27 02:35:13 +000056 SetSP(value_sp); // whenever setting the SP call SetSP() since it knows how to deal with synthetic values properly
Chris Lattner24943d22010-06-08 16:52:24 +000057}
58
Enrico Granatadba1de82012-03-27 02:35:13 +000059SBValue::SBValue(const SBValue &rhs)
Greg Clayton538eb822010-11-05 23:17:00 +000060{
Enrico Granatadba1de82012-03-27 02:35:13 +000061 SetSP(rhs.m_opaque_sp); // whenever setting the SP call SetSP() since it knows how to deal with synthetic values properly
Greg Clayton538eb822010-11-05 23:17:00 +000062}
63
Greg Claytond68e0892011-09-09 23:04:00 +000064SBValue &
Greg Clayton538eb822010-11-05 23:17:00 +000065SBValue::operator = (const SBValue &rhs)
66{
67 if (this != &rhs)
Enrico Granatadba1de82012-03-27 02:35:13 +000068 {
69 SetSP(rhs.m_opaque_sp); // whenever setting the SP call SetSP() since it knows how to deal with synthetic values properly
70 }
Greg Clayton538eb822010-11-05 23:17:00 +000071 return *this;
72}
73
Chris Lattner24943d22010-06-08 16:52:24 +000074SBValue::~SBValue()
75{
76}
77
78bool
Greg Claytond68e0892011-09-09 23:04:00 +000079SBValue::IsValid ()
Chris Lattner24943d22010-06-08 16:52:24 +000080{
Greg Clayton49ce6822010-10-31 03:01:06 +000081 // If this function ever changes to anything that does more than just
82 // check if the opaque shared pointer is non NULL, then we need to update
83 // all "if (m_opaque_sp)" code in this file.
84 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000085}
86
Jim Inghame0bd5712011-12-19 20:39:44 +000087void
88SBValue::Clear()
89{
90 m_opaque_sp.reset();
91}
92
Greg Claytonc5f728c2010-10-06 22:10:17 +000093SBError
94SBValue::GetError()
95{
96 SBError sb_error;
97
Greg Clayton0a19a1b2012-02-04 02:27:34 +000098 lldb::ValueObjectSP value_sp(GetSP());
99 if (value_sp)
100 sb_error.SetError(value_sp->GetError());
Greg Clayton334d33a2012-01-30 07:41:31 +0000101 else
102 sb_error.SetErrorString("error: invalid value");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000103
104 return sb_error;
105}
106
Johnny Chen968958c2011-07-07 20:46:23 +0000107user_id_t
108SBValue::GetID()
109{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000110 lldb::ValueObjectSP value_sp(GetSP());
111 if (value_sp)
112 return value_sp->GetID();
Johnny Chen968958c2011-07-07 20:46:23 +0000113 return LLDB_INVALID_UID;
114}
115
Chris Lattner24943d22010-06-08 16:52:24 +0000116const char *
117SBValue::GetName()
118{
Greg Clayton49ce6822010-10-31 03:01:06 +0000119
120 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000121 lldb::ValueObjectSP value_sp(GetSP());
122 if (value_sp)
123 name = value_sp->GetName().GetCString();
Greg Clayton49ce6822010-10-31 03:01:06 +0000124
Greg Claytone005f2c2010-11-06 01:53:30 +0000125 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000126 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000127 {
128 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000129 log->Printf ("SBValue(%p)::GetName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000130 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000131 log->Printf ("SBValue(%p)::GetName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000132 }
Caroline Tice7826c882010-10-26 03:11:13 +0000133
Greg Clayton49ce6822010-10-31 03:01:06 +0000134 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000135}
136
137const char *
138SBValue::GetTypeName ()
139{
Greg Clayton49ce6822010-10-31 03:01:06 +0000140 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000141 lldb::ValueObjectSP value_sp(GetSP());
142 if (value_sp)
Greg Claytondc0a38c2012-03-26 23:03:23 +0000143 name = value_sp->GetQualifiedTypeName().GetCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000144 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000145 if (log)
146 {
147 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000148 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000149 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000150 log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000151 }
152
153 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000154}
155
156size_t
157SBValue::GetByteSize ()
158{
159 size_t result = 0;
160
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000161 lldb::ValueObjectSP value_sp(GetSP());
162 if (value_sp)
163 result = value_sp->GetByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000164
Greg Claytone005f2c2010-11-06 01:53:30 +0000165 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000166 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000167 log->Printf ("SBValue(%p)::GetByteSize () => %zu", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000168
Chris Lattner24943d22010-06-08 16:52:24 +0000169 return result;
170}
171
172bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000173SBValue::IsInScope ()
174{
Chris Lattner24943d22010-06-08 16:52:24 +0000175 bool result = false;
176
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000177 lldb::ValueObjectSP value_sp(GetSP());
178 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000179 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000180 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000181 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000182 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000183 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000184 result = value_sp->IsInScope ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000185 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000186 }
Chris Lattner24943d22010-06-08 16:52:24 +0000187
Greg Claytone005f2c2010-11-06 01:53:30 +0000188 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000189 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000190 log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000191
Chris Lattner24943d22010-06-08 16:52:24 +0000192 return result;
193}
194
195const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000196SBValue::GetValue ()
197{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000198 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
199
Greg Clayton49ce6822010-10-31 03:01:06 +0000200 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000201 lldb::ValueObjectSP value_sp(GetSP());
202 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000203 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000204 ProcessSP process_sp(value_sp->GetProcessSP());
205 Process::StopLocker stop_locker;
206 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000207 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000208 if (log)
209 log->Printf ("SBValue(%p)::GetValue() => error: process is running", value_sp.get());
210 }
211 else
212 {
213 TargetSP target_sp(value_sp->GetTargetSP());
214 if (target_sp)
215 {
216 Mutex::Locker api_locker (target_sp->GetAPIMutex());
217 cstr = value_sp->GetValueAsCString ();
218 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000219 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000220 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000221 if (log)
222 {
223 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000224 log->Printf ("SBValue(%p)::GetValue() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000225 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000226 log->Printf ("SBValue(%p)::GetValue() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000227 }
228
229 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000230}
231
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000232ValueType
233SBValue::GetValueType ()
234{
Greg Clayton49ce6822010-10-31 03:01:06 +0000235 ValueType result = eValueTypeInvalid;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000236 lldb::ValueObjectSP value_sp(GetSP());
237 if (value_sp)
238 result = value_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000239 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000240 if (log)
241 {
242 switch (result)
243 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000244 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break;
245 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break;
246 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break;
247 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break;
248 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break;
249 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break;
250 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break;
251 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break;
252 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", value_sp.get(), result); break;
Greg Clayton49ce6822010-10-31 03:01:06 +0000253 }
254 }
255 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000256}
257
Jim Ingham4ae51962010-09-10 23:12:17 +0000258const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000259SBValue::GetObjectDescription ()
260{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000261 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000262 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000263 lldb::ValueObjectSP value_sp(GetSP());
264 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000265 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000266 ProcessSP process_sp(value_sp->GetProcessSP());
267 Process::StopLocker stop_locker;
268 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000269 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000270 if (log)
271 log->Printf ("SBValue(%p)::GetObjectDescription() => error: process is running", value_sp.get());
272 }
273 else
274 {
275 TargetSP target_sp(value_sp->GetTargetSP());
276 if (target_sp)
277 {
278 Mutex::Locker api_locker (target_sp->GetAPIMutex());
279 cstr = value_sp->GetObjectDescription ();
280 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000281 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000282 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000283 if (log)
284 {
285 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000286 log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000287 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000288 log->Printf ("SBValue(%p)::GetObjectDescription() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000289 }
290 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000291}
292
Enrico Granata979e20d2011-07-29 19:53:35 +0000293SBType
294SBValue::GetType()
295{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000296 SBType sb_type;
297 lldb::ValueObjectSP value_sp(GetSP());
298 TypeImplSP type_sp;
299 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000300 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000301 type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType())));
302 sb_type.SetSP(type_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000303 }
304 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
305 if (log)
306 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000307 if (type_sp)
308 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000309 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000310 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000311 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000312 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000313}
314
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000315bool
316SBValue::GetValueDidChange ()
317{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000318 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000319 bool result = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000320 lldb::ValueObjectSP value_sp(GetSP());
321 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000322 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000323 ProcessSP process_sp(value_sp->GetProcessSP());
324 Process::StopLocker stop_locker;
325 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000326 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000327 if (log)
328 log->Printf ("SBValue(%p)::GetValueDidChange() => error: process is running", value_sp.get());
329 }
330 else
331 {
332 TargetSP target_sp(value_sp->GetTargetSP());
333 if (target_sp)
334 {
335 Mutex::Locker api_locker (target_sp->GetAPIMutex());
336 result = value_sp->GetValueDidChange ();
337 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000338 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000339 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000340 if (log)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000341 log->Printf ("SBValue(%p)::GetValueDidChange() => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000342
343 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000344}
345
Jason Molendac48ca822012-02-21 05:33:55 +0000346#ifndef LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000347const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000348SBValue::GetSummary ()
349{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000350 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000351 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000352 lldb::ValueObjectSP value_sp(GetSP());
353 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000354 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000355 ProcessSP process_sp(value_sp->GetProcessSP());
356 Process::StopLocker stop_locker;
357 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000358 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000359 if (log)
360 log->Printf ("SBValue(%p)::GetSummary() => error: process is running", value_sp.get());
361 }
362 else
363 {
364 TargetSP target_sp(value_sp->GetTargetSP());
365 if (target_sp)
366 {
367 Mutex::Locker api_locker (target_sp->GetAPIMutex());
368 cstr = value_sp->GetSummaryAsCString();
369 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000370 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000371 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000372 if (log)
373 {
374 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000375 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000376 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000377 log->Printf ("SBValue(%p)::GetSummary() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000378 }
379 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000380}
Jason Molendac48ca822012-02-21 05:33:55 +0000381#endif // LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000382
383const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000384SBValue::GetLocation ()
385{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000386 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000387 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000388 lldb::ValueObjectSP value_sp(GetSP());
389 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000390 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000391 ProcessSP process_sp(value_sp->GetProcessSP());
392 Process::StopLocker stop_locker;
393 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000394 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000395 if (log)
396 log->Printf ("SBValue(%p)::GetLocation() => error: process is running", value_sp.get());
397 }
398 else
399 {
400 TargetSP target_sp(value_sp->GetTargetSP());
401 if (target_sp)
402 {
403 Mutex::Locker api_locker (target_sp->GetAPIMutex());
404 cstr = value_sp->GetLocationAsCString();
405 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000406 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000407 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000408 if (log)
409 {
410 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000411 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000412 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000413 log->Printf ("SBValue(%p)::GetLocation() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000414 }
415 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000416}
417
418bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000419SBValue::SetValueFromCString (const char *value_str)
420{
Chris Lattner24943d22010-06-08 16:52:24 +0000421 bool success = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000422 lldb::ValueObjectSP value_sp(GetSP());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000423 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000424 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000425 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000426 ProcessSP process_sp(value_sp->GetProcessSP());
427 Process::StopLocker stop_locker;
428 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000429 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000430 if (log)
431 log->Printf ("SBValue(%p)::SetValueFromCString() => error: process is running", value_sp.get());
432 }
433 else
434 {
435 TargetSP target_sp(value_sp->GetTargetSP());
436 if (target_sp)
437 {
438 Mutex::Locker api_locker (target_sp->GetAPIMutex());
439 success = value_sp->SetValueFromCString (value_str);
440 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000441 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000442 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000443 if (log)
444 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i", value_sp.get(), value_str, success);
445
Chris Lattner24943d22010-06-08 16:52:24 +0000446 return success;
447}
448
Enrico Granatad760907c2012-02-17 03:18:30 +0000449lldb::SBTypeFormat
450SBValue::GetTypeFormat ()
451{
452 lldb::SBTypeFormat format;
453 lldb::ValueObjectSP value_sp(GetSP());
454 if (value_sp)
455 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000456 TargetSP target_sp(value_sp->GetTargetSP());
457 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000458 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000459 Mutex::Locker api_locker (target_sp->GetAPIMutex());
460 if (value_sp->UpdateValueIfNeeded(true))
461 {
462 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
463 if (format_sp)
464 format.SetSP(format_sp);
465 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000466 }
467 }
468 return format;
469}
470
Jason Molendac48ca822012-02-21 05:33:55 +0000471#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000472lldb::SBTypeSummary
473SBValue::GetTypeSummary ()
474{
475 lldb::SBTypeSummary summary;
476 lldb::ValueObjectSP value_sp(GetSP());
477 if (value_sp)
478 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000479 ProcessSP process_sp(value_sp->GetProcessSP());
480 Process::StopLocker stop_locker;
481 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000482 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000483 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
484 if (log)
485 log->Printf ("SBValue(%p)::GetTypeSummary() => error: process is running", value_sp.get());
486 }
487 else
488 {
489 TargetSP target_sp(value_sp->GetTargetSP());
490 if (target_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000491 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000492 Mutex::Locker api_locker (target_sp->GetAPIMutex());
493 if (value_sp->UpdateValueIfNeeded(true))
494 {
495 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
496 if (summary_sp)
497 summary.SetSP(summary_sp);
498 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000499 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000500 }
501 }
502 return summary;
503}
Jason Molendac48ca822012-02-21 05:33:55 +0000504#endif // LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000505
506lldb::SBTypeFilter
507SBValue::GetTypeFilter ()
508{
509 lldb::SBTypeFilter filter;
510 lldb::ValueObjectSP value_sp(GetSP());
511 if (value_sp)
512 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000513 ProcessSP process_sp(value_sp->GetProcessSP());
514 Process::StopLocker stop_locker;
515 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000516 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000517 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
518 if (log)
519 log->Printf ("SBValue(%p)::GetTypeFilter() => error: process is running", value_sp.get());
520 }
521 else
522 {
523 TargetSP target_sp(value_sp->GetTargetSP());
524 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000525 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000526 Mutex::Locker api_locker (target_sp->GetAPIMutex());
527 if (value_sp->UpdateValueIfNeeded(true))
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000528 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000529 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
530
531 if (synthetic_sp && !synthetic_sp->IsScripted())
532 {
533 TypeFilterImplSP filter_sp = STD_STATIC_POINTER_CAST(TypeFilterImpl,synthetic_sp);
534 filter.SetSP(filter_sp);
535 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000536 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000537 }
538 }
539 }
540 return filter;
541}
542
Jason Molendac48ca822012-02-21 05:33:55 +0000543#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000544lldb::SBTypeSynthetic
545SBValue::GetTypeSynthetic ()
546{
547 lldb::SBTypeSynthetic synthetic;
548 lldb::ValueObjectSP value_sp(GetSP());
549 if (value_sp)
550 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000551 ProcessSP process_sp(value_sp->GetProcessSP());
552 Process::StopLocker stop_locker;
553 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000554 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000555 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
556 if (log)
557 log->Printf ("SBValue(%p)::GetTypeSynthetic() => error: process is running", value_sp.get());
558 }
559 else
560 {
561 TargetSP target_sp(value_sp->GetTargetSP());
562 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000563 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000564 Mutex::Locker api_locker (target_sp->GetAPIMutex());
565 if (value_sp->UpdateValueIfNeeded(true))
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000566 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000567 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
568
569 if (children_sp && children_sp->IsScripted())
570 {
571 TypeSyntheticImplSP synth_sp = STD_STATIC_POINTER_CAST(TypeSyntheticImpl,children_sp);
572 synthetic.SetSP(synth_sp);
573 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000574 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000575 }
576 }
577 }
578 return synthetic;
579}
Jason Molendac48ca822012-02-21 05:33:55 +0000580#endif
Enrico Granatad760907c2012-02-17 03:18:30 +0000581
Enrico Granata979e20d2011-07-29 19:53:35 +0000582lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000583SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000584{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000585 lldb::SBValue sb_value;
586 lldb::ValueObjectSP value_sp(GetSP());
587 lldb::ValueObjectSP new_value_sp;
588 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000589 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000590 TypeImplSP type_sp (type.GetSP());
Enrico Granata979e20d2011-07-29 19:53:35 +0000591 if (type.IsValid())
592 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000593 sb_value = SBValue(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true));
594 new_value_sp = sb_value.GetSP();
595 if (new_value_sp)
596 new_value_sp->SetName(ConstString(name));
Enrico Granata979e20d2011-07-29 19:53:35 +0000597 }
598 }
599 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
600 if (log)
601 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000602 if (new_value_sp)
603 log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000604 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000605 log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000606 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000607 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000608}
609
610lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000611SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000612{
Greg Clayton4eb01a72012-01-31 04:25:15 +0000613 lldb::SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000614 lldb::ValueObjectSP value_sp(GetSP());
615 TypeImplSP type_sp (type.GetSP());
616 if (value_sp && type_sp)
617 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()));
Greg Clayton4eb01a72012-01-31 04:25:15 +0000618 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000619}
620
621lldb::SBValue
622SBValue::CreateValueFromExpression (const char *name, const char* expression)
623{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000624 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000625 lldb::SBValue sb_value;
626 lldb::ValueObjectSP value_sp(GetSP());
627 lldb::ValueObjectSP new_value_sp;
628 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000629 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000630 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000631 ProcessSP process_sp(exe_ctx.GetProcessSP());
632 Process::StopLocker stop_locker;
633 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Johnny Chen9fd2e382011-12-20 01:52:44 +0000634 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000635 if (log)
636 log->Printf ("SBValue(%p)::CreateValueFromExpression() => error: process is running", value_sp.get());
637 }
638 else
639 {
640 Target* target = exe_ctx.GetTargetPtr();
641 if (target)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000642 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000643 target->EvaluateExpression (expression,
644 exe_ctx.GetFramePtr(),
645 eExecutionPolicyOnlyWhenNeeded,
646 false, // coerce to id
647 true, // unwind on error
648 true, // keep in memory
649 eNoDynamicValues,
650 new_value_sp);
651 if (new_value_sp)
652 {
653 new_value_sp->SetName(ConstString(name));
654 sb_value.SetSP(new_value_sp);
655 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000656 }
Johnny Chen9fd2e382011-12-20 01:52:44 +0000657 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000658 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000659 if (log)
660 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000661 if (new_value_sp)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000662 log->Printf ("SBValue(%p)::GetChildFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
663 value_sp.get(),
664 name,
665 expression,
666 new_value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000667 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000668 log->Printf ("SBValue(%p)::GetChildFromExpression(name=\"%s\", expression=\"%s\") => NULL",
669 value_sp.get(),
670 name,
671 expression);
Enrico Granata979e20d2011-07-29 19:53:35 +0000672 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000673 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000674}
675
676lldb::SBValue
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000677SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000678{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000679 lldb::SBValue sb_value;
680 lldb::ValueObjectSP value_sp(GetSP());
681 lldb::ValueObjectSP new_value_sp;
682 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
683 if (value_sp && type_impl_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000684 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000685 ClangASTType pointee_ast_type(type_impl_sp->GetASTContext(), type_impl_sp->GetClangASTType().GetPointerType ());
686 lldb::TypeImplSP pointee_type_impl_sp (new TypeImpl(pointee_ast_type));
687 if (pointee_type_impl_sp)
Enrico Granatac9310302011-08-04 17:07:02 +0000688 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000689
690 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
691
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000692 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
693 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000694 pointee_type_impl_sp->GetASTContext(),
695 pointee_type_impl_sp->GetOpaqueQualType(),
696 ConstString(name),
697 buffer,
698 lldb::endian::InlHostByteOrder(),
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000699 exe_ctx.GetAddressByteSize()));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000700
701 if (ptr_result_valobj_sp)
702 {
703 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
704 Error err;
705 new_value_sp = ptr_result_valobj_sp->Dereference(err);
706 if (new_value_sp)
707 new_value_sp->SetName(ConstString(name));
708 }
709 sb_value.SetSP(new_value_sp);
Enrico Granatac9310302011-08-04 17:07:02 +0000710 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000711 }
712 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
713 if (log)
714 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000715 if (new_value_sp)
716 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000717 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000718 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
Johnny Chena713b862011-08-09 22:38:07 +0000719 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000720 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000721}
722
Enrico Granata91544802011-09-06 19:20:51 +0000723lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000724SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000725{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000726 lldb::SBValue sb_value;
727 lldb::ValueObjectSP new_value_sp;
728 lldb::ValueObjectSP value_sp(GetSP());
729 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +0000730 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000731 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
732
733 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000734 type.m_opaque_sp->GetASTContext() ,
735 type.m_opaque_sp->GetOpaqueQualType(),
736 ConstString(name),
737 *data.m_opaque_sp,
738 LLDB_INVALID_ADDRESS);
739 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
740 sb_value.SetSP(new_value_sp);
Enrico Granata91544802011-09-06 19:20:51 +0000741 }
742 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
743 if (log)
744 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000745 if (new_value_sp)
746 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000747 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000748 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +0000749 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000750 return sb_value;
Enrico Granata91544802011-09-06 19:20:51 +0000751}
752
Chris Lattner24943d22010-06-08 16:52:24 +0000753SBValue
754SBValue::GetChildAtIndex (uint32_t idx)
755{
Greg Clayton8f64c472011-07-15 19:31:49 +0000756 const bool can_create_synthetic = false;
757 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000758 lldb::ValueObjectSP value_sp(GetSP());
759 if (value_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000760 {
761 TargetSP target_sp(value_sp->GetTargetSP());
762 if (target_sp)
763 use_dynamic = target_sp->GetPreferDynamicValue();
764 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000765 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000766}
767
768SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000769SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000770{
Chris Lattner24943d22010-06-08 16:52:24 +0000771 lldb::ValueObjectSP child_sp;
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000772 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000773
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000774 lldb::ValueObjectSP value_sp(GetSP());
775 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000776 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000777 ProcessSP process_sp(value_sp->GetProcessSP());
778 Process::StopLocker stop_locker;
779 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000780 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000781 if (log)
782 log->Printf ("SBValue(%p)::GetChildAtIndex() => error: process is running", value_sp.get());
783 }
784 else
785 {
786 TargetSP target_sp(value_sp->GetTargetSP());
787 if (target_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000788 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000789 Mutex::Locker api_locker (target_sp->GetAPIMutex());
790 const bool can_create = true;
791 child_sp = value_sp->GetChildAtIndex (idx, can_create);
792 if (can_create_synthetic && !child_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000793 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000794 if (value_sp->IsPointerType())
795 {
796 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
797 }
798 else if (value_sp->IsArrayType())
799 {
800 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
801 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000802 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000803
804 if (child_sp)
Greg Clayton8f64c472011-07-15 19:31:49 +0000805 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000806 if (use_dynamic != lldb::eNoDynamicValues)
807 {
808 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
809 if (dynamic_sp)
810 child_sp = dynamic_sp;
811 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000812 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000813 }
Jim Inghame41494a2011-04-16 00:01:13 +0000814 }
815 }
816
Chris Lattner24943d22010-06-08 16:52:24 +0000817 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000818 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000819 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000820
Chris Lattner24943d22010-06-08 16:52:24 +0000821 return sb_value;
822}
823
824uint32_t
825SBValue::GetIndexOfChildWithName (const char *name)
826{
Greg Clayton49ce6822010-10-31 03:01:06 +0000827 uint32_t idx = UINT32_MAX;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000828 lldb::ValueObjectSP value_sp(GetSP());
829 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000830 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000831 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000832 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000833 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000834 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000835
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000836 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000837 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000838 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000839 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000840 if (log)
841 {
842 if (idx == UINT32_MAX)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000843 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000844 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000845 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
Greg Clayton49ce6822010-10-31 03:01:06 +0000846 }
847 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000848}
849
850SBValue
851SBValue::GetChildMemberWithName (const char *name)
852{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000853 lldb::ValueObjectSP value_sp(GetSP());
854 if (value_sp)
Johnny Chen446ccaa2011-06-29 21:19:39 +0000855 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000856 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000857 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000858 if (target_sp)
859 {
860 Mutex::Locker api_locker (target_sp->GetAPIMutex());
861 use_dynamic_value = target_sp->GetPreferDynamicValue();
862 }
Johnny Chen446ccaa2011-06-29 21:19:39 +0000863 return GetChildMemberWithName (name, use_dynamic_value);
864 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000865 return SBValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000866}
867
868SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000869SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000870{
Chris Lattner24943d22010-06-08 16:52:24 +0000871 lldb::ValueObjectSP child_sp;
872 const ConstString str_name (name);
873
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000874 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton905acaf2011-05-20 22:07:17 +0000875
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000876 lldb::ValueObjectSP value_sp(GetSP());
877 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000878 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000879 ProcessSP process_sp(value_sp->GetProcessSP());
880 Process::StopLocker stop_locker;
881 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Jim Inghame41494a2011-04-16 00:01:13 +0000882 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000883 if (log)
884 log->Printf ("SBValue(%p)::GetChildMemberWithName() => error: process is running", value_sp.get());
885 }
886 else
887 {
888 TargetSP target_sp(value_sp->GetTargetSP());
889 if (target_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000890 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000891 Mutex::Locker api_locker (target_sp->GetAPIMutex());
892 child_sp = value_sp->GetChildMemberWithName (str_name, true);
893 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000894 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000895 if (child_sp)
896 {
897 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
898 if (dynamic_sp)
899 child_sp = dynamic_sp;
900 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000901 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000902 }
Jim Inghame41494a2011-04-16 00:01:13 +0000903 }
904 }
905
Chris Lattner24943d22010-06-08 16:52:24 +0000906 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000907
Greg Clayton49ce6822010-10-31 03:01:06 +0000908 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000909 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000910
Chris Lattner24943d22010-06-08 16:52:24 +0000911 return sb_value;
912}
913
Enrico Granataf7a9b142011-07-15 02:26:42 +0000914lldb::SBValue
Jim Ingham1b425752011-12-08 19:44:08 +0000915SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
916{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000917 lldb::ValueObjectSP value_sp(GetSP());
918 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000919 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000920 ProcessSP process_sp(value_sp->GetProcessSP());
921 Process::StopLocker stop_locker;
922 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Jim Ingham1b425752011-12-08 19:44:08 +0000923 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000924 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
925 if (log)
926 log->Printf ("SBValue(%p)::GetDynamicValue() => error: process is running", value_sp.get());
927 }
928 else
929 {
930 TargetSP target_sp(value_sp->GetTargetSP());
931 if (target_sp)
932 {
933 Mutex::Locker api_locker (target_sp->GetAPIMutex());
934 return SBValue (value_sp->GetDynamicValue(use_dynamic));
935 }
Jim Ingham1b425752011-12-08 19:44:08 +0000936 }
937 }
938
939 return SBValue();
940}
941
942lldb::SBValue
943SBValue::GetStaticValue ()
944{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000945 lldb::ValueObjectSP value_sp(GetSP());
946 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000947 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000948 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000949 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000950 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000951 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000952 return SBValue(value_sp->GetStaticValue());
Jim Ingham1b425752011-12-08 19:44:08 +0000953 }
954 }
955
956 return SBValue();
957}
958
Enrico Granatadba1de82012-03-27 02:35:13 +0000959lldb::SBValue
960SBValue::GetNonSyntheticValue ()
961{
962 SBValue sb_value;
963 lldb::ValueObjectSP value_sp(GetSP());
964 if (value_sp)
965 {
966 if (value_sp->IsSynthetic())
967 {
968 TargetSP target_sp(value_sp->GetTargetSP());
969 if (target_sp)
970 {
971 Mutex::Locker api_locker (target_sp->GetAPIMutex());
972 // deliberately breaking the rules here to optimize the case where we DO NOT want
973 // the synthetic value to be returned to the user - if we did not do this, we would have to tell
974 // the target to suppress the synthetic value, and then return the flag to its original value
975 if (value_sp->GetParent())
976 sb_value.m_opaque_sp = value_sp->GetParent()->GetSP();
977 }
978 }
979 }
980 return sb_value;
981}
982
Jim Ingham1b425752011-12-08 19:44:08 +0000983bool
984SBValue::IsDynamic()
985{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000986 lldb::ValueObjectSP value_sp(GetSP());
987 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000988 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000989 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000990 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000991 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000992 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000993 return value_sp->IsDynamic();
Jim Ingham1b425752011-12-08 19:44:08 +0000994 }
995 }
996 return false;
997}
998
999lldb::SBValue
Enrico Granataf7a9b142011-07-15 02:26:42 +00001000SBValue::GetValueForExpressionPath(const char* expr_path)
1001{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001002 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf7a9b142011-07-15 02:26:42 +00001003 lldb::ValueObjectSP child_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001004 lldb::ValueObjectSP value_sp(GetSP());
1005 if (value_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +00001006 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001007 ProcessSP process_sp(value_sp->GetProcessSP());
1008 Process::StopLocker stop_locker;
1009 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granataf7a9b142011-07-15 02:26:42 +00001010 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001011 if (log)
1012 log->Printf ("SBValue(%p)::GetValueForExpressionPath() => error: process is running", value_sp.get());
1013 }
1014 else
1015 {
1016 TargetSP target_sp(value_sp->GetTargetSP());
1017 if (target_sp)
1018 {
1019 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1020 // using default values for all the fancy options, just do it if you can
1021 child_sp = value_sp->GetValueForExpressionPath(expr_path);
1022 }
Enrico Granataf7a9b142011-07-15 02:26:42 +00001023 }
1024 }
1025
1026 SBValue sb_value (child_sp);
1027
Enrico Granataf7a9b142011-07-15 02:26:42 +00001028 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001029 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 +00001030
1031 return sb_value;
1032}
Chris Lattner24943d22010-06-08 16:52:24 +00001033
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001034int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +00001035SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1036{
Jim Ingham574c3d62011-08-12 23:34:31 +00001037 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001038 lldb::ValueObjectSP value_sp(GetSP());
1039 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +00001040 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001041 ProcessSP process_sp(value_sp->GetProcessSP());
1042 Process::StopLocker stop_locker;
1043 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatac92eb402011-08-04 01:41:02 +00001044 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001045 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1046 if (log)
1047 log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
1048 error.SetErrorString("process is running");
Enrico Granatac92eb402011-08-04 01:41:02 +00001049 }
1050 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001051 {
1052 TargetSP target_sp(value_sp->GetTargetSP());
1053 if (target_sp)
1054 {
1055 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1056 Scalar scalar;
1057 if (value_sp->ResolveValue (scalar))
1058 return scalar.GetRawBits64(fail_value);
1059 else
1060 error.SetErrorString("could not get value");
1061 }
1062 else
1063 error.SetErrorString("could not get target");
1064 }
Enrico Granatac92eb402011-08-04 01:41:02 +00001065 }
1066 error.SetErrorString("invalid SBValue");
1067 return fail_value;
1068}
1069
1070uint64_t
1071SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1072{
Jim Ingham574c3d62011-08-12 23:34:31 +00001073 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001074 lldb::ValueObjectSP value_sp(GetSP());
1075 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +00001076 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001077 ProcessSP process_sp(value_sp->GetProcessSP());
1078 Process::StopLocker stop_locker;
1079 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatac92eb402011-08-04 01:41:02 +00001080 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001081 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1082 if (log)
1083 log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
1084 error.SetErrorString("process is running");
Enrico Granatac92eb402011-08-04 01:41:02 +00001085 }
1086 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001087 {
1088 TargetSP target_sp(value_sp->GetTargetSP());
1089 if (target_sp)
1090 {
1091 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1092 Scalar scalar;
1093 if (value_sp->ResolveValue (scalar))
1094 return scalar.GetRawBits64(fail_value);
1095 else
1096 error.SetErrorString("could not get value");
1097 }
1098 else
1099 error.SetErrorString("could not get target");
1100 }
Enrico Granatac92eb402011-08-04 01:41:02 +00001101 }
1102 error.SetErrorString("invalid SBValue");
1103 return fail_value;
1104}
1105
1106int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001107SBValue::GetValueAsSigned(int64_t fail_value)
1108{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001109 lldb::ValueObjectSP value_sp(GetSP());
1110 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001111 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001112 ProcessSP process_sp(value_sp->GetProcessSP());
1113 Process::StopLocker stop_locker;
1114 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001115 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001116 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1117 if (log)
1118 log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
1119 }
1120 else
1121 {
1122 TargetSP target_sp(value_sp->GetTargetSP());
1123 if (target_sp)
1124 {
1125 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1126 Scalar scalar;
1127 if (value_sp->ResolveValue (scalar))
1128 return scalar.GetRawBits64(fail_value);
1129 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001130 }
1131 }
1132 return fail_value;
1133}
1134
1135uint64_t
1136SBValue::GetValueAsUnsigned(uint64_t fail_value)
1137{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001138 lldb::ValueObjectSP value_sp(GetSP());
1139 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001140 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001141 ProcessSP process_sp(value_sp->GetProcessSP());
1142 Process::StopLocker stop_locker;
1143 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001144 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001145 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1146 if (log)
1147 log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
1148 }
1149 else
1150 {
1151 TargetSP target_sp(value_sp->GetTargetSP());
1152 if (target_sp)
1153 {
1154 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1155 Scalar scalar;
1156 if (value_sp->ResolveValue (scalar))
1157 return scalar.GetRawBits64(fail_value);
1158 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001159 }
1160 }
1161 return fail_value;
1162}
1163
Chris Lattner24943d22010-06-08 16:52:24 +00001164uint32_t
1165SBValue::GetNumChildren ()
1166{
1167 uint32_t num_children = 0;
1168
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001169 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001170 lldb::ValueObjectSP value_sp(GetSP());
1171 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001172 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001173 ProcessSP process_sp(value_sp->GetProcessSP());
1174 Process::StopLocker stop_locker;
1175 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +00001176 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001177 if (log)
1178 log->Printf ("SBValue(%p)::GetNumChildren() => error: process is running", value_sp.get());
1179 }
1180 else
1181 {
1182 TargetSP target_sp(value_sp->GetTargetSP());
1183 if (target_sp)
1184 {
1185 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001186
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001187 num_children = value_sp->GetNumChildren();
1188 }
Greg Claytonb9dcc512011-06-29 18:28:50 +00001189 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001190 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001191
Greg Clayton49ce6822010-10-31 03:01:06 +00001192 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001193 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +00001194
1195 return num_children;
1196}
1197
Chris Lattner24943d22010-06-08 16:52:24 +00001198
1199SBValue
1200SBValue::Dereference ()
1201{
Greg Clayton49ce6822010-10-31 03:01:06 +00001202 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001203 lldb::ValueObjectSP value_sp(GetSP());
1204 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001205 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001206 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001207 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001208 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001209 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001210
Greg Claytonb9dcc512011-06-29 18:28:50 +00001211 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001212 sb_value = value_sp->Dereference (error);
Greg Claytonb9dcc512011-06-29 18:28:50 +00001213 }
Chris Lattner24943d22010-06-08 16:52:24 +00001214 }
Greg Claytone005f2c2010-11-06 01:53:30 +00001215 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001216 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001217 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +00001218
1219 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +00001220}
1221
1222bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001223SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +00001224{
1225 bool is_ptr_type = false;
1226
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001227 lldb::ValueObjectSP value_sp(GetSP());
1228 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001229 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001230 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001231 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001232 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001233 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001234
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001235 is_ptr_type = value_sp->IsPointerType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001236 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001237 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001238
Greg Claytone005f2c2010-11-06 01:53:30 +00001239 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001240 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001241 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
Greg Clayton49ce6822010-10-31 03:01:06 +00001242
Chris Lattner24943d22010-06-08 16:52:24 +00001243
1244 return is_ptr_type;
1245}
1246
Chris Lattner24943d22010-06-08 16:52:24 +00001247void *
1248SBValue::GetOpaqueType()
1249{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001250 lldb::ValueObjectSP value_sp(GetSP());
1251 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001252 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001253 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001254 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001255 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001256 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001257
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001258 return value_sp->GetClangType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001259 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001260 }
Chris Lattner24943d22010-06-08 16:52:24 +00001261 return NULL;
1262}
1263
Enrico Granata979e20d2011-07-29 19:53:35 +00001264lldb::SBTarget
1265SBValue::GetTarget()
1266{
Greg Clayton334d33a2012-01-30 07:41:31 +00001267 SBTarget sb_target;
1268 TargetSP target_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001269 lldb::ValueObjectSP value_sp(GetSP());
1270 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001271 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001272 target_sp = value_sp->GetTargetSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001273 sb_target.SetSP (target_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001274 }
1275 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1276 if (log)
1277 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001278 if (target_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001279 log->Printf ("SBValue(%p)::GetTarget () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001280 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001281 log->Printf ("SBValue(%p)::GetTarget () => %p", value_sp.get(), target_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001282 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001283 return sb_target;
Enrico Granata979e20d2011-07-29 19:53:35 +00001284}
1285
1286lldb::SBProcess
1287SBValue::GetProcess()
1288{
Greg Clayton334d33a2012-01-30 07:41:31 +00001289 SBProcess sb_process;
1290 ProcessSP process_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001291 lldb::ValueObjectSP value_sp(GetSP());
1292 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001293 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001294 process_sp = value_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001295 if (process_sp)
1296 sb_process.SetSP (process_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001297 }
1298 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1299 if (log)
1300 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001301 if (process_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001302 log->Printf ("SBValue(%p)::GetProcess () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001303 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001304 log->Printf ("SBValue(%p)::GetProcess () => %p", value_sp.get(), process_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001305 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001306 return sb_process;
Enrico Granata979e20d2011-07-29 19:53:35 +00001307}
1308
1309lldb::SBThread
1310SBValue::GetThread()
1311{
Greg Clayton90c52142012-01-30 02:53:15 +00001312 SBThread sb_thread;
1313 ThreadSP thread_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001314 lldb::ValueObjectSP value_sp(GetSP());
1315 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001316 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001317 thread_sp = value_sp->GetThreadSP();
1318 sb_thread.SetThread(thread_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001319 }
1320 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1321 if (log)
1322 {
Greg Clayton90c52142012-01-30 02:53:15 +00001323 if (thread_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001324 log->Printf ("SBValue(%p)::GetThread () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001325 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001326 log->Printf ("SBValue(%p)::GetThread () => %p", value_sp.get(), thread_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001327 }
Greg Clayton90c52142012-01-30 02:53:15 +00001328 return sb_thread;
Enrico Granata979e20d2011-07-29 19:53:35 +00001329}
1330
1331lldb::SBFrame
1332SBValue::GetFrame()
1333{
Greg Clayton334d33a2012-01-30 07:41:31 +00001334 SBFrame sb_frame;
1335 StackFrameSP frame_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001336 lldb::ValueObjectSP value_sp(GetSP());
1337 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001338 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001339 frame_sp = value_sp->GetFrameSP();
1340 sb_frame.SetFrameSP (frame_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001341 }
1342 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1343 if (log)
1344 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001345 if (frame_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001346 log->Printf ("SBValue(%p)::GetFrame () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001347 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001348 log->Printf ("SBValue(%p)::GetFrame () => %p", value_sp.get(), frame_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001349 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001350 return sb_frame;
Enrico Granata979e20d2011-07-29 19:53:35 +00001351}
1352
1353
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001354lldb::ValueObjectSP
1355SBValue::GetSP () const
Chris Lattner24943d22010-06-08 16:52:24 +00001356{
Greg Clayton63094e02010-06-23 01:19:29 +00001357 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001358}
1359
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001360void
1361SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001362{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001363 m_opaque_sp = sp;
Enrico Granatadba1de82012-03-27 02:35:13 +00001364 if (IsValid() && m_opaque_sp->HasSyntheticValue())
1365 m_opaque_sp = m_opaque_sp->GetSyntheticValue();
Chris Lattner24943d22010-06-08 16:52:24 +00001366}
Caroline Tice98f930f2010-09-20 05:20:02 +00001367
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001368
Caroline Tice98f930f2010-09-20 05:20:02 +00001369bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001370SBValue::GetExpressionPath (SBStream &description)
1371{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001372 lldb::ValueObjectSP value_sp(GetSP());
1373 if (value_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +00001374 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001375 value_sp->GetExpressionPath (description.ref(), false);
Greg Claytonb01000f2011-01-17 03:46:26 +00001376 return true;
1377 }
1378 return false;
1379}
1380
1381bool
1382SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1383{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001384 lldb::ValueObjectSP value_sp(GetSP());
1385 if (value_sp)
Greg Claytonb01000f2011-01-17 03:46:26 +00001386 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001387 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +00001388 return true;
1389 }
1390 return false;
1391}
1392
1393bool
Caroline Tice98f930f2010-09-20 05:20:02 +00001394SBValue::GetDescription (SBStream &description)
1395{
Greg Clayton96154be2011-11-13 06:57:31 +00001396 Stream &strm = description.ref();
1397
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001398 lldb::ValueObjectSP value_sp(GetSP());
1399 if (value_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +00001400 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001401 ProcessSP process_sp(value_sp->GetProcessSP());
1402 Process::StopLocker stop_locker;
1403 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
1404 {
1405 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1406 if (log)
1407 log->Printf ("SBValue(%p)::GetDescription() => error: process is running", value_sp.get());
1408 }
1409 else
1410 {
1411 ValueObject::DumpValueObject (strm, value_sp.get());
1412 }
Caroline Tice98f930f2010-09-20 05:20:02 +00001413 }
1414 else
Greg Clayton96154be2011-11-13 06:57:31 +00001415 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +00001416
1417 return true;
1418}
Greg Claytone179a582011-01-05 18:43:15 +00001419
1420lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +00001421SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +00001422{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001423 lldb::ValueObjectSP value_sp(GetSP());
1424 if (value_sp)
1425 return value_sp->GetFormat();
Greg Claytone179a582011-01-05 18:43:15 +00001426 return eFormatDefault;
1427}
1428
1429void
1430SBValue::SetFormat (lldb::Format format)
1431{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001432 lldb::ValueObjectSP value_sp(GetSP());
1433 if (value_sp)
1434 value_sp->SetFormat(format);
Greg Claytone179a582011-01-05 18:43:15 +00001435}
1436
Enrico Granata979e20d2011-07-29 19:53:35 +00001437lldb::SBValue
1438SBValue::AddressOf()
1439{
1440 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001441 lldb::ValueObjectSP value_sp(GetSP());
1442 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001443 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001444 TargetSP target_sp (value_sp->GetTargetSP());
1445 if (target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001446 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001447 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001448 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001449 sb_value = value_sp->AddressOf (error);
Enrico Granata979e20d2011-07-29 19:53:35 +00001450 }
1451 }
1452 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1453 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001454 log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", value_sp.get(), value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001455
1456 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001457}
Enrico Granata91544802011-09-06 19:20:51 +00001458
1459lldb::addr_t
1460SBValue::GetLoadAddress()
1461{
1462 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001463 lldb::ValueObjectSP value_sp(GetSP());
1464 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001465 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001466 TargetSP target_sp (value_sp->GetTargetSP());
1467 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001468 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001469 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001470 const bool scalar_is_load_address = true;
1471 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001472 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001473 if (addr_type == eAddressTypeFile)
1474 {
Greg Clayton3508c382012-02-24 01:59:29 +00001475 ModuleSP module_sp (value_sp->GetModule());
1476 if (!module_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001477 value = LLDB_INVALID_ADDRESS;
1478 else
1479 {
1480 Address addr;
Greg Clayton3508c382012-02-24 01:59:29 +00001481 module_sp->ResolveFileAddress(value, addr);
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001482 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001483 }
1484 }
1485 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1486 value = LLDB_INVALID_ADDRESS;
1487 }
1488 }
1489 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1490 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001491 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", value_sp.get(), value);
Enrico Granata91544802011-09-06 19:20:51 +00001492
1493 return value;
1494}
1495
1496lldb::SBAddress
1497SBValue::GetAddress()
1498{
1499 Address addr;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001500 lldb::ValueObjectSP value_sp(GetSP());
1501 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001502 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001503 TargetSP target_sp (value_sp->GetTargetSP());
1504 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001505 {
1506 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001507 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001508 const bool scalar_is_load_address = true;
1509 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001510 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001511 if (addr_type == eAddressTypeFile)
1512 {
Greg Clayton3508c382012-02-24 01:59:29 +00001513 ModuleSP module_sp (value_sp->GetModule());
1514 if (module_sp)
1515 module_sp->ResolveFileAddress(value, addr);
Enrico Granata91544802011-09-06 19:20:51 +00001516 }
1517 else if (addr_type == eAddressTypeLoad)
1518 {
1519 // no need to check the return value on this.. if it can actually do the resolve
1520 // addr will be in the form (section,offset), otherwise it will simply be returned
1521 // as (NULL, value)
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001522 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001523 }
1524 }
1525 }
1526 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1527 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001528 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 +00001529 return SBAddress(new Address(addr));
1530}
1531
1532lldb::SBData
1533SBValue::GetPointeeData (uint32_t item_idx,
1534 uint32_t item_count)
1535{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001536 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata91544802011-09-06 19:20:51 +00001537 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001538 lldb::ValueObjectSP value_sp(GetSP());
1539 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001540 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001541 ProcessSP process_sp(value_sp->GetProcessSP());
1542 Process::StopLocker stop_locker;
1543 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata91544802011-09-06 19:20:51 +00001544 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001545 if (log)
1546 log->Printf ("SBValue(%p)::GetPointeeData() => error: process is running", value_sp.get());
1547 }
1548 else
1549 {
1550 TargetSP target_sp (value_sp->GetTargetSP());
1551 if (target_sp)
1552 {
1553 DataExtractorSP data_sp(new DataExtractor());
1554 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1555 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1556 if (data_sp->GetByteSize() > 0)
1557 *sb_data = data_sp;
1558 }
Enrico Granata91544802011-09-06 19:20:51 +00001559 }
1560 }
Enrico Granata91544802011-09-06 19:20:51 +00001561 if (log)
1562 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001563 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001564 item_idx,
1565 item_count,
1566 sb_data.get());
1567
1568 return sb_data;
1569}
1570
1571lldb::SBData
1572SBValue::GetData ()
1573{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001574 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata91544802011-09-06 19:20:51 +00001575 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001576 lldb::ValueObjectSP value_sp(GetSP());
1577 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001578 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001579 ProcessSP process_sp(value_sp->GetProcessSP());
1580 Process::StopLocker stop_locker;
1581 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata91544802011-09-06 19:20:51 +00001582 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001583 if (log)
1584 log->Printf ("SBValue(%p)::GetData() => error: process is running", value_sp.get());
1585 }
1586 else
1587 {
1588 TargetSP target_sp (value_sp->GetTargetSP());
1589 if (target_sp)
1590 {
1591 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1592 DataExtractorSP data_sp(new DataExtractor());
1593 value_sp->GetData(*data_sp);
1594 if (data_sp->GetByteSize() > 0)
1595 *sb_data = data_sp;
1596 }
Enrico Granata91544802011-09-06 19:20:51 +00001597 }
1598 }
Enrico Granata91544802011-09-06 19:20:51 +00001599 if (log)
1600 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001601 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001602 sb_data.get());
1603
1604 return sb_data;
1605}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001606
1607lldb::SBWatchpoint
1608SBValue::Watch (bool resolve_location, bool read, bool write)
1609{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001610 SBWatchpoint sb_watchpoint;
1611
1612 // If the SBValue is not valid, there's no point in even trying to watch it.
1613 lldb::ValueObjectSP value_sp(GetSP());
1614 TargetSP target_sp (GetTarget().GetSP());
1615 if (value_sp && target_sp)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001616 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001617 // Can't watch this if the process is running
1618 ProcessSP process_sp(value_sp->GetProcessSP());
1619 Process::StopLocker stop_locker;
1620 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
1621 {
1622 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1623 if (log)
1624 log->Printf ("SBValue(%p)::Watch() => error: process is running", value_sp.get());
1625 return sb_watchpoint;
1626 }
1627
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001628 // Read and Write cannot both be false.
1629 if (!read && !write)
1630 return sb_watchpoint;
1631
1632 // If the value is not in scope, don't try and watch and invalid value
1633 if (!IsInScope())
1634 return sb_watchpoint;
1635
1636 addr_t addr = GetLoadAddress();
1637 if (addr == LLDB_INVALID_ADDRESS)
1638 return sb_watchpoint;
1639 size_t byte_size = GetByteSize();
1640 if (byte_size == 0)
1641 return sb_watchpoint;
1642
1643 uint32_t watch_type = 0;
1644 if (read)
1645 watch_type |= LLDB_WATCH_TYPE_READ;
1646 if (write)
1647 watch_type |= LLDB_WATCH_TYPE_WRITE;
1648
1649 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type);
1650
1651 if (watchpoint_sp)
1652 {
1653 sb_watchpoint.SetSP (watchpoint_sp);
1654 Declaration decl;
1655 if (value_sp->GetDeclaration (decl))
1656 {
1657 if (decl.GetFile())
1658 {
1659 StreamString ss;
1660 // True to show fullpath for declaration file.
1661 decl.DumpStopContext(&ss, true);
1662 watchpoint_sp->SetDeclInfo(ss.GetString());
1663 }
1664 }
1665 }
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001666 }
1667 return sb_watchpoint;
1668}
1669
1670lldb::SBWatchpoint
1671SBValue::WatchPointee (bool resolve_location, bool read, bool write)
1672{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001673 SBWatchpoint sb_watchpoint;
1674 if (IsInScope() && GetType().IsPointerType())
1675 sb_watchpoint = Dereference().Watch (resolve_location, read, write);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001676 return sb_watchpoint;
1677}
1678