blob: 0aa01a6c9cc0e4be58f425946288d2fa447a8de7 [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
Enrico Granata49306142012-10-10 22:54:17 +000012#include "lldb/API/SBDeclaration.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000013#include "lldb/API/SBStream.h"
Enrico Granatad760907c2012-02-17 03:18:30 +000014#include "lldb/API/SBTypeFilter.h"
15#include "lldb/API/SBTypeFormat.h"
16#include "lldb/API/SBTypeSummary.h"
17#include "lldb/API/SBTypeSynthetic.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018
Johnny Chenecd4feb2011-10-14 00:42:25 +000019#include "lldb/Breakpoint/Watchpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/Core/DataExtractor.h"
Enrico Granatad760907c2012-02-17 03:18:30 +000021#include "lldb/Core/DataVisualization.h"
Caroline Tice7826c882010-10-26 03:11:13 +000022#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Core/Module.h"
Greg Clayton0fb0bcc2011-08-03 22:57:10 +000024#include "lldb/Core/Scalar.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000025#include "lldb/Core/Section.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026#include "lldb/Core/Stream.h"
27#include "lldb/Core/StreamFile.h"
28#include "lldb/Core/Value.h"
29#include "lldb/Core/ValueObject.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000030#include "lldb/Core/ValueObjectConstResult.h"
Chris Lattner24943d22010-06-08 16:52:24 +000031#include "lldb/Symbol/Block.h"
Enrico Granata49306142012-10-10 22:54:17 +000032#include "lldb/Symbol/Declaration.h"
Chris Lattner24943d22010-06-08 16:52:24 +000033#include "lldb/Symbol/ObjectFile.h"
Greg Clayton0a19a1b2012-02-04 02:27:34 +000034#include "lldb/Symbol/Type.h"
Chris Lattner24943d22010-06-08 16:52:24 +000035#include "lldb/Symbol/Variable.h"
Johnny Chenecd4feb2011-10-14 00:42:25 +000036#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000037#include "lldb/Target/ExecutionContext.h"
38#include "lldb/Target/Process.h"
39#include "lldb/Target/StackFrame.h"
Greg Claytonbdcda462010-12-20 20:49:23 +000040#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000041#include "lldb/Target/Thread.h"
42
Jim Ingham47beabb2012-10-16 21:41:58 +000043#include "lldb/API/SBDebugger.h"
44#include "lldb/API/SBExpressionOptions.h"
45#include "lldb/API/SBFrame.h"
Eli Friedman7a62c8b2010-06-09 07:44:37 +000046#include "lldb/API/SBProcess.h"
47#include "lldb/API/SBTarget.h"
48#include "lldb/API/SBThread.h"
Chris Lattner24943d22010-06-08 16:52:24 +000049
50using namespace lldb;
51using namespace lldb_private;
52
53SBValue::SBValue () :
Greg Clayton63094e02010-06-23 01:19:29 +000054 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000055{
56}
57
Enrico Granatadba1de82012-03-27 02:35:13 +000058SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000059{
Enrico Granatadba1de82012-03-27 02:35:13 +000060 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 +000061}
62
Enrico Granatadba1de82012-03-27 02:35:13 +000063SBValue::SBValue(const SBValue &rhs)
Greg Clayton538eb822010-11-05 23:17:00 +000064{
Enrico Granatadba1de82012-03-27 02:35:13 +000065 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 +000066}
67
Greg Claytond68e0892011-09-09 23:04:00 +000068SBValue &
Greg Clayton538eb822010-11-05 23:17:00 +000069SBValue::operator = (const SBValue &rhs)
70{
71 if (this != &rhs)
Enrico Granatadba1de82012-03-27 02:35:13 +000072 {
73 SetSP(rhs.m_opaque_sp); // whenever setting the SP call SetSP() since it knows how to deal with synthetic values properly
74 }
Greg Clayton538eb822010-11-05 23:17:00 +000075 return *this;
76}
77
Chris Lattner24943d22010-06-08 16:52:24 +000078SBValue::~SBValue()
79{
80}
81
82bool
Greg Claytond68e0892011-09-09 23:04:00 +000083SBValue::IsValid ()
Chris Lattner24943d22010-06-08 16:52:24 +000084{
Greg Clayton49ce6822010-10-31 03:01:06 +000085 // If this function ever changes to anything that does more than just
86 // check if the opaque shared pointer is non NULL, then we need to update
87 // all "if (m_opaque_sp)" code in this file.
88 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000089}
90
Jim Inghame0bd5712011-12-19 20:39:44 +000091void
92SBValue::Clear()
93{
94 m_opaque_sp.reset();
95}
96
Greg Claytonc5f728c2010-10-06 22:10:17 +000097SBError
98SBValue::GetError()
99{
100 SBError sb_error;
101
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000102 lldb::ValueObjectSP value_sp(GetSP());
103 if (value_sp)
104 sb_error.SetError(value_sp->GetError());
Greg Clayton334d33a2012-01-30 07:41:31 +0000105 else
106 sb_error.SetErrorString("error: invalid value");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000107
108 return sb_error;
109}
110
Johnny Chen968958c2011-07-07 20:46:23 +0000111user_id_t
112SBValue::GetID()
113{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000114 lldb::ValueObjectSP value_sp(GetSP());
115 if (value_sp)
116 return value_sp->GetID();
Johnny Chen968958c2011-07-07 20:46:23 +0000117 return LLDB_INVALID_UID;
118}
119
Chris Lattner24943d22010-06-08 16:52:24 +0000120const char *
121SBValue::GetName()
122{
Greg Clayton49ce6822010-10-31 03:01:06 +0000123
124 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000125 lldb::ValueObjectSP value_sp(GetSP());
126 if (value_sp)
127 name = value_sp->GetName().GetCString();
Greg Clayton49ce6822010-10-31 03:01:06 +0000128
Greg Claytone005f2c2010-11-06 01:53:30 +0000129 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000130 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000131 {
132 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000133 log->Printf ("SBValue(%p)::GetName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000134 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000135 log->Printf ("SBValue(%p)::GetName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000136 }
Caroline Tice7826c882010-10-26 03:11:13 +0000137
Greg Clayton49ce6822010-10-31 03:01:06 +0000138 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000139}
140
141const char *
142SBValue::GetTypeName ()
143{
Jim Ingham684d4012012-08-21 01:46:35 +0000144 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000145 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000146 lldb::ValueObjectSP value_sp(GetSP());
147 if (value_sp)
Jim Ingham684d4012012-08-21 01:46:35 +0000148 {
149 // For a dynamic type we might have to run code to determine the type we are going to report,
150 // and we might not have updated the type before we get asked this. So make sure to get the API lock.
151
152 ProcessSP process_sp(value_sp->GetProcessSP());
153 Process::StopLocker stop_locker;
154 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
155 {
156 if (log)
157 log->Printf ("SBValue(%p)::GetTypeName() => error: process is running", value_sp.get());
158 }
159 else
160 {
161 TargetSP target_sp(value_sp->GetTargetSP());
162 if (target_sp)
163 {
164 Mutex::Locker api_locker (target_sp->GetAPIMutex());
165 name = value_sp->GetQualifiedTypeName().GetCString();
166 }
167 }
168 }
169
Greg Clayton49ce6822010-10-31 03:01:06 +0000170 if (log)
171 {
172 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000173 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000174 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000175 log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000176 }
177
178 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000179}
180
181size_t
182SBValue::GetByteSize ()
183{
Jim Ingham684d4012012-08-21 01:46:35 +0000184 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000185 size_t result = 0;
186
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000187 lldb::ValueObjectSP value_sp(GetSP());
188 if (value_sp)
Jim Ingham684d4012012-08-21 01:46:35 +0000189 {
190 // For a dynamic type we might have to run code to determine the type we are going to report,
191 // and we might not have updated the type before we get asked this. So make sure to get the API lock.
192
193 ProcessSP process_sp(value_sp->GetProcessSP());
194 Process::StopLocker stop_locker;
195 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
196 {
197 if (log)
198 log->Printf ("SBValue(%p)::GetTypeName() => error: process is running", value_sp.get());
199 }
200 else
201 {
202 TargetSP target_sp(value_sp->GetTargetSP());
203 if (target_sp)
204 {
205 Mutex::Locker api_locker (target_sp->GetAPIMutex());
206 result = value_sp->GetByteSize();
207 }
208 }
209 }
Chris Lattner24943d22010-06-08 16:52:24 +0000210
Greg Clayton49ce6822010-10-31 03:01:06 +0000211 if (log)
Greg Clayton851e30e2012-09-18 18:04:04 +0000212 log->Printf ("SBValue(%p)::GetByteSize () => %llu", value_sp.get(), (uint64_t)result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000213
Chris Lattner24943d22010-06-08 16:52:24 +0000214 return result;
215}
216
217bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000218SBValue::IsInScope ()
219{
Chris Lattner24943d22010-06-08 16:52:24 +0000220 bool result = false;
221
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000222 lldb::ValueObjectSP value_sp(GetSP());
223 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000224 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000225 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000226 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000227 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000228 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000229 result = value_sp->IsInScope ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000230 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000231 }
Chris Lattner24943d22010-06-08 16:52:24 +0000232
Greg Claytone005f2c2010-11-06 01:53:30 +0000233 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000234 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000235 log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000236
Chris Lattner24943d22010-06-08 16:52:24 +0000237 return result;
238}
239
240const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000241SBValue::GetValue ()
242{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000243 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
244
Greg Clayton49ce6822010-10-31 03:01:06 +0000245 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000246 lldb::ValueObjectSP value_sp(GetSP());
247 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000248 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000249 ProcessSP process_sp(value_sp->GetProcessSP());
250 Process::StopLocker stop_locker;
251 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000252 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000253 if (log)
254 log->Printf ("SBValue(%p)::GetValue() => error: process is running", value_sp.get());
255 }
256 else
257 {
258 TargetSP target_sp(value_sp->GetTargetSP());
259 if (target_sp)
260 {
261 Mutex::Locker api_locker (target_sp->GetAPIMutex());
262 cstr = value_sp->GetValueAsCString ();
263 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000264 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000265 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000266 if (log)
267 {
268 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000269 log->Printf ("SBValue(%p)::GetValue() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000270 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000271 log->Printf ("SBValue(%p)::GetValue() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000272 }
273
274 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000275}
276
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000277ValueType
278SBValue::GetValueType ()
279{
Greg Clayton49ce6822010-10-31 03:01:06 +0000280 ValueType result = eValueTypeInvalid;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000281 lldb::ValueObjectSP value_sp(GetSP());
282 if (value_sp)
283 result = value_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000284 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000285 if (log)
286 {
287 switch (result)
288 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000289 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break;
290 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break;
291 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break;
292 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break;
293 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break;
294 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break;
295 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break;
296 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break;
297 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", value_sp.get(), result); break;
Greg Clayton49ce6822010-10-31 03:01:06 +0000298 }
299 }
300 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000301}
302
Jim Ingham4ae51962010-09-10 23:12:17 +0000303const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000304SBValue::GetObjectDescription ()
305{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000306 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000307 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000308 lldb::ValueObjectSP value_sp(GetSP());
309 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000310 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000311 ProcessSP process_sp(value_sp->GetProcessSP());
312 Process::StopLocker stop_locker;
313 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000314 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000315 if (log)
316 log->Printf ("SBValue(%p)::GetObjectDescription() => error: process is running", value_sp.get());
317 }
318 else
319 {
320 TargetSP target_sp(value_sp->GetTargetSP());
321 if (target_sp)
322 {
323 Mutex::Locker api_locker (target_sp->GetAPIMutex());
324 cstr = value_sp->GetObjectDescription ();
325 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000326 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000327 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000328 if (log)
329 {
330 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000331 log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000332 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000333 log->Printf ("SBValue(%p)::GetObjectDescription() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000334 }
335 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000336}
337
Enrico Granata979e20d2011-07-29 19:53:35 +0000338SBType
339SBValue::GetType()
340{
Jim Ingham5b4905d2012-04-13 18:30:20 +0000341 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000342 SBType sb_type;
343 lldb::ValueObjectSP value_sp(GetSP());
344 TypeImplSP type_sp;
345 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000346 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000347 ProcessSP process_sp(value_sp->GetProcessSP());
348 Process::StopLocker stop_locker;
349 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
350 {
351 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000352 log->Printf ("SBValue(%p)::GetType() => error: process is running", value_sp.get());
Jim Ingham5b4905d2012-04-13 18:30:20 +0000353 }
354 else
355 {
356 TargetSP target_sp(value_sp->GetTargetSP());
357 if (target_sp)
358 {
359 Mutex::Locker api_locker (target_sp->GetAPIMutex());
360 type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType())));
361 sb_type.SetSP(type_sp);
362 }
363 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000364 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000365 if (log)
366 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000367 if (type_sp)
368 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000369 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000370 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000371 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000372 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000373}
374
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000375bool
376SBValue::GetValueDidChange ()
377{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000378 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000379 bool result = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000380 lldb::ValueObjectSP value_sp(GetSP());
381 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000382 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000383 ProcessSP process_sp(value_sp->GetProcessSP());
384 Process::StopLocker stop_locker;
385 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000386 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000387 if (log)
388 log->Printf ("SBValue(%p)::GetValueDidChange() => error: process is running", value_sp.get());
389 }
390 else
391 {
392 TargetSP target_sp(value_sp->GetTargetSP());
393 if (target_sp)
394 {
395 Mutex::Locker api_locker (target_sp->GetAPIMutex());
396 result = value_sp->GetValueDidChange ();
397 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000398 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000399 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000400 if (log)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000401 log->Printf ("SBValue(%p)::GetValueDidChange() => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000402
403 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000404}
405
Jason Molendac48ca822012-02-21 05:33:55 +0000406#ifndef LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000407const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000408SBValue::GetSummary ()
409{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000410 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000411 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000412 lldb::ValueObjectSP value_sp(GetSP());
413 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000414 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000415 ProcessSP process_sp(value_sp->GetProcessSP());
416 Process::StopLocker stop_locker;
417 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000418 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000419 if (log)
420 log->Printf ("SBValue(%p)::GetSummary() => error: process is running", value_sp.get());
421 }
422 else
423 {
424 TargetSP target_sp(value_sp->GetTargetSP());
425 if (target_sp)
426 {
427 Mutex::Locker api_locker (target_sp->GetAPIMutex());
428 cstr = value_sp->GetSummaryAsCString();
429 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000430 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000431 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000432 if (log)
433 {
434 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000435 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000436 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000437 log->Printf ("SBValue(%p)::GetSummary() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000438 }
439 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000440}
Jason Molendac48ca822012-02-21 05:33:55 +0000441#endif // LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000442
443const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000444SBValue::GetLocation ()
445{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000446 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000447 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000448 lldb::ValueObjectSP value_sp(GetSP());
449 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000450 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000451 ProcessSP process_sp(value_sp->GetProcessSP());
452 Process::StopLocker stop_locker;
453 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000454 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000455 if (log)
456 log->Printf ("SBValue(%p)::GetLocation() => error: process is running", value_sp.get());
457 }
458 else
459 {
460 TargetSP target_sp(value_sp->GetTargetSP());
461 if (target_sp)
462 {
463 Mutex::Locker api_locker (target_sp->GetAPIMutex());
464 cstr = value_sp->GetLocationAsCString();
465 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000466 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000467 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000468 if (log)
469 {
470 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000471 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000472 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000473 log->Printf ("SBValue(%p)::GetLocation() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000474 }
475 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000476}
477
Enrico Granata651cbe22012-05-08 21:25:06 +0000478// Deprecated - use the one that takes an lldb::SBError
Chris Lattner24943d22010-06-08 16:52:24 +0000479bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000480SBValue::SetValueFromCString (const char *value_str)
481{
Enrico Granata651cbe22012-05-08 21:25:06 +0000482 lldb::SBError dummy;
483 return SetValueFromCString(value_str,dummy);
484}
485
486bool
487SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
488{
Chris Lattner24943d22010-06-08 16:52:24 +0000489 bool success = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000490 lldb::ValueObjectSP value_sp(GetSP());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000491 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000492 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000493 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000494 ProcessSP process_sp(value_sp->GetProcessSP());
495 Process::StopLocker stop_locker;
496 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000497 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000498 if (log)
499 log->Printf ("SBValue(%p)::SetValueFromCString() => error: process is running", value_sp.get());
500 }
501 else
502 {
503 TargetSP target_sp(value_sp->GetTargetSP());
504 if (target_sp)
505 {
506 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata651cbe22012-05-08 21:25:06 +0000507 success = value_sp->SetValueFromCString (value_str,error.ref());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000508 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000509 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000510 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000511 if (log)
512 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i", value_sp.get(), value_str, success);
513
Chris Lattner24943d22010-06-08 16:52:24 +0000514 return success;
515}
516
Enrico Granatad760907c2012-02-17 03:18:30 +0000517lldb::SBTypeFormat
518SBValue::GetTypeFormat ()
519{
520 lldb::SBTypeFormat format;
521 lldb::ValueObjectSP value_sp(GetSP());
522 if (value_sp)
523 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000524 ProcessSP process_sp(value_sp->GetProcessSP());
525 Process::StopLocker stop_locker;
526 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000527 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000528 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
529 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000530 log->Printf ("SBValue(%p)::GetTypeFormat() => error: process is running", value_sp.get());
Jim Ingham5b4905d2012-04-13 18:30:20 +0000531 }
532 else
533 {
534 TargetSP target_sp(value_sp->GetTargetSP());
535 if (target_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000536 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000537 Mutex::Locker api_locker (target_sp->GetAPIMutex());
538 if (value_sp->UpdateValueIfNeeded(true))
539 {
540 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
541 if (format_sp)
542 format.SetSP(format_sp);
543 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000544 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000545 }
546 }
547 return format;
548}
549
Jason Molendac48ca822012-02-21 05:33:55 +0000550#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000551lldb::SBTypeSummary
552SBValue::GetTypeSummary ()
553{
554 lldb::SBTypeSummary summary;
555 lldb::ValueObjectSP value_sp(GetSP());
556 if (value_sp)
557 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000558 ProcessSP process_sp(value_sp->GetProcessSP());
559 Process::StopLocker stop_locker;
560 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000561 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000562 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
563 if (log)
564 log->Printf ("SBValue(%p)::GetTypeSummary() => error: process is running", value_sp.get());
565 }
566 else
567 {
568 TargetSP target_sp(value_sp->GetTargetSP());
569 if (target_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000570 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000571 Mutex::Locker api_locker (target_sp->GetAPIMutex());
572 if (value_sp->UpdateValueIfNeeded(true))
573 {
574 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
575 if (summary_sp)
576 summary.SetSP(summary_sp);
577 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000578 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000579 }
580 }
581 return summary;
582}
Jason Molendac48ca822012-02-21 05:33:55 +0000583#endif // LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000584
585lldb::SBTypeFilter
586SBValue::GetTypeFilter ()
587{
588 lldb::SBTypeFilter filter;
589 lldb::ValueObjectSP value_sp(GetSP());
590 if (value_sp)
591 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000592 ProcessSP process_sp(value_sp->GetProcessSP());
593 Process::StopLocker stop_locker;
594 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000595 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000596 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
597 if (log)
598 log->Printf ("SBValue(%p)::GetTypeFilter() => error: process is running", value_sp.get());
599 }
600 else
601 {
602 TargetSP target_sp(value_sp->GetTargetSP());
603 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000604 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000605 Mutex::Locker api_locker (target_sp->GetAPIMutex());
606 if (value_sp->UpdateValueIfNeeded(true))
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000607 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000608 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
609
610 if (synthetic_sp && !synthetic_sp->IsScripted())
611 {
612 TypeFilterImplSP filter_sp = STD_STATIC_POINTER_CAST(TypeFilterImpl,synthetic_sp);
613 filter.SetSP(filter_sp);
614 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000615 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000616 }
617 }
618 }
619 return filter;
620}
621
Jason Molendac48ca822012-02-21 05:33:55 +0000622#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000623lldb::SBTypeSynthetic
624SBValue::GetTypeSynthetic ()
625{
626 lldb::SBTypeSynthetic synthetic;
627 lldb::ValueObjectSP value_sp(GetSP());
628 if (value_sp)
629 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000630 ProcessSP process_sp(value_sp->GetProcessSP());
631 Process::StopLocker stop_locker;
632 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000633 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000634 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
635 if (log)
636 log->Printf ("SBValue(%p)::GetTypeSynthetic() => error: process is running", value_sp.get());
637 }
638 else
639 {
640 TargetSP target_sp(value_sp->GetTargetSP());
641 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000642 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000643 Mutex::Locker api_locker (target_sp->GetAPIMutex());
644 if (value_sp->UpdateValueIfNeeded(true))
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000645 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000646 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
647
648 if (children_sp && children_sp->IsScripted())
649 {
650 TypeSyntheticImplSP synth_sp = STD_STATIC_POINTER_CAST(TypeSyntheticImpl,children_sp);
651 synthetic.SetSP(synth_sp);
652 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000653 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000654 }
655 }
656 }
657 return synthetic;
658}
Jason Molendac48ca822012-02-21 05:33:55 +0000659#endif
Enrico Granatad760907c2012-02-17 03:18:30 +0000660
Enrico Granata979e20d2011-07-29 19:53:35 +0000661lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000662SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000663{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000664 lldb::SBValue sb_value;
665 lldb::ValueObjectSP value_sp(GetSP());
666 lldb::ValueObjectSP new_value_sp;
667 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000668 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000669 ProcessSP process_sp(value_sp->GetProcessSP());
670 Process::StopLocker stop_locker;
671 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata979e20d2011-07-29 19:53:35 +0000672 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000673 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
674 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000675 log->Printf ("SBValue(%p)::CreateChildAtOffset() => error: process is running", value_sp.get());
Jim Ingham5b4905d2012-04-13 18:30:20 +0000676 }
677 else
678 {
679 TargetSP target_sp(value_sp->GetTargetSP());
680 if (target_sp)
681 {
682 Mutex::Locker api_locker (target_sp->GetAPIMutex());
683 TypeImplSP type_sp (type.GetSP());
684 if (type.IsValid())
685 {
686 sb_value = SBValue(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true));
687 new_value_sp = sb_value.GetSP();
688 if (new_value_sp)
689 new_value_sp->SetName(ConstString(name));
690 }
691 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000692 }
693 }
694 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
695 if (log)
696 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000697 if (new_value_sp)
Jim Ingham47beabb2012-10-16 21:41:58 +0000698 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"",
699 value_sp.get(),
700 new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000701 else
Jim Ingham47beabb2012-10-16 21:41:58 +0000702 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL",
703 value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000704 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000705 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000706}
707
708lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000709SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000710{
Greg Clayton4eb01a72012-01-31 04:25:15 +0000711 lldb::SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000712 lldb::ValueObjectSP value_sp(GetSP());
713 TypeImplSP type_sp (type.GetSP());
714 if (value_sp && type_sp)
715 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()));
Greg Clayton4eb01a72012-01-31 04:25:15 +0000716 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000717}
718
719lldb::SBValue
720SBValue::CreateValueFromExpression (const char *name, const char* expression)
721{
Jim Ingham47beabb2012-10-16 21:41:58 +0000722 SBExpressionOptions options;
723 options.SetKeepInMemory(true);
724 return CreateValueFromExpression (name, expression, options);
725}
726
727lldb::SBValue
728SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options)
729{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000730 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000731 lldb::SBValue sb_value;
732 lldb::ValueObjectSP value_sp(GetSP());
733 lldb::ValueObjectSP new_value_sp;
734 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000735 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000736 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000737 ProcessSP process_sp(exe_ctx.GetProcessSP());
738 Process::StopLocker stop_locker;
739 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Johnny Chen9fd2e382011-12-20 01:52:44 +0000740 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000741 if (log)
742 log->Printf ("SBValue(%p)::CreateValueFromExpression() => error: process is running", value_sp.get());
743 }
744 else
745 {
746 Target* target = exe_ctx.GetTargetPtr();
747 if (target)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000748 {
Enrico Granatad27026e2012-09-05 20:41:26 +0000749 options.SetKeepInMemory(true);
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000750 target->EvaluateExpression (expression,
751 exe_ctx.GetFramePtr(),
Enrico Granatad27026e2012-09-05 20:41:26 +0000752 new_value_sp,
Jim Ingham47beabb2012-10-16 21:41:58 +0000753 options.ref());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000754 if (new_value_sp)
755 {
756 new_value_sp->SetName(ConstString(name));
757 sb_value.SetSP(new_value_sp);
758 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000759 }
Johnny Chen9fd2e382011-12-20 01:52:44 +0000760 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000761 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000762 if (log)
763 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000764 if (new_value_sp)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000765 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000766 value_sp.get(),
767 name,
768 expression,
769 new_value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000770 else
Greg Clayton12b7ea32012-06-04 20:13:23 +0000771 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000772 value_sp.get(),
773 name,
774 expression);
Enrico Granata979e20d2011-07-29 19:53:35 +0000775 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000776 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000777}
778
779lldb::SBValue
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000780SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000781{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000782 lldb::SBValue sb_value;
783 lldb::ValueObjectSP value_sp(GetSP());
784 lldb::ValueObjectSP new_value_sp;
785 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
786 if (value_sp && type_impl_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000787 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000788 ClangASTType pointee_ast_type(type_impl_sp->GetASTContext(), type_impl_sp->GetClangASTType().GetPointerType ());
789 lldb::TypeImplSP pointee_type_impl_sp (new TypeImpl(pointee_ast_type));
790 if (pointee_type_impl_sp)
Enrico Granatac9310302011-08-04 17:07:02 +0000791 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000792
793 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
794
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000795 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
796 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000797 pointee_type_impl_sp->GetASTContext(),
798 pointee_type_impl_sp->GetOpaqueQualType(),
799 ConstString(name),
800 buffer,
801 lldb::endian::InlHostByteOrder(),
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000802 exe_ctx.GetAddressByteSize()));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000803
804 if (ptr_result_valobj_sp)
805 {
806 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
807 Error err;
808 new_value_sp = ptr_result_valobj_sp->Dereference(err);
809 if (new_value_sp)
810 new_value_sp->SetName(ConstString(name));
811 }
812 sb_value.SetSP(new_value_sp);
Enrico Granatac9310302011-08-04 17:07:02 +0000813 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000814 }
815 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
816 if (log)
817 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000818 if (new_value_sp)
819 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000820 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000821 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
Johnny Chena713b862011-08-09 22:38:07 +0000822 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000823 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000824}
825
Enrico Granata91544802011-09-06 19:20:51 +0000826lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000827SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000828{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000829 lldb::SBValue sb_value;
830 lldb::ValueObjectSP new_value_sp;
831 lldb::ValueObjectSP value_sp(GetSP());
832 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +0000833 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000834 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
835
836 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000837 type.m_opaque_sp->GetASTContext() ,
838 type.m_opaque_sp->GetOpaqueQualType(),
839 ConstString(name),
840 *data.m_opaque_sp,
841 LLDB_INVALID_ADDRESS);
842 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
843 sb_value.SetSP(new_value_sp);
Enrico Granata91544802011-09-06 19:20:51 +0000844 }
845 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
846 if (log)
847 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000848 if (new_value_sp)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000849 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000850 else
Greg Clayton12b7ea32012-06-04 20:13:23 +0000851 log->Printf ("SBValue(%p)::CreateValueFromData => NULL", value_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +0000852 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000853 return sb_value;
Enrico Granata91544802011-09-06 19:20:51 +0000854}
855
Chris Lattner24943d22010-06-08 16:52:24 +0000856SBValue
857SBValue::GetChildAtIndex (uint32_t idx)
858{
Greg Clayton8f64c472011-07-15 19:31:49 +0000859 const bool can_create_synthetic = false;
860 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000861 lldb::ValueObjectSP value_sp(GetSP());
862 if (value_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000863 {
864 TargetSP target_sp(value_sp->GetTargetSP());
865 if (target_sp)
866 use_dynamic = target_sp->GetPreferDynamicValue();
867 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000868 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000869}
870
871SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000872SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000873{
Chris Lattner24943d22010-06-08 16:52:24 +0000874 lldb::ValueObjectSP child_sp;
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000875 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000876
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000877 lldb::ValueObjectSP value_sp(GetSP());
878 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000879 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000880 ProcessSP process_sp(value_sp->GetProcessSP());
881 Process::StopLocker stop_locker;
882 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000883 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000884 if (log)
885 log->Printf ("SBValue(%p)::GetChildAtIndex() => error: process is running", value_sp.get());
886 }
887 else
888 {
889 TargetSP target_sp(value_sp->GetTargetSP());
890 if (target_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000891 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000892 Mutex::Locker api_locker (target_sp->GetAPIMutex());
893 const bool can_create = true;
894 child_sp = value_sp->GetChildAtIndex (idx, can_create);
895 if (can_create_synthetic && !child_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000896 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000897 if (value_sp->IsPointerType())
898 {
899 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
900 }
901 else if (value_sp->IsArrayType())
902 {
903 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
904 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000905 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000906
907 if (child_sp)
Greg Clayton8f64c472011-07-15 19:31:49 +0000908 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000909 if (use_dynamic != lldb::eNoDynamicValues)
910 {
911 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
912 if (dynamic_sp)
913 child_sp = dynamic_sp;
914 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000915 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000916 }
Jim Inghame41494a2011-04-16 00:01:13 +0000917 }
918 }
919
Chris Lattner24943d22010-06-08 16:52:24 +0000920 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000921 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000922 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000923
Chris Lattner24943d22010-06-08 16:52:24 +0000924 return sb_value;
925}
926
927uint32_t
928SBValue::GetIndexOfChildWithName (const char *name)
929{
Greg Clayton49ce6822010-10-31 03:01:06 +0000930 uint32_t idx = UINT32_MAX;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000931 lldb::ValueObjectSP value_sp(GetSP());
932 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000933 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000934 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000935 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000936 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000937 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000938
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000939 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000940 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000941 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000942 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000943 if (log)
944 {
945 if (idx == UINT32_MAX)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000946 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000947 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000948 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
Greg Clayton49ce6822010-10-31 03:01:06 +0000949 }
950 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000951}
952
953SBValue
954SBValue::GetChildMemberWithName (const char *name)
955{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000956 lldb::ValueObjectSP value_sp(GetSP());
957 if (value_sp)
Johnny Chen446ccaa2011-06-29 21:19:39 +0000958 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000959 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000960 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000961 if (target_sp)
962 {
963 Mutex::Locker api_locker (target_sp->GetAPIMutex());
964 use_dynamic_value = target_sp->GetPreferDynamicValue();
965 }
Johnny Chen446ccaa2011-06-29 21:19:39 +0000966 return GetChildMemberWithName (name, use_dynamic_value);
967 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000968 return SBValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000969}
970
971SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000972SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000973{
Chris Lattner24943d22010-06-08 16:52:24 +0000974 lldb::ValueObjectSP child_sp;
975 const ConstString str_name (name);
976
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000977 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton905acaf2011-05-20 22:07:17 +0000978
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000979 lldb::ValueObjectSP value_sp(GetSP());
980 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000981 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000982 ProcessSP process_sp(value_sp->GetProcessSP());
983 Process::StopLocker stop_locker;
984 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Jim Inghame41494a2011-04-16 00:01:13 +0000985 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000986 if (log)
987 log->Printf ("SBValue(%p)::GetChildMemberWithName() => error: process is running", value_sp.get());
988 }
989 else
990 {
991 TargetSP target_sp(value_sp->GetTargetSP());
992 if (target_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000993 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000994 Mutex::Locker api_locker (target_sp->GetAPIMutex());
995 child_sp = value_sp->GetChildMemberWithName (str_name, true);
996 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000997 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000998 if (child_sp)
999 {
1000 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
1001 if (dynamic_sp)
1002 child_sp = dynamic_sp;
1003 }
Greg Claytonb9dcc512011-06-29 18:28:50 +00001004 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001005 }
Jim Inghame41494a2011-04-16 00:01:13 +00001006 }
1007 }
1008
Chris Lattner24943d22010-06-08 16:52:24 +00001009 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +00001010
Greg Clayton49ce6822010-10-31 03:01:06 +00001011 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001012 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +00001013
Chris Lattner24943d22010-06-08 16:52:24 +00001014 return sb_value;
1015}
1016
Enrico Granataf7a9b142011-07-15 02:26:42 +00001017lldb::SBValue
Jim Ingham1b425752011-12-08 19:44:08 +00001018SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
1019{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001020 lldb::ValueObjectSP value_sp(GetSP());
1021 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001022 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001023 ProcessSP process_sp(value_sp->GetProcessSP());
1024 Process::StopLocker stop_locker;
1025 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Jim Ingham1b425752011-12-08 19:44:08 +00001026 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001027 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1028 if (log)
1029 log->Printf ("SBValue(%p)::GetDynamicValue() => error: process is running", value_sp.get());
1030 }
1031 else
1032 {
1033 TargetSP target_sp(value_sp->GetTargetSP());
1034 if (target_sp)
1035 {
1036 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1037 return SBValue (value_sp->GetDynamicValue(use_dynamic));
1038 }
Jim Ingham1b425752011-12-08 19:44:08 +00001039 }
1040 }
1041
1042 return SBValue();
1043}
1044
1045lldb::SBValue
1046SBValue::GetStaticValue ()
1047{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001048 lldb::ValueObjectSP value_sp(GetSP());
1049 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001050 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001051 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001052 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001053 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001054 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001055 return SBValue(value_sp->GetStaticValue());
Jim Ingham1b425752011-12-08 19:44:08 +00001056 }
1057 }
1058
1059 return SBValue();
1060}
1061
Enrico Granatadba1de82012-03-27 02:35:13 +00001062lldb::SBValue
1063SBValue::GetNonSyntheticValue ()
1064{
1065 SBValue sb_value;
1066 lldb::ValueObjectSP value_sp(GetSP());
1067 if (value_sp)
1068 {
1069 if (value_sp->IsSynthetic())
1070 {
1071 TargetSP target_sp(value_sp->GetTargetSP());
1072 if (target_sp)
1073 {
1074 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1075 // deliberately breaking the rules here to optimize the case where we DO NOT want
1076 // the synthetic value to be returned to the user - if we did not do this, we would have to tell
1077 // the target to suppress the synthetic value, and then return the flag to its original value
Enrico Granata4758a3c2012-05-08 18:47:08 +00001078 if (value_sp->GetNonSyntheticValue())
1079 sb_value.m_opaque_sp = value_sp->GetNonSyntheticValue();
Enrico Granatadba1de82012-03-27 02:35:13 +00001080 }
1081 }
1082 }
1083 return sb_value;
1084}
1085
Jim Ingham1b425752011-12-08 19:44:08 +00001086bool
1087SBValue::IsDynamic()
1088{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001089 lldb::ValueObjectSP value_sp(GetSP());
1090 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001091 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001092 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001093 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001094 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001095 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001096 return value_sp->IsDynamic();
Jim Ingham1b425752011-12-08 19:44:08 +00001097 }
1098 }
1099 return false;
1100}
1101
1102lldb::SBValue
Enrico Granataf7a9b142011-07-15 02:26:42 +00001103SBValue::GetValueForExpressionPath(const char* expr_path)
1104{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001105 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf7a9b142011-07-15 02:26:42 +00001106 lldb::ValueObjectSP child_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001107 lldb::ValueObjectSP value_sp(GetSP());
1108 if (value_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +00001109 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001110 ProcessSP process_sp(value_sp->GetProcessSP());
1111 Process::StopLocker stop_locker;
1112 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granataf7a9b142011-07-15 02:26:42 +00001113 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001114 if (log)
1115 log->Printf ("SBValue(%p)::GetValueForExpressionPath() => error: process is running", value_sp.get());
1116 }
1117 else
1118 {
1119 TargetSP target_sp(value_sp->GetTargetSP());
1120 if (target_sp)
1121 {
1122 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1123 // using default values for all the fancy options, just do it if you can
1124 child_sp = value_sp->GetValueForExpressionPath(expr_path);
1125 }
Enrico Granataf7a9b142011-07-15 02:26:42 +00001126 }
1127 }
1128
1129 SBValue sb_value (child_sp);
1130
Enrico Granataf7a9b142011-07-15 02:26:42 +00001131 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001132 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 +00001133
1134 return sb_value;
1135}
Chris Lattner24943d22010-06-08 16:52:24 +00001136
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001137int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +00001138SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1139{
Jim Ingham574c3d62011-08-12 23:34:31 +00001140 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001141 lldb::ValueObjectSP value_sp(GetSP());
1142 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +00001143 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001144 ProcessSP process_sp(value_sp->GetProcessSP());
1145 Process::StopLocker stop_locker;
1146 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatac92eb402011-08-04 01:41:02 +00001147 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001148 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1149 if (log)
1150 log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
1151 error.SetErrorString("process is running");
Enrico Granatac92eb402011-08-04 01:41:02 +00001152 }
1153 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001154 {
1155 TargetSP target_sp(value_sp->GetTargetSP());
1156 if (target_sp)
1157 {
1158 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1159 Scalar scalar;
1160 if (value_sp->ResolveValue (scalar))
1161 return scalar.GetRawBits64(fail_value);
1162 else
1163 error.SetErrorString("could not get value");
1164 }
1165 else
1166 error.SetErrorString("could not get target");
1167 }
Enrico Granatac92eb402011-08-04 01:41:02 +00001168 }
1169 error.SetErrorString("invalid SBValue");
1170 return fail_value;
1171}
1172
1173uint64_t
1174SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1175{
Jim Ingham574c3d62011-08-12 23:34:31 +00001176 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001177 lldb::ValueObjectSP value_sp(GetSP());
1178 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +00001179 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001180 ProcessSP process_sp(value_sp->GetProcessSP());
1181 Process::StopLocker stop_locker;
1182 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatac92eb402011-08-04 01:41:02 +00001183 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001184 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1185 if (log)
1186 log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
1187 error.SetErrorString("process is running");
Enrico Granatac92eb402011-08-04 01:41:02 +00001188 }
1189 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001190 {
1191 TargetSP target_sp(value_sp->GetTargetSP());
1192 if (target_sp)
1193 {
1194 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1195 Scalar scalar;
1196 if (value_sp->ResolveValue (scalar))
1197 return scalar.GetRawBits64(fail_value);
1198 else
1199 error.SetErrorString("could not get value");
1200 }
1201 else
1202 error.SetErrorString("could not get target");
1203 }
Enrico Granatac92eb402011-08-04 01:41:02 +00001204 }
1205 error.SetErrorString("invalid SBValue");
1206 return fail_value;
1207}
1208
1209int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001210SBValue::GetValueAsSigned(int64_t fail_value)
1211{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001212 lldb::ValueObjectSP value_sp(GetSP());
1213 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +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 Clayton0fb0bcc2011-08-03 22:57:10 +00001218 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001219 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1220 if (log)
1221 log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
1222 }
1223 else
1224 {
1225 TargetSP target_sp(value_sp->GetTargetSP());
1226 if (target_sp)
1227 {
1228 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1229 Scalar scalar;
1230 if (value_sp->ResolveValue (scalar))
1231 return scalar.GetRawBits64(fail_value);
1232 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001233 }
1234 }
1235 return fail_value;
1236}
1237
1238uint64_t
1239SBValue::GetValueAsUnsigned(uint64_t fail_value)
1240{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001241 lldb::ValueObjectSP value_sp(GetSP());
1242 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001243 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001244 ProcessSP process_sp(value_sp->GetProcessSP());
1245 Process::StopLocker stop_locker;
1246 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001247 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001248 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1249 if (log)
1250 log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
1251 }
1252 else
1253 {
1254 TargetSP target_sp(value_sp->GetTargetSP());
1255 if (target_sp)
1256 {
1257 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1258 Scalar scalar;
1259 if (value_sp->ResolveValue (scalar))
1260 return scalar.GetRawBits64(fail_value);
1261 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001262 }
1263 }
1264 return fail_value;
1265}
1266
Chris Lattner24943d22010-06-08 16:52:24 +00001267uint32_t
1268SBValue::GetNumChildren ()
1269{
1270 uint32_t num_children = 0;
1271
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001272 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001273 lldb::ValueObjectSP value_sp(GetSP());
1274 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001275 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001276 ProcessSP process_sp(value_sp->GetProcessSP());
1277 Process::StopLocker stop_locker;
1278 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +00001279 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001280 if (log)
1281 log->Printf ("SBValue(%p)::GetNumChildren() => error: process is running", value_sp.get());
1282 }
1283 else
1284 {
1285 TargetSP target_sp(value_sp->GetTargetSP());
1286 if (target_sp)
1287 {
1288 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001289
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001290 num_children = value_sp->GetNumChildren();
1291 }
Greg Claytonb9dcc512011-06-29 18:28:50 +00001292 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001293 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001294
Greg Clayton49ce6822010-10-31 03:01:06 +00001295 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001296 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +00001297
1298 return num_children;
1299}
1300
Chris Lattner24943d22010-06-08 16:52:24 +00001301
1302SBValue
1303SBValue::Dereference ()
1304{
Greg Clayton49ce6822010-10-31 03:01:06 +00001305 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001306 lldb::ValueObjectSP value_sp(GetSP());
1307 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001308 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001309 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001310 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001311 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001312 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001313
Greg Claytonb9dcc512011-06-29 18:28:50 +00001314 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001315 sb_value = value_sp->Dereference (error);
Greg Claytonb9dcc512011-06-29 18:28:50 +00001316 }
Chris Lattner24943d22010-06-08 16:52:24 +00001317 }
Greg Claytone005f2c2010-11-06 01:53:30 +00001318 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001319 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001320 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +00001321
1322 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +00001323}
1324
1325bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001326SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +00001327{
1328 bool is_ptr_type = false;
1329
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001330 lldb::ValueObjectSP value_sp(GetSP());
1331 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001332 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001333 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001334 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001335 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001336 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001337
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001338 is_ptr_type = value_sp->IsPointerType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001339 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001340 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001341
Greg Claytone005f2c2010-11-06 01:53:30 +00001342 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001343 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001344 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
Greg Clayton49ce6822010-10-31 03:01:06 +00001345
Chris Lattner24943d22010-06-08 16:52:24 +00001346
1347 return is_ptr_type;
1348}
1349
Chris Lattner24943d22010-06-08 16:52:24 +00001350void *
1351SBValue::GetOpaqueType()
1352{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001353 lldb::ValueObjectSP value_sp(GetSP());
1354 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001355 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001356 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001357 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001358 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001359 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001360
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001361 return value_sp->GetClangType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001362 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001363 }
Chris Lattner24943d22010-06-08 16:52:24 +00001364 return NULL;
1365}
1366
Enrico Granata979e20d2011-07-29 19:53:35 +00001367lldb::SBTarget
1368SBValue::GetTarget()
1369{
Greg Clayton334d33a2012-01-30 07:41:31 +00001370 SBTarget sb_target;
1371 TargetSP target_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001372 lldb::ValueObjectSP value_sp(GetSP());
1373 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001374 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001375 target_sp = value_sp->GetTargetSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001376 sb_target.SetSP (target_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001377 }
1378 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1379 if (log)
1380 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001381 if (target_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001382 log->Printf ("SBValue(%p)::GetTarget () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001383 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001384 log->Printf ("SBValue(%p)::GetTarget () => %p", value_sp.get(), target_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001385 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001386 return sb_target;
Enrico Granata979e20d2011-07-29 19:53:35 +00001387}
1388
1389lldb::SBProcess
1390SBValue::GetProcess()
1391{
Greg Clayton334d33a2012-01-30 07:41:31 +00001392 SBProcess sb_process;
1393 ProcessSP process_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001394 lldb::ValueObjectSP value_sp(GetSP());
1395 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001396 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001397 process_sp = value_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001398 if (process_sp)
1399 sb_process.SetSP (process_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001400 }
1401 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1402 if (log)
1403 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001404 if (process_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001405 log->Printf ("SBValue(%p)::GetProcess () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001406 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001407 log->Printf ("SBValue(%p)::GetProcess () => %p", value_sp.get(), process_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001408 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001409 return sb_process;
Enrico Granata979e20d2011-07-29 19:53:35 +00001410}
1411
1412lldb::SBThread
1413SBValue::GetThread()
1414{
Greg Clayton90c52142012-01-30 02:53:15 +00001415 SBThread sb_thread;
1416 ThreadSP thread_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001417 lldb::ValueObjectSP value_sp(GetSP());
1418 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001419 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001420 thread_sp = value_sp->GetThreadSP();
1421 sb_thread.SetThread(thread_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001422 }
1423 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1424 if (log)
1425 {
Greg Clayton90c52142012-01-30 02:53:15 +00001426 if (thread_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001427 log->Printf ("SBValue(%p)::GetThread () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001428 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001429 log->Printf ("SBValue(%p)::GetThread () => %p", value_sp.get(), thread_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001430 }
Greg Clayton90c52142012-01-30 02:53:15 +00001431 return sb_thread;
Enrico Granata979e20d2011-07-29 19:53:35 +00001432}
1433
1434lldb::SBFrame
1435SBValue::GetFrame()
1436{
Greg Clayton334d33a2012-01-30 07:41:31 +00001437 SBFrame sb_frame;
1438 StackFrameSP frame_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001439 lldb::ValueObjectSP value_sp(GetSP());
1440 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001441 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001442 frame_sp = value_sp->GetFrameSP();
1443 sb_frame.SetFrameSP (frame_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001444 }
1445 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1446 if (log)
1447 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001448 if (frame_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001449 log->Printf ("SBValue(%p)::GetFrame () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001450 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001451 log->Printf ("SBValue(%p)::GetFrame () => %p", value_sp.get(), frame_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001452 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001453 return sb_frame;
Enrico Granata979e20d2011-07-29 19:53:35 +00001454}
1455
1456
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001457lldb::ValueObjectSP
1458SBValue::GetSP () const
Chris Lattner24943d22010-06-08 16:52:24 +00001459{
Greg Clayton63094e02010-06-23 01:19:29 +00001460 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001461}
1462
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001463void
1464SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001465{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001466 m_opaque_sp = sp;
Enrico Granatadba1de82012-03-27 02:35:13 +00001467 if (IsValid() && m_opaque_sp->HasSyntheticValue())
1468 m_opaque_sp = m_opaque_sp->GetSyntheticValue();
Chris Lattner24943d22010-06-08 16:52:24 +00001469}
Caroline Tice98f930f2010-09-20 05:20:02 +00001470
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001471
Caroline Tice98f930f2010-09-20 05:20:02 +00001472bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001473SBValue::GetExpressionPath (SBStream &description)
1474{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001475 lldb::ValueObjectSP value_sp(GetSP());
1476 if (value_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +00001477 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001478 value_sp->GetExpressionPath (description.ref(), false);
Greg Claytonb01000f2011-01-17 03:46:26 +00001479 return true;
1480 }
1481 return false;
1482}
1483
1484bool
1485SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1486{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001487 lldb::ValueObjectSP value_sp(GetSP());
1488 if (value_sp)
Greg Claytonb01000f2011-01-17 03:46:26 +00001489 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001490 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +00001491 return true;
1492 }
1493 return false;
1494}
1495
1496bool
Caroline Tice98f930f2010-09-20 05:20:02 +00001497SBValue::GetDescription (SBStream &description)
1498{
Greg Clayton96154be2011-11-13 06:57:31 +00001499 Stream &strm = description.ref();
1500
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001501 lldb::ValueObjectSP value_sp(GetSP());
1502 if (value_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +00001503 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001504 ProcessSP process_sp(value_sp->GetProcessSP());
1505 Process::StopLocker stop_locker;
1506 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
1507 {
1508 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1509 if (log)
1510 log->Printf ("SBValue(%p)::GetDescription() => error: process is running", value_sp.get());
1511 }
1512 else
1513 {
1514 ValueObject::DumpValueObject (strm, value_sp.get());
1515 }
Caroline Tice98f930f2010-09-20 05:20:02 +00001516 }
1517 else
Greg Clayton96154be2011-11-13 06:57:31 +00001518 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +00001519
1520 return true;
1521}
Greg Claytone179a582011-01-05 18:43:15 +00001522
1523lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +00001524SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +00001525{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001526 lldb::ValueObjectSP value_sp(GetSP());
1527 if (value_sp)
1528 return value_sp->GetFormat();
Greg Claytone179a582011-01-05 18:43:15 +00001529 return eFormatDefault;
1530}
1531
1532void
1533SBValue::SetFormat (lldb::Format format)
1534{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001535 lldb::ValueObjectSP value_sp(GetSP());
1536 if (value_sp)
1537 value_sp->SetFormat(format);
Greg Claytone179a582011-01-05 18:43:15 +00001538}
1539
Enrico Granata979e20d2011-07-29 19:53:35 +00001540lldb::SBValue
1541SBValue::AddressOf()
1542{
1543 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001544 lldb::ValueObjectSP value_sp(GetSP());
1545 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001546 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001547 TargetSP target_sp (value_sp->GetTargetSP());
1548 if (target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001549 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001550 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001551 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001552 sb_value = value_sp->AddressOf (error);
Enrico Granata979e20d2011-07-29 19:53:35 +00001553 }
1554 }
1555 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1556 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +00001557 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)", value_sp.get(), value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001558
1559 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001560}
Enrico Granata91544802011-09-06 19:20:51 +00001561
1562lldb::addr_t
1563SBValue::GetLoadAddress()
1564{
1565 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001566 lldb::ValueObjectSP value_sp(GetSP());
1567 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001568 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001569 TargetSP target_sp (value_sp->GetTargetSP());
1570 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001571 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001572 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001573 const bool scalar_is_load_address = true;
1574 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001575 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001576 if (addr_type == eAddressTypeFile)
1577 {
Greg Clayton3508c382012-02-24 01:59:29 +00001578 ModuleSP module_sp (value_sp->GetModule());
1579 if (!module_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001580 value = LLDB_INVALID_ADDRESS;
1581 else
1582 {
1583 Address addr;
Greg Clayton3508c382012-02-24 01:59:29 +00001584 module_sp->ResolveFileAddress(value, addr);
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001585 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001586 }
1587 }
1588 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1589 value = LLDB_INVALID_ADDRESS;
1590 }
1591 }
1592 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1593 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001594 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", value_sp.get(), value);
Enrico Granata91544802011-09-06 19:20:51 +00001595
1596 return value;
1597}
1598
1599lldb::SBAddress
1600SBValue::GetAddress()
1601{
1602 Address addr;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001603 lldb::ValueObjectSP value_sp(GetSP());
1604 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001605 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001606 TargetSP target_sp (value_sp->GetTargetSP());
1607 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001608 {
1609 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001610 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001611 const bool scalar_is_load_address = true;
1612 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001613 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001614 if (addr_type == eAddressTypeFile)
1615 {
Greg Clayton3508c382012-02-24 01:59:29 +00001616 ModuleSP module_sp (value_sp->GetModule());
1617 if (module_sp)
1618 module_sp->ResolveFileAddress(value, addr);
Enrico Granata91544802011-09-06 19:20:51 +00001619 }
1620 else if (addr_type == eAddressTypeLoad)
1621 {
1622 // no need to check the return value on this.. if it can actually do the resolve
1623 // addr will be in the form (section,offset), otherwise it will simply be returned
1624 // as (NULL, value)
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001625 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001626 }
1627 }
1628 }
1629 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1630 if (log)
Jim Ingham47beabb2012-10-16 21:41:58 +00001631 log->Printf ("SBValue(%p)::GetAddress () => (%s,%llu)", value_sp.get(),
1632 (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"),
1633 addr.GetOffset());
Enrico Granata91544802011-09-06 19:20:51 +00001634 return SBAddress(new Address(addr));
1635}
1636
1637lldb::SBData
1638SBValue::GetPointeeData (uint32_t item_idx,
1639 uint32_t item_count)
1640{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001641 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata91544802011-09-06 19:20:51 +00001642 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001643 lldb::ValueObjectSP value_sp(GetSP());
1644 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001645 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001646 ProcessSP process_sp(value_sp->GetProcessSP());
1647 Process::StopLocker stop_locker;
1648 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata91544802011-09-06 19:20:51 +00001649 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001650 if (log)
1651 log->Printf ("SBValue(%p)::GetPointeeData() => error: process is running", value_sp.get());
1652 }
1653 else
1654 {
1655 TargetSP target_sp (value_sp->GetTargetSP());
1656 if (target_sp)
1657 {
1658 DataExtractorSP data_sp(new DataExtractor());
1659 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1660 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1661 if (data_sp->GetByteSize() > 0)
1662 *sb_data = data_sp;
1663 }
Enrico Granata91544802011-09-06 19:20:51 +00001664 }
1665 }
Enrico Granata91544802011-09-06 19:20:51 +00001666 if (log)
1667 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001668 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001669 item_idx,
1670 item_count,
1671 sb_data.get());
1672
1673 return sb_data;
1674}
1675
1676lldb::SBData
1677SBValue::GetData ()
1678{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001679 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata91544802011-09-06 19:20:51 +00001680 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001681 lldb::ValueObjectSP value_sp(GetSP());
1682 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001683 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001684 ProcessSP process_sp(value_sp->GetProcessSP());
1685 Process::StopLocker stop_locker;
1686 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata91544802011-09-06 19:20:51 +00001687 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001688 if (log)
1689 log->Printf ("SBValue(%p)::GetData() => error: process is running", value_sp.get());
1690 }
1691 else
1692 {
1693 TargetSP target_sp (value_sp->GetTargetSP());
1694 if (target_sp)
1695 {
1696 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1697 DataExtractorSP data_sp(new DataExtractor());
1698 value_sp->GetData(*data_sp);
1699 if (data_sp->GetByteSize() > 0)
1700 *sb_data = data_sp;
1701 }
Enrico Granata91544802011-09-06 19:20:51 +00001702 }
1703 }
Enrico Granata91544802011-09-06 19:20:51 +00001704 if (log)
1705 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001706 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001707 sb_data.get());
1708
1709 return sb_data;
1710}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001711
Enrico Granata49306142012-10-10 22:54:17 +00001712lldb::SBDeclaration
1713SBValue::GetDeclaration ()
1714{
1715 lldb::ValueObjectSP value_sp(GetSP());
1716 SBDeclaration decl_sb;
1717 if (value_sp)
1718 {
1719 Declaration decl;
1720 if (value_sp->GetDeclaration(decl))
1721 decl_sb.SetDeclaration(decl);
1722 }
1723 return decl_sb;
1724}
1725
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001726lldb::SBWatchpoint
Johnny Chen3f883492012-06-04 23:19:54 +00001727SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001728{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001729 SBWatchpoint sb_watchpoint;
1730
1731 // If the SBValue is not valid, there's no point in even trying to watch it.
1732 lldb::ValueObjectSP value_sp(GetSP());
1733 TargetSP target_sp (GetTarget().GetSP());
1734 if (value_sp && target_sp)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001735 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001736 // Can't watch this if the process is running
1737 ProcessSP process_sp(value_sp->GetProcessSP());
1738 Process::StopLocker stop_locker;
1739 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
1740 {
1741 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1742 if (log)
1743 log->Printf ("SBValue(%p)::Watch() => error: process is running", value_sp.get());
1744 return sb_watchpoint;
1745 }
1746
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001747 // Read and Write cannot both be false.
1748 if (!read && !write)
1749 return sb_watchpoint;
1750
1751 // If the value is not in scope, don't try and watch and invalid value
1752 if (!IsInScope())
1753 return sb_watchpoint;
1754
1755 addr_t addr = GetLoadAddress();
1756 if (addr == LLDB_INVALID_ADDRESS)
1757 return sb_watchpoint;
1758 size_t byte_size = GetByteSize();
1759 if (byte_size == 0)
1760 return sb_watchpoint;
1761
1762 uint32_t watch_type = 0;
1763 if (read)
1764 watch_type |= LLDB_WATCH_TYPE_READ;
1765 if (write)
1766 watch_type |= LLDB_WATCH_TYPE_WRITE;
1767
Johnny Chen3f883492012-06-04 23:19:54 +00001768 Error rc;
1769 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type, rc);
1770 error.SetError(rc);
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001771
1772 if (watchpoint_sp)
1773 {
1774 sb_watchpoint.SetSP (watchpoint_sp);
1775 Declaration decl;
1776 if (value_sp->GetDeclaration (decl))
1777 {
1778 if (decl.GetFile())
1779 {
1780 StreamString ss;
1781 // True to show fullpath for declaration file.
1782 decl.DumpStopContext(&ss, true);
1783 watchpoint_sp->SetDeclInfo(ss.GetString());
1784 }
1785 }
1786 }
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001787 }
1788 return sb_watchpoint;
1789}
1790
Johnny Chen8a5ce772012-06-04 23:45:50 +00001791// FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1792// Backward compatibility fix in the interim.
1793lldb::SBWatchpoint
1794SBValue::Watch (bool resolve_location, bool read, bool write)
1795{
Johnny Chen9c4a3442012-06-05 00:14:15 +00001796 SBError error;
1797 return Watch(resolve_location, read, write, error);
Johnny Chen8a5ce772012-06-04 23:45:50 +00001798}
1799
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001800lldb::SBWatchpoint
Johnny Chen3f883492012-06-04 23:19:54 +00001801SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001802{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001803 SBWatchpoint sb_watchpoint;
1804 if (IsInScope() && GetType().IsPointerType())
Johnny Chen3f883492012-06-04 23:19:54 +00001805 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001806 return sb_watchpoint;
1807}
1808