blob: 3521e903d15b2c0cd2220f1ac3839c524dd41c8a [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{
Jim Ingham684d4012012-08-21 01:46:35 +0000140 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000141 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000142 lldb::ValueObjectSP value_sp(GetSP());
143 if (value_sp)
Jim Ingham684d4012012-08-21 01:46:35 +0000144 {
145 // For a dynamic type we might have to run code to determine the type we are going to report,
146 // and we might not have updated the type before we get asked this. So make sure to get the API lock.
147
148 ProcessSP process_sp(value_sp->GetProcessSP());
149 Process::StopLocker stop_locker;
150 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
151 {
152 if (log)
153 log->Printf ("SBValue(%p)::GetTypeName() => error: process is running", value_sp.get());
154 }
155 else
156 {
157 TargetSP target_sp(value_sp->GetTargetSP());
158 if (target_sp)
159 {
160 Mutex::Locker api_locker (target_sp->GetAPIMutex());
161 name = value_sp->GetQualifiedTypeName().GetCString();
162 }
163 }
164 }
165
Greg Clayton49ce6822010-10-31 03:01:06 +0000166 if (log)
167 {
168 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000169 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000170 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000171 log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000172 }
173
174 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000175}
176
177size_t
178SBValue::GetByteSize ()
179{
Jim Ingham684d4012012-08-21 01:46:35 +0000180 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000181 size_t result = 0;
182
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000183 lldb::ValueObjectSP value_sp(GetSP());
184 if (value_sp)
Jim Ingham684d4012012-08-21 01:46:35 +0000185 {
186 // For a dynamic type we might have to run code to determine the type we are going to report,
187 // and we might not have updated the type before we get asked this. So make sure to get the API lock.
188
189 ProcessSP process_sp(value_sp->GetProcessSP());
190 Process::StopLocker stop_locker;
191 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
192 {
193 if (log)
194 log->Printf ("SBValue(%p)::GetTypeName() => error: process is running", value_sp.get());
195 }
196 else
197 {
198 TargetSP target_sp(value_sp->GetTargetSP());
199 if (target_sp)
200 {
201 Mutex::Locker api_locker (target_sp->GetAPIMutex());
202 result = value_sp->GetByteSize();
203 }
204 }
205 }
Chris Lattner24943d22010-06-08 16:52:24 +0000206
Greg Clayton49ce6822010-10-31 03:01:06 +0000207 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000208 log->Printf ("SBValue(%p)::GetByteSize () => %zu", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000209
Chris Lattner24943d22010-06-08 16:52:24 +0000210 return result;
211}
212
213bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000214SBValue::IsInScope ()
215{
Chris Lattner24943d22010-06-08 16:52:24 +0000216 bool result = false;
217
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000218 lldb::ValueObjectSP value_sp(GetSP());
219 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000220 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000221 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000222 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000223 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000224 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000225 result = value_sp->IsInScope ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000226 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000227 }
Chris Lattner24943d22010-06-08 16:52:24 +0000228
Greg Claytone005f2c2010-11-06 01:53:30 +0000229 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000230 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000231 log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000232
Chris Lattner24943d22010-06-08 16:52:24 +0000233 return result;
234}
235
236const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000237SBValue::GetValue ()
238{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000239 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
240
Greg Clayton49ce6822010-10-31 03:01:06 +0000241 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000242 lldb::ValueObjectSP value_sp(GetSP());
243 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000244 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000245 ProcessSP process_sp(value_sp->GetProcessSP());
246 Process::StopLocker stop_locker;
247 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000248 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000249 if (log)
250 log->Printf ("SBValue(%p)::GetValue() => error: process is running", value_sp.get());
251 }
252 else
253 {
254 TargetSP target_sp(value_sp->GetTargetSP());
255 if (target_sp)
256 {
257 Mutex::Locker api_locker (target_sp->GetAPIMutex());
258 cstr = value_sp->GetValueAsCString ();
259 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000260 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000261 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000262 if (log)
263 {
264 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000265 log->Printf ("SBValue(%p)::GetValue() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000266 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000267 log->Printf ("SBValue(%p)::GetValue() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000268 }
269
270 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000271}
272
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000273ValueType
274SBValue::GetValueType ()
275{
Greg Clayton49ce6822010-10-31 03:01:06 +0000276 ValueType result = eValueTypeInvalid;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000277 lldb::ValueObjectSP value_sp(GetSP());
278 if (value_sp)
279 result = value_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000280 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000281 if (log)
282 {
283 switch (result)
284 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000285 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break;
286 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break;
287 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break;
288 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break;
289 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break;
290 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break;
291 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break;
292 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break;
293 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", value_sp.get(), result); break;
Greg Clayton49ce6822010-10-31 03:01:06 +0000294 }
295 }
296 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000297}
298
Jim Ingham4ae51962010-09-10 23:12:17 +0000299const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000300SBValue::GetObjectDescription ()
301{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000302 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000303 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000304 lldb::ValueObjectSP value_sp(GetSP());
305 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000306 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000307 ProcessSP process_sp(value_sp->GetProcessSP());
308 Process::StopLocker stop_locker;
309 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000310 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000311 if (log)
312 log->Printf ("SBValue(%p)::GetObjectDescription() => error: process is running", value_sp.get());
313 }
314 else
315 {
316 TargetSP target_sp(value_sp->GetTargetSP());
317 if (target_sp)
318 {
319 Mutex::Locker api_locker (target_sp->GetAPIMutex());
320 cstr = value_sp->GetObjectDescription ();
321 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000322 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000323 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000324 if (log)
325 {
326 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000327 log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000328 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000329 log->Printf ("SBValue(%p)::GetObjectDescription() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000330 }
331 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000332}
333
Enrico Granata979e20d2011-07-29 19:53:35 +0000334SBType
335SBValue::GetType()
336{
Jim Ingham5b4905d2012-04-13 18:30:20 +0000337 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000338 SBType sb_type;
339 lldb::ValueObjectSP value_sp(GetSP());
340 TypeImplSP type_sp;
341 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000342 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000343 ProcessSP process_sp(value_sp->GetProcessSP());
344 Process::StopLocker stop_locker;
345 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
346 {
347 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000348 log->Printf ("SBValue(%p)::GetType() => error: process is running", value_sp.get());
Jim Ingham5b4905d2012-04-13 18:30:20 +0000349 }
350 else
351 {
352 TargetSP target_sp(value_sp->GetTargetSP());
353 if (target_sp)
354 {
355 Mutex::Locker api_locker (target_sp->GetAPIMutex());
356 type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType())));
357 sb_type.SetSP(type_sp);
358 }
359 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000360 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000361 if (log)
362 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000363 if (type_sp)
364 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000365 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000366 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000367 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000368 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000369}
370
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000371bool
372SBValue::GetValueDidChange ()
373{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000374 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000375 bool result = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000376 lldb::ValueObjectSP value_sp(GetSP());
377 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000378 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000379 ProcessSP process_sp(value_sp->GetProcessSP());
380 Process::StopLocker stop_locker;
381 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000382 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000383 if (log)
384 log->Printf ("SBValue(%p)::GetValueDidChange() => error: process is running", value_sp.get());
385 }
386 else
387 {
388 TargetSP target_sp(value_sp->GetTargetSP());
389 if (target_sp)
390 {
391 Mutex::Locker api_locker (target_sp->GetAPIMutex());
392 result = value_sp->GetValueDidChange ();
393 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000394 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000395 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000396 if (log)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000397 log->Printf ("SBValue(%p)::GetValueDidChange() => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000398
399 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000400}
401
Jason Molendac48ca822012-02-21 05:33:55 +0000402#ifndef LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000403const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000404SBValue::GetSummary ()
405{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000406 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000407 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000408 lldb::ValueObjectSP value_sp(GetSP());
409 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000410 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000411 ProcessSP process_sp(value_sp->GetProcessSP());
412 Process::StopLocker stop_locker;
413 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000414 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000415 if (log)
416 log->Printf ("SBValue(%p)::GetSummary() => error: process is running", value_sp.get());
417 }
418 else
419 {
420 TargetSP target_sp(value_sp->GetTargetSP());
421 if (target_sp)
422 {
423 Mutex::Locker api_locker (target_sp->GetAPIMutex());
424 cstr = value_sp->GetSummaryAsCString();
425 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000426 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000427 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000428 if (log)
429 {
430 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000431 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000432 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000433 log->Printf ("SBValue(%p)::GetSummary() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000434 }
435 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000436}
Jason Molendac48ca822012-02-21 05:33:55 +0000437#endif // LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000438
439const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000440SBValue::GetLocation ()
441{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000442 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000443 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000444 lldb::ValueObjectSP value_sp(GetSP());
445 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000446 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000447 ProcessSP process_sp(value_sp->GetProcessSP());
448 Process::StopLocker stop_locker;
449 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000450 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000451 if (log)
452 log->Printf ("SBValue(%p)::GetLocation() => error: process is running", value_sp.get());
453 }
454 else
455 {
456 TargetSP target_sp(value_sp->GetTargetSP());
457 if (target_sp)
458 {
459 Mutex::Locker api_locker (target_sp->GetAPIMutex());
460 cstr = value_sp->GetLocationAsCString();
461 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000462 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000463 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000464 if (log)
465 {
466 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000467 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000468 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000469 log->Printf ("SBValue(%p)::GetLocation() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000470 }
471 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000472}
473
Enrico Granata651cbe22012-05-08 21:25:06 +0000474// Deprecated - use the one that takes an lldb::SBError
Chris Lattner24943d22010-06-08 16:52:24 +0000475bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000476SBValue::SetValueFromCString (const char *value_str)
477{
Enrico Granata651cbe22012-05-08 21:25:06 +0000478 lldb::SBError dummy;
479 return SetValueFromCString(value_str,dummy);
480}
481
482bool
483SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
484{
Chris Lattner24943d22010-06-08 16:52:24 +0000485 bool success = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000486 lldb::ValueObjectSP value_sp(GetSP());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000487 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000488 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000489 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000490 ProcessSP process_sp(value_sp->GetProcessSP());
491 Process::StopLocker stop_locker;
492 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000493 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000494 if (log)
495 log->Printf ("SBValue(%p)::SetValueFromCString() => error: process is running", value_sp.get());
496 }
497 else
498 {
499 TargetSP target_sp(value_sp->GetTargetSP());
500 if (target_sp)
501 {
502 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata651cbe22012-05-08 21:25:06 +0000503 success = value_sp->SetValueFromCString (value_str,error.ref());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000504 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000505 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000506 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000507 if (log)
508 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i", value_sp.get(), value_str, success);
509
Chris Lattner24943d22010-06-08 16:52:24 +0000510 return success;
511}
512
Enrico Granatad760907c2012-02-17 03:18:30 +0000513lldb::SBTypeFormat
514SBValue::GetTypeFormat ()
515{
516 lldb::SBTypeFormat format;
517 lldb::ValueObjectSP value_sp(GetSP());
518 if (value_sp)
519 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000520 ProcessSP process_sp(value_sp->GetProcessSP());
521 Process::StopLocker stop_locker;
522 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000523 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000524 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
525 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000526 log->Printf ("SBValue(%p)::GetTypeFormat() => error: process is running", value_sp.get());
Jim Ingham5b4905d2012-04-13 18:30:20 +0000527 }
528 else
529 {
530 TargetSP target_sp(value_sp->GetTargetSP());
531 if (target_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000532 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000533 Mutex::Locker api_locker (target_sp->GetAPIMutex());
534 if (value_sp->UpdateValueIfNeeded(true))
535 {
536 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
537 if (format_sp)
538 format.SetSP(format_sp);
539 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000540 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000541 }
542 }
543 return format;
544}
545
Jason Molendac48ca822012-02-21 05:33:55 +0000546#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000547lldb::SBTypeSummary
548SBValue::GetTypeSummary ()
549{
550 lldb::SBTypeSummary summary;
551 lldb::ValueObjectSP value_sp(GetSP());
552 if (value_sp)
553 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000554 ProcessSP process_sp(value_sp->GetProcessSP());
555 Process::StopLocker stop_locker;
556 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000557 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000558 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
559 if (log)
560 log->Printf ("SBValue(%p)::GetTypeSummary() => error: process is running", value_sp.get());
561 }
562 else
563 {
564 TargetSP target_sp(value_sp->GetTargetSP());
565 if (target_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000566 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000567 Mutex::Locker api_locker (target_sp->GetAPIMutex());
568 if (value_sp->UpdateValueIfNeeded(true))
569 {
570 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
571 if (summary_sp)
572 summary.SetSP(summary_sp);
573 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000574 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000575 }
576 }
577 return summary;
578}
Jason Molendac48ca822012-02-21 05:33:55 +0000579#endif // LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000580
581lldb::SBTypeFilter
582SBValue::GetTypeFilter ()
583{
584 lldb::SBTypeFilter filter;
585 lldb::ValueObjectSP value_sp(GetSP());
586 if (value_sp)
587 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000588 ProcessSP process_sp(value_sp->GetProcessSP());
589 Process::StopLocker stop_locker;
590 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000591 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000592 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
593 if (log)
594 log->Printf ("SBValue(%p)::GetTypeFilter() => error: process is running", value_sp.get());
595 }
596 else
597 {
598 TargetSP target_sp(value_sp->GetTargetSP());
599 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000600 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000601 Mutex::Locker api_locker (target_sp->GetAPIMutex());
602 if (value_sp->UpdateValueIfNeeded(true))
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000603 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000604 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
605
606 if (synthetic_sp && !synthetic_sp->IsScripted())
607 {
608 TypeFilterImplSP filter_sp = STD_STATIC_POINTER_CAST(TypeFilterImpl,synthetic_sp);
609 filter.SetSP(filter_sp);
610 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000611 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000612 }
613 }
614 }
615 return filter;
616}
617
Jason Molendac48ca822012-02-21 05:33:55 +0000618#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000619lldb::SBTypeSynthetic
620SBValue::GetTypeSynthetic ()
621{
622 lldb::SBTypeSynthetic synthetic;
623 lldb::ValueObjectSP value_sp(GetSP());
624 if (value_sp)
625 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000626 ProcessSP process_sp(value_sp->GetProcessSP());
627 Process::StopLocker stop_locker;
628 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000629 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000630 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
631 if (log)
632 log->Printf ("SBValue(%p)::GetTypeSynthetic() => error: process is running", value_sp.get());
633 }
634 else
635 {
636 TargetSP target_sp(value_sp->GetTargetSP());
637 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000638 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000639 Mutex::Locker api_locker (target_sp->GetAPIMutex());
640 if (value_sp->UpdateValueIfNeeded(true))
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000641 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000642 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
643
644 if (children_sp && children_sp->IsScripted())
645 {
646 TypeSyntheticImplSP synth_sp = STD_STATIC_POINTER_CAST(TypeSyntheticImpl,children_sp);
647 synthetic.SetSP(synth_sp);
648 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000649 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000650 }
651 }
652 }
653 return synthetic;
654}
Jason Molendac48ca822012-02-21 05:33:55 +0000655#endif
Enrico Granatad760907c2012-02-17 03:18:30 +0000656
Enrico Granata979e20d2011-07-29 19:53:35 +0000657lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000658SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000659{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000660 lldb::SBValue sb_value;
661 lldb::ValueObjectSP value_sp(GetSP());
662 lldb::ValueObjectSP new_value_sp;
663 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000664 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000665 ProcessSP process_sp(value_sp->GetProcessSP());
666 Process::StopLocker stop_locker;
667 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata979e20d2011-07-29 19:53:35 +0000668 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000669 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
670 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000671 log->Printf ("SBValue(%p)::CreateChildAtOffset() => error: process is running", value_sp.get());
Jim Ingham5b4905d2012-04-13 18:30:20 +0000672 }
673 else
674 {
675 TargetSP target_sp(value_sp->GetTargetSP());
676 if (target_sp)
677 {
678 Mutex::Locker api_locker (target_sp->GetAPIMutex());
679 TypeImplSP type_sp (type.GetSP());
680 if (type.IsValid())
681 {
682 sb_value = SBValue(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true));
683 new_value_sp = sb_value.GetSP();
684 if (new_value_sp)
685 new_value_sp->SetName(ConstString(name));
686 }
687 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000688 }
689 }
690 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
691 if (log)
692 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000693 if (new_value_sp)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000694 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000695 else
Greg Clayton12b7ea32012-06-04 20:13:23 +0000696 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000697 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000698 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000699}
700
701lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000702SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000703{
Greg Clayton4eb01a72012-01-31 04:25:15 +0000704 lldb::SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000705 lldb::ValueObjectSP value_sp(GetSP());
706 TypeImplSP type_sp (type.GetSP());
707 if (value_sp && type_sp)
708 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()));
Greg Clayton4eb01a72012-01-31 04:25:15 +0000709 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000710}
711
712lldb::SBValue
713SBValue::CreateValueFromExpression (const char *name, const char* expression)
714{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000715 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000716 lldb::SBValue sb_value;
717 lldb::ValueObjectSP value_sp(GetSP());
718 lldb::ValueObjectSP new_value_sp;
719 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000720 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000721 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000722 ProcessSP process_sp(exe_ctx.GetProcessSP());
723 Process::StopLocker stop_locker;
724 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Johnny Chen9fd2e382011-12-20 01:52:44 +0000725 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000726 if (log)
727 log->Printf ("SBValue(%p)::CreateValueFromExpression() => error: process is running", value_sp.get());
728 }
729 else
730 {
731 Target* target = exe_ctx.GetTargetPtr();
732 if (target)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000733 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000734 target->EvaluateExpression (expression,
735 exe_ctx.GetFramePtr(),
736 eExecutionPolicyOnlyWhenNeeded,
737 false, // coerce to id
738 true, // unwind on error
739 true, // keep in memory
740 eNoDynamicValues,
741 new_value_sp);
742 if (new_value_sp)
743 {
744 new_value_sp->SetName(ConstString(name));
745 sb_value.SetSP(new_value_sp);
746 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000747 }
Johnny Chen9fd2e382011-12-20 01:52:44 +0000748 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000749 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000750 if (log)
751 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000752 if (new_value_sp)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000753 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000754 value_sp.get(),
755 name,
756 expression,
757 new_value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000758 else
Greg Clayton12b7ea32012-06-04 20:13:23 +0000759 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000760 value_sp.get(),
761 name,
762 expression);
Enrico Granata979e20d2011-07-29 19:53:35 +0000763 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000764 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000765}
766
767lldb::SBValue
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000768SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000769{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000770 lldb::SBValue sb_value;
771 lldb::ValueObjectSP value_sp(GetSP());
772 lldb::ValueObjectSP new_value_sp;
773 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
774 if (value_sp && type_impl_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000775 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000776 ClangASTType pointee_ast_type(type_impl_sp->GetASTContext(), type_impl_sp->GetClangASTType().GetPointerType ());
777 lldb::TypeImplSP pointee_type_impl_sp (new TypeImpl(pointee_ast_type));
778 if (pointee_type_impl_sp)
Enrico Granatac9310302011-08-04 17:07:02 +0000779 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000780
781 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
782
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000783 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
784 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000785 pointee_type_impl_sp->GetASTContext(),
786 pointee_type_impl_sp->GetOpaqueQualType(),
787 ConstString(name),
788 buffer,
789 lldb::endian::InlHostByteOrder(),
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000790 exe_ctx.GetAddressByteSize()));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000791
792 if (ptr_result_valobj_sp)
793 {
794 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
795 Error err;
796 new_value_sp = ptr_result_valobj_sp->Dereference(err);
797 if (new_value_sp)
798 new_value_sp->SetName(ConstString(name));
799 }
800 sb_value.SetSP(new_value_sp);
Enrico Granatac9310302011-08-04 17:07:02 +0000801 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000802 }
803 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
804 if (log)
805 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000806 if (new_value_sp)
807 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000808 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000809 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
Johnny Chena713b862011-08-09 22:38:07 +0000810 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000811 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000812}
813
Enrico Granata91544802011-09-06 19:20:51 +0000814lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000815SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000816{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000817 lldb::SBValue sb_value;
818 lldb::ValueObjectSP new_value_sp;
819 lldb::ValueObjectSP value_sp(GetSP());
820 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +0000821 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000822 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
823
824 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000825 type.m_opaque_sp->GetASTContext() ,
826 type.m_opaque_sp->GetOpaqueQualType(),
827 ConstString(name),
828 *data.m_opaque_sp,
829 LLDB_INVALID_ADDRESS);
830 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
831 sb_value.SetSP(new_value_sp);
Enrico Granata91544802011-09-06 19:20:51 +0000832 }
833 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
834 if (log)
835 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000836 if (new_value_sp)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000837 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000838 else
Greg Clayton12b7ea32012-06-04 20:13:23 +0000839 log->Printf ("SBValue(%p)::CreateValueFromData => NULL", value_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +0000840 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000841 return sb_value;
Enrico Granata91544802011-09-06 19:20:51 +0000842}
843
Chris Lattner24943d22010-06-08 16:52:24 +0000844SBValue
845SBValue::GetChildAtIndex (uint32_t idx)
846{
Greg Clayton8f64c472011-07-15 19:31:49 +0000847 const bool can_create_synthetic = false;
848 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000849 lldb::ValueObjectSP value_sp(GetSP());
850 if (value_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000851 {
852 TargetSP target_sp(value_sp->GetTargetSP());
853 if (target_sp)
854 use_dynamic = target_sp->GetPreferDynamicValue();
855 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000856 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000857}
858
859SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000860SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000861{
Chris Lattner24943d22010-06-08 16:52:24 +0000862 lldb::ValueObjectSP child_sp;
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000863 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000864
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000865 lldb::ValueObjectSP value_sp(GetSP());
866 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000867 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000868 ProcessSP process_sp(value_sp->GetProcessSP());
869 Process::StopLocker stop_locker;
870 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000871 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000872 if (log)
873 log->Printf ("SBValue(%p)::GetChildAtIndex() => error: process is running", value_sp.get());
874 }
875 else
876 {
877 TargetSP target_sp(value_sp->GetTargetSP());
878 if (target_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000879 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000880 Mutex::Locker api_locker (target_sp->GetAPIMutex());
881 const bool can_create = true;
882 child_sp = value_sp->GetChildAtIndex (idx, can_create);
883 if (can_create_synthetic && !child_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000884 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000885 if (value_sp->IsPointerType())
886 {
887 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
888 }
889 else if (value_sp->IsArrayType())
890 {
891 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
892 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000893 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000894
895 if (child_sp)
Greg Clayton8f64c472011-07-15 19:31:49 +0000896 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000897 if (use_dynamic != lldb::eNoDynamicValues)
898 {
899 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
900 if (dynamic_sp)
901 child_sp = dynamic_sp;
902 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000903 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000904 }
Jim Inghame41494a2011-04-16 00:01:13 +0000905 }
906 }
907
Chris Lattner24943d22010-06-08 16:52:24 +0000908 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000909 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000910 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000911
Chris Lattner24943d22010-06-08 16:52:24 +0000912 return sb_value;
913}
914
915uint32_t
916SBValue::GetIndexOfChildWithName (const char *name)
917{
Greg Clayton49ce6822010-10-31 03:01:06 +0000918 uint32_t idx = UINT32_MAX;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000919 lldb::ValueObjectSP value_sp(GetSP());
920 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000921 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000922 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000923 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000924 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000925 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000926
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000927 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000928 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000929 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000930 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000931 if (log)
932 {
933 if (idx == UINT32_MAX)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000934 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000935 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000936 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
Greg Clayton49ce6822010-10-31 03:01:06 +0000937 }
938 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000939}
940
941SBValue
942SBValue::GetChildMemberWithName (const char *name)
943{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000944 lldb::ValueObjectSP value_sp(GetSP());
945 if (value_sp)
Johnny Chen446ccaa2011-06-29 21:19:39 +0000946 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000947 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000948 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000949 if (target_sp)
950 {
951 Mutex::Locker api_locker (target_sp->GetAPIMutex());
952 use_dynamic_value = target_sp->GetPreferDynamicValue();
953 }
Johnny Chen446ccaa2011-06-29 21:19:39 +0000954 return GetChildMemberWithName (name, use_dynamic_value);
955 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000956 return SBValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000957}
958
959SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000960SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000961{
Chris Lattner24943d22010-06-08 16:52:24 +0000962 lldb::ValueObjectSP child_sp;
963 const ConstString str_name (name);
964
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000965 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton905acaf2011-05-20 22:07:17 +0000966
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000967 lldb::ValueObjectSP value_sp(GetSP());
968 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +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 Inghame41494a2011-04-16 00:01:13 +0000973 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000974 if (log)
975 log->Printf ("SBValue(%p)::GetChildMemberWithName() => error: process is running", value_sp.get());
976 }
977 else
978 {
979 TargetSP target_sp(value_sp->GetTargetSP());
980 if (target_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000981 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000982 Mutex::Locker api_locker (target_sp->GetAPIMutex());
983 child_sp = value_sp->GetChildMemberWithName (str_name, true);
984 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000985 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000986 if (child_sp)
987 {
988 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
989 if (dynamic_sp)
990 child_sp = dynamic_sp;
991 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000992 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000993 }
Jim Inghame41494a2011-04-16 00:01:13 +0000994 }
995 }
996
Chris Lattner24943d22010-06-08 16:52:24 +0000997 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000998
Greg Clayton49ce6822010-10-31 03:01:06 +0000999 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001000 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +00001001
Chris Lattner24943d22010-06-08 16:52:24 +00001002 return sb_value;
1003}
1004
Enrico Granataf7a9b142011-07-15 02:26:42 +00001005lldb::SBValue
Jim Ingham1b425752011-12-08 19:44:08 +00001006SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
1007{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001008 lldb::ValueObjectSP value_sp(GetSP());
1009 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001010 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001011 ProcessSP process_sp(value_sp->GetProcessSP());
1012 Process::StopLocker stop_locker;
1013 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Jim Ingham1b425752011-12-08 19:44:08 +00001014 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001015 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1016 if (log)
1017 log->Printf ("SBValue(%p)::GetDynamicValue() => error: process is running", value_sp.get());
1018 }
1019 else
1020 {
1021 TargetSP target_sp(value_sp->GetTargetSP());
1022 if (target_sp)
1023 {
1024 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1025 return SBValue (value_sp->GetDynamicValue(use_dynamic));
1026 }
Jim Ingham1b425752011-12-08 19:44:08 +00001027 }
1028 }
1029
1030 return SBValue();
1031}
1032
1033lldb::SBValue
1034SBValue::GetStaticValue ()
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 SBValue(value_sp->GetStaticValue());
Jim Ingham1b425752011-12-08 19:44:08 +00001044 }
1045 }
1046
1047 return SBValue();
1048}
1049
Enrico Granatadba1de82012-03-27 02:35:13 +00001050lldb::SBValue
1051SBValue::GetNonSyntheticValue ()
1052{
1053 SBValue sb_value;
1054 lldb::ValueObjectSP value_sp(GetSP());
1055 if (value_sp)
1056 {
1057 if (value_sp->IsSynthetic())
1058 {
1059 TargetSP target_sp(value_sp->GetTargetSP());
1060 if (target_sp)
1061 {
1062 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1063 // deliberately breaking the rules here to optimize the case where we DO NOT want
1064 // the synthetic value to be returned to the user - if we did not do this, we would have to tell
1065 // the target to suppress the synthetic value, and then return the flag to its original value
Enrico Granata4758a3c2012-05-08 18:47:08 +00001066 if (value_sp->GetNonSyntheticValue())
1067 sb_value.m_opaque_sp = value_sp->GetNonSyntheticValue();
Enrico Granatadba1de82012-03-27 02:35:13 +00001068 }
1069 }
1070 }
1071 return sb_value;
1072}
1073
Jim Ingham1b425752011-12-08 19:44:08 +00001074bool
1075SBValue::IsDynamic()
1076{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001077 lldb::ValueObjectSP value_sp(GetSP());
1078 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001079 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001080 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001081 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001082 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001083 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001084 return value_sp->IsDynamic();
Jim Ingham1b425752011-12-08 19:44:08 +00001085 }
1086 }
1087 return false;
1088}
1089
1090lldb::SBValue
Enrico Granataf7a9b142011-07-15 02:26:42 +00001091SBValue::GetValueForExpressionPath(const char* expr_path)
1092{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001093 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf7a9b142011-07-15 02:26:42 +00001094 lldb::ValueObjectSP child_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001095 lldb::ValueObjectSP value_sp(GetSP());
1096 if (value_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +00001097 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001098 ProcessSP process_sp(value_sp->GetProcessSP());
1099 Process::StopLocker stop_locker;
1100 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granataf7a9b142011-07-15 02:26:42 +00001101 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001102 if (log)
1103 log->Printf ("SBValue(%p)::GetValueForExpressionPath() => error: process is running", value_sp.get());
1104 }
1105 else
1106 {
1107 TargetSP target_sp(value_sp->GetTargetSP());
1108 if (target_sp)
1109 {
1110 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1111 // using default values for all the fancy options, just do it if you can
1112 child_sp = value_sp->GetValueForExpressionPath(expr_path);
1113 }
Enrico Granataf7a9b142011-07-15 02:26:42 +00001114 }
1115 }
1116
1117 SBValue sb_value (child_sp);
1118
Enrico Granataf7a9b142011-07-15 02:26:42 +00001119 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001120 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 +00001121
1122 return sb_value;
1123}
Chris Lattner24943d22010-06-08 16:52:24 +00001124
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001125int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +00001126SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1127{
Jim Ingham574c3d62011-08-12 23:34:31 +00001128 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001129 lldb::ValueObjectSP value_sp(GetSP());
1130 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +00001131 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001132 ProcessSP process_sp(value_sp->GetProcessSP());
1133 Process::StopLocker stop_locker;
1134 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatac92eb402011-08-04 01:41:02 +00001135 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001136 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1137 if (log)
1138 log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
1139 error.SetErrorString("process is running");
Enrico Granatac92eb402011-08-04 01:41:02 +00001140 }
1141 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001142 {
1143 TargetSP target_sp(value_sp->GetTargetSP());
1144 if (target_sp)
1145 {
1146 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1147 Scalar scalar;
1148 if (value_sp->ResolveValue (scalar))
1149 return scalar.GetRawBits64(fail_value);
1150 else
1151 error.SetErrorString("could not get value");
1152 }
1153 else
1154 error.SetErrorString("could not get target");
1155 }
Enrico Granatac92eb402011-08-04 01:41:02 +00001156 }
1157 error.SetErrorString("invalid SBValue");
1158 return fail_value;
1159}
1160
1161uint64_t
1162SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1163{
Jim Ingham574c3d62011-08-12 23:34:31 +00001164 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001165 lldb::ValueObjectSP value_sp(GetSP());
1166 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +00001167 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001168 ProcessSP process_sp(value_sp->GetProcessSP());
1169 Process::StopLocker stop_locker;
1170 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatac92eb402011-08-04 01:41:02 +00001171 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001172 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1173 if (log)
1174 log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
1175 error.SetErrorString("process is running");
Enrico Granatac92eb402011-08-04 01:41:02 +00001176 }
1177 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001178 {
1179 TargetSP target_sp(value_sp->GetTargetSP());
1180 if (target_sp)
1181 {
1182 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1183 Scalar scalar;
1184 if (value_sp->ResolveValue (scalar))
1185 return scalar.GetRawBits64(fail_value);
1186 else
1187 error.SetErrorString("could not get value");
1188 }
1189 else
1190 error.SetErrorString("could not get target");
1191 }
Enrico Granatac92eb402011-08-04 01:41:02 +00001192 }
1193 error.SetErrorString("invalid SBValue");
1194 return fail_value;
1195}
1196
1197int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001198SBValue::GetValueAsSigned(int64_t fail_value)
1199{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001200 lldb::ValueObjectSP value_sp(GetSP());
1201 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001202 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001203 ProcessSP process_sp(value_sp->GetProcessSP());
1204 Process::StopLocker stop_locker;
1205 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001206 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001207 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1208 if (log)
1209 log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
1210 }
1211 else
1212 {
1213 TargetSP target_sp(value_sp->GetTargetSP());
1214 if (target_sp)
1215 {
1216 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1217 Scalar scalar;
1218 if (value_sp->ResolveValue (scalar))
1219 return scalar.GetRawBits64(fail_value);
1220 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001221 }
1222 }
1223 return fail_value;
1224}
1225
1226uint64_t
1227SBValue::GetValueAsUnsigned(uint64_t fail_value)
1228{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001229 lldb::ValueObjectSP value_sp(GetSP());
1230 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001231 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001232 ProcessSP process_sp(value_sp->GetProcessSP());
1233 Process::StopLocker stop_locker;
1234 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001235 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001236 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1237 if (log)
1238 log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
1239 }
1240 else
1241 {
1242 TargetSP target_sp(value_sp->GetTargetSP());
1243 if (target_sp)
1244 {
1245 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1246 Scalar scalar;
1247 if (value_sp->ResolveValue (scalar))
1248 return scalar.GetRawBits64(fail_value);
1249 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001250 }
1251 }
1252 return fail_value;
1253}
1254
Chris Lattner24943d22010-06-08 16:52:24 +00001255uint32_t
1256SBValue::GetNumChildren ()
1257{
1258 uint32_t num_children = 0;
1259
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001260 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001261 lldb::ValueObjectSP value_sp(GetSP());
1262 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001263 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001264 ProcessSP process_sp(value_sp->GetProcessSP());
1265 Process::StopLocker stop_locker;
1266 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +00001267 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001268 if (log)
1269 log->Printf ("SBValue(%p)::GetNumChildren() => error: process is running", value_sp.get());
1270 }
1271 else
1272 {
1273 TargetSP target_sp(value_sp->GetTargetSP());
1274 if (target_sp)
1275 {
1276 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001277
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001278 num_children = value_sp->GetNumChildren();
1279 }
Greg Claytonb9dcc512011-06-29 18:28:50 +00001280 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001281 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001282
Greg Clayton49ce6822010-10-31 03:01:06 +00001283 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001284 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +00001285
1286 return num_children;
1287}
1288
Chris Lattner24943d22010-06-08 16:52:24 +00001289
1290SBValue
1291SBValue::Dereference ()
1292{
Greg Clayton49ce6822010-10-31 03:01:06 +00001293 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001294 lldb::ValueObjectSP value_sp(GetSP());
1295 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001296 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001297 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001298 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001299 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001300 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001301
Greg Claytonb9dcc512011-06-29 18:28:50 +00001302 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001303 sb_value = value_sp->Dereference (error);
Greg Claytonb9dcc512011-06-29 18:28:50 +00001304 }
Chris Lattner24943d22010-06-08 16:52:24 +00001305 }
Greg Claytone005f2c2010-11-06 01:53:30 +00001306 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001307 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001308 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +00001309
1310 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +00001311}
1312
1313bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001314SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +00001315{
1316 bool is_ptr_type = false;
1317
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001318 lldb::ValueObjectSP value_sp(GetSP());
1319 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001320 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001321 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001322 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001323 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001324 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001325
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001326 is_ptr_type = value_sp->IsPointerType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001327 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001328 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001329
Greg Claytone005f2c2010-11-06 01:53:30 +00001330 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001331 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001332 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
Greg Clayton49ce6822010-10-31 03:01:06 +00001333
Chris Lattner24943d22010-06-08 16:52:24 +00001334
1335 return is_ptr_type;
1336}
1337
Chris Lattner24943d22010-06-08 16:52:24 +00001338void *
1339SBValue::GetOpaqueType()
1340{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001341 lldb::ValueObjectSP value_sp(GetSP());
1342 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001343 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001344 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001345 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001346 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001347 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001348
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001349 return value_sp->GetClangType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001350 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001351 }
Chris Lattner24943d22010-06-08 16:52:24 +00001352 return NULL;
1353}
1354
Enrico Granata979e20d2011-07-29 19:53:35 +00001355lldb::SBTarget
1356SBValue::GetTarget()
1357{
Greg Clayton334d33a2012-01-30 07:41:31 +00001358 SBTarget sb_target;
1359 TargetSP target_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001360 lldb::ValueObjectSP value_sp(GetSP());
1361 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001362 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001363 target_sp = value_sp->GetTargetSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001364 sb_target.SetSP (target_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001365 }
1366 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1367 if (log)
1368 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001369 if (target_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001370 log->Printf ("SBValue(%p)::GetTarget () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001371 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001372 log->Printf ("SBValue(%p)::GetTarget () => %p", value_sp.get(), target_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001373 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001374 return sb_target;
Enrico Granata979e20d2011-07-29 19:53:35 +00001375}
1376
1377lldb::SBProcess
1378SBValue::GetProcess()
1379{
Greg Clayton334d33a2012-01-30 07:41:31 +00001380 SBProcess sb_process;
1381 ProcessSP process_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001382 lldb::ValueObjectSP value_sp(GetSP());
1383 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001384 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001385 process_sp = value_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001386 if (process_sp)
1387 sb_process.SetSP (process_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001388 }
1389 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1390 if (log)
1391 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001392 if (process_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001393 log->Printf ("SBValue(%p)::GetProcess () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001394 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001395 log->Printf ("SBValue(%p)::GetProcess () => %p", value_sp.get(), process_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001396 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001397 return sb_process;
Enrico Granata979e20d2011-07-29 19:53:35 +00001398}
1399
1400lldb::SBThread
1401SBValue::GetThread()
1402{
Greg Clayton90c52142012-01-30 02:53:15 +00001403 SBThread sb_thread;
1404 ThreadSP thread_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001405 lldb::ValueObjectSP value_sp(GetSP());
1406 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001407 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001408 thread_sp = value_sp->GetThreadSP();
1409 sb_thread.SetThread(thread_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001410 }
1411 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1412 if (log)
1413 {
Greg Clayton90c52142012-01-30 02:53:15 +00001414 if (thread_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001415 log->Printf ("SBValue(%p)::GetThread () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001416 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001417 log->Printf ("SBValue(%p)::GetThread () => %p", value_sp.get(), thread_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001418 }
Greg Clayton90c52142012-01-30 02:53:15 +00001419 return sb_thread;
Enrico Granata979e20d2011-07-29 19:53:35 +00001420}
1421
1422lldb::SBFrame
1423SBValue::GetFrame()
1424{
Greg Clayton334d33a2012-01-30 07:41:31 +00001425 SBFrame sb_frame;
1426 StackFrameSP frame_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001427 lldb::ValueObjectSP value_sp(GetSP());
1428 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001429 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001430 frame_sp = value_sp->GetFrameSP();
1431 sb_frame.SetFrameSP (frame_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001432 }
1433 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1434 if (log)
1435 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001436 if (frame_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001437 log->Printf ("SBValue(%p)::GetFrame () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001438 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001439 log->Printf ("SBValue(%p)::GetFrame () => %p", value_sp.get(), frame_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001440 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001441 return sb_frame;
Enrico Granata979e20d2011-07-29 19:53:35 +00001442}
1443
1444
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001445lldb::ValueObjectSP
1446SBValue::GetSP () const
Chris Lattner24943d22010-06-08 16:52:24 +00001447{
Greg Clayton63094e02010-06-23 01:19:29 +00001448 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001449}
1450
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001451void
1452SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001453{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001454 m_opaque_sp = sp;
Enrico Granatadba1de82012-03-27 02:35:13 +00001455 if (IsValid() && m_opaque_sp->HasSyntheticValue())
1456 m_opaque_sp = m_opaque_sp->GetSyntheticValue();
Chris Lattner24943d22010-06-08 16:52:24 +00001457}
Caroline Tice98f930f2010-09-20 05:20:02 +00001458
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001459
Caroline Tice98f930f2010-09-20 05:20:02 +00001460bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001461SBValue::GetExpressionPath (SBStream &description)
1462{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001463 lldb::ValueObjectSP value_sp(GetSP());
1464 if (value_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +00001465 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001466 value_sp->GetExpressionPath (description.ref(), false);
Greg Claytonb01000f2011-01-17 03:46:26 +00001467 return true;
1468 }
1469 return false;
1470}
1471
1472bool
1473SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1474{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001475 lldb::ValueObjectSP value_sp(GetSP());
1476 if (value_sp)
Greg Claytonb01000f2011-01-17 03:46:26 +00001477 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001478 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +00001479 return true;
1480 }
1481 return false;
1482}
1483
1484bool
Caroline Tice98f930f2010-09-20 05:20:02 +00001485SBValue::GetDescription (SBStream &description)
1486{
Greg Clayton96154be2011-11-13 06:57:31 +00001487 Stream &strm = description.ref();
1488
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001489 lldb::ValueObjectSP value_sp(GetSP());
1490 if (value_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +00001491 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001492 ProcessSP process_sp(value_sp->GetProcessSP());
1493 Process::StopLocker stop_locker;
1494 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
1495 {
1496 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1497 if (log)
1498 log->Printf ("SBValue(%p)::GetDescription() => error: process is running", value_sp.get());
1499 }
1500 else
1501 {
1502 ValueObject::DumpValueObject (strm, value_sp.get());
1503 }
Caroline Tice98f930f2010-09-20 05:20:02 +00001504 }
1505 else
Greg Clayton96154be2011-11-13 06:57:31 +00001506 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +00001507
1508 return true;
1509}
Greg Claytone179a582011-01-05 18:43:15 +00001510
1511lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +00001512SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +00001513{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001514 lldb::ValueObjectSP value_sp(GetSP());
1515 if (value_sp)
1516 return value_sp->GetFormat();
Greg Claytone179a582011-01-05 18:43:15 +00001517 return eFormatDefault;
1518}
1519
1520void
1521SBValue::SetFormat (lldb::Format format)
1522{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001523 lldb::ValueObjectSP value_sp(GetSP());
1524 if (value_sp)
1525 value_sp->SetFormat(format);
Greg Claytone179a582011-01-05 18:43:15 +00001526}
1527
Enrico Granata979e20d2011-07-29 19:53:35 +00001528lldb::SBValue
1529SBValue::AddressOf()
1530{
1531 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001532 lldb::ValueObjectSP value_sp(GetSP());
1533 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001534 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001535 TargetSP target_sp (value_sp->GetTargetSP());
1536 if (target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001537 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001538 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001539 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001540 sb_value = value_sp->AddressOf (error);
Enrico Granata979e20d2011-07-29 19:53:35 +00001541 }
1542 }
1543 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1544 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +00001545 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)", value_sp.get(), value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001546
1547 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001548}
Enrico Granata91544802011-09-06 19:20:51 +00001549
1550lldb::addr_t
1551SBValue::GetLoadAddress()
1552{
1553 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001554 lldb::ValueObjectSP value_sp(GetSP());
1555 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001556 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001557 TargetSP target_sp (value_sp->GetTargetSP());
1558 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001559 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001560 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001561 const bool scalar_is_load_address = true;
1562 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001563 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001564 if (addr_type == eAddressTypeFile)
1565 {
Greg Clayton3508c382012-02-24 01:59:29 +00001566 ModuleSP module_sp (value_sp->GetModule());
1567 if (!module_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001568 value = LLDB_INVALID_ADDRESS;
1569 else
1570 {
1571 Address addr;
Greg Clayton3508c382012-02-24 01:59:29 +00001572 module_sp->ResolveFileAddress(value, addr);
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001573 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001574 }
1575 }
1576 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1577 value = LLDB_INVALID_ADDRESS;
1578 }
1579 }
1580 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1581 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001582 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", value_sp.get(), value);
Enrico Granata91544802011-09-06 19:20:51 +00001583
1584 return value;
1585}
1586
1587lldb::SBAddress
1588SBValue::GetAddress()
1589{
1590 Address addr;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001591 lldb::ValueObjectSP value_sp(GetSP());
1592 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001593 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001594 TargetSP target_sp (value_sp->GetTargetSP());
1595 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001596 {
1597 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001598 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001599 const bool scalar_is_load_address = true;
1600 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001601 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001602 if (addr_type == eAddressTypeFile)
1603 {
Greg Clayton3508c382012-02-24 01:59:29 +00001604 ModuleSP module_sp (value_sp->GetModule());
1605 if (module_sp)
1606 module_sp->ResolveFileAddress(value, addr);
Enrico Granata91544802011-09-06 19:20:51 +00001607 }
1608 else if (addr_type == eAddressTypeLoad)
1609 {
1610 // no need to check the return value on this.. if it can actually do the resolve
1611 // addr will be in the form (section,offset), otherwise it will simply be returned
1612 // as (NULL, value)
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001613 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001614 }
1615 }
1616 }
1617 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1618 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001619 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 +00001620 return SBAddress(new Address(addr));
1621}
1622
1623lldb::SBData
1624SBValue::GetPointeeData (uint32_t item_idx,
1625 uint32_t item_count)
1626{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001627 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata91544802011-09-06 19:20:51 +00001628 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001629 lldb::ValueObjectSP value_sp(GetSP());
1630 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001631 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001632 ProcessSP process_sp(value_sp->GetProcessSP());
1633 Process::StopLocker stop_locker;
1634 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata91544802011-09-06 19:20:51 +00001635 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001636 if (log)
1637 log->Printf ("SBValue(%p)::GetPointeeData() => error: process is running", value_sp.get());
1638 }
1639 else
1640 {
1641 TargetSP target_sp (value_sp->GetTargetSP());
1642 if (target_sp)
1643 {
1644 DataExtractorSP data_sp(new DataExtractor());
1645 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1646 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1647 if (data_sp->GetByteSize() > 0)
1648 *sb_data = data_sp;
1649 }
Enrico Granata91544802011-09-06 19:20:51 +00001650 }
1651 }
Enrico Granata91544802011-09-06 19:20:51 +00001652 if (log)
1653 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001654 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001655 item_idx,
1656 item_count,
1657 sb_data.get());
1658
1659 return sb_data;
1660}
1661
1662lldb::SBData
1663SBValue::GetData ()
1664{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001665 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata91544802011-09-06 19:20:51 +00001666 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001667 lldb::ValueObjectSP value_sp(GetSP());
1668 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001669 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001670 ProcessSP process_sp(value_sp->GetProcessSP());
1671 Process::StopLocker stop_locker;
1672 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata91544802011-09-06 19:20:51 +00001673 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001674 if (log)
1675 log->Printf ("SBValue(%p)::GetData() => error: process is running", value_sp.get());
1676 }
1677 else
1678 {
1679 TargetSP target_sp (value_sp->GetTargetSP());
1680 if (target_sp)
1681 {
1682 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1683 DataExtractorSP data_sp(new DataExtractor());
1684 value_sp->GetData(*data_sp);
1685 if (data_sp->GetByteSize() > 0)
1686 *sb_data = data_sp;
1687 }
Enrico Granata91544802011-09-06 19:20:51 +00001688 }
1689 }
Enrico Granata91544802011-09-06 19:20:51 +00001690 if (log)
1691 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001692 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001693 sb_data.get());
1694
1695 return sb_data;
1696}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001697
1698lldb::SBWatchpoint
Johnny Chen3f883492012-06-04 23:19:54 +00001699SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001700{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001701 SBWatchpoint sb_watchpoint;
1702
1703 // If the SBValue is not valid, there's no point in even trying to watch it.
1704 lldb::ValueObjectSP value_sp(GetSP());
1705 TargetSP target_sp (GetTarget().GetSP());
1706 if (value_sp && target_sp)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001707 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001708 // Can't watch this if the process is running
1709 ProcessSP process_sp(value_sp->GetProcessSP());
1710 Process::StopLocker stop_locker;
1711 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
1712 {
1713 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1714 if (log)
1715 log->Printf ("SBValue(%p)::Watch() => error: process is running", value_sp.get());
1716 return sb_watchpoint;
1717 }
1718
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001719 // Read and Write cannot both be false.
1720 if (!read && !write)
1721 return sb_watchpoint;
1722
1723 // If the value is not in scope, don't try and watch and invalid value
1724 if (!IsInScope())
1725 return sb_watchpoint;
1726
1727 addr_t addr = GetLoadAddress();
1728 if (addr == LLDB_INVALID_ADDRESS)
1729 return sb_watchpoint;
1730 size_t byte_size = GetByteSize();
1731 if (byte_size == 0)
1732 return sb_watchpoint;
1733
1734 uint32_t watch_type = 0;
1735 if (read)
1736 watch_type |= LLDB_WATCH_TYPE_READ;
1737 if (write)
1738 watch_type |= LLDB_WATCH_TYPE_WRITE;
1739
Johnny Chen3f883492012-06-04 23:19:54 +00001740 Error rc;
1741 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type, rc);
1742 error.SetError(rc);
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001743
1744 if (watchpoint_sp)
1745 {
1746 sb_watchpoint.SetSP (watchpoint_sp);
1747 Declaration decl;
1748 if (value_sp->GetDeclaration (decl))
1749 {
1750 if (decl.GetFile())
1751 {
1752 StreamString ss;
1753 // True to show fullpath for declaration file.
1754 decl.DumpStopContext(&ss, true);
1755 watchpoint_sp->SetDeclInfo(ss.GetString());
1756 }
1757 }
1758 }
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001759 }
1760 return sb_watchpoint;
1761}
1762
Johnny Chen8a5ce772012-06-04 23:45:50 +00001763// FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1764// Backward compatibility fix in the interim.
1765lldb::SBWatchpoint
1766SBValue::Watch (bool resolve_location, bool read, bool write)
1767{
Johnny Chen9c4a3442012-06-05 00:14:15 +00001768 SBError error;
1769 return Watch(resolve_location, read, write, error);
Johnny Chen8a5ce772012-06-04 23:45:50 +00001770}
1771
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001772lldb::SBWatchpoint
Johnny Chen3f883492012-06-04 23:19:54 +00001773SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001774{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001775 SBWatchpoint sb_watchpoint;
1776 if (IsInScope() && GetType().IsPointerType())
Johnny Chen3f883492012-06-04 23:19:54 +00001777 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001778 return sb_watchpoint;
1779}
1780