1ac7ddfbfSEd Maste //===-- SBValue.cpp ---------------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste //                     The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste 
10ac7ddfbfSEd Maste #include "lldb/API/SBValue.h"
11ac7ddfbfSEd Maste 
12ac7ddfbfSEd Maste #include "lldb/API/SBDeclaration.h"
13ac7ddfbfSEd Maste #include "lldb/API/SBStream.h"
14ac7ddfbfSEd Maste #include "lldb/API/SBTypeFilter.h"
15ac7ddfbfSEd Maste #include "lldb/API/SBTypeFormat.h"
16ac7ddfbfSEd Maste #include "lldb/API/SBTypeSummary.h"
17ac7ddfbfSEd Maste #include "lldb/API/SBTypeSynthetic.h"
18ac7ddfbfSEd Maste 
19ac7ddfbfSEd Maste #include "lldb/Breakpoint/Watchpoint.h"
20ac7ddfbfSEd Maste #include "lldb/Core/Module.h"
21ac7ddfbfSEd Maste #include "lldb/Core/Section.h"
22ac7ddfbfSEd Maste #include "lldb/Core/StreamFile.h"
23ac7ddfbfSEd Maste #include "lldb/Core/Value.h"
24ac7ddfbfSEd Maste #include "lldb/Core/ValueObject.h"
25ac7ddfbfSEd Maste #include "lldb/Core/ValueObjectConstResult.h"
26ac7ddfbfSEd Maste #include "lldb/DataFormatters/DataVisualization.h"
27ac7ddfbfSEd Maste #include "lldb/Symbol/Block.h"
28ac7ddfbfSEd Maste #include "lldb/Symbol/Declaration.h"
29ac7ddfbfSEd Maste #include "lldb/Symbol/ObjectFile.h"
30ac7ddfbfSEd Maste #include "lldb/Symbol/Type.h"
31ac7ddfbfSEd Maste #include "lldb/Symbol/Variable.h"
32ac7ddfbfSEd Maste #include "lldb/Symbol/VariableList.h"
33ac7ddfbfSEd Maste #include "lldb/Target/ExecutionContext.h"
34ac7ddfbfSEd Maste #include "lldb/Target/Process.h"
35ac7ddfbfSEd Maste #include "lldb/Target/StackFrame.h"
36ac7ddfbfSEd Maste #include "lldb/Target/Target.h"
37ac7ddfbfSEd Maste #include "lldb/Target/Thread.h"
38f678e45dSDimitry Andric #include "lldb/Utility/DataExtractor.h"
39f678e45dSDimitry Andric #include "lldb/Utility/Log.h"
40*b5893f02SDimitry Andric #include "lldb/Utility/Scalar.h"
41f678e45dSDimitry Andric #include "lldb/Utility/Stream.h"
42ac7ddfbfSEd Maste 
43ac7ddfbfSEd Maste #include "lldb/API/SBDebugger.h"
44ac7ddfbfSEd Maste #include "lldb/API/SBExpressionOptions.h"
45ac7ddfbfSEd Maste #include "lldb/API/SBFrame.h"
46ac7ddfbfSEd Maste #include "lldb/API/SBProcess.h"
47ac7ddfbfSEd Maste #include "lldb/API/SBTarget.h"
48ac7ddfbfSEd Maste #include "lldb/API/SBThread.h"
49ac7ddfbfSEd Maste 
50ac7ddfbfSEd Maste using namespace lldb;
51ac7ddfbfSEd Maste using namespace lldb_private;
52ac7ddfbfSEd Maste 
53435933ddSDimitry Andric class ValueImpl {
54ac7ddfbfSEd Maste public:
ValueImpl()55435933ddSDimitry Andric   ValueImpl() {}
56ac7ddfbfSEd Maste 
ValueImpl(lldb::ValueObjectSP in_valobj_sp,lldb::DynamicValueType use_dynamic,bool use_synthetic,const char * name=NULL)57ac7ddfbfSEd Maste   ValueImpl(lldb::ValueObjectSP in_valobj_sp,
58435933ddSDimitry Andric             lldb::DynamicValueType use_dynamic, bool use_synthetic,
59435933ddSDimitry Andric             const char *name = NULL)
60435933ddSDimitry Andric       : m_valobj_sp(), m_use_dynamic(use_dynamic),
61435933ddSDimitry Andric         m_use_synthetic(use_synthetic), m_name(name) {
62435933ddSDimitry Andric     if (in_valobj_sp) {
63435933ddSDimitry Andric       if ((m_valobj_sp = in_valobj_sp->GetQualifiedRepresentationIfAvailable(
64435933ddSDimitry Andric                lldb::eNoDynamicValues, false))) {
651c3bbb01SEd Maste         if (!m_name.IsEmpty())
66ac7ddfbfSEd Maste           m_valobj_sp->SetName(m_name);
67ac7ddfbfSEd Maste       }
681c3bbb01SEd Maste     }
691c3bbb01SEd Maste   }
70ac7ddfbfSEd Maste 
ValueImpl(const ValueImpl & rhs)71435933ddSDimitry Andric   ValueImpl(const ValueImpl &rhs)
72435933ddSDimitry Andric       : m_valobj_sp(rhs.m_valobj_sp), m_use_dynamic(rhs.m_use_dynamic),
73435933ddSDimitry Andric         m_use_synthetic(rhs.m_use_synthetic), m_name(rhs.m_name) {}
74ac7ddfbfSEd Maste 
operator =(const ValueImpl & rhs)75435933ddSDimitry Andric   ValueImpl &operator=(const ValueImpl &rhs) {
76435933ddSDimitry Andric     if (this != &rhs) {
77ac7ddfbfSEd Maste       m_valobj_sp = rhs.m_valobj_sp;
78ac7ddfbfSEd Maste       m_use_dynamic = rhs.m_use_dynamic;
79ac7ddfbfSEd Maste       m_use_synthetic = rhs.m_use_synthetic;
80ac7ddfbfSEd Maste       m_name = rhs.m_name;
81ac7ddfbfSEd Maste     }
82ac7ddfbfSEd Maste     return *this;
83ac7ddfbfSEd Maste   }
84ac7ddfbfSEd Maste 
IsValid()85435933ddSDimitry Andric   bool IsValid() {
8612b93ac6SEd Maste     if (m_valobj_sp.get() == NULL)
8712b93ac6SEd Maste       return false;
88435933ddSDimitry Andric     else {
89435933ddSDimitry Andric       // FIXME: This check is necessary but not sufficient.  We for sure don't
90435933ddSDimitry Andric       // want to touch SBValues whose owning
91435933ddSDimitry Andric       // targets have gone away.  This check is a little weak in that it
924ba319b5SDimitry Andric       // enforces that restriction when you call IsValid, but since IsValid
934ba319b5SDimitry Andric       // doesn't lock the target, you have no guarantee that the SBValue won't
944ba319b5SDimitry Andric       // go invalid after you call this... Also, an SBValue could depend on
954ba319b5SDimitry Andric       // data from one of the modules in the target, and those could go away
964ba319b5SDimitry Andric       // independently of the target, for instance if a module is unloaded.
974ba319b5SDimitry Andric       // But right now, neither SBValues nor ValueObjects know which modules
984ba319b5SDimitry Andric       // they depend on.  So I have no good way to make that check without
9912b93ac6SEd Maste       // tracking that in all the ValueObject subclasses.
10012b93ac6SEd Maste       TargetSP target_sp = m_valobj_sp->GetTargetSP();
101*b5893f02SDimitry Andric       return target_sp && target_sp->IsValid();
10212b93ac6SEd Maste     }
103ac7ddfbfSEd Maste   }
104ac7ddfbfSEd Maste 
GetRootSP()105435933ddSDimitry Andric   lldb::ValueObjectSP GetRootSP() { return m_valobj_sp; }
106ac7ddfbfSEd Maste 
GetSP(Process::StopLocker & stop_locker,std::unique_lock<std::recursive_mutex> & lock,Status & error)107435933ddSDimitry Andric   lldb::ValueObjectSP GetSP(Process::StopLocker &stop_locker,
108435933ddSDimitry Andric                             std::unique_lock<std::recursive_mutex> &lock,
1095517e702SDimitry Andric                             Status &error) {
110ac7ddfbfSEd Maste     Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
111435933ddSDimitry Andric     if (!m_valobj_sp) {
112ac7ddfbfSEd Maste       error.SetErrorString("invalid value object");
113ac7ddfbfSEd Maste       return m_valobj_sp;
114ac7ddfbfSEd Maste     }
115ac7ddfbfSEd Maste 
116ac7ddfbfSEd Maste     lldb::ValueObjectSP value_sp = m_valobj_sp;
117ac7ddfbfSEd Maste 
118ac7ddfbfSEd Maste     Target *target = value_sp->GetTargetSP().get();
1194bb0738eSEd Maste     if (!target)
12012b93ac6SEd Maste       return ValueObjectSP();
121ac7ddfbfSEd Maste 
1224bb0738eSEd Maste     lock = std::unique_lock<std::recursive_mutex>(target->GetAPIMutex());
1234bb0738eSEd Maste 
124ac7ddfbfSEd Maste     ProcessSP process_sp(value_sp->GetProcessSP());
125435933ddSDimitry Andric     if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock())) {
1264ba319b5SDimitry Andric       // We don't allow people to play around with ValueObject if the process
1274ba319b5SDimitry Andric       // is running. If you want to look at values, pause the process, then
1284ba319b5SDimitry Andric       // look.
129ac7ddfbfSEd Maste       if (log)
1300127ef0fSEd Maste         log->Printf("SBValue(%p)::GetSP() => error: process is running",
1310127ef0fSEd Maste                     static_cast<void *>(value_sp.get()));
132ac7ddfbfSEd Maste       error.SetErrorString("process must be stopped.");
133ac7ddfbfSEd Maste       return ValueObjectSP();
134ac7ddfbfSEd Maste     }
135ac7ddfbfSEd Maste 
136435933ddSDimitry Andric     if (m_use_dynamic != eNoDynamicValues) {
1371c3bbb01SEd Maste       ValueObjectSP dynamic_sp = value_sp->GetDynamicValue(m_use_dynamic);
1381c3bbb01SEd Maste       if (dynamic_sp)
1391c3bbb01SEd Maste         value_sp = dynamic_sp;
1401c3bbb01SEd Maste     }
1411c3bbb01SEd Maste 
142435933ddSDimitry Andric     if (m_use_synthetic) {
1431c3bbb01SEd Maste       ValueObjectSP synthetic_sp = value_sp->GetSyntheticValue(m_use_synthetic);
1441c3bbb01SEd Maste       if (synthetic_sp)
1451c3bbb01SEd Maste         value_sp = synthetic_sp;
1461c3bbb01SEd Maste     }
1471c3bbb01SEd Maste 
148ac7ddfbfSEd Maste     if (!value_sp)
149ac7ddfbfSEd Maste       error.SetErrorString("invalid value object");
150ac7ddfbfSEd Maste     if (!m_name.IsEmpty())
151ac7ddfbfSEd Maste       value_sp->SetName(m_name);
152ac7ddfbfSEd Maste 
153ac7ddfbfSEd Maste     return value_sp;
154ac7ddfbfSEd Maste   }
155ac7ddfbfSEd Maste 
SetUseDynamic(lldb::DynamicValueType use_dynamic)156435933ddSDimitry Andric   void SetUseDynamic(lldb::DynamicValueType use_dynamic) {
157ac7ddfbfSEd Maste     m_use_dynamic = use_dynamic;
158ac7ddfbfSEd Maste   }
159ac7ddfbfSEd Maste 
SetUseSynthetic(bool use_synthetic)160435933ddSDimitry Andric   void SetUseSynthetic(bool use_synthetic) { m_use_synthetic = use_synthetic; }
161ac7ddfbfSEd Maste 
GetUseDynamic()162435933ddSDimitry Andric   lldb::DynamicValueType GetUseDynamic() { return m_use_dynamic; }
163ac7ddfbfSEd Maste 
GetUseSynthetic()164435933ddSDimitry Andric   bool GetUseSynthetic() { return m_use_synthetic; }
165ac7ddfbfSEd Maste 
166ac7ddfbfSEd Maste   // All the derived values that we would make from the m_valobj_sp will share
167435933ddSDimitry Andric   // the ExecutionContext with m_valobj_sp, so we don't need to do the
1684ba319b5SDimitry Andric   // calculations in GetSP to return the Target, Process, Thread or Frame.  It
1694ba319b5SDimitry Andric   // is convenient to provide simple accessors for these, which I do here.
GetTargetSP()170435933ddSDimitry Andric   TargetSP GetTargetSP() {
171ac7ddfbfSEd Maste     if (m_valobj_sp)
172ac7ddfbfSEd Maste       return m_valobj_sp->GetTargetSP();
173ac7ddfbfSEd Maste     else
174ac7ddfbfSEd Maste       return TargetSP();
175ac7ddfbfSEd Maste   }
176ac7ddfbfSEd Maste 
GetProcessSP()177435933ddSDimitry Andric   ProcessSP GetProcessSP() {
178ac7ddfbfSEd Maste     if (m_valobj_sp)
179ac7ddfbfSEd Maste       return m_valobj_sp->GetProcessSP();
180ac7ddfbfSEd Maste     else
181ac7ddfbfSEd Maste       return ProcessSP();
182ac7ddfbfSEd Maste   }
183ac7ddfbfSEd Maste 
GetThreadSP()184435933ddSDimitry Andric   ThreadSP GetThreadSP() {
185ac7ddfbfSEd Maste     if (m_valobj_sp)
186ac7ddfbfSEd Maste       return m_valobj_sp->GetThreadSP();
187ac7ddfbfSEd Maste     else
188ac7ddfbfSEd Maste       return ThreadSP();
189ac7ddfbfSEd Maste   }
190ac7ddfbfSEd Maste 
GetFrameSP()191435933ddSDimitry Andric   StackFrameSP GetFrameSP() {
192ac7ddfbfSEd Maste     if (m_valobj_sp)
193ac7ddfbfSEd Maste       return m_valobj_sp->GetFrameSP();
194ac7ddfbfSEd Maste     else
195ac7ddfbfSEd Maste       return StackFrameSP();
196ac7ddfbfSEd Maste   }
197ac7ddfbfSEd Maste 
198ac7ddfbfSEd Maste private:
199ac7ddfbfSEd Maste   lldb::ValueObjectSP m_valobj_sp;
200ac7ddfbfSEd Maste   lldb::DynamicValueType m_use_dynamic;
201ac7ddfbfSEd Maste   bool m_use_synthetic;
202ac7ddfbfSEd Maste   ConstString m_name;
203ac7ddfbfSEd Maste };
204ac7ddfbfSEd Maste 
205435933ddSDimitry Andric class ValueLocker {
206ac7ddfbfSEd Maste public:
ValueLocker()207435933ddSDimitry Andric   ValueLocker() {}
208ac7ddfbfSEd Maste 
GetLockedSP(ValueImpl & in_value)209435933ddSDimitry Andric   ValueObjectSP GetLockedSP(ValueImpl &in_value) {
2104bb0738eSEd Maste     return in_value.GetSP(m_stop_locker, m_lock, m_lock_error);
211ac7ddfbfSEd Maste   }
212ac7ddfbfSEd Maste 
GetError()2135517e702SDimitry Andric   Status &GetError() { return m_lock_error; }
214ac7ddfbfSEd Maste 
215ac7ddfbfSEd Maste private:
216ac7ddfbfSEd Maste   Process::StopLocker m_stop_locker;
2174bb0738eSEd Maste   std::unique_lock<std::recursive_mutex> m_lock;
2185517e702SDimitry Andric   Status m_lock_error;
219ac7ddfbfSEd Maste };
220ac7ddfbfSEd Maste 
SBValue()221435933ddSDimitry Andric SBValue::SBValue() : m_opaque_sp() {}
222ac7ddfbfSEd Maste 
SBValue(const lldb::ValueObjectSP & value_sp)223435933ddSDimitry Andric SBValue::SBValue(const lldb::ValueObjectSP &value_sp) { SetSP(value_sp); }
224ac7ddfbfSEd Maste 
SBValue(const SBValue & rhs)225435933ddSDimitry Andric SBValue::SBValue(const SBValue &rhs) { SetSP(rhs.m_opaque_sp); }
226ac7ddfbfSEd Maste 
operator =(const SBValue & rhs)227435933ddSDimitry Andric SBValue &SBValue::operator=(const SBValue &rhs) {
228435933ddSDimitry Andric   if (this != &rhs) {
229ac7ddfbfSEd Maste     SetSP(rhs.m_opaque_sp);
230ac7ddfbfSEd Maste   }
231ac7ddfbfSEd Maste   return *this;
232ac7ddfbfSEd Maste }
233ac7ddfbfSEd Maste 
~SBValue()234435933ddSDimitry Andric SBValue::~SBValue() {}
235ac7ddfbfSEd Maste 
IsValid()236435933ddSDimitry Andric bool SBValue::IsValid() {
2374ba319b5SDimitry Andric   // If this function ever changes to anything that does more than just check
2384ba319b5SDimitry Andric   // if the opaque shared pointer is non NULL, then we need to update all "if
2394ba319b5SDimitry Andric   // (m_opaque_sp)" code in this file.
240435933ddSDimitry Andric   return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid() &&
241435933ddSDimitry Andric          m_opaque_sp->GetRootSP().get() != NULL;
242ac7ddfbfSEd Maste }
243ac7ddfbfSEd Maste 
Clear()244435933ddSDimitry Andric void SBValue::Clear() { m_opaque_sp.reset(); }
245ac7ddfbfSEd Maste 
GetError()246435933ddSDimitry Andric SBError SBValue::GetError() {
247ac7ddfbfSEd Maste   SBError sb_error;
248ac7ddfbfSEd Maste 
249ac7ddfbfSEd Maste   ValueLocker locker;
250ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
251ac7ddfbfSEd Maste   if (value_sp)
252ac7ddfbfSEd Maste     sb_error.SetError(value_sp->GetError());
253ac7ddfbfSEd Maste   else
254435933ddSDimitry Andric     sb_error.SetErrorStringWithFormat("error: %s",
255435933ddSDimitry Andric                                       locker.GetError().AsCString());
256ac7ddfbfSEd Maste 
257ac7ddfbfSEd Maste   return sb_error;
258ac7ddfbfSEd Maste }
259ac7ddfbfSEd Maste 
GetID()260435933ddSDimitry Andric user_id_t SBValue::GetID() {
261ac7ddfbfSEd Maste   ValueLocker locker;
262ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
263ac7ddfbfSEd Maste   if (value_sp)
264ac7ddfbfSEd Maste     return value_sp->GetID();
265ac7ddfbfSEd Maste   return LLDB_INVALID_UID;
266ac7ddfbfSEd Maste }
267ac7ddfbfSEd Maste 
GetName()268435933ddSDimitry Andric const char *SBValue::GetName() {
269ac7ddfbfSEd Maste   const char *name = NULL;
270ac7ddfbfSEd Maste   ValueLocker locker;
271ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
272ac7ddfbfSEd Maste   if (value_sp)
273ac7ddfbfSEd Maste     name = value_sp->GetName().GetCString();
274ac7ddfbfSEd Maste 
275ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
276435933ddSDimitry Andric   if (log) {
277ac7ddfbfSEd Maste     if (name)
2780127ef0fSEd Maste       log->Printf("SBValue(%p)::GetName () => \"%s\"",
2790127ef0fSEd Maste                   static_cast<void *>(value_sp.get()), name);
280ac7ddfbfSEd Maste     else
2810127ef0fSEd Maste       log->Printf("SBValue(%p)::GetName () => NULL",
2820127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
283ac7ddfbfSEd Maste   }
284ac7ddfbfSEd Maste 
285ac7ddfbfSEd Maste   return name;
286ac7ddfbfSEd Maste }
287ac7ddfbfSEd Maste 
GetTypeName()288435933ddSDimitry Andric const char *SBValue::GetTypeName() {
289ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
290ac7ddfbfSEd Maste   const char *name = NULL;
291ac7ddfbfSEd Maste   ValueLocker locker;
292ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
293435933ddSDimitry Andric   if (value_sp) {
294ac7ddfbfSEd Maste     name = value_sp->GetQualifiedTypeName().GetCString();
295ac7ddfbfSEd Maste   }
296ac7ddfbfSEd Maste 
297435933ddSDimitry Andric   if (log) {
298ac7ddfbfSEd Maste     if (name)
2990127ef0fSEd Maste       log->Printf("SBValue(%p)::GetTypeName () => \"%s\"",
3000127ef0fSEd Maste                   static_cast<void *>(value_sp.get()), name);
301ac7ddfbfSEd Maste     else
3020127ef0fSEd Maste       log->Printf("SBValue(%p)::GetTypeName () => NULL",
3030127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
3040127ef0fSEd Maste   }
3050127ef0fSEd Maste 
3060127ef0fSEd Maste   return name;
3070127ef0fSEd Maste }
3080127ef0fSEd Maste 
GetDisplayTypeName()309435933ddSDimitry Andric const char *SBValue::GetDisplayTypeName() {
3100127ef0fSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
3110127ef0fSEd Maste   const char *name = NULL;
3120127ef0fSEd Maste   ValueLocker locker;
3130127ef0fSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
314435933ddSDimitry Andric   if (value_sp) {
3150127ef0fSEd Maste     name = value_sp->GetDisplayTypeName().GetCString();
3160127ef0fSEd Maste   }
3170127ef0fSEd Maste 
318435933ddSDimitry Andric   if (log) {
3190127ef0fSEd Maste     if (name)
3200127ef0fSEd Maste       log->Printf("SBValue(%p)::GetTypeName () => \"%s\"",
3210127ef0fSEd Maste                   static_cast<void *>(value_sp.get()), name);
3220127ef0fSEd Maste     else
3230127ef0fSEd Maste       log->Printf("SBValue(%p)::GetTypeName () => NULL",
3240127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
325ac7ddfbfSEd Maste   }
326ac7ddfbfSEd Maste 
327ac7ddfbfSEd Maste   return name;
328ac7ddfbfSEd Maste }
329ac7ddfbfSEd Maste 
GetByteSize()330435933ddSDimitry Andric size_t SBValue::GetByteSize() {
331ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
332ac7ddfbfSEd Maste   size_t result = 0;
333ac7ddfbfSEd Maste 
334ac7ddfbfSEd Maste   ValueLocker locker;
335ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
336435933ddSDimitry Andric   if (value_sp) {
337ac7ddfbfSEd Maste     result = value_sp->GetByteSize();
338ac7ddfbfSEd Maste   }
339ac7ddfbfSEd Maste 
340ac7ddfbfSEd Maste   if (log)
3410127ef0fSEd Maste     log->Printf("SBValue(%p)::GetByteSize () => %" PRIu64,
3420127ef0fSEd Maste                 static_cast<void *>(value_sp.get()),
3430127ef0fSEd Maste                 static_cast<uint64_t>(result));
344ac7ddfbfSEd Maste 
345ac7ddfbfSEd Maste   return result;
346ac7ddfbfSEd Maste }
347ac7ddfbfSEd Maste 
IsInScope()348435933ddSDimitry Andric bool SBValue::IsInScope() {
349ac7ddfbfSEd Maste   bool result = false;
350ac7ddfbfSEd Maste 
351ac7ddfbfSEd Maste   ValueLocker locker;
352ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
353435933ddSDimitry Andric   if (value_sp) {
354ac7ddfbfSEd Maste     result = value_sp->IsInScope();
355ac7ddfbfSEd Maste   }
356ac7ddfbfSEd Maste 
357ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
358ac7ddfbfSEd Maste   if (log)
3590127ef0fSEd Maste     log->Printf("SBValue(%p)::IsInScope () => %i",
3600127ef0fSEd Maste                 static_cast<void *>(value_sp.get()), result);
361ac7ddfbfSEd Maste 
362ac7ddfbfSEd Maste   return result;
363ac7ddfbfSEd Maste }
364ac7ddfbfSEd Maste 
GetValue()365435933ddSDimitry Andric const char *SBValue::GetValue() {
366ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
367ac7ddfbfSEd Maste 
368ac7ddfbfSEd Maste   const char *cstr = NULL;
369ac7ddfbfSEd Maste   ValueLocker locker;
370ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
371435933ddSDimitry Andric   if (value_sp) {
372ac7ddfbfSEd Maste     cstr = value_sp->GetValueAsCString();
373ac7ddfbfSEd Maste   }
374435933ddSDimitry Andric   if (log) {
375ac7ddfbfSEd Maste     if (cstr)
3760127ef0fSEd Maste       log->Printf("SBValue(%p)::GetValue() => \"%s\"",
3770127ef0fSEd Maste                   static_cast<void *>(value_sp.get()), cstr);
378ac7ddfbfSEd Maste     else
3790127ef0fSEd Maste       log->Printf("SBValue(%p)::GetValue() => NULL",
3800127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
381ac7ddfbfSEd Maste   }
382ac7ddfbfSEd Maste 
383ac7ddfbfSEd Maste   return cstr;
384ac7ddfbfSEd Maste }
385ac7ddfbfSEd Maste 
GetValueType()386435933ddSDimitry Andric ValueType SBValue::GetValueType() {
387ac7ddfbfSEd Maste   ValueType result = eValueTypeInvalid;
388ac7ddfbfSEd Maste   ValueLocker locker;
389ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
390ac7ddfbfSEd Maste   if (value_sp)
391ac7ddfbfSEd Maste     result = value_sp->GetValueType();
392ac7ddfbfSEd Maste 
393ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
394435933ddSDimitry Andric   if (log) {
395435933ddSDimitry Andric     switch (result) {
3960127ef0fSEd Maste     case eValueTypeInvalid:
3970127ef0fSEd Maste       log->Printf("SBValue(%p)::GetValueType () => eValueTypeInvalid",
3980127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
3990127ef0fSEd Maste       break;
4000127ef0fSEd Maste     case eValueTypeVariableGlobal:
4010127ef0fSEd Maste       log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal",
4020127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
4030127ef0fSEd Maste       break;
4040127ef0fSEd Maste     case eValueTypeVariableStatic:
4050127ef0fSEd Maste       log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableStatic",
4060127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
4070127ef0fSEd Maste       break;
4080127ef0fSEd Maste     case eValueTypeVariableArgument:
4090127ef0fSEd Maste       log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableArgument",
4100127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
4110127ef0fSEd Maste       break;
4120127ef0fSEd Maste     case eValueTypeVariableLocal:
4130127ef0fSEd Maste       log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableLocal",
4140127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
4150127ef0fSEd Maste       break;
4160127ef0fSEd Maste     case eValueTypeRegister:
4170127ef0fSEd Maste       log->Printf("SBValue(%p)::GetValueType () => eValueTypeRegister",
4180127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
4190127ef0fSEd Maste       break;
4200127ef0fSEd Maste     case eValueTypeRegisterSet:
4210127ef0fSEd Maste       log->Printf("SBValue(%p)::GetValueType () => eValueTypeRegisterSet",
4220127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
4230127ef0fSEd Maste       break;
4240127ef0fSEd Maste     case eValueTypeConstResult:
4250127ef0fSEd Maste       log->Printf("SBValue(%p)::GetValueType () => eValueTypeConstResult",
4260127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
4270127ef0fSEd Maste       break;
4284bb0738eSEd Maste     case eValueTypeVariableThreadLocal:
429435933ddSDimitry Andric       log->Printf(
430435933ddSDimitry Andric           "SBValue(%p)::GetValueType () => eValueTypeVariableThreadLocal",
4314bb0738eSEd Maste           static_cast<void *>(value_sp.get()));
4324bb0738eSEd Maste       break;
433ac7ddfbfSEd Maste     }
434ac7ddfbfSEd Maste   }
435ac7ddfbfSEd Maste   return result;
436ac7ddfbfSEd Maste }
437ac7ddfbfSEd Maste 
GetObjectDescription()438435933ddSDimitry Andric const char *SBValue::GetObjectDescription() {
439ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
440ac7ddfbfSEd Maste   const char *cstr = NULL;
441ac7ddfbfSEd Maste   ValueLocker locker;
442ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
443435933ddSDimitry Andric   if (value_sp) {
444ac7ddfbfSEd Maste     cstr = value_sp->GetObjectDescription();
445ac7ddfbfSEd Maste   }
446435933ddSDimitry Andric   if (log) {
447ac7ddfbfSEd Maste     if (cstr)
4480127ef0fSEd Maste       log->Printf("SBValue(%p)::GetObjectDescription() => \"%s\"",
4490127ef0fSEd Maste                   static_cast<void *>(value_sp.get()), cstr);
450ac7ddfbfSEd Maste     else
4510127ef0fSEd Maste       log->Printf("SBValue(%p)::GetObjectDescription() => NULL",
4520127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
453ac7ddfbfSEd Maste   }
454ac7ddfbfSEd Maste   return cstr;
455ac7ddfbfSEd Maste }
456ac7ddfbfSEd Maste 
GetTypeValidatorResult()457435933ddSDimitry Andric const char *SBValue::GetTypeValidatorResult() {
4587aa51b79SEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
4597aa51b79SEd Maste   const char *cstr = NULL;
4607aa51b79SEd Maste   ValueLocker locker;
4617aa51b79SEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
462435933ddSDimitry Andric   if (value_sp) {
4637aa51b79SEd Maste     const auto &validation(value_sp->GetValidationStatus());
464435933ddSDimitry Andric     if (TypeValidatorResult::Failure == validation.first) {
4657aa51b79SEd Maste       if (validation.second.empty())
4667aa51b79SEd Maste         cstr = "unknown error";
4677aa51b79SEd Maste       else
4687aa51b79SEd Maste         cstr = validation.second.c_str();
4697aa51b79SEd Maste     }
4707aa51b79SEd Maste   }
471435933ddSDimitry Andric   if (log) {
4727aa51b79SEd Maste     if (cstr)
4737aa51b79SEd Maste       log->Printf("SBValue(%p)::GetTypeValidatorResult() => \"%s\"",
4747aa51b79SEd Maste                   static_cast<void *>(value_sp.get()), cstr);
4757aa51b79SEd Maste     else
4767aa51b79SEd Maste       log->Printf("SBValue(%p)::GetTypeValidatorResult() => NULL",
4777aa51b79SEd Maste                   static_cast<void *>(value_sp.get()));
4787aa51b79SEd Maste   }
4797aa51b79SEd Maste   return cstr;
4807aa51b79SEd Maste }
4817aa51b79SEd Maste 
GetType()482435933ddSDimitry Andric SBType SBValue::GetType() {
483ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
484ac7ddfbfSEd Maste   SBType sb_type;
485ac7ddfbfSEd Maste   ValueLocker locker;
486ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
487ac7ddfbfSEd Maste   TypeImplSP type_sp;
488435933ddSDimitry Andric   if (value_sp) {
48935617911SEd Maste     type_sp.reset(new TypeImpl(value_sp->GetTypeImpl()));
490ac7ddfbfSEd Maste     sb_type.SetSP(type_sp);
491ac7ddfbfSEd Maste   }
492435933ddSDimitry Andric   if (log) {
493ac7ddfbfSEd Maste     if (type_sp)
4940127ef0fSEd Maste       log->Printf("SBValue(%p)::GetType => SBType(%p)",
4950127ef0fSEd Maste                   static_cast<void *>(value_sp.get()),
4960127ef0fSEd Maste                   static_cast<void *>(type_sp.get()));
497ac7ddfbfSEd Maste     else
4980127ef0fSEd Maste       log->Printf("SBValue(%p)::GetType => NULL",
4990127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
500ac7ddfbfSEd Maste   }
501ac7ddfbfSEd Maste   return sb_type;
502ac7ddfbfSEd Maste }
503ac7ddfbfSEd Maste 
GetValueDidChange()504435933ddSDimitry Andric bool SBValue::GetValueDidChange() {
505ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
506ac7ddfbfSEd Maste   bool result = false;
507ac7ddfbfSEd Maste   ValueLocker locker;
508ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
509435933ddSDimitry Andric   if (value_sp) {
5101c3bbb01SEd Maste     if (value_sp->UpdateValueIfNeeded(false))
511ac7ddfbfSEd Maste       result = value_sp->GetValueDidChange();
512ac7ddfbfSEd Maste   }
513ac7ddfbfSEd Maste   if (log)
5140127ef0fSEd Maste     log->Printf("SBValue(%p)::GetValueDidChange() => %i",
5150127ef0fSEd Maste                 static_cast<void *>(value_sp.get()), result);
516ac7ddfbfSEd Maste 
517ac7ddfbfSEd Maste   return result;
518ac7ddfbfSEd Maste }
519ac7ddfbfSEd Maste 
GetSummary()520435933ddSDimitry Andric const char *SBValue::GetSummary() {
521ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
522ac7ddfbfSEd Maste   const char *cstr = NULL;
523ac7ddfbfSEd Maste   ValueLocker locker;
524ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
525435933ddSDimitry Andric   if (value_sp) {
526ac7ddfbfSEd Maste     cstr = value_sp->GetSummaryAsCString();
527ac7ddfbfSEd Maste   }
528435933ddSDimitry Andric   if (log) {
529ac7ddfbfSEd Maste     if (cstr)
5300127ef0fSEd Maste       log->Printf("SBValue(%p)::GetSummary() => \"%s\"",
5310127ef0fSEd Maste                   static_cast<void *>(value_sp.get()), cstr);
532ac7ddfbfSEd Maste     else
5330127ef0fSEd Maste       log->Printf("SBValue(%p)::GetSummary() => NULL",
5340127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
535ac7ddfbfSEd Maste   }
536ac7ddfbfSEd Maste   return cstr;
537ac7ddfbfSEd Maste }
5387aa51b79SEd Maste 
GetSummary(lldb::SBStream & stream,lldb::SBTypeSummaryOptions & options)539435933ddSDimitry Andric const char *SBValue::GetSummary(lldb::SBStream &stream,
540435933ddSDimitry Andric                                 lldb::SBTypeSummaryOptions &options) {
5417aa51b79SEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
5427aa51b79SEd Maste   ValueLocker locker;
5437aa51b79SEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
544435933ddSDimitry Andric   if (value_sp) {
5457aa51b79SEd Maste     std::string buffer;
5467aa51b79SEd Maste     if (value_sp->GetSummaryAsCString(buffer, options.ref()) && !buffer.empty())
5477aa51b79SEd Maste       stream.Printf("%s", buffer.c_str());
5487aa51b79SEd Maste   }
5497aa51b79SEd Maste   const char *cstr = stream.GetData();
550435933ddSDimitry Andric   if (log) {
5517aa51b79SEd Maste     if (cstr)
5527aa51b79SEd Maste       log->Printf("SBValue(%p)::GetSummary() => \"%s\"",
5537aa51b79SEd Maste                   static_cast<void *>(value_sp.get()), cstr);
5547aa51b79SEd Maste     else
5557aa51b79SEd Maste       log->Printf("SBValue(%p)::GetSummary() => NULL",
5567aa51b79SEd Maste                   static_cast<void *>(value_sp.get()));
5577aa51b79SEd Maste   }
5587aa51b79SEd Maste   return cstr;
5597aa51b79SEd Maste }
560ac7ddfbfSEd Maste 
GetLocation()561435933ddSDimitry Andric const char *SBValue::GetLocation() {
562ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
563ac7ddfbfSEd Maste   const char *cstr = NULL;
564ac7ddfbfSEd Maste   ValueLocker locker;
565ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
566435933ddSDimitry Andric   if (value_sp) {
567ac7ddfbfSEd Maste     cstr = value_sp->GetLocationAsCString();
568ac7ddfbfSEd Maste   }
569435933ddSDimitry Andric   if (log) {
570ac7ddfbfSEd Maste     if (cstr)
5710127ef0fSEd Maste       log->Printf("SBValue(%p)::GetLocation() => \"%s\"",
5720127ef0fSEd Maste                   static_cast<void *>(value_sp.get()), cstr);
573ac7ddfbfSEd Maste     else
5740127ef0fSEd Maste       log->Printf("SBValue(%p)::GetLocation() => NULL",
5750127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
576ac7ddfbfSEd Maste   }
577ac7ddfbfSEd Maste   return cstr;
578ac7ddfbfSEd Maste }
579ac7ddfbfSEd Maste 
580ac7ddfbfSEd Maste // Deprecated - use the one that takes an lldb::SBError
SetValueFromCString(const char * value_str)581435933ddSDimitry Andric bool SBValue::SetValueFromCString(const char *value_str) {
582ac7ddfbfSEd Maste   lldb::SBError dummy;
583ac7ddfbfSEd Maste   return SetValueFromCString(value_str, dummy);
584ac7ddfbfSEd Maste }
585ac7ddfbfSEd Maste 
SetValueFromCString(const char * value_str,lldb::SBError & error)586435933ddSDimitry Andric bool SBValue::SetValueFromCString(const char *value_str, lldb::SBError &error) {
587ac7ddfbfSEd Maste   bool success = false;
588ac7ddfbfSEd Maste   ValueLocker locker;
589ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
590ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
591435933ddSDimitry Andric   if (value_sp) {
592ac7ddfbfSEd Maste     success = value_sp->SetValueFromCString(value_str, error.ref());
593435933ddSDimitry Andric   } else
594435933ddSDimitry Andric     error.SetErrorStringWithFormat("Could not get value: %s",
595435933ddSDimitry Andric                                    locker.GetError().AsCString());
596ac7ddfbfSEd Maste 
597ac7ddfbfSEd Maste   if (log)
5980127ef0fSEd Maste     log->Printf("SBValue(%p)::SetValueFromCString(\"%s\") => %i",
5990127ef0fSEd Maste                 static_cast<void *>(value_sp.get()), value_str, success);
600ac7ddfbfSEd Maste 
601ac7ddfbfSEd Maste   return success;
602ac7ddfbfSEd Maste }
603ac7ddfbfSEd Maste 
GetTypeFormat()604435933ddSDimitry Andric lldb::SBTypeFormat SBValue::GetTypeFormat() {
605ac7ddfbfSEd Maste   lldb::SBTypeFormat format;
606ac7ddfbfSEd Maste   ValueLocker locker;
607ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
608435933ddSDimitry Andric   if (value_sp) {
609435933ddSDimitry Andric     if (value_sp->UpdateValueIfNeeded(true)) {
610ac7ddfbfSEd Maste       lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
611ac7ddfbfSEd Maste       if (format_sp)
612ac7ddfbfSEd Maste         format.SetSP(format_sp);
613ac7ddfbfSEd Maste     }
614ac7ddfbfSEd Maste   }
615ac7ddfbfSEd Maste   return format;
616ac7ddfbfSEd Maste }
617ac7ddfbfSEd Maste 
GetTypeSummary()618435933ddSDimitry Andric lldb::SBTypeSummary SBValue::GetTypeSummary() {
619ac7ddfbfSEd Maste   lldb::SBTypeSummary summary;
620ac7ddfbfSEd Maste   ValueLocker locker;
621ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
622435933ddSDimitry Andric   if (value_sp) {
623435933ddSDimitry Andric     if (value_sp->UpdateValueIfNeeded(true)) {
624ac7ddfbfSEd Maste       lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
625ac7ddfbfSEd Maste       if (summary_sp)
626ac7ddfbfSEd Maste         summary.SetSP(summary_sp);
627ac7ddfbfSEd Maste     }
628ac7ddfbfSEd Maste   }
629ac7ddfbfSEd Maste   return summary;
630ac7ddfbfSEd Maste }
631ac7ddfbfSEd Maste 
GetTypeFilter()632435933ddSDimitry Andric lldb::SBTypeFilter SBValue::GetTypeFilter() {
633ac7ddfbfSEd Maste   lldb::SBTypeFilter filter;
634ac7ddfbfSEd Maste   ValueLocker locker;
635ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
636435933ddSDimitry Andric   if (value_sp) {
637435933ddSDimitry Andric     if (value_sp->UpdateValueIfNeeded(true)) {
638ac7ddfbfSEd Maste       lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
639ac7ddfbfSEd Maste 
640435933ddSDimitry Andric       if (synthetic_sp && !synthetic_sp->IsScripted()) {
641435933ddSDimitry Andric         TypeFilterImplSP filter_sp =
642435933ddSDimitry Andric             std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
643ac7ddfbfSEd Maste         filter.SetSP(filter_sp);
644ac7ddfbfSEd Maste       }
645ac7ddfbfSEd Maste     }
646ac7ddfbfSEd Maste   }
647ac7ddfbfSEd Maste   return filter;
648ac7ddfbfSEd Maste }
649ac7ddfbfSEd Maste 
650ac7ddfbfSEd Maste #ifndef LLDB_DISABLE_PYTHON
GetTypeSynthetic()651435933ddSDimitry Andric lldb::SBTypeSynthetic SBValue::GetTypeSynthetic() {
652ac7ddfbfSEd Maste   lldb::SBTypeSynthetic synthetic;
653ac7ddfbfSEd Maste   ValueLocker locker;
654ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
655435933ddSDimitry Andric   if (value_sp) {
656435933ddSDimitry Andric     if (value_sp->UpdateValueIfNeeded(true)) {
657ac7ddfbfSEd Maste       lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
658ac7ddfbfSEd Maste 
659435933ddSDimitry Andric       if (children_sp && children_sp->IsScripted()) {
660435933ddSDimitry Andric         ScriptedSyntheticChildrenSP synth_sp =
661435933ddSDimitry Andric             std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
662ac7ddfbfSEd Maste         synthetic.SetSP(synth_sp);
663ac7ddfbfSEd Maste       }
664ac7ddfbfSEd Maste     }
665ac7ddfbfSEd Maste   }
666ac7ddfbfSEd Maste   return synthetic;
667ac7ddfbfSEd Maste }
668ac7ddfbfSEd Maste #endif
669ac7ddfbfSEd Maste 
CreateChildAtOffset(const char * name,uint32_t offset,SBType type)670435933ddSDimitry Andric lldb::SBValue SBValue::CreateChildAtOffset(const char *name, uint32_t offset,
671435933ddSDimitry Andric                                            SBType type) {
672ac7ddfbfSEd Maste   lldb::SBValue sb_value;
673ac7ddfbfSEd Maste   ValueLocker locker;
674ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
675ac7ddfbfSEd Maste   lldb::ValueObjectSP new_value_sp;
676435933ddSDimitry Andric   if (value_sp) {
677ac7ddfbfSEd Maste     TypeImplSP type_sp(type.GetSP());
678435933ddSDimitry Andric     if (type.IsValid()) {
679435933ddSDimitry Andric       sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(
680435933ddSDimitry Andric                          offset, type_sp->GetCompilerType(false), true),
681435933ddSDimitry Andric                      GetPreferDynamicValue(), GetPreferSyntheticValue(), name);
682ac7ddfbfSEd Maste     }
683ac7ddfbfSEd Maste   }
684ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
685435933ddSDimitry Andric   if (log) {
686ac7ddfbfSEd Maste     if (new_value_sp)
687ac7ddfbfSEd Maste       log->Printf("SBValue(%p)::CreateChildAtOffset => \"%s\"",
6880127ef0fSEd Maste                   static_cast<void *>(value_sp.get()),
689ac7ddfbfSEd Maste                   new_value_sp->GetName().AsCString());
690ac7ddfbfSEd Maste     else
691ac7ddfbfSEd Maste       log->Printf("SBValue(%p)::CreateChildAtOffset => NULL",
6920127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
693ac7ddfbfSEd Maste   }
694ac7ddfbfSEd Maste   return sb_value;
695ac7ddfbfSEd Maste }
696ac7ddfbfSEd Maste 
Cast(SBType type)697435933ddSDimitry Andric lldb::SBValue SBValue::Cast(SBType type) {
698ac7ddfbfSEd Maste   lldb::SBValue sb_value;
699ac7ddfbfSEd Maste   ValueLocker locker;
700ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
701ac7ddfbfSEd Maste   TypeImplSP type_sp(type.GetSP());
702ac7ddfbfSEd Maste   if (value_sp && type_sp)
703435933ddSDimitry Andric     sb_value.SetSP(value_sp->Cast(type_sp->GetCompilerType(false)),
704435933ddSDimitry Andric                    GetPreferDynamicValue(), GetPreferSyntheticValue());
705ac7ddfbfSEd Maste   return sb_value;
706ac7ddfbfSEd Maste }
707ac7ddfbfSEd Maste 
CreateValueFromExpression(const char * name,const char * expression)708435933ddSDimitry Andric lldb::SBValue SBValue::CreateValueFromExpression(const char *name,
709435933ddSDimitry Andric                                                  const char *expression) {
710ac7ddfbfSEd Maste   SBExpressionOptions options;
711ac7ddfbfSEd Maste   options.ref().SetKeepInMemory(true);
712ac7ddfbfSEd Maste   return CreateValueFromExpression(name, expression, options);
713ac7ddfbfSEd Maste }
714ac7ddfbfSEd Maste 
CreateValueFromExpression(const char * name,const char * expression,SBExpressionOptions & options)715435933ddSDimitry Andric lldb::SBValue SBValue::CreateValueFromExpression(const char *name,
716435933ddSDimitry Andric                                                  const char *expression,
717435933ddSDimitry Andric                                                  SBExpressionOptions &options) {
718ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
719ac7ddfbfSEd Maste   lldb::SBValue sb_value;
720ac7ddfbfSEd Maste   ValueLocker locker;
721ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
722ac7ddfbfSEd Maste   lldb::ValueObjectSP new_value_sp;
723435933ddSDimitry Andric   if (value_sp) {
724ac7ddfbfSEd Maste     ExecutionContext exe_ctx(value_sp->GetExecutionContextRef());
725435933ddSDimitry Andric     new_value_sp = ValueObject::CreateValueObjectFromExpression(
726435933ddSDimitry Andric         name, expression, exe_ctx, options.ref());
727ac7ddfbfSEd Maste     if (new_value_sp)
728ac7ddfbfSEd Maste       new_value_sp->SetName(ConstString(name));
7297aa51b79SEd Maste   }
730ac7ddfbfSEd Maste   sb_value.SetSP(new_value_sp);
731435933ddSDimitry Andric   if (log) {
732ac7ddfbfSEd Maste     if (new_value_sp)
733435933ddSDimitry Andric       log->Printf("SBValue(%p)::CreateValueFromExpression(name=\"%s\", "
734435933ddSDimitry Andric                   "expression=\"%s\") => SBValue (%p)",
7350127ef0fSEd Maste                   static_cast<void *>(value_sp.get()), name, expression,
7360127ef0fSEd Maste                   static_cast<void *>(new_value_sp.get()));
737ac7ddfbfSEd Maste     else
738435933ddSDimitry Andric       log->Printf("SBValue(%p)::CreateValueFromExpression(name=\"%s\", "
739435933ddSDimitry Andric                   "expression=\"%s\") => NULL",
7400127ef0fSEd Maste                   static_cast<void *>(value_sp.get()), name, expression);
741ac7ddfbfSEd Maste   }
742ac7ddfbfSEd Maste   return sb_value;
743ac7ddfbfSEd Maste }
744ac7ddfbfSEd Maste 
CreateValueFromAddress(const char * name,lldb::addr_t address,SBType sb_type)745435933ddSDimitry Andric lldb::SBValue SBValue::CreateValueFromAddress(const char *name,
746435933ddSDimitry Andric                                               lldb::addr_t address,
747435933ddSDimitry Andric                                               SBType sb_type) {
748ac7ddfbfSEd Maste   lldb::SBValue sb_value;
749ac7ddfbfSEd Maste   ValueLocker locker;
750ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
751ac7ddfbfSEd Maste   lldb::ValueObjectSP new_value_sp;
752ac7ddfbfSEd Maste   lldb::TypeImplSP type_impl_sp(sb_type.GetSP());
753435933ddSDimitry Andric   if (value_sp && type_impl_sp) {
7549f2f44ceSEd Maste     CompilerType ast_type(type_impl_sp->GetCompilerType(true));
755ac7ddfbfSEd Maste     ExecutionContext exe_ctx(value_sp->GetExecutionContextRef());
756435933ddSDimitry Andric     new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address,
757435933ddSDimitry Andric                                                              exe_ctx, ast_type);
758ac7ddfbfSEd Maste   }
759ac7ddfbfSEd Maste   sb_value.SetSP(new_value_sp);
760ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
761435933ddSDimitry Andric   if (log) {
762ac7ddfbfSEd Maste     if (new_value_sp)
7630127ef0fSEd Maste       log->Printf("SBValue(%p)::CreateValueFromAddress => \"%s\"",
7640127ef0fSEd Maste                   static_cast<void *>(value_sp.get()),
7650127ef0fSEd Maste                   new_value_sp->GetName().AsCString());
766ac7ddfbfSEd Maste     else
7670127ef0fSEd Maste       log->Printf("SBValue(%p)::CreateValueFromAddress => NULL",
7680127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
769ac7ddfbfSEd Maste   }
770ac7ddfbfSEd Maste   return sb_value;
771ac7ddfbfSEd Maste }
772ac7ddfbfSEd Maste 
CreateValueFromData(const char * name,SBData data,SBType sb_type)773435933ddSDimitry Andric lldb::SBValue SBValue::CreateValueFromData(const char *name, SBData data,
774435933ddSDimitry Andric                                            SBType sb_type) {
775ac7ddfbfSEd Maste   lldb::SBValue sb_value;
776ac7ddfbfSEd Maste   lldb::ValueObjectSP new_value_sp;
777ac7ddfbfSEd Maste   ValueLocker locker;
778ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
7794bb0738eSEd Maste   lldb::TypeImplSP type_impl_sp(sb_type.GetSP());
780435933ddSDimitry Andric   if (value_sp && type_impl_sp) {
781ac7ddfbfSEd Maste     ExecutionContext exe_ctx(value_sp->GetExecutionContextRef());
782435933ddSDimitry Andric     new_value_sp = ValueObject::CreateValueObjectFromData(
783435933ddSDimitry Andric         name, **data, exe_ctx, type_impl_sp->GetCompilerType(true));
784ac7ddfbfSEd Maste     new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
785ac7ddfbfSEd Maste   }
7867aa51b79SEd Maste   sb_value.SetSP(new_value_sp);
787ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
788435933ddSDimitry Andric   if (log) {
789ac7ddfbfSEd Maste     if (new_value_sp)
7900127ef0fSEd Maste       log->Printf("SBValue(%p)::CreateValueFromData => \"%s\"",
7910127ef0fSEd Maste                   static_cast<void *>(value_sp.get()),
7920127ef0fSEd Maste                   new_value_sp->GetName().AsCString());
793ac7ddfbfSEd Maste     else
7940127ef0fSEd Maste       log->Printf("SBValue(%p)::CreateValueFromData => NULL",
7950127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
796ac7ddfbfSEd Maste   }
797ac7ddfbfSEd Maste   return sb_value;
798ac7ddfbfSEd Maste }
799ac7ddfbfSEd Maste 
GetChildAtIndex(uint32_t idx)800435933ddSDimitry Andric SBValue SBValue::GetChildAtIndex(uint32_t idx) {
801ac7ddfbfSEd Maste   const bool can_create_synthetic = false;
802ac7ddfbfSEd Maste   lldb::DynamicValueType use_dynamic = eNoDynamicValues;
803ac7ddfbfSEd Maste   TargetSP target_sp;
804ac7ddfbfSEd Maste   if (m_opaque_sp)
805ac7ddfbfSEd Maste     target_sp = m_opaque_sp->GetTargetSP();
806ac7ddfbfSEd Maste 
807ac7ddfbfSEd Maste   if (target_sp)
808ac7ddfbfSEd Maste     use_dynamic = target_sp->GetPreferDynamicValue();
809ac7ddfbfSEd Maste 
810ac7ddfbfSEd Maste   return GetChildAtIndex(idx, use_dynamic, can_create_synthetic);
811ac7ddfbfSEd Maste }
812ac7ddfbfSEd Maste 
GetChildAtIndex(uint32_t idx,lldb::DynamicValueType use_dynamic,bool can_create_synthetic)813435933ddSDimitry Andric SBValue SBValue::GetChildAtIndex(uint32_t idx,
814435933ddSDimitry Andric                                  lldb::DynamicValueType use_dynamic,
815435933ddSDimitry Andric                                  bool can_create_synthetic) {
816ac7ddfbfSEd Maste   lldb::ValueObjectSP child_sp;
817ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
818ac7ddfbfSEd Maste 
819ac7ddfbfSEd Maste   ValueLocker locker;
820ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
821435933ddSDimitry Andric   if (value_sp) {
822ac7ddfbfSEd Maste     const bool can_create = true;
823ac7ddfbfSEd Maste     child_sp = value_sp->GetChildAtIndex(idx, can_create);
824435933ddSDimitry Andric     if (can_create_synthetic && !child_sp) {
8251c3bbb01SEd Maste       child_sp = value_sp->GetSyntheticArrayMember(idx, can_create);
826ac7ddfbfSEd Maste     }
827ac7ddfbfSEd Maste   }
828ac7ddfbfSEd Maste 
829ac7ddfbfSEd Maste   SBValue sb_value;
830ac7ddfbfSEd Maste   sb_value.SetSP(child_sp, use_dynamic, GetPreferSyntheticValue());
831ac7ddfbfSEd Maste   if (log)
8320127ef0fSEd Maste     log->Printf("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)",
8330127ef0fSEd Maste                 static_cast<void *>(value_sp.get()), idx,
8340127ef0fSEd Maste                 static_cast<void *>(value_sp.get()));
835ac7ddfbfSEd Maste 
836ac7ddfbfSEd Maste   return sb_value;
837ac7ddfbfSEd Maste }
838ac7ddfbfSEd Maste 
GetIndexOfChildWithName(const char * name)839435933ddSDimitry Andric uint32_t SBValue::GetIndexOfChildWithName(const char *name) {
840ac7ddfbfSEd Maste   uint32_t idx = UINT32_MAX;
841ac7ddfbfSEd Maste   ValueLocker locker;
842ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
843435933ddSDimitry Andric   if (value_sp) {
844ac7ddfbfSEd Maste     idx = value_sp->GetIndexOfChildWithName(ConstString(name));
845ac7ddfbfSEd Maste   }
846ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
847435933ddSDimitry Andric   if (log) {
848ac7ddfbfSEd Maste     if (idx == UINT32_MAX)
849435933ddSDimitry Andric       log->Printf(
850435933ddSDimitry Andric           "SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND",
8510127ef0fSEd Maste           static_cast<void *>(value_sp.get()), name);
852ac7ddfbfSEd Maste     else
8530127ef0fSEd Maste       log->Printf("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u",
8540127ef0fSEd Maste                   static_cast<void *>(value_sp.get()), name, idx);
855ac7ddfbfSEd Maste   }
856ac7ddfbfSEd Maste   return idx;
857ac7ddfbfSEd Maste }
858ac7ddfbfSEd Maste 
GetChildMemberWithName(const char * name)859435933ddSDimitry Andric SBValue SBValue::GetChildMemberWithName(const char *name) {
860ac7ddfbfSEd Maste   lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
861ac7ddfbfSEd Maste   TargetSP target_sp;
862ac7ddfbfSEd Maste   if (m_opaque_sp)
863ac7ddfbfSEd Maste     target_sp = m_opaque_sp->GetTargetSP();
864ac7ddfbfSEd Maste 
865ac7ddfbfSEd Maste   if (target_sp)
866ac7ddfbfSEd Maste     use_dynamic_value = target_sp->GetPreferDynamicValue();
867ac7ddfbfSEd Maste   return GetChildMemberWithName(name, use_dynamic_value);
868ac7ddfbfSEd Maste }
869ac7ddfbfSEd Maste 
870ac7ddfbfSEd Maste SBValue
GetChildMemberWithName(const char * name,lldb::DynamicValueType use_dynamic_value)871435933ddSDimitry Andric SBValue::GetChildMemberWithName(const char *name,
872435933ddSDimitry Andric                                 lldb::DynamicValueType use_dynamic_value) {
873ac7ddfbfSEd Maste   lldb::ValueObjectSP child_sp;
874ac7ddfbfSEd Maste   const ConstString str_name(name);
875ac7ddfbfSEd Maste 
876ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
877ac7ddfbfSEd Maste 
878ac7ddfbfSEd Maste   ValueLocker locker;
879ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
880435933ddSDimitry Andric   if (value_sp) {
881ac7ddfbfSEd Maste     child_sp = value_sp->GetChildMemberWithName(str_name, true);
882ac7ddfbfSEd Maste   }
883ac7ddfbfSEd Maste 
884ac7ddfbfSEd Maste   SBValue sb_value;
885ac7ddfbfSEd Maste   sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
886ac7ddfbfSEd Maste 
887ac7ddfbfSEd Maste   if (log)
888435933ddSDimitry Andric     log->Printf(
889435933ddSDimitry Andric         "SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)",
8900127ef0fSEd Maste         static_cast<void *>(value_sp.get()), name,
8910127ef0fSEd Maste         static_cast<void *>(value_sp.get()));
892ac7ddfbfSEd Maste 
893ac7ddfbfSEd Maste   return sb_value;
894ac7ddfbfSEd Maste }
895ac7ddfbfSEd Maste 
GetDynamicValue(lldb::DynamicValueType use_dynamic)896435933ddSDimitry Andric lldb::SBValue SBValue::GetDynamicValue(lldb::DynamicValueType use_dynamic) {
897ac7ddfbfSEd Maste   SBValue value_sb;
898435933ddSDimitry Andric   if (IsValid()) {
899435933ddSDimitry Andric     ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(), use_dynamic,
900435933ddSDimitry Andric                                        m_opaque_sp->GetUseSynthetic()));
901ac7ddfbfSEd Maste     value_sb.SetSP(proxy_sp);
902ac7ddfbfSEd Maste   }
903ac7ddfbfSEd Maste   return value_sb;
904ac7ddfbfSEd Maste }
905ac7ddfbfSEd Maste 
GetStaticValue()906435933ddSDimitry Andric lldb::SBValue SBValue::GetStaticValue() {
907ac7ddfbfSEd Maste   SBValue value_sb;
908435933ddSDimitry Andric   if (IsValid()) {
909435933ddSDimitry Andric     ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),
910435933ddSDimitry Andric                                        eNoDynamicValues,
911435933ddSDimitry Andric                                        m_opaque_sp->GetUseSynthetic()));
912ac7ddfbfSEd Maste     value_sb.SetSP(proxy_sp);
913ac7ddfbfSEd Maste   }
914ac7ddfbfSEd Maste   return value_sb;
915ac7ddfbfSEd Maste }
916ac7ddfbfSEd Maste 
GetNonSyntheticValue()917435933ddSDimitry Andric lldb::SBValue SBValue::GetNonSyntheticValue() {
918ac7ddfbfSEd Maste   SBValue value_sb;
919435933ddSDimitry Andric   if (IsValid()) {
920435933ddSDimitry Andric     ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),
921435933ddSDimitry Andric                                        m_opaque_sp->GetUseDynamic(), false));
922ac7ddfbfSEd Maste     value_sb.SetSP(proxy_sp);
923ac7ddfbfSEd Maste   }
924ac7ddfbfSEd Maste   return value_sb;
925ac7ddfbfSEd Maste }
926ac7ddfbfSEd Maste 
GetPreferDynamicValue()927435933ddSDimitry Andric lldb::DynamicValueType SBValue::GetPreferDynamicValue() {
928ac7ddfbfSEd Maste   if (!IsValid())
929ac7ddfbfSEd Maste     return eNoDynamicValues;
930ac7ddfbfSEd Maste   return m_opaque_sp->GetUseDynamic();
931ac7ddfbfSEd Maste }
932ac7ddfbfSEd Maste 
SetPreferDynamicValue(lldb::DynamicValueType use_dynamic)933435933ddSDimitry Andric void SBValue::SetPreferDynamicValue(lldb::DynamicValueType use_dynamic) {
934ac7ddfbfSEd Maste   if (IsValid())
935ac7ddfbfSEd Maste     return m_opaque_sp->SetUseDynamic(use_dynamic);
936ac7ddfbfSEd Maste }
937ac7ddfbfSEd Maste 
GetPreferSyntheticValue()938435933ddSDimitry Andric bool SBValue::GetPreferSyntheticValue() {
939ac7ddfbfSEd Maste   if (!IsValid())
940ac7ddfbfSEd Maste     return false;
941ac7ddfbfSEd Maste   return m_opaque_sp->GetUseSynthetic();
942ac7ddfbfSEd Maste }
943ac7ddfbfSEd Maste 
SetPreferSyntheticValue(bool use_synthetic)944435933ddSDimitry Andric void SBValue::SetPreferSyntheticValue(bool use_synthetic) {
945ac7ddfbfSEd Maste   if (IsValid())
946ac7ddfbfSEd Maste     return m_opaque_sp->SetUseSynthetic(use_synthetic);
947ac7ddfbfSEd Maste }
948ac7ddfbfSEd Maste 
IsDynamic()949435933ddSDimitry Andric bool SBValue::IsDynamic() {
950ac7ddfbfSEd Maste   ValueLocker locker;
951ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
952ac7ddfbfSEd Maste   if (value_sp)
953ac7ddfbfSEd Maste     return value_sp->IsDynamic();
954ac7ddfbfSEd Maste   return false;
955ac7ddfbfSEd Maste }
956ac7ddfbfSEd Maste 
IsSynthetic()957435933ddSDimitry Andric bool SBValue::IsSynthetic() {
958ac7ddfbfSEd Maste   ValueLocker locker;
959ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
960ac7ddfbfSEd Maste   if (value_sp)
961ac7ddfbfSEd Maste     return value_sp->IsSynthetic();
962ac7ddfbfSEd Maste   return false;
963ac7ddfbfSEd Maste }
964ac7ddfbfSEd Maste 
IsSyntheticChildrenGenerated()965435933ddSDimitry Andric bool SBValue::IsSyntheticChildrenGenerated() {
9664bb0738eSEd Maste   ValueLocker locker;
9674bb0738eSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
9684bb0738eSEd Maste   if (value_sp)
9694bb0738eSEd Maste     return value_sp->IsSyntheticChildrenGenerated();
9704bb0738eSEd Maste   return false;
9714bb0738eSEd Maste }
9724bb0738eSEd Maste 
SetSyntheticChildrenGenerated(bool is)973435933ddSDimitry Andric void SBValue::SetSyntheticChildrenGenerated(bool is) {
9744bb0738eSEd Maste   ValueLocker locker;
9754bb0738eSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
9764bb0738eSEd Maste   if (value_sp)
9774bb0738eSEd Maste     return value_sp->SetSyntheticChildrenGenerated(is);
9784bb0738eSEd Maste }
9794bb0738eSEd Maste 
GetValueForExpressionPath(const char * expr_path)980435933ddSDimitry Andric lldb::SBValue SBValue::GetValueForExpressionPath(const char *expr_path) {
981ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
982ac7ddfbfSEd Maste   lldb::ValueObjectSP child_sp;
983ac7ddfbfSEd Maste   ValueLocker locker;
984ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
985435933ddSDimitry Andric   if (value_sp) {
986ac7ddfbfSEd Maste     // using default values for all the fancy options, just do it if you can
987ac7ddfbfSEd Maste     child_sp = value_sp->GetValueForExpressionPath(expr_path);
988ac7ddfbfSEd Maste   }
989ac7ddfbfSEd Maste 
990ac7ddfbfSEd Maste   SBValue sb_value;
991ac7ddfbfSEd Maste   sb_value.SetSP(child_sp, GetPreferDynamicValue(), GetPreferSyntheticValue());
992ac7ddfbfSEd Maste 
993ac7ddfbfSEd Maste   if (log)
994435933ddSDimitry Andric     log->Printf("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => "
995435933ddSDimitry Andric                 "SBValue(%p)",
9960127ef0fSEd Maste                 static_cast<void *>(value_sp.get()), expr_path,
9970127ef0fSEd Maste                 static_cast<void *>(value_sp.get()));
998ac7ddfbfSEd Maste 
999ac7ddfbfSEd Maste   return sb_value;
1000ac7ddfbfSEd Maste }
1001ac7ddfbfSEd Maste 
GetValueAsSigned(SBError & error,int64_t fail_value)1002435933ddSDimitry Andric int64_t SBValue::GetValueAsSigned(SBError &error, int64_t fail_value) {
1003ac7ddfbfSEd Maste   error.Clear();
1004ac7ddfbfSEd Maste   ValueLocker locker;
1005ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1006435933ddSDimitry Andric   if (value_sp) {
100735617911SEd Maste     bool success = true;
100835617911SEd Maste     uint64_t ret_val = fail_value;
100935617911SEd Maste     ret_val = value_sp->GetValueAsSigned(fail_value, &success);
101035617911SEd Maste     if (!success)
1011ac7ddfbfSEd Maste       error.SetErrorString("could not resolve value");
101235617911SEd Maste     return ret_val;
1013435933ddSDimitry Andric   } else
1014435933ddSDimitry Andric     error.SetErrorStringWithFormat("could not get SBValue: %s",
1015435933ddSDimitry Andric                                    locker.GetError().AsCString());
1016ac7ddfbfSEd Maste 
1017ac7ddfbfSEd Maste   return fail_value;
1018ac7ddfbfSEd Maste }
1019ac7ddfbfSEd Maste 
GetValueAsUnsigned(SBError & error,uint64_t fail_value)1020435933ddSDimitry Andric uint64_t SBValue::GetValueAsUnsigned(SBError &error, uint64_t fail_value) {
1021ac7ddfbfSEd Maste   error.Clear();
1022ac7ddfbfSEd Maste   ValueLocker locker;
1023ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1024435933ddSDimitry Andric   if (value_sp) {
102535617911SEd Maste     bool success = true;
102635617911SEd Maste     uint64_t ret_val = fail_value;
102735617911SEd Maste     ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
102835617911SEd Maste     if (!success)
1029ac7ddfbfSEd Maste       error.SetErrorString("could not resolve value");
103035617911SEd Maste     return ret_val;
1031435933ddSDimitry Andric   } else
1032435933ddSDimitry Andric     error.SetErrorStringWithFormat("could not get SBValue: %s",
1033435933ddSDimitry Andric                                    locker.GetError().AsCString());
1034ac7ddfbfSEd Maste 
1035ac7ddfbfSEd Maste   return fail_value;
1036ac7ddfbfSEd Maste }
1037ac7ddfbfSEd Maste 
GetValueAsSigned(int64_t fail_value)1038435933ddSDimitry Andric int64_t SBValue::GetValueAsSigned(int64_t fail_value) {
1039ac7ddfbfSEd Maste   ValueLocker locker;
1040ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1041435933ddSDimitry Andric   if (value_sp) {
104235617911SEd Maste     return value_sp->GetValueAsSigned(fail_value);
1043ac7ddfbfSEd Maste   }
1044ac7ddfbfSEd Maste   return fail_value;
1045ac7ddfbfSEd Maste }
1046ac7ddfbfSEd Maste 
GetValueAsUnsigned(uint64_t fail_value)1047435933ddSDimitry Andric uint64_t SBValue::GetValueAsUnsigned(uint64_t fail_value) {
1048ac7ddfbfSEd Maste   ValueLocker locker;
1049ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1050435933ddSDimitry Andric   if (value_sp) {
105135617911SEd Maste     return value_sp->GetValueAsUnsigned(fail_value);
1052ac7ddfbfSEd Maste   }
1053ac7ddfbfSEd Maste   return fail_value;
1054ac7ddfbfSEd Maste }
1055ac7ddfbfSEd Maste 
MightHaveChildren()1056435933ddSDimitry Andric bool SBValue::MightHaveChildren() {
1057ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1058ac7ddfbfSEd Maste   bool has_children = false;
1059ac7ddfbfSEd Maste   ValueLocker locker;
1060ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1061ac7ddfbfSEd Maste   if (value_sp)
1062ac7ddfbfSEd Maste     has_children = value_sp->MightHaveChildren();
1063ac7ddfbfSEd Maste 
1064ac7ddfbfSEd Maste   if (log)
10650127ef0fSEd Maste     log->Printf("SBValue(%p)::MightHaveChildren() => %i",
10660127ef0fSEd Maste                 static_cast<void *>(value_sp.get()), has_children);
1067ac7ddfbfSEd Maste   return has_children;
1068ac7ddfbfSEd Maste }
1069ac7ddfbfSEd Maste 
IsRuntimeSupportValue()1070435933ddSDimitry Andric bool SBValue::IsRuntimeSupportValue() {
10711c3bbb01SEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
10721c3bbb01SEd Maste   bool is_support = false;
10731c3bbb01SEd Maste   ValueLocker locker;
10741c3bbb01SEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
10751c3bbb01SEd Maste   if (value_sp)
10761c3bbb01SEd Maste     is_support = value_sp->IsRuntimeSupportValue();
10771c3bbb01SEd Maste 
10781c3bbb01SEd Maste   if (log)
10791c3bbb01SEd Maste     log->Printf("SBValue(%p)::IsRuntimeSupportValue() => %i",
10801c3bbb01SEd Maste                 static_cast<void *>(value_sp.get()), is_support);
10811c3bbb01SEd Maste   return is_support;
10821c3bbb01SEd Maste }
10831c3bbb01SEd Maste 
GetNumChildren()1084435933ddSDimitry Andric uint32_t SBValue::GetNumChildren() { return GetNumChildren(UINT32_MAX); }
10859f2f44ceSEd Maste 
GetNumChildren(uint32_t max)1086435933ddSDimitry Andric uint32_t SBValue::GetNumChildren(uint32_t max) {
1087ac7ddfbfSEd Maste   uint32_t num_children = 0;
1088ac7ddfbfSEd Maste 
1089ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1090ac7ddfbfSEd Maste   ValueLocker locker;
1091ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1092ac7ddfbfSEd Maste   if (value_sp)
10939f2f44ceSEd Maste     num_children = value_sp->GetNumChildren(max);
1094ac7ddfbfSEd Maste 
1095ac7ddfbfSEd Maste   if (log)
10969f2f44ceSEd Maste     log->Printf("SBValue(%p)::GetNumChildren (%u) => %u",
10979f2f44ceSEd Maste                 static_cast<void *>(value_sp.get()), max, num_children);
1098ac7ddfbfSEd Maste 
1099ac7ddfbfSEd Maste   return num_children;
1100ac7ddfbfSEd Maste }
1101ac7ddfbfSEd Maste 
Dereference()1102435933ddSDimitry Andric SBValue SBValue::Dereference() {
1103ac7ddfbfSEd Maste   SBValue sb_value;
1104ac7ddfbfSEd Maste   ValueLocker locker;
1105ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1106435933ddSDimitry Andric   if (value_sp) {
11075517e702SDimitry Andric     Status error;
1108ac7ddfbfSEd Maste     sb_value = value_sp->Dereference(error);
1109ac7ddfbfSEd Maste   }
1110ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1111ac7ddfbfSEd Maste   if (log)
11120127ef0fSEd Maste     log->Printf("SBValue(%p)::Dereference () => SBValue(%p)",
11130127ef0fSEd Maste                 static_cast<void *>(value_sp.get()),
11140127ef0fSEd Maste                 static_cast<void *>(value_sp.get()));
1115ac7ddfbfSEd Maste 
1116ac7ddfbfSEd Maste   return sb_value;
1117ac7ddfbfSEd Maste }
1118ac7ddfbfSEd Maste 
11199f2f44ceSEd Maste // Deprecated - please use GetType().IsPointerType() instead.
TypeIsPointerType()1120435933ddSDimitry Andric bool SBValue::TypeIsPointerType() { return GetType().IsPointerType(); }
1121ac7ddfbfSEd Maste 
GetOpaqueType()1122435933ddSDimitry Andric void *SBValue::GetOpaqueType() {
1123ac7ddfbfSEd Maste   ValueLocker locker;
1124ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1125ac7ddfbfSEd Maste   if (value_sp)
11269f2f44ceSEd Maste     return value_sp->GetCompilerType().GetOpaqueQualType();
1127ac7ddfbfSEd Maste   return NULL;
1128ac7ddfbfSEd Maste }
1129ac7ddfbfSEd Maste 
GetTarget()1130435933ddSDimitry Andric lldb::SBTarget SBValue::GetTarget() {
1131ac7ddfbfSEd Maste   SBTarget sb_target;
1132ac7ddfbfSEd Maste   TargetSP target_sp;
1133435933ddSDimitry Andric   if (m_opaque_sp) {
1134ac7ddfbfSEd Maste     target_sp = m_opaque_sp->GetTargetSP();
1135ac7ddfbfSEd Maste     sb_target.SetSP(target_sp);
1136ac7ddfbfSEd Maste   }
1137ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1138435933ddSDimitry Andric   if (log) {
1139ac7ddfbfSEd Maste     if (target_sp.get() == NULL)
11400127ef0fSEd Maste       log->Printf("SBValue(%p)::GetTarget () => NULL",
11410127ef0fSEd Maste                   static_cast<void *>(m_opaque_sp.get()));
1142ac7ddfbfSEd Maste     else
11430127ef0fSEd Maste       log->Printf("SBValue(%p)::GetTarget () => %p",
11440127ef0fSEd Maste                   static_cast<void *>(m_opaque_sp.get()),
11450127ef0fSEd Maste                   static_cast<void *>(target_sp.get()));
1146ac7ddfbfSEd Maste   }
1147ac7ddfbfSEd Maste   return sb_target;
1148ac7ddfbfSEd Maste }
1149ac7ddfbfSEd Maste 
GetProcess()1150435933ddSDimitry Andric lldb::SBProcess SBValue::GetProcess() {
1151ac7ddfbfSEd Maste   SBProcess sb_process;
1152ac7ddfbfSEd Maste   ProcessSP process_sp;
1153435933ddSDimitry Andric   if (m_opaque_sp) {
1154ac7ddfbfSEd Maste     process_sp = m_opaque_sp->GetProcessSP();
1155ac7ddfbfSEd Maste     sb_process.SetSP(process_sp);
1156ac7ddfbfSEd Maste   }
1157ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1158435933ddSDimitry Andric   if (log) {
1159ac7ddfbfSEd Maste     if (process_sp.get() == NULL)
11600127ef0fSEd Maste       log->Printf("SBValue(%p)::GetProcess () => NULL",
11610127ef0fSEd Maste                   static_cast<void *>(m_opaque_sp.get()));
1162ac7ddfbfSEd Maste     else
11630127ef0fSEd Maste       log->Printf("SBValue(%p)::GetProcess () => %p",
11640127ef0fSEd Maste                   static_cast<void *>(m_opaque_sp.get()),
11650127ef0fSEd Maste                   static_cast<void *>(process_sp.get()));
1166ac7ddfbfSEd Maste   }
1167ac7ddfbfSEd Maste   return sb_process;
1168ac7ddfbfSEd Maste }
1169ac7ddfbfSEd Maste 
GetThread()1170435933ddSDimitry Andric lldb::SBThread SBValue::GetThread() {
1171ac7ddfbfSEd Maste   SBThread sb_thread;
1172ac7ddfbfSEd Maste   ThreadSP thread_sp;
1173435933ddSDimitry Andric   if (m_opaque_sp) {
1174ac7ddfbfSEd Maste     thread_sp = m_opaque_sp->GetThreadSP();
1175ac7ddfbfSEd Maste     sb_thread.SetThread(thread_sp);
1176ac7ddfbfSEd Maste   }
1177ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1178435933ddSDimitry Andric   if (log) {
1179ac7ddfbfSEd Maste     if (thread_sp.get() == NULL)
11800127ef0fSEd Maste       log->Printf("SBValue(%p)::GetThread () => NULL",
11810127ef0fSEd Maste                   static_cast<void *>(m_opaque_sp.get()));
1182ac7ddfbfSEd Maste     else
11830127ef0fSEd Maste       log->Printf("SBValue(%p)::GetThread () => %p",
11840127ef0fSEd Maste                   static_cast<void *>(m_opaque_sp.get()),
11850127ef0fSEd Maste                   static_cast<void *>(thread_sp.get()));
1186ac7ddfbfSEd Maste   }
1187ac7ddfbfSEd Maste   return sb_thread;
1188ac7ddfbfSEd Maste }
1189ac7ddfbfSEd Maste 
GetFrame()1190435933ddSDimitry Andric lldb::SBFrame SBValue::GetFrame() {
1191ac7ddfbfSEd Maste   SBFrame sb_frame;
1192ac7ddfbfSEd Maste   StackFrameSP frame_sp;
1193435933ddSDimitry Andric   if (m_opaque_sp) {
1194ac7ddfbfSEd Maste     frame_sp = m_opaque_sp->GetFrameSP();
1195ac7ddfbfSEd Maste     sb_frame.SetFrameSP(frame_sp);
1196ac7ddfbfSEd Maste   }
1197ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1198435933ddSDimitry Andric   if (log) {
1199ac7ddfbfSEd Maste     if (frame_sp.get() == NULL)
12000127ef0fSEd Maste       log->Printf("SBValue(%p)::GetFrame () => NULL",
12010127ef0fSEd Maste                   static_cast<void *>(m_opaque_sp.get()));
1202ac7ddfbfSEd Maste     else
12030127ef0fSEd Maste       log->Printf("SBValue(%p)::GetFrame () => %p",
12040127ef0fSEd Maste                   static_cast<void *>(m_opaque_sp.get()),
12050127ef0fSEd Maste                   static_cast<void *>(frame_sp.get()));
1206ac7ddfbfSEd Maste   }
1207ac7ddfbfSEd Maste   return sb_frame;
1208ac7ddfbfSEd Maste }
1209ac7ddfbfSEd Maste 
GetSP(ValueLocker & locker) const1210435933ddSDimitry Andric lldb::ValueObjectSP SBValue::GetSP(ValueLocker &locker) const {
1211435933ddSDimitry Andric   if (!m_opaque_sp || !m_opaque_sp->IsValid()) {
12129f2f44ceSEd Maste     locker.GetError().SetErrorString("No value");
1213ac7ddfbfSEd Maste     return ValueObjectSP();
12149f2f44ceSEd Maste   }
1215ac7ddfbfSEd Maste   return locker.GetLockedSP(*m_opaque_sp.get());
1216ac7ddfbfSEd Maste }
1217ac7ddfbfSEd Maste 
GetSP() const1218435933ddSDimitry Andric lldb::ValueObjectSP SBValue::GetSP() const {
1219ac7ddfbfSEd Maste   ValueLocker locker;
1220ac7ddfbfSEd Maste   return GetSP(locker);
1221ac7ddfbfSEd Maste }
1222ac7ddfbfSEd Maste 
SetSP(ValueImplSP impl_sp)1223435933ddSDimitry Andric void SBValue::SetSP(ValueImplSP impl_sp) { m_opaque_sp = impl_sp; }
1224ac7ddfbfSEd Maste 
SetSP(const lldb::ValueObjectSP & sp)1225435933ddSDimitry Andric void SBValue::SetSP(const lldb::ValueObjectSP &sp) {
1226435933ddSDimitry Andric   if (sp) {
1227ac7ddfbfSEd Maste     lldb::TargetSP target_sp(sp->GetTargetSP());
1228435933ddSDimitry Andric     if (target_sp) {
1229ac7ddfbfSEd Maste       lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1230435933ddSDimitry Andric       bool use_synthetic =
1231435933ddSDimitry Andric           target_sp->TargetProperties::GetEnableSyntheticValue();
1232ac7ddfbfSEd Maste       m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1233435933ddSDimitry Andric     } else
1234ac7ddfbfSEd Maste       m_opaque_sp = ValueImplSP(new ValueImpl(sp, eNoDynamicValues, true));
1235435933ddSDimitry Andric   } else
1236ac7ddfbfSEd Maste     m_opaque_sp = ValueImplSP(new ValueImpl(sp, eNoDynamicValues, false));
1237ac7ddfbfSEd Maste }
1238ac7ddfbfSEd Maste 
SetSP(const lldb::ValueObjectSP & sp,lldb::DynamicValueType use_dynamic)1239435933ddSDimitry Andric void SBValue::SetSP(const lldb::ValueObjectSP &sp,
1240435933ddSDimitry Andric                     lldb::DynamicValueType use_dynamic) {
1241435933ddSDimitry Andric   if (sp) {
1242ac7ddfbfSEd Maste     lldb::TargetSP target_sp(sp->GetTargetSP());
1243435933ddSDimitry Andric     if (target_sp) {
1244435933ddSDimitry Andric       bool use_synthetic =
1245435933ddSDimitry Andric           target_sp->TargetProperties::GetEnableSyntheticValue();
1246ac7ddfbfSEd Maste       SetSP(sp, use_dynamic, use_synthetic);
1247435933ddSDimitry Andric     } else
1248ac7ddfbfSEd Maste       SetSP(sp, use_dynamic, true);
1249435933ddSDimitry Andric   } else
1250ac7ddfbfSEd Maste     SetSP(sp, use_dynamic, false);
1251ac7ddfbfSEd Maste }
1252ac7ddfbfSEd Maste 
SetSP(const lldb::ValueObjectSP & sp,bool use_synthetic)1253435933ddSDimitry Andric void SBValue::SetSP(const lldb::ValueObjectSP &sp, bool use_synthetic) {
1254435933ddSDimitry Andric   if (sp) {
1255ac7ddfbfSEd Maste     lldb::TargetSP target_sp(sp->GetTargetSP());
1256435933ddSDimitry Andric     if (target_sp) {
1257ac7ddfbfSEd Maste       lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1258ac7ddfbfSEd Maste       SetSP(sp, use_dynamic, use_synthetic);
1259435933ddSDimitry Andric     } else
1260ac7ddfbfSEd Maste       SetSP(sp, eNoDynamicValues, use_synthetic);
1261435933ddSDimitry Andric   } else
1262ac7ddfbfSEd Maste     SetSP(sp, eNoDynamicValues, use_synthetic);
1263ac7ddfbfSEd Maste }
1264ac7ddfbfSEd Maste 
SetSP(const lldb::ValueObjectSP & sp,lldb::DynamicValueType use_dynamic,bool use_synthetic)1265435933ddSDimitry Andric void SBValue::SetSP(const lldb::ValueObjectSP &sp,
1266435933ddSDimitry Andric                     lldb::DynamicValueType use_dynamic, bool use_synthetic) {
1267ac7ddfbfSEd Maste   m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1268ac7ddfbfSEd Maste }
1269ac7ddfbfSEd Maste 
SetSP(const lldb::ValueObjectSP & sp,lldb::DynamicValueType use_dynamic,bool use_synthetic,const char * name)1270435933ddSDimitry Andric void SBValue::SetSP(const lldb::ValueObjectSP &sp,
1271435933ddSDimitry Andric                     lldb::DynamicValueType use_dynamic, bool use_synthetic,
1272435933ddSDimitry Andric                     const char *name) {
1273435933ddSDimitry Andric   m_opaque_sp =
1274435933ddSDimitry Andric       ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic, name));
1275ac7ddfbfSEd Maste }
1276ac7ddfbfSEd Maste 
GetExpressionPath(SBStream & description)1277435933ddSDimitry Andric bool SBValue::GetExpressionPath(SBStream &description) {
1278ac7ddfbfSEd Maste   ValueLocker locker;
1279ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1280435933ddSDimitry Andric   if (value_sp) {
1281ac7ddfbfSEd Maste     value_sp->GetExpressionPath(description.ref(), false);
1282ac7ddfbfSEd Maste     return true;
1283ac7ddfbfSEd Maste   }
1284ac7ddfbfSEd Maste   return false;
1285ac7ddfbfSEd Maste }
1286ac7ddfbfSEd Maste 
GetExpressionPath(SBStream & description,bool qualify_cxx_base_classes)1287435933ddSDimitry Andric bool SBValue::GetExpressionPath(SBStream &description,
1288435933ddSDimitry Andric                                 bool qualify_cxx_base_classes) {
1289ac7ddfbfSEd Maste   ValueLocker locker;
1290ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1291435933ddSDimitry Andric   if (value_sp) {
1292ac7ddfbfSEd Maste     value_sp->GetExpressionPath(description.ref(), qualify_cxx_base_classes);
1293ac7ddfbfSEd Maste     return true;
1294ac7ddfbfSEd Maste   }
1295ac7ddfbfSEd Maste   return false;
1296ac7ddfbfSEd Maste }
1297ac7ddfbfSEd Maste 
GetDescription(SBStream & description)1298435933ddSDimitry Andric bool SBValue::GetDescription(SBStream &description) {
1299ac7ddfbfSEd Maste   Stream &strm = description.ref();
1300ac7ddfbfSEd Maste 
1301ac7ddfbfSEd Maste   ValueLocker locker;
1302ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1303ac7ddfbfSEd Maste   if (value_sp)
130435617911SEd Maste     value_sp->Dump(strm);
1305ac7ddfbfSEd Maste   else
1306ac7ddfbfSEd Maste     strm.PutCString("No value");
1307ac7ddfbfSEd Maste 
1308ac7ddfbfSEd Maste   return true;
1309ac7ddfbfSEd Maste }
1310ac7ddfbfSEd Maste 
GetFormat()1311435933ddSDimitry Andric lldb::Format SBValue::GetFormat() {
1312ac7ddfbfSEd Maste   ValueLocker locker;
1313ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1314ac7ddfbfSEd Maste   if (value_sp)
1315ac7ddfbfSEd Maste     return value_sp->GetFormat();
1316ac7ddfbfSEd Maste   return eFormatDefault;
1317ac7ddfbfSEd Maste }
1318ac7ddfbfSEd Maste 
SetFormat(lldb::Format format)1319435933ddSDimitry Andric void SBValue::SetFormat(lldb::Format format) {
1320ac7ddfbfSEd Maste   ValueLocker locker;
1321ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1322ac7ddfbfSEd Maste   if (value_sp)
1323ac7ddfbfSEd Maste     value_sp->SetFormat(format);
1324ac7ddfbfSEd Maste }
1325ac7ddfbfSEd Maste 
AddressOf()1326435933ddSDimitry Andric lldb::SBValue SBValue::AddressOf() {
1327ac7ddfbfSEd Maste   SBValue sb_value;
1328ac7ddfbfSEd Maste   ValueLocker locker;
1329ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1330435933ddSDimitry Andric   if (value_sp) {
13315517e702SDimitry Andric     Status error;
1332435933ddSDimitry Andric     sb_value.SetSP(value_sp->AddressOf(error), GetPreferDynamicValue(),
1333435933ddSDimitry Andric                    GetPreferSyntheticValue());
1334ac7ddfbfSEd Maste   }
1335ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1336ac7ddfbfSEd Maste   if (log)
13370127ef0fSEd Maste     log->Printf("SBValue(%p)::AddressOf () => SBValue(%p)",
13380127ef0fSEd Maste                 static_cast<void *>(value_sp.get()),
13390127ef0fSEd Maste                 static_cast<void *>(value_sp.get()));
1340ac7ddfbfSEd Maste 
1341ac7ddfbfSEd Maste   return sb_value;
1342ac7ddfbfSEd Maste }
1343ac7ddfbfSEd Maste 
GetLoadAddress()1344435933ddSDimitry Andric lldb::addr_t SBValue::GetLoadAddress() {
1345ac7ddfbfSEd Maste   lldb::addr_t value = LLDB_INVALID_ADDRESS;
1346ac7ddfbfSEd Maste   ValueLocker locker;
1347ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1348435933ddSDimitry Andric   if (value_sp) {
1349ac7ddfbfSEd Maste     TargetSP target_sp(value_sp->GetTargetSP());
1350435933ddSDimitry Andric     if (target_sp) {
1351ac7ddfbfSEd Maste       const bool scalar_is_load_address = true;
1352ac7ddfbfSEd Maste       AddressType addr_type;
1353ac7ddfbfSEd Maste       value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1354435933ddSDimitry Andric       if (addr_type == eAddressTypeFile) {
1355ac7ddfbfSEd Maste         ModuleSP module_sp(value_sp->GetModule());
1356ac7ddfbfSEd Maste         if (!module_sp)
1357ac7ddfbfSEd Maste           value = LLDB_INVALID_ADDRESS;
1358435933ddSDimitry Andric         else {
1359ac7ddfbfSEd Maste           Address addr;
1360ac7ddfbfSEd Maste           module_sp->ResolveFileAddress(value, addr);
1361ac7ddfbfSEd Maste           value = addr.GetLoadAddress(target_sp.get());
1362ac7ddfbfSEd Maste         }
1363435933ddSDimitry Andric       } else if (addr_type == eAddressTypeHost ||
1364435933ddSDimitry Andric                  addr_type == eAddressTypeInvalid)
1365ac7ddfbfSEd Maste         value = LLDB_INVALID_ADDRESS;
1366ac7ddfbfSEd Maste     }
1367ac7ddfbfSEd Maste   }
1368ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1369ac7ddfbfSEd Maste   if (log)
13700127ef0fSEd Maste     log->Printf("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")",
13710127ef0fSEd Maste                 static_cast<void *>(value_sp.get()), value);
1372ac7ddfbfSEd Maste 
1373ac7ddfbfSEd Maste   return value;
1374ac7ddfbfSEd Maste }
1375ac7ddfbfSEd Maste 
GetAddress()1376435933ddSDimitry Andric lldb::SBAddress SBValue::GetAddress() {
1377ac7ddfbfSEd Maste   Address addr;
1378ac7ddfbfSEd Maste   ValueLocker locker;
1379ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1380435933ddSDimitry Andric   if (value_sp) {
1381ac7ddfbfSEd Maste     TargetSP target_sp(value_sp->GetTargetSP());
1382435933ddSDimitry Andric     if (target_sp) {
1383ac7ddfbfSEd Maste       lldb::addr_t value = LLDB_INVALID_ADDRESS;
1384ac7ddfbfSEd Maste       const bool scalar_is_load_address = true;
1385ac7ddfbfSEd Maste       AddressType addr_type;
1386ac7ddfbfSEd Maste       value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1387435933ddSDimitry Andric       if (addr_type == eAddressTypeFile) {
1388ac7ddfbfSEd Maste         ModuleSP module_sp(value_sp->GetModule());
1389ac7ddfbfSEd Maste         if (module_sp)
1390ac7ddfbfSEd Maste           module_sp->ResolveFileAddress(value, addr);
1391435933ddSDimitry Andric       } else if (addr_type == eAddressTypeLoad) {
13924ba319b5SDimitry Andric         // no need to check the return value on this.. if it can actually do
13934ba319b5SDimitry Andric         // the resolve addr will be in the form (section,offset), otherwise it
13944ba319b5SDimitry Andric         // will simply be returned as (NULL, value)
1395ac7ddfbfSEd Maste         addr.SetLoadAddress(value, target_sp.get());
1396ac7ddfbfSEd Maste       }
1397ac7ddfbfSEd Maste     }
1398ac7ddfbfSEd Maste   }
1399ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1400ac7ddfbfSEd Maste   if (log)
14010127ef0fSEd Maste     log->Printf("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")",
14020127ef0fSEd Maste                 static_cast<void *>(value_sp.get()),
1403435933ddSDimitry Andric                 (addr.GetSection() ? addr.GetSection()->GetName().GetCString()
14040127ef0fSEd Maste                                    : "NULL"),
1405ac7ddfbfSEd Maste                 addr.GetOffset());
1406ac7ddfbfSEd Maste   return SBAddress(new Address(addr));
1407ac7ddfbfSEd Maste }
1408ac7ddfbfSEd Maste 
GetPointeeData(uint32_t item_idx,uint32_t item_count)1409435933ddSDimitry Andric lldb::SBData SBValue::GetPointeeData(uint32_t item_idx, uint32_t item_count) {
1410ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1411ac7ddfbfSEd Maste   lldb::SBData sb_data;
1412ac7ddfbfSEd Maste   ValueLocker locker;
1413ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1414435933ddSDimitry Andric   if (value_sp) {
1415ac7ddfbfSEd Maste     TargetSP target_sp(value_sp->GetTargetSP());
1416435933ddSDimitry Andric     if (target_sp) {
1417ac7ddfbfSEd Maste       DataExtractorSP data_sp(new DataExtractor());
1418ac7ddfbfSEd Maste       value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1419ac7ddfbfSEd Maste       if (data_sp->GetByteSize() > 0)
1420ac7ddfbfSEd Maste         *sb_data = data_sp;
1421ac7ddfbfSEd Maste     }
1422ac7ddfbfSEd Maste   }
1423ac7ddfbfSEd Maste   if (log)
1424ac7ddfbfSEd Maste     log->Printf("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
14250127ef0fSEd Maste                 static_cast<void *>(value_sp.get()), item_idx, item_count,
14260127ef0fSEd Maste                 static_cast<void *>(sb_data.get()));
1427ac7ddfbfSEd Maste 
1428ac7ddfbfSEd Maste   return sb_data;
1429ac7ddfbfSEd Maste }
1430ac7ddfbfSEd Maste 
GetData()1431435933ddSDimitry Andric lldb::SBData SBValue::GetData() {
1432ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1433ac7ddfbfSEd Maste   lldb::SBData sb_data;
1434ac7ddfbfSEd Maste   ValueLocker locker;
1435ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1436435933ddSDimitry Andric   if (value_sp) {
1437ac7ddfbfSEd Maste     DataExtractorSP data_sp(new DataExtractor());
14385517e702SDimitry Andric     Status error;
14390127ef0fSEd Maste     value_sp->GetData(*data_sp, error);
14400127ef0fSEd Maste     if (error.Success())
1441ac7ddfbfSEd Maste       *sb_data = data_sp;
1442ac7ddfbfSEd Maste   }
1443ac7ddfbfSEd Maste   if (log)
1444ac7ddfbfSEd Maste     log->Printf("SBValue(%p)::GetData () => SBData(%p)",
14450127ef0fSEd Maste                 static_cast<void *>(value_sp.get()),
14460127ef0fSEd Maste                 static_cast<void *>(sb_data.get()));
1447ac7ddfbfSEd Maste 
1448ac7ddfbfSEd Maste   return sb_data;
1449ac7ddfbfSEd Maste }
1450ac7ddfbfSEd Maste 
SetData(lldb::SBData & data,SBError & error)1451435933ddSDimitry Andric bool SBValue::SetData(lldb::SBData &data, SBError &error) {
1452ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1453ac7ddfbfSEd Maste   ValueLocker locker;
1454ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1455ac7ddfbfSEd Maste   bool ret = true;
1456ac7ddfbfSEd Maste 
1457435933ddSDimitry Andric   if (value_sp) {
1458ac7ddfbfSEd Maste     DataExtractor *data_extractor = data.get();
1459ac7ddfbfSEd Maste 
1460435933ddSDimitry Andric     if (!data_extractor) {
1461ac7ddfbfSEd Maste       if (log)
14620127ef0fSEd Maste         log->Printf("SBValue(%p)::SetData() => error: no data to set",
14630127ef0fSEd Maste                     static_cast<void *>(value_sp.get()));
1464ac7ddfbfSEd Maste 
1465ac7ddfbfSEd Maste       error.SetErrorString("No data to set");
1466ac7ddfbfSEd Maste       ret = false;
1467435933ddSDimitry Andric     } else {
14685517e702SDimitry Andric       Status set_error;
1469ac7ddfbfSEd Maste 
1470ac7ddfbfSEd Maste       value_sp->SetData(*data_extractor, set_error);
1471ac7ddfbfSEd Maste 
1472435933ddSDimitry Andric       if (!set_error.Success()) {
1473435933ddSDimitry Andric         error.SetErrorStringWithFormat("Couldn't set data: %s",
1474435933ddSDimitry Andric                                        set_error.AsCString());
1475ac7ddfbfSEd Maste         ret = false;
1476ac7ddfbfSEd Maste       }
1477ac7ddfbfSEd Maste     }
1478435933ddSDimitry Andric   } else {
1479435933ddSDimitry Andric     error.SetErrorStringWithFormat(
1480435933ddSDimitry Andric         "Couldn't set data: could not get SBValue: %s",
1481435933ddSDimitry Andric         locker.GetError().AsCString());
1482ac7ddfbfSEd Maste     ret = false;
1483ac7ddfbfSEd Maste   }
1484ac7ddfbfSEd Maste 
1485ac7ddfbfSEd Maste   if (log)
1486ac7ddfbfSEd Maste     log->Printf("SBValue(%p)::SetData (%p) => %s",
14870127ef0fSEd Maste                 static_cast<void *>(value_sp.get()),
14880127ef0fSEd Maste                 static_cast<void *>(data.get()), ret ? "true" : "false");
1489ac7ddfbfSEd Maste   return ret;
1490ac7ddfbfSEd Maste }
1491ac7ddfbfSEd Maste 
GetDeclaration()1492435933ddSDimitry Andric lldb::SBDeclaration SBValue::GetDeclaration() {
1493ac7ddfbfSEd Maste   ValueLocker locker;
1494ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1495ac7ddfbfSEd Maste   SBDeclaration decl_sb;
1496435933ddSDimitry Andric   if (value_sp) {
1497ac7ddfbfSEd Maste     Declaration decl;
1498ac7ddfbfSEd Maste     if (value_sp->GetDeclaration(decl))
1499ac7ddfbfSEd Maste       decl_sb.SetDeclaration(decl);
1500ac7ddfbfSEd Maste   }
1501ac7ddfbfSEd Maste   return decl_sb;
1502ac7ddfbfSEd Maste }
1503ac7ddfbfSEd Maste 
Watch(bool resolve_location,bool read,bool write,SBError & error)1504435933ddSDimitry Andric lldb::SBWatchpoint SBValue::Watch(bool resolve_location, bool read, bool write,
1505435933ddSDimitry Andric                                   SBError &error) {
1506ac7ddfbfSEd Maste   SBWatchpoint sb_watchpoint;
1507ac7ddfbfSEd Maste 
1508ac7ddfbfSEd Maste   // If the SBValue is not valid, there's no point in even trying to watch it.
1509ac7ddfbfSEd Maste   ValueLocker locker;
1510ac7ddfbfSEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
1511ac7ddfbfSEd Maste   TargetSP target_sp(GetTarget().GetSP());
1512435933ddSDimitry Andric   if (value_sp && target_sp) {
1513ac7ddfbfSEd Maste     // Read and Write cannot both be false.
1514ac7ddfbfSEd Maste     if (!read && !write)
1515ac7ddfbfSEd Maste       return sb_watchpoint;
1516ac7ddfbfSEd Maste 
1517ac7ddfbfSEd Maste     // If the value is not in scope, don't try and watch and invalid value
1518ac7ddfbfSEd Maste     if (!IsInScope())
1519ac7ddfbfSEd Maste       return sb_watchpoint;
1520ac7ddfbfSEd Maste 
1521ac7ddfbfSEd Maste     addr_t addr = GetLoadAddress();
1522ac7ddfbfSEd Maste     if (addr == LLDB_INVALID_ADDRESS)
1523ac7ddfbfSEd Maste       return sb_watchpoint;
1524ac7ddfbfSEd Maste     size_t byte_size = GetByteSize();
1525ac7ddfbfSEd Maste     if (byte_size == 0)
1526ac7ddfbfSEd Maste       return sb_watchpoint;
1527ac7ddfbfSEd Maste 
1528ac7ddfbfSEd Maste     uint32_t watch_type = 0;
1529ac7ddfbfSEd Maste     if (read)
1530ac7ddfbfSEd Maste       watch_type |= LLDB_WATCH_TYPE_READ;
1531ac7ddfbfSEd Maste     if (write)
1532ac7ddfbfSEd Maste       watch_type |= LLDB_WATCH_TYPE_WRITE;
1533ac7ddfbfSEd Maste 
15345517e702SDimitry Andric     Status rc;
15359f2f44ceSEd Maste     CompilerType type(value_sp->GetCompilerType());
1536435933ddSDimitry Andric     WatchpointSP watchpoint_sp =
1537435933ddSDimitry Andric         target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
1538ac7ddfbfSEd Maste     error.SetError(rc);
1539ac7ddfbfSEd Maste 
1540435933ddSDimitry Andric     if (watchpoint_sp) {
1541ac7ddfbfSEd Maste       sb_watchpoint.SetSP(watchpoint_sp);
1542ac7ddfbfSEd Maste       Declaration decl;
1543435933ddSDimitry Andric       if (value_sp->GetDeclaration(decl)) {
1544435933ddSDimitry Andric         if (decl.GetFile()) {
1545ac7ddfbfSEd Maste           StreamString ss;
1546ac7ddfbfSEd Maste           // True to show fullpath for declaration file.
1547ac7ddfbfSEd Maste           decl.DumpStopContext(&ss, true);
1548ac7ddfbfSEd Maste           watchpoint_sp->SetDeclInfo(ss.GetString());
1549ac7ddfbfSEd Maste         }
1550ac7ddfbfSEd Maste       }
1551ac7ddfbfSEd Maste     }
1552435933ddSDimitry Andric   } else if (target_sp) {
1553ac7ddfbfSEd Maste     Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1554ac7ddfbfSEd Maste     if (log)
15550127ef0fSEd Maste       log->Printf("SBValue(%p)::Watch() => error getting SBValue: %s",
15560127ef0fSEd Maste                   static_cast<void *>(value_sp.get()),
15570127ef0fSEd Maste                   locker.GetError().AsCString());
1558ac7ddfbfSEd Maste 
1559435933ddSDimitry Andric     error.SetErrorStringWithFormat("could not get SBValue: %s",
1560435933ddSDimitry Andric                                    locker.GetError().AsCString());
1561435933ddSDimitry Andric   } else {
1562ac7ddfbfSEd Maste     Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1563ac7ddfbfSEd Maste     if (log)
15640127ef0fSEd Maste       log->Printf("SBValue(%p)::Watch() => error getting SBValue: no target",
15650127ef0fSEd Maste                   static_cast<void *>(value_sp.get()));
1566ac7ddfbfSEd Maste     error.SetErrorString("could not set watchpoint, a target is required");
1567ac7ddfbfSEd Maste   }
1568ac7ddfbfSEd Maste 
1569ac7ddfbfSEd Maste   return sb_watchpoint;
1570ac7ddfbfSEd Maste }
1571ac7ddfbfSEd Maste 
1572435933ddSDimitry Andric // FIXME: Remove this method impl (as well as the decl in .h) once it is no
1573435933ddSDimitry Andric // longer needed.
1574ac7ddfbfSEd Maste // Backward compatibility fix in the interim.
Watch(bool resolve_location,bool read,bool write)1575435933ddSDimitry Andric lldb::SBWatchpoint SBValue::Watch(bool resolve_location, bool read,
1576435933ddSDimitry Andric                                   bool write) {
1577ac7ddfbfSEd Maste   SBError error;
1578ac7ddfbfSEd Maste   return Watch(resolve_location, read, write, error);
1579ac7ddfbfSEd Maste }
1580ac7ddfbfSEd Maste 
WatchPointee(bool resolve_location,bool read,bool write,SBError & error)1581435933ddSDimitry Andric lldb::SBWatchpoint SBValue::WatchPointee(bool resolve_location, bool read,
1582435933ddSDimitry Andric                                          bool write, SBError &error) {
1583ac7ddfbfSEd Maste   SBWatchpoint sb_watchpoint;
1584ac7ddfbfSEd Maste   if (IsInScope() && GetType().IsPointerType())
1585ac7ddfbfSEd Maste     sb_watchpoint = Dereference().Watch(resolve_location, read, write, error);
1586ac7ddfbfSEd Maste   return sb_watchpoint;
1587ac7ddfbfSEd Maste }
15887aa51b79SEd Maste 
Persist()1589435933ddSDimitry Andric lldb::SBValue SBValue::Persist() {
15907aa51b79SEd Maste   ValueLocker locker;
15917aa51b79SEd Maste   lldb::ValueObjectSP value_sp(GetSP(locker));
15927aa51b79SEd Maste   SBValue persisted_sb;
1593435933ddSDimitry Andric   if (value_sp) {
15947aa51b79SEd Maste     persisted_sb.SetSP(value_sp->Persist());
15957aa51b79SEd Maste   }
15967aa51b79SEd Maste   return persisted_sb;
15977aa51b79SEd Maste }
1598