1 //===-- SBValue.cpp ---------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/API/SBValue.h"
11 
12 #include "lldb/API/SBDeclaration.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/API/SBTypeFilter.h"
15 #include "lldb/API/SBTypeFormat.h"
16 #include "lldb/API/SBTypeSummary.h"
17 #include "lldb/API/SBTypeSynthetic.h"
18 
19 #include "lldb/Breakpoint/Watchpoint.h"
20 #include "lldb/Core/DataExtractor.h"
21 #include "lldb/Core/Log.h"
22 #include "lldb/Core/Module.h"
23 #include "lldb/Core/Scalar.h"
24 #include "lldb/Core/Section.h"
25 #include "lldb/Core/Stream.h"
26 #include "lldb/Core/StreamFile.h"
27 #include "lldb/Core/Value.h"
28 #include "lldb/Core/ValueObject.h"
29 #include "lldb/Core/ValueObjectConstResult.h"
30 #include "lldb/DataFormatters/DataVisualization.h"
31 #include "lldb/Symbol/Block.h"
32 #include "lldb/Symbol/Declaration.h"
33 #include "lldb/Symbol/ObjectFile.h"
34 #include "lldb/Symbol/Type.h"
35 #include "lldb/Symbol/Variable.h"
36 #include "lldb/Symbol/VariableList.h"
37 #include "lldb/Target/ExecutionContext.h"
38 #include "lldb/Target/Process.h"
39 #include "lldb/Target/StackFrame.h"
40 #include "lldb/Target/Target.h"
41 #include "lldb/Target/Thread.h"
42 
43 #include "lldb/API/SBDebugger.h"
44 #include "lldb/API/SBExpressionOptions.h"
45 #include "lldb/API/SBFrame.h"
46 #include "lldb/API/SBProcess.h"
47 #include "lldb/API/SBTarget.h"
48 #include "lldb/API/SBThread.h"
49 
50 using namespace lldb;
51 using namespace lldb_private;
52 
53 class ValueImpl
54 {
55 public:
56     ValueImpl ()
57     {
58     }
59 
60     ValueImpl (lldb::ValueObjectSP in_valobj_sp,
61                lldb::DynamicValueType use_dynamic,
62                bool use_synthetic,
63                const char *name = NULL) :
64     m_valobj_sp(),
65     m_use_dynamic(use_dynamic),
66     m_use_synthetic(use_synthetic),
67     m_name (name)
68     {
69         if (in_valobj_sp)
70         {
71             if ( (m_valobj_sp = in_valobj_sp->GetQualifiedRepresentationIfAvailable(lldb::eNoDynamicValues, false)) )
72             {
73                 if (!m_name.IsEmpty())
74                     m_valobj_sp->SetName(m_name);
75             }
76         }
77     }
78 
79     ValueImpl (const ValueImpl& rhs) :
80     m_valobj_sp(rhs.m_valobj_sp),
81     m_use_dynamic(rhs.m_use_dynamic),
82     m_use_synthetic(rhs.m_use_synthetic),
83     m_name (rhs.m_name)
84     {
85     }
86 
87     ValueImpl &
88     operator = (const ValueImpl &rhs)
89     {
90         if (this != &rhs)
91         {
92             m_valobj_sp = rhs.m_valobj_sp;
93             m_use_dynamic = rhs.m_use_dynamic;
94             m_use_synthetic = rhs.m_use_synthetic;
95             m_name = rhs.m_name;
96         }
97         return *this;
98     }
99 
100     bool
101     IsValid ()
102     {
103         if (m_valobj_sp.get() == NULL)
104             return false;
105         else
106         {
107             // FIXME: This check is necessary but not sufficient.  We for sure don't want to touch SBValues whose owning
108             // targets have gone away.  This check is a little weak in that it enforces that restriction when you call
109             // IsValid, but since IsValid doesn't lock the target, you have no guarantee that the SBValue won't go
110             // invalid after you call this...
111             // Also, an SBValue could depend on data from one of the modules in the target, and those could go away
112             // independently of the target, for instance if a module is unloaded.  But right now, neither SBValues
113             // nor ValueObjects know which modules they depend on.  So I have no good way to make that check without
114             // tracking that in all the ValueObject subclasses.
115             TargetSP target_sp = m_valobj_sp->GetTargetSP();
116             if (target_sp && target_sp->IsValid())
117                 return true;
118             else
119                 return false;
120         }
121     }
122 
123     lldb::ValueObjectSP
124     GetRootSP ()
125     {
126         return m_valobj_sp;
127     }
128 
129     lldb::ValueObjectSP
130     GetSP(Process::StopLocker &stop_locker, std::unique_lock<std::recursive_mutex> &lock, Error &error)
131     {
132         Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
133         if (!m_valobj_sp)
134         {
135             error.SetErrorString("invalid value object");
136             return m_valobj_sp;
137         }
138 
139         lldb::ValueObjectSP value_sp = m_valobj_sp;
140 
141         Target *target = value_sp->GetTargetSP().get();
142         if (!target)
143             return ValueObjectSP();
144 
145         lock = std::unique_lock<std::recursive_mutex>(target->GetAPIMutex());
146 
147         ProcessSP process_sp(value_sp->GetProcessSP());
148         if (process_sp && !stop_locker.TryLock (&process_sp->GetRunLock()))
149         {
150             // We don't allow people to play around with ValueObject if the process is running.
151             // If you want to look at values, pause the process, then look.
152             if (log)
153                 log->Printf ("SBValue(%p)::GetSP() => error: process is running",
154                              static_cast<void*>(value_sp.get()));
155             error.SetErrorString ("process must be stopped.");
156             return ValueObjectSP();
157         }
158 
159         if (m_use_dynamic != eNoDynamicValues)
160         {
161             ValueObjectSP dynamic_sp = value_sp->GetDynamicValue(m_use_dynamic);
162             if (dynamic_sp)
163                 value_sp = dynamic_sp;
164         }
165 
166         if (m_use_synthetic)
167         {
168             ValueObjectSP synthetic_sp = value_sp->GetSyntheticValue(m_use_synthetic);
169             if (synthetic_sp)
170                 value_sp = synthetic_sp;
171         }
172 
173         if (!value_sp)
174             error.SetErrorString("invalid value object");
175         if (!m_name.IsEmpty())
176             value_sp->SetName(m_name);
177 
178         return value_sp;
179     }
180 
181     void
182     SetUseDynamic (lldb::DynamicValueType use_dynamic)
183     {
184         m_use_dynamic = use_dynamic;
185     }
186 
187     void
188     SetUseSynthetic (bool use_synthetic)
189     {
190         m_use_synthetic = use_synthetic;
191     }
192 
193     lldb::DynamicValueType
194     GetUseDynamic ()
195     {
196         return m_use_dynamic;
197     }
198 
199     bool
200     GetUseSynthetic ()
201     {
202         return m_use_synthetic;
203     }
204 
205     // All the derived values that we would make from the m_valobj_sp will share
206     // the ExecutionContext with m_valobj_sp, so we don't need to do the calculations
207     // in GetSP to return the Target, Process, Thread or Frame.  It is convenient to
208     // provide simple accessors for these, which I do here.
209     TargetSP
210     GetTargetSP ()
211     {
212         if (m_valobj_sp)
213             return m_valobj_sp->GetTargetSP();
214         else
215             return TargetSP();
216     }
217 
218     ProcessSP
219     GetProcessSP ()
220     {
221         if (m_valobj_sp)
222             return m_valobj_sp->GetProcessSP();
223         else
224             return ProcessSP();
225     }
226 
227     ThreadSP
228     GetThreadSP ()
229     {
230         if (m_valobj_sp)
231             return m_valobj_sp->GetThreadSP();
232         else
233             return ThreadSP();
234     }
235 
236     StackFrameSP
237     GetFrameSP ()
238     {
239         if (m_valobj_sp)
240             return m_valobj_sp->GetFrameSP();
241         else
242             return StackFrameSP();
243     }
244 
245 private:
246     lldb::ValueObjectSP m_valobj_sp;
247     lldb::DynamicValueType m_use_dynamic;
248     bool m_use_synthetic;
249     ConstString m_name;
250 };
251 
252 class ValueLocker
253 {
254 public:
255     ValueLocker ()
256     {
257     }
258 
259     ValueObjectSP
260     GetLockedSP(ValueImpl &in_value)
261     {
262         return in_value.GetSP(m_stop_locker, m_lock, m_lock_error);
263     }
264 
265     Error &
266     GetError()
267     {
268         return m_lock_error;
269     }
270 
271 private:
272     Process::StopLocker m_stop_locker;
273     std::unique_lock<std::recursive_mutex> m_lock;
274     Error m_lock_error;
275 };
276 
277 SBValue::SBValue () :
278 m_opaque_sp ()
279 {
280 }
281 
282 SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
283 {
284     SetSP(value_sp);
285 }
286 
287 SBValue::SBValue(const SBValue &rhs)
288 {
289     SetSP(rhs.m_opaque_sp);
290 }
291 
292 SBValue &
293 SBValue::operator = (const SBValue &rhs)
294 {
295     if (this != &rhs)
296     {
297         SetSP(rhs.m_opaque_sp);
298     }
299     return *this;
300 }
301 
302 SBValue::~SBValue()
303 {
304 }
305 
306 bool
307 SBValue::IsValid ()
308 {
309     // If this function ever changes to anything that does more than just
310     // check if the opaque shared pointer is non NULL, then we need to update
311     // all "if (m_opaque_sp)" code in this file.
312     return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid() && m_opaque_sp->GetRootSP().get() != NULL;
313 }
314 
315 void
316 SBValue::Clear()
317 {
318     m_opaque_sp.reset();
319 }
320 
321 SBError
322 SBValue::GetError()
323 {
324     SBError sb_error;
325 
326     ValueLocker locker;
327     lldb::ValueObjectSP value_sp(GetSP(locker));
328     if (value_sp)
329         sb_error.SetError(value_sp->GetError());
330     else
331         sb_error.SetErrorStringWithFormat ("error: %s", locker.GetError().AsCString());
332 
333     return sb_error;
334 }
335 
336 user_id_t
337 SBValue::GetID()
338 {
339     ValueLocker locker;
340     lldb::ValueObjectSP value_sp(GetSP(locker));
341     if (value_sp)
342         return value_sp->GetID();
343     return LLDB_INVALID_UID;
344 }
345 
346 const char *
347 SBValue::GetName()
348 {
349     const char *name = NULL;
350     ValueLocker locker;
351     lldb::ValueObjectSP value_sp(GetSP(locker));
352     if (value_sp)
353         name = value_sp->GetName().GetCString();
354 
355     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
356     if (log)
357     {
358         if (name)
359             log->Printf ("SBValue(%p)::GetName () => \"%s\"",
360                          static_cast<void*>(value_sp.get()), name);
361         else
362             log->Printf ("SBValue(%p)::GetName () => NULL",
363                          static_cast<void*>(value_sp.get()));
364     }
365 
366     return name;
367 }
368 
369 const char *
370 SBValue::GetTypeName ()
371 {
372     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
373     const char *name = NULL;
374     ValueLocker locker;
375     lldb::ValueObjectSP value_sp(GetSP(locker));
376     if (value_sp)
377     {
378         name = value_sp->GetQualifiedTypeName().GetCString();
379     }
380 
381     if (log)
382     {
383         if (name)
384             log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"",
385                          static_cast<void*>(value_sp.get()), name);
386         else
387             log->Printf ("SBValue(%p)::GetTypeName () => NULL",
388                          static_cast<void*>(value_sp.get()));
389     }
390 
391     return name;
392 }
393 
394 const char *
395 SBValue::GetDisplayTypeName ()
396 {
397     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
398     const char *name = NULL;
399     ValueLocker locker;
400     lldb::ValueObjectSP value_sp(GetSP(locker));
401     if (value_sp)
402     {
403         name = value_sp->GetDisplayTypeName().GetCString();
404     }
405 
406     if (log)
407     {
408         if (name)
409             log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"",
410                          static_cast<void*>(value_sp.get()), name);
411         else
412             log->Printf ("SBValue(%p)::GetTypeName () => NULL",
413                          static_cast<void*>(value_sp.get()));
414     }
415 
416     return name;
417 }
418 
419 size_t
420 SBValue::GetByteSize ()
421 {
422     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
423     size_t result = 0;
424 
425     ValueLocker locker;
426     lldb::ValueObjectSP value_sp(GetSP(locker));
427     if (value_sp)
428     {
429         result = value_sp->GetByteSize();
430     }
431 
432     if (log)
433         log->Printf ("SBValue(%p)::GetByteSize () => %" PRIu64,
434                      static_cast<void*>(value_sp.get()),
435                      static_cast<uint64_t>(result));
436 
437     return result;
438 }
439 
440 bool
441 SBValue::IsInScope ()
442 {
443     bool result = false;
444 
445     ValueLocker locker;
446     lldb::ValueObjectSP value_sp(GetSP(locker));
447     if (value_sp)
448     {
449         result = value_sp->IsInScope ();
450     }
451 
452     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
453     if (log)
454         log->Printf ("SBValue(%p)::IsInScope () => %i",
455                      static_cast<void*>(value_sp.get()), result);
456 
457     return result;
458 }
459 
460 const char *
461 SBValue::GetValue ()
462 {
463     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
464 
465     const char *cstr = NULL;
466     ValueLocker locker;
467     lldb::ValueObjectSP value_sp(GetSP(locker));
468     if (value_sp)
469     {
470         cstr = value_sp->GetValueAsCString ();
471     }
472     if (log)
473     {
474         if (cstr)
475             log->Printf ("SBValue(%p)::GetValue() => \"%s\"",
476                          static_cast<void*>(value_sp.get()), cstr);
477         else
478             log->Printf ("SBValue(%p)::GetValue() => NULL",
479                          static_cast<void*>(value_sp.get()));
480     }
481 
482     return cstr;
483 }
484 
485 ValueType
486 SBValue::GetValueType ()
487 {
488     ValueType result = eValueTypeInvalid;
489     ValueLocker locker;
490     lldb::ValueObjectSP value_sp(GetSP(locker));
491     if (value_sp)
492         result = value_sp->GetValueType();
493 
494     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
495     if (log)
496     {
497         switch (result)
498         {
499             case eValueTypeInvalid:
500                 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid",
501                              static_cast<void*>(value_sp.get()));
502                 break;
503             case eValueTypeVariableGlobal:
504                 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal",
505                              static_cast<void*>(value_sp.get()));
506                 break;
507             case eValueTypeVariableStatic:
508                 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic",
509                              static_cast<void*>(value_sp.get()));
510                 break;
511             case eValueTypeVariableArgument:
512                 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument",
513                              static_cast<void*>(value_sp.get()));
514                 break;
515             case eValueTypeVariableLocal:
516                 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal",
517                              static_cast<void*>(value_sp.get()));
518                 break;
519             case eValueTypeRegister:
520                 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister",
521                              static_cast<void*>(value_sp.get()));
522                 break;
523             case eValueTypeRegisterSet:
524                 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet",
525                              static_cast<void*>(value_sp.get()));
526                 break;
527             case eValueTypeConstResult:
528                 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult",
529                              static_cast<void*>(value_sp.get()));
530                 break;
531         }
532     }
533     return result;
534 }
535 
536 const char *
537 SBValue::GetObjectDescription ()
538 {
539     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
540     const char *cstr = NULL;
541     ValueLocker locker;
542     lldb::ValueObjectSP value_sp(GetSP(locker));
543     if (value_sp)
544     {
545         cstr = value_sp->GetObjectDescription ();
546     }
547     if (log)
548     {
549         if (cstr)
550             log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"",
551                          static_cast<void*>(value_sp.get()), cstr);
552         else
553             log->Printf ("SBValue(%p)::GetObjectDescription() => NULL",
554                          static_cast<void*>(value_sp.get()));
555     }
556     return cstr;
557 }
558 
559 const char *
560 SBValue::GetTypeValidatorResult ()
561 {
562     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
563     const char *cstr = NULL;
564     ValueLocker locker;
565     lldb::ValueObjectSP value_sp(GetSP(locker));
566     if (value_sp)
567     {
568         const auto& validation(value_sp->GetValidationStatus());
569         if (TypeValidatorResult::Failure == validation.first)
570         {
571             if (validation.second.empty())
572                 cstr = "unknown error";
573             else
574                 cstr = validation.second.c_str();
575         }
576     }
577     if (log)
578     {
579         if (cstr)
580             log->Printf ("SBValue(%p)::GetTypeValidatorResult() => \"%s\"",
581                          static_cast<void*>(value_sp.get()), cstr);
582         else
583             log->Printf ("SBValue(%p)::GetTypeValidatorResult() => NULL",
584                          static_cast<void*>(value_sp.get()));
585     }
586     return cstr;
587 }
588 
589 SBType
590 SBValue::GetType()
591 {
592     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
593     SBType sb_type;
594     ValueLocker locker;
595     lldb::ValueObjectSP value_sp(GetSP(locker));
596     TypeImplSP type_sp;
597     if (value_sp)
598     {
599         type_sp.reset (new TypeImpl(value_sp->GetTypeImpl()));
600         sb_type.SetSP(type_sp);
601     }
602     if (log)
603     {
604         if (type_sp)
605             log->Printf ("SBValue(%p)::GetType => SBType(%p)",
606                          static_cast<void*>(value_sp.get()),
607                          static_cast<void*>(type_sp.get()));
608         else
609             log->Printf ("SBValue(%p)::GetType => NULL",
610                          static_cast<void*>(value_sp.get()));
611     }
612     return sb_type;
613 }
614 
615 bool
616 SBValue::GetValueDidChange ()
617 {
618     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
619     bool result = false;
620     ValueLocker locker;
621     lldb::ValueObjectSP value_sp(GetSP(locker));
622     if (value_sp)
623     {
624         if (value_sp->UpdateValueIfNeeded(false))
625             result = value_sp->GetValueDidChange ();
626     }
627     if (log)
628         log->Printf ("SBValue(%p)::GetValueDidChange() => %i",
629                      static_cast<void*>(value_sp.get()), result);
630 
631     return result;
632 }
633 
634 const char *
635 SBValue::GetSummary ()
636 {
637     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
638     const char *cstr = NULL;
639     ValueLocker locker;
640     lldb::ValueObjectSP value_sp(GetSP(locker));
641     if (value_sp)
642     {
643         cstr = value_sp->GetSummaryAsCString();
644     }
645     if (log)
646     {
647         if (cstr)
648             log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
649                          static_cast<void*>(value_sp.get()), cstr);
650         else
651             log->Printf ("SBValue(%p)::GetSummary() => NULL",
652                          static_cast<void*>(value_sp.get()));
653     }
654     return cstr;
655 }
656 
657 const char *
658 SBValue::GetSummary (lldb::SBStream& stream,
659                      lldb::SBTypeSummaryOptions& options)
660 {
661     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
662     ValueLocker locker;
663     lldb::ValueObjectSP value_sp(GetSP(locker));
664     if (value_sp)
665     {
666         std::string buffer;
667         if (value_sp->GetSummaryAsCString(buffer,options.ref()) && !buffer.empty())
668             stream.Printf("%s",buffer.c_str());
669     }
670     const char* cstr = stream.GetData();
671     if (log)
672     {
673         if (cstr)
674             log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
675                          static_cast<void*>(value_sp.get()), cstr);
676         else
677             log->Printf ("SBValue(%p)::GetSummary() => NULL",
678                          static_cast<void*>(value_sp.get()));
679     }
680     return cstr;
681 }
682 
683 const char *
684 SBValue::GetLocation ()
685 {
686     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
687     const char *cstr = NULL;
688     ValueLocker locker;
689     lldb::ValueObjectSP value_sp(GetSP(locker));
690     if (value_sp)
691     {
692         cstr = value_sp->GetLocationAsCString();
693     }
694     if (log)
695     {
696         if (cstr)
697             log->Printf ("SBValue(%p)::GetLocation() => \"%s\"",
698                          static_cast<void*>(value_sp.get()), cstr);
699         else
700             log->Printf ("SBValue(%p)::GetLocation() => NULL",
701                          static_cast<void*>(value_sp.get()));
702     }
703     return cstr;
704 }
705 
706 // Deprecated - use the one that takes an lldb::SBError
707 bool
708 SBValue::SetValueFromCString (const char *value_str)
709 {
710     lldb::SBError dummy;
711     return SetValueFromCString(value_str,dummy);
712 }
713 
714 bool
715 SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
716 {
717     bool success = false;
718     ValueLocker locker;
719     lldb::ValueObjectSP value_sp(GetSP(locker));
720     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
721     if (value_sp)
722     {
723         success = value_sp->SetValueFromCString (value_str,error.ref());
724     }
725     else
726         error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString());
727 
728     if (log)
729         log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i",
730                      static_cast<void*>(value_sp.get()), value_str, success);
731 
732     return success;
733 }
734 
735 lldb::SBTypeFormat
736 SBValue::GetTypeFormat ()
737 {
738     lldb::SBTypeFormat format;
739     ValueLocker locker;
740     lldb::ValueObjectSP value_sp(GetSP(locker));
741     if (value_sp)
742     {
743         if (value_sp->UpdateValueIfNeeded(true))
744         {
745             lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
746             if (format_sp)
747                 format.SetSP(format_sp);
748         }
749     }
750     return format;
751 }
752 
753 lldb::SBTypeSummary
754 SBValue::GetTypeSummary ()
755 {
756     lldb::SBTypeSummary summary;
757     ValueLocker locker;
758     lldb::ValueObjectSP value_sp(GetSP(locker));
759     if (value_sp)
760     {
761         if (value_sp->UpdateValueIfNeeded(true))
762         {
763             lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
764             if (summary_sp)
765                 summary.SetSP(summary_sp);
766         }
767     }
768     return summary;
769 }
770 
771 lldb::SBTypeFilter
772 SBValue::GetTypeFilter ()
773 {
774     lldb::SBTypeFilter filter;
775     ValueLocker locker;
776     lldb::ValueObjectSP value_sp(GetSP(locker));
777     if (value_sp)
778     {
779         if (value_sp->UpdateValueIfNeeded(true))
780         {
781             lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
782 
783             if (synthetic_sp && !synthetic_sp->IsScripted())
784             {
785                 TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
786                 filter.SetSP(filter_sp);
787             }
788         }
789     }
790     return filter;
791 }
792 
793 #ifndef LLDB_DISABLE_PYTHON
794 lldb::SBTypeSynthetic
795 SBValue::GetTypeSynthetic ()
796 {
797     lldb::SBTypeSynthetic synthetic;
798     ValueLocker locker;
799     lldb::ValueObjectSP value_sp(GetSP(locker));
800     if (value_sp)
801     {
802         if (value_sp->UpdateValueIfNeeded(true))
803         {
804             lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
805 
806             if (children_sp && children_sp->IsScripted())
807             {
808                 ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
809                 synthetic.SetSP(synth_sp);
810             }
811         }
812     }
813     return synthetic;
814 }
815 #endif
816 
817 lldb::SBValue
818 SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
819 {
820     lldb::SBValue sb_value;
821     ValueLocker locker;
822     lldb::ValueObjectSP value_sp(GetSP(locker));
823     lldb::ValueObjectSP new_value_sp;
824     if (value_sp)
825     {
826         TypeImplSP type_sp (type.GetSP());
827         if (type.IsValid())
828         {
829             sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetCompilerType(false), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name);
830         }
831     }
832     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
833     if (log)
834     {
835         if (new_value_sp)
836             log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"",
837                          static_cast<void*>(value_sp.get()),
838                          new_value_sp->GetName().AsCString());
839         else
840             log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL",
841                          static_cast<void*>(value_sp.get()));
842     }
843     return sb_value;
844 }
845 
846 lldb::SBValue
847 SBValue::Cast (SBType type)
848 {
849     lldb::SBValue sb_value;
850     ValueLocker locker;
851     lldb::ValueObjectSP value_sp(GetSP(locker));
852     TypeImplSP type_sp (type.GetSP());
853     if (value_sp && type_sp)
854         sb_value.SetSP(value_sp->Cast(type_sp->GetCompilerType(false)),GetPreferDynamicValue(),GetPreferSyntheticValue());
855     return sb_value;
856 }
857 
858 lldb::SBValue
859 SBValue::CreateValueFromExpression (const char *name, const char* expression)
860 {
861     SBExpressionOptions options;
862     options.ref().SetKeepInMemory(true);
863     return CreateValueFromExpression (name, expression, options);
864 }
865 
866 lldb::SBValue
867 SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options)
868 {
869     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
870     lldb::SBValue sb_value;
871     ValueLocker locker;
872     lldb::ValueObjectSP value_sp(GetSP(locker));
873     lldb::ValueObjectSP new_value_sp;
874     if (value_sp)
875     {
876         ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
877         new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx, options.ref());
878         if (new_value_sp)
879             new_value_sp->SetName(ConstString(name));
880     }
881     sb_value.SetSP(new_value_sp);
882     if (log)
883     {
884         if (new_value_sp)
885             log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
886                          static_cast<void*>(value_sp.get()), name, expression,
887                          static_cast<void*>(new_value_sp.get()));
888         else
889             log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
890                          static_cast<void*>(value_sp.get()), name, expression);
891     }
892     return sb_value;
893 }
894 
895 lldb::SBValue
896 SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
897 {
898     lldb::SBValue sb_value;
899     ValueLocker locker;
900     lldb::ValueObjectSP value_sp(GetSP(locker));
901     lldb::ValueObjectSP new_value_sp;
902     lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
903     if (value_sp && type_impl_sp)
904     {
905         CompilerType ast_type(type_impl_sp->GetCompilerType(true));
906         ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
907         new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, ast_type);
908     }
909     sb_value.SetSP(new_value_sp);
910     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
911     if (log)
912     {
913         if (new_value_sp)
914             log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"",
915                          static_cast<void*>(value_sp.get()),
916                          new_value_sp->GetName().AsCString());
917         else
918             log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL",
919                          static_cast<void*>(value_sp.get()));
920     }
921     return sb_value;
922 }
923 
924 lldb::SBValue
925 SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
926 {
927     lldb::SBValue sb_value;
928     lldb::ValueObjectSP new_value_sp;
929     ValueLocker locker;
930     lldb::ValueObjectSP value_sp(GetSP(locker));
931     if (value_sp)
932     {
933         ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
934         new_value_sp = ValueObject::CreateValueObjectFromData(name, **data, exe_ctx, type.GetSP()->GetCompilerType(true));
935         new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
936     }
937     sb_value.SetSP(new_value_sp);
938     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
939     if (log)
940     {
941         if (new_value_sp)
942             log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"",
943                          static_cast<void*>(value_sp.get()),
944                          new_value_sp->GetName().AsCString());
945         else
946             log->Printf ("SBValue(%p)::CreateValueFromData => NULL",
947                          static_cast<void*>(value_sp.get()));
948     }
949     return sb_value;
950 }
951 
952 SBValue
953 SBValue::GetChildAtIndex (uint32_t idx)
954 {
955     const bool can_create_synthetic = false;
956     lldb::DynamicValueType use_dynamic = eNoDynamicValues;
957     TargetSP target_sp;
958     if (m_opaque_sp)
959         target_sp = m_opaque_sp->GetTargetSP();
960 
961     if (target_sp)
962         use_dynamic = target_sp->GetPreferDynamicValue();
963 
964     return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
965 }
966 
967 SBValue
968 SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
969 {
970     lldb::ValueObjectSP child_sp;
971     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
972 
973     ValueLocker locker;
974     lldb::ValueObjectSP value_sp(GetSP(locker));
975     if (value_sp)
976     {
977         const bool can_create = true;
978         child_sp = value_sp->GetChildAtIndex (idx, can_create);
979         if (can_create_synthetic && !child_sp)
980         {
981             child_sp = value_sp->GetSyntheticArrayMember(idx, can_create);
982         }
983     }
984 
985     SBValue sb_value;
986     sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
987     if (log)
988         log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)",
989                      static_cast<void*>(value_sp.get()), idx,
990                      static_cast<void*>(value_sp.get()));
991 
992     return sb_value;
993 }
994 
995 uint32_t
996 SBValue::GetIndexOfChildWithName (const char *name)
997 {
998     uint32_t idx = UINT32_MAX;
999     ValueLocker locker;
1000     lldb::ValueObjectSP value_sp(GetSP(locker));
1001     if (value_sp)
1002     {
1003         idx = value_sp->GetIndexOfChildWithName (ConstString(name));
1004     }
1005     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1006     if (log)
1007     {
1008         if (idx == UINT32_MAX)
1009             log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND",
1010                          static_cast<void*>(value_sp.get()), name);
1011         else
1012             log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u",
1013                          static_cast<void*>(value_sp.get()), name, idx);
1014     }
1015     return idx;
1016 }
1017 
1018 SBValue
1019 SBValue::GetChildMemberWithName (const char *name)
1020 {
1021     lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
1022     TargetSP target_sp;
1023     if (m_opaque_sp)
1024         target_sp = m_opaque_sp->GetTargetSP();
1025 
1026     if (target_sp)
1027         use_dynamic_value = target_sp->GetPreferDynamicValue();
1028     return GetChildMemberWithName (name, use_dynamic_value);
1029 }
1030 
1031 SBValue
1032 SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
1033 {
1034     lldb::ValueObjectSP child_sp;
1035     const ConstString str_name (name);
1036 
1037     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1038 
1039     ValueLocker locker;
1040     lldb::ValueObjectSP value_sp(GetSP(locker));
1041     if (value_sp)
1042     {
1043         child_sp = value_sp->GetChildMemberWithName (str_name, true);
1044     }
1045 
1046     SBValue sb_value;
1047     sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
1048 
1049     if (log)
1050         log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)",
1051                      static_cast<void*>(value_sp.get()), name,
1052                      static_cast<void*>(value_sp.get()));
1053 
1054     return sb_value;
1055 }
1056 
1057 lldb::SBValue
1058 SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
1059 {
1060     SBValue value_sb;
1061     if (IsValid())
1062     {
1063         ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
1064         value_sb.SetSP(proxy_sp);
1065     }
1066     return value_sb;
1067 }
1068 
1069 lldb::SBValue
1070 SBValue::GetStaticValue ()
1071 {
1072     SBValue value_sb;
1073     if (IsValid())
1074     {
1075         ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic()));
1076         value_sb.SetSP(proxy_sp);
1077     }
1078     return value_sb;
1079 }
1080 
1081 lldb::SBValue
1082 SBValue::GetNonSyntheticValue ()
1083 {
1084     SBValue value_sb;
1085     if (IsValid())
1086     {
1087         ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
1088         value_sb.SetSP(proxy_sp);
1089     }
1090     return value_sb;
1091 }
1092 
1093 lldb::DynamicValueType
1094 SBValue::GetPreferDynamicValue ()
1095 {
1096     if (!IsValid())
1097         return eNoDynamicValues;
1098     return m_opaque_sp->GetUseDynamic();
1099 }
1100 
1101 void
1102 SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
1103 {
1104     if (IsValid())
1105         return m_opaque_sp->SetUseDynamic (use_dynamic);
1106 }
1107 
1108 bool
1109 SBValue::GetPreferSyntheticValue ()
1110 {
1111     if (!IsValid())
1112         return false;
1113     return m_opaque_sp->GetUseSynthetic();
1114 }
1115 
1116 void
1117 SBValue::SetPreferSyntheticValue (bool use_synthetic)
1118 {
1119     if (IsValid())
1120         return m_opaque_sp->SetUseSynthetic (use_synthetic);
1121 }
1122 
1123 bool
1124 SBValue::IsDynamic()
1125 {
1126     ValueLocker locker;
1127     lldb::ValueObjectSP value_sp(GetSP(locker));
1128     if (value_sp)
1129         return value_sp->IsDynamic();
1130     return false;
1131 }
1132 
1133 bool
1134 SBValue::IsSynthetic ()
1135 {
1136     ValueLocker locker;
1137     lldb::ValueObjectSP value_sp(GetSP(locker));
1138     if (value_sp)
1139         return value_sp->IsSynthetic();
1140     return false;
1141 }
1142 
1143 lldb::SBValue
1144 SBValue::GetValueForExpressionPath(const char* expr_path)
1145 {
1146     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1147     lldb::ValueObjectSP child_sp;
1148     ValueLocker locker;
1149     lldb::ValueObjectSP value_sp(GetSP(locker));
1150     if (value_sp)
1151     {
1152         // using default values for all the fancy options, just do it if you can
1153         child_sp = value_sp->GetValueForExpressionPath(expr_path);
1154     }
1155 
1156     SBValue sb_value;
1157     sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
1158 
1159     if (log)
1160         log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)",
1161                      static_cast<void*>(value_sp.get()), expr_path,
1162                      static_cast<void*>(value_sp.get()));
1163 
1164     return sb_value;
1165 }
1166 
1167 int64_t
1168 SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1169 {
1170     error.Clear();
1171     ValueLocker locker;
1172     lldb::ValueObjectSP value_sp(GetSP(locker));
1173     if (value_sp)
1174     {
1175         bool success = true;
1176         uint64_t ret_val = fail_value;
1177         ret_val = value_sp->GetValueAsSigned(fail_value, &success);
1178         if (!success)
1179             error.SetErrorString("could not resolve value");
1180         return ret_val;
1181     }
1182     else
1183         error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1184 
1185     return fail_value;
1186 }
1187 
1188 uint64_t
1189 SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1190 {
1191     error.Clear();
1192     ValueLocker locker;
1193     lldb::ValueObjectSP value_sp(GetSP(locker));
1194     if (value_sp)
1195     {
1196         bool success = true;
1197         uint64_t ret_val = fail_value;
1198         ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
1199         if (!success)
1200             error.SetErrorString("could not resolve value");
1201         return ret_val;
1202     }
1203     else
1204         error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1205 
1206     return fail_value;
1207 }
1208 
1209 int64_t
1210 SBValue::GetValueAsSigned(int64_t fail_value)
1211 {
1212     ValueLocker locker;
1213     lldb::ValueObjectSP value_sp(GetSP(locker));
1214     if (value_sp)
1215     {
1216         return value_sp->GetValueAsSigned(fail_value);
1217     }
1218     return fail_value;
1219 }
1220 
1221 uint64_t
1222 SBValue::GetValueAsUnsigned(uint64_t fail_value)
1223 {
1224     ValueLocker locker;
1225     lldb::ValueObjectSP value_sp(GetSP(locker));
1226     if (value_sp)
1227     {
1228         return value_sp->GetValueAsUnsigned(fail_value);
1229     }
1230     return fail_value;
1231 }
1232 
1233 bool
1234 SBValue::MightHaveChildren ()
1235 {
1236     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1237     bool has_children = false;
1238     ValueLocker locker;
1239     lldb::ValueObjectSP value_sp(GetSP(locker));
1240     if (value_sp)
1241         has_children = value_sp->MightHaveChildren();
1242 
1243     if (log)
1244         log->Printf ("SBValue(%p)::MightHaveChildren() => %i",
1245                      static_cast<void*>(value_sp.get()), has_children);
1246     return has_children;
1247 }
1248 
1249 bool
1250 SBValue::IsRuntimeSupportValue ()
1251 {
1252     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1253     bool is_support = false;
1254     ValueLocker locker;
1255     lldb::ValueObjectSP value_sp(GetSP(locker));
1256     if (value_sp)
1257         is_support = value_sp->IsRuntimeSupportValue();
1258 
1259     if (log)
1260         log->Printf ("SBValue(%p)::IsRuntimeSupportValue() => %i",
1261                      static_cast<void*>(value_sp.get()), is_support);
1262     return is_support;
1263 }
1264 
1265 uint32_t
1266 SBValue::GetNumChildren ()
1267 {
1268     return GetNumChildren (UINT32_MAX);
1269 }
1270 
1271 uint32_t
1272 SBValue::GetNumChildren (uint32_t max)
1273 {
1274     uint32_t num_children = 0;
1275 
1276     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1277     ValueLocker locker;
1278     lldb::ValueObjectSP value_sp(GetSP(locker));
1279     if (value_sp)
1280         num_children = value_sp->GetNumChildren(max);
1281 
1282     if (log)
1283         log->Printf ("SBValue(%p)::GetNumChildren (%u) => %u",
1284                      static_cast<void*>(value_sp.get()), max, num_children);
1285 
1286     return num_children;
1287 }
1288 
1289 SBValue
1290 SBValue::Dereference ()
1291 {
1292     SBValue sb_value;
1293     ValueLocker locker;
1294     lldb::ValueObjectSP value_sp(GetSP(locker));
1295     if (value_sp)
1296     {
1297         Error error;
1298         sb_value = value_sp->Dereference (error);
1299     }
1300     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1301     if (log)
1302         log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)",
1303                      static_cast<void*>(value_sp.get()),
1304                      static_cast<void*>(value_sp.get()));
1305 
1306     return sb_value;
1307 }
1308 
1309 // Deprecated - please use GetType().IsPointerType() instead.
1310 bool
1311 SBValue::TypeIsPointerType ()
1312 {
1313     return GetType().IsPointerType();
1314 }
1315 
1316 void *
1317 SBValue::GetOpaqueType()
1318 {
1319     ValueLocker locker;
1320     lldb::ValueObjectSP value_sp(GetSP(locker));
1321     if (value_sp)
1322         return value_sp->GetCompilerType().GetOpaqueQualType();
1323     return NULL;
1324 }
1325 
1326 lldb::SBTarget
1327 SBValue::GetTarget()
1328 {
1329     SBTarget sb_target;
1330     TargetSP target_sp;
1331     if (m_opaque_sp)
1332     {
1333         target_sp = m_opaque_sp->GetTargetSP();
1334         sb_target.SetSP (target_sp);
1335     }
1336     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1337     if (log)
1338     {
1339         if (target_sp.get() == NULL)
1340             log->Printf ("SBValue(%p)::GetTarget () => NULL",
1341                          static_cast<void*>(m_opaque_sp.get()));
1342         else
1343             log->Printf ("SBValue(%p)::GetTarget () => %p",
1344                          static_cast<void*>(m_opaque_sp.get()),
1345                          static_cast<void*>(target_sp.get()));
1346     }
1347     return sb_target;
1348 }
1349 
1350 lldb::SBProcess
1351 SBValue::GetProcess()
1352 {
1353     SBProcess sb_process;
1354     ProcessSP process_sp;
1355     if (m_opaque_sp)
1356     {
1357         process_sp = m_opaque_sp->GetProcessSP();
1358         sb_process.SetSP (process_sp);
1359     }
1360     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1361     if (log)
1362     {
1363         if (process_sp.get() == NULL)
1364             log->Printf ("SBValue(%p)::GetProcess () => NULL",
1365                          static_cast<void*>(m_opaque_sp.get()));
1366         else
1367             log->Printf ("SBValue(%p)::GetProcess () => %p",
1368                          static_cast<void*>(m_opaque_sp.get()),
1369                          static_cast<void*>(process_sp.get()));
1370     }
1371     return sb_process;
1372 }
1373 
1374 lldb::SBThread
1375 SBValue::GetThread()
1376 {
1377     SBThread sb_thread;
1378     ThreadSP thread_sp;
1379     if (m_opaque_sp)
1380     {
1381         thread_sp = m_opaque_sp->GetThreadSP();
1382         sb_thread.SetThread(thread_sp);
1383     }
1384     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1385     if (log)
1386     {
1387         if (thread_sp.get() == NULL)
1388             log->Printf ("SBValue(%p)::GetThread () => NULL",
1389                          static_cast<void*>(m_opaque_sp.get()));
1390         else
1391             log->Printf ("SBValue(%p)::GetThread () => %p",
1392                          static_cast<void*>(m_opaque_sp.get()),
1393                          static_cast<void*>(thread_sp.get()));
1394     }
1395     return sb_thread;
1396 }
1397 
1398 lldb::SBFrame
1399 SBValue::GetFrame()
1400 {
1401     SBFrame sb_frame;
1402     StackFrameSP frame_sp;
1403     if (m_opaque_sp)
1404     {
1405         frame_sp = m_opaque_sp->GetFrameSP();
1406         sb_frame.SetFrameSP (frame_sp);
1407     }
1408     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1409     if (log)
1410     {
1411         if (frame_sp.get() == NULL)
1412             log->Printf ("SBValue(%p)::GetFrame () => NULL",
1413                          static_cast<void*>(m_opaque_sp.get()));
1414         else
1415             log->Printf ("SBValue(%p)::GetFrame () => %p",
1416                          static_cast<void*>(m_opaque_sp.get()),
1417                          static_cast<void*>(frame_sp.get()));
1418     }
1419     return sb_frame;
1420 }
1421 
1422 
1423 lldb::ValueObjectSP
1424 SBValue::GetSP (ValueLocker &locker) const
1425 {
1426     if (!m_opaque_sp || !m_opaque_sp->IsValid())
1427     {
1428         locker.GetError().SetErrorString("No value");
1429         return ValueObjectSP();
1430     }
1431     return locker.GetLockedSP(*m_opaque_sp.get());
1432 }
1433 
1434 lldb::ValueObjectSP
1435 SBValue::GetSP () const
1436 {
1437     ValueLocker locker;
1438     return GetSP(locker);
1439 }
1440 
1441 void
1442 SBValue::SetSP (ValueImplSP impl_sp)
1443 {
1444     m_opaque_sp = impl_sp;
1445 }
1446 
1447 void
1448 SBValue::SetSP (const lldb::ValueObjectSP &sp)
1449 {
1450     if (sp)
1451     {
1452         lldb::TargetSP target_sp(sp->GetTargetSP());
1453         if (target_sp)
1454         {
1455             lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1456             bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1457             m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1458         }
1459         else
1460             m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
1461     }
1462     else
1463         m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
1464 }
1465 
1466 void
1467 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
1468 {
1469     if (sp)
1470     {
1471         lldb::TargetSP target_sp(sp->GetTargetSP());
1472         if (target_sp)
1473         {
1474             bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1475             SetSP (sp, use_dynamic, use_synthetic);
1476         }
1477         else
1478             SetSP (sp, use_dynamic, true);
1479     }
1480     else
1481         SetSP (sp, use_dynamic, false);
1482 }
1483 
1484 void
1485 SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
1486 {
1487     if (sp)
1488     {
1489         lldb::TargetSP target_sp(sp->GetTargetSP());
1490         if (target_sp)
1491         {
1492             lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1493             SetSP (sp, use_dynamic, use_synthetic);
1494         }
1495         else
1496             SetSP (sp, eNoDynamicValues, use_synthetic);
1497     }
1498     else
1499         SetSP (sp, eNoDynamicValues, use_synthetic);
1500 }
1501 
1502 void
1503 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
1504 {
1505     m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
1506 }
1507 
1508 void
1509 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
1510 {
1511     m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
1512 }
1513 
1514 bool
1515 SBValue::GetExpressionPath (SBStream &description)
1516 {
1517     ValueLocker locker;
1518     lldb::ValueObjectSP value_sp(GetSP(locker));
1519     if (value_sp)
1520     {
1521         value_sp->GetExpressionPath (description.ref(), false);
1522         return true;
1523     }
1524     return false;
1525 }
1526 
1527 bool
1528 SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1529 {
1530     ValueLocker locker;
1531     lldb::ValueObjectSP value_sp(GetSP(locker));
1532     if (value_sp)
1533     {
1534         value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
1535         return true;
1536     }
1537     return false;
1538 }
1539 
1540 bool
1541 SBValue::GetDescription (SBStream &description)
1542 {
1543     Stream &strm = description.ref();
1544 
1545     ValueLocker locker;
1546     lldb::ValueObjectSP value_sp(GetSP(locker));
1547     if (value_sp)
1548         value_sp->Dump(strm);
1549     else
1550         strm.PutCString ("No value");
1551 
1552     return true;
1553 }
1554 
1555 lldb::Format
1556 SBValue::GetFormat ()
1557 {
1558     ValueLocker locker;
1559     lldb::ValueObjectSP value_sp(GetSP(locker));
1560     if (value_sp)
1561         return value_sp->GetFormat();
1562     return eFormatDefault;
1563 }
1564 
1565 void
1566 SBValue::SetFormat (lldb::Format format)
1567 {
1568     ValueLocker locker;
1569     lldb::ValueObjectSP value_sp(GetSP(locker));
1570     if (value_sp)
1571         value_sp->SetFormat(format);
1572 }
1573 
1574 lldb::SBValue
1575 SBValue::AddressOf()
1576 {
1577     SBValue sb_value;
1578     ValueLocker locker;
1579     lldb::ValueObjectSP value_sp(GetSP(locker));
1580     if (value_sp)
1581     {
1582         Error error;
1583         sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
1584     }
1585     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1586     if (log)
1587         log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)",
1588                      static_cast<void*>(value_sp.get()),
1589                      static_cast<void*>(value_sp.get()));
1590 
1591     return sb_value;
1592 }
1593 
1594 lldb::addr_t
1595 SBValue::GetLoadAddress()
1596 {
1597     lldb::addr_t value = LLDB_INVALID_ADDRESS;
1598     ValueLocker locker;
1599     lldb::ValueObjectSP value_sp(GetSP(locker));
1600     if (value_sp)
1601     {
1602         TargetSP target_sp (value_sp->GetTargetSP());
1603         if (target_sp)
1604         {
1605             const bool scalar_is_load_address = true;
1606             AddressType addr_type;
1607             value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1608             if (addr_type == eAddressTypeFile)
1609             {
1610                 ModuleSP module_sp (value_sp->GetModule());
1611                 if (!module_sp)
1612                     value = LLDB_INVALID_ADDRESS;
1613                 else
1614                 {
1615                     Address addr;
1616                     module_sp->ResolveFileAddress(value, addr);
1617                     value = addr.GetLoadAddress(target_sp.get());
1618                 }
1619             }
1620             else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1621                 value = LLDB_INVALID_ADDRESS;
1622         }
1623     }
1624     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1625     if (log)
1626         log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")",
1627                      static_cast<void*>(value_sp.get()), value);
1628 
1629     return value;
1630 }
1631 
1632 lldb::SBAddress
1633 SBValue::GetAddress()
1634 {
1635     Address addr;
1636     ValueLocker locker;
1637     lldb::ValueObjectSP value_sp(GetSP(locker));
1638     if (value_sp)
1639     {
1640         TargetSP target_sp (value_sp->GetTargetSP());
1641         if (target_sp)
1642         {
1643             lldb::addr_t value = LLDB_INVALID_ADDRESS;
1644             const bool scalar_is_load_address = true;
1645             AddressType addr_type;
1646             value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1647             if (addr_type == eAddressTypeFile)
1648             {
1649                 ModuleSP module_sp (value_sp->GetModule());
1650                 if (module_sp)
1651                     module_sp->ResolveFileAddress(value, addr);
1652             }
1653             else if (addr_type == eAddressTypeLoad)
1654             {
1655                 // no need to check the return value on this.. if it can actually do the resolve
1656                 // addr will be in the form (section,offset), otherwise it will simply be returned
1657                 // as (NULL, value)
1658                 addr.SetLoadAddress(value, target_sp.get());
1659             }
1660         }
1661     }
1662     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1663     if (log)
1664         log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")",
1665                      static_cast<void*>(value_sp.get()),
1666                      (addr.GetSection()
1667                         ? addr.GetSection()->GetName().GetCString()
1668                         : "NULL"),
1669                      addr.GetOffset());
1670     return SBAddress(new Address(addr));
1671 }
1672 
1673 lldb::SBData
1674 SBValue::GetPointeeData (uint32_t item_idx,
1675                          uint32_t item_count)
1676 {
1677     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1678     lldb::SBData sb_data;
1679     ValueLocker locker;
1680     lldb::ValueObjectSP value_sp(GetSP(locker));
1681     if (value_sp)
1682     {
1683         TargetSP target_sp (value_sp->GetTargetSP());
1684         if (target_sp)
1685         {
1686             DataExtractorSP data_sp(new DataExtractor());
1687             value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1688             if (data_sp->GetByteSize() > 0)
1689                 *sb_data = data_sp;
1690         }
1691     }
1692     if (log)
1693         log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
1694                      static_cast<void*>(value_sp.get()), item_idx, item_count,
1695                      static_cast<void*>(sb_data.get()));
1696 
1697     return sb_data;
1698 }
1699 
1700 lldb::SBData
1701 SBValue::GetData ()
1702 {
1703     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1704     lldb::SBData sb_data;
1705     ValueLocker locker;
1706     lldb::ValueObjectSP value_sp(GetSP(locker));
1707     if (value_sp)
1708     {
1709         DataExtractorSP data_sp(new DataExtractor());
1710         Error error;
1711         value_sp->GetData(*data_sp, error);
1712         if (error.Success())
1713             *sb_data = data_sp;
1714     }
1715     if (log)
1716         log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
1717                      static_cast<void*>(value_sp.get()),
1718                      static_cast<void*>(sb_data.get()));
1719 
1720     return sb_data;
1721 }
1722 
1723 bool
1724 SBValue::SetData (lldb::SBData &data, SBError &error)
1725 {
1726     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1727     ValueLocker locker;
1728     lldb::ValueObjectSP value_sp(GetSP(locker));
1729     bool ret = true;
1730 
1731     if (value_sp)
1732     {
1733         DataExtractor *data_extractor = data.get();
1734 
1735         if (!data_extractor)
1736         {
1737             if (log)
1738                 log->Printf ("SBValue(%p)::SetData() => error: no data to set",
1739                              static_cast<void*>(value_sp.get()));
1740 
1741             error.SetErrorString("No data to set");
1742             ret = false;
1743         }
1744         else
1745         {
1746             Error set_error;
1747 
1748             value_sp->SetData(*data_extractor, set_error);
1749 
1750             if (!set_error.Success())
1751             {
1752                 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
1753                 ret = false;
1754             }
1755         }
1756     }
1757     else
1758     {
1759         error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
1760         ret = false;
1761     }
1762 
1763     if (log)
1764         log->Printf ("SBValue(%p)::SetData (%p) => %s",
1765                      static_cast<void*>(value_sp.get()),
1766                      static_cast<void*>(data.get()), ret ? "true" : "false");
1767     return ret;
1768 }
1769 
1770 lldb::SBDeclaration
1771 SBValue::GetDeclaration ()
1772 {
1773     ValueLocker locker;
1774     lldb::ValueObjectSP value_sp(GetSP(locker));
1775     SBDeclaration decl_sb;
1776     if (value_sp)
1777     {
1778         Declaration decl;
1779         if (value_sp->GetDeclaration(decl))
1780             decl_sb.SetDeclaration(decl);
1781     }
1782     return decl_sb;
1783 }
1784 
1785 lldb::SBWatchpoint
1786 SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
1787 {
1788     SBWatchpoint sb_watchpoint;
1789 
1790     // If the SBValue is not valid, there's no point in even trying to watch it.
1791     ValueLocker locker;
1792     lldb::ValueObjectSP value_sp(GetSP(locker));
1793     TargetSP target_sp (GetTarget().GetSP());
1794     if (value_sp && target_sp)
1795     {
1796         // Read and Write cannot both be false.
1797         if (!read && !write)
1798             return sb_watchpoint;
1799 
1800         // If the value is not in scope, don't try and watch and invalid value
1801         if (!IsInScope())
1802             return sb_watchpoint;
1803 
1804         addr_t addr = GetLoadAddress();
1805         if (addr == LLDB_INVALID_ADDRESS)
1806             return sb_watchpoint;
1807         size_t byte_size = GetByteSize();
1808         if (byte_size == 0)
1809             return sb_watchpoint;
1810 
1811         uint32_t watch_type = 0;
1812         if (read)
1813             watch_type |= LLDB_WATCH_TYPE_READ;
1814         if (write)
1815             watch_type |= LLDB_WATCH_TYPE_WRITE;
1816 
1817         Error rc;
1818         CompilerType type (value_sp->GetCompilerType());
1819         WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
1820         error.SetError(rc);
1821 
1822         if (watchpoint_sp)
1823         {
1824             sb_watchpoint.SetSP (watchpoint_sp);
1825             Declaration decl;
1826             if (value_sp->GetDeclaration (decl))
1827             {
1828                 if (decl.GetFile())
1829                 {
1830                     StreamString ss;
1831                     // True to show fullpath for declaration file.
1832                     decl.DumpStopContext(&ss, true);
1833                     watchpoint_sp->SetDeclInfo(ss.GetString());
1834                 }
1835             }
1836         }
1837     }
1838     else if (target_sp)
1839     {
1840         Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1841         if (log)
1842             log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s",
1843                          static_cast<void*>(value_sp.get()),
1844                          locker.GetError().AsCString());
1845 
1846         error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
1847     }
1848     else
1849     {
1850         Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1851         if (log)
1852             log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target",
1853                          static_cast<void*>(value_sp.get()));
1854         error.SetErrorString("could not set watchpoint, a target is required");
1855     }
1856 
1857     return sb_watchpoint;
1858 }
1859 
1860 // FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1861 // Backward compatibility fix in the interim.
1862 lldb::SBWatchpoint
1863 SBValue::Watch (bool resolve_location, bool read, bool write)
1864 {
1865     SBError error;
1866     return Watch(resolve_location, read, write, error);
1867 }
1868 
1869 lldb::SBWatchpoint
1870 SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
1871 {
1872     SBWatchpoint sb_watchpoint;
1873     if (IsInScope() && GetType().IsPointerType())
1874         sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
1875     return sb_watchpoint;
1876 }
1877 
1878 lldb::SBValue
1879 SBValue::Persist ()
1880 {
1881     ValueLocker locker;
1882     lldb::ValueObjectSP value_sp(GetSP(locker));
1883     SBValue persisted_sb;
1884     if (value_sp)
1885     {
1886         persisted_sb.SetSP(value_sp->Persist());
1887     }
1888     return persisted_sb;
1889 }
1890