blob: 67ad6259cde08d4641ff5b6fbe4fb93fadc7da63 [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/Module.h"
Greg Clayton1f746072012-08-29 21:13:06 +000021#include "lldb/Core/Section.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/StreamFile.h"
23#include "lldb/Core/Value.h"
24#include "lldb/Core/ValueObject.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000025#include "lldb/Core/ValueObjectConstResult.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000026#include "lldb/DataFormatters/DataVisualization.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Symbol/Block.h"
Enrico Granata10de0902012-10-10 22:54:17 +000028#include "lldb/Symbol/Declaration.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Symbol/ObjectFile.h"
Greg Clayton81e871e2012-02-04 02:27:34 +000030#include "lldb/Symbol/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Symbol/Variable.h"
Johnny Chen01a67862011-10-14 00:42:25 +000032#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Target/ExecutionContext.h"
34#include "lldb/Target/Process.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000035#include "lldb/Target/StackFrame.h"
Greg Claytonaf67cec2010-12-20 20:49:23 +000036#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037#include "lldb/Target/Thread.h"
Zachary Turner666cc0b2017-03-04 01:30:05 +000038#include "lldb/Utility/DataExtractor.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000039#include "lldb/Utility/Log.h"
Pavel Labathd821c992018-08-07 11:07:21 +000040#include "lldb/Utility/Scalar.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
Adrian Prantl05097242018-04-30 16:49:04 +000092 // enforces that restriction when you call IsValid, but since IsValid
93 // doesn't lock the target, you have no guarantee that the SBValue won't
94 // go invalid after you call this... Also, an SBValue could depend on
95 // data from one of the modules in the target, and those could go away
96 // independently of the target, for instance if a module is unloaded.
97 // But right now, neither SBValues nor ValueObjects know which modules
98 // they depend on. So I have no good way to make that check without
Kate Stoneb9c1b512016-09-06 20:57:50 +000099 // tracking that in all the ValueObject subclasses.
100 TargetSP target_sp = m_valobj_sp->GetTargetSP();
101 if (target_sp && target_sp->IsValid())
102 return true;
103 else
104 return false;
105 }
106 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000107
Kate Stoneb9c1b512016-09-06 20:57:50 +0000108 lldb::ValueObjectSP GetRootSP() { return m_valobj_sp; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000109
Kate Stoneb9c1b512016-09-06 20:57:50 +0000110 lldb::ValueObjectSP GetSP(Process::StopLocker &stop_locker,
111 std::unique_lock<std::recursive_mutex> &lock,
Zachary Turner97206d52017-05-12 04:51:55 +0000112 Status &error) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
114 if (!m_valobj_sp) {
115 error.SetErrorString("invalid value object");
116 return m_valobj_sp;
117 }
Jim Ingham5d3bca42011-12-19 20:39:44 +0000118
Kate Stoneb9c1b512016-09-06 20:57:50 +0000119 lldb::ValueObjectSP value_sp = m_valobj_sp;
120
121 Target *target = value_sp->GetTargetSP().get();
122 if (!target)
123 return ValueObjectSP();
124
125 lock = std::unique_lock<std::recursive_mutex>(target->GetAPIMutex());
126
127 ProcessSP process_sp(value_sp->GetProcessSP());
128 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock())) {
Adrian Prantl05097242018-04-30 16:49:04 +0000129 // We don't allow people to play around with ValueObject if the process
130 // is running. If you want to look at values, pause the process, then
131 // look.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000132 if (log)
133 log->Printf("SBValue(%p)::GetSP() => error: process is running",
134 static_cast<void *>(value_sp.get()));
135 error.SetErrorString("process must be stopped.");
136 return ValueObjectSP();
137 }
138
139 if (m_use_dynamic != eNoDynamicValues) {
140 ValueObjectSP dynamic_sp = value_sp->GetDynamicValue(m_use_dynamic);
141 if (dynamic_sp)
142 value_sp = dynamic_sp;
143 }
144
145 if (m_use_synthetic) {
146 ValueObjectSP synthetic_sp = value_sp->GetSyntheticValue(m_use_synthetic);
147 if (synthetic_sp)
148 value_sp = synthetic_sp;
149 }
150
151 if (!value_sp)
152 error.SetErrorString("invalid value object");
153 if (!m_name.IsEmpty())
154 value_sp->SetName(m_name);
155
156 return value_sp;
157 }
158
159 void SetUseDynamic(lldb::DynamicValueType use_dynamic) {
160 m_use_dynamic = use_dynamic;
161 }
162
163 void SetUseSynthetic(bool use_synthetic) { m_use_synthetic = use_synthetic; }
164
165 lldb::DynamicValueType GetUseDynamic() { return m_use_dynamic; }
166
167 bool GetUseSynthetic() { return m_use_synthetic; }
168
169 // All the derived values that we would make from the m_valobj_sp will share
170 // the ExecutionContext with m_valobj_sp, so we don't need to do the
Adrian Prantl05097242018-04-30 16:49:04 +0000171 // calculations in GetSP to return the Target, Process, Thread or Frame. It
172 // is convenient to provide simple accessors for these, which I do here.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000173 TargetSP GetTargetSP() {
174 if (m_valobj_sp)
175 return m_valobj_sp->GetTargetSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000176 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000177 return TargetSP();
178 }
179
180 ProcessSP GetProcessSP() {
181 if (m_valobj_sp)
182 return m_valobj_sp->GetProcessSP();
183 else
184 return ProcessSP();
185 }
186
187 ThreadSP GetThreadSP() {
188 if (m_valobj_sp)
189 return m_valobj_sp->GetThreadSP();
190 else
191 return ThreadSP();
192 }
193
194 StackFrameSP GetFrameSP() {
195 if (m_valobj_sp)
196 return m_valobj_sp->GetFrameSP();
197 else
198 return StackFrameSP();
199 }
200
201private:
202 lldb::ValueObjectSP m_valobj_sp;
203 lldb::DynamicValueType m_use_dynamic;
204 bool m_use_synthetic;
205 ConstString m_name;
206};
207
208class ValueLocker {
209public:
210 ValueLocker() {}
211
212 ValueObjectSP GetLockedSP(ValueImpl &in_value) {
213 return in_value.GetSP(m_stop_locker, m_lock, m_lock_error);
214 }
215
Zachary Turner97206d52017-05-12 04:51:55 +0000216 Status &GetError() { return m_lock_error; }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000217
218private:
219 Process::StopLocker m_stop_locker;
220 std::unique_lock<std::recursive_mutex> m_lock;
Zachary Turner97206d52017-05-12 04:51:55 +0000221 Status m_lock_error;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000222};
223
224SBValue::SBValue() : m_opaque_sp() {}
225
226SBValue::SBValue(const lldb::ValueObjectSP &value_sp) { SetSP(value_sp); }
227
228SBValue::SBValue(const SBValue &rhs) { SetSP(rhs.m_opaque_sp); }
229
230SBValue &SBValue::operator=(const SBValue &rhs) {
231 if (this != &rhs) {
232 SetSP(rhs.m_opaque_sp);
233 }
234 return *this;
Greg Clayton524e60b2010-10-06 22:10:17 +0000235}
236
Kate Stoneb9c1b512016-09-06 20:57:50 +0000237SBValue::~SBValue() {}
238
239bool SBValue::IsValid() {
Adrian Prantl05097242018-04-30 16:49:04 +0000240 // If this function ever changes to anything that does more than just check
241 // if the opaque shared pointer is non NULL, then we need to update all "if
242 // (m_opaque_sp)" code in this file.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000243 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid() &&
244 m_opaque_sp->GetRootSP().get() != NULL;
Johnny Chenb0b8be72011-07-07 20:46:23 +0000245}
246
Kate Stoneb9c1b512016-09-06 20:57:50 +0000247void SBValue::Clear() { m_opaque_sp.reset(); }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000248
Kate Stoneb9c1b512016-09-06 20:57:50 +0000249SBError SBValue::GetError() {
250 SBError sb_error;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000251
Kate Stoneb9c1b512016-09-06 20:57:50 +0000252 ValueLocker locker;
253 lldb::ValueObjectSP value_sp(GetSP(locker));
254 if (value_sp)
255 sb_error.SetError(value_sp->GetError());
256 else
257 sb_error.SetErrorStringWithFormat("error: %s",
258 locker.GetError().AsCString());
259
260 return sb_error;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000261}
262
Kate Stoneb9c1b512016-09-06 20:57:50 +0000263user_id_t SBValue::GetID() {
264 ValueLocker locker;
265 lldb::ValueObjectSP value_sp(GetSP(locker));
266 if (value_sp)
267 return value_sp->GetID();
268 return LLDB_INVALID_UID;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000269}
270
Kate Stoneb9c1b512016-09-06 20:57:50 +0000271const char *SBValue::GetName() {
272 const char *name = NULL;
273 ValueLocker locker;
274 lldb::ValueObjectSP value_sp(GetSP(locker));
275 if (value_sp)
276 name = value_sp->GetName().GetCString();
277
278 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
279 if (log) {
280 if (name)
281 log->Printf("SBValue(%p)::GetName () => \"%s\"",
282 static_cast<void *>(value_sp.get()), name);
283 else
284 log->Printf("SBValue(%p)::GetName () => NULL",
285 static_cast<void *>(value_sp.get()));
286 }
287
288 return name;
Enrico Granatae8daa2f2014-05-17 19:14:17 +0000289}
290
Kate Stoneb9c1b512016-09-06 20:57:50 +0000291const char *SBValue::GetTypeName() {
292 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
293 const char *name = NULL;
294 ValueLocker locker;
295 lldb::ValueObjectSP value_sp(GetSP(locker));
296 if (value_sp) {
297 name = value_sp->GetQualifiedTypeName().GetCString();
298 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000299
Kate Stoneb9c1b512016-09-06 20:57:50 +0000300 if (log) {
301 if (name)
302 log->Printf("SBValue(%p)::GetTypeName () => \"%s\"",
303 static_cast<void *>(value_sp.get()), name);
304 else
305 log->Printf("SBValue(%p)::GetTypeName () => NULL",
306 static_cast<void *>(value_sp.get()));
307 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000308
Kate Stoneb9c1b512016-09-06 20:57:50 +0000309 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310}
311
Kate Stoneb9c1b512016-09-06 20:57:50 +0000312const char *SBValue::GetDisplayTypeName() {
313 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
314 const char *name = NULL;
315 ValueLocker locker;
316 lldb::ValueObjectSP value_sp(GetSP(locker));
317 if (value_sp) {
318 name = value_sp->GetDisplayTypeName().GetCString();
319 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000320
Kate Stoneb9c1b512016-09-06 20:57:50 +0000321 if (log) {
322 if (name)
323 log->Printf("SBValue(%p)::GetTypeName () => \"%s\"",
324 static_cast<void *>(value_sp.get()), name);
325 else
326 log->Printf("SBValue(%p)::GetTypeName () => NULL",
327 static_cast<void *>(value_sp.get()));
328 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000329
Kate Stoneb9c1b512016-09-06 20:57:50 +0000330 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000331}
332
Kate Stoneb9c1b512016-09-06 20:57:50 +0000333size_t SBValue::GetByteSize() {
334 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
335 size_t result = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000336
Kate Stoneb9c1b512016-09-06 20:57:50 +0000337 ValueLocker locker;
338 lldb::ValueObjectSP value_sp(GetSP(locker));
339 if (value_sp) {
340 result = value_sp->GetByteSize();
341 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000342
Kate Stoneb9c1b512016-09-06 20:57:50 +0000343 if (log)
344 log->Printf("SBValue(%p)::GetByteSize () => %" PRIu64,
345 static_cast<void *>(value_sp.get()),
346 static_cast<uint64_t>(result));
347
348 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000349}
350
Kate Stoneb9c1b512016-09-06 20:57:50 +0000351bool SBValue::IsInScope() {
352 bool result = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000353
Kate Stoneb9c1b512016-09-06 20:57:50 +0000354 ValueLocker locker;
355 lldb::ValueObjectSP value_sp(GetSP(locker));
356 if (value_sp) {
357 result = value_sp->IsInScope();
358 }
359
360 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
361 if (log)
362 log->Printf("SBValue(%p)::IsInScope () => %i",
363 static_cast<void *>(value_sp.get()), result);
364
365 return result;
Greg Clayton73b472d2010-10-27 03:32:59 +0000366}
367
Kate Stoneb9c1b512016-09-06 20:57:50 +0000368const char *SBValue::GetValue() {
369 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
370
371 const char *cstr = NULL;
372 ValueLocker locker;
373 lldb::ValueObjectSP value_sp(GetSP(locker));
374 if (value_sp) {
375 cstr = value_sp->GetValueAsCString();
376 }
377 if (log) {
378 if (cstr)
379 log->Printf("SBValue(%p)::GetValue() => \"%s\"",
380 static_cast<void *>(value_sp.get()), cstr);
381 else
382 log->Printf("SBValue(%p)::GetValue() => NULL",
383 static_cast<void *>(value_sp.get()));
384 }
385
386 return cstr;
Jim Ingham53c47f12010-09-10 23:12:17 +0000387}
388
Kate Stoneb9c1b512016-09-06 20:57:50 +0000389ValueType SBValue::GetValueType() {
390 ValueType result = eValueTypeInvalid;
391 ValueLocker locker;
392 lldb::ValueObjectSP value_sp(GetSP(locker));
393 if (value_sp)
394 result = value_sp->GetValueType();
395
396 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
397 if (log) {
398 switch (result) {
399 case eValueTypeInvalid:
400 log->Printf("SBValue(%p)::GetValueType () => eValueTypeInvalid",
401 static_cast<void *>(value_sp.get()));
402 break;
403 case eValueTypeVariableGlobal:
404 log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal",
405 static_cast<void *>(value_sp.get()));
406 break;
407 case eValueTypeVariableStatic:
408 log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableStatic",
409 static_cast<void *>(value_sp.get()));
410 break;
411 case eValueTypeVariableArgument:
412 log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableArgument",
413 static_cast<void *>(value_sp.get()));
414 break;
415 case eValueTypeVariableLocal:
416 log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableLocal",
417 static_cast<void *>(value_sp.get()));
418 break;
419 case eValueTypeRegister:
420 log->Printf("SBValue(%p)::GetValueType () => eValueTypeRegister",
421 static_cast<void *>(value_sp.get()));
422 break;
423 case eValueTypeRegisterSet:
424 log->Printf("SBValue(%p)::GetValueType () => eValueTypeRegisterSet",
425 static_cast<void *>(value_sp.get()));
426 break;
427 case eValueTypeConstResult:
428 log->Printf("SBValue(%p)::GetValueType () => eValueTypeConstResult",
429 static_cast<void *>(value_sp.get()));
430 break;
431 case eValueTypeVariableThreadLocal:
432 log->Printf(
433 "SBValue(%p)::GetValueType () => eValueTypeVariableThreadLocal",
434 static_cast<void *>(value_sp.get()));
435 break;
Enrico Granataedc44142014-09-06 01:30:04 +0000436 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000437 }
438 return result;
Enrico Granataedc44142014-09-06 01:30:04 +0000439}
440
Kate Stoneb9c1b512016-09-06 20:57:50 +0000441const char *SBValue::GetObjectDescription() {
442 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
443 const char *cstr = NULL;
444 ValueLocker locker;
445 lldb::ValueObjectSP value_sp(GetSP(locker));
446 if (value_sp) {
447 cstr = value_sp->GetObjectDescription();
448 }
449 if (log) {
450 if (cstr)
451 log->Printf("SBValue(%p)::GetObjectDescription() => \"%s\"",
452 static_cast<void *>(value_sp.get()), cstr);
453 else
454 log->Printf("SBValue(%p)::GetObjectDescription() => NULL",
455 static_cast<void *>(value_sp.get()));
456 }
457 return cstr;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000458}
459
Kate Stoneb9c1b512016-09-06 20:57:50 +0000460const char *SBValue::GetTypeValidatorResult() {
461 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
462 const char *cstr = NULL;
463 ValueLocker locker;
464 lldb::ValueObjectSP value_sp(GetSP(locker));
465 if (value_sp) {
466 const auto &validation(value_sp->GetValidationStatus());
467 if (TypeValidatorResult::Failure == validation.first) {
468 if (validation.second.empty())
469 cstr = "unknown error";
470 else
471 cstr = validation.second.c_str();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000472 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000473 }
474 if (log) {
475 if (cstr)
476 log->Printf("SBValue(%p)::GetTypeValidatorResult() => \"%s\"",
477 static_cast<void *>(value_sp.get()), cstr);
478 else
479 log->Printf("SBValue(%p)::GetTypeValidatorResult() => NULL",
480 static_cast<void *>(value_sp.get()));
481 }
482 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483}
484
Kate Stoneb9c1b512016-09-06 20:57:50 +0000485SBType SBValue::GetType() {
486 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
487 SBType sb_type;
488 ValueLocker locker;
489 lldb::ValueObjectSP value_sp(GetSP(locker));
490 TypeImplSP type_sp;
491 if (value_sp) {
492 type_sp.reset(new TypeImpl(value_sp->GetTypeImpl()));
493 sb_type.SetSP(type_sp);
494 }
495 if (log) {
496 if (type_sp)
497 log->Printf("SBValue(%p)::GetType => SBType(%p)",
498 static_cast<void *>(value_sp.get()),
499 static_cast<void *>(type_sp.get()));
500 else
501 log->Printf("SBValue(%p)::GetType => NULL",
502 static_cast<void *>(value_sp.get()));
503 }
504 return sb_type;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505}
Enrico Granatac1247f52014-11-06 21:23:20 +0000506
Kate Stoneb9c1b512016-09-06 20:57:50 +0000507bool SBValue::GetValueDidChange() {
508 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
509 bool result = false;
510 ValueLocker locker;
511 lldb::ValueObjectSP value_sp(GetSP(locker));
512 if (value_sp) {
513 if (value_sp->UpdateValueIfNeeded(false))
514 result = value_sp->GetValueDidChange();
515 }
516 if (log)
517 log->Printf("SBValue(%p)::GetValueDidChange() => %i",
518 static_cast<void *>(value_sp.get()), result);
519
520 return result;
Enrico Granatac1247f52014-11-06 21:23:20 +0000521}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522
Kate Stoneb9c1b512016-09-06 20:57:50 +0000523const char *SBValue::GetSummary() {
524 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
525 const char *cstr = NULL;
526 ValueLocker locker;
527 lldb::ValueObjectSP value_sp(GetSP(locker));
528 if (value_sp) {
529 cstr = value_sp->GetSummaryAsCString();
530 }
531 if (log) {
532 if (cstr)
533 log->Printf("SBValue(%p)::GetSummary() => \"%s\"",
534 static_cast<void *>(value_sp.get()), cstr);
535 else
536 log->Printf("SBValue(%p)::GetSummary() => NULL",
537 static_cast<void *>(value_sp.get()));
538 }
539 return cstr;
540}
541
542const char *SBValue::GetSummary(lldb::SBStream &stream,
543 lldb::SBTypeSummaryOptions &options) {
544 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
545 ValueLocker locker;
546 lldb::ValueObjectSP value_sp(GetSP(locker));
547 if (value_sp) {
548 std::string buffer;
549 if (value_sp->GetSummaryAsCString(buffer, options.ref()) && !buffer.empty())
550 stream.Printf("%s", buffer.c_str());
551 }
552 const char *cstr = stream.GetData();
553 if (log) {
554 if (cstr)
555 log->Printf("SBValue(%p)::GetSummary() => \"%s\"",
556 static_cast<void *>(value_sp.get()), cstr);
557 else
558 log->Printf("SBValue(%p)::GetSummary() => NULL",
559 static_cast<void *>(value_sp.get()));
560 }
561 return cstr;
562}
563
564const char *SBValue::GetLocation() {
565 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
566 const char *cstr = NULL;
567 ValueLocker locker;
568 lldb::ValueObjectSP value_sp(GetSP(locker));
569 if (value_sp) {
570 cstr = value_sp->GetLocationAsCString();
571 }
572 if (log) {
573 if (cstr)
574 log->Printf("SBValue(%p)::GetLocation() => \"%s\"",
575 static_cast<void *>(value_sp.get()), cstr);
576 else
577 log->Printf("SBValue(%p)::GetLocation() => NULL",
578 static_cast<void *>(value_sp.get()));
579 }
580 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000581}
582
Enrico Granata07a4ac22012-05-08 21:25:06 +0000583// Deprecated - use the one that takes an lldb::SBError
Kate Stoneb9c1b512016-09-06 20:57:50 +0000584bool SBValue::SetValueFromCString(const char *value_str) {
585 lldb::SBError dummy;
586 return SetValueFromCString(value_str, dummy);
Enrico Granata07a4ac22012-05-08 21:25:06 +0000587}
588
Kate Stoneb9c1b512016-09-06 20:57:50 +0000589bool SBValue::SetValueFromCString(const char *value_str, lldb::SBError &error) {
590 bool success = false;
591 ValueLocker locker;
592 lldb::ValueObjectSP value_sp(GetSP(locker));
593 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
594 if (value_sp) {
595 success = value_sp->SetValueFromCString(value_str, error.ref());
596 } else
597 error.SetErrorStringWithFormat("Could not get value: %s",
598 locker.GetError().AsCString());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000599
Kate Stoneb9c1b512016-09-06 20:57:50 +0000600 if (log)
601 log->Printf("SBValue(%p)::SetValueFromCString(\"%s\") => %i",
602 static_cast<void *>(value_sp.get()), value_str, success);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000603
Kate Stoneb9c1b512016-09-06 20:57:50 +0000604 return success;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000605}
606
Kate Stoneb9c1b512016-09-06 20:57:50 +0000607lldb::SBTypeFormat SBValue::GetTypeFormat() {
608 lldb::SBTypeFormat format;
609 ValueLocker locker;
610 lldb::ValueObjectSP value_sp(GetSP(locker));
611 if (value_sp) {
612 if (value_sp->UpdateValueIfNeeded(true)) {
613 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
614 if (format_sp)
615 format.SetSP(format_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000616 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000617 }
618 return format;
Enrico Granata864e3e82012-02-17 03:18:30 +0000619}
620
Kate Stoneb9c1b512016-09-06 20:57:50 +0000621lldb::SBTypeSummary SBValue::GetTypeSummary() {
622 lldb::SBTypeSummary summary;
623 ValueLocker locker;
624 lldb::ValueObjectSP value_sp(GetSP(locker));
625 if (value_sp) {
626 if (value_sp->UpdateValueIfNeeded(true)) {
627 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
628 if (summary_sp)
629 summary.SetSP(summary_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000630 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000631 }
632 return summary;
Enrico Granata864e3e82012-02-17 03:18:30 +0000633}
634
Kate Stoneb9c1b512016-09-06 20:57:50 +0000635lldb::SBTypeFilter SBValue::GetTypeFilter() {
636 lldb::SBTypeFilter filter;
637 ValueLocker locker;
638 lldb::ValueObjectSP value_sp(GetSP(locker));
639 if (value_sp) {
640 if (value_sp->UpdateValueIfNeeded(true)) {
641 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
642
643 if (synthetic_sp && !synthetic_sp->IsScripted()) {
644 TypeFilterImplSP filter_sp =
645 std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
646 filter.SetSP(filter_sp);
647 }
Enrico Granata864e3e82012-02-17 03:18:30 +0000648 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000649 }
650 return filter;
Enrico Granata864e3e82012-02-17 03:18:30 +0000651}
652
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000653#ifndef LLDB_DISABLE_PYTHON
Kate Stoneb9c1b512016-09-06 20:57:50 +0000654lldb::SBTypeSynthetic SBValue::GetTypeSynthetic() {
655 lldb::SBTypeSynthetic synthetic;
656 ValueLocker locker;
657 lldb::ValueObjectSP value_sp(GetSP(locker));
658 if (value_sp) {
659 if (value_sp->UpdateValueIfNeeded(true)) {
660 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
661
662 if (children_sp && children_sp->IsScripted()) {
663 ScriptedSyntheticChildrenSP synth_sp =
664 std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
665 synthetic.SetSP(synth_sp);
666 }
Enrico Granata864e3e82012-02-17 03:18:30 +0000667 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000668 }
669 return synthetic;
Enrico Granata864e3e82012-02-17 03:18:30 +0000670}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000671#endif
Enrico Granata864e3e82012-02-17 03:18:30 +0000672
Kate Stoneb9c1b512016-09-06 20:57:50 +0000673lldb::SBValue SBValue::CreateChildAtOffset(const char *name, uint32_t offset,
674 SBType type) {
675 lldb::SBValue sb_value;
676 ValueLocker locker;
677 lldb::ValueObjectSP value_sp(GetSP(locker));
678 lldb::ValueObjectSP new_value_sp;
679 if (value_sp) {
680 TypeImplSP type_sp(type.GetSP());
681 if (type.IsValid()) {
682 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(
683 offset, type_sp->GetCompilerType(false), true),
684 GetPreferDynamicValue(), GetPreferSyntheticValue(), name);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000685 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000686 }
687 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
688 if (log) {
689 if (new_value_sp)
690 log->Printf("SBValue(%p)::CreateChildAtOffset => \"%s\"",
691 static_cast<void *>(value_sp.get()),
692 new_value_sp->GetName().AsCString());
Jim Ingham362e39a2013-05-15 02:16:21 +0000693 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000694 log->Printf("SBValue(%p)::CreateChildAtOffset => NULL",
695 static_cast<void *>(value_sp.get()));
696 }
697 return sb_value;
Enrico Granata6fd87d52011-08-04 01:41:02 +0000698}
699
Kate Stoneb9c1b512016-09-06 20:57:50 +0000700lldb::SBValue SBValue::Cast(SBType type) {
701 lldb::SBValue sb_value;
702 ValueLocker locker;
703 lldb::ValueObjectSP value_sp(GetSP(locker));
704 TypeImplSP type_sp(type.GetSP());
705 if (value_sp && type_sp)
706 sb_value.SetSP(value_sp->Cast(type_sp->GetCompilerType(false)),
707 GetPreferDynamicValue(), GetPreferSyntheticValue());
708 return sb_value;
709}
710
711lldb::SBValue SBValue::CreateValueFromExpression(const char *name,
712 const char *expression) {
713 SBExpressionOptions options;
714 options.ref().SetKeepInMemory(true);
715 return CreateValueFromExpression(name, expression, options);
716}
717
718lldb::SBValue SBValue::CreateValueFromExpression(const char *name,
719 const char *expression,
720 SBExpressionOptions &options) {
721 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
722 lldb::SBValue sb_value;
723 ValueLocker locker;
724 lldb::ValueObjectSP value_sp(GetSP(locker));
725 lldb::ValueObjectSP new_value_sp;
726 if (value_sp) {
727 ExecutionContext exe_ctx(value_sp->GetExecutionContextRef());
728 new_value_sp = ValueObject::CreateValueObjectFromExpression(
729 name, expression, exe_ctx, options.ref());
730 if (new_value_sp)
731 new_value_sp->SetName(ConstString(name));
732 }
733 sb_value.SetSP(new_value_sp);
734 if (log) {
735 if (new_value_sp)
736 log->Printf("SBValue(%p)::CreateValueFromExpression(name=\"%s\", "
737 "expression=\"%s\") => SBValue (%p)",
738 static_cast<void *>(value_sp.get()), name, expression,
739 static_cast<void *>(new_value_sp.get()));
Jim Ingham362e39a2013-05-15 02:16:21 +0000740 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000741 log->Printf("SBValue(%p)::CreateValueFromExpression(name=\"%s\", "
742 "expression=\"%s\") => NULL",
743 static_cast<void *>(value_sp.get()), name, expression);
744 }
745 return sb_value;
Enrico Granata6fd87d52011-08-04 01:41:02 +0000746}
747
Kate Stoneb9c1b512016-09-06 20:57:50 +0000748lldb::SBValue SBValue::CreateValueFromAddress(const char *name,
749 lldb::addr_t address,
750 SBType sb_type) {
751 lldb::SBValue sb_value;
752 ValueLocker locker;
753 lldb::ValueObjectSP value_sp(GetSP(locker));
754 lldb::ValueObjectSP new_value_sp;
755 lldb::TypeImplSP type_impl_sp(sb_type.GetSP());
756 if (value_sp && type_impl_sp) {
757 CompilerType ast_type(type_impl_sp->GetCompilerType(true));
758 ExecutionContext exe_ctx(value_sp->GetExecutionContextRef());
759 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address,
760 exe_ctx, ast_type);
761 }
762 sb_value.SetSP(new_value_sp);
763 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
764 if (log) {
765 if (new_value_sp)
766 log->Printf("SBValue(%p)::CreateValueFromAddress => \"%s\"",
767 static_cast<void *>(value_sp.get()),
768 new_value_sp->GetName().AsCString());
769 else
770 log->Printf("SBValue(%p)::CreateValueFromAddress => NULL",
771 static_cast<void *>(value_sp.get()));
772 }
773 return sb_value;
774}
775
776lldb::SBValue SBValue::CreateValueFromData(const char *name, SBData data,
777 SBType sb_type) {
778 lldb::SBValue sb_value;
779 lldb::ValueObjectSP new_value_sp;
780 ValueLocker locker;
781 lldb::ValueObjectSP value_sp(GetSP(locker));
782 lldb::TypeImplSP type_impl_sp(sb_type.GetSP());
783 if (value_sp && type_impl_sp) {
784 ExecutionContext exe_ctx(value_sp->GetExecutionContextRef());
785 new_value_sp = ValueObject::CreateValueObjectFromData(
786 name, **data, exe_ctx, type_impl_sp->GetCompilerType(true));
787 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
788 }
789 sb_value.SetSP(new_value_sp);
790 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
791 if (log) {
792 if (new_value_sp)
793 log->Printf("SBValue(%p)::CreateValueFromData => \"%s\"",
794 static_cast<void *>(value_sp.get()),
795 new_value_sp->GetName().AsCString());
796 else
797 log->Printf("SBValue(%p)::CreateValueFromData => NULL",
798 static_cast<void *>(value_sp.get()));
799 }
800 return sb_value;
801}
802
803SBValue SBValue::GetChildAtIndex(uint32_t idx) {
804 const bool can_create_synthetic = false;
805 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
806 TargetSP target_sp;
807 if (m_opaque_sp)
808 target_sp = m_opaque_sp->GetTargetSP();
809
810 if (target_sp)
811 use_dynamic = target_sp->GetPreferDynamicValue();
812
813 return GetChildAtIndex(idx, use_dynamic, can_create_synthetic);
814}
815
816SBValue SBValue::GetChildAtIndex(uint32_t idx,
817 lldb::DynamicValueType use_dynamic,
818 bool can_create_synthetic) {
819 lldb::ValueObjectSP child_sp;
820 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
821
822 ValueLocker locker;
823 lldb::ValueObjectSP value_sp(GetSP(locker));
824 if (value_sp) {
825 const bool can_create = true;
826 child_sp = value_sp->GetChildAtIndex(idx, can_create);
827 if (can_create_synthetic && !child_sp) {
828 child_sp = value_sp->GetSyntheticArrayMember(idx, can_create);
Greg Claytonfe42ac42011-08-03 22:57:10 +0000829 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000830 }
831
832 SBValue sb_value;
833 sb_value.SetSP(child_sp, use_dynamic, GetPreferSyntheticValue());
834 if (log)
835 log->Printf("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)",
836 static_cast<void *>(value_sp.get()), idx,
837 static_cast<void *>(value_sp.get()));
838
839 return sb_value;
Greg Claytonfe42ac42011-08-03 22:57:10 +0000840}
841
Kate Stoneb9c1b512016-09-06 20:57:50 +0000842uint32_t SBValue::GetIndexOfChildWithName(const char *name) {
843 uint32_t idx = UINT32_MAX;
844 ValueLocker locker;
845 lldb::ValueObjectSP value_sp(GetSP(locker));
846 if (value_sp) {
847 idx = value_sp->GetIndexOfChildWithName(ConstString(name));
848 }
849 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
850 if (log) {
851 if (idx == UINT32_MAX)
852 log->Printf(
853 "SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND",
854 static_cast<void *>(value_sp.get()), name);
855 else
856 log->Printf("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u",
857 static_cast<void *>(value_sp.get()), name, idx);
858 }
859 return idx;
Greg Claytonfe42ac42011-08-03 22:57:10 +0000860}
861
Kate Stoneb9c1b512016-09-06 20:57:50 +0000862SBValue SBValue::GetChildMemberWithName(const char *name) {
863 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
864 TargetSP target_sp;
865 if (m_opaque_sp)
866 target_sp = m_opaque_sp->GetTargetSP();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000867
Kate Stoneb9c1b512016-09-06 20:57:50 +0000868 if (target_sp)
869 use_dynamic_value = target_sp->GetPreferDynamicValue();
870 return GetChildMemberWithName(name, use_dynamic_value);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000871}
872
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000873SBValue
Kate Stoneb9c1b512016-09-06 20:57:50 +0000874SBValue::GetChildMemberWithName(const char *name,
875 lldb::DynamicValueType use_dynamic_value) {
876 lldb::ValueObjectSP child_sp;
877 const ConstString str_name(name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000878
Kate Stoneb9c1b512016-09-06 20:57:50 +0000879 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
880
881 ValueLocker locker;
882 lldb::ValueObjectSP value_sp(GetSP(locker));
883 if (value_sp) {
884 child_sp = value_sp->GetChildMemberWithName(str_name, true);
885 }
886
887 SBValue sb_value;
888 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
889
890 if (log)
891 log->Printf(
892 "SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)",
893 static_cast<void *>(value_sp.get()), name,
894 static_cast<void *>(value_sp.get()));
895
896 return sb_value;
897}
898
899lldb::SBValue SBValue::GetDynamicValue(lldb::DynamicValueType use_dynamic) {
900 SBValue value_sb;
901 if (IsValid()) {
902 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(), use_dynamic,
903 m_opaque_sp->GetUseSynthetic()));
904 value_sb.SetSP(proxy_sp);
905 }
906 return value_sb;
907}
908
909lldb::SBValue SBValue::GetStaticValue() {
910 SBValue value_sb;
911 if (IsValid()) {
912 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),
913 eNoDynamicValues,
914 m_opaque_sp->GetUseSynthetic()));
915 value_sb.SetSP(proxy_sp);
916 }
917 return value_sb;
918}
919
920lldb::SBValue SBValue::GetNonSyntheticValue() {
921 SBValue value_sb;
922 if (IsValid()) {
923 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),
924 m_opaque_sp->GetUseDynamic(), false));
925 value_sb.SetSP(proxy_sp);
926 }
927 return value_sb;
928}
929
930lldb::DynamicValueType SBValue::GetPreferDynamicValue() {
931 if (!IsValid())
932 return eNoDynamicValues;
933 return m_opaque_sp->GetUseDynamic();
934}
935
936void SBValue::SetPreferDynamicValue(lldb::DynamicValueType use_dynamic) {
937 if (IsValid())
938 return m_opaque_sp->SetUseDynamic(use_dynamic);
939}
940
941bool SBValue::GetPreferSyntheticValue() {
942 if (!IsValid())
943 return false;
944 return m_opaque_sp->GetUseSynthetic();
945}
946
947void SBValue::SetPreferSyntheticValue(bool use_synthetic) {
948 if (IsValid())
949 return m_opaque_sp->SetUseSynthetic(use_synthetic);
950}
951
952bool SBValue::IsDynamic() {
953 ValueLocker locker;
954 lldb::ValueObjectSP value_sp(GetSP(locker));
955 if (value_sp)
956 return value_sp->IsDynamic();
957 return false;
958}
959
960bool SBValue::IsSynthetic() {
961 ValueLocker locker;
962 lldb::ValueObjectSP value_sp(GetSP(locker));
963 if (value_sp)
964 return value_sp->IsSynthetic();
965 return false;
966}
967
968bool SBValue::IsSyntheticChildrenGenerated() {
969 ValueLocker locker;
970 lldb::ValueObjectSP value_sp(GetSP(locker));
971 if (value_sp)
972 return value_sp->IsSyntheticChildrenGenerated();
973 return false;
974}
975
976void SBValue::SetSyntheticChildrenGenerated(bool is) {
977 ValueLocker locker;
978 lldb::ValueObjectSP value_sp(GetSP(locker));
979 if (value_sp)
980 return value_sp->SetSyntheticChildrenGenerated(is);
981}
982
983lldb::SBValue SBValue::GetValueForExpressionPath(const char *expr_path) {
984 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
985 lldb::ValueObjectSP child_sp;
986 ValueLocker locker;
987 lldb::ValueObjectSP value_sp(GetSP(locker));
988 if (value_sp) {
989 // using default values for all the fancy options, just do it if you can
990 child_sp = value_sp->GetValueForExpressionPath(expr_path);
991 }
992
993 SBValue sb_value;
994 sb_value.SetSP(child_sp, GetPreferDynamicValue(), GetPreferSyntheticValue());
995
996 if (log)
997 log->Printf("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => "
998 "SBValue(%p)",
999 static_cast<void *>(value_sp.get()), expr_path,
1000 static_cast<void *>(value_sp.get()));
1001
1002 return sb_value;
1003}
1004
1005int64_t SBValue::GetValueAsSigned(SBError &error, int64_t fail_value) {
1006 error.Clear();
1007 ValueLocker locker;
1008 lldb::ValueObjectSP value_sp(GetSP(locker));
1009 if (value_sp) {
1010 bool success = true;
1011 uint64_t ret_val = fail_value;
1012 ret_val = value_sp->GetValueAsSigned(fail_value, &success);
1013 if (!success)
1014 error.SetErrorString("could not resolve value");
1015 return ret_val;
1016 } else
1017 error.SetErrorStringWithFormat("could not get SBValue: %s",
1018 locker.GetError().AsCString());
1019
1020 return fail_value;
1021}
1022
1023uint64_t SBValue::GetValueAsUnsigned(SBError &error, uint64_t fail_value) {
1024 error.Clear();
1025 ValueLocker locker;
1026 lldb::ValueObjectSP value_sp(GetSP(locker));
1027 if (value_sp) {
1028 bool success = true;
1029 uint64_t ret_val = fail_value;
1030 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
1031 if (!success)
1032 error.SetErrorString("could not resolve value");
1033 return ret_val;
1034 } else
1035 error.SetErrorStringWithFormat("could not get SBValue: %s",
1036 locker.GetError().AsCString());
1037
1038 return fail_value;
1039}
1040
1041int64_t SBValue::GetValueAsSigned(int64_t fail_value) {
1042 ValueLocker locker;
1043 lldb::ValueObjectSP value_sp(GetSP(locker));
1044 if (value_sp) {
1045 return value_sp->GetValueAsSigned(fail_value);
1046 }
1047 return fail_value;
1048}
1049
1050uint64_t SBValue::GetValueAsUnsigned(uint64_t fail_value) {
1051 ValueLocker locker;
1052 lldb::ValueObjectSP value_sp(GetSP(locker));
1053 if (value_sp) {
1054 return value_sp->GetValueAsUnsigned(fail_value);
1055 }
1056 return fail_value;
1057}
1058
1059bool SBValue::MightHaveChildren() {
1060 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1061 bool has_children = false;
1062 ValueLocker locker;
1063 lldb::ValueObjectSP value_sp(GetSP(locker));
1064 if (value_sp)
1065 has_children = value_sp->MightHaveChildren();
1066
1067 if (log)
1068 log->Printf("SBValue(%p)::MightHaveChildren() => %i",
1069 static_cast<void *>(value_sp.get()), has_children);
1070 return has_children;
1071}
1072
1073bool SBValue::IsRuntimeSupportValue() {
1074 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1075 bool is_support = false;
1076 ValueLocker locker;
1077 lldb::ValueObjectSP value_sp(GetSP(locker));
1078 if (value_sp)
1079 is_support = value_sp->IsRuntimeSupportValue();
1080
1081 if (log)
1082 log->Printf("SBValue(%p)::IsRuntimeSupportValue() => %i",
1083 static_cast<void *>(value_sp.get()), is_support);
1084 return is_support;
1085}
1086
1087uint32_t SBValue::GetNumChildren() { return GetNumChildren(UINT32_MAX); }
1088
1089uint32_t SBValue::GetNumChildren(uint32_t max) {
1090 uint32_t num_children = 0;
1091
1092 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1093 ValueLocker locker;
1094 lldb::ValueObjectSP value_sp(GetSP(locker));
1095 if (value_sp)
1096 num_children = value_sp->GetNumChildren(max);
1097
1098 if (log)
1099 log->Printf("SBValue(%p)::GetNumChildren (%u) => %u",
1100 static_cast<void *>(value_sp.get()), max, num_children);
1101
1102 return num_children;
1103}
1104
1105SBValue SBValue::Dereference() {
1106 SBValue sb_value;
1107 ValueLocker locker;
1108 lldb::ValueObjectSP value_sp(GetSP(locker));
1109 if (value_sp) {
Zachary Turner97206d52017-05-12 04:51:55 +00001110 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001111 sb_value = value_sp->Dereference(error);
1112 }
1113 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1114 if (log)
1115 log->Printf("SBValue(%p)::Dereference () => SBValue(%p)",
1116 static_cast<void *>(value_sp.get()),
1117 static_cast<void *>(value_sp.get()));
1118
1119 return sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001120}
1121
Chaoren Lin4630de82015-07-27 21:51:56 +00001122// Deprecated - please use GetType().IsPointerType() instead.
Kate Stoneb9c1b512016-09-06 20:57:50 +00001123bool SBValue::TypeIsPointerType() { return GetType().IsPointerType(); }
1124
1125void *SBValue::GetOpaqueType() {
1126 ValueLocker locker;
1127 lldb::ValueObjectSP value_sp(GetSP(locker));
1128 if (value_sp)
1129 return value_sp->GetCompilerType().GetOpaqueQualType();
1130 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001131}
1132
Kate Stoneb9c1b512016-09-06 20:57:50 +00001133lldb::SBTarget SBValue::GetTarget() {
1134 SBTarget sb_target;
1135 TargetSP target_sp;
1136 if (m_opaque_sp) {
1137 target_sp = m_opaque_sp->GetTargetSP();
1138 sb_target.SetSP(target_sp);
1139 }
1140 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1141 if (log) {
1142 if (target_sp.get() == NULL)
1143 log->Printf("SBValue(%p)::GetTarget () => NULL",
1144 static_cast<void *>(m_opaque_sp.get()));
Enrico Granatae3e91512012-10-22 18:18:36 +00001145 else
Kate Stoneb9c1b512016-09-06 20:57:50 +00001146 log->Printf("SBValue(%p)::GetTarget () => %p",
1147 static_cast<void *>(m_opaque_sp.get()),
1148 static_cast<void *>(target_sp.get()));
1149 }
1150 return sb_target;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001151}
Caroline Ticedde9cff2010-09-20 05:20:02 +00001152
Kate Stoneb9c1b512016-09-06 20:57:50 +00001153lldb::SBProcess SBValue::GetProcess() {
1154 SBProcess sb_process;
1155 ProcessSP process_sp;
1156 if (m_opaque_sp) {
1157 process_sp = m_opaque_sp->GetProcessSP();
1158 sb_process.SetSP(process_sp);
1159 }
1160 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1161 if (log) {
1162 if (process_sp.get() == NULL)
1163 log->Printf("SBValue(%p)::GetProcess () => NULL",
1164 static_cast<void *>(m_opaque_sp.get()));
Enrico Granatae3e91512012-10-22 18:18:36 +00001165 else
Kate Stoneb9c1b512016-09-06 20:57:50 +00001166 log->Printf("SBValue(%p)::GetProcess () => %p",
1167 static_cast<void *>(m_opaque_sp.get()),
1168 static_cast<void *>(process_sp.get()));
1169 }
1170 return sb_process;
Enrico Granatae3e91512012-10-22 18:18:36 +00001171}
1172
Kate Stoneb9c1b512016-09-06 20:57:50 +00001173lldb::SBThread SBValue::GetThread() {
1174 SBThread sb_thread;
1175 ThreadSP thread_sp;
1176 if (m_opaque_sp) {
1177 thread_sp = m_opaque_sp->GetThreadSP();
1178 sb_thread.SetThread(thread_sp);
1179 }
1180 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1181 if (log) {
1182 if (thread_sp.get() == NULL)
1183 log->Printf("SBValue(%p)::GetThread () => NULL",
1184 static_cast<void *>(m_opaque_sp.get()));
Enrico Granatae3e91512012-10-22 18:18:36 +00001185 else
Kate Stoneb9c1b512016-09-06 20:57:50 +00001186 log->Printf("SBValue(%p)::GetThread () => %p",
1187 static_cast<void *>(m_opaque_sp.get()),
1188 static_cast<void *>(thread_sp.get()));
1189 }
1190 return sb_thread;
Enrico Granatae3e91512012-10-22 18:18:36 +00001191}
1192
Kate Stoneb9c1b512016-09-06 20:57:50 +00001193lldb::SBFrame SBValue::GetFrame() {
1194 SBFrame sb_frame;
1195 StackFrameSP frame_sp;
1196 if (m_opaque_sp) {
1197 frame_sp = m_opaque_sp->GetFrameSP();
1198 sb_frame.SetFrameSP(frame_sp);
1199 }
1200 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1201 if (log) {
1202 if (frame_sp.get() == NULL)
1203 log->Printf("SBValue(%p)::GetFrame () => NULL",
1204 static_cast<void *>(m_opaque_sp.get()));
Caroline Ticedde9cff2010-09-20 05:20:02 +00001205 else
Kate Stoneb9c1b512016-09-06 20:57:50 +00001206 log->Printf("SBValue(%p)::GetFrame () => %p",
1207 static_cast<void *>(m_opaque_sp.get()),
1208 static_cast<void *>(frame_sp.get()));
1209 }
1210 return sb_frame;
1211}
1212
1213lldb::ValueObjectSP SBValue::GetSP(ValueLocker &locker) const {
1214 if (!m_opaque_sp || !m_opaque_sp->IsValid()) {
1215 locker.GetError().SetErrorString("No value");
1216 return ValueObjectSP();
1217 }
1218 return locker.GetLockedSP(*m_opaque_sp.get());
1219}
1220
1221lldb::ValueObjectSP SBValue::GetSP() const {
1222 ValueLocker locker;
1223 return GetSP(locker);
1224}
1225
1226void SBValue::SetSP(ValueImplSP impl_sp) { m_opaque_sp = impl_sp; }
1227
1228void SBValue::SetSP(const lldb::ValueObjectSP &sp) {
1229 if (sp) {
1230 lldb::TargetSP target_sp(sp->GetTargetSP());
1231 if (target_sp) {
1232 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1233 bool use_synthetic =
1234 target_sp->TargetProperties::GetEnableSyntheticValue();
1235 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1236 } else
1237 m_opaque_sp = ValueImplSP(new ValueImpl(sp, eNoDynamicValues, true));
1238 } else
1239 m_opaque_sp = ValueImplSP(new ValueImpl(sp, eNoDynamicValues, false));
1240}
1241
1242void SBValue::SetSP(const lldb::ValueObjectSP &sp,
1243 lldb::DynamicValueType use_dynamic) {
1244 if (sp) {
1245 lldb::TargetSP target_sp(sp->GetTargetSP());
1246 if (target_sp) {
1247 bool use_synthetic =
1248 target_sp->TargetProperties::GetEnableSyntheticValue();
1249 SetSP(sp, use_dynamic, use_synthetic);
1250 } else
1251 SetSP(sp, use_dynamic, true);
1252 } else
1253 SetSP(sp, use_dynamic, false);
1254}
1255
1256void SBValue::SetSP(const lldb::ValueObjectSP &sp, bool use_synthetic) {
1257 if (sp) {
1258 lldb::TargetSP target_sp(sp->GetTargetSP());
1259 if (target_sp) {
1260 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1261 SetSP(sp, use_dynamic, use_synthetic);
1262 } else
1263 SetSP(sp, eNoDynamicValues, use_synthetic);
1264 } else
1265 SetSP(sp, eNoDynamicValues, use_synthetic);
1266}
1267
1268void SBValue::SetSP(const lldb::ValueObjectSP &sp,
1269 lldb::DynamicValueType use_dynamic, bool use_synthetic) {
1270 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1271}
1272
1273void SBValue::SetSP(const lldb::ValueObjectSP &sp,
1274 lldb::DynamicValueType use_dynamic, bool use_synthetic,
1275 const char *name) {
1276 m_opaque_sp =
1277 ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic, name));
1278}
1279
1280bool SBValue::GetExpressionPath(SBStream &description) {
1281 ValueLocker locker;
1282 lldb::ValueObjectSP value_sp(GetSP(locker));
1283 if (value_sp) {
1284 value_sp->GetExpressionPath(description.ref(), false);
Caroline Ticedde9cff2010-09-20 05:20:02 +00001285 return true;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001286 }
1287 return false;
Caroline Ticedde9cff2010-09-20 05:20:02 +00001288}
Greg Claytondc4e9632011-01-05 18:43:15 +00001289
Kate Stoneb9c1b512016-09-06 20:57:50 +00001290bool SBValue::GetExpressionPath(SBStream &description,
1291 bool qualify_cxx_base_classes) {
1292 ValueLocker locker;
1293 lldb::ValueObjectSP value_sp(GetSP(locker));
1294 if (value_sp) {
1295 value_sp->GetExpressionPath(description.ref(), qualify_cxx_base_classes);
1296 return true;
1297 }
1298 return false;
Greg Claytondc4e9632011-01-05 18:43:15 +00001299}
1300
Kate Stoneb9c1b512016-09-06 20:57:50 +00001301bool SBValue::GetDescription(SBStream &description) {
1302 Stream &strm = description.ref();
1303
1304 ValueLocker locker;
1305 lldb::ValueObjectSP value_sp(GetSP(locker));
1306 if (value_sp)
1307 value_sp->Dump(strm);
1308 else
1309 strm.PutCString("No value");
1310
1311 return true;
Greg Claytondc4e9632011-01-05 18:43:15 +00001312}
1313
Kate Stoneb9c1b512016-09-06 20:57:50 +00001314lldb::Format SBValue::GetFormat() {
1315 ValueLocker locker;
1316 lldb::ValueObjectSP value_sp(GetSP(locker));
1317 if (value_sp)
1318 return value_sp->GetFormat();
1319 return eFormatDefault;
Johnny Chen4a871f92011-08-09 22:38:07 +00001320}
Enrico Granata9128ee22011-09-06 19:20:51 +00001321
Kate Stoneb9c1b512016-09-06 20:57:50 +00001322void SBValue::SetFormat(lldb::Format format) {
1323 ValueLocker locker;
1324 lldb::ValueObjectSP value_sp(GetSP(locker));
1325 if (value_sp)
1326 value_sp->SetFormat(format);
1327}
1328
1329lldb::SBValue SBValue::AddressOf() {
1330 SBValue sb_value;
1331 ValueLocker locker;
1332 lldb::ValueObjectSP value_sp(GetSP(locker));
1333 if (value_sp) {
Zachary Turner97206d52017-05-12 04:51:55 +00001334 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001335 sb_value.SetSP(value_sp->AddressOf(error), GetPreferDynamicValue(),
1336 GetPreferSyntheticValue());
1337 }
1338 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1339 if (log)
1340 log->Printf("SBValue(%p)::AddressOf () => SBValue(%p)",
1341 static_cast<void *>(value_sp.get()),
1342 static_cast<void *>(value_sp.get()));
1343
1344 return sb_value;
1345}
1346
1347lldb::addr_t SBValue::GetLoadAddress() {
1348 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1349 ValueLocker locker;
1350 lldb::ValueObjectSP value_sp(GetSP(locker));
1351 if (value_sp) {
1352 TargetSP target_sp(value_sp->GetTargetSP());
1353 if (target_sp) {
1354 const bool scalar_is_load_address = true;
1355 AddressType addr_type;
1356 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1357 if (addr_type == eAddressTypeFile) {
1358 ModuleSP module_sp(value_sp->GetModule());
1359 if (!module_sp)
1360 value = LLDB_INVALID_ADDRESS;
1361 else {
1362 Address addr;
1363 module_sp->ResolveFileAddress(value, addr);
1364 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001365 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001366 } else if (addr_type == eAddressTypeHost ||
1367 addr_type == eAddressTypeInvalid)
1368 value = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001369 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001370 }
1371 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1372 if (log)
1373 log->Printf("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")",
1374 static_cast<void *>(value_sp.get()), value);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001375
Kate Stoneb9c1b512016-09-06 20:57:50 +00001376 return value;
Enrico Granata9128ee22011-09-06 19:20:51 +00001377}
1378
Kate Stoneb9c1b512016-09-06 20:57:50 +00001379lldb::SBAddress SBValue::GetAddress() {
1380 Address addr;
1381 ValueLocker locker;
1382 lldb::ValueObjectSP value_sp(GetSP(locker));
1383 if (value_sp) {
1384 TargetSP target_sp(value_sp->GetTargetSP());
1385 if (target_sp) {
1386 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1387 const bool scalar_is_load_address = true;
1388 AddressType addr_type;
1389 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1390 if (addr_type == eAddressTypeFile) {
1391 ModuleSP module_sp(value_sp->GetModule());
1392 if (module_sp)
1393 module_sp->ResolveFileAddress(value, addr);
1394 } else if (addr_type == eAddressTypeLoad) {
Adrian Prantl05097242018-04-30 16:49:04 +00001395 // no need to check the return value on this.. if it can actually do
1396 // the resolve addr will be in the form (section,offset), otherwise it
1397 // will simply be returned as (NULL, value)
Kate Stoneb9c1b512016-09-06 20:57:50 +00001398 addr.SetLoadAddress(value, target_sp.get());
1399 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001400 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001401 }
1402 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1403 if (log)
1404 log->Printf("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")",
1405 static_cast<void *>(value_sp.get()),
1406 (addr.GetSection() ? addr.GetSection()->GetName().GetCString()
1407 : "NULL"),
1408 addr.GetOffset());
1409 return SBAddress(new Address(addr));
Enrico Granata9128ee22011-09-06 19:20:51 +00001410}
1411
Kate Stoneb9c1b512016-09-06 20:57:50 +00001412lldb::SBData SBValue::GetPointeeData(uint32_t item_idx, uint32_t item_count) {
1413 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1414 lldb::SBData sb_data;
1415 ValueLocker locker;
1416 lldb::ValueObjectSP value_sp(GetSP(locker));
1417 if (value_sp) {
1418 TargetSP target_sp(value_sp->GetTargetSP());
1419 if (target_sp) {
1420 DataExtractorSP data_sp(new DataExtractor());
1421 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1422 if (data_sp->GetByteSize() > 0)
1423 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001424 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001425 }
1426 if (log)
1427 log->Printf("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
1428 static_cast<void *>(value_sp.get()), item_idx, item_count,
1429 static_cast<void *>(sb_data.get()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001430
Kate Stoneb9c1b512016-09-06 20:57:50 +00001431 return sb_data;
Enrico Granata9128ee22011-09-06 19:20:51 +00001432}
1433
Kate Stoneb9c1b512016-09-06 20:57:50 +00001434lldb::SBData SBValue::GetData() {
1435 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1436 lldb::SBData sb_data;
1437 ValueLocker locker;
1438 lldb::ValueObjectSP value_sp(GetSP(locker));
1439 if (value_sp) {
1440 DataExtractorSP data_sp(new DataExtractor());
Zachary Turner97206d52017-05-12 04:51:55 +00001441 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001442 value_sp->GetData(*data_sp, error);
1443 if (error.Success())
1444 *sb_data = data_sp;
1445 }
1446 if (log)
1447 log->Printf("SBValue(%p)::GetData () => SBData(%p)",
1448 static_cast<void *>(value_sp.get()),
1449 static_cast<void *>(sb_data.get()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001450
Kate Stoneb9c1b512016-09-06 20:57:50 +00001451 return sb_data;
Enrico Granata9128ee22011-09-06 19:20:51 +00001452}
Greg Clayton1b282f92011-10-13 18:08:26 +00001453
Kate Stoneb9c1b512016-09-06 20:57:50 +00001454bool SBValue::SetData(lldb::SBData &data, SBError &error) {
1455 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1456 ValueLocker locker;
1457 lldb::ValueObjectSP value_sp(GetSP(locker));
1458 bool ret = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001459
Kate Stoneb9c1b512016-09-06 20:57:50 +00001460 if (value_sp) {
1461 DataExtractor *data_extractor = data.get();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001462
Kate Stoneb9c1b512016-09-06 20:57:50 +00001463 if (!data_extractor) {
1464 if (log)
1465 log->Printf("SBValue(%p)::SetData() => error: no data to set",
1466 static_cast<void *>(value_sp.get()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001467
Kate Stoneb9c1b512016-09-06 20:57:50 +00001468 error.SetErrorString("No data to set");
1469 ret = false;
1470 } else {
Zachary Turner97206d52017-05-12 04:51:55 +00001471 Status set_error;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001472
Kate Stoneb9c1b512016-09-06 20:57:50 +00001473 value_sp->SetData(*data_extractor, set_error);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001474
Kate Stoneb9c1b512016-09-06 20:57:50 +00001475 if (!set_error.Success()) {
1476 error.SetErrorStringWithFormat("Couldn't set data: %s",
1477 set_error.AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001478 ret = false;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001479 }
Sean Callanan389823e2013-04-13 01:21:23 +00001480 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001481 } else {
1482 error.SetErrorStringWithFormat(
1483 "Couldn't set data: could not get SBValue: %s",
1484 locker.GetError().AsCString());
1485 ret = false;
1486 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001487
Kate Stoneb9c1b512016-09-06 20:57:50 +00001488 if (log)
1489 log->Printf("SBValue(%p)::SetData (%p) => %s",
1490 static_cast<void *>(value_sp.get()),
1491 static_cast<void *>(data.get()), ret ? "true" : "false");
1492 return ret;
Sean Callanan389823e2013-04-13 01:21:23 +00001493}
1494
Kate Stoneb9c1b512016-09-06 20:57:50 +00001495lldb::SBDeclaration SBValue::GetDeclaration() {
1496 ValueLocker locker;
1497 lldb::ValueObjectSP value_sp(GetSP(locker));
1498 SBDeclaration decl_sb;
1499 if (value_sp) {
1500 Declaration decl;
1501 if (value_sp->GetDeclaration(decl))
1502 decl_sb.SetDeclaration(decl);
1503 }
1504 return decl_sb;
Enrico Granata10de0902012-10-10 22:54:17 +00001505}
1506
Kate Stoneb9c1b512016-09-06 20:57:50 +00001507lldb::SBWatchpoint SBValue::Watch(bool resolve_location, bool read, bool write,
1508 SBError &error) {
1509 SBWatchpoint sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001510
Kate Stoneb9c1b512016-09-06 20:57:50 +00001511 // If the SBValue is not valid, there's no point in even trying to watch it.
1512 ValueLocker locker;
1513 lldb::ValueObjectSP value_sp(GetSP(locker));
1514 TargetSP target_sp(GetTarget().GetSP());
1515 if (value_sp && target_sp) {
1516 // Read and Write cannot both be false.
1517 if (!read && !write)
1518 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001519
Kate Stoneb9c1b512016-09-06 20:57:50 +00001520 // If the value is not in scope, don't try and watch and invalid value
1521 if (!IsInScope())
1522 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001523
Kate Stoneb9c1b512016-09-06 20:57:50 +00001524 addr_t addr = GetLoadAddress();
1525 if (addr == LLDB_INVALID_ADDRESS)
1526 return sb_watchpoint;
1527 size_t byte_size = GetByteSize();
1528 if (byte_size == 0)
1529 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001530
Kate Stoneb9c1b512016-09-06 20:57:50 +00001531 uint32_t watch_type = 0;
1532 if (read)
1533 watch_type |= LLDB_WATCH_TYPE_READ;
1534 if (write)
1535 watch_type |= LLDB_WATCH_TYPE_WRITE;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001536
Zachary Turner97206d52017-05-12 04:51:55 +00001537 Status rc;
Kate Stoneb9c1b512016-09-06 20:57:50 +00001538 CompilerType type(value_sp->GetCompilerType());
1539 WatchpointSP watchpoint_sp =
1540 target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
1541 error.SetError(rc);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001542
Kate Stoneb9c1b512016-09-06 20:57:50 +00001543 if (watchpoint_sp) {
1544 sb_watchpoint.SetSP(watchpoint_sp);
1545 Declaration decl;
1546 if (value_sp->GetDeclaration(decl)) {
1547 if (decl.GetFile()) {
1548 StreamString ss;
1549 // True to show fullpath for declaration file.
1550 decl.DumpStopContext(&ss, true);
1551 watchpoint_sp->SetDeclInfo(ss.GetString());
Greg Clayton81e871e2012-02-04 02:27:34 +00001552 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001553 }
Greg Clayton1b282f92011-10-13 18:08:26 +00001554 }
Kate Stoneb9c1b512016-09-06 20:57:50 +00001555 } else if (target_sp) {
1556 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1557 if (log)
1558 log->Printf("SBValue(%p)::Watch() => error getting SBValue: %s",
1559 static_cast<void *>(value_sp.get()),
1560 locker.GetError().AsCString());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001561
Kate Stoneb9c1b512016-09-06 20:57:50 +00001562 error.SetErrorStringWithFormat("could not get SBValue: %s",
1563 locker.GetError().AsCString());
1564 } else {
1565 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1566 if (log)
1567 log->Printf("SBValue(%p)::Watch() => error getting SBValue: no target",
1568 static_cast<void *>(value_sp.get()));
1569 error.SetErrorString("could not set watchpoint, a target is required");
1570 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001571
Kate Stoneb9c1b512016-09-06 20:57:50 +00001572 return sb_watchpoint;
Greg Clayton1b282f92011-10-13 18:08:26 +00001573}
1574
Kate Stoneb9c1b512016-09-06 20:57:50 +00001575// FIXME: Remove this method impl (as well as the decl in .h) once it is no
1576// longer needed.
Johnny Chend3761a72012-06-04 23:45:50 +00001577// Backward compatibility fix in the interim.
Kate Stoneb9c1b512016-09-06 20:57:50 +00001578lldb::SBWatchpoint SBValue::Watch(bool resolve_location, bool read,
1579 bool write) {
1580 SBError error;
1581 return Watch(resolve_location, read, write, error);
Johnny Chend3761a72012-06-04 23:45:50 +00001582}
1583
Kate Stoneb9c1b512016-09-06 20:57:50 +00001584lldb::SBWatchpoint SBValue::WatchPointee(bool resolve_location, bool read,
1585 bool write, SBError &error) {
1586 SBWatchpoint sb_watchpoint;
1587 if (IsInScope() && GetType().IsPointerType())
1588 sb_watchpoint = Dereference().Watch(resolve_location, read, write, error);
1589 return sb_watchpoint;
Greg Clayton1b282f92011-10-13 18:08:26 +00001590}
Enrico Granata0c10a852014-12-08 23:13:56 +00001591
Kate Stoneb9c1b512016-09-06 20:57:50 +00001592lldb::SBValue SBValue::Persist() {
1593 ValueLocker locker;
1594 lldb::ValueObjectSP value_sp(GetSP(locker));
1595 SBValue persisted_sb;
1596 if (value_sp) {
1597 persisted_sb.SetSP(value_sp->Persist());
1598 }
1599 return persisted_sb;
Enrico Granata0c10a852014-12-08 23:13:56 +00001600}