xref: /src/contrib/llvm-project/lldb/source/API/SBValue.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1cfca06d7SDimitry Andric //===-- SBValue.cpp -------------------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste 
9f034231aSEd Maste #include "lldb/API/SBValue.h"
106f8fc217SDimitry Andric #include "lldb/Utility/Instrumentation.h"
11f034231aSEd Maste 
12f034231aSEd Maste #include "lldb/API/SBDeclaration.h"
13f034231aSEd Maste #include "lldb/API/SBStream.h"
14f034231aSEd Maste #include "lldb/API/SBTypeFilter.h"
15f034231aSEd Maste #include "lldb/API/SBTypeFormat.h"
16f034231aSEd Maste #include "lldb/API/SBTypeSummary.h"
17f034231aSEd Maste #include "lldb/API/SBTypeSynthetic.h"
18f034231aSEd Maste 
19f034231aSEd Maste #include "lldb/Breakpoint/Watchpoint.h"
20344a3780SDimitry Andric #include "lldb/Core/Declaration.h"
21f034231aSEd Maste #include "lldb/Core/Module.h"
22f034231aSEd Maste #include "lldb/Core/Section.h"
23f034231aSEd Maste #include "lldb/Core/Value.h"
24f034231aSEd Maste #include "lldb/Core/ValueObject.h"
25f034231aSEd Maste #include "lldb/Core/ValueObjectConstResult.h"
26f034231aSEd Maste #include "lldb/DataFormatters/DataVisualization.h"
2799aabd70SDimitry Andric #include "lldb/DataFormatters/DumpValueObjectOptions.h"
28f034231aSEd Maste #include "lldb/Symbol/Block.h"
29f034231aSEd Maste #include "lldb/Symbol/ObjectFile.h"
30f034231aSEd Maste #include "lldb/Symbol/Type.h"
31f034231aSEd Maste #include "lldb/Symbol/Variable.h"
32f034231aSEd Maste #include "lldb/Symbol/VariableList.h"
33f034231aSEd Maste #include "lldb/Target/ExecutionContext.h"
34f034231aSEd Maste #include "lldb/Target/Process.h"
35f034231aSEd Maste #include "lldb/Target/StackFrame.h"
36f034231aSEd Maste #include "lldb/Target/Target.h"
37f034231aSEd Maste #include "lldb/Target/Thread.h"
3874a628f7SDimitry Andric #include "lldb/Utility/DataExtractor.h"
3994994d37SDimitry Andric #include "lldb/Utility/Scalar.h"
4074a628f7SDimitry Andric #include "lldb/Utility/Stream.h"
41f034231aSEd Maste 
42f034231aSEd Maste #include "lldb/API/SBDebugger.h"
43f034231aSEd Maste #include "lldb/API/SBExpressionOptions.h"
44f034231aSEd Maste #include "lldb/API/SBFrame.h"
45f034231aSEd Maste #include "lldb/API/SBProcess.h"
46f034231aSEd Maste #include "lldb/API/SBTarget.h"
47f034231aSEd Maste #include "lldb/API/SBThread.h"
48f034231aSEd Maste 
495f29bb8aSDimitry Andric #include <memory>
505f29bb8aSDimitry Andric 
51f034231aSEd Maste using namespace lldb;
52f034231aSEd Maste using namespace lldb_private;
53f034231aSEd Maste 
5414f1b3e8SDimitry Andric class ValueImpl {
55f034231aSEd Maste public:
56cfca06d7SDimitry Andric   ValueImpl() = default;
57f034231aSEd Maste 
ValueImpl(lldb::ValueObjectSP in_valobj_sp,lldb::DynamicValueType use_dynamic,bool use_synthetic,const char * name=nullptr)58f034231aSEd Maste   ValueImpl(lldb::ValueObjectSP in_valobj_sp,
5914f1b3e8SDimitry Andric             lldb::DynamicValueType use_dynamic, bool use_synthetic,
605f29bb8aSDimitry Andric             const char *name = nullptr)
616f8fc217SDimitry Andric       : m_use_dynamic(use_dynamic), m_use_synthetic(use_synthetic),
626f8fc217SDimitry Andric         m_name(name) {
6314f1b3e8SDimitry Andric     if (in_valobj_sp) {
6414f1b3e8SDimitry Andric       if ((m_valobj_sp = in_valobj_sp->GetQualifiedRepresentationIfAvailable(
6514f1b3e8SDimitry Andric                lldb::eNoDynamicValues, false))) {
665e95aa85SEd Maste         if (!m_name.IsEmpty())
67f034231aSEd Maste           m_valobj_sp->SetName(m_name);
68f034231aSEd Maste       }
695e95aa85SEd Maste     }
705e95aa85SEd Maste   }
71f034231aSEd Maste 
72145449b1SDimitry Andric   ValueImpl(const ValueImpl &rhs) = default;
73f034231aSEd Maste 
operator =(const ValueImpl & rhs)7414f1b3e8SDimitry Andric   ValueImpl &operator=(const ValueImpl &rhs) {
7514f1b3e8SDimitry Andric     if (this != &rhs) {
76f034231aSEd Maste       m_valobj_sp = rhs.m_valobj_sp;
77f034231aSEd Maste       m_use_dynamic = rhs.m_use_dynamic;
78f034231aSEd Maste       m_use_synthetic = rhs.m_use_synthetic;
79f034231aSEd Maste       m_name = rhs.m_name;
80f034231aSEd Maste     }
81f034231aSEd Maste     return *this;
82f034231aSEd Maste   }
83f034231aSEd Maste 
IsValid()8414f1b3e8SDimitry Andric   bool IsValid() {
855f29bb8aSDimitry Andric     if (m_valobj_sp.get() == nullptr)
86866dcdacSEd Maste       return false;
8714f1b3e8SDimitry Andric     else {
8814f1b3e8SDimitry Andric       // FIXME: This check is necessary but not sufficient.  We for sure don't
8914f1b3e8SDimitry Andric       // want to touch SBValues whose owning
9014f1b3e8SDimitry Andric       // targets have gone away.  This check is a little weak in that it
91f73363f1SDimitry Andric       // enforces that restriction when you call IsValid, but since IsValid
92f73363f1SDimitry Andric       // doesn't lock the target, you have no guarantee that the SBValue won't
93f73363f1SDimitry Andric       // go invalid after you call this... Also, an SBValue could depend on
94f73363f1SDimitry Andric       // data from one of the modules in the target, and those could go away
95f73363f1SDimitry Andric       // independently of the target, for instance if a module is unloaded.
96f73363f1SDimitry Andric       // But right now, neither SBValues nor ValueObjects know which modules
97f73363f1SDimitry Andric       // they depend on.  So I have no good way to make that check without
98866dcdacSEd Maste       // tracking that in all the ValueObject subclasses.
99866dcdacSEd Maste       TargetSP target_sp = m_valobj_sp->GetTargetSP();
10094994d37SDimitry Andric       return target_sp && target_sp->IsValid();
101866dcdacSEd Maste     }
102f034231aSEd Maste   }
103f034231aSEd Maste 
GetRootSP()10414f1b3e8SDimitry Andric   lldb::ValueObjectSP GetRootSP() { return m_valobj_sp; }
105f034231aSEd Maste 
GetSP(Process::StopLocker & stop_locker,std::unique_lock<std::recursive_mutex> & lock,Status & error)10614f1b3e8SDimitry Andric   lldb::ValueObjectSP GetSP(Process::StopLocker &stop_locker,
10714f1b3e8SDimitry Andric                             std::unique_lock<std::recursive_mutex> &lock,
108b76161e4SDimitry Andric                             Status &error) {
10914f1b3e8SDimitry Andric     if (!m_valobj_sp) {
110f034231aSEd Maste       error.SetErrorString("invalid value object");
111f034231aSEd Maste       return m_valobj_sp;
112f034231aSEd Maste     }
113f034231aSEd Maste 
114f034231aSEd Maste     lldb::ValueObjectSP value_sp = m_valobj_sp;
115f034231aSEd Maste 
116f034231aSEd Maste     Target *target = value_sp->GetTargetSP().get();
1177fa27ce4SDimitry Andric     // If this ValueObject holds an error, then it is valuable for that.
1187fa27ce4SDimitry Andric     if (value_sp->GetError().Fail())
1197fa27ce4SDimitry Andric       return value_sp;
1207fa27ce4SDimitry Andric 
121f3fbd1c0SDimitry Andric     if (!target)
122866dcdacSEd Maste       return ValueObjectSP();
123f034231aSEd Maste 
124f3fbd1c0SDimitry Andric     lock = std::unique_lock<std::recursive_mutex>(target->GetAPIMutex());
125f3fbd1c0SDimitry Andric 
126f034231aSEd Maste     ProcessSP process_sp(value_sp->GetProcessSP());
12714f1b3e8SDimitry Andric     if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock())) {
128f73363f1SDimitry Andric       // We don't allow people to play around with ValueObject if the process
129f73363f1SDimitry Andric       // is running. If you want to look at values, pause the process, then
130f73363f1SDimitry Andric       // look.
131f034231aSEd Maste       error.SetErrorString("process must be stopped.");
132f034231aSEd Maste       return ValueObjectSP();
133f034231aSEd Maste     }
134f034231aSEd Maste 
13514f1b3e8SDimitry Andric     if (m_use_dynamic != eNoDynamicValues) {
1365e95aa85SEd Maste       ValueObjectSP dynamic_sp = value_sp->GetDynamicValue(m_use_dynamic);
1375e95aa85SEd Maste       if (dynamic_sp)
1385e95aa85SEd Maste         value_sp = dynamic_sp;
1395e95aa85SEd Maste     }
1405e95aa85SEd Maste 
14114f1b3e8SDimitry Andric     if (m_use_synthetic) {
142cfca06d7SDimitry Andric       ValueObjectSP synthetic_sp = value_sp->GetSyntheticValue();
1435e95aa85SEd Maste       if (synthetic_sp)
1445e95aa85SEd Maste         value_sp = synthetic_sp;
1455e95aa85SEd Maste     }
1465e95aa85SEd Maste 
147f034231aSEd Maste     if (!value_sp)
148f034231aSEd Maste       error.SetErrorString("invalid value object");
149f034231aSEd Maste     if (!m_name.IsEmpty())
150f034231aSEd Maste       value_sp->SetName(m_name);
151f034231aSEd Maste 
152f034231aSEd Maste     return value_sp;
153f034231aSEd Maste   }
154f034231aSEd Maste 
SetUseDynamic(lldb::DynamicValueType use_dynamic)15514f1b3e8SDimitry Andric   void SetUseDynamic(lldb::DynamicValueType use_dynamic) {
156f034231aSEd Maste     m_use_dynamic = use_dynamic;
157f034231aSEd Maste   }
158f034231aSEd Maste 
SetUseSynthetic(bool use_synthetic)15914f1b3e8SDimitry Andric   void SetUseSynthetic(bool use_synthetic) { m_use_synthetic = use_synthetic; }
160f034231aSEd Maste 
GetUseDynamic()16114f1b3e8SDimitry Andric   lldb::DynamicValueType GetUseDynamic() { return m_use_dynamic; }
162f034231aSEd Maste 
GetUseSynthetic()16314f1b3e8SDimitry Andric   bool GetUseSynthetic() { return m_use_synthetic; }
164f034231aSEd Maste 
165f034231aSEd Maste   // All the derived values that we would make from the m_valobj_sp will share
16614f1b3e8SDimitry Andric   // the ExecutionContext with m_valobj_sp, so we don't need to do the
167f73363f1SDimitry Andric   // calculations in GetSP to return the Target, Process, Thread or Frame.  It
168f73363f1SDimitry Andric   // is convenient to provide simple accessors for these, which I do here.
GetTargetSP()16914f1b3e8SDimitry Andric   TargetSP GetTargetSP() {
170f034231aSEd Maste     if (m_valobj_sp)
171f034231aSEd Maste       return m_valobj_sp->GetTargetSP();
172f034231aSEd Maste     else
173f034231aSEd Maste       return TargetSP();
174f034231aSEd Maste   }
175f034231aSEd Maste 
GetProcessSP()17614f1b3e8SDimitry Andric   ProcessSP GetProcessSP() {
177f034231aSEd Maste     if (m_valobj_sp)
178f034231aSEd Maste       return m_valobj_sp->GetProcessSP();
179f034231aSEd Maste     else
180f034231aSEd Maste       return ProcessSP();
181f034231aSEd Maste   }
182f034231aSEd Maste 
GetThreadSP()18314f1b3e8SDimitry Andric   ThreadSP GetThreadSP() {
184f034231aSEd Maste     if (m_valobj_sp)
185f034231aSEd Maste       return m_valobj_sp->GetThreadSP();
186f034231aSEd Maste     else
187f034231aSEd Maste       return ThreadSP();
188f034231aSEd Maste   }
189f034231aSEd Maste 
GetFrameSP()19014f1b3e8SDimitry Andric   StackFrameSP GetFrameSP() {
191f034231aSEd Maste     if (m_valobj_sp)
192f034231aSEd Maste       return m_valobj_sp->GetFrameSP();
193f034231aSEd Maste     else
194f034231aSEd Maste       return StackFrameSP();
195f034231aSEd Maste   }
196f034231aSEd Maste 
197f034231aSEd Maste private:
198f034231aSEd Maste   lldb::ValueObjectSP m_valobj_sp;
199f034231aSEd Maste   lldb::DynamicValueType m_use_dynamic;
200f034231aSEd Maste   bool m_use_synthetic;
201f034231aSEd Maste   ConstString m_name;
202f034231aSEd Maste };
203f034231aSEd Maste 
20414f1b3e8SDimitry Andric class ValueLocker {
205f034231aSEd Maste public:
206cfca06d7SDimitry Andric   ValueLocker() = default;
207f034231aSEd Maste 
GetLockedSP(ValueImpl & in_value)20814f1b3e8SDimitry Andric   ValueObjectSP GetLockedSP(ValueImpl &in_value) {
209f3fbd1c0SDimitry Andric     return in_value.GetSP(m_stop_locker, m_lock, m_lock_error);
210f034231aSEd Maste   }
211f034231aSEd Maste 
GetError()212b76161e4SDimitry Andric   Status &GetError() { return m_lock_error; }
213f034231aSEd Maste 
214f034231aSEd Maste private:
215f034231aSEd Maste   Process::StopLocker m_stop_locker;
216f3fbd1c0SDimitry Andric   std::unique_lock<std::recursive_mutex> m_lock;
217b76161e4SDimitry Andric   Status m_lock_error;
218f034231aSEd Maste };
219f034231aSEd Maste 
SBValue()2206f8fc217SDimitry Andric SBValue::SBValue() { LLDB_INSTRUMENT_VA(this); }
221f034231aSEd Maste 
SBValue(const lldb::ValueObjectSP & value_sp)2225f29bb8aSDimitry Andric SBValue::SBValue(const lldb::ValueObjectSP &value_sp) {
2236f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, value_sp);
224f034231aSEd Maste 
2255f29bb8aSDimitry Andric   SetSP(value_sp);
2265f29bb8aSDimitry Andric }
2275f29bb8aSDimitry Andric 
SBValue(const SBValue & rhs)2285f29bb8aSDimitry Andric SBValue::SBValue(const SBValue &rhs) {
2296f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
2305f29bb8aSDimitry Andric 
2315f29bb8aSDimitry Andric   SetSP(rhs.m_opaque_sp);
2325f29bb8aSDimitry Andric }
233f034231aSEd Maste 
operator =(const SBValue & rhs)23414f1b3e8SDimitry Andric SBValue &SBValue::operator=(const SBValue &rhs) {
2356f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
2365f29bb8aSDimitry Andric 
23714f1b3e8SDimitry Andric   if (this != &rhs) {
238f034231aSEd Maste     SetSP(rhs.m_opaque_sp);
239f034231aSEd Maste   }
2406f8fc217SDimitry Andric   return *this;
241f034231aSEd Maste }
242f034231aSEd Maste 
243cfca06d7SDimitry Andric SBValue::~SBValue() = default;
244f034231aSEd Maste 
IsValid()24514f1b3e8SDimitry Andric bool SBValue::IsValid() {
2466f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
2475f29bb8aSDimitry Andric   return this->operator bool();
2485f29bb8aSDimitry Andric }
operator bool() const2495f29bb8aSDimitry Andric SBValue::operator bool() const {
2506f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
2515f29bb8aSDimitry Andric 
252f73363f1SDimitry Andric   // If this function ever changes to anything that does more than just check
253f73363f1SDimitry Andric   // if the opaque shared pointer is non NULL, then we need to update all "if
254f73363f1SDimitry Andric   // (m_opaque_sp)" code in this file.
2555f29bb8aSDimitry Andric   return m_opaque_sp.get() != nullptr && m_opaque_sp->IsValid() &&
2565f29bb8aSDimitry Andric          m_opaque_sp->GetRootSP().get() != nullptr;
257f034231aSEd Maste }
258f034231aSEd Maste 
Clear()2595f29bb8aSDimitry Andric void SBValue::Clear() {
2606f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
2615f29bb8aSDimitry Andric 
2625f29bb8aSDimitry Andric   m_opaque_sp.reset();
2635f29bb8aSDimitry Andric }
264f034231aSEd Maste 
GetError()26514f1b3e8SDimitry Andric SBError SBValue::GetError() {
2666f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
2675f29bb8aSDimitry Andric 
268f034231aSEd Maste   SBError sb_error;
269f034231aSEd Maste 
270f034231aSEd Maste   ValueLocker locker;
271f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
272f034231aSEd Maste   if (value_sp)
273f034231aSEd Maste     sb_error.SetError(value_sp->GetError());
274f034231aSEd Maste   else
27514f1b3e8SDimitry Andric     sb_error.SetErrorStringWithFormat("error: %s",
27614f1b3e8SDimitry Andric                                       locker.GetError().AsCString());
277f034231aSEd Maste 
2786f8fc217SDimitry Andric   return sb_error;
279f034231aSEd Maste }
280f034231aSEd Maste 
GetID()28114f1b3e8SDimitry Andric user_id_t SBValue::GetID() {
2826f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
2835f29bb8aSDimitry Andric 
284f034231aSEd Maste   ValueLocker locker;
285f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
286f034231aSEd Maste   if (value_sp)
287f034231aSEd Maste     return value_sp->GetID();
288f034231aSEd Maste   return LLDB_INVALID_UID;
289f034231aSEd Maste }
290f034231aSEd Maste 
GetName()29114f1b3e8SDimitry Andric const char *SBValue::GetName() {
2926f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
2935f29bb8aSDimitry Andric 
294f034231aSEd Maste   ValueLocker locker;
295f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
2967fa27ce4SDimitry Andric   if (!value_sp)
2977fa27ce4SDimitry Andric     return nullptr;
298f034231aSEd Maste 
2997fa27ce4SDimitry Andric   return value_sp->GetName().GetCString();
300f034231aSEd Maste }
301f034231aSEd Maste 
GetTypeName()30214f1b3e8SDimitry Andric const char *SBValue::GetTypeName() {
3036f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
3045f29bb8aSDimitry Andric 
305f034231aSEd Maste   ValueLocker locker;
306f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
3077fa27ce4SDimitry Andric   if (!value_sp)
3087fa27ce4SDimitry Andric     return nullptr;
309f034231aSEd Maste 
3107fa27ce4SDimitry Andric   return value_sp->GetQualifiedTypeName().GetCString();
3110cac4ca3SEd Maste }
3120cac4ca3SEd Maste 
GetDisplayTypeName()31314f1b3e8SDimitry Andric const char *SBValue::GetDisplayTypeName() {
3146f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
3155f29bb8aSDimitry Andric 
3160cac4ca3SEd Maste   ValueLocker locker;
3170cac4ca3SEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
3187fa27ce4SDimitry Andric   if (!value_sp)
3197fa27ce4SDimitry Andric     return nullptr;
3200cac4ca3SEd Maste 
3217fa27ce4SDimitry Andric   return value_sp->GetDisplayTypeName().GetCString();
322f034231aSEd Maste }
323f034231aSEd Maste 
GetByteSize()32414f1b3e8SDimitry Andric size_t SBValue::GetByteSize() {
3256f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
3265f29bb8aSDimitry Andric 
327f034231aSEd Maste   size_t result = 0;
328f034231aSEd Maste 
329f034231aSEd Maste   ValueLocker locker;
330f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
33114f1b3e8SDimitry Andric   if (value_sp) {
332145449b1SDimitry Andric     result = value_sp->GetByteSize().value_or(0);
333f034231aSEd Maste   }
334f034231aSEd Maste 
335f034231aSEd Maste   return result;
336f034231aSEd Maste }
337f034231aSEd Maste 
IsInScope()33814f1b3e8SDimitry Andric bool SBValue::IsInScope() {
3396f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
3405f29bb8aSDimitry Andric 
341f034231aSEd Maste   bool result = false;
342f034231aSEd Maste 
343f034231aSEd Maste   ValueLocker locker;
344f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
34514f1b3e8SDimitry Andric   if (value_sp) {
346f034231aSEd Maste     result = value_sp->IsInScope();
347f034231aSEd Maste   }
348f034231aSEd Maste 
349f034231aSEd Maste   return result;
350f034231aSEd Maste }
351f034231aSEd Maste 
GetValue()35214f1b3e8SDimitry Andric const char *SBValue::GetValue() {
3536f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
354f034231aSEd Maste 
355f034231aSEd Maste   ValueLocker locker;
356f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
3577fa27ce4SDimitry Andric   if (!value_sp)
3587fa27ce4SDimitry Andric     return nullptr;
3597fa27ce4SDimitry Andric   return ConstString(value_sp->GetValueAsCString()).GetCString();
360f034231aSEd Maste }
361f034231aSEd Maste 
GetValueType()36214f1b3e8SDimitry Andric ValueType SBValue::GetValueType() {
3636f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
3645f29bb8aSDimitry Andric 
365f034231aSEd Maste   ValueType result = eValueTypeInvalid;
366f034231aSEd Maste   ValueLocker locker;
367f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
368f034231aSEd Maste   if (value_sp)
369f034231aSEd Maste     result = value_sp->GetValueType();
370f034231aSEd Maste 
371f034231aSEd Maste   return result;
372f034231aSEd Maste }
373f034231aSEd Maste 
GetObjectDescription()37414f1b3e8SDimitry Andric const char *SBValue::GetObjectDescription() {
3756f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
3765f29bb8aSDimitry Andric 
377f034231aSEd Maste   ValueLocker locker;
378f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
3797fa27ce4SDimitry Andric   if (!value_sp)
3807fa27ce4SDimitry Andric     return nullptr;
3815f29bb8aSDimitry Andric 
382ac9a064cSDimitry Andric   llvm::Expected<std::string> str = value_sp->GetObjectDescription();
383ac9a064cSDimitry Andric   if (!str)
384ac9a064cSDimitry Andric     return ConstString("error: " + toString(str.takeError())).AsCString();
385ac9a064cSDimitry Andric   return ConstString(*str).AsCString();
386f034231aSEd Maste }
387f034231aSEd Maste 
GetType()38814f1b3e8SDimitry Andric SBType SBValue::GetType() {
3896f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
3905f29bb8aSDimitry Andric 
391f034231aSEd Maste   SBType sb_type;
392f034231aSEd Maste   ValueLocker locker;
393f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
394f034231aSEd Maste   TypeImplSP type_sp;
39514f1b3e8SDimitry Andric   if (value_sp) {
3965f29bb8aSDimitry Andric     type_sp = std::make_shared<TypeImpl>(value_sp->GetTypeImpl());
397f034231aSEd Maste     sb_type.SetSP(type_sp);
398f034231aSEd Maste   }
3995f29bb8aSDimitry Andric 
4006f8fc217SDimitry Andric   return sb_type;
401f034231aSEd Maste }
402f034231aSEd Maste 
GetValueDidChange()40314f1b3e8SDimitry Andric bool SBValue::GetValueDidChange() {
4046f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
4055f29bb8aSDimitry Andric 
406f034231aSEd Maste   bool result = false;
407f034231aSEd Maste   ValueLocker locker;
408f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
40914f1b3e8SDimitry Andric   if (value_sp) {
41012bd4897SEd Maste     if (value_sp->UpdateValueIfNeeded(false))
411f034231aSEd Maste       result = value_sp->GetValueDidChange();
412f034231aSEd Maste   }
413f034231aSEd Maste 
414f034231aSEd Maste   return result;
415f034231aSEd Maste }
416f034231aSEd Maste 
GetSummary()41714f1b3e8SDimitry Andric const char *SBValue::GetSummary() {
4186f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
4195f29bb8aSDimitry Andric 
420f034231aSEd Maste   ValueLocker locker;
421f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
4227fa27ce4SDimitry Andric   if (!value_sp)
4237fa27ce4SDimitry Andric     return nullptr;
4245f29bb8aSDimitry Andric 
4257fa27ce4SDimitry Andric   return ConstString(value_sp->GetSummaryAsCString()).GetCString();
426f034231aSEd Maste }
427205afe67SEd Maste 
GetSummary(lldb::SBStream & stream,lldb::SBTypeSummaryOptions & options)42814f1b3e8SDimitry Andric const char *SBValue::GetSummary(lldb::SBStream &stream,
42914f1b3e8SDimitry Andric                                 lldb::SBTypeSummaryOptions &options) {
4306f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, stream, options);
4315f29bb8aSDimitry Andric 
432205afe67SEd Maste   ValueLocker locker;
433205afe67SEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
43414f1b3e8SDimitry Andric   if (value_sp) {
435205afe67SEd Maste     std::string buffer;
436205afe67SEd Maste     if (value_sp->GetSummaryAsCString(buffer, options.ref()) && !buffer.empty())
437205afe67SEd Maste       stream.Printf("%s", buffer.c_str());
438205afe67SEd Maste   }
4397fa27ce4SDimitry Andric   return ConstString(stream.GetData()).GetCString();
440205afe67SEd Maste }
441f034231aSEd Maste 
GetLocation()44214f1b3e8SDimitry Andric const char *SBValue::GetLocation() {
4436f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
4445f29bb8aSDimitry Andric 
445f034231aSEd Maste   ValueLocker locker;
446f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
4477fa27ce4SDimitry Andric   if (!value_sp)
4487fa27ce4SDimitry Andric     return nullptr;
4497fa27ce4SDimitry Andric 
4507fa27ce4SDimitry Andric   return ConstString(value_sp->GetLocationAsCString()).GetCString();
451f034231aSEd Maste }
452f034231aSEd Maste 
453f034231aSEd Maste // Deprecated - use the one that takes an lldb::SBError
SetValueFromCString(const char * value_str)45414f1b3e8SDimitry Andric bool SBValue::SetValueFromCString(const char *value_str) {
4556f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, value_str);
4565f29bb8aSDimitry Andric 
457f034231aSEd Maste   lldb::SBError dummy;
458f034231aSEd Maste   return SetValueFromCString(value_str, dummy);
459f034231aSEd Maste }
460f034231aSEd Maste 
SetValueFromCString(const char * value_str,lldb::SBError & error)46114f1b3e8SDimitry Andric bool SBValue::SetValueFromCString(const char *value_str, lldb::SBError &error) {
4626f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, value_str, error);
4635f29bb8aSDimitry Andric 
464f034231aSEd Maste   bool success = false;
465f034231aSEd Maste   ValueLocker locker;
466f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
46714f1b3e8SDimitry Andric   if (value_sp) {
468f034231aSEd Maste     success = value_sp->SetValueFromCString(value_str, error.ref());
46914f1b3e8SDimitry Andric   } else
47014f1b3e8SDimitry Andric     error.SetErrorStringWithFormat("Could not get value: %s",
47114f1b3e8SDimitry Andric                                    locker.GetError().AsCString());
472f034231aSEd Maste 
473f034231aSEd Maste   return success;
474f034231aSEd Maste }
475f034231aSEd Maste 
GetTypeFormat()47614f1b3e8SDimitry Andric lldb::SBTypeFormat SBValue::GetTypeFormat() {
4776f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
4785f29bb8aSDimitry Andric 
479f034231aSEd Maste   lldb::SBTypeFormat format;
480f034231aSEd Maste   ValueLocker locker;
481f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
48214f1b3e8SDimitry Andric   if (value_sp) {
48314f1b3e8SDimitry Andric     if (value_sp->UpdateValueIfNeeded(true)) {
484f034231aSEd Maste       lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
485f034231aSEd Maste       if (format_sp)
486f034231aSEd Maste         format.SetSP(format_sp);
487f034231aSEd Maste     }
488f034231aSEd Maste   }
4896f8fc217SDimitry Andric   return format;
490f034231aSEd Maste }
491f034231aSEd Maste 
GetTypeSummary()49214f1b3e8SDimitry Andric lldb::SBTypeSummary SBValue::GetTypeSummary() {
4936f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
4945f29bb8aSDimitry Andric 
495f034231aSEd Maste   lldb::SBTypeSummary summary;
496f034231aSEd Maste   ValueLocker locker;
497f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
49814f1b3e8SDimitry Andric   if (value_sp) {
49914f1b3e8SDimitry Andric     if (value_sp->UpdateValueIfNeeded(true)) {
500f034231aSEd Maste       lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
501f034231aSEd Maste       if (summary_sp)
502f034231aSEd Maste         summary.SetSP(summary_sp);
503f034231aSEd Maste     }
504f034231aSEd Maste   }
5056f8fc217SDimitry Andric   return summary;
506f034231aSEd Maste }
507f034231aSEd Maste 
GetTypeFilter()50814f1b3e8SDimitry Andric lldb::SBTypeFilter SBValue::GetTypeFilter() {
5096f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
5105f29bb8aSDimitry Andric 
511f034231aSEd Maste   lldb::SBTypeFilter filter;
512f034231aSEd Maste   ValueLocker locker;
513f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
51414f1b3e8SDimitry Andric   if (value_sp) {
51514f1b3e8SDimitry Andric     if (value_sp->UpdateValueIfNeeded(true)) {
516f034231aSEd Maste       lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
517f034231aSEd Maste 
51814f1b3e8SDimitry Andric       if (synthetic_sp && !synthetic_sp->IsScripted()) {
51914f1b3e8SDimitry Andric         TypeFilterImplSP filter_sp =
52014f1b3e8SDimitry Andric             std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
521f034231aSEd Maste         filter.SetSP(filter_sp);
522f034231aSEd Maste       }
523f034231aSEd Maste     }
524f034231aSEd Maste   }
5256f8fc217SDimitry Andric   return filter;
526f034231aSEd Maste }
527f034231aSEd Maste 
GetTypeSynthetic()52814f1b3e8SDimitry Andric lldb::SBTypeSynthetic SBValue::GetTypeSynthetic() {
5296f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
5305f29bb8aSDimitry Andric 
531f034231aSEd Maste   lldb::SBTypeSynthetic synthetic;
532f034231aSEd Maste   ValueLocker locker;
533f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
53414f1b3e8SDimitry Andric   if (value_sp) {
53514f1b3e8SDimitry Andric     if (value_sp->UpdateValueIfNeeded(true)) {
536f034231aSEd Maste       lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
537f034231aSEd Maste 
53814f1b3e8SDimitry Andric       if (children_sp && children_sp->IsScripted()) {
53914f1b3e8SDimitry Andric         ScriptedSyntheticChildrenSP synth_sp =
54014f1b3e8SDimitry Andric             std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
541f034231aSEd Maste         synthetic.SetSP(synth_sp);
542f034231aSEd Maste       }
543f034231aSEd Maste     }
544f034231aSEd Maste   }
5456f8fc217SDimitry Andric   return synthetic;
546f034231aSEd Maste }
547f034231aSEd Maste 
CreateChildAtOffset(const char * name,uint32_t offset,SBType type)54814f1b3e8SDimitry Andric lldb::SBValue SBValue::CreateChildAtOffset(const char *name, uint32_t offset,
54914f1b3e8SDimitry Andric                                            SBType type) {
5506f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name, offset, type);
5515f29bb8aSDimitry Andric 
552f034231aSEd Maste   lldb::SBValue sb_value;
553f034231aSEd Maste   ValueLocker locker;
554f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
555f034231aSEd Maste   lldb::ValueObjectSP new_value_sp;
55614f1b3e8SDimitry Andric   if (value_sp) {
557f034231aSEd Maste     TypeImplSP type_sp(type.GetSP());
55814f1b3e8SDimitry Andric     if (type.IsValid()) {
55914f1b3e8SDimitry Andric       sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(
56014f1b3e8SDimitry Andric                          offset, type_sp->GetCompilerType(false), true),
56114f1b3e8SDimitry Andric                      GetPreferDynamicValue(), GetPreferSyntheticValue(), name);
562f034231aSEd Maste     }
563f034231aSEd Maste   }
5646f8fc217SDimitry Andric   return sb_value;
565f034231aSEd Maste }
566f034231aSEd Maste 
Cast(SBType type)56714f1b3e8SDimitry Andric lldb::SBValue SBValue::Cast(SBType type) {
5686f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, type);
5695f29bb8aSDimitry Andric 
570f034231aSEd Maste   lldb::SBValue sb_value;
571f034231aSEd Maste   ValueLocker locker;
572f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
573f034231aSEd Maste   TypeImplSP type_sp(type.GetSP());
574f034231aSEd Maste   if (value_sp && type_sp)
57514f1b3e8SDimitry Andric     sb_value.SetSP(value_sp->Cast(type_sp->GetCompilerType(false)),
57614f1b3e8SDimitry Andric                    GetPreferDynamicValue(), GetPreferSyntheticValue());
5776f8fc217SDimitry Andric   return sb_value;
578f034231aSEd Maste }
579f034231aSEd Maste 
CreateValueFromExpression(const char * name,const char * expression)58014f1b3e8SDimitry Andric lldb::SBValue SBValue::CreateValueFromExpression(const char *name,
58114f1b3e8SDimitry Andric                                                  const char *expression) {
5826f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name, expression);
5835f29bb8aSDimitry Andric 
584f034231aSEd Maste   SBExpressionOptions options;
585f034231aSEd Maste   options.ref().SetKeepInMemory(true);
5866f8fc217SDimitry Andric   return CreateValueFromExpression(name, expression, options);
587f034231aSEd Maste }
588f034231aSEd Maste 
CreateValueFromExpression(const char * name,const char * expression,SBExpressionOptions & options)58914f1b3e8SDimitry Andric lldb::SBValue SBValue::CreateValueFromExpression(const char *name,
59014f1b3e8SDimitry Andric                                                  const char *expression,
59114f1b3e8SDimitry Andric                                                  SBExpressionOptions &options) {
5926f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name, expression, options);
5935f29bb8aSDimitry Andric 
594f034231aSEd Maste   lldb::SBValue sb_value;
595f034231aSEd Maste   ValueLocker locker;
596f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
597f034231aSEd Maste   lldb::ValueObjectSP new_value_sp;
59814f1b3e8SDimitry Andric   if (value_sp) {
599f034231aSEd Maste     ExecutionContext exe_ctx(value_sp->GetExecutionContextRef());
60014f1b3e8SDimitry Andric     new_value_sp = ValueObject::CreateValueObjectFromExpression(
60114f1b3e8SDimitry Andric         name, expression, exe_ctx, options.ref());
602f034231aSEd Maste     if (new_value_sp)
603f034231aSEd Maste       new_value_sp->SetName(ConstString(name));
604205afe67SEd Maste   }
605f034231aSEd Maste   sb_value.SetSP(new_value_sp);
6066f8fc217SDimitry Andric   return sb_value;
607f034231aSEd Maste }
608f034231aSEd Maste 
CreateValueFromAddress(const char * name,lldb::addr_t address,SBType sb_type)60914f1b3e8SDimitry Andric lldb::SBValue SBValue::CreateValueFromAddress(const char *name,
61014f1b3e8SDimitry Andric                                               lldb::addr_t address,
61114f1b3e8SDimitry Andric                                               SBType sb_type) {
6126f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name, address, sb_type);
6135f29bb8aSDimitry Andric 
614f034231aSEd Maste   lldb::SBValue sb_value;
615f034231aSEd Maste   ValueLocker locker;
616f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
617f034231aSEd Maste   lldb::ValueObjectSP new_value_sp;
618f034231aSEd Maste   lldb::TypeImplSP type_impl_sp(sb_type.GetSP());
61914f1b3e8SDimitry Andric   if (value_sp && type_impl_sp) {
620e81d9d49SDimitry Andric     CompilerType ast_type(type_impl_sp->GetCompilerType(true));
621f034231aSEd Maste     ExecutionContext exe_ctx(value_sp->GetExecutionContextRef());
62214f1b3e8SDimitry Andric     new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address,
62314f1b3e8SDimitry Andric                                                              exe_ctx, ast_type);
624f034231aSEd Maste   }
625f034231aSEd Maste   sb_value.SetSP(new_value_sp);
6266f8fc217SDimitry Andric   return sb_value;
627f034231aSEd Maste }
628f034231aSEd Maste 
CreateValueFromData(const char * name,SBData data,SBType sb_type)62914f1b3e8SDimitry Andric lldb::SBValue SBValue::CreateValueFromData(const char *name, SBData data,
63014f1b3e8SDimitry Andric                                            SBType sb_type) {
6316f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name, data, sb_type);
6325f29bb8aSDimitry Andric 
633f034231aSEd Maste   lldb::SBValue sb_value;
634f034231aSEd Maste   lldb::ValueObjectSP new_value_sp;
635f034231aSEd Maste   ValueLocker locker;
636f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
637f3fbd1c0SDimitry Andric   lldb::TypeImplSP type_impl_sp(sb_type.GetSP());
63814f1b3e8SDimitry Andric   if (value_sp && type_impl_sp) {
639f034231aSEd Maste     ExecutionContext exe_ctx(value_sp->GetExecutionContextRef());
64014f1b3e8SDimitry Andric     new_value_sp = ValueObject::CreateValueObjectFromData(
64114f1b3e8SDimitry Andric         name, **data, exe_ctx, type_impl_sp->GetCompilerType(true));
642f034231aSEd Maste     new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
643f034231aSEd Maste   }
644205afe67SEd Maste   sb_value.SetSP(new_value_sp);
6456f8fc217SDimitry Andric   return sb_value;
646f034231aSEd Maste }
647f034231aSEd Maste 
GetChildAtIndex(uint32_t idx)64814f1b3e8SDimitry Andric SBValue SBValue::GetChildAtIndex(uint32_t idx) {
6496f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, idx);
6505f29bb8aSDimitry Andric 
651f034231aSEd Maste   const bool can_create_synthetic = false;
652f034231aSEd Maste   lldb::DynamicValueType use_dynamic = eNoDynamicValues;
653f034231aSEd Maste   TargetSP target_sp;
654f034231aSEd Maste   if (m_opaque_sp)
655f034231aSEd Maste     target_sp = m_opaque_sp->GetTargetSP();
656f034231aSEd Maste 
657f034231aSEd Maste   if (target_sp)
658f034231aSEd Maste     use_dynamic = target_sp->GetPreferDynamicValue();
659f034231aSEd Maste 
6606f8fc217SDimitry Andric   return GetChildAtIndex(idx, use_dynamic, can_create_synthetic);
661f034231aSEd Maste }
662f034231aSEd Maste 
GetChildAtIndex(uint32_t idx,lldb::DynamicValueType use_dynamic,bool can_create_synthetic)66314f1b3e8SDimitry Andric SBValue SBValue::GetChildAtIndex(uint32_t idx,
66414f1b3e8SDimitry Andric                                  lldb::DynamicValueType use_dynamic,
66514f1b3e8SDimitry Andric                                  bool can_create_synthetic) {
6666f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, idx, use_dynamic, can_create_synthetic);
6675f29bb8aSDimitry Andric 
668f034231aSEd Maste   lldb::ValueObjectSP child_sp;
669f034231aSEd Maste 
670f034231aSEd Maste   ValueLocker locker;
671f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
67214f1b3e8SDimitry Andric   if (value_sp) {
673f034231aSEd Maste     const bool can_create = true;
6747fa27ce4SDimitry Andric     child_sp = value_sp->GetChildAtIndex(idx);
67514f1b3e8SDimitry Andric     if (can_create_synthetic && !child_sp) {
6765e95aa85SEd Maste       child_sp = value_sp->GetSyntheticArrayMember(idx, can_create);
677f034231aSEd Maste     }
678f034231aSEd Maste   }
679f034231aSEd Maste 
680f034231aSEd Maste   SBValue sb_value;
681f034231aSEd Maste   sb_value.SetSP(child_sp, use_dynamic, GetPreferSyntheticValue());
682f034231aSEd Maste 
6836f8fc217SDimitry Andric   return sb_value;
684f034231aSEd Maste }
685f034231aSEd Maste 
GetIndexOfChildWithName(const char * name)68614f1b3e8SDimitry Andric uint32_t SBValue::GetIndexOfChildWithName(const char *name) {
6876f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name);
6885f29bb8aSDimitry Andric 
689f034231aSEd Maste   uint32_t idx = UINT32_MAX;
690f034231aSEd Maste   ValueLocker locker;
691f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
69214f1b3e8SDimitry Andric   if (value_sp) {
6937fa27ce4SDimitry Andric     idx = value_sp->GetIndexOfChildWithName(name);
694f034231aSEd Maste   }
695f034231aSEd Maste   return idx;
696f034231aSEd Maste }
697f034231aSEd Maste 
GetChildMemberWithName(const char * name)69814f1b3e8SDimitry Andric SBValue SBValue::GetChildMemberWithName(const char *name) {
6996f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name);
7005f29bb8aSDimitry Andric 
701f034231aSEd Maste   lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
702f034231aSEd Maste   TargetSP target_sp;
703f034231aSEd Maste   if (m_opaque_sp)
704f034231aSEd Maste     target_sp = m_opaque_sp->GetTargetSP();
705f034231aSEd Maste 
706f034231aSEd Maste   if (target_sp)
707f034231aSEd Maste     use_dynamic_value = target_sp->GetPreferDynamicValue();
7086f8fc217SDimitry Andric   return GetChildMemberWithName(name, use_dynamic_value);
709f034231aSEd Maste }
710f034231aSEd Maste 
711f034231aSEd Maste SBValue
GetChildMemberWithName(const char * name,lldb::DynamicValueType use_dynamic_value)71214f1b3e8SDimitry Andric SBValue::GetChildMemberWithName(const char *name,
71314f1b3e8SDimitry Andric                                 lldb::DynamicValueType use_dynamic_value) {
7146f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name, use_dynamic_value);
7155f29bb8aSDimitry Andric 
716f034231aSEd Maste   lldb::ValueObjectSP child_sp;
717f034231aSEd Maste 
718f034231aSEd Maste   ValueLocker locker;
719f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
72014f1b3e8SDimitry Andric   if (value_sp) {
7217fa27ce4SDimitry Andric     child_sp = value_sp->GetChildMemberWithName(name);
722f034231aSEd Maste   }
723f034231aSEd Maste 
724f034231aSEd Maste   SBValue sb_value;
725f034231aSEd Maste   sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
726f034231aSEd Maste 
7276f8fc217SDimitry Andric   return sb_value;
728f034231aSEd Maste }
729f034231aSEd Maste 
GetDynamicValue(lldb::DynamicValueType use_dynamic)73014f1b3e8SDimitry Andric lldb::SBValue SBValue::GetDynamicValue(lldb::DynamicValueType use_dynamic) {
7316f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, use_dynamic);
7325f29bb8aSDimitry Andric 
733f034231aSEd Maste   SBValue value_sb;
73414f1b3e8SDimitry Andric   if (IsValid()) {
73514f1b3e8SDimitry Andric     ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(), use_dynamic,
73614f1b3e8SDimitry Andric                                        m_opaque_sp->GetUseSynthetic()));
737f034231aSEd Maste     value_sb.SetSP(proxy_sp);
738f034231aSEd Maste   }
7396f8fc217SDimitry Andric   return value_sb;
740f034231aSEd Maste }
741f034231aSEd Maste 
GetStaticValue()74214f1b3e8SDimitry Andric lldb::SBValue SBValue::GetStaticValue() {
7436f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
7445f29bb8aSDimitry Andric 
745f034231aSEd Maste   SBValue value_sb;
74614f1b3e8SDimitry Andric   if (IsValid()) {
74714f1b3e8SDimitry Andric     ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),
74814f1b3e8SDimitry Andric                                        eNoDynamicValues,
74914f1b3e8SDimitry Andric                                        m_opaque_sp->GetUseSynthetic()));
750f034231aSEd Maste     value_sb.SetSP(proxy_sp);
751f034231aSEd Maste   }
7526f8fc217SDimitry Andric   return value_sb;
753f034231aSEd Maste }
754f034231aSEd Maste 
GetNonSyntheticValue()75514f1b3e8SDimitry Andric lldb::SBValue SBValue::GetNonSyntheticValue() {
7566f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
7575f29bb8aSDimitry Andric 
758f034231aSEd Maste   SBValue value_sb;
75914f1b3e8SDimitry Andric   if (IsValid()) {
76014f1b3e8SDimitry Andric     ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),
76114f1b3e8SDimitry Andric                                        m_opaque_sp->GetUseDynamic(), false));
762f034231aSEd Maste     value_sb.SetSP(proxy_sp);
763f034231aSEd Maste   }
7646f8fc217SDimitry Andric   return value_sb;
765f034231aSEd Maste }
766f034231aSEd Maste 
GetSyntheticValue()767ac9a064cSDimitry Andric lldb::SBValue SBValue::GetSyntheticValue() {
768ac9a064cSDimitry Andric   LLDB_INSTRUMENT_VA(this);
769ac9a064cSDimitry Andric 
770ac9a064cSDimitry Andric   SBValue value_sb;
771ac9a064cSDimitry Andric   if (IsValid()) {
772ac9a064cSDimitry Andric     ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),
773ac9a064cSDimitry Andric                                        m_opaque_sp->GetUseDynamic(), true));
774ac9a064cSDimitry Andric     value_sb.SetSP(proxy_sp);
775ac9a064cSDimitry Andric     if (!value_sb.IsSynthetic()) {
776ac9a064cSDimitry Andric       return {};
777ac9a064cSDimitry Andric     }
778ac9a064cSDimitry Andric   }
779ac9a064cSDimitry Andric   return value_sb;
780ac9a064cSDimitry Andric }
781ac9a064cSDimitry Andric 
GetPreferDynamicValue()78214f1b3e8SDimitry Andric lldb::DynamicValueType SBValue::GetPreferDynamicValue() {
7836f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
7845f29bb8aSDimitry Andric 
785f034231aSEd Maste   if (!IsValid())
786f034231aSEd Maste     return eNoDynamicValues;
787f034231aSEd Maste   return m_opaque_sp->GetUseDynamic();
788f034231aSEd Maste }
789f034231aSEd Maste 
SetPreferDynamicValue(lldb::DynamicValueType use_dynamic)79014f1b3e8SDimitry Andric void SBValue::SetPreferDynamicValue(lldb::DynamicValueType use_dynamic) {
7916f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, use_dynamic);
7925f29bb8aSDimitry Andric 
793f034231aSEd Maste   if (IsValid())
794f034231aSEd Maste     return m_opaque_sp->SetUseDynamic(use_dynamic);
795f034231aSEd Maste }
796f034231aSEd Maste 
GetPreferSyntheticValue()79714f1b3e8SDimitry Andric bool SBValue::GetPreferSyntheticValue() {
7986f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
7995f29bb8aSDimitry Andric 
800f034231aSEd Maste   if (!IsValid())
801f034231aSEd Maste     return false;
802f034231aSEd Maste   return m_opaque_sp->GetUseSynthetic();
803f034231aSEd Maste }
804f034231aSEd Maste 
SetPreferSyntheticValue(bool use_synthetic)80514f1b3e8SDimitry Andric void SBValue::SetPreferSyntheticValue(bool use_synthetic) {
8066f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, use_synthetic);
8075f29bb8aSDimitry Andric 
808f034231aSEd Maste   if (IsValid())
809f034231aSEd Maste     return m_opaque_sp->SetUseSynthetic(use_synthetic);
810f034231aSEd Maste }
811f034231aSEd Maste 
IsDynamic()81214f1b3e8SDimitry Andric bool SBValue::IsDynamic() {
8136f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
8145f29bb8aSDimitry Andric 
815f034231aSEd Maste   ValueLocker locker;
816f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
817f034231aSEd Maste   if (value_sp)
818f034231aSEd Maste     return value_sp->IsDynamic();
819f034231aSEd Maste   return false;
820f034231aSEd Maste }
821f034231aSEd Maste 
IsSynthetic()82214f1b3e8SDimitry Andric bool SBValue::IsSynthetic() {
8236f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
8245f29bb8aSDimitry Andric 
825f034231aSEd Maste   ValueLocker locker;
826f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
827f034231aSEd Maste   if (value_sp)
828f034231aSEd Maste     return value_sp->IsSynthetic();
829f034231aSEd Maste   return false;
830f034231aSEd Maste }
831f034231aSEd Maste 
IsSyntheticChildrenGenerated()83214f1b3e8SDimitry Andric bool SBValue::IsSyntheticChildrenGenerated() {
8336f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
8345f29bb8aSDimitry Andric 
835f3fbd1c0SDimitry Andric   ValueLocker locker;
836f3fbd1c0SDimitry Andric   lldb::ValueObjectSP value_sp(GetSP(locker));
837f3fbd1c0SDimitry Andric   if (value_sp)
838f3fbd1c0SDimitry Andric     return value_sp->IsSyntheticChildrenGenerated();
839f3fbd1c0SDimitry Andric   return false;
840f3fbd1c0SDimitry Andric }
841f3fbd1c0SDimitry Andric 
SetSyntheticChildrenGenerated(bool is)84214f1b3e8SDimitry Andric void SBValue::SetSyntheticChildrenGenerated(bool is) {
8436f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, is);
8445f29bb8aSDimitry Andric 
845f3fbd1c0SDimitry Andric   ValueLocker locker;
846f3fbd1c0SDimitry Andric   lldb::ValueObjectSP value_sp(GetSP(locker));
847f3fbd1c0SDimitry Andric   if (value_sp)
848f3fbd1c0SDimitry Andric     return value_sp->SetSyntheticChildrenGenerated(is);
849f3fbd1c0SDimitry Andric }
850f3fbd1c0SDimitry Andric 
GetValueForExpressionPath(const char * expr_path)85114f1b3e8SDimitry Andric lldb::SBValue SBValue::GetValueForExpressionPath(const char *expr_path) {
8526f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, expr_path);
8535f29bb8aSDimitry Andric 
854f034231aSEd Maste   lldb::ValueObjectSP child_sp;
855f034231aSEd Maste   ValueLocker locker;
856f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
85714f1b3e8SDimitry Andric   if (value_sp) {
858f034231aSEd Maste     // using default values for all the fancy options, just do it if you can
859f034231aSEd Maste     child_sp = value_sp->GetValueForExpressionPath(expr_path);
860f034231aSEd Maste   }
861f034231aSEd Maste 
862f034231aSEd Maste   SBValue sb_value;
863f034231aSEd Maste   sb_value.SetSP(child_sp, GetPreferDynamicValue(), GetPreferSyntheticValue());
864f034231aSEd Maste 
8656f8fc217SDimitry Andric   return sb_value;
866f034231aSEd Maste }
867f034231aSEd Maste 
GetValueAsSigned(SBError & error,int64_t fail_value)86814f1b3e8SDimitry Andric int64_t SBValue::GetValueAsSigned(SBError &error, int64_t fail_value) {
8696f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, error, fail_value);
8705f29bb8aSDimitry Andric 
871f034231aSEd Maste   error.Clear();
872f034231aSEd Maste   ValueLocker locker;
873f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
87414f1b3e8SDimitry Andric   if (value_sp) {
875f21a844fSEd Maste     bool success = true;
876f21a844fSEd Maste     uint64_t ret_val = fail_value;
877f21a844fSEd Maste     ret_val = value_sp->GetValueAsSigned(fail_value, &success);
878f21a844fSEd Maste     if (!success)
879f034231aSEd Maste       error.SetErrorString("could not resolve value");
880f21a844fSEd Maste     return ret_val;
88114f1b3e8SDimitry Andric   } else
88214f1b3e8SDimitry Andric     error.SetErrorStringWithFormat("could not get SBValue: %s",
88314f1b3e8SDimitry Andric                                    locker.GetError().AsCString());
884f034231aSEd Maste 
885f034231aSEd Maste   return fail_value;
886f034231aSEd Maste }
887f034231aSEd Maste 
GetValueAsUnsigned(SBError & error,uint64_t fail_value)88814f1b3e8SDimitry Andric uint64_t SBValue::GetValueAsUnsigned(SBError &error, uint64_t fail_value) {
8896f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, error, fail_value);
8905f29bb8aSDimitry Andric 
891f034231aSEd Maste   error.Clear();
892f034231aSEd Maste   ValueLocker locker;
893f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
89414f1b3e8SDimitry Andric   if (value_sp) {
895f21a844fSEd Maste     bool success = true;
896f21a844fSEd Maste     uint64_t ret_val = fail_value;
897f21a844fSEd Maste     ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
898f21a844fSEd Maste     if (!success)
899f034231aSEd Maste       error.SetErrorString("could not resolve value");
900f21a844fSEd Maste     return ret_val;
90114f1b3e8SDimitry Andric   } else
90214f1b3e8SDimitry Andric     error.SetErrorStringWithFormat("could not get SBValue: %s",
90314f1b3e8SDimitry Andric                                    locker.GetError().AsCString());
904f034231aSEd Maste 
905f034231aSEd Maste   return fail_value;
906f034231aSEd Maste }
907f034231aSEd Maste 
GetValueAsSigned(int64_t fail_value)90814f1b3e8SDimitry Andric int64_t SBValue::GetValueAsSigned(int64_t fail_value) {
9096f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, fail_value);
9105f29bb8aSDimitry Andric 
911f034231aSEd Maste   ValueLocker locker;
912f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
91314f1b3e8SDimitry Andric   if (value_sp) {
914f21a844fSEd Maste     return value_sp->GetValueAsSigned(fail_value);
915f034231aSEd Maste   }
916f034231aSEd Maste   return fail_value;
917f034231aSEd Maste }
918f034231aSEd Maste 
GetValueAsUnsigned(uint64_t fail_value)91914f1b3e8SDimitry Andric uint64_t SBValue::GetValueAsUnsigned(uint64_t fail_value) {
9206f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, fail_value);
9215f29bb8aSDimitry Andric 
922f034231aSEd Maste   ValueLocker locker;
923f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
92414f1b3e8SDimitry Andric   if (value_sp) {
925f21a844fSEd Maste     return value_sp->GetValueAsUnsigned(fail_value);
926f034231aSEd Maste   }
927f034231aSEd Maste   return fail_value;
928f034231aSEd Maste }
929f034231aSEd Maste 
GetValueAsAddress()930ac9a064cSDimitry Andric lldb::addr_t SBValue::GetValueAsAddress() {
931ac9a064cSDimitry Andric   addr_t fail_value = LLDB_INVALID_ADDRESS;
932ac9a064cSDimitry Andric   ValueLocker locker;
933ac9a064cSDimitry Andric   lldb::ValueObjectSP value_sp(GetSP(locker));
934ac9a064cSDimitry Andric   if (value_sp) {
935ac9a064cSDimitry Andric     bool success = true;
936ac9a064cSDimitry Andric     uint64_t ret_val = fail_value;
937ac9a064cSDimitry Andric     ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
938ac9a064cSDimitry Andric     if (!success)
939ac9a064cSDimitry Andric       return fail_value;
940ac9a064cSDimitry Andric     ProcessSP process_sp = m_opaque_sp->GetProcessSP();
941ac9a064cSDimitry Andric     if (!process_sp)
942ac9a064cSDimitry Andric       return ret_val;
943ac9a064cSDimitry Andric     return process_sp->FixDataAddress(ret_val);
944ac9a064cSDimitry Andric   }
945ac9a064cSDimitry Andric 
946ac9a064cSDimitry Andric   return fail_value;
947ac9a064cSDimitry Andric }
948ac9a064cSDimitry Andric 
MightHaveChildren()94914f1b3e8SDimitry Andric bool SBValue::MightHaveChildren() {
9506f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
9515f29bb8aSDimitry Andric 
952f034231aSEd Maste   bool has_children = false;
953f034231aSEd Maste   ValueLocker locker;
954f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
955f034231aSEd Maste   if (value_sp)
956f034231aSEd Maste     has_children = value_sp->MightHaveChildren();
957f034231aSEd Maste 
958f034231aSEd Maste   return has_children;
959f034231aSEd Maste }
960f034231aSEd Maste 
IsRuntimeSupportValue()96114f1b3e8SDimitry Andric bool SBValue::IsRuntimeSupportValue() {
9626f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
9635f29bb8aSDimitry Andric 
9645e95aa85SEd Maste   bool is_support = false;
9655e95aa85SEd Maste   ValueLocker locker;
9665e95aa85SEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
9675e95aa85SEd Maste   if (value_sp)
9685e95aa85SEd Maste     is_support = value_sp->IsRuntimeSupportValue();
9695e95aa85SEd Maste 
9705e95aa85SEd Maste   return is_support;
9715e95aa85SEd Maste }
9725e95aa85SEd Maste 
GetNumChildren()9735f29bb8aSDimitry Andric uint32_t SBValue::GetNumChildren() {
9746f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
9755f29bb8aSDimitry Andric 
9765f29bb8aSDimitry Andric   return GetNumChildren(UINT32_MAX);
9775f29bb8aSDimitry Andric }
978e81d9d49SDimitry Andric 
GetNumChildren(uint32_t max)97914f1b3e8SDimitry Andric uint32_t SBValue::GetNumChildren(uint32_t max) {
9806f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, max);
9815f29bb8aSDimitry Andric 
982f034231aSEd Maste   uint32_t num_children = 0;
983f034231aSEd Maste 
984f034231aSEd Maste   ValueLocker locker;
985f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
986f034231aSEd Maste   if (value_sp)
987ac9a064cSDimitry Andric     num_children = value_sp->GetNumChildrenIgnoringErrors(max);
988f034231aSEd Maste 
989f034231aSEd Maste   return num_children;
990f034231aSEd Maste }
991f034231aSEd Maste 
Dereference()99214f1b3e8SDimitry Andric SBValue SBValue::Dereference() {
9936f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
9945f29bb8aSDimitry Andric 
995f034231aSEd Maste   SBValue sb_value;
996f034231aSEd Maste   ValueLocker locker;
997f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
99814f1b3e8SDimitry Andric   if (value_sp) {
999b76161e4SDimitry Andric     Status error;
1000f034231aSEd Maste     sb_value = value_sp->Dereference(error);
1001f034231aSEd Maste   }
1002f034231aSEd Maste 
10036f8fc217SDimitry Andric   return sb_value;
1004f034231aSEd Maste }
1005f034231aSEd Maste 
1006e81d9d49SDimitry Andric // Deprecated - please use GetType().IsPointerType() instead.
TypeIsPointerType()10075f29bb8aSDimitry Andric bool SBValue::TypeIsPointerType() {
10086f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
10095f29bb8aSDimitry Andric 
10105f29bb8aSDimitry Andric   return GetType().IsPointerType();
10115f29bb8aSDimitry Andric }
1012f034231aSEd Maste 
GetOpaqueType()101314f1b3e8SDimitry Andric void *SBValue::GetOpaqueType() {
10146f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
10155f29bb8aSDimitry Andric 
1016f034231aSEd Maste   ValueLocker locker;
1017f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1018f034231aSEd Maste   if (value_sp)
1019e81d9d49SDimitry Andric     return value_sp->GetCompilerType().GetOpaqueQualType();
10205f29bb8aSDimitry Andric   return nullptr;
1021f034231aSEd Maste }
1022f034231aSEd Maste 
GetTarget()102314f1b3e8SDimitry Andric lldb::SBTarget SBValue::GetTarget() {
10246f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
10255f29bb8aSDimitry Andric 
1026f034231aSEd Maste   SBTarget sb_target;
1027f034231aSEd Maste   TargetSP target_sp;
102814f1b3e8SDimitry Andric   if (m_opaque_sp) {
1029f034231aSEd Maste     target_sp = m_opaque_sp->GetTargetSP();
1030f034231aSEd Maste     sb_target.SetSP(target_sp);
1031f034231aSEd Maste   }
10325f29bb8aSDimitry Andric 
10336f8fc217SDimitry Andric   return sb_target;
1034f034231aSEd Maste }
1035f034231aSEd Maste 
GetProcess()103614f1b3e8SDimitry Andric lldb::SBProcess SBValue::GetProcess() {
10376f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
10385f29bb8aSDimitry Andric 
1039f034231aSEd Maste   SBProcess sb_process;
1040f034231aSEd Maste   ProcessSP process_sp;
104114f1b3e8SDimitry Andric   if (m_opaque_sp) {
1042f034231aSEd Maste     process_sp = m_opaque_sp->GetProcessSP();
1043f034231aSEd Maste     sb_process.SetSP(process_sp);
1044f034231aSEd Maste   }
10455f29bb8aSDimitry Andric 
10466f8fc217SDimitry Andric   return sb_process;
1047f034231aSEd Maste }
1048f034231aSEd Maste 
GetThread()104914f1b3e8SDimitry Andric lldb::SBThread SBValue::GetThread() {
10506f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
10515f29bb8aSDimitry Andric 
1052f034231aSEd Maste   SBThread sb_thread;
1053f034231aSEd Maste   ThreadSP thread_sp;
105414f1b3e8SDimitry Andric   if (m_opaque_sp) {
1055f034231aSEd Maste     thread_sp = m_opaque_sp->GetThreadSP();
1056f034231aSEd Maste     sb_thread.SetThread(thread_sp);
1057f034231aSEd Maste   }
10585f29bb8aSDimitry Andric 
10596f8fc217SDimitry Andric   return sb_thread;
1060f034231aSEd Maste }
1061f034231aSEd Maste 
GetFrame()106214f1b3e8SDimitry Andric lldb::SBFrame SBValue::GetFrame() {
10636f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
10645f29bb8aSDimitry Andric 
1065f034231aSEd Maste   SBFrame sb_frame;
1066f034231aSEd Maste   StackFrameSP frame_sp;
106714f1b3e8SDimitry Andric   if (m_opaque_sp) {
1068f034231aSEd Maste     frame_sp = m_opaque_sp->GetFrameSP();
1069f034231aSEd Maste     sb_frame.SetFrameSP(frame_sp);
1070f034231aSEd Maste   }
10715f29bb8aSDimitry Andric 
10726f8fc217SDimitry Andric   return sb_frame;
1073f034231aSEd Maste }
1074f034231aSEd Maste 
GetSP(ValueLocker & locker) const107514f1b3e8SDimitry Andric lldb::ValueObjectSP SBValue::GetSP(ValueLocker &locker) const {
10767fa27ce4SDimitry Andric   // IsValid means that the SBValue has a value in it.  But that's not the
10777fa27ce4SDimitry Andric   // only time that ValueObjects are useful.  We also want to return the value
10787fa27ce4SDimitry Andric   // if there's an error state in it.
10797fa27ce4SDimitry Andric   if (!m_opaque_sp || (!m_opaque_sp->IsValid()
10807fa27ce4SDimitry Andric       && (m_opaque_sp->GetRootSP()
10817fa27ce4SDimitry Andric           && !m_opaque_sp->GetRootSP()->GetError().Fail()))) {
1082e81d9d49SDimitry Andric     locker.GetError().SetErrorString("No value");
1083f034231aSEd Maste     return ValueObjectSP();
1084e81d9d49SDimitry Andric   }
1085f034231aSEd Maste   return locker.GetLockedSP(*m_opaque_sp.get());
1086f034231aSEd Maste }
1087f034231aSEd Maste 
GetSP() const108814f1b3e8SDimitry Andric lldb::ValueObjectSP SBValue::GetSP() const {
10896f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
10905f29bb8aSDimitry Andric 
1091f034231aSEd Maste   ValueLocker locker;
10926f8fc217SDimitry Andric   return GetSP(locker);
1093f034231aSEd Maste }
1094f034231aSEd Maste 
SetSP(ValueImplSP impl_sp)109514f1b3e8SDimitry Andric void SBValue::SetSP(ValueImplSP impl_sp) { m_opaque_sp = impl_sp; }
1096f034231aSEd Maste 
SetSP(const lldb::ValueObjectSP & sp)109714f1b3e8SDimitry Andric void SBValue::SetSP(const lldb::ValueObjectSP &sp) {
109814f1b3e8SDimitry Andric   if (sp) {
1099f034231aSEd Maste     lldb::TargetSP target_sp(sp->GetTargetSP());
110014f1b3e8SDimitry Andric     if (target_sp) {
1101f034231aSEd Maste       lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
110214f1b3e8SDimitry Andric       bool use_synthetic =
110314f1b3e8SDimitry Andric           target_sp->TargetProperties::GetEnableSyntheticValue();
1104f034231aSEd Maste       m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
110514f1b3e8SDimitry Andric     } else
1106f034231aSEd Maste       m_opaque_sp = ValueImplSP(new ValueImpl(sp, eNoDynamicValues, true));
110714f1b3e8SDimitry Andric   } else
1108f034231aSEd Maste     m_opaque_sp = ValueImplSP(new ValueImpl(sp, eNoDynamicValues, false));
1109f034231aSEd Maste }
1110f034231aSEd Maste 
SetSP(const lldb::ValueObjectSP & sp,lldb::DynamicValueType use_dynamic)111114f1b3e8SDimitry Andric void SBValue::SetSP(const lldb::ValueObjectSP &sp,
111214f1b3e8SDimitry Andric                     lldb::DynamicValueType use_dynamic) {
111314f1b3e8SDimitry Andric   if (sp) {
1114f034231aSEd Maste     lldb::TargetSP target_sp(sp->GetTargetSP());
111514f1b3e8SDimitry Andric     if (target_sp) {
111614f1b3e8SDimitry Andric       bool use_synthetic =
111714f1b3e8SDimitry Andric           target_sp->TargetProperties::GetEnableSyntheticValue();
1118f034231aSEd Maste       SetSP(sp, use_dynamic, use_synthetic);
111914f1b3e8SDimitry Andric     } else
1120f034231aSEd Maste       SetSP(sp, use_dynamic, true);
112114f1b3e8SDimitry Andric   } else
1122f034231aSEd Maste     SetSP(sp, use_dynamic, false);
1123f034231aSEd Maste }
1124f034231aSEd Maste 
SetSP(const lldb::ValueObjectSP & sp,bool use_synthetic)112514f1b3e8SDimitry Andric void SBValue::SetSP(const lldb::ValueObjectSP &sp, bool use_synthetic) {
112614f1b3e8SDimitry Andric   if (sp) {
1127f034231aSEd Maste     lldb::TargetSP target_sp(sp->GetTargetSP());
112814f1b3e8SDimitry Andric     if (target_sp) {
1129f034231aSEd Maste       lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1130f034231aSEd Maste       SetSP(sp, use_dynamic, use_synthetic);
113114f1b3e8SDimitry Andric     } else
1132f034231aSEd Maste       SetSP(sp, eNoDynamicValues, use_synthetic);
113314f1b3e8SDimitry Andric   } else
1134f034231aSEd Maste     SetSP(sp, eNoDynamicValues, use_synthetic);
1135f034231aSEd Maste }
1136f034231aSEd Maste 
SetSP(const lldb::ValueObjectSP & sp,lldb::DynamicValueType use_dynamic,bool use_synthetic)113714f1b3e8SDimitry Andric void SBValue::SetSP(const lldb::ValueObjectSP &sp,
113814f1b3e8SDimitry Andric                     lldb::DynamicValueType use_dynamic, bool use_synthetic) {
1139f034231aSEd Maste   m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1140f034231aSEd Maste }
1141f034231aSEd Maste 
SetSP(const lldb::ValueObjectSP & sp,lldb::DynamicValueType use_dynamic,bool use_synthetic,const char * name)114214f1b3e8SDimitry Andric void SBValue::SetSP(const lldb::ValueObjectSP &sp,
114314f1b3e8SDimitry Andric                     lldb::DynamicValueType use_dynamic, bool use_synthetic,
114414f1b3e8SDimitry Andric                     const char *name) {
114514f1b3e8SDimitry Andric   m_opaque_sp =
114614f1b3e8SDimitry Andric       ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic, name));
1147f034231aSEd Maste }
1148f034231aSEd Maste 
GetExpressionPath(SBStream & description)114914f1b3e8SDimitry Andric bool SBValue::GetExpressionPath(SBStream &description) {
11506f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, description);
11515f29bb8aSDimitry Andric 
1152f034231aSEd Maste   ValueLocker locker;
1153f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
115414f1b3e8SDimitry Andric   if (value_sp) {
1155cfca06d7SDimitry Andric     value_sp->GetExpressionPath(description.ref());
1156f034231aSEd Maste     return true;
1157f034231aSEd Maste   }
1158f034231aSEd Maste   return false;
1159f034231aSEd Maste }
1160f034231aSEd Maste 
GetExpressionPath(SBStream & description,bool qualify_cxx_base_classes)116114f1b3e8SDimitry Andric bool SBValue::GetExpressionPath(SBStream &description,
116214f1b3e8SDimitry Andric                                 bool qualify_cxx_base_classes) {
11636f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, description, qualify_cxx_base_classes);
11645f29bb8aSDimitry Andric 
1165f034231aSEd Maste   ValueLocker locker;
1166f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
116714f1b3e8SDimitry Andric   if (value_sp) {
1168cfca06d7SDimitry Andric     value_sp->GetExpressionPath(description.ref());
1169f034231aSEd Maste     return true;
1170f034231aSEd Maste   }
1171f034231aSEd Maste   return false;
1172f034231aSEd Maste }
1173f034231aSEd Maste 
EvaluateExpression(const char * expr) const11745f29bb8aSDimitry Andric lldb::SBValue SBValue::EvaluateExpression(const char *expr) const {
11756f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, expr);
11765f29bb8aSDimitry Andric 
11775f29bb8aSDimitry Andric   ValueLocker locker;
11785f29bb8aSDimitry Andric   lldb::ValueObjectSP value_sp(GetSP(locker));
11795f29bb8aSDimitry Andric   if (!value_sp)
11806f8fc217SDimitry Andric     return SBValue();
11815f29bb8aSDimitry Andric 
11825f29bb8aSDimitry Andric   lldb::TargetSP target_sp = value_sp->GetTargetSP();
11835f29bb8aSDimitry Andric   if (!target_sp)
11846f8fc217SDimitry Andric     return SBValue();
11855f29bb8aSDimitry Andric 
11865f29bb8aSDimitry Andric   lldb::SBExpressionOptions options;
11875f29bb8aSDimitry Andric   options.SetFetchDynamicValue(target_sp->GetPreferDynamicValue());
11885f29bb8aSDimitry Andric   options.SetUnwindOnError(true);
11895f29bb8aSDimitry Andric   options.SetIgnoreBreakpoints(true);
11905f29bb8aSDimitry Andric 
11916f8fc217SDimitry Andric   return EvaluateExpression(expr, options, nullptr);
11925f29bb8aSDimitry Andric }
11935f29bb8aSDimitry Andric 
11945f29bb8aSDimitry Andric lldb::SBValue
EvaluateExpression(const char * expr,const SBExpressionOptions & options) const11955f29bb8aSDimitry Andric SBValue::EvaluateExpression(const char *expr,
11965f29bb8aSDimitry Andric                             const SBExpressionOptions &options) const {
11976f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, expr, options);
11985f29bb8aSDimitry Andric 
11996f8fc217SDimitry Andric   return EvaluateExpression(expr, options, nullptr);
12005f29bb8aSDimitry Andric }
12015f29bb8aSDimitry Andric 
EvaluateExpression(const char * expr,const SBExpressionOptions & options,const char * name) const12025f29bb8aSDimitry Andric lldb::SBValue SBValue::EvaluateExpression(const char *expr,
12035f29bb8aSDimitry Andric                                           const SBExpressionOptions &options,
12045f29bb8aSDimitry Andric                                           const char *name) const {
12056f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, expr, options, name);
12065f29bb8aSDimitry Andric 
12075f29bb8aSDimitry Andric   if (!expr || expr[0] == '\0') {
12086f8fc217SDimitry Andric     return SBValue();
12095f29bb8aSDimitry Andric   }
12105f29bb8aSDimitry Andric 
12115f29bb8aSDimitry Andric 
12125f29bb8aSDimitry Andric   ValueLocker locker;
12135f29bb8aSDimitry Andric   lldb::ValueObjectSP value_sp(GetSP(locker));
12145f29bb8aSDimitry Andric   if (!value_sp) {
12156f8fc217SDimitry Andric     return SBValue();
12165f29bb8aSDimitry Andric   }
12175f29bb8aSDimitry Andric 
12185f29bb8aSDimitry Andric   lldb::TargetSP target_sp = value_sp->GetTargetSP();
12195f29bb8aSDimitry Andric   if (!target_sp) {
12206f8fc217SDimitry Andric     return SBValue();
12215f29bb8aSDimitry Andric   }
12225f29bb8aSDimitry Andric 
12235f29bb8aSDimitry Andric   std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
12245f29bb8aSDimitry Andric   ExecutionContext exe_ctx(target_sp.get());
12255f29bb8aSDimitry Andric 
12265f29bb8aSDimitry Andric   StackFrame *frame = exe_ctx.GetFramePtr();
12275f29bb8aSDimitry Andric   if (!frame) {
12286f8fc217SDimitry Andric     return SBValue();
12295f29bb8aSDimitry Andric   }
12305f29bb8aSDimitry Andric 
12315f29bb8aSDimitry Andric   ValueObjectSP res_val_sp;
12325f29bb8aSDimitry Andric   target_sp->EvaluateExpression(expr, frame, res_val_sp, options.ref(), nullptr,
12335f29bb8aSDimitry Andric                                 value_sp.get());
12345f29bb8aSDimitry Andric 
12355f29bb8aSDimitry Andric   if (name)
12365f29bb8aSDimitry Andric     res_val_sp->SetName(ConstString(name));
12375f29bb8aSDimitry Andric 
12385f29bb8aSDimitry Andric   SBValue result;
12395f29bb8aSDimitry Andric   result.SetSP(res_val_sp, options.GetFetchDynamicValue());
12406f8fc217SDimitry Andric   return result;
12415f29bb8aSDimitry Andric }
12425f29bb8aSDimitry Andric 
GetDescription(SBStream & description)124314f1b3e8SDimitry Andric bool SBValue::GetDescription(SBStream &description) {
12446f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, description);
12455f29bb8aSDimitry Andric 
1246f034231aSEd Maste   Stream &strm = description.ref();
1247f034231aSEd Maste 
1248f034231aSEd Maste   ValueLocker locker;
1249f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
125099aabd70SDimitry Andric   if (value_sp) {
125199aabd70SDimitry Andric     DumpValueObjectOptions options;
125299aabd70SDimitry Andric     options.SetUseDynamicType(m_opaque_sp->GetUseDynamic());
125399aabd70SDimitry Andric     options.SetUseSyntheticValue(m_opaque_sp->GetUseSynthetic());
1254ac9a064cSDimitry Andric     if (llvm::Error error = value_sp->Dump(strm, options)) {
1255ac9a064cSDimitry Andric       strm << "error: " << toString(std::move(error));
1256ac9a064cSDimitry Andric       return false;
1257ac9a064cSDimitry Andric     }
125899aabd70SDimitry Andric   } else {
1259f034231aSEd Maste     strm.PutCString("No value");
126099aabd70SDimitry Andric   }
1261f034231aSEd Maste 
1262f034231aSEd Maste   return true;
1263f034231aSEd Maste }
1264f034231aSEd Maste 
GetFormat()126514f1b3e8SDimitry Andric lldb::Format SBValue::GetFormat() {
12666f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
12675f29bb8aSDimitry Andric 
1268f034231aSEd Maste   ValueLocker locker;
1269f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1270f034231aSEd Maste   if (value_sp)
1271f034231aSEd Maste     return value_sp->GetFormat();
1272f034231aSEd Maste   return eFormatDefault;
1273f034231aSEd Maste }
1274f034231aSEd Maste 
SetFormat(lldb::Format format)127514f1b3e8SDimitry Andric void SBValue::SetFormat(lldb::Format format) {
12766f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, format);
12775f29bb8aSDimitry Andric 
1278f034231aSEd Maste   ValueLocker locker;
1279f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1280f034231aSEd Maste   if (value_sp)
1281f034231aSEd Maste     value_sp->SetFormat(format);
1282f034231aSEd Maste }
1283f034231aSEd Maste 
AddressOf()128414f1b3e8SDimitry Andric lldb::SBValue SBValue::AddressOf() {
12856f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
12865f29bb8aSDimitry Andric 
1287f034231aSEd Maste   SBValue sb_value;
1288f034231aSEd Maste   ValueLocker locker;
1289f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
129014f1b3e8SDimitry Andric   if (value_sp) {
1291b76161e4SDimitry Andric     Status error;
129214f1b3e8SDimitry Andric     sb_value.SetSP(value_sp->AddressOf(error), GetPreferDynamicValue(),
129314f1b3e8SDimitry Andric                    GetPreferSyntheticValue());
1294f034231aSEd Maste   }
1295f034231aSEd Maste 
12966f8fc217SDimitry Andric   return sb_value;
1297f034231aSEd Maste }
1298f034231aSEd Maste 
GetLoadAddress()129914f1b3e8SDimitry Andric lldb::addr_t SBValue::GetLoadAddress() {
13006f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
13015f29bb8aSDimitry Andric 
1302f034231aSEd Maste   lldb::addr_t value = LLDB_INVALID_ADDRESS;
1303f034231aSEd Maste   ValueLocker locker;
1304f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1305ac9a064cSDimitry Andric   if (value_sp)
1306ac9a064cSDimitry Andric     return value_sp->GetLoadAddress();
1307f034231aSEd Maste 
1308f034231aSEd Maste   return value;
1309f034231aSEd Maste }
1310f034231aSEd Maste 
GetAddress()131114f1b3e8SDimitry Andric lldb::SBAddress SBValue::GetAddress() {
13126f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
13135f29bb8aSDimitry Andric 
1314f034231aSEd Maste   Address addr;
1315f034231aSEd Maste   ValueLocker locker;
1316f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
131714f1b3e8SDimitry Andric   if (value_sp) {
1318f034231aSEd Maste     TargetSP target_sp(value_sp->GetTargetSP());
131914f1b3e8SDimitry Andric     if (target_sp) {
1320f034231aSEd Maste       lldb::addr_t value = LLDB_INVALID_ADDRESS;
1321f034231aSEd Maste       const bool scalar_is_load_address = true;
1322f034231aSEd Maste       AddressType addr_type;
1323f034231aSEd Maste       value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
132414f1b3e8SDimitry Andric       if (addr_type == eAddressTypeFile) {
1325f034231aSEd Maste         ModuleSP module_sp(value_sp->GetModule());
1326f034231aSEd Maste         if (module_sp)
1327f034231aSEd Maste           module_sp->ResolveFileAddress(value, addr);
132814f1b3e8SDimitry Andric       } else if (addr_type == eAddressTypeLoad) {
1329f73363f1SDimitry Andric         // no need to check the return value on this.. if it can actually do
1330f73363f1SDimitry Andric         // the resolve addr will be in the form (section,offset), otherwise it
1331f73363f1SDimitry Andric         // will simply be returned as (NULL, value)
1332f034231aSEd Maste         addr.SetLoadAddress(value, target_sp.get());
1333f034231aSEd Maste       }
1334f034231aSEd Maste     }
1335f034231aSEd Maste   }
13365f29bb8aSDimitry Andric 
13376f8fc217SDimitry Andric   return SBAddress(addr);
1338f034231aSEd Maste }
1339f034231aSEd Maste 
GetPointeeData(uint32_t item_idx,uint32_t item_count)134014f1b3e8SDimitry Andric lldb::SBData SBValue::GetPointeeData(uint32_t item_idx, uint32_t item_count) {
13416f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, item_idx, item_count);
13425f29bb8aSDimitry Andric 
1343f034231aSEd Maste   lldb::SBData sb_data;
1344f034231aSEd Maste   ValueLocker locker;
1345f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
134614f1b3e8SDimitry Andric   if (value_sp) {
1347f034231aSEd Maste     TargetSP target_sp(value_sp->GetTargetSP());
134814f1b3e8SDimitry Andric     if (target_sp) {
1349f034231aSEd Maste       DataExtractorSP data_sp(new DataExtractor());
1350f034231aSEd Maste       value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1351f034231aSEd Maste       if (data_sp->GetByteSize() > 0)
1352f034231aSEd Maste         *sb_data = data_sp;
1353f034231aSEd Maste     }
1354f034231aSEd Maste   }
1355f034231aSEd Maste 
13566f8fc217SDimitry Andric   return sb_data;
1357f034231aSEd Maste }
1358f034231aSEd Maste 
GetData()135914f1b3e8SDimitry Andric lldb::SBData SBValue::GetData() {
13606f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
13615f29bb8aSDimitry Andric 
1362f034231aSEd Maste   lldb::SBData sb_data;
1363f034231aSEd Maste   ValueLocker locker;
1364f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
136514f1b3e8SDimitry Andric   if (value_sp) {
1366f034231aSEd Maste     DataExtractorSP data_sp(new DataExtractor());
1367b76161e4SDimitry Andric     Status error;
13680cac4ca3SEd Maste     value_sp->GetData(*data_sp, error);
13690cac4ca3SEd Maste     if (error.Success())
1370f034231aSEd Maste       *sb_data = data_sp;
1371f034231aSEd Maste   }
1372f034231aSEd Maste 
13736f8fc217SDimitry Andric   return sb_data;
1374f034231aSEd Maste }
1375f034231aSEd Maste 
SetData(lldb::SBData & data,SBError & error)137614f1b3e8SDimitry Andric bool SBValue::SetData(lldb::SBData &data, SBError &error) {
13776f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, data, error);
13785f29bb8aSDimitry Andric 
1379f034231aSEd Maste   ValueLocker locker;
1380f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1381f034231aSEd Maste   bool ret = true;
1382f034231aSEd Maste 
138314f1b3e8SDimitry Andric   if (value_sp) {
1384f034231aSEd Maste     DataExtractor *data_extractor = data.get();
1385f034231aSEd Maste 
138614f1b3e8SDimitry Andric     if (!data_extractor) {
1387f034231aSEd Maste       error.SetErrorString("No data to set");
1388f034231aSEd Maste       ret = false;
138914f1b3e8SDimitry Andric     } else {
1390b76161e4SDimitry Andric       Status set_error;
1391f034231aSEd Maste 
1392f034231aSEd Maste       value_sp->SetData(*data_extractor, set_error);
1393f034231aSEd Maste 
139414f1b3e8SDimitry Andric       if (!set_error.Success()) {
139514f1b3e8SDimitry Andric         error.SetErrorStringWithFormat("Couldn't set data: %s",
139614f1b3e8SDimitry Andric                                        set_error.AsCString());
1397f034231aSEd Maste         ret = false;
1398f034231aSEd Maste       }
1399f034231aSEd Maste     }
140014f1b3e8SDimitry Andric   } else {
140114f1b3e8SDimitry Andric     error.SetErrorStringWithFormat(
140214f1b3e8SDimitry Andric         "Couldn't set data: could not get SBValue: %s",
140314f1b3e8SDimitry Andric         locker.GetError().AsCString());
1404f034231aSEd Maste     ret = false;
1405f034231aSEd Maste   }
1406f034231aSEd Maste 
1407f034231aSEd Maste   return ret;
1408f034231aSEd Maste }
1409f034231aSEd Maste 
Clone(const char * new_name)1410f65dcba8SDimitry Andric lldb::SBValue SBValue::Clone(const char *new_name) {
14116f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, new_name);
1412f65dcba8SDimitry Andric 
1413f65dcba8SDimitry Andric   ValueLocker locker;
1414f65dcba8SDimitry Andric   lldb::ValueObjectSP value_sp(GetSP(locker));
1415f65dcba8SDimitry Andric 
1416f65dcba8SDimitry Andric   if (value_sp)
1417f65dcba8SDimitry Andric     return lldb::SBValue(value_sp->Clone(ConstString(new_name)));
1418f65dcba8SDimitry Andric   else
1419f65dcba8SDimitry Andric     return lldb::SBValue();
1420f65dcba8SDimitry Andric }
1421f65dcba8SDimitry Andric 
GetDeclaration()142214f1b3e8SDimitry Andric lldb::SBDeclaration SBValue::GetDeclaration() {
14236f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
14245f29bb8aSDimitry Andric 
1425f034231aSEd Maste   ValueLocker locker;
1426f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1427f034231aSEd Maste   SBDeclaration decl_sb;
142814f1b3e8SDimitry Andric   if (value_sp) {
1429f034231aSEd Maste     Declaration decl;
1430f034231aSEd Maste     if (value_sp->GetDeclaration(decl))
1431f034231aSEd Maste       decl_sb.SetDeclaration(decl);
1432f034231aSEd Maste   }
14336f8fc217SDimitry Andric   return decl_sb;
1434f034231aSEd Maste }
1435f034231aSEd Maste 
Watch(bool resolve_location,bool read,bool write,SBError & error)143614f1b3e8SDimitry Andric lldb::SBWatchpoint SBValue::Watch(bool resolve_location, bool read, bool write,
143714f1b3e8SDimitry Andric                                   SBError &error) {
14386f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, resolve_location, read, write, error);
14395f29bb8aSDimitry Andric 
1440f034231aSEd Maste   SBWatchpoint sb_watchpoint;
1441f034231aSEd Maste 
1442f034231aSEd Maste   // If the SBValue is not valid, there's no point in even trying to watch it.
1443f034231aSEd Maste   ValueLocker locker;
1444f034231aSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1445f034231aSEd Maste   TargetSP target_sp(GetTarget().GetSP());
144614f1b3e8SDimitry Andric   if (value_sp && target_sp) {
1447f034231aSEd Maste     // Read and Write cannot both be false.
1448f034231aSEd Maste     if (!read && !write)
14496f8fc217SDimitry Andric       return sb_watchpoint;
1450f034231aSEd Maste 
1451f034231aSEd Maste     // If the value is not in scope, don't try and watch and invalid value
1452f034231aSEd Maste     if (!IsInScope())
14536f8fc217SDimitry Andric       return sb_watchpoint;
1454f034231aSEd Maste 
1455f034231aSEd Maste     addr_t addr = GetLoadAddress();
1456f034231aSEd Maste     if (addr == LLDB_INVALID_ADDRESS)
14576f8fc217SDimitry Andric       return sb_watchpoint;
1458f034231aSEd Maste     size_t byte_size = GetByteSize();
1459f034231aSEd Maste     if (byte_size == 0)
14606f8fc217SDimitry Andric       return sb_watchpoint;
1461f034231aSEd Maste 
1462f034231aSEd Maste     uint32_t watch_type = 0;
1463b1c73532SDimitry Andric     if (read) {
1464f034231aSEd Maste       watch_type |= LLDB_WATCH_TYPE_READ;
1465b1c73532SDimitry Andric       // read + write, the most likely intention
1466b1c73532SDimitry Andric       // is to catch all writes to this, not just
1467b1c73532SDimitry Andric       // value modifications.
1468f034231aSEd Maste       if (write)
1469f034231aSEd Maste         watch_type |= LLDB_WATCH_TYPE_WRITE;
1470b1c73532SDimitry Andric     } else {
1471b1c73532SDimitry Andric       if (write)
1472b1c73532SDimitry Andric         watch_type |= LLDB_WATCH_TYPE_MODIFY;
1473b1c73532SDimitry Andric     }
1474f034231aSEd Maste 
1475b76161e4SDimitry Andric     Status rc;
1476e81d9d49SDimitry Andric     CompilerType type(value_sp->GetCompilerType());
147714f1b3e8SDimitry Andric     WatchpointSP watchpoint_sp =
147814f1b3e8SDimitry Andric         target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
1479f034231aSEd Maste     error.SetError(rc);
1480f034231aSEd Maste 
148114f1b3e8SDimitry Andric     if (watchpoint_sp) {
1482f034231aSEd Maste       sb_watchpoint.SetSP(watchpoint_sp);
1483f034231aSEd Maste       Declaration decl;
148414f1b3e8SDimitry Andric       if (value_sp->GetDeclaration(decl)) {
148514f1b3e8SDimitry Andric         if (decl.GetFile()) {
1486f034231aSEd Maste           StreamString ss;
1487f034231aSEd Maste           // True to show fullpath for declaration file.
1488f034231aSEd Maste           decl.DumpStopContext(&ss, true);
1489cfca06d7SDimitry Andric           watchpoint_sp->SetDeclInfo(std::string(ss.GetString()));
1490f034231aSEd Maste         }
1491f034231aSEd Maste       }
1492f034231aSEd Maste     }
149314f1b3e8SDimitry Andric   } else if (target_sp) {
149414f1b3e8SDimitry Andric     error.SetErrorStringWithFormat("could not get SBValue: %s",
149514f1b3e8SDimitry Andric                                    locker.GetError().AsCString());
149614f1b3e8SDimitry Andric   } else {
1497f034231aSEd Maste     error.SetErrorString("could not set watchpoint, a target is required");
1498f034231aSEd Maste   }
1499f034231aSEd Maste 
15006f8fc217SDimitry Andric   return sb_watchpoint;
1501f034231aSEd Maste }
1502f034231aSEd Maste 
150314f1b3e8SDimitry Andric // FIXME: Remove this method impl (as well as the decl in .h) once it is no
150414f1b3e8SDimitry Andric // longer needed.
1505f034231aSEd Maste // Backward compatibility fix in the interim.
Watch(bool resolve_location,bool read,bool write)150614f1b3e8SDimitry Andric lldb::SBWatchpoint SBValue::Watch(bool resolve_location, bool read,
150714f1b3e8SDimitry Andric                                   bool write) {
15086f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, resolve_location, read, write);
15095f29bb8aSDimitry Andric 
1510f034231aSEd Maste   SBError error;
15116f8fc217SDimitry Andric   return Watch(resolve_location, read, write, error);
1512f034231aSEd Maste }
1513f034231aSEd Maste 
WatchPointee(bool resolve_location,bool read,bool write,SBError & error)151414f1b3e8SDimitry Andric lldb::SBWatchpoint SBValue::WatchPointee(bool resolve_location, bool read,
151514f1b3e8SDimitry Andric                                          bool write, SBError &error) {
15166f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, resolve_location, read, write, error);
15175f29bb8aSDimitry Andric 
1518f034231aSEd Maste   SBWatchpoint sb_watchpoint;
1519f034231aSEd Maste   if (IsInScope() && GetType().IsPointerType())
1520f034231aSEd Maste     sb_watchpoint = Dereference().Watch(resolve_location, read, write, error);
15216f8fc217SDimitry Andric   return sb_watchpoint;
1522f034231aSEd Maste }
1523205afe67SEd Maste 
Persist()152414f1b3e8SDimitry Andric lldb::SBValue SBValue::Persist() {
15256f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
15265f29bb8aSDimitry Andric 
1527205afe67SEd Maste   ValueLocker locker;
1528205afe67SEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1529205afe67SEd Maste   SBValue persisted_sb;
153014f1b3e8SDimitry Andric   if (value_sp) {
1531205afe67SEd Maste     persisted_sb.SetSP(value_sp->Persist());
1532205afe67SEd Maste   }
15336f8fc217SDimitry Andric   return persisted_sb;
1534205afe67SEd Maste }
1535b1c73532SDimitry Andric 
GetVTable()1536b1c73532SDimitry Andric lldb::SBValue SBValue::GetVTable() {
1537b1c73532SDimitry Andric   SBValue vtable_sb;
1538b1c73532SDimitry Andric   ValueLocker locker;
1539b1c73532SDimitry Andric   lldb::ValueObjectSP value_sp(GetSP(locker));
1540b1c73532SDimitry Andric   if (!value_sp)
1541b1c73532SDimitry Andric     return vtable_sb;
1542b1c73532SDimitry Andric 
1543b1c73532SDimitry Andric   vtable_sb.SetSP(value_sp->GetVTable());
1544b1c73532SDimitry Andric   return vtable_sb;
1545b1c73532SDimitry Andric }
1546