blob: 1709742ef6daf0b054e284ea4a80789b132c47b1 [file] [log] [blame]
Chris Lattner30fdc8d2010-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 Friedman4c5de692010-06-09 07:44:37 +000010#include "lldb/API/SBValue.h"
Enrico Granata864e3e82012-02-17 03:18:30 +000011
Enrico Granata10de0902012-10-10 22:54:17 +000012#include "lldb/API/SBDeclaration.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000013#include "lldb/API/SBStream.h"
Enrico Granata864e3e82012-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 Lattner30fdc8d2010-06-08 16:52:24 +000018
Johnny Chen01a67862011-10-14 00:42:25 +000019#include "lldb/Breakpoint/Watchpoint.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/DataExtractor.h"
21#include "lldb/Core/Module.h"
Greg Claytonfe42ac42011-08-03 22:57:10 +000022#include "lldb/Core/Scalar.h"
Greg Clayton1f746072012-08-29 21:13:06 +000023#include "lldb/Core/Section.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Core/StreamFile.h"
25#include "lldb/Core/Value.h"
26#include "lldb/Core/ValueObject.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000027#include "lldb/Core/ValueObjectConstResult.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000028#include "lldb/DataFormatters/DataVisualization.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Symbol/Block.h"
Enrico Granata10de0902012-10-10 22:54:17 +000030#include "lldb/Symbol/Declaration.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Symbol/ObjectFile.h"
Greg Clayton81e871e2012-02-04 02:27:34 +000032#include "lldb/Symbol/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Symbol/Variable.h"
Johnny Chen01a67862011-10-14 00:42:25 +000034#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035#include "lldb/Target/ExecutionContext.h"
36#include "lldb/Target/Process.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000037#include "lldb/Target/StackFrame.h"
Greg Claytonaf67cec2010-12-20 20:49:23 +000038#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Target/Thread.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000040#include "lldb/Utility/Log.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000041#include "lldb/Utility/Stream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042
Jim Ingham35e1bda2012-10-16 21:41:58 +000043#include "lldb/API/SBDebugger.h"
44#include "lldb/API/SBExpressionOptions.h"
45#include "lldb/API/SBFrame.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000046#include "lldb/API/SBProcess.h"
47#include "lldb/API/SBTarget.h"
48#include "lldb/API/SBThread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049
50using namespace lldb;
51using namespace lldb_private;
52
Kate Stoneb9c1b512016-09-06 20:57:50 +000053class ValueImpl {
Enrico Granata19f0e8c2013-04-22 22:57:56 +000054public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000055 ValueImpl() {}
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000056
Kate Stoneb9c1b512016-09-06 20:57:50 +000057 ValueImpl(lldb::ValueObjectSP in_valobj_sp,
58 lldb::DynamicValueType use_dynamic, bool use_synthetic,
59 const char *name = NULL)
60 : m_valobj_sp(), m_use_dynamic(use_dynamic),
61 m_use_synthetic(use_synthetic), m_name(name) {
62 if (in_valobj_sp) {
63 if ((m_valobj_sp = in_valobj_sp->GetQualifiedRepresentationIfAvailable(
64 lldb::eNoDynamicValues, false))) {
Jim Ingham362e39a2013-05-15 02:16:21 +000065 if (!m_name.IsEmpty())
Kate Stoneb9c1b512016-09-06 20:57:50 +000066 m_valobj_sp->SetName(m_name);
67 }
Enrico Granata19f0e8c2013-04-22 22:57:56 +000068 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000069 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000070
Kate Stoneb9c1b512016-09-06 20:57:50 +000071 ValueImpl(const ValueImpl &rhs)
72 : m_valobj_sp(rhs.m_valobj_sp), m_use_dynamic(rhs.m_use_dynamic),
73 m_use_synthetic(rhs.m_use_synthetic), m_name(rhs.m_name) {}
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000074
Kate Stoneb9c1b512016-09-06 20:57:50 +000075 ValueImpl &operator=(const ValueImpl &rhs) {
76 if (this != &rhs) {
77 m_valobj_sp = rhs.m_valobj_sp;
78 m_use_dynamic = rhs.m_use_dynamic;
79 m_use_synthetic = rhs.m_use_synthetic;
80 m_name = rhs.m_name;
Enrico Granatac5bc4122012-03-27 02:35:13 +000081 }
Greg Claytonefabb122010-11-05 23:17:00 +000082 return *this;
Kate Stoneb9c1b512016-09-06 20:57:50 +000083 }
Greg Claytonefabb122010-11-05 23:17:00 +000084
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 bool IsValid() {
86 if (m_valobj_sp.get() == NULL)
87 return false;
88 else {
89 // FIXME: This check is necessary but not sufficient. We for sure don't
90 // want to touch SBValues whose owning
91 // targets have gone away. This check is a little weak in that it
92 // enforces that restriction when you call
93 // IsValid, but since IsValid doesn't lock the target, you have no
94 // guarantee that the SBValue won't go
95 // invalid after you call this...
96 // Also, an SBValue could depend on data from one of the modules in the
97 // target, and those could go away
98 // independently of the target, for instance if a module is unloaded. But
99 // right now, neither SBValues
100 // nor ValueObjects know which modules they depend on. So I have no good
101 // way to make that check without
102 // tracking that in all the ValueObject subclasses.
103 TargetSP target_sp = m_valobj_sp->GetTargetSP();
104 if (target_sp && target_sp->IsValid())
105 return true;
106 else
107 return false;
108 }
109 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110
Kate Stoneb9c1b512016-09-06 20:57:50 +0000111 lldb::ValueObjectSP GetRootSP() { return m_valobj_sp; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113 lldb::ValueObjectSP GetSP(Process::StopLocker &stop_locker,
114 std::unique_lock<std::recursive_mutex> &lock,
115 Error &error) {
116 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
117 if (!m_valobj_sp) {
118 error.SetErrorString("invalid value object");
119 return m_valobj_sp;
120 }
Jim Ingham5d3bca42011-12-19 20:39:44 +0000121
Kate Stoneb9c1b512016-09-06 20:57:50 +0000122 lldb::ValueObjectSP value_sp = m_valobj_sp;
123
124 Target *target = value_sp->GetTargetSP().get();
125 if (!target)
126 return ValueObjectSP();
127
128 lock = std::unique_lock<std::recursive_mutex>(target->GetAPIMutex());
129
130 ProcessSP process_sp(value_sp->GetProcessSP());
131 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock())) {
132 // We don't allow people to play around with ValueObject if the process is
133 // running.
134 // If you want to look at values, pause the process, then look.
135 if (log)
136 log->Printf("SBValue(%p)::GetSP() => error: process is running",
137 static_cast<void *>(value_sp.get()));
138 error.SetErrorString("process must be stopped.");
139 return ValueObjectSP();
140 }
141
142 if (m_use_dynamic != eNoDynamicValues) {
143 ValueObjectSP dynamic_sp = value_sp->GetDynamicValue(m_use_dynamic);
144 if (dynamic_sp)
145 value_sp = dynamic_sp;
146 }
147
148 if (m_use_synthetic) {
149 ValueObjectSP synthetic_sp = value_sp->GetSyntheticValue(m_use_synthetic);
150 if (synthetic_sp)
151 value_sp = synthetic_sp;
152 }
153
154 if (!value_sp)
155 error.SetErrorString("invalid value object");
156 if (!m_name.IsEmpty())
157 value_sp->SetName(m_name);
158
159 return value_sp;
160 }
161
162 void SetUseDynamic(lldb::DynamicValueType use_dynamic) {
163 m_use_dynamic = use_dynamic;
164 }
165
166 void SetUseSynthetic(bool use_synthetic) { m_use_synthetic = use_synthetic; }
167
168 lldb::DynamicValueType GetUseDynamic() { return m_use_dynamic; }
169
170 bool GetUseSynthetic() { return m_use_synthetic; }
171
172 // All the derived values that we would make from the m_valobj_sp will share
173 // the ExecutionContext with m_valobj_sp, so we don't need to do the
174 // calculations
175 // in GetSP to return the Target, Process, Thread or Frame. It is convenient
176 // to
177 // provide simple accessors for these, which I do here.
178 TargetSP GetTargetSP() {
179 if (m_valobj_sp)
180 return m_valobj_sp->GetTargetSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000181 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000182 return TargetSP();
183 }
184
185 ProcessSP GetProcessSP() {
186 if (m_valobj_sp)
187 return m_valobj_sp->GetProcessSP();
188 else
189 return ProcessSP();
190 }
191
192 ThreadSP GetThreadSP() {
193 if (m_valobj_sp)
194 return m_valobj_sp->GetThreadSP();
195 else
196 return ThreadSP();
197 }
198
199 StackFrameSP GetFrameSP() {
200 if (m_valobj_sp)
201 return m_valobj_sp->GetFrameSP();
202 else
203 return StackFrameSP();
204 }
205
206private:
207 lldb::ValueObjectSP m_valobj_sp;
208 lldb::DynamicValueType m_use_dynamic;
209 bool m_use_synthetic;
210 ConstString m_name;
211};
212
213class ValueLocker {
214public:
215 ValueLocker() {}
216
217 ValueObjectSP GetLockedSP(ValueImpl &in_value) {
218 return in_value.GetSP(m_stop_locker, m_lock, m_lock_error);
219 }
220
221 Error &GetError() { return m_lock_error; }
222
223private:
224 Process::StopLocker m_stop_locker;
225 std::unique_lock<std::recursive_mutex> m_lock;
226 Error m_lock_error;
227};
228
229SBValue::SBValue() : m_opaque_sp() {}
230
231SBValue::SBValue(const lldb::ValueObjectSP &value_sp) { SetSP(value_sp); }
232
233SBValue::SBValue(const SBValue &rhs) { SetSP(rhs.m_opaque_sp); }
234
235SBValue &SBValue::operator=(const SBValue &rhs) {
236 if (this != &rhs) {
237 SetSP(rhs.m_opaque_sp);
238 }
239 return *this;
Greg Clayton524e60b2010-10-06 22:10:17 +0000240}
241
Kate Stoneb9c1b512016-09-06 20:57:50 +0000242SBValue::~SBValue() {}
243
244bool SBValue::IsValid() {
245 // If this function ever changes to anything that does more than just
246 // check if the opaque shared pointer is non NULL, then we need to update
247 // all "if (m_opaque_sp)" code in this file.
248 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid() &&
249 m_opaque_sp->GetRootSP().get() != NULL;
Johnny Chenb0b8be72011-07-07 20:46:23 +0000250}
251
Kate Stoneb9c1b512016-09-06 20:57:50 +0000252void SBValue::Clear() { m_opaque_sp.reset(); }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000253
Kate Stoneb9c1b512016-09-06 20:57:50 +0000254SBError SBValue::GetError() {
255 SBError sb_error;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000256
Kate Stoneb9c1b512016-09-06 20:57:50 +0000257 ValueLocker locker;
258 lldb::ValueObjectSP value_sp(GetSP(locker));
259 if (value_sp)
260 sb_error.SetError(value_sp->GetError());
261 else
262 sb_error.SetErrorStringWithFormat("error: %s",
263 locker.GetError().AsCString());
264
265 return sb_error;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000266}
267
Kate Stoneb9c1b512016-09-06 20:57:50 +0000268user_id_t SBValue::GetID() {
269 ValueLocker locker;
270 lldb::ValueObjectSP value_sp(GetSP(locker));
271 if (value_sp)
272 return value_sp->GetID();
273 return LLDB_INVALID_UID;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000274}
275
Kate Stoneb9c1b512016-09-06 20:57:50 +0000276const char *SBValue::GetName() {
277 const char *name = NULL;
278 ValueLocker locker;
279 lldb::ValueObjectSP value_sp(GetSP(locker));
280 if (value_sp)
281 name = value_sp->GetName().GetCString();
282
283 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
284 if (log) {
285 if (name)
286 log->Printf("SBValue(%p)::GetName () => \"%s\"",
287 static_cast<void *>(value_sp.get()), name);
288 else
289 log->Printf("SBValue(%p)::GetName () => NULL",
290 static_cast<void *>(value_sp.get()));
291 }
292
293 return name;
Enrico Granatae8daa2f2014-05-17 19:14:17 +0000294}
295
Kate Stoneb9c1b512016-09-06 20:57:50 +0000296const char *SBValue::GetTypeName() {
297 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
298 const char *name = NULL;
299 ValueLocker locker;
300 lldb::ValueObjectSP value_sp(GetSP(locker));
301 if (value_sp) {
302 name = value_sp->GetQualifiedTypeName().GetCString();
303 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000304
Kate Stoneb9c1b512016-09-06 20:57:50 +0000305 if (log) {
306 if (name)
307 log->Printf("SBValue(%p)::GetTypeName () => \"%s\"",
308 static_cast<void *>(value_sp.get()), name);
309 else
310 log->Printf("SBValue(%p)::GetTypeName () => NULL",
311 static_cast<void *>(value_sp.get()));
312 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000313
Kate Stoneb9c1b512016-09-06 20:57:50 +0000314 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000315}
316
Kate Stoneb9c1b512016-09-06 20:57:50 +0000317const char *SBValue::GetDisplayTypeName() {
318 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
319 const char *name = NULL;
320 ValueLocker locker;
321 lldb::ValueObjectSP value_sp(GetSP(locker));
322 if (value_sp) {
323 name = value_sp->GetDisplayTypeName().GetCString();
324 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000325
Kate Stoneb9c1b512016-09-06 20:57:50 +0000326 if (log) {
327 if (name)
328 log->Printf("SBValue(%p)::GetTypeName () => \"%s\"",
329 static_cast<void *>(value_sp.get()), name);
330 else
331 log->Printf("SBValue(%p)::GetTypeName () => NULL",
332 static_cast<void *>(value_sp.get()));
333 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000334
Kate Stoneb9c1b512016-09-06 20:57:50 +0000335 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000336}
337
Kate Stoneb9c1b512016-09-06 20:57:50 +0000338size_t SBValue::GetByteSize() {
339 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
340 size_t result = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000341
Kate Stoneb9c1b512016-09-06 20:57:50 +0000342 ValueLocker locker;
343 lldb::ValueObjectSP value_sp(GetSP(locker));
344 if (value_sp) {
345 result = value_sp->GetByteSize();
346 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000347
Kate Stoneb9c1b512016-09-06 20:57:50 +0000348 if (log)
349 log->Printf("SBValue(%p)::GetByteSize () => %" PRIu64,
350 static_cast<void *>(value_sp.get()),
351 static_cast<uint64_t>(result));
352
353 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000354}
355
Kate Stoneb9c1b512016-09-06 20:57:50 +0000356bool SBValue::IsInScope() {
357 bool result = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000358
Kate Stoneb9c1b512016-09-06 20:57:50 +0000359 ValueLocker locker;
360 lldb::ValueObjectSP value_sp(GetSP(locker));
361 if (value_sp) {
362 result = value_sp->IsInScope();
363 }
364
365 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
366 if (log)
367 log->Printf("SBValue(%p)::IsInScope () => %i",
368 static_cast<void *>(value_sp.get()), result);
369
370 return result;
Greg Clayton73b472d2010-10-27 03:32:59 +0000371}
372
Kate Stoneb9c1b512016-09-06 20:57:50 +0000373const char *SBValue::GetValue() {
374 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
375
376 const char *cstr = NULL;
377 ValueLocker locker;
378 lldb::ValueObjectSP value_sp(GetSP(locker));
379 if (value_sp) {
380 cstr = value_sp->GetValueAsCString();
381 }
382 if (log) {
383 if (cstr)
384 log->Printf("SBValue(%p)::GetValue() => \"%s\"",
385 static_cast<void *>(value_sp.get()), cstr);
386 else
387 log->Printf("SBValue(%p)::GetValue() => NULL",
388 static_cast<void *>(value_sp.get()));
389 }
390
391 return cstr;
Jim Ingham53c47f12010-09-10 23:12:17 +0000392}
393
Kate Stoneb9c1b512016-09-06 20:57:50 +0000394ValueType SBValue::GetValueType() {
395 ValueType result = eValueTypeInvalid;
396 ValueLocker locker;
397 lldb::ValueObjectSP value_sp(GetSP(locker));
398 if (value_sp)
399 result = value_sp->GetValueType();
400
401 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
402 if (log) {
403 switch (result) {
404 case eValueTypeInvalid:
405 log->Printf("SBValue(%p)::GetValueType () => eValueTypeInvalid",
406 static_cast<void *>(value_sp.get()));
407 break;
408 case eValueTypeVariableGlobal:
409 log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal",
410 static_cast<void *>(value_sp.get()));
411 break;
412 case eValueTypeVariableStatic:
413 log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableStatic",
414 static_cast<void *>(value_sp.get()));
415 break;
416 case eValueTypeVariableArgument:
417 log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableArgument",
418 static_cast<void *>(value_sp.get()));
419 break;
420 case eValueTypeVariableLocal:
421 log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableLocal",
422 static_cast<void *>(value_sp.get()));
423 break;
424 case eValueTypeRegister:
425 log->Printf("SBValue(%p)::GetValueType () => eValueTypeRegister",
426 static_cast<void *>(value_sp.get()));
427 break;
428 case eValueTypeRegisterSet:
429 log->Printf("SBValue(%p)::GetValueType () => eValueTypeRegisterSet",
430 static_cast<void *>(value_sp.get()));
431 break;
432 case eValueTypeConstResult:
433 log->Printf("SBValue(%p)::GetValueType () => eValueTypeConstResult",
434 static_cast<void *>(value_sp.get()));
435 break;
436 case eValueTypeVariableThreadLocal:
437 log->Printf(
438 "SBValue(%p)::GetValueType () => eValueTypeVariableThreadLocal",
439 static_cast<void *>(value_sp.get()));
440 break;
Enrico Granataedc44142014-09-06 01:30:04 +0000441 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000442 }
443 return result;
Enrico Granataedc44142014-09-06 01:30:04 +0000444}
445
Kate Stoneb9c1b512016-09-06 20:57:50 +0000446const char *SBValue::GetObjectDescription() {
447 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
448 const char *cstr = NULL;
449 ValueLocker locker;
450 lldb::ValueObjectSP value_sp(GetSP(locker));
451 if (value_sp) {
452 cstr = value_sp->GetObjectDescription();
453 }
454 if (log) {
455 if (cstr)
456 log->Printf("SBValue(%p)::GetObjectDescription() => \"%s\"",
457 static_cast<void *>(value_sp.get()), cstr);
458 else
459 log->Printf("SBValue(%p)::GetObjectDescription() => NULL",
460 static_cast<void *>(value_sp.get()));
461 }
462 return cstr;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000463}
464
Kate Stoneb9c1b512016-09-06 20:57:50 +0000465const char *SBValue::GetTypeValidatorResult() {
466 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
467 const char *cstr = NULL;
468 ValueLocker locker;
469 lldb::ValueObjectSP value_sp(GetSP(locker));
470 if (value_sp) {
471 const auto &validation(value_sp->GetValidationStatus());
472 if (TypeValidatorResult::Failure == validation.first) {
473 if (validation.second.empty())
474 cstr = "unknown error";
475 else
476 cstr = validation.second.c_str();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000477 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000478 }
479 if (log) {
480 if (cstr)
481 log->Printf("SBValue(%p)::GetTypeValidatorResult() => \"%s\"",
482 static_cast<void *>(value_sp.get()), cstr);
483 else
484 log->Printf("SBValue(%p)::GetTypeValidatorResult() => NULL",
485 static_cast<void *>(value_sp.get()));
486 }
487 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488}
489
Kate Stoneb9c1b512016-09-06 20:57:50 +0000490SBType SBValue::GetType() {
491 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
492 SBType sb_type;
493 ValueLocker locker;
494 lldb::ValueObjectSP value_sp(GetSP(locker));
495 TypeImplSP type_sp;
496 if (value_sp) {
497 type_sp.reset(new TypeImpl(value_sp->GetTypeImpl()));
498 sb_type.SetSP(type_sp);
499 }
500 if (log) {
501 if (type_sp)
502 log->Printf("SBValue(%p)::GetType => SBType(%p)",
503 static_cast<void *>(value_sp.get()),
504 static_cast<void *>(type_sp.get()));
505 else
506 log->Printf("SBValue(%p)::GetType => NULL",
507 static_cast<void *>(value_sp.get()));
508 }
509 return sb_type;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510}
Enrico Granatac1247f52014-11-06 21:23:20 +0000511
Kate Stoneb9c1b512016-09-06 20:57:50 +0000512bool SBValue::GetValueDidChange() {
513 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
514 bool result = false;
515 ValueLocker locker;
516 lldb::ValueObjectSP value_sp(GetSP(locker));
517 if (value_sp) {
518 if (value_sp->UpdateValueIfNeeded(false))
519 result = value_sp->GetValueDidChange();
520 }
521 if (log)
522 log->Printf("SBValue(%p)::GetValueDidChange() => %i",
523 static_cast<void *>(value_sp.get()), result);
524
525 return result;
Enrico Granatac1247f52014-11-06 21:23:20 +0000526}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527
Kate Stoneb9c1b512016-09-06 20:57:50 +0000528const char *SBValue::GetSummary() {
529 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
530 const char *cstr = NULL;
531 ValueLocker locker;
532 lldb::ValueObjectSP value_sp(GetSP(locker));
533 if (value_sp) {
534 cstr = value_sp->GetSummaryAsCString();
535 }
536 if (log) {
537 if (cstr)
538 log->Printf("SBValue(%p)::GetSummary() => \"%s\"",
539 static_cast<void *>(value_sp.get()), cstr);
540 else
541 log->Printf("SBValue(%p)::GetSummary() => NULL",
542 static_cast<void *>(value_sp.get()));
543 }
544 return cstr;
545}
546
547const char *SBValue::GetSummary(lldb::SBStream &stream,
548 lldb::SBTypeSummaryOptions &options) {
549 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
550 ValueLocker locker;
551 lldb::ValueObjectSP value_sp(GetSP(locker));
552 if (value_sp) {
553 std::string buffer;
554 if (value_sp->GetSummaryAsCString(buffer, options.ref()) && !buffer.empty())
555 stream.Printf("%s", buffer.c_str());
556 }
557 const char *cstr = stream.GetData();
558 if (log) {
559 if (cstr)
560 log->Printf("SBValue(%p)::GetSummary() => \"%s\"",
561 static_cast<void *>(value_sp.get()), cstr);
562 else
563 log->Printf("SBValue(%p)::GetSummary() => NULL",
564 static_cast<void *>(value_sp.get()));
565 }
566 return cstr;
567}
568
569const char *SBValue::GetLocation() {
570 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
571 const char *cstr = NULL;
572 ValueLocker locker;
573 lldb::ValueObjectSP value_sp(GetSP(locker));
574 if (value_sp) {
575 cstr = value_sp->GetLocationAsCString();
576 }
577 if (log) {
578 if (cstr)
579 log->Printf("SBValue(%p)::GetLocation() => \"%s\"",
580 static_cast<void *>(value_sp.get()), cstr);
581 else
582 log->Printf("SBValue(%p)::GetLocation() => NULL",
583 static_cast<void *>(value_sp.get()));
584 }
585 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586}
587
Enrico Granata07a4ac22012-05-08 21:25:06 +0000588// Deprecated - use the one that takes an lldb::SBError
Kate Stoneb9c1b512016-09-06 20:57:50 +0000589bool SBValue::SetValueFromCString(const char *value_str) {
590 lldb::SBError dummy;
591 return SetValueFromCString(value_str, dummy);
Enrico Granata07a4ac22012-05-08 21:25:06 +0000592}
593
Kate Stoneb9c1b512016-09-06 20:57:50 +0000594bool SBValue::SetValueFromCString(const char *value_str, lldb::SBError &error) {
595 bool success = false;
596 ValueLocker locker;
597 lldb::ValueObjectSP value_sp(GetSP(locker));
598 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
599 if (value_sp) {
600 success = value_sp->SetValueFromCString(value_str, error.ref());
601 } else
602 error.SetErrorStringWithFormat("Could not get value: %s",
603 locker.GetError().AsCString());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000604
Kate Stoneb9c1b512016-09-06 20:57:50 +0000605 if (log)
606 log->Printf("SBValue(%p)::SetValueFromCString(\"%s\") => %i",
607 static_cast<void *>(value_sp.get()), value_str, success);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000608
Kate Stoneb9c1b512016-09-06 20:57:50 +0000609 return success;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000610}
611
Kate Stoneb9c1b512016-09-06 20:57:50 +0000612lldb::SBTypeFormat SBValue::GetTypeFormat() {
613 lldb::SBTypeFormat format;
614 ValueLocker locker;
615 lldb::ValueObjectSP value_sp(GetSP(locker));
616 if (value_sp) {
617 if (value_sp->UpdateValueIfNeeded(true)) {
618 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
619 if (format_sp)
620 format.SetSP(format_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000621 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000622 }
623 return format;
Enrico Granata864e3e82012-02-17 03:18:30 +0000624}
625
Kate Stoneb9c1b512016-09-06 20:57:50 +0000626lldb::SBTypeSummary SBValue::GetTypeSummary() {
627 lldb::SBTypeSummary summary;
628 ValueLocker locker;
629 lldb::ValueObjectSP value_sp(GetSP(locker));
630 if (value_sp) {
631 if (value_sp->UpdateValueIfNeeded(true)) {
632 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
633 if (summary_sp)
634 summary.SetSP(summary_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000635 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000636 }
637 return summary;
Enrico Granata864e3e82012-02-17 03:18:30 +0000638}
639
Kate Stoneb9c1b512016-09-06 20:57:50 +0000640lldb::SBTypeFilter SBValue::GetTypeFilter() {
641 lldb::SBTypeFilter filter;
642 ValueLocker locker;
643 lldb::ValueObjectSP value_sp(GetSP(locker));
644 if (value_sp) {
645 if (value_sp->UpdateValueIfNeeded(true)) {
646 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
647
648 if (synthetic_sp && !synthetic_sp->IsScripted()) {
649 TypeFilterImplSP filter_sp =
650 std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
651 filter.SetSP(filter_sp);
652 }
Enrico Granata864e3e82012-02-17 03:18:30 +0000653 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000654 }
655 return filter;
Enrico Granata864e3e82012-02-17 03:18:30 +0000656}
657
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000658#ifndef LLDB_DISABLE_PYTHON
Kate Stoneb9c1b512016-09-06 20:57:50 +0000659lldb::SBTypeSynthetic SBValue::GetTypeSynthetic() {
660 lldb::SBTypeSynthetic synthetic;
661 ValueLocker locker;
662 lldb::ValueObjectSP value_sp(GetSP(locker));
663 if (value_sp) {
664 if (value_sp->UpdateValueIfNeeded(true)) {
665 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
666
667 if (children_sp && children_sp->IsScripted()) {
668 ScriptedSyntheticChildrenSP synth_sp =
669 std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
670 synthetic.SetSP(synth_sp);
671 }
Enrico Granata864e3e82012-02-17 03:18:30 +0000672 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000673 }
674 return synthetic;
Enrico Granata864e3e82012-02-17 03:18:30 +0000675}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000676#endif
Enrico Granata864e3e82012-02-17 03:18:30 +0000677
Kate Stoneb9c1b512016-09-06 20:57:50 +0000678lldb::SBValue SBValue::CreateChildAtOffset(const char *name, uint32_t offset,
679 SBType type) {
680 lldb::SBValue sb_value;
681 ValueLocker locker;
682 lldb::ValueObjectSP value_sp(GetSP(locker));
683 lldb::ValueObjectSP new_value_sp;
684 if (value_sp) {
685 TypeImplSP type_sp(type.GetSP());
686 if (type.IsValid()) {
687 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(
688 offset, type_sp->GetCompilerType(false), true),
689 GetPreferDynamicValue(), GetPreferSyntheticValue(), name);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000690 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000691 }
692 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
693 if (log) {
694 if (new_value_sp)
695 log->Printf("SBValue(%p)::CreateChildAtOffset => \"%s\"",
696 static_cast<void *>(value_sp.get()),
697 new_value_sp->GetName().AsCString());
Jim Ingham362e39a2013-05-15 02:16:21 +0000698 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000699 log->Printf("SBValue(%p)::CreateChildAtOffset => NULL",
700 static_cast<void *>(value_sp.get()));
701 }
702 return sb_value;
Enrico Granata6fd87d52011-08-04 01:41:02 +0000703}
704
Kate Stoneb9c1b512016-09-06 20:57:50 +0000705lldb::SBValue SBValue::Cast(SBType type) {
706 lldb::SBValue sb_value;
707 ValueLocker locker;
708 lldb::ValueObjectSP value_sp(GetSP(locker));
709 TypeImplSP type_sp(type.GetSP());
710 if (value_sp && type_sp)
711 sb_value.SetSP(value_sp->Cast(type_sp->GetCompilerType(false)),
712 GetPreferDynamicValue(), GetPreferSyntheticValue());
713 return sb_value;
714}
715
716lldb::SBValue SBValue::CreateValueFromExpression(const char *name,
717 const char *expression) {
718 SBExpressionOptions options;
719 options.ref().SetKeepInMemory(true);
720 return CreateValueFromExpression(name, expression, options);
721}
722
723lldb::SBValue SBValue::CreateValueFromExpression(const char *name,
724 const char *expression,
725 SBExpressionOptions &options) {
726 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
727 lldb::SBValue sb_value;
728 ValueLocker locker;
729 lldb::ValueObjectSP value_sp(GetSP(locker));
730 lldb::ValueObjectSP new_value_sp;
731 if (value_sp) {
732 ExecutionContext exe_ctx(value_sp->GetExecutionContextRef());
733 new_value_sp = ValueObject::CreateValueObjectFromExpression(
734 name, expression, exe_ctx, options.ref());
735 if (new_value_sp)
736 new_value_sp->SetName(ConstString(name));
737 }
738 sb_value.SetSP(new_value_sp);
739 if (log) {
740 if (new_value_sp)
741 log->Printf("SBValue(%p)::CreateValueFromExpression(name=\"%s\", "
742 "expression=\"%s\") => SBValue (%p)",
743 static_cast<void *>(value_sp.get()), name, expression,
744 static_cast<void *>(new_value_sp.get()));
Jim Ingham362e39a2013-05-15 02:16:21 +0000745 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000746 log->Printf("SBValue(%p)::CreateValueFromExpression(name=\"%s\", "
747 "expression=\"%s\") => NULL",
748 static_cast<void *>(value_sp.get()), name, expression);
749 }
750 return sb_value;
Enrico Granata6fd87d52011-08-04 01:41:02 +0000751}
752
Kate Stoneb9c1b512016-09-06 20:57:50 +0000753lldb::SBValue SBValue::CreateValueFromAddress(const char *name,
754 lldb::addr_t address,
755 SBType sb_type) {
756 lldb::SBValue sb_value;
757 ValueLocker locker;
758 lldb::ValueObjectSP value_sp(GetSP(locker));
759 lldb::ValueObjectSP new_value_sp;
760 lldb::TypeImplSP type_impl_sp(sb_type.GetSP());
761 if (value_sp && type_impl_sp) {
762 CompilerType ast_type(type_impl_sp->GetCompilerType(true));
763 ExecutionContext exe_ctx(value_sp->GetExecutionContextRef());
764 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address,
765 exe_ctx, ast_type);
766 }
767 sb_value.SetSP(new_value_sp);
768 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
769 if (log) {
770 if (new_value_sp)
771 log->Printf("SBValue(%p)::CreateValueFromAddress => \"%s\"",
772 static_cast<void *>(value_sp.get()),
773 new_value_sp->GetName().AsCString());
774 else
775 log->Printf("SBValue(%p)::CreateValueFromAddress => NULL",
776 static_cast<void *>(value_sp.get()));
777 }
778 return sb_value;
779}
780
781lldb::SBValue SBValue::CreateValueFromData(const char *name, SBData data,
782 SBType sb_type) {
783 lldb::SBValue sb_value;
784 lldb::ValueObjectSP new_value_sp;
785 ValueLocker locker;
786 lldb::ValueObjectSP value_sp(GetSP(locker));
787 lldb::TypeImplSP type_impl_sp(sb_type.GetSP());
788 if (value_sp && type_impl_sp) {
789 ExecutionContext exe_ctx(value_sp->GetExecutionContextRef());
790 new_value_sp = ValueObject::CreateValueObjectFromData(
791 name, **data, exe_ctx, type_impl_sp->GetCompilerType(true));
792 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
793 }
794 sb_value.SetSP(new_value_sp);
795 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
796 if (log) {
797 if (new_value_sp)
798 log->Printf("SBValue(%p)::CreateValueFromData => \"%s\"",
799 static_cast<void *>(value_sp.get()),
800 new_value_sp->GetName().AsCString());
801 else
802 log->Printf("SBValue(%p)::CreateValueFromData => NULL",
803 static_cast<void *>(value_sp.get()));
804 }
805 return sb_value;
806}
807
808SBValue SBValue::GetChildAtIndex(uint32_t idx) {
809 const bool can_create_synthetic = false;
810 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
811 TargetSP target_sp;
812 if (m_opaque_sp)
813 target_sp = m_opaque_sp->GetTargetSP();
814
815 if (target_sp)
816 use_dynamic = target_sp->GetPreferDynamicValue();
817
818 return GetChildAtIndex(idx, use_dynamic, can_create_synthetic);
819}
820
821SBValue SBValue::GetChildAtIndex(uint32_t idx,
822 lldb::DynamicValueType use_dynamic,
823 bool can_create_synthetic) {
824 lldb::ValueObjectSP child_sp;
825 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
826
827 ValueLocker locker;
828 lldb::ValueObjectSP value_sp(GetSP(locker));
829 if (value_sp) {
830 const bool can_create = true;
831 child_sp = value_sp->GetChildAtIndex(idx, can_create);
832 if (can_create_synthetic && !child_sp) {
833 child_sp = value_sp->GetSyntheticArrayMember(idx, can_create);
Greg Claytonfe42ac42011-08-03 22:57:10 +0000834 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000835 }
836
837 SBValue sb_value;
838 sb_value.SetSP(child_sp, use_dynamic, GetPreferSyntheticValue());
839 if (log)
840 log->Printf("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)",
841 static_cast<void *>(value_sp.get()), idx,
842 static_cast<void *>(value_sp.get()));
843
844 return sb_value;
Greg Claytonfe42ac42011-08-03 22:57:10 +0000845}
846
Kate Stoneb9c1b512016-09-06 20:57:50 +0000847uint32_t SBValue::GetIndexOfChildWithName(const char *name) {
848 uint32_t idx = UINT32_MAX;
849 ValueLocker locker;
850 lldb::ValueObjectSP value_sp(GetSP(locker));
851 if (value_sp) {
852 idx = value_sp->GetIndexOfChildWithName(ConstString(name));
853 }
854 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
855 if (log) {
856 if (idx == UINT32_MAX)
857 log->Printf(
858 "SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND",
859 static_cast<void *>(value_sp.get()), name);
860 else
861 log->Printf("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u",
862 static_cast<void *>(value_sp.get()), name, idx);
863 }
864 return idx;
Greg Claytonfe42ac42011-08-03 22:57:10 +0000865}
866
Kate Stoneb9c1b512016-09-06 20:57:50 +0000867SBValue SBValue::GetChildMemberWithName(const char *name) {
868 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
869 TargetSP target_sp;
870 if (m_opaque_sp)
871 target_sp = m_opaque_sp->GetTargetSP();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000872
Kate Stoneb9c1b512016-09-06 20:57:50 +0000873 if (target_sp)
874 use_dynamic_value = target_sp->GetPreferDynamicValue();
875 return GetChildMemberWithName(name, use_dynamic_value);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000876}
877
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000878SBValue
Kate Stoneb9c1b512016-09-06 20:57:50 +0000879SBValue::GetChildMemberWithName(const char *name,
880 lldb::DynamicValueType use_dynamic_value) {
881 lldb::ValueObjectSP child_sp;
882 const ConstString str_name(name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000883
Kate Stoneb9c1b512016-09-06 20:57:50 +0000884 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
885
886 ValueLocker locker;
887 lldb::ValueObjectSP value_sp(GetSP(locker));
888 if (value_sp) {
889 child_sp = value_sp->GetChildMemberWithName(str_name, true);
890 }
891
892 SBValue sb_value;
893 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
894
895 if (log)
896 log->Printf(
897 "SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)",
898 static_cast<void *>(value_sp.get()), name,
899 static_cast<void *>(value_sp.get()));
900
901 return sb_value;
902}
903
904lldb::SBValue SBValue::GetDynamicValue(lldb::DynamicValueType use_dynamic) {
905 SBValue value_sb;
906 if (IsValid()) {
907 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(), use_dynamic,
908 m_opaque_sp->GetUseSynthetic()));
909 value_sb.SetSP(proxy_sp);
910 }
911 return value_sb;
912}
913
914lldb::SBValue SBValue::GetStaticValue() {
915 SBValue value_sb;
916 if (IsValid()) {
917 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),
918 eNoDynamicValues,
919 m_opaque_sp->GetUseSynthetic()));
920 value_sb.SetSP(proxy_sp);
921 }
922 return value_sb;
923}
924
925lldb::SBValue SBValue::GetNonSyntheticValue() {
926 SBValue value_sb;
927 if (IsValid()) {
928 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),
929 m_opaque_sp->GetUseDynamic(), false));
930 value_sb.SetSP(proxy_sp);
931 }
932 return value_sb;
933}
934
935lldb::DynamicValueType SBValue::GetPreferDynamicValue() {
936 if (!IsValid())
937 return eNoDynamicValues;
938 return m_opaque_sp->GetUseDynamic();
939}
940
941void SBValue::SetPreferDynamicValue(lldb::DynamicValueType use_dynamic) {
942 if (IsValid())
943 return m_opaque_sp->SetUseDynamic(use_dynamic);
944}
945
946bool SBValue::GetPreferSyntheticValue() {
947 if (!IsValid())
948 return false;
949 return m_opaque_sp->GetUseSynthetic();
950}
951
952void SBValue::SetPreferSyntheticValue(bool use_synthetic) {
953 if (IsValid())
954 return m_opaque_sp->SetUseSynthetic(use_synthetic);
955}
956
957bool SBValue::IsDynamic() {
958 ValueLocker locker;
959 lldb::ValueObjectSP value_sp(GetSP(locker));
960 if (value_sp)
961 return value_sp->IsDynamic();
962 return false;
963}
964
965bool SBValue::IsSynthetic() {
966 ValueLocker locker;
967 lldb::ValueObjectSP value_sp(GetSP(locker));
968 if (value_sp)
969 return value_sp->IsSynthetic();
970 return false;
971}
972
973bool SBValue::IsSyntheticChildrenGenerated() {
974 ValueLocker locker;
975 lldb::ValueObjectSP value_sp(GetSP(locker));
976 if (value_sp)
977 return value_sp->IsSyntheticChildrenGenerated();
978 return false;
979}
980
981void SBValue::SetSyntheticChildrenGenerated(bool is) {
982 ValueLocker locker;
983 lldb::ValueObjectSP value_sp(GetSP(locker));
984 if (value_sp)
985 return value_sp->SetSyntheticChildrenGenerated(is);
986}
987
988lldb::SBValue SBValue::GetValueForExpressionPath(const char *expr_path) {
989 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
990 lldb::ValueObjectSP child_sp;
991 ValueLocker locker;
992 lldb::ValueObjectSP value_sp(GetSP(locker));
993 if (value_sp) {
994 // using default values for all the fancy options, just do it if you can
995 child_sp = value_sp->GetValueForExpressionPath(expr_path);
996 }
997
998 SBValue sb_value;
999 sb_value.SetSP(child_sp, GetPreferDynamicValue(), GetPreferSyntheticValue());
1000
1001 if (log)
1002 log->Printf("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => "
1003 "SBValue(%p)",
1004 static_cast<void *>(value_sp.get()), expr_path,
1005 static_cast<void *>(value_sp.get()));
1006
1007 return sb_value;
1008}
1009
1010int64_t SBValue::GetValueAsSigned(SBError &error, int64_t fail_value) {
1011 error.Clear();
1012 ValueLocker locker;
1013 lldb::ValueObjectSP value_sp(GetSP(locker));
1014 if (value_sp) {
1015 bool success = true;
1016 uint64_t ret_val = fail_value;
1017 ret_val = value_sp->GetValueAsSigned(fail_value, &success);
1018 if (!success)
1019 error.SetErrorString("could not resolve value");
1020 return ret_val;
1021 } else
1022 error.SetErrorStringWithFormat("could not get SBValue: %s",
1023 locker.GetError().AsCString());
1024
1025 return fail_value;
1026}
1027
1028uint64_t SBValue::GetValueAsUnsigned(SBError &error, uint64_t fail_value) {
1029 error.Clear();
1030 ValueLocker locker;
1031 lldb::ValueObjectSP value_sp(GetSP(locker));
1032 if (value_sp) {
1033 bool success = true;
1034 uint64_t ret_val = fail_value;
1035 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
1036 if (!success)
1037 error.SetErrorString("could not resolve value");
1038 return ret_val;
1039 } else
1040 error.SetErrorStringWithFormat("could not get SBValue: %s",
1041 locker.GetError().AsCString());
1042
1043 return fail_value;
1044}
1045
1046int64_t SBValue::GetValueAsSigned(int64_t fail_value) {
1047 ValueLocker locker;
1048 lldb::ValueObjectSP value_sp(GetSP(locker));
1049 if (value_sp) {
1050 return value_sp->GetValueAsSigned(fail_value);
1051 }
1052 return fail_value;
1053}
1054
1055uint64_t SBValue::GetValueAsUnsigned(uint64_t fail_value) {
1056 ValueLocker locker;
1057 lldb::ValueObjectSP value_sp(GetSP(locker));
1058 if (value_sp) {
1059 return value_sp->GetValueAsUnsigned(fail_value);
1060 }
1061 return fail_value;
1062}
1063
1064bool SBValue::MightHaveChildren() {
1065 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1066 bool has_children = false;
1067 ValueLocker locker;
1068 lldb::ValueObjectSP value_sp(GetSP(locker));
1069 if (value_sp)
1070 has_children = value_sp->MightHaveChildren();
1071
1072 if (log)
1073 log->Printf("SBValue(%p)::MightHaveChildren() => %i",
1074 static_cast<void *>(value_sp.get()), has_children);
1075 return has_children;
1076}
1077
1078bool SBValue::IsRuntimeSupportValue() {
1079 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1080 bool is_support = false;
1081 ValueLocker locker;
1082 lldb::ValueObjectSP value_sp(GetSP(locker));
1083 if (value_sp)
1084 is_support = value_sp->IsRuntimeSupportValue();
1085
1086 if (log)
1087 log->Printf("SBValue(%p)::IsRuntimeSupportValue() => %i",
1088 static_cast<void *>(value_sp.get()), is_support);
1089 return is_support;
1090}
1091
1092uint32_t SBValue::GetNumChildren() { return GetNumChildren(UINT32_MAX); }
1093
1094uint32_t SBValue::GetNumChildren(uint32_t max) {
1095 uint32_t num_children = 0;
1096
1097 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1098 ValueLocker locker;
1099 lldb::ValueObjectSP value_sp(GetSP(locker));
1100 if (value_sp)
1101 num_children = value_sp->GetNumChildren(max);
1102
1103 if (log)
1104 log->Printf("SBValue(%p)::GetNumChildren (%u) => %u",
1105 static_cast<void *>(value_sp.get()), max, num_children);
1106
1107 return num_children;
1108}
1109
1110SBValue SBValue::Dereference() {
1111 SBValue sb_value;
1112 ValueLocker locker;
1113 lldb::ValueObjectSP value_sp(GetSP(locker));
1114 if (value_sp) {
1115 Error error;
1116 sb_value = value_sp->Dereference(error);
1117 }
1118 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1119 if (log)
1120 log->Printf("SBValue(%p)::Dereference () => SBValue(%p)",
1121 static_cast<void *>(value_sp.get()),
1122 static_cast<void *>(value_sp.get()));
1123
1124 return sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001125}
1126
Chaoren Lin4630de82015-07-27 21:51:56 +00001127// Deprecated - please use GetType().IsPointerType() instead.
Kate Stoneb9c1b512016-09-06 20:57:50 +00001128bool SBValue::TypeIsPointerType() { return GetType().IsPointerType(); }
1129
1130void *SBValue::GetOpaqueType() {
1131 ValueLocker locker;
1132 lldb::ValueObjectSP value_sp(GetSP(locker));
1133 if (value_sp)
1134 return value_sp->GetCompilerType().GetOpaqueQualType();
1135 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001136}
1137
Kate Stoneb9c1b512016-09-06 20:57:50 +00001138lldb::SBTarget SBValue::GetTarget() {
1139 SBTarget sb_target;
1140 TargetSP target_sp;
1141 if (m_opaque_sp) {
1142 target_sp = m_opaque_sp->GetTargetSP();
1143 sb_target.SetSP(target_sp);
1144 }
1145 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1146 if (log) {
1147 if (target_sp.get() == NULL)
1148 log->Printf("SBValue(%p)::GetTarget () => NULL",
1149 static_cast<void *>(m_opaque_sp.get()));
Enrico Granatae3e91512012-10-22 18:18:36 +00001150 else
Kate Stoneb9c1b512016-09-06 20:57:50 +00001151 log->Printf("SBValue(%p)::GetTarget () => %p",
1152 static_cast<void *>(m_opaque_sp.get()),
1153 static_cast<void *>(target_sp.get()));
1154 }
1155 return sb_target;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001156}
Caroline Ticedde9cff2010-09-20 05:20:02 +00001157
Kate Stoneb9c1b512016-09-06 20:57:50 +00001158lldb::SBProcess SBValue::GetProcess() {
1159 SBProcess sb_process;
1160 ProcessSP process_sp;
1161 if (m_opaque_sp) {
1162 process_sp = m_opaque_sp->GetProcessSP();
1163 sb_process.SetSP(process_sp);
1164 }
1165 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1166 if (log) {
1167 if (process_sp.get() == NULL)
1168 log->Printf("SBValue(%p)::GetProcess () => NULL",
1169 static_cast<void *>(m_opaque_sp.get()));
Enrico Granatae3e91512012-10-22 18:18:36 +00001170 else
Kate Stoneb9c1b512016-09-06 20:57:50 +00001171 log->Printf("SBValue(%p)::GetProcess () => %p",
1172 static_cast<void *>(m_opaque_sp.get()),
1173 static_cast<void *>(process_sp.get()));
1174 }
1175 return sb_process;
Enrico Granatae3e91512012-10-22 18:18:36 +00001176}
1177
Kate Stoneb9c1b512016-09-06 20:57:50 +00001178lldb::SBThread SBValue::GetThread() {
1179 SBThread sb_thread;
1180 ThreadSP thread_sp;
1181 if (m_opaque_sp) {
1182 thread_sp = m_opaque_sp->GetThreadSP();
1183 sb_thread.SetThread(thread_sp);
1184 }
1185 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1186 if (log) {
1187 if (thread_sp.get() == NULL)
1188 log->Printf("SBValue(%p)::GetThread () => NULL",
1189 static_cast<void *>(m_opaque_sp.get()));
Enrico Granatae3e91512012-10-22 18:18:36 +00001190 else
Kate Stoneb9c1b512016-09-06 20:57:50 +00001191 log->Printf("SBValue(%p)::GetThread () => %p",
1192 static_cast<void *>(m_opaque_sp.get()),
1193 static_cast<void *>(thread_sp.get()));
1194 }
1195 return sb_thread;
Enrico Granatae3e91512012-10-22 18:18:36 +00001196}
1197
Kate Stoneb9c1b512016-09-06 20:57:50 +00001198lldb::SBFrame SBValue::GetFrame() {
1199 SBFrame sb_frame;
1200 StackFrameSP frame_sp;
1201 if (m_opaque_sp) {
1202 frame_sp = m_opaque_sp->GetFrameSP();
1203 sb_frame.SetFrameSP(frame_sp);
1204 }
1205 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1206 if (log) {
1207 if (frame_sp.get() == NULL)
1208 log->Printf("SBValue(%p)::GetFrame () => NULL",
1209 static_cast<void *>(m_opaque_sp.get()));
Caroline Ticedde9cff2010-09-20 05:20:02 +00001210 else
Kate Stoneb9c1b512016-09-06 20:57:50 +00001211 log->Printf("SBValue(%p)::GetFrame () => %p",
1212 static_cast<void *>(m_opaque_sp.get()),
1213 static_cast<void *>(frame_sp.get()));
1214 }
1215 return sb_frame;
1216}
1217
1218lldb::ValueObjectSP SBValue::GetSP(ValueLocker &locker) const {
1219 if (!m_opaque_sp || !m_opaque_sp->IsValid()) {
1220 locker.GetError().SetErrorString("No value");
1221 return ValueObjectSP();
1222 }
1223 return locker.GetLockedSP(*m_opaque_sp.get());
1224}
1225
1226lldb::ValueObjectSP SBValue::GetSP() const {
1227 ValueLocker locker;
1228 return GetSP(locker);
1229}
1230
1231void SBValue::SetSP(ValueImplSP impl_sp) { m_opaque_sp = impl_sp; }
1232
1233void SBValue::SetSP(const lldb::ValueObjectSP &sp) {
1234 if (sp) {
1235 lldb::TargetSP target_sp(sp->GetTargetSP());
1236 if (target_sp) {
1237 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1238 bool use_synthetic =
1239 target_sp->TargetProperties::GetEnableSyntheticValue();
1240 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1241 } else
1242 m_opaque_sp = ValueImplSP(new ValueImpl(sp, eNoDynamicValues, true));
1243 } else
1244 m_opaque_sp = ValueImplSP(new ValueImpl(sp, eNoDynamicValues, false));
1245}
1246
1247void SBValue::SetSP(const lldb::ValueObjectSP &sp,
1248 lldb::DynamicValueType use_dynamic) {
1249 if (sp) {
1250 lldb::TargetSP target_sp(sp->GetTargetSP());
1251 if (target_sp) {
1252 bool use_synthetic =
1253 target_sp->TargetProperties::GetEnableSyntheticValue();
1254 SetSP(sp, use_dynamic, use_synthetic);
1255 } else
1256 SetSP(sp, use_dynamic, true);
1257 } else
1258 SetSP(sp, use_dynamic, false);
1259}
1260
1261void SBValue::SetSP(const lldb::ValueObjectSP &sp, bool use_synthetic) {
1262 if (sp) {
1263 lldb::TargetSP target_sp(sp->GetTargetSP());
1264 if (target_sp) {
1265 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1266 SetSP(sp, use_dynamic, use_synthetic);
1267 } else
1268 SetSP(sp, eNoDynamicValues, use_synthetic);
1269 } else
1270 SetSP(sp, eNoDynamicValues, use_synthetic);
1271}
1272
1273void SBValue::SetSP(const lldb::ValueObjectSP &sp,
1274 lldb::DynamicValueType use_dynamic, bool use_synthetic) {
1275 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1276}
1277
1278void SBValue::SetSP(const lldb::ValueObjectSP &sp,
1279 lldb::DynamicValueType use_dynamic, bool use_synthetic,
1280 const char *name) {
1281 m_opaque_sp =
1282 ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic, name));
1283}
1284
1285bool SBValue::GetExpressionPath(SBStream &description) {
1286 ValueLocker locker;
1287 lldb::ValueObjectSP value_sp(GetSP(locker));
1288 if (value_sp) {
1289 value_sp->GetExpressionPath(description.ref(), false);
Caroline Ticedde9cff2010-09-20 05:20:02 +00001290 return true;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001291 }
1292 return false;
Caroline Ticedde9cff2010-09-20 05:20:02 +00001293}
Greg Claytondc4e9632011-01-05 18:43:15 +00001294
Kate Stoneb9c1b512016-09-06 20:57:50 +00001295bool SBValue::GetExpressionPath(SBStream &description,
1296 bool qualify_cxx_base_classes) {
1297 ValueLocker locker;
1298 lldb::ValueObjectSP value_sp(GetSP(locker));
1299 if (value_sp) {
1300 value_sp->GetExpressionPath(description.ref(), qualify_cxx_base_classes);
1301 return true;
1302 }
1303 return false;
Greg Claytondc4e9632011-01-05 18:43:15 +00001304}
1305
Kate Stoneb9c1b512016-09-06 20:57:50 +00001306bool SBValue::GetDescription(SBStream &description) {
1307 Stream &strm = description.ref();
1308
1309 ValueLocker locker;
1310 lldb::ValueObjectSP value_sp(GetSP(locker));
1311 if (value_sp)
1312 value_sp->Dump(strm);
1313 else
1314 strm.PutCString("No value");
1315
1316 return true;
Greg Claytondc4e9632011-01-05 18:43:15 +00001317}
1318
Kate Stoneb9c1b512016-09-06 20:57:50 +00001319lldb::Format SBValue::GetFormat() {
1320 ValueLocker locker;
1321 lldb::ValueObjectSP value_sp(GetSP(locker));
1322 if (value_sp)
1323 return value_sp->GetFormat();
1324 return eFormatDefault;
Johnny Chen4a871f92011-08-09 22:38:07 +00001325}
Enrico Granata9128ee22011-09-06 19:20:51 +00001326
Kate Stoneb9c1b512016-09-06 20:57:50 +00001327void SBValue::SetFormat(lldb::Format format) {
1328 ValueLocker locker;
1329 lldb::ValueObjectSP value_sp(GetSP(locker));
1330 if (value_sp)
1331 value_sp->SetFormat(format);
1332}
1333
1334lldb::SBValue SBValue::AddressOf() {
1335 SBValue sb_value;
1336 ValueLocker locker;
1337 lldb::ValueObjectSP value_sp(GetSP(locker));
1338 if (value_sp) {
1339 Error error;
1340 sb_value.SetSP(value_sp->AddressOf(error), GetPreferDynamicValue(),
1341 GetPreferSyntheticValue());
1342 }
1343 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1344 if (log)
1345 log->Printf("SBValue(%p)::AddressOf () => SBValue(%p)",
1346 static_cast<void *>(value_sp.get()),
1347 static_cast<void *>(value_sp.get()));
1348
1349 return sb_value;
1350}
1351
1352lldb::addr_t SBValue::GetLoadAddress() {
1353 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1354 ValueLocker locker;
1355 lldb::ValueObjectSP value_sp(GetSP(locker));
1356 if (value_sp) {
1357 TargetSP target_sp(value_sp->GetTargetSP());
1358 if (target_sp) {
1359 const bool scalar_is_load_address = true;
1360 AddressType addr_type;
1361 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1362 if (addr_type == eAddressTypeFile) {
1363 ModuleSP module_sp(value_sp->GetModule());
1364 if (!module_sp)
1365 value = LLDB_INVALID_ADDRESS;
1366 else {
1367 Address addr;
1368 module_sp->ResolveFileAddress(value, addr);
1369 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001370 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001371 } else if (addr_type == eAddressTypeHost ||
1372 addr_type == eAddressTypeInvalid)
1373 value = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001374 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001375 }
1376 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1377 if (log)
1378 log->Printf("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")",
1379 static_cast<void *>(value_sp.get()), value);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001380
Kate Stoneb9c1b512016-09-06 20:57:50 +00001381 return value;
Enrico Granata9128ee22011-09-06 19:20:51 +00001382}
1383
Kate Stoneb9c1b512016-09-06 20:57:50 +00001384lldb::SBAddress SBValue::GetAddress() {
1385 Address addr;
1386 ValueLocker locker;
1387 lldb::ValueObjectSP value_sp(GetSP(locker));
1388 if (value_sp) {
1389 TargetSP target_sp(value_sp->GetTargetSP());
1390 if (target_sp) {
1391 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1392 const bool scalar_is_load_address = true;
1393 AddressType addr_type;
1394 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1395 if (addr_type == eAddressTypeFile) {
1396 ModuleSP module_sp(value_sp->GetModule());
1397 if (module_sp)
1398 module_sp->ResolveFileAddress(value, addr);
1399 } else if (addr_type == eAddressTypeLoad) {
1400 // no need to check the return value on this.. if it can actually do the
1401 // resolve
1402 // addr will be in the form (section,offset), otherwise it will simply
1403 // be returned
1404 // as (NULL, value)
1405 addr.SetLoadAddress(value, target_sp.get());
1406 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001407 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001408 }
1409 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1410 if (log)
1411 log->Printf("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")",
1412 static_cast<void *>(value_sp.get()),
1413 (addr.GetSection() ? addr.GetSection()->GetName().GetCString()
1414 : "NULL"),
1415 addr.GetOffset());
1416 return SBAddress(new Address(addr));
Enrico Granata9128ee22011-09-06 19:20:51 +00001417}
1418
Kate Stoneb9c1b512016-09-06 20:57:50 +00001419lldb::SBData SBValue::GetPointeeData(uint32_t item_idx, uint32_t item_count) {
1420 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1421 lldb::SBData sb_data;
1422 ValueLocker locker;
1423 lldb::ValueObjectSP value_sp(GetSP(locker));
1424 if (value_sp) {
1425 TargetSP target_sp(value_sp->GetTargetSP());
1426 if (target_sp) {
1427 DataExtractorSP data_sp(new DataExtractor());
1428 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1429 if (data_sp->GetByteSize() > 0)
1430 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001431 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001432 }
1433 if (log)
1434 log->Printf("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
1435 static_cast<void *>(value_sp.get()), item_idx, item_count,
1436 static_cast<void *>(sb_data.get()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001437
Kate Stoneb9c1b512016-09-06 20:57:50 +00001438 return sb_data;
Enrico Granata9128ee22011-09-06 19:20:51 +00001439}
1440
Kate Stoneb9c1b512016-09-06 20:57:50 +00001441lldb::SBData SBValue::GetData() {
1442 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1443 lldb::SBData sb_data;
1444 ValueLocker locker;
1445 lldb::ValueObjectSP value_sp(GetSP(locker));
1446 if (value_sp) {
1447 DataExtractorSP data_sp(new DataExtractor());
1448 Error error;
1449 value_sp->GetData(*data_sp, error);
1450 if (error.Success())
1451 *sb_data = data_sp;
1452 }
1453 if (log)
1454 log->Printf("SBValue(%p)::GetData () => SBData(%p)",
1455 static_cast<void *>(value_sp.get()),
1456 static_cast<void *>(sb_data.get()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001457
Kate Stoneb9c1b512016-09-06 20:57:50 +00001458 return sb_data;
Enrico Granata9128ee22011-09-06 19:20:51 +00001459}
Greg Clayton1b282f92011-10-13 18:08:26 +00001460
Kate Stoneb9c1b512016-09-06 20:57:50 +00001461bool SBValue::SetData(lldb::SBData &data, SBError &error) {
1462 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1463 ValueLocker locker;
1464 lldb::ValueObjectSP value_sp(GetSP(locker));
1465 bool ret = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001466
Kate Stoneb9c1b512016-09-06 20:57:50 +00001467 if (value_sp) {
1468 DataExtractor *data_extractor = data.get();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001469
Kate Stoneb9c1b512016-09-06 20:57:50 +00001470 if (!data_extractor) {
1471 if (log)
1472 log->Printf("SBValue(%p)::SetData() => error: no data to set",
1473 static_cast<void *>(value_sp.get()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001474
Kate Stoneb9c1b512016-09-06 20:57:50 +00001475 error.SetErrorString("No data to set");
1476 ret = false;
1477 } else {
1478 Error set_error;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001479
Kate Stoneb9c1b512016-09-06 20:57:50 +00001480 value_sp->SetData(*data_extractor, set_error);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001481
Kate Stoneb9c1b512016-09-06 20:57:50 +00001482 if (!set_error.Success()) {
1483 error.SetErrorStringWithFormat("Couldn't set data: %s",
1484 set_error.AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001485 ret = false;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001486 }
Sean Callanan389823e2013-04-13 01:21:23 +00001487 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001488 } else {
1489 error.SetErrorStringWithFormat(
1490 "Couldn't set data: could not get SBValue: %s",
1491 locker.GetError().AsCString());
1492 ret = false;
1493 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001494
Kate Stoneb9c1b512016-09-06 20:57:50 +00001495 if (log)
1496 log->Printf("SBValue(%p)::SetData (%p) => %s",
1497 static_cast<void *>(value_sp.get()),
1498 static_cast<void *>(data.get()), ret ? "true" : "false");
1499 return ret;
Sean Callanan389823e2013-04-13 01:21:23 +00001500}
1501
Kate Stoneb9c1b512016-09-06 20:57:50 +00001502lldb::SBDeclaration SBValue::GetDeclaration() {
1503 ValueLocker locker;
1504 lldb::ValueObjectSP value_sp(GetSP(locker));
1505 SBDeclaration decl_sb;
1506 if (value_sp) {
1507 Declaration decl;
1508 if (value_sp->GetDeclaration(decl))
1509 decl_sb.SetDeclaration(decl);
1510 }
1511 return decl_sb;
Enrico Granata10de0902012-10-10 22:54:17 +00001512}
1513
Kate Stoneb9c1b512016-09-06 20:57:50 +00001514lldb::SBWatchpoint SBValue::Watch(bool resolve_location, bool read, bool write,
1515 SBError &error) {
1516 SBWatchpoint sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001517
Kate Stoneb9c1b512016-09-06 20:57:50 +00001518 // If the SBValue is not valid, there's no point in even trying to watch it.
1519 ValueLocker locker;
1520 lldb::ValueObjectSP value_sp(GetSP(locker));
1521 TargetSP target_sp(GetTarget().GetSP());
1522 if (value_sp && target_sp) {
1523 // Read and Write cannot both be false.
1524 if (!read && !write)
1525 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001526
Kate Stoneb9c1b512016-09-06 20:57:50 +00001527 // If the value is not in scope, don't try and watch and invalid value
1528 if (!IsInScope())
1529 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001530
Kate Stoneb9c1b512016-09-06 20:57:50 +00001531 addr_t addr = GetLoadAddress();
1532 if (addr == LLDB_INVALID_ADDRESS)
1533 return sb_watchpoint;
1534 size_t byte_size = GetByteSize();
1535 if (byte_size == 0)
1536 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001537
Kate Stoneb9c1b512016-09-06 20:57:50 +00001538 uint32_t watch_type = 0;
1539 if (read)
1540 watch_type |= LLDB_WATCH_TYPE_READ;
1541 if (write)
1542 watch_type |= LLDB_WATCH_TYPE_WRITE;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001543
Kate Stoneb9c1b512016-09-06 20:57:50 +00001544 Error rc;
1545 CompilerType type(value_sp->GetCompilerType());
1546 WatchpointSP watchpoint_sp =
1547 target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
1548 error.SetError(rc);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001549
Kate Stoneb9c1b512016-09-06 20:57:50 +00001550 if (watchpoint_sp) {
1551 sb_watchpoint.SetSP(watchpoint_sp);
1552 Declaration decl;
1553 if (value_sp->GetDeclaration(decl)) {
1554 if (decl.GetFile()) {
1555 StreamString ss;
1556 // True to show fullpath for declaration file.
1557 decl.DumpStopContext(&ss, true);
1558 watchpoint_sp->SetDeclInfo(ss.GetString());
Greg Clayton81e871e2012-02-04 02:27:34 +00001559 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001560 }
Greg Clayton1b282f92011-10-13 18:08:26 +00001561 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001562 } else if (target_sp) {
1563 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1564 if (log)
1565 log->Printf("SBValue(%p)::Watch() => error getting SBValue: %s",
1566 static_cast<void *>(value_sp.get()),
1567 locker.GetError().AsCString());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001568
Kate Stoneb9c1b512016-09-06 20:57:50 +00001569 error.SetErrorStringWithFormat("could not get SBValue: %s",
1570 locker.GetError().AsCString());
1571 } else {
1572 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1573 if (log)
1574 log->Printf("SBValue(%p)::Watch() => error getting SBValue: no target",
1575 static_cast<void *>(value_sp.get()));
1576 error.SetErrorString("could not set watchpoint, a target is required");
1577 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001578
Kate Stoneb9c1b512016-09-06 20:57:50 +00001579 return sb_watchpoint;
Greg Clayton1b282f92011-10-13 18:08:26 +00001580}
1581
Kate Stoneb9c1b512016-09-06 20:57:50 +00001582// FIXME: Remove this method impl (as well as the decl in .h) once it is no
1583// longer needed.
Johnny Chend3761a72012-06-04 23:45:50 +00001584// Backward compatibility fix in the interim.
Kate Stoneb9c1b512016-09-06 20:57:50 +00001585lldb::SBWatchpoint SBValue::Watch(bool resolve_location, bool read,
1586 bool write) {
1587 SBError error;
1588 return Watch(resolve_location, read, write, error);
Johnny Chend3761a72012-06-04 23:45:50 +00001589}
1590
Kate Stoneb9c1b512016-09-06 20:57:50 +00001591lldb::SBWatchpoint SBValue::WatchPointee(bool resolve_location, bool read,
1592 bool write, SBError &error) {
1593 SBWatchpoint sb_watchpoint;
1594 if (IsInScope() && GetType().IsPointerType())
1595 sb_watchpoint = Dereference().Watch(resolve_location, read, write, error);
1596 return sb_watchpoint;
Greg Clayton1b282f92011-10-13 18:08:26 +00001597}
Enrico Granata0c10a852014-12-08 23:13:56 +00001598
Kate Stoneb9c1b512016-09-06 20:57:50 +00001599lldb::SBValue SBValue::Persist() {
1600 ValueLocker locker;
1601 lldb::ValueObjectSP value_sp(GetSP(locker));
1602 SBValue persisted_sb;
1603 if (value_sp) {
1604 persisted_sb.SetSP(value_sp->Persist());
1605 }
1606 return persisted_sb;
Enrico Granata0c10a852014-12-08 23:13:56 +00001607}