blob: bb656e57956e9814d90ba36ae99b4c08df03a75b [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{
Jim Ingham5b4905d2012-04-13 18:30:20 +0000296 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000297 SBType sb_type;
298 lldb::ValueObjectSP value_sp(GetSP());
299 TypeImplSP type_sp;
300 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000301 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000302 ProcessSP process_sp(value_sp->GetProcessSP());
303 Process::StopLocker stop_locker;
304 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
305 {
306 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000307 log->Printf ("SBValue(%p)::GetType() => error: process is running", value_sp.get());
Jim Ingham5b4905d2012-04-13 18:30:20 +0000308 }
309 else
310 {
311 TargetSP target_sp(value_sp->GetTargetSP());
312 if (target_sp)
313 {
314 Mutex::Locker api_locker (target_sp->GetAPIMutex());
315 type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType())));
316 sb_type.SetSP(type_sp);
317 }
318 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000319 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000320 if (log)
321 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000322 if (type_sp)
323 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000324 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000325 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000326 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000327 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000328}
329
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000330bool
331SBValue::GetValueDidChange ()
332{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000333 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000334 bool result = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000335 lldb::ValueObjectSP value_sp(GetSP());
336 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000337 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000338 ProcessSP process_sp(value_sp->GetProcessSP());
339 Process::StopLocker stop_locker;
340 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000341 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000342 if (log)
343 log->Printf ("SBValue(%p)::GetValueDidChange() => error: process is running", value_sp.get());
344 }
345 else
346 {
347 TargetSP target_sp(value_sp->GetTargetSP());
348 if (target_sp)
349 {
350 Mutex::Locker api_locker (target_sp->GetAPIMutex());
351 result = value_sp->GetValueDidChange ();
352 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000353 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000354 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000355 if (log)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000356 log->Printf ("SBValue(%p)::GetValueDidChange() => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000357
358 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000359}
360
Jason Molendac48ca822012-02-21 05:33:55 +0000361#ifndef LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000362const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000363SBValue::GetSummary ()
364{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000365 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000366 const char *cstr = NULL;
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 Clayton9f3c98e2012-04-06 02:17:47 +0000370 ProcessSP process_sp(value_sp->GetProcessSP());
371 Process::StopLocker stop_locker;
372 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000373 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000374 if (log)
375 log->Printf ("SBValue(%p)::GetSummary() => error: process is running", value_sp.get());
376 }
377 else
378 {
379 TargetSP target_sp(value_sp->GetTargetSP());
380 if (target_sp)
381 {
382 Mutex::Locker api_locker (target_sp->GetAPIMutex());
383 cstr = value_sp->GetSummaryAsCString();
384 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000385 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000386 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000387 if (log)
388 {
389 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000390 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000391 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000392 log->Printf ("SBValue(%p)::GetSummary() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000393 }
394 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000395}
Jason Molendac48ca822012-02-21 05:33:55 +0000396#endif // LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000397
398const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000399SBValue::GetLocation ()
400{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000401 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000402 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000403 lldb::ValueObjectSP value_sp(GetSP());
404 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000405 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000406 ProcessSP process_sp(value_sp->GetProcessSP());
407 Process::StopLocker stop_locker;
408 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000409 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000410 if (log)
411 log->Printf ("SBValue(%p)::GetLocation() => error: process is running", value_sp.get());
412 }
413 else
414 {
415 TargetSP target_sp(value_sp->GetTargetSP());
416 if (target_sp)
417 {
418 Mutex::Locker api_locker (target_sp->GetAPIMutex());
419 cstr = value_sp->GetLocationAsCString();
420 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000421 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000422 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000423 if (log)
424 {
425 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000426 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000427 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000428 log->Printf ("SBValue(%p)::GetLocation() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000429 }
430 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000431}
432
Enrico Granata651cbe22012-05-08 21:25:06 +0000433// Deprecated - use the one that takes an lldb::SBError
Chris Lattner24943d22010-06-08 16:52:24 +0000434bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000435SBValue::SetValueFromCString (const char *value_str)
436{
Enrico Granata651cbe22012-05-08 21:25:06 +0000437 lldb::SBError dummy;
438 return SetValueFromCString(value_str,dummy);
439}
440
441bool
442SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
443{
Chris Lattner24943d22010-06-08 16:52:24 +0000444 bool success = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000445 lldb::ValueObjectSP value_sp(GetSP());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000446 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000447 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000448 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000449 ProcessSP process_sp(value_sp->GetProcessSP());
450 Process::StopLocker stop_locker;
451 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000452 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000453 if (log)
454 log->Printf ("SBValue(%p)::SetValueFromCString() => error: process is running", value_sp.get());
455 }
456 else
457 {
458 TargetSP target_sp(value_sp->GetTargetSP());
459 if (target_sp)
460 {
461 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata651cbe22012-05-08 21:25:06 +0000462 success = value_sp->SetValueFromCString (value_str,error.ref());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000463 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000464 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000465 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000466 if (log)
467 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i", value_sp.get(), value_str, success);
468
Chris Lattner24943d22010-06-08 16:52:24 +0000469 return success;
470}
471
Enrico Granatad760907c2012-02-17 03:18:30 +0000472lldb::SBTypeFormat
473SBValue::GetTypeFormat ()
474{
475 lldb::SBTypeFormat format;
476 lldb::ValueObjectSP value_sp(GetSP());
477 if (value_sp)
478 {
Jim Ingham5b4905d2012-04-13 18:30:20 +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 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000483 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
484 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000485 log->Printf ("SBValue(%p)::GetTypeFormat() => error: process is running", value_sp.get());
Jim Ingham5b4905d2012-04-13 18:30:20 +0000486 }
487 else
488 {
489 TargetSP target_sp(value_sp->GetTargetSP());
490 if (target_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000491 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000492 Mutex::Locker api_locker (target_sp->GetAPIMutex());
493 if (value_sp->UpdateValueIfNeeded(true))
494 {
495 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
496 if (format_sp)
497 format.SetSP(format_sp);
498 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000499 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000500 }
501 }
502 return format;
503}
504
Jason Molendac48ca822012-02-21 05:33:55 +0000505#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000506lldb::SBTypeSummary
507SBValue::GetTypeSummary ()
508{
509 lldb::SBTypeSummary summary;
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)::GetTypeSummary() => error: process is running", value_sp.get());
520 }
521 else
522 {
523 TargetSP target_sp(value_sp->GetTargetSP());
524 if (target_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000525 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000526 Mutex::Locker api_locker (target_sp->GetAPIMutex());
527 if (value_sp->UpdateValueIfNeeded(true))
528 {
529 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
530 if (summary_sp)
531 summary.SetSP(summary_sp);
532 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000533 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000534 }
535 }
536 return summary;
537}
Jason Molendac48ca822012-02-21 05:33:55 +0000538#endif // LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000539
540lldb::SBTypeFilter
541SBValue::GetTypeFilter ()
542{
543 lldb::SBTypeFilter filter;
544 lldb::ValueObjectSP value_sp(GetSP());
545 if (value_sp)
546 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000547 ProcessSP process_sp(value_sp->GetProcessSP());
548 Process::StopLocker stop_locker;
549 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000550 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000551 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
552 if (log)
553 log->Printf ("SBValue(%p)::GetTypeFilter() => error: process is running", value_sp.get());
554 }
555 else
556 {
557 TargetSP target_sp(value_sp->GetTargetSP());
558 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000559 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000560 Mutex::Locker api_locker (target_sp->GetAPIMutex());
561 if (value_sp->UpdateValueIfNeeded(true))
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000562 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000563 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
564
565 if (synthetic_sp && !synthetic_sp->IsScripted())
566 {
567 TypeFilterImplSP filter_sp = STD_STATIC_POINTER_CAST(TypeFilterImpl,synthetic_sp);
568 filter.SetSP(filter_sp);
569 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000570 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000571 }
572 }
573 }
574 return filter;
575}
576
Jason Molendac48ca822012-02-21 05:33:55 +0000577#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000578lldb::SBTypeSynthetic
579SBValue::GetTypeSynthetic ()
580{
581 lldb::SBTypeSynthetic synthetic;
582 lldb::ValueObjectSP value_sp(GetSP());
583 if (value_sp)
584 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000585 ProcessSP process_sp(value_sp->GetProcessSP());
586 Process::StopLocker stop_locker;
587 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000588 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000589 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
590 if (log)
591 log->Printf ("SBValue(%p)::GetTypeSynthetic() => error: process is running", value_sp.get());
592 }
593 else
594 {
595 TargetSP target_sp(value_sp->GetTargetSP());
596 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000597 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000598 Mutex::Locker api_locker (target_sp->GetAPIMutex());
599 if (value_sp->UpdateValueIfNeeded(true))
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000600 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000601 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
602
603 if (children_sp && children_sp->IsScripted())
604 {
605 TypeSyntheticImplSP synth_sp = STD_STATIC_POINTER_CAST(TypeSyntheticImpl,children_sp);
606 synthetic.SetSP(synth_sp);
607 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000608 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000609 }
610 }
611 }
612 return synthetic;
613}
Jason Molendac48ca822012-02-21 05:33:55 +0000614#endif
Enrico Granatad760907c2012-02-17 03:18:30 +0000615
Enrico Granata979e20d2011-07-29 19:53:35 +0000616lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000617SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000618{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000619 lldb::SBValue sb_value;
620 lldb::ValueObjectSP value_sp(GetSP());
621 lldb::ValueObjectSP new_value_sp;
622 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000623 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000624 ProcessSP process_sp(value_sp->GetProcessSP());
625 Process::StopLocker stop_locker;
626 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata979e20d2011-07-29 19:53:35 +0000627 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000628 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
629 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000630 log->Printf ("SBValue(%p)::CreateChildAtOffset() => error: process is running", value_sp.get());
Jim Ingham5b4905d2012-04-13 18:30:20 +0000631 }
632 else
633 {
634 TargetSP target_sp(value_sp->GetTargetSP());
635 if (target_sp)
636 {
637 Mutex::Locker api_locker (target_sp->GetAPIMutex());
638 TypeImplSP type_sp (type.GetSP());
639 if (type.IsValid())
640 {
641 sb_value = SBValue(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true));
642 new_value_sp = sb_value.GetSP();
643 if (new_value_sp)
644 new_value_sp->SetName(ConstString(name));
645 }
646 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000647 }
648 }
649 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
650 if (log)
651 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000652 if (new_value_sp)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000653 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000654 else
Greg Clayton12b7ea32012-06-04 20:13:23 +0000655 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000656 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000657 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000658}
659
660lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000661SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000662{
Greg Clayton4eb01a72012-01-31 04:25:15 +0000663 lldb::SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000664 lldb::ValueObjectSP value_sp(GetSP());
665 TypeImplSP type_sp (type.GetSP());
666 if (value_sp && type_sp)
667 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()));
Greg Clayton4eb01a72012-01-31 04:25:15 +0000668 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000669}
670
671lldb::SBValue
672SBValue::CreateValueFromExpression (const char *name, const char* expression)
673{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000674 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000675 lldb::SBValue sb_value;
676 lldb::ValueObjectSP value_sp(GetSP());
677 lldb::ValueObjectSP new_value_sp;
678 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000679 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000680 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000681 ProcessSP process_sp(exe_ctx.GetProcessSP());
682 Process::StopLocker stop_locker;
683 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Johnny Chen9fd2e382011-12-20 01:52:44 +0000684 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000685 if (log)
686 log->Printf ("SBValue(%p)::CreateValueFromExpression() => error: process is running", value_sp.get());
687 }
688 else
689 {
690 Target* target = exe_ctx.GetTargetPtr();
691 if (target)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000692 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000693 target->EvaluateExpression (expression,
694 exe_ctx.GetFramePtr(),
695 eExecutionPolicyOnlyWhenNeeded,
696 false, // coerce to id
697 true, // unwind on error
698 true, // keep in memory
699 eNoDynamicValues,
700 new_value_sp);
701 if (new_value_sp)
702 {
703 new_value_sp->SetName(ConstString(name));
704 sb_value.SetSP(new_value_sp);
705 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000706 }
Johnny Chen9fd2e382011-12-20 01:52:44 +0000707 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000708 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000709 if (log)
710 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000711 if (new_value_sp)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000712 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000713 value_sp.get(),
714 name,
715 expression,
716 new_value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000717 else
Greg Clayton12b7ea32012-06-04 20:13:23 +0000718 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000719 value_sp.get(),
720 name,
721 expression);
Enrico Granata979e20d2011-07-29 19:53:35 +0000722 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000723 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000724}
725
726lldb::SBValue
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000727SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000728{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000729 lldb::SBValue sb_value;
730 lldb::ValueObjectSP value_sp(GetSP());
731 lldb::ValueObjectSP new_value_sp;
732 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
733 if (value_sp && type_impl_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000734 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000735 ClangASTType pointee_ast_type(type_impl_sp->GetASTContext(), type_impl_sp->GetClangASTType().GetPointerType ());
736 lldb::TypeImplSP pointee_type_impl_sp (new TypeImpl(pointee_ast_type));
737 if (pointee_type_impl_sp)
Enrico Granatac9310302011-08-04 17:07:02 +0000738 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000739
740 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
741
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000742 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
743 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000744 pointee_type_impl_sp->GetASTContext(),
745 pointee_type_impl_sp->GetOpaqueQualType(),
746 ConstString(name),
747 buffer,
748 lldb::endian::InlHostByteOrder(),
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000749 exe_ctx.GetAddressByteSize()));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000750
751 if (ptr_result_valobj_sp)
752 {
753 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
754 Error err;
755 new_value_sp = ptr_result_valobj_sp->Dereference(err);
756 if (new_value_sp)
757 new_value_sp->SetName(ConstString(name));
758 }
759 sb_value.SetSP(new_value_sp);
Enrico Granatac9310302011-08-04 17:07:02 +0000760 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000761 }
762 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
763 if (log)
764 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000765 if (new_value_sp)
766 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000767 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000768 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
Johnny Chena713b862011-08-09 22:38:07 +0000769 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000770 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000771}
772
Enrico Granata91544802011-09-06 19:20:51 +0000773lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000774SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000775{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000776 lldb::SBValue sb_value;
777 lldb::ValueObjectSP new_value_sp;
778 lldb::ValueObjectSP value_sp(GetSP());
779 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +0000780 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000781 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
782
783 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000784 type.m_opaque_sp->GetASTContext() ,
785 type.m_opaque_sp->GetOpaqueQualType(),
786 ConstString(name),
787 *data.m_opaque_sp,
788 LLDB_INVALID_ADDRESS);
789 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
790 sb_value.SetSP(new_value_sp);
Enrico Granata91544802011-09-06 19:20:51 +0000791 }
792 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
793 if (log)
794 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000795 if (new_value_sp)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000796 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000797 else
Greg Clayton12b7ea32012-06-04 20:13:23 +0000798 log->Printf ("SBValue(%p)::CreateValueFromData => NULL", value_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +0000799 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000800 return sb_value;
Enrico Granata91544802011-09-06 19:20:51 +0000801}
802
Chris Lattner24943d22010-06-08 16:52:24 +0000803SBValue
804SBValue::GetChildAtIndex (uint32_t idx)
805{
Greg Clayton8f64c472011-07-15 19:31:49 +0000806 const bool can_create_synthetic = false;
807 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000808 lldb::ValueObjectSP value_sp(GetSP());
809 if (value_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000810 {
811 TargetSP target_sp(value_sp->GetTargetSP());
812 if (target_sp)
813 use_dynamic = target_sp->GetPreferDynamicValue();
814 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000815 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000816}
817
818SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000819SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000820{
Chris Lattner24943d22010-06-08 16:52:24 +0000821 lldb::ValueObjectSP child_sp;
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000822 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000823
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000824 lldb::ValueObjectSP value_sp(GetSP());
825 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000826 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000827 ProcessSP process_sp(value_sp->GetProcessSP());
828 Process::StopLocker stop_locker;
829 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000830 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000831 if (log)
832 log->Printf ("SBValue(%p)::GetChildAtIndex() => error: process is running", value_sp.get());
833 }
834 else
835 {
836 TargetSP target_sp(value_sp->GetTargetSP());
837 if (target_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000838 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000839 Mutex::Locker api_locker (target_sp->GetAPIMutex());
840 const bool can_create = true;
841 child_sp = value_sp->GetChildAtIndex (idx, can_create);
842 if (can_create_synthetic && !child_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000843 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000844 if (value_sp->IsPointerType())
845 {
846 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
847 }
848 else if (value_sp->IsArrayType())
849 {
850 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
851 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000852 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000853
854 if (child_sp)
Greg Clayton8f64c472011-07-15 19:31:49 +0000855 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000856 if (use_dynamic != lldb::eNoDynamicValues)
857 {
858 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
859 if (dynamic_sp)
860 child_sp = dynamic_sp;
861 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000862 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000863 }
Jim Inghame41494a2011-04-16 00:01:13 +0000864 }
865 }
866
Chris Lattner24943d22010-06-08 16:52:24 +0000867 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000868 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000869 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000870
Chris Lattner24943d22010-06-08 16:52:24 +0000871 return sb_value;
872}
873
874uint32_t
875SBValue::GetIndexOfChildWithName (const char *name)
876{
Greg Clayton49ce6822010-10-31 03:01:06 +0000877 uint32_t idx = UINT32_MAX;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000878 lldb::ValueObjectSP value_sp(GetSP());
879 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000880 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000881 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000882 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000883 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000884 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000885
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000886 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000887 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000888 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000889 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000890 if (log)
891 {
892 if (idx == UINT32_MAX)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000893 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000894 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000895 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
Greg Clayton49ce6822010-10-31 03:01:06 +0000896 }
897 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000898}
899
900SBValue
901SBValue::GetChildMemberWithName (const char *name)
902{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000903 lldb::ValueObjectSP value_sp(GetSP());
904 if (value_sp)
Johnny Chen446ccaa2011-06-29 21:19:39 +0000905 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000906 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000907 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000908 if (target_sp)
909 {
910 Mutex::Locker api_locker (target_sp->GetAPIMutex());
911 use_dynamic_value = target_sp->GetPreferDynamicValue();
912 }
Johnny Chen446ccaa2011-06-29 21:19:39 +0000913 return GetChildMemberWithName (name, use_dynamic_value);
914 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000915 return SBValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000916}
917
918SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000919SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000920{
Chris Lattner24943d22010-06-08 16:52:24 +0000921 lldb::ValueObjectSP child_sp;
922 const ConstString str_name (name);
923
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000924 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton905acaf2011-05-20 22:07:17 +0000925
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000926 lldb::ValueObjectSP value_sp(GetSP());
927 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000928 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000929 ProcessSP process_sp(value_sp->GetProcessSP());
930 Process::StopLocker stop_locker;
931 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Jim Inghame41494a2011-04-16 00:01:13 +0000932 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000933 if (log)
934 log->Printf ("SBValue(%p)::GetChildMemberWithName() => error: process is running", value_sp.get());
935 }
936 else
937 {
938 TargetSP target_sp(value_sp->GetTargetSP());
939 if (target_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000940 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000941 Mutex::Locker api_locker (target_sp->GetAPIMutex());
942 child_sp = value_sp->GetChildMemberWithName (str_name, true);
943 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000944 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000945 if (child_sp)
946 {
947 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
948 if (dynamic_sp)
949 child_sp = dynamic_sp;
950 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000951 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000952 }
Jim Inghame41494a2011-04-16 00:01:13 +0000953 }
954 }
955
Chris Lattner24943d22010-06-08 16:52:24 +0000956 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000957
Greg Clayton49ce6822010-10-31 03:01:06 +0000958 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000959 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000960
Chris Lattner24943d22010-06-08 16:52:24 +0000961 return sb_value;
962}
963
Enrico Granataf7a9b142011-07-15 02:26:42 +0000964lldb::SBValue
Jim Ingham1b425752011-12-08 19:44:08 +0000965SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
966{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000967 lldb::ValueObjectSP value_sp(GetSP());
968 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000969 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000970 ProcessSP process_sp(value_sp->GetProcessSP());
971 Process::StopLocker stop_locker;
972 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Jim Ingham1b425752011-12-08 19:44:08 +0000973 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000974 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
975 if (log)
976 log->Printf ("SBValue(%p)::GetDynamicValue() => error: process is running", value_sp.get());
977 }
978 else
979 {
980 TargetSP target_sp(value_sp->GetTargetSP());
981 if (target_sp)
982 {
983 Mutex::Locker api_locker (target_sp->GetAPIMutex());
984 return SBValue (value_sp->GetDynamicValue(use_dynamic));
985 }
Jim Ingham1b425752011-12-08 19:44:08 +0000986 }
987 }
988
989 return SBValue();
990}
991
992lldb::SBValue
993SBValue::GetStaticValue ()
994{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000995 lldb::ValueObjectSP value_sp(GetSP());
996 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000997 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000998 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000999 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001000 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001001 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001002 return SBValue(value_sp->GetStaticValue());
Jim Ingham1b425752011-12-08 19:44:08 +00001003 }
1004 }
1005
1006 return SBValue();
1007}
1008
Enrico Granatadba1de82012-03-27 02:35:13 +00001009lldb::SBValue
1010SBValue::GetNonSyntheticValue ()
1011{
1012 SBValue sb_value;
1013 lldb::ValueObjectSP value_sp(GetSP());
1014 if (value_sp)
1015 {
1016 if (value_sp->IsSynthetic())
1017 {
1018 TargetSP target_sp(value_sp->GetTargetSP());
1019 if (target_sp)
1020 {
1021 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1022 // deliberately breaking the rules here to optimize the case where we DO NOT want
1023 // the synthetic value to be returned to the user - if we did not do this, we would have to tell
1024 // the target to suppress the synthetic value, and then return the flag to its original value
Enrico Granata4758a3c2012-05-08 18:47:08 +00001025 if (value_sp->GetNonSyntheticValue())
1026 sb_value.m_opaque_sp = value_sp->GetNonSyntheticValue();
Enrico Granatadba1de82012-03-27 02:35:13 +00001027 }
1028 }
1029 }
1030 return sb_value;
1031}
1032
Jim Ingham1b425752011-12-08 19:44:08 +00001033bool
1034SBValue::IsDynamic()
1035{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001036 lldb::ValueObjectSP value_sp(GetSP());
1037 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001038 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001039 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001040 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001041 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001042 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001043 return value_sp->IsDynamic();
Jim Ingham1b425752011-12-08 19:44:08 +00001044 }
1045 }
1046 return false;
1047}
1048
1049lldb::SBValue
Enrico Granataf7a9b142011-07-15 02:26:42 +00001050SBValue::GetValueForExpressionPath(const char* expr_path)
1051{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001052 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf7a9b142011-07-15 02:26:42 +00001053 lldb::ValueObjectSP child_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001054 lldb::ValueObjectSP value_sp(GetSP());
1055 if (value_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +00001056 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001057 ProcessSP process_sp(value_sp->GetProcessSP());
1058 Process::StopLocker stop_locker;
1059 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granataf7a9b142011-07-15 02:26:42 +00001060 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001061 if (log)
1062 log->Printf ("SBValue(%p)::GetValueForExpressionPath() => error: process is running", value_sp.get());
1063 }
1064 else
1065 {
1066 TargetSP target_sp(value_sp->GetTargetSP());
1067 if (target_sp)
1068 {
1069 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1070 // using default values for all the fancy options, just do it if you can
1071 child_sp = value_sp->GetValueForExpressionPath(expr_path);
1072 }
Enrico Granataf7a9b142011-07-15 02:26:42 +00001073 }
1074 }
1075
1076 SBValue sb_value (child_sp);
1077
Enrico Granataf7a9b142011-07-15 02:26:42 +00001078 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001079 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 +00001080
1081 return sb_value;
1082}
Chris Lattner24943d22010-06-08 16:52:24 +00001083
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001084int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +00001085SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1086{
Jim Ingham574c3d62011-08-12 23:34:31 +00001087 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001088 lldb::ValueObjectSP value_sp(GetSP());
1089 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +00001090 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001091 ProcessSP process_sp(value_sp->GetProcessSP());
1092 Process::StopLocker stop_locker;
1093 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatac92eb402011-08-04 01:41:02 +00001094 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001095 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1096 if (log)
1097 log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
1098 error.SetErrorString("process is running");
Enrico Granatac92eb402011-08-04 01:41:02 +00001099 }
1100 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001101 {
1102 TargetSP target_sp(value_sp->GetTargetSP());
1103 if (target_sp)
1104 {
1105 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1106 Scalar scalar;
1107 if (value_sp->ResolveValue (scalar))
1108 return scalar.GetRawBits64(fail_value);
1109 else
1110 error.SetErrorString("could not get value");
1111 }
1112 else
1113 error.SetErrorString("could not get target");
1114 }
Enrico Granatac92eb402011-08-04 01:41:02 +00001115 }
1116 error.SetErrorString("invalid SBValue");
1117 return fail_value;
1118}
1119
1120uint64_t
1121SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1122{
Jim Ingham574c3d62011-08-12 23:34:31 +00001123 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001124 lldb::ValueObjectSP value_sp(GetSP());
1125 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +00001126 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001127 ProcessSP process_sp(value_sp->GetProcessSP());
1128 Process::StopLocker stop_locker;
1129 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatac92eb402011-08-04 01:41:02 +00001130 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001131 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1132 if (log)
1133 log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
1134 error.SetErrorString("process is running");
Enrico Granatac92eb402011-08-04 01:41:02 +00001135 }
1136 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001137 {
1138 TargetSP target_sp(value_sp->GetTargetSP());
1139 if (target_sp)
1140 {
1141 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1142 Scalar scalar;
1143 if (value_sp->ResolveValue (scalar))
1144 return scalar.GetRawBits64(fail_value);
1145 else
1146 error.SetErrorString("could not get value");
1147 }
1148 else
1149 error.SetErrorString("could not get target");
1150 }
Enrico Granatac92eb402011-08-04 01:41:02 +00001151 }
1152 error.SetErrorString("invalid SBValue");
1153 return fail_value;
1154}
1155
1156int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001157SBValue::GetValueAsSigned(int64_t fail_value)
1158{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001159 lldb::ValueObjectSP value_sp(GetSP());
1160 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001161 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001162 ProcessSP process_sp(value_sp->GetProcessSP());
1163 Process::StopLocker stop_locker;
1164 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001165 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001166 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1167 if (log)
1168 log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
1169 }
1170 else
1171 {
1172 TargetSP target_sp(value_sp->GetTargetSP());
1173 if (target_sp)
1174 {
1175 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1176 Scalar scalar;
1177 if (value_sp->ResolveValue (scalar))
1178 return scalar.GetRawBits64(fail_value);
1179 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001180 }
1181 }
1182 return fail_value;
1183}
1184
1185uint64_t
1186SBValue::GetValueAsUnsigned(uint64_t fail_value)
1187{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001188 lldb::ValueObjectSP value_sp(GetSP());
1189 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001190 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001191 ProcessSP process_sp(value_sp->GetProcessSP());
1192 Process::StopLocker stop_locker;
1193 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001194 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001195 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1196 if (log)
1197 log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
1198 }
1199 else
1200 {
1201 TargetSP target_sp(value_sp->GetTargetSP());
1202 if (target_sp)
1203 {
1204 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1205 Scalar scalar;
1206 if (value_sp->ResolveValue (scalar))
1207 return scalar.GetRawBits64(fail_value);
1208 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001209 }
1210 }
1211 return fail_value;
1212}
1213
Chris Lattner24943d22010-06-08 16:52:24 +00001214uint32_t
1215SBValue::GetNumChildren ()
1216{
1217 uint32_t num_children = 0;
1218
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001219 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001220 lldb::ValueObjectSP value_sp(GetSP());
1221 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001222 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001223 ProcessSP process_sp(value_sp->GetProcessSP());
1224 Process::StopLocker stop_locker;
1225 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +00001226 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001227 if (log)
1228 log->Printf ("SBValue(%p)::GetNumChildren() => error: process is running", value_sp.get());
1229 }
1230 else
1231 {
1232 TargetSP target_sp(value_sp->GetTargetSP());
1233 if (target_sp)
1234 {
1235 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001236
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001237 num_children = value_sp->GetNumChildren();
1238 }
Greg Claytonb9dcc512011-06-29 18:28:50 +00001239 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001240 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001241
Greg Clayton49ce6822010-10-31 03:01:06 +00001242 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001243 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +00001244
1245 return num_children;
1246}
1247
Chris Lattner24943d22010-06-08 16:52:24 +00001248
1249SBValue
1250SBValue::Dereference ()
1251{
Greg Clayton49ce6822010-10-31 03:01:06 +00001252 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001253 lldb::ValueObjectSP value_sp(GetSP());
1254 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001255 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001256 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001257 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001258 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001259 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001260
Greg Claytonb9dcc512011-06-29 18:28:50 +00001261 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001262 sb_value = value_sp->Dereference (error);
Greg Claytonb9dcc512011-06-29 18:28:50 +00001263 }
Chris Lattner24943d22010-06-08 16:52:24 +00001264 }
Greg Claytone005f2c2010-11-06 01:53:30 +00001265 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001266 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001267 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +00001268
1269 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +00001270}
1271
1272bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001273SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +00001274{
1275 bool is_ptr_type = false;
1276
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001277 lldb::ValueObjectSP value_sp(GetSP());
1278 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001279 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001280 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001281 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001282 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001283 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001284
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001285 is_ptr_type = value_sp->IsPointerType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001286 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001287 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001288
Greg Claytone005f2c2010-11-06 01:53:30 +00001289 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001290 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001291 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
Greg Clayton49ce6822010-10-31 03:01:06 +00001292
Chris Lattner24943d22010-06-08 16:52:24 +00001293
1294 return is_ptr_type;
1295}
1296
Chris Lattner24943d22010-06-08 16:52:24 +00001297void *
1298SBValue::GetOpaqueType()
1299{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001300 lldb::ValueObjectSP value_sp(GetSP());
1301 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001302 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001303 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001304 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001305 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001306 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001307
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001308 return value_sp->GetClangType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001309 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001310 }
Chris Lattner24943d22010-06-08 16:52:24 +00001311 return NULL;
1312}
1313
Enrico Granata979e20d2011-07-29 19:53:35 +00001314lldb::SBTarget
1315SBValue::GetTarget()
1316{
Greg Clayton334d33a2012-01-30 07:41:31 +00001317 SBTarget sb_target;
1318 TargetSP target_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001319 lldb::ValueObjectSP value_sp(GetSP());
1320 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001321 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001322 target_sp = value_sp->GetTargetSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001323 sb_target.SetSP (target_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001324 }
1325 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1326 if (log)
1327 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001328 if (target_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001329 log->Printf ("SBValue(%p)::GetTarget () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001330 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001331 log->Printf ("SBValue(%p)::GetTarget () => %p", value_sp.get(), target_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001332 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001333 return sb_target;
Enrico Granata979e20d2011-07-29 19:53:35 +00001334}
1335
1336lldb::SBProcess
1337SBValue::GetProcess()
1338{
Greg Clayton334d33a2012-01-30 07:41:31 +00001339 SBProcess sb_process;
1340 ProcessSP process_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001341 lldb::ValueObjectSP value_sp(GetSP());
1342 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001343 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001344 process_sp = value_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001345 if (process_sp)
1346 sb_process.SetSP (process_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001347 }
1348 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1349 if (log)
1350 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001351 if (process_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001352 log->Printf ("SBValue(%p)::GetProcess () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001353 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001354 log->Printf ("SBValue(%p)::GetProcess () => %p", value_sp.get(), process_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001355 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001356 return sb_process;
Enrico Granata979e20d2011-07-29 19:53:35 +00001357}
1358
1359lldb::SBThread
1360SBValue::GetThread()
1361{
Greg Clayton90c52142012-01-30 02:53:15 +00001362 SBThread sb_thread;
1363 ThreadSP thread_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001364 lldb::ValueObjectSP value_sp(GetSP());
1365 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001366 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001367 thread_sp = value_sp->GetThreadSP();
1368 sb_thread.SetThread(thread_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001369 }
1370 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1371 if (log)
1372 {
Greg Clayton90c52142012-01-30 02:53:15 +00001373 if (thread_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001374 log->Printf ("SBValue(%p)::GetThread () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001375 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001376 log->Printf ("SBValue(%p)::GetThread () => %p", value_sp.get(), thread_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001377 }
Greg Clayton90c52142012-01-30 02:53:15 +00001378 return sb_thread;
Enrico Granata979e20d2011-07-29 19:53:35 +00001379}
1380
1381lldb::SBFrame
1382SBValue::GetFrame()
1383{
Greg Clayton334d33a2012-01-30 07:41:31 +00001384 SBFrame sb_frame;
1385 StackFrameSP frame_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001386 lldb::ValueObjectSP value_sp(GetSP());
1387 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001388 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001389 frame_sp = value_sp->GetFrameSP();
1390 sb_frame.SetFrameSP (frame_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001391 }
1392 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1393 if (log)
1394 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001395 if (frame_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001396 log->Printf ("SBValue(%p)::GetFrame () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001397 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001398 log->Printf ("SBValue(%p)::GetFrame () => %p", value_sp.get(), frame_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001399 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001400 return sb_frame;
Enrico Granata979e20d2011-07-29 19:53:35 +00001401}
1402
1403
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001404lldb::ValueObjectSP
1405SBValue::GetSP () const
Chris Lattner24943d22010-06-08 16:52:24 +00001406{
Greg Clayton63094e02010-06-23 01:19:29 +00001407 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001408}
1409
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001410void
1411SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001412{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001413 m_opaque_sp = sp;
Enrico Granatadba1de82012-03-27 02:35:13 +00001414 if (IsValid() && m_opaque_sp->HasSyntheticValue())
1415 m_opaque_sp = m_opaque_sp->GetSyntheticValue();
Chris Lattner24943d22010-06-08 16:52:24 +00001416}
Caroline Tice98f930f2010-09-20 05:20:02 +00001417
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001418
Caroline Tice98f930f2010-09-20 05:20:02 +00001419bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001420SBValue::GetExpressionPath (SBStream &description)
1421{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001422 lldb::ValueObjectSP value_sp(GetSP());
1423 if (value_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +00001424 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001425 value_sp->GetExpressionPath (description.ref(), false);
Greg Claytonb01000f2011-01-17 03:46:26 +00001426 return true;
1427 }
1428 return false;
1429}
1430
1431bool
1432SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1433{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001434 lldb::ValueObjectSP value_sp(GetSP());
1435 if (value_sp)
Greg Claytonb01000f2011-01-17 03:46:26 +00001436 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001437 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +00001438 return true;
1439 }
1440 return false;
1441}
1442
1443bool
Caroline Tice98f930f2010-09-20 05:20:02 +00001444SBValue::GetDescription (SBStream &description)
1445{
Greg Clayton96154be2011-11-13 06:57:31 +00001446 Stream &strm = description.ref();
1447
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001448 lldb::ValueObjectSP value_sp(GetSP());
1449 if (value_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +00001450 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001451 ProcessSP process_sp(value_sp->GetProcessSP());
1452 Process::StopLocker stop_locker;
1453 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
1454 {
1455 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1456 if (log)
1457 log->Printf ("SBValue(%p)::GetDescription() => error: process is running", value_sp.get());
1458 }
1459 else
1460 {
1461 ValueObject::DumpValueObject (strm, value_sp.get());
1462 }
Caroline Tice98f930f2010-09-20 05:20:02 +00001463 }
1464 else
Greg Clayton96154be2011-11-13 06:57:31 +00001465 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +00001466
1467 return true;
1468}
Greg Claytone179a582011-01-05 18:43:15 +00001469
1470lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +00001471SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +00001472{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001473 lldb::ValueObjectSP value_sp(GetSP());
1474 if (value_sp)
1475 return value_sp->GetFormat();
Greg Claytone179a582011-01-05 18:43:15 +00001476 return eFormatDefault;
1477}
1478
1479void
1480SBValue::SetFormat (lldb::Format format)
1481{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001482 lldb::ValueObjectSP value_sp(GetSP());
1483 if (value_sp)
1484 value_sp->SetFormat(format);
Greg Claytone179a582011-01-05 18:43:15 +00001485}
1486
Enrico Granata979e20d2011-07-29 19:53:35 +00001487lldb::SBValue
1488SBValue::AddressOf()
1489{
1490 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001491 lldb::ValueObjectSP value_sp(GetSP());
1492 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001493 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001494 TargetSP target_sp (value_sp->GetTargetSP());
1495 if (target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001496 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001497 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001498 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001499 sb_value = value_sp->AddressOf (error);
Enrico Granata979e20d2011-07-29 19:53:35 +00001500 }
1501 }
1502 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1503 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +00001504 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)", value_sp.get(), value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001505
1506 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001507}
Enrico Granata91544802011-09-06 19:20:51 +00001508
1509lldb::addr_t
1510SBValue::GetLoadAddress()
1511{
1512 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001513 lldb::ValueObjectSP value_sp(GetSP());
1514 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001515 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001516 TargetSP target_sp (value_sp->GetTargetSP());
1517 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001518 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001519 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001520 const bool scalar_is_load_address = true;
1521 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001522 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001523 if (addr_type == eAddressTypeFile)
1524 {
Greg Clayton3508c382012-02-24 01:59:29 +00001525 ModuleSP module_sp (value_sp->GetModule());
1526 if (!module_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001527 value = LLDB_INVALID_ADDRESS;
1528 else
1529 {
1530 Address addr;
Greg Clayton3508c382012-02-24 01:59:29 +00001531 module_sp->ResolveFileAddress(value, addr);
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001532 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001533 }
1534 }
1535 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1536 value = LLDB_INVALID_ADDRESS;
1537 }
1538 }
1539 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1540 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001541 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", value_sp.get(), value);
Enrico Granata91544802011-09-06 19:20:51 +00001542
1543 return value;
1544}
1545
1546lldb::SBAddress
1547SBValue::GetAddress()
1548{
1549 Address addr;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001550 lldb::ValueObjectSP value_sp(GetSP());
1551 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001552 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001553 TargetSP target_sp (value_sp->GetTargetSP());
1554 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001555 {
1556 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001557 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001558 const bool scalar_is_load_address = true;
1559 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001560 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001561 if (addr_type == eAddressTypeFile)
1562 {
Greg Clayton3508c382012-02-24 01:59:29 +00001563 ModuleSP module_sp (value_sp->GetModule());
1564 if (module_sp)
1565 module_sp->ResolveFileAddress(value, addr);
Enrico Granata91544802011-09-06 19:20:51 +00001566 }
1567 else if (addr_type == eAddressTypeLoad)
1568 {
1569 // no need to check the return value on this.. if it can actually do the resolve
1570 // addr will be in the form (section,offset), otherwise it will simply be returned
1571 // as (NULL, value)
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001572 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001573 }
1574 }
1575 }
1576 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1577 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001578 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 +00001579 return SBAddress(new Address(addr));
1580}
1581
1582lldb::SBData
1583SBValue::GetPointeeData (uint32_t item_idx,
1584 uint32_t item_count)
1585{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001586 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata91544802011-09-06 19:20:51 +00001587 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001588 lldb::ValueObjectSP value_sp(GetSP());
1589 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001590 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001591 ProcessSP process_sp(value_sp->GetProcessSP());
1592 Process::StopLocker stop_locker;
1593 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata91544802011-09-06 19:20:51 +00001594 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001595 if (log)
1596 log->Printf ("SBValue(%p)::GetPointeeData() => error: process is running", value_sp.get());
1597 }
1598 else
1599 {
1600 TargetSP target_sp (value_sp->GetTargetSP());
1601 if (target_sp)
1602 {
1603 DataExtractorSP data_sp(new DataExtractor());
1604 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1605 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1606 if (data_sp->GetByteSize() > 0)
1607 *sb_data = data_sp;
1608 }
Enrico Granata91544802011-09-06 19:20:51 +00001609 }
1610 }
Enrico Granata91544802011-09-06 19:20:51 +00001611 if (log)
1612 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001613 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001614 item_idx,
1615 item_count,
1616 sb_data.get());
1617
1618 return sb_data;
1619}
1620
1621lldb::SBData
1622SBValue::GetData ()
1623{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001624 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata91544802011-09-06 19:20:51 +00001625 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001626 lldb::ValueObjectSP value_sp(GetSP());
1627 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001628 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001629 ProcessSP process_sp(value_sp->GetProcessSP());
1630 Process::StopLocker stop_locker;
1631 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata91544802011-09-06 19:20:51 +00001632 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001633 if (log)
1634 log->Printf ("SBValue(%p)::GetData() => error: process is running", value_sp.get());
1635 }
1636 else
1637 {
1638 TargetSP target_sp (value_sp->GetTargetSP());
1639 if (target_sp)
1640 {
1641 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1642 DataExtractorSP data_sp(new DataExtractor());
1643 value_sp->GetData(*data_sp);
1644 if (data_sp->GetByteSize() > 0)
1645 *sb_data = data_sp;
1646 }
Enrico Granata91544802011-09-06 19:20:51 +00001647 }
1648 }
Enrico Granata91544802011-09-06 19:20:51 +00001649 if (log)
1650 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001651 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001652 sb_data.get());
1653
1654 return sb_data;
1655}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001656
1657lldb::SBWatchpoint
1658SBValue::Watch (bool resolve_location, bool read, bool write)
1659{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001660 SBWatchpoint sb_watchpoint;
1661
1662 // If the SBValue is not valid, there's no point in even trying to watch it.
1663 lldb::ValueObjectSP value_sp(GetSP());
1664 TargetSP target_sp (GetTarget().GetSP());
1665 if (value_sp && target_sp)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001666 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001667 // Can't watch this if the process is running
1668 ProcessSP process_sp(value_sp->GetProcessSP());
1669 Process::StopLocker stop_locker;
1670 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
1671 {
1672 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1673 if (log)
1674 log->Printf ("SBValue(%p)::Watch() => error: process is running", value_sp.get());
1675 return sb_watchpoint;
1676 }
1677
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001678 // Read and Write cannot both be false.
1679 if (!read && !write)
1680 return sb_watchpoint;
1681
1682 // If the value is not in scope, don't try and watch and invalid value
1683 if (!IsInScope())
1684 return sb_watchpoint;
1685
1686 addr_t addr = GetLoadAddress();
1687 if (addr == LLDB_INVALID_ADDRESS)
1688 return sb_watchpoint;
1689 size_t byte_size = GetByteSize();
1690 if (byte_size == 0)
1691 return sb_watchpoint;
1692
1693 uint32_t watch_type = 0;
1694 if (read)
1695 watch_type |= LLDB_WATCH_TYPE_READ;
1696 if (write)
1697 watch_type |= LLDB_WATCH_TYPE_WRITE;
1698
1699 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type);
1700
1701 if (watchpoint_sp)
1702 {
1703 sb_watchpoint.SetSP (watchpoint_sp);
1704 Declaration decl;
1705 if (value_sp->GetDeclaration (decl))
1706 {
1707 if (decl.GetFile())
1708 {
1709 StreamString ss;
1710 // True to show fullpath for declaration file.
1711 decl.DumpStopContext(&ss, true);
1712 watchpoint_sp->SetDeclInfo(ss.GetString());
1713 }
1714 }
1715 }
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001716 }
1717 return sb_watchpoint;
1718}
1719
1720lldb::SBWatchpoint
1721SBValue::WatchPointee (bool resolve_location, bool read, bool write)
1722{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001723 SBWatchpoint sb_watchpoint;
1724 if (IsInScope() && GetType().IsPointerType())
1725 sb_watchpoint = Dereference().Watch (resolve_location, read, write);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001726 return sb_watchpoint;
1727}
1728