blob: 6908c8f13d4d8cd830cd6c241fc344e1e0d7c1e4 [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)
307 log->Printf ("SBValue(%p)::GetValueDidChange() => error: process is running", value_sp.get());
308 }
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
433bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000434SBValue::SetValueFromCString (const char *value_str)
435{
Chris Lattner24943d22010-06-08 16:52:24 +0000436 bool success = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000437 lldb::ValueObjectSP value_sp(GetSP());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000438 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000439 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000440 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000441 ProcessSP process_sp(value_sp->GetProcessSP());
442 Process::StopLocker stop_locker;
443 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000444 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000445 if (log)
446 log->Printf ("SBValue(%p)::SetValueFromCString() => error: process is running", value_sp.get());
447 }
448 else
449 {
450 TargetSP target_sp(value_sp->GetTargetSP());
451 if (target_sp)
452 {
453 Mutex::Locker api_locker (target_sp->GetAPIMutex());
454 success = value_sp->SetValueFromCString (value_str);
455 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000456 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000457 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000458 if (log)
459 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i", value_sp.get(), value_str, success);
460
Chris Lattner24943d22010-06-08 16:52:24 +0000461 return success;
462}
463
Enrico Granatad760907c2012-02-17 03:18:30 +0000464lldb::SBTypeFormat
465SBValue::GetTypeFormat ()
466{
467 lldb::SBTypeFormat format;
468 lldb::ValueObjectSP value_sp(GetSP());
469 if (value_sp)
470 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000471 ProcessSP process_sp(value_sp->GetProcessSP());
472 Process::StopLocker stop_locker;
473 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000474 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000475 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
476 if (log)
477 log->Printf ("SBValue(%p)::GetTypeSummary() => error: process is running", value_sp.get());
478 }
479 else
480 {
481 TargetSP target_sp(value_sp->GetTargetSP());
482 if (target_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000483 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000484 Mutex::Locker api_locker (target_sp->GetAPIMutex());
485 if (value_sp->UpdateValueIfNeeded(true))
486 {
487 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
488 if (format_sp)
489 format.SetSP(format_sp);
490 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000491 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000492 }
493 }
494 return format;
495}
496
Jason Molendac48ca822012-02-21 05:33:55 +0000497#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000498lldb::SBTypeSummary
499SBValue::GetTypeSummary ()
500{
501 lldb::SBTypeSummary summary;
502 lldb::ValueObjectSP value_sp(GetSP());
503 if (value_sp)
504 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000505 ProcessSP process_sp(value_sp->GetProcessSP());
506 Process::StopLocker stop_locker;
507 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000508 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000509 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
510 if (log)
511 log->Printf ("SBValue(%p)::GetTypeSummary() => error: process is running", value_sp.get());
512 }
513 else
514 {
515 TargetSP target_sp(value_sp->GetTargetSP());
516 if (target_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000517 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000518 Mutex::Locker api_locker (target_sp->GetAPIMutex());
519 if (value_sp->UpdateValueIfNeeded(true))
520 {
521 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
522 if (summary_sp)
523 summary.SetSP(summary_sp);
524 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000525 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000526 }
527 }
528 return summary;
529}
Jason Molendac48ca822012-02-21 05:33:55 +0000530#endif // LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000531
532lldb::SBTypeFilter
533SBValue::GetTypeFilter ()
534{
535 lldb::SBTypeFilter filter;
536 lldb::ValueObjectSP value_sp(GetSP());
537 if (value_sp)
538 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000539 ProcessSP process_sp(value_sp->GetProcessSP());
540 Process::StopLocker stop_locker;
541 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000542 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000543 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
544 if (log)
545 log->Printf ("SBValue(%p)::GetTypeFilter() => error: process is running", value_sp.get());
546 }
547 else
548 {
549 TargetSP target_sp(value_sp->GetTargetSP());
550 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000551 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000552 Mutex::Locker api_locker (target_sp->GetAPIMutex());
553 if (value_sp->UpdateValueIfNeeded(true))
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000554 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000555 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
556
557 if (synthetic_sp && !synthetic_sp->IsScripted())
558 {
559 TypeFilterImplSP filter_sp = STD_STATIC_POINTER_CAST(TypeFilterImpl,synthetic_sp);
560 filter.SetSP(filter_sp);
561 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000562 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000563 }
564 }
565 }
566 return filter;
567}
568
Jason Molendac48ca822012-02-21 05:33:55 +0000569#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000570lldb::SBTypeSynthetic
571SBValue::GetTypeSynthetic ()
572{
573 lldb::SBTypeSynthetic synthetic;
574 lldb::ValueObjectSP value_sp(GetSP());
575 if (value_sp)
576 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000577 ProcessSP process_sp(value_sp->GetProcessSP());
578 Process::StopLocker stop_locker;
579 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000580 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000581 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
582 if (log)
583 log->Printf ("SBValue(%p)::GetTypeSynthetic() => error: process is running", value_sp.get());
584 }
585 else
586 {
587 TargetSP target_sp(value_sp->GetTargetSP());
588 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000589 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000590 Mutex::Locker api_locker (target_sp->GetAPIMutex());
591 if (value_sp->UpdateValueIfNeeded(true))
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000592 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000593 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
594
595 if (children_sp && children_sp->IsScripted())
596 {
597 TypeSyntheticImplSP synth_sp = STD_STATIC_POINTER_CAST(TypeSyntheticImpl,children_sp);
598 synthetic.SetSP(synth_sp);
599 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000600 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000601 }
602 }
603 }
604 return synthetic;
605}
Jason Molendac48ca822012-02-21 05:33:55 +0000606#endif
Enrico Granatad760907c2012-02-17 03:18:30 +0000607
Enrico Granata979e20d2011-07-29 19:53:35 +0000608lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000609SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000610{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000611 lldb::SBValue sb_value;
612 lldb::ValueObjectSP value_sp(GetSP());
613 lldb::ValueObjectSP new_value_sp;
614 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000615 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000616 ProcessSP process_sp(value_sp->GetProcessSP());
617 Process::StopLocker stop_locker;
618 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata979e20d2011-07-29 19:53:35 +0000619 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000620 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
621 if (log)
622 log->Printf ("SBValue(%p)::GetTypeSynthetic() => error: process is running", value_sp.get());
623 }
624 else
625 {
626 TargetSP target_sp(value_sp->GetTargetSP());
627 if (target_sp)
628 {
629 Mutex::Locker api_locker (target_sp->GetAPIMutex());
630 TypeImplSP type_sp (type.GetSP());
631 if (type.IsValid())
632 {
633 sb_value = SBValue(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true));
634 new_value_sp = sb_value.GetSP();
635 if (new_value_sp)
636 new_value_sp->SetName(ConstString(name));
637 }
638 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000639 }
640 }
641 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
642 if (log)
643 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000644 if (new_value_sp)
645 log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000646 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000647 log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000648 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000649 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000650}
651
652lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000653SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000654{
Greg Clayton4eb01a72012-01-31 04:25:15 +0000655 lldb::SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000656 lldb::ValueObjectSP value_sp(GetSP());
657 TypeImplSP type_sp (type.GetSP());
658 if (value_sp && type_sp)
659 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()));
Greg Clayton4eb01a72012-01-31 04:25:15 +0000660 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000661}
662
663lldb::SBValue
664SBValue::CreateValueFromExpression (const char *name, const char* expression)
665{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000666 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000667 lldb::SBValue sb_value;
668 lldb::ValueObjectSP value_sp(GetSP());
669 lldb::ValueObjectSP new_value_sp;
670 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000671 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000672 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000673 ProcessSP process_sp(exe_ctx.GetProcessSP());
674 Process::StopLocker stop_locker;
675 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Johnny Chen9fd2e382011-12-20 01:52:44 +0000676 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000677 if (log)
678 log->Printf ("SBValue(%p)::CreateValueFromExpression() => error: process is running", value_sp.get());
679 }
680 else
681 {
682 Target* target = exe_ctx.GetTargetPtr();
683 if (target)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000684 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000685 target->EvaluateExpression (expression,
686 exe_ctx.GetFramePtr(),
687 eExecutionPolicyOnlyWhenNeeded,
688 false, // coerce to id
689 true, // unwind on error
690 true, // keep in memory
691 eNoDynamicValues,
692 new_value_sp);
693 if (new_value_sp)
694 {
695 new_value_sp->SetName(ConstString(name));
696 sb_value.SetSP(new_value_sp);
697 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000698 }
Johnny Chen9fd2e382011-12-20 01:52:44 +0000699 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000700 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000701 if (log)
702 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000703 if (new_value_sp)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000704 log->Printf ("SBValue(%p)::GetChildFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
705 value_sp.get(),
706 name,
707 expression,
708 new_value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000709 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000710 log->Printf ("SBValue(%p)::GetChildFromExpression(name=\"%s\", expression=\"%s\") => NULL",
711 value_sp.get(),
712 name,
713 expression);
Enrico Granata979e20d2011-07-29 19:53:35 +0000714 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000715 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000716}
717
718lldb::SBValue
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000719SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000720{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000721 lldb::SBValue sb_value;
722 lldb::ValueObjectSP value_sp(GetSP());
723 lldb::ValueObjectSP new_value_sp;
724 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
725 if (value_sp && type_impl_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000726 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000727 ClangASTType pointee_ast_type(type_impl_sp->GetASTContext(), type_impl_sp->GetClangASTType().GetPointerType ());
728 lldb::TypeImplSP pointee_type_impl_sp (new TypeImpl(pointee_ast_type));
729 if (pointee_type_impl_sp)
Enrico Granatac9310302011-08-04 17:07:02 +0000730 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000731
732 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
733
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000734 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
735 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000736 pointee_type_impl_sp->GetASTContext(),
737 pointee_type_impl_sp->GetOpaqueQualType(),
738 ConstString(name),
739 buffer,
740 lldb::endian::InlHostByteOrder(),
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000741 exe_ctx.GetAddressByteSize()));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000742
743 if (ptr_result_valobj_sp)
744 {
745 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
746 Error err;
747 new_value_sp = ptr_result_valobj_sp->Dereference(err);
748 if (new_value_sp)
749 new_value_sp->SetName(ConstString(name));
750 }
751 sb_value.SetSP(new_value_sp);
Enrico Granatac9310302011-08-04 17:07:02 +0000752 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000753 }
754 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
755 if (log)
756 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000757 if (new_value_sp)
758 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000759 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000760 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
Johnny Chena713b862011-08-09 22:38:07 +0000761 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000762 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000763}
764
Enrico Granata91544802011-09-06 19:20:51 +0000765lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000766SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000767{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000768 lldb::SBValue sb_value;
769 lldb::ValueObjectSP new_value_sp;
770 lldb::ValueObjectSP value_sp(GetSP());
771 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +0000772 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000773 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
774
775 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000776 type.m_opaque_sp->GetASTContext() ,
777 type.m_opaque_sp->GetOpaqueQualType(),
778 ConstString(name),
779 *data.m_opaque_sp,
780 LLDB_INVALID_ADDRESS);
781 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
782 sb_value.SetSP(new_value_sp);
Enrico Granata91544802011-09-06 19:20:51 +0000783 }
784 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
785 if (log)
786 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000787 if (new_value_sp)
788 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000789 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000790 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +0000791 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000792 return sb_value;
Enrico Granata91544802011-09-06 19:20:51 +0000793}
794
Chris Lattner24943d22010-06-08 16:52:24 +0000795SBValue
796SBValue::GetChildAtIndex (uint32_t idx)
797{
Greg Clayton8f64c472011-07-15 19:31:49 +0000798 const bool can_create_synthetic = false;
799 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000800 lldb::ValueObjectSP value_sp(GetSP());
801 if (value_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000802 {
803 TargetSP target_sp(value_sp->GetTargetSP());
804 if (target_sp)
805 use_dynamic = target_sp->GetPreferDynamicValue();
806 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000807 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000808}
809
810SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000811SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000812{
Chris Lattner24943d22010-06-08 16:52:24 +0000813 lldb::ValueObjectSP child_sp;
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000814 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000815
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000816 lldb::ValueObjectSP value_sp(GetSP());
817 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000818 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000819 ProcessSP process_sp(value_sp->GetProcessSP());
820 Process::StopLocker stop_locker;
821 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000822 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000823 if (log)
824 log->Printf ("SBValue(%p)::GetChildAtIndex() => error: process is running", value_sp.get());
825 }
826 else
827 {
828 TargetSP target_sp(value_sp->GetTargetSP());
829 if (target_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000830 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000831 Mutex::Locker api_locker (target_sp->GetAPIMutex());
832 const bool can_create = true;
833 child_sp = value_sp->GetChildAtIndex (idx, can_create);
834 if (can_create_synthetic && !child_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000835 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000836 if (value_sp->IsPointerType())
837 {
838 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
839 }
840 else if (value_sp->IsArrayType())
841 {
842 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
843 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000844 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000845
846 if (child_sp)
Greg Clayton8f64c472011-07-15 19:31:49 +0000847 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000848 if (use_dynamic != lldb::eNoDynamicValues)
849 {
850 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
851 if (dynamic_sp)
852 child_sp = dynamic_sp;
853 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000854 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000855 }
Jim Inghame41494a2011-04-16 00:01:13 +0000856 }
857 }
858
Chris Lattner24943d22010-06-08 16:52:24 +0000859 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000860 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000861 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000862
Chris Lattner24943d22010-06-08 16:52:24 +0000863 return sb_value;
864}
865
866uint32_t
867SBValue::GetIndexOfChildWithName (const char *name)
868{
Greg Clayton49ce6822010-10-31 03:01:06 +0000869 uint32_t idx = UINT32_MAX;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000870 lldb::ValueObjectSP value_sp(GetSP());
871 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000872 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000873 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000874 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000875 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000876 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000877
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000878 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000879 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000880 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000881 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000882 if (log)
883 {
884 if (idx == UINT32_MAX)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000885 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000886 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000887 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
Greg Clayton49ce6822010-10-31 03:01:06 +0000888 }
889 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000890}
891
892SBValue
893SBValue::GetChildMemberWithName (const char *name)
894{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000895 lldb::ValueObjectSP value_sp(GetSP());
896 if (value_sp)
Johnny Chen446ccaa2011-06-29 21:19:39 +0000897 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000898 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000899 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000900 if (target_sp)
901 {
902 Mutex::Locker api_locker (target_sp->GetAPIMutex());
903 use_dynamic_value = target_sp->GetPreferDynamicValue();
904 }
Johnny Chen446ccaa2011-06-29 21:19:39 +0000905 return GetChildMemberWithName (name, use_dynamic_value);
906 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000907 return SBValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000908}
909
910SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000911SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000912{
Chris Lattner24943d22010-06-08 16:52:24 +0000913 lldb::ValueObjectSP child_sp;
914 const ConstString str_name (name);
915
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000916 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton905acaf2011-05-20 22:07:17 +0000917
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000918 lldb::ValueObjectSP value_sp(GetSP());
919 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000920 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000921 ProcessSP process_sp(value_sp->GetProcessSP());
922 Process::StopLocker stop_locker;
923 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Jim Inghame41494a2011-04-16 00:01:13 +0000924 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000925 if (log)
926 log->Printf ("SBValue(%p)::GetChildMemberWithName() => error: process is running", value_sp.get());
927 }
928 else
929 {
930 TargetSP target_sp(value_sp->GetTargetSP());
931 if (target_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000932 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000933 Mutex::Locker api_locker (target_sp->GetAPIMutex());
934 child_sp = value_sp->GetChildMemberWithName (str_name, true);
935 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000936 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000937 if (child_sp)
938 {
939 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
940 if (dynamic_sp)
941 child_sp = dynamic_sp;
942 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000943 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000944 }
Jim Inghame41494a2011-04-16 00:01:13 +0000945 }
946 }
947
Chris Lattner24943d22010-06-08 16:52:24 +0000948 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000949
Greg Clayton49ce6822010-10-31 03:01:06 +0000950 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000951 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000952
Chris Lattner24943d22010-06-08 16:52:24 +0000953 return sb_value;
954}
955
Enrico Granataf7a9b142011-07-15 02:26:42 +0000956lldb::SBValue
Jim Ingham1b425752011-12-08 19:44:08 +0000957SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
958{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000959 lldb::ValueObjectSP value_sp(GetSP());
960 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000961 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000962 ProcessSP process_sp(value_sp->GetProcessSP());
963 Process::StopLocker stop_locker;
964 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Jim Ingham1b425752011-12-08 19:44:08 +0000965 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000966 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
967 if (log)
968 log->Printf ("SBValue(%p)::GetDynamicValue() => error: process is running", value_sp.get());
969 }
970 else
971 {
972 TargetSP target_sp(value_sp->GetTargetSP());
973 if (target_sp)
974 {
975 Mutex::Locker api_locker (target_sp->GetAPIMutex());
976 return SBValue (value_sp->GetDynamicValue(use_dynamic));
977 }
Jim Ingham1b425752011-12-08 19:44:08 +0000978 }
979 }
980
981 return SBValue();
982}
983
984lldb::SBValue
985SBValue::GetStaticValue ()
986{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000987 lldb::ValueObjectSP value_sp(GetSP());
988 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000989 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000990 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000991 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000992 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000993 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000994 return SBValue(value_sp->GetStaticValue());
Jim Ingham1b425752011-12-08 19:44:08 +0000995 }
996 }
997
998 return SBValue();
999}
1000
Enrico Granatadba1de82012-03-27 02:35:13 +00001001lldb::SBValue
1002SBValue::GetNonSyntheticValue ()
1003{
1004 SBValue sb_value;
1005 lldb::ValueObjectSP value_sp(GetSP());
1006 if (value_sp)
1007 {
1008 if (value_sp->IsSynthetic())
1009 {
1010 TargetSP target_sp(value_sp->GetTargetSP());
1011 if (target_sp)
1012 {
1013 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1014 // deliberately breaking the rules here to optimize the case where we DO NOT want
1015 // the synthetic value to be returned to the user - if we did not do this, we would have to tell
1016 // the target to suppress the synthetic value, and then return the flag to its original value
1017 if (value_sp->GetParent())
1018 sb_value.m_opaque_sp = value_sp->GetParent()->GetSP();
1019 }
1020 }
1021 }
1022 return sb_value;
1023}
1024
Jim Ingham1b425752011-12-08 19:44:08 +00001025bool
1026SBValue::IsDynamic()
1027{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001028 lldb::ValueObjectSP value_sp(GetSP());
1029 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001030 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001031 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001032 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001033 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001034 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001035 return value_sp->IsDynamic();
Jim Ingham1b425752011-12-08 19:44:08 +00001036 }
1037 }
1038 return false;
1039}
1040
1041lldb::SBValue
Enrico Granataf7a9b142011-07-15 02:26:42 +00001042SBValue::GetValueForExpressionPath(const char* expr_path)
1043{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001044 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf7a9b142011-07-15 02:26:42 +00001045 lldb::ValueObjectSP child_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001046 lldb::ValueObjectSP value_sp(GetSP());
1047 if (value_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +00001048 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001049 ProcessSP process_sp(value_sp->GetProcessSP());
1050 Process::StopLocker stop_locker;
1051 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granataf7a9b142011-07-15 02:26:42 +00001052 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001053 if (log)
1054 log->Printf ("SBValue(%p)::GetValueForExpressionPath() => error: process is running", value_sp.get());
1055 }
1056 else
1057 {
1058 TargetSP target_sp(value_sp->GetTargetSP());
1059 if (target_sp)
1060 {
1061 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1062 // using default values for all the fancy options, just do it if you can
1063 child_sp = value_sp->GetValueForExpressionPath(expr_path);
1064 }
Enrico Granataf7a9b142011-07-15 02:26:42 +00001065 }
1066 }
1067
1068 SBValue sb_value (child_sp);
1069
Enrico Granataf7a9b142011-07-15 02:26:42 +00001070 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001071 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 +00001072
1073 return sb_value;
1074}
Chris Lattner24943d22010-06-08 16:52:24 +00001075
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001076int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +00001077SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1078{
Jim Ingham574c3d62011-08-12 23:34:31 +00001079 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001080 lldb::ValueObjectSP value_sp(GetSP());
1081 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +00001082 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001083 ProcessSP process_sp(value_sp->GetProcessSP());
1084 Process::StopLocker stop_locker;
1085 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatac92eb402011-08-04 01:41:02 +00001086 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001087 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1088 if (log)
1089 log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
1090 error.SetErrorString("process is running");
Enrico Granatac92eb402011-08-04 01:41:02 +00001091 }
1092 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001093 {
1094 TargetSP target_sp(value_sp->GetTargetSP());
1095 if (target_sp)
1096 {
1097 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1098 Scalar scalar;
1099 if (value_sp->ResolveValue (scalar))
1100 return scalar.GetRawBits64(fail_value);
1101 else
1102 error.SetErrorString("could not get value");
1103 }
1104 else
1105 error.SetErrorString("could not get target");
1106 }
Enrico Granatac92eb402011-08-04 01:41:02 +00001107 }
1108 error.SetErrorString("invalid SBValue");
1109 return fail_value;
1110}
1111
1112uint64_t
1113SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1114{
Jim Ingham574c3d62011-08-12 23:34:31 +00001115 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001116 lldb::ValueObjectSP value_sp(GetSP());
1117 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +00001118 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001119 ProcessSP process_sp(value_sp->GetProcessSP());
1120 Process::StopLocker stop_locker;
1121 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatac92eb402011-08-04 01:41:02 +00001122 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001123 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1124 if (log)
1125 log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
1126 error.SetErrorString("process is running");
Enrico Granatac92eb402011-08-04 01:41:02 +00001127 }
1128 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001129 {
1130 TargetSP target_sp(value_sp->GetTargetSP());
1131 if (target_sp)
1132 {
1133 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1134 Scalar scalar;
1135 if (value_sp->ResolveValue (scalar))
1136 return scalar.GetRawBits64(fail_value);
1137 else
1138 error.SetErrorString("could not get value");
1139 }
1140 else
1141 error.SetErrorString("could not get target");
1142 }
Enrico Granatac92eb402011-08-04 01:41:02 +00001143 }
1144 error.SetErrorString("invalid SBValue");
1145 return fail_value;
1146}
1147
1148int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001149SBValue::GetValueAsSigned(int64_t fail_value)
1150{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001151 lldb::ValueObjectSP value_sp(GetSP());
1152 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001153 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001154 ProcessSP process_sp(value_sp->GetProcessSP());
1155 Process::StopLocker stop_locker;
1156 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001157 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001158 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1159 if (log)
1160 log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
1161 }
1162 else
1163 {
1164 TargetSP target_sp(value_sp->GetTargetSP());
1165 if (target_sp)
1166 {
1167 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1168 Scalar scalar;
1169 if (value_sp->ResolveValue (scalar))
1170 return scalar.GetRawBits64(fail_value);
1171 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001172 }
1173 }
1174 return fail_value;
1175}
1176
1177uint64_t
1178SBValue::GetValueAsUnsigned(uint64_t fail_value)
1179{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001180 lldb::ValueObjectSP value_sp(GetSP());
1181 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001182 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001183 ProcessSP process_sp(value_sp->GetProcessSP());
1184 Process::StopLocker stop_locker;
1185 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001186 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001187 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1188 if (log)
1189 log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
1190 }
1191 else
1192 {
1193 TargetSP target_sp(value_sp->GetTargetSP());
1194 if (target_sp)
1195 {
1196 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1197 Scalar scalar;
1198 if (value_sp->ResolveValue (scalar))
1199 return scalar.GetRawBits64(fail_value);
1200 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001201 }
1202 }
1203 return fail_value;
1204}
1205
Chris Lattner24943d22010-06-08 16:52:24 +00001206uint32_t
1207SBValue::GetNumChildren ()
1208{
1209 uint32_t num_children = 0;
1210
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001211 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001212 lldb::ValueObjectSP value_sp(GetSP());
1213 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001214 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001215 ProcessSP process_sp(value_sp->GetProcessSP());
1216 Process::StopLocker stop_locker;
1217 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +00001218 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001219 if (log)
1220 log->Printf ("SBValue(%p)::GetNumChildren() => error: process is running", value_sp.get());
1221 }
1222 else
1223 {
1224 TargetSP target_sp(value_sp->GetTargetSP());
1225 if (target_sp)
1226 {
1227 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001228
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001229 num_children = value_sp->GetNumChildren();
1230 }
Greg Claytonb9dcc512011-06-29 18:28:50 +00001231 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001232 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001233
Greg Clayton49ce6822010-10-31 03:01:06 +00001234 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001235 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +00001236
1237 return num_children;
1238}
1239
Chris Lattner24943d22010-06-08 16:52:24 +00001240
1241SBValue
1242SBValue::Dereference ()
1243{
Greg Clayton49ce6822010-10-31 03:01:06 +00001244 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001245 lldb::ValueObjectSP value_sp(GetSP());
1246 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001247 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001248 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001249 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001250 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001251 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001252
Greg Claytonb9dcc512011-06-29 18:28:50 +00001253 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001254 sb_value = value_sp->Dereference (error);
Greg Claytonb9dcc512011-06-29 18:28:50 +00001255 }
Chris Lattner24943d22010-06-08 16:52:24 +00001256 }
Greg Claytone005f2c2010-11-06 01:53:30 +00001257 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001258 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001259 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +00001260
1261 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +00001262}
1263
1264bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001265SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +00001266{
1267 bool is_ptr_type = false;
1268
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001269 lldb::ValueObjectSP value_sp(GetSP());
1270 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001271 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001272 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001273 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001274 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001275 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001276
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001277 is_ptr_type = value_sp->IsPointerType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001278 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001279 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001280
Greg Claytone005f2c2010-11-06 01:53:30 +00001281 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001282 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001283 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
Greg Clayton49ce6822010-10-31 03:01:06 +00001284
Chris Lattner24943d22010-06-08 16:52:24 +00001285
1286 return is_ptr_type;
1287}
1288
Chris Lattner24943d22010-06-08 16:52:24 +00001289void *
1290SBValue::GetOpaqueType()
1291{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001292 lldb::ValueObjectSP value_sp(GetSP());
1293 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001294 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001295 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001296 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001297 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001298 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001299
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001300 return value_sp->GetClangType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001301 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001302 }
Chris Lattner24943d22010-06-08 16:52:24 +00001303 return NULL;
1304}
1305
Enrico Granata979e20d2011-07-29 19:53:35 +00001306lldb::SBTarget
1307SBValue::GetTarget()
1308{
Greg Clayton334d33a2012-01-30 07:41:31 +00001309 SBTarget sb_target;
1310 TargetSP target_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001311 lldb::ValueObjectSP value_sp(GetSP());
1312 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001313 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001314 target_sp = value_sp->GetTargetSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001315 sb_target.SetSP (target_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001316 }
1317 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1318 if (log)
1319 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001320 if (target_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001321 log->Printf ("SBValue(%p)::GetTarget () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001322 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001323 log->Printf ("SBValue(%p)::GetTarget () => %p", value_sp.get(), target_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001324 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001325 return sb_target;
Enrico Granata979e20d2011-07-29 19:53:35 +00001326}
1327
1328lldb::SBProcess
1329SBValue::GetProcess()
1330{
Greg Clayton334d33a2012-01-30 07:41:31 +00001331 SBProcess sb_process;
1332 ProcessSP process_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001333 lldb::ValueObjectSP value_sp(GetSP());
1334 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001335 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001336 process_sp = value_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001337 if (process_sp)
1338 sb_process.SetSP (process_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001339 }
1340 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1341 if (log)
1342 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001343 if (process_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001344 log->Printf ("SBValue(%p)::GetProcess () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001345 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001346 log->Printf ("SBValue(%p)::GetProcess () => %p", value_sp.get(), process_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001347 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001348 return sb_process;
Enrico Granata979e20d2011-07-29 19:53:35 +00001349}
1350
1351lldb::SBThread
1352SBValue::GetThread()
1353{
Greg Clayton90c52142012-01-30 02:53:15 +00001354 SBThread sb_thread;
1355 ThreadSP thread_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001356 lldb::ValueObjectSP value_sp(GetSP());
1357 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001358 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001359 thread_sp = value_sp->GetThreadSP();
1360 sb_thread.SetThread(thread_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001361 }
1362 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1363 if (log)
1364 {
Greg Clayton90c52142012-01-30 02:53:15 +00001365 if (thread_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001366 log->Printf ("SBValue(%p)::GetThread () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001367 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001368 log->Printf ("SBValue(%p)::GetThread () => %p", value_sp.get(), thread_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001369 }
Greg Clayton90c52142012-01-30 02:53:15 +00001370 return sb_thread;
Enrico Granata979e20d2011-07-29 19:53:35 +00001371}
1372
1373lldb::SBFrame
1374SBValue::GetFrame()
1375{
Greg Clayton334d33a2012-01-30 07:41:31 +00001376 SBFrame sb_frame;
1377 StackFrameSP frame_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001378 lldb::ValueObjectSP value_sp(GetSP());
1379 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001380 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001381 frame_sp = value_sp->GetFrameSP();
1382 sb_frame.SetFrameSP (frame_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001383 }
1384 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1385 if (log)
1386 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001387 if (frame_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001388 log->Printf ("SBValue(%p)::GetFrame () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001389 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001390 log->Printf ("SBValue(%p)::GetFrame () => %p", value_sp.get(), frame_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001391 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001392 return sb_frame;
Enrico Granata979e20d2011-07-29 19:53:35 +00001393}
1394
1395
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001396lldb::ValueObjectSP
1397SBValue::GetSP () const
Chris Lattner24943d22010-06-08 16:52:24 +00001398{
Greg Clayton63094e02010-06-23 01:19:29 +00001399 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001400}
1401
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001402void
1403SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001404{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001405 m_opaque_sp = sp;
Enrico Granatadba1de82012-03-27 02:35:13 +00001406 if (IsValid() && m_opaque_sp->HasSyntheticValue())
1407 m_opaque_sp = m_opaque_sp->GetSyntheticValue();
Chris Lattner24943d22010-06-08 16:52:24 +00001408}
Caroline Tice98f930f2010-09-20 05:20:02 +00001409
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001410
Caroline Tice98f930f2010-09-20 05:20:02 +00001411bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001412SBValue::GetExpressionPath (SBStream &description)
1413{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001414 lldb::ValueObjectSP value_sp(GetSP());
1415 if (value_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +00001416 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001417 value_sp->GetExpressionPath (description.ref(), false);
Greg Claytonb01000f2011-01-17 03:46:26 +00001418 return true;
1419 }
1420 return false;
1421}
1422
1423bool
1424SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1425{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001426 lldb::ValueObjectSP value_sp(GetSP());
1427 if (value_sp)
Greg Claytonb01000f2011-01-17 03:46:26 +00001428 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001429 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +00001430 return true;
1431 }
1432 return false;
1433}
1434
1435bool
Caroline Tice98f930f2010-09-20 05:20:02 +00001436SBValue::GetDescription (SBStream &description)
1437{
Greg Clayton96154be2011-11-13 06:57:31 +00001438 Stream &strm = description.ref();
1439
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001440 lldb::ValueObjectSP value_sp(GetSP());
1441 if (value_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +00001442 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001443 ProcessSP process_sp(value_sp->GetProcessSP());
1444 Process::StopLocker stop_locker;
1445 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
1446 {
1447 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1448 if (log)
1449 log->Printf ("SBValue(%p)::GetDescription() => error: process is running", value_sp.get());
1450 }
1451 else
1452 {
1453 ValueObject::DumpValueObject (strm, value_sp.get());
1454 }
Caroline Tice98f930f2010-09-20 05:20:02 +00001455 }
1456 else
Greg Clayton96154be2011-11-13 06:57:31 +00001457 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +00001458
1459 return true;
1460}
Greg Claytone179a582011-01-05 18:43:15 +00001461
1462lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +00001463SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +00001464{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001465 lldb::ValueObjectSP value_sp(GetSP());
1466 if (value_sp)
1467 return value_sp->GetFormat();
Greg Claytone179a582011-01-05 18:43:15 +00001468 return eFormatDefault;
1469}
1470
1471void
1472SBValue::SetFormat (lldb::Format format)
1473{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001474 lldb::ValueObjectSP value_sp(GetSP());
1475 if (value_sp)
1476 value_sp->SetFormat(format);
Greg Claytone179a582011-01-05 18:43:15 +00001477}
1478
Enrico Granata979e20d2011-07-29 19:53:35 +00001479lldb::SBValue
1480SBValue::AddressOf()
1481{
1482 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001483 lldb::ValueObjectSP value_sp(GetSP());
1484 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001485 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001486 TargetSP target_sp (value_sp->GetTargetSP());
1487 if (target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001488 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001489 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001490 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001491 sb_value = value_sp->AddressOf (error);
Enrico Granata979e20d2011-07-29 19:53:35 +00001492 }
1493 }
1494 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1495 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001496 log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", value_sp.get(), value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001497
1498 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001499}
Enrico Granata91544802011-09-06 19:20:51 +00001500
1501lldb::addr_t
1502SBValue::GetLoadAddress()
1503{
1504 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001505 lldb::ValueObjectSP value_sp(GetSP());
1506 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001507 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001508 TargetSP target_sp (value_sp->GetTargetSP());
1509 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001510 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001511 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001512 const bool scalar_is_load_address = true;
1513 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001514 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001515 if (addr_type == eAddressTypeFile)
1516 {
Greg Clayton3508c382012-02-24 01:59:29 +00001517 ModuleSP module_sp (value_sp->GetModule());
1518 if (!module_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001519 value = LLDB_INVALID_ADDRESS;
1520 else
1521 {
1522 Address addr;
Greg Clayton3508c382012-02-24 01:59:29 +00001523 module_sp->ResolveFileAddress(value, addr);
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001524 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001525 }
1526 }
1527 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1528 value = LLDB_INVALID_ADDRESS;
1529 }
1530 }
1531 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1532 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001533 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", value_sp.get(), value);
Enrico Granata91544802011-09-06 19:20:51 +00001534
1535 return value;
1536}
1537
1538lldb::SBAddress
1539SBValue::GetAddress()
1540{
1541 Address addr;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001542 lldb::ValueObjectSP value_sp(GetSP());
1543 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001544 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001545 TargetSP target_sp (value_sp->GetTargetSP());
1546 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001547 {
1548 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001549 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001550 const bool scalar_is_load_address = true;
1551 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001552 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001553 if (addr_type == eAddressTypeFile)
1554 {
Greg Clayton3508c382012-02-24 01:59:29 +00001555 ModuleSP module_sp (value_sp->GetModule());
1556 if (module_sp)
1557 module_sp->ResolveFileAddress(value, addr);
Enrico Granata91544802011-09-06 19:20:51 +00001558 }
1559 else if (addr_type == eAddressTypeLoad)
1560 {
1561 // no need to check the return value on this.. if it can actually do the resolve
1562 // addr will be in the form (section,offset), otherwise it will simply be returned
1563 // as (NULL, value)
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001564 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001565 }
1566 }
1567 }
1568 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1569 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001570 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 +00001571 return SBAddress(new Address(addr));
1572}
1573
1574lldb::SBData
1575SBValue::GetPointeeData (uint32_t item_idx,
1576 uint32_t item_count)
1577{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001578 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata91544802011-09-06 19:20:51 +00001579 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001580 lldb::ValueObjectSP value_sp(GetSP());
1581 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001582 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001583 ProcessSP process_sp(value_sp->GetProcessSP());
1584 Process::StopLocker stop_locker;
1585 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata91544802011-09-06 19:20:51 +00001586 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001587 if (log)
1588 log->Printf ("SBValue(%p)::GetPointeeData() => error: process is running", value_sp.get());
1589 }
1590 else
1591 {
1592 TargetSP target_sp (value_sp->GetTargetSP());
1593 if (target_sp)
1594 {
1595 DataExtractorSP data_sp(new DataExtractor());
1596 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1597 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1598 if (data_sp->GetByteSize() > 0)
1599 *sb_data = data_sp;
1600 }
Enrico Granata91544802011-09-06 19:20:51 +00001601 }
1602 }
Enrico Granata91544802011-09-06 19:20:51 +00001603 if (log)
1604 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001605 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001606 item_idx,
1607 item_count,
1608 sb_data.get());
1609
1610 return sb_data;
1611}
1612
1613lldb::SBData
1614SBValue::GetData ()
1615{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001616 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata91544802011-09-06 19:20:51 +00001617 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001618 lldb::ValueObjectSP value_sp(GetSP());
1619 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001620 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001621 ProcessSP process_sp(value_sp->GetProcessSP());
1622 Process::StopLocker stop_locker;
1623 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata91544802011-09-06 19:20:51 +00001624 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001625 if (log)
1626 log->Printf ("SBValue(%p)::GetData() => error: process is running", value_sp.get());
1627 }
1628 else
1629 {
1630 TargetSP target_sp (value_sp->GetTargetSP());
1631 if (target_sp)
1632 {
1633 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1634 DataExtractorSP data_sp(new DataExtractor());
1635 value_sp->GetData(*data_sp);
1636 if (data_sp->GetByteSize() > 0)
1637 *sb_data = data_sp;
1638 }
Enrico Granata91544802011-09-06 19:20:51 +00001639 }
1640 }
Enrico Granata91544802011-09-06 19:20:51 +00001641 if (log)
1642 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001643 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001644 sb_data.get());
1645
1646 return sb_data;
1647}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001648
1649lldb::SBWatchpoint
1650SBValue::Watch (bool resolve_location, bool read, bool write)
1651{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001652 SBWatchpoint sb_watchpoint;
1653
1654 // If the SBValue is not valid, there's no point in even trying to watch it.
1655 lldb::ValueObjectSP value_sp(GetSP());
1656 TargetSP target_sp (GetTarget().GetSP());
1657 if (value_sp && target_sp)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001658 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001659 // Can't watch this if the process is running
1660 ProcessSP process_sp(value_sp->GetProcessSP());
1661 Process::StopLocker stop_locker;
1662 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
1663 {
1664 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1665 if (log)
1666 log->Printf ("SBValue(%p)::Watch() => error: process is running", value_sp.get());
1667 return sb_watchpoint;
1668 }
1669
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001670 // Read and Write cannot both be false.
1671 if (!read && !write)
1672 return sb_watchpoint;
1673
1674 // If the value is not in scope, don't try and watch and invalid value
1675 if (!IsInScope())
1676 return sb_watchpoint;
1677
1678 addr_t addr = GetLoadAddress();
1679 if (addr == LLDB_INVALID_ADDRESS)
1680 return sb_watchpoint;
1681 size_t byte_size = GetByteSize();
1682 if (byte_size == 0)
1683 return sb_watchpoint;
1684
1685 uint32_t watch_type = 0;
1686 if (read)
1687 watch_type |= LLDB_WATCH_TYPE_READ;
1688 if (write)
1689 watch_type |= LLDB_WATCH_TYPE_WRITE;
1690
1691 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type);
1692
1693 if (watchpoint_sp)
1694 {
1695 sb_watchpoint.SetSP (watchpoint_sp);
1696 Declaration decl;
1697 if (value_sp->GetDeclaration (decl))
1698 {
1699 if (decl.GetFile())
1700 {
1701 StreamString ss;
1702 // True to show fullpath for declaration file.
1703 decl.DumpStopContext(&ss, true);
1704 watchpoint_sp->SetDeclInfo(ss.GetString());
1705 }
1706 }
1707 }
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001708 }
1709 return sb_watchpoint;
1710}
1711
1712lldb::SBWatchpoint
1713SBValue::WatchPointee (bool resolve_location, bool read, bool write)
1714{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001715 SBWatchpoint sb_watchpoint;
1716 if (IsInScope() && GetType().IsPointerType())
1717 sb_watchpoint = Dereference().Watch (resolve_location, read, write);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001718 return sb_watchpoint;
1719}
1720