]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/API/SBValue.cpp
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / source / API / SBValue.cpp
1 //===-- 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
10 #include "lldb/API/SBValue.h"
11
12 #include "lldb/API/SBDeclaration.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/API/SBTypeFilter.h"
15 #include "lldb/API/SBTypeFormat.h"
16 #include "lldb/API/SBTypeSummary.h"
17 #include "lldb/API/SBTypeSynthetic.h"
18
19 #include "lldb/Breakpoint/Watchpoint.h"
20 #include "lldb/Core/DataExtractor.h"
21 #include "lldb/Core/Log.h"
22 #include "lldb/Core/Module.h"
23 #include "lldb/Core/Scalar.h"
24 #include "lldb/Core/Section.h"
25 #include "lldb/Core/Stream.h"
26 #include "lldb/Core/StreamFile.h"
27 #include "lldb/Core/Value.h"
28 #include "lldb/Core/ValueObject.h"
29 #include "lldb/Core/ValueObjectConstResult.h"
30 #include "lldb/DataFormatters/DataVisualization.h"
31 #include "lldb/Symbol/Block.h"
32 #include "lldb/Symbol/Declaration.h"
33 #include "lldb/Symbol/ObjectFile.h"
34 #include "lldb/Symbol/Type.h"
35 #include "lldb/Symbol/Variable.h"
36 #include "lldb/Symbol/VariableList.h"
37 #include "lldb/Target/ExecutionContext.h"
38 #include "lldb/Target/Process.h"
39 #include "lldb/Target/StackFrame.h"
40 #include "lldb/Target/Target.h"
41 #include "lldb/Target/Thread.h"
42
43 #include "lldb/API/SBDebugger.h"
44 #include "lldb/API/SBExpressionOptions.h"
45 #include "lldb/API/SBFrame.h"
46 #include "lldb/API/SBProcess.h"
47 #include "lldb/API/SBTarget.h"
48 #include "lldb/API/SBThread.h"
49
50 using namespace lldb;
51 using namespace lldb_private;
52
53 class ValueImpl {
54 public:
55   ValueImpl() {}
56
57   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))) {
65         if (!m_name.IsEmpty())
66           m_valobj_sp->SetName(m_name);
67       }
68     }
69   }
70
71   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) {}
74
75   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;
81     }
82     return *this;
83   }
84
85   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   }
110
111   lldb::ValueObjectSP GetRootSP() { return m_valobj_sp; }
112
113   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     }
121
122     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();
181     else
182       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
206 private:
207   lldb::ValueObjectSP m_valobj_sp;
208   lldb::DynamicValueType m_use_dynamic;
209   bool m_use_synthetic;
210   ConstString m_name;
211 };
212
213 class ValueLocker {
214 public:
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
223 private:
224   Process::StopLocker m_stop_locker;
225   std::unique_lock<std::recursive_mutex> m_lock;
226   Error m_lock_error;
227 };
228
229 SBValue::SBValue() : m_opaque_sp() {}
230
231 SBValue::SBValue(const lldb::ValueObjectSP &value_sp) { SetSP(value_sp); }
232
233 SBValue::SBValue(const SBValue &rhs) { SetSP(rhs.m_opaque_sp); }
234
235 SBValue &SBValue::operator=(const SBValue &rhs) {
236   if (this != &rhs) {
237     SetSP(rhs.m_opaque_sp);
238   }
239   return *this;
240 }
241
242 SBValue::~SBValue() {}
243
244 bool 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;
250 }
251
252 void SBValue::Clear() { m_opaque_sp.reset(); }
253
254 SBError SBValue::GetError() {
255   SBError sb_error;
256
257   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;
266 }
267
268 user_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;
274 }
275
276 const 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;
294 }
295
296 const 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   }
304
305   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   }
313
314   return name;
315 }
316
317 const 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   }
325
326   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   }
334
335   return name;
336 }
337
338 size_t SBValue::GetByteSize() {
339   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
340   size_t result = 0;
341
342   ValueLocker locker;
343   lldb::ValueObjectSP value_sp(GetSP(locker));
344   if (value_sp) {
345     result = value_sp->GetByteSize();
346   }
347
348   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;
354 }
355
356 bool SBValue::IsInScope() {
357   bool result = false;
358
359   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;
371 }
372
373 const 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;
392 }
393
394 ValueType 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;
441     }
442   }
443   return result;
444 }
445
446 const 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;
463 }
464
465 const 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();
477     }
478   }
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;
488 }
489
490 SBType 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;
510 }
511
512 bool 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;
526 }
527
528 const 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
547 const 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
569 const 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;
586 }
587
588 // Deprecated - use the one that takes an lldb::SBError
589 bool SBValue::SetValueFromCString(const char *value_str) {
590   lldb::SBError dummy;
591   return SetValueFromCString(value_str, dummy);
592 }
593
594 bool 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());
604
605   if (log)
606     log->Printf("SBValue(%p)::SetValueFromCString(\"%s\") => %i",
607                 static_cast<void *>(value_sp.get()), value_str, success);
608
609   return success;
610 }
611
612 lldb::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);
621     }
622   }
623   return format;
624 }
625
626 lldb::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);
635     }
636   }
637   return summary;
638 }
639
640 lldb::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       }
653     }
654   }
655   return filter;
656 }
657
658 #ifndef LLDB_DISABLE_PYTHON
659 lldb::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       }
672     }
673   }
674   return synthetic;
675 }
676 #endif
677
678 lldb::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);
690     }
691   }
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());
698     else
699       log->Printf("SBValue(%p)::CreateChildAtOffset => NULL",
700                   static_cast<void *>(value_sp.get()));
701   }
702   return sb_value;
703 }
704
705 lldb::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
716 lldb::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
723 lldb::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()));
745     else
746       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;
751 }
752
753 lldb::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
781 lldb::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
808 SBValue 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
821 SBValue 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);
834     }
835   }
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;
845 }
846
847 uint32_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;
865 }
866
867 SBValue 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();
872
873   if (target_sp)
874     use_dynamic_value = target_sp->GetPreferDynamicValue();
875   return GetChildMemberWithName(name, use_dynamic_value);
876 }
877
878 SBValue
879 SBValue::GetChildMemberWithName(const char *name,
880                                 lldb::DynamicValueType use_dynamic_value) {
881   lldb::ValueObjectSP child_sp;
882   const ConstString str_name(name);
883
884   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
904 lldb::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
914 lldb::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
925 lldb::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
935 lldb::DynamicValueType SBValue::GetPreferDynamicValue() {
936   if (!IsValid())
937     return eNoDynamicValues;
938   return m_opaque_sp->GetUseDynamic();
939 }
940
941 void SBValue::SetPreferDynamicValue(lldb::DynamicValueType use_dynamic) {
942   if (IsValid())
943     return m_opaque_sp->SetUseDynamic(use_dynamic);
944 }
945
946 bool SBValue::GetPreferSyntheticValue() {
947   if (!IsValid())
948     return false;
949   return m_opaque_sp->GetUseSynthetic();
950 }
951
952 void SBValue::SetPreferSyntheticValue(bool use_synthetic) {
953   if (IsValid())
954     return m_opaque_sp->SetUseSynthetic(use_synthetic);
955 }
956
957 bool 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
965 bool 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
973 bool 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
981 void 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
988 lldb::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
1010 int64_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
1028 uint64_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
1046 int64_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
1055 uint64_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
1064 bool 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
1078 bool 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
1092 uint32_t SBValue::GetNumChildren() { return GetNumChildren(UINT32_MAX); }
1093
1094 uint32_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
1110 SBValue 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;
1125 }
1126
1127 // Deprecated - please use GetType().IsPointerType() instead.
1128 bool SBValue::TypeIsPointerType() { return GetType().IsPointerType(); }
1129
1130 void *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;
1136 }
1137
1138 lldb::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()));
1150     else
1151       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;
1156 }
1157
1158 lldb::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()));
1170     else
1171       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;
1176 }
1177
1178 lldb::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()));
1190     else
1191       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;
1196 }
1197
1198 lldb::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()));
1210     else
1211       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
1218 lldb::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
1226 lldb::ValueObjectSP SBValue::GetSP() const {
1227   ValueLocker locker;
1228   return GetSP(locker);
1229 }
1230
1231 void SBValue::SetSP(ValueImplSP impl_sp) { m_opaque_sp = impl_sp; }
1232
1233 void 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
1247 void 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
1261 void 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
1273 void 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
1278 void 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
1285 bool 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);
1290     return true;
1291   }
1292   return false;
1293 }
1294
1295 bool 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;
1304 }
1305
1306 bool 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;
1317 }
1318
1319 lldb::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;
1325 }
1326
1327 void 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
1334 lldb::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
1352 lldb::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());
1370         }
1371       } else if (addr_type == eAddressTypeHost ||
1372                  addr_type == eAddressTypeInvalid)
1373         value = LLDB_INVALID_ADDRESS;
1374     }
1375   }
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);
1380
1381   return value;
1382 }
1383
1384 lldb::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       }
1407     }
1408   }
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));
1417 }
1418
1419 lldb::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;
1431     }
1432   }
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()));
1437
1438   return sb_data;
1439 }
1440
1441 lldb::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()));
1457
1458   return sb_data;
1459 }
1460
1461 bool 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;
1466
1467   if (value_sp) {
1468     DataExtractor *data_extractor = data.get();
1469
1470     if (!data_extractor) {
1471       if (log)
1472         log->Printf("SBValue(%p)::SetData() => error: no data to set",
1473                     static_cast<void *>(value_sp.get()));
1474
1475       error.SetErrorString("No data to set");
1476       ret = false;
1477     } else {
1478       Error set_error;
1479
1480       value_sp->SetData(*data_extractor, set_error);
1481
1482       if (!set_error.Success()) {
1483         error.SetErrorStringWithFormat("Couldn't set data: %s",
1484                                        set_error.AsCString());
1485         ret = false;
1486       }
1487     }
1488   } else {
1489     error.SetErrorStringWithFormat(
1490         "Couldn't set data: could not get SBValue: %s",
1491         locker.GetError().AsCString());
1492     ret = false;
1493   }
1494
1495   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;
1500 }
1501
1502 lldb::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;
1512 }
1513
1514 lldb::SBWatchpoint SBValue::Watch(bool resolve_location, bool read, bool write,
1515                                   SBError &error) {
1516   SBWatchpoint sb_watchpoint;
1517
1518   // 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;
1526
1527     // If the value is not in scope, don't try and watch and invalid value
1528     if (!IsInScope())
1529       return sb_watchpoint;
1530
1531     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;
1537
1538     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;
1543
1544     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);
1549
1550     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());
1559         }
1560       }
1561     }
1562   } 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());
1568
1569     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   }
1578
1579   return sb_watchpoint;
1580 }
1581
1582 // FIXME: Remove this method impl (as well as the decl in .h) once it is no
1583 // longer needed.
1584 // Backward compatibility fix in the interim.
1585 lldb::SBWatchpoint SBValue::Watch(bool resolve_location, bool read,
1586                                   bool write) {
1587   SBError error;
1588   return Watch(resolve_location, read, write, error);
1589 }
1590
1591 lldb::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;
1597 }
1598
1599 lldb::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;
1607 }