]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/API/SBValue.cpp
Merge ^/head r306906 through r307382.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / API / SBValue.cpp
1 //===-- SBValue.cpp ---------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/API/SBValue.h"
11
12 #include "lldb/API/SBDeclaration.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/API/SBTypeFilter.h"
15 #include "lldb/API/SBTypeFormat.h"
16 #include "lldb/API/SBTypeSummary.h"
17 #include "lldb/API/SBTypeSynthetic.h"
18
19 #include "lldb/Breakpoint/Watchpoint.h"
20 #include "lldb/Core/DataExtractor.h"
21 #include "lldb/Core/Log.h"
22 #include "lldb/Core/Module.h"
23 #include "lldb/Core/Scalar.h"
24 #include "lldb/Core/Section.h"
25 #include "lldb/Core/Stream.h"
26 #include "lldb/Core/StreamFile.h"
27 #include "lldb/Core/Value.h"
28 #include "lldb/Core/ValueObject.h"
29 #include "lldb/Core/ValueObjectConstResult.h"
30 #include "lldb/DataFormatters/DataVisualization.h"
31 #include "lldb/Symbol/Block.h"
32 #include "lldb/Symbol/Declaration.h"
33 #include "lldb/Symbol/ObjectFile.h"
34 #include "lldb/Symbol/Type.h"
35 #include "lldb/Symbol/Variable.h"
36 #include "lldb/Symbol/VariableList.h"
37 #include "lldb/Target/ExecutionContext.h"
38 #include "lldb/Target/Process.h"
39 #include "lldb/Target/StackFrame.h"
40 #include "lldb/Target/Target.h"
41 #include "lldb/Target/Thread.h"
42
43 #include "lldb/API/SBDebugger.h"
44 #include "lldb/API/SBExpressionOptions.h"
45 #include "lldb/API/SBFrame.h"
46 #include "lldb/API/SBProcess.h"
47 #include "lldb/API/SBTarget.h"
48 #include "lldb/API/SBThread.h"
49
50 using namespace lldb;
51 using namespace lldb_private;
52
53 class ValueImpl
54 {
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             case eValueTypeVariableThreadLocal:
532                 log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableThreadLocal",
533                             static_cast<void *>(value_sp.get()));
534                 break;
535         }
536     }
537     return result;
538 }
539
540 const char *
541 SBValue::GetObjectDescription ()
542 {
543     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
544     const char *cstr = NULL;
545     ValueLocker locker;
546     lldb::ValueObjectSP value_sp(GetSP(locker));
547     if (value_sp)
548     {
549         cstr = value_sp->GetObjectDescription ();
550     }
551     if (log)
552     {
553         if (cstr)
554             log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"",
555                          static_cast<void*>(value_sp.get()), cstr);
556         else
557             log->Printf ("SBValue(%p)::GetObjectDescription() => NULL",
558                          static_cast<void*>(value_sp.get()));
559     }
560     return cstr;
561 }
562
563 const char *
564 SBValue::GetTypeValidatorResult ()
565 {
566     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
567     const char *cstr = NULL;
568     ValueLocker locker;
569     lldb::ValueObjectSP value_sp(GetSP(locker));
570     if (value_sp)
571     {
572         const auto& validation(value_sp->GetValidationStatus());
573         if (TypeValidatorResult::Failure == validation.first)
574         {
575             if (validation.second.empty())
576                 cstr = "unknown error";
577             else
578                 cstr = validation.second.c_str();
579         }
580     }
581     if (log)
582     {
583         if (cstr)
584             log->Printf ("SBValue(%p)::GetTypeValidatorResult() => \"%s\"",
585                          static_cast<void*>(value_sp.get()), cstr);
586         else
587             log->Printf ("SBValue(%p)::GetTypeValidatorResult() => NULL",
588                          static_cast<void*>(value_sp.get()));
589     }
590     return cstr;
591 }
592
593 SBType
594 SBValue::GetType()
595 {
596     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
597     SBType sb_type;
598     ValueLocker locker;
599     lldb::ValueObjectSP value_sp(GetSP(locker));
600     TypeImplSP type_sp;
601     if (value_sp)
602     {
603         type_sp.reset (new TypeImpl(value_sp->GetTypeImpl()));
604         sb_type.SetSP(type_sp);
605     }
606     if (log)
607     {
608         if (type_sp)
609             log->Printf ("SBValue(%p)::GetType => SBType(%p)",
610                          static_cast<void*>(value_sp.get()),
611                          static_cast<void*>(type_sp.get()));
612         else
613             log->Printf ("SBValue(%p)::GetType => NULL",
614                          static_cast<void*>(value_sp.get()));
615     }
616     return sb_type;
617 }
618
619 bool
620 SBValue::GetValueDidChange ()
621 {
622     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
623     bool result = false;
624     ValueLocker locker;
625     lldb::ValueObjectSP value_sp(GetSP(locker));
626     if (value_sp)
627     {
628         if (value_sp->UpdateValueIfNeeded(false))
629             result = value_sp->GetValueDidChange ();
630     }
631     if (log)
632         log->Printf ("SBValue(%p)::GetValueDidChange() => %i",
633                      static_cast<void*>(value_sp.get()), result);
634
635     return result;
636 }
637
638 const char *
639 SBValue::GetSummary ()
640 {
641     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
642     const char *cstr = NULL;
643     ValueLocker locker;
644     lldb::ValueObjectSP value_sp(GetSP(locker));
645     if (value_sp)
646     {
647         cstr = value_sp->GetSummaryAsCString();
648     }
649     if (log)
650     {
651         if (cstr)
652             log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
653                          static_cast<void*>(value_sp.get()), cstr);
654         else
655             log->Printf ("SBValue(%p)::GetSummary() => NULL",
656                          static_cast<void*>(value_sp.get()));
657     }
658     return cstr;
659 }
660
661 const char *
662 SBValue::GetSummary (lldb::SBStream& stream,
663                      lldb::SBTypeSummaryOptions& options)
664 {
665     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
666     ValueLocker locker;
667     lldb::ValueObjectSP value_sp(GetSP(locker));
668     if (value_sp)
669     {
670         std::string buffer;
671         if (value_sp->GetSummaryAsCString(buffer,options.ref()) && !buffer.empty())
672             stream.Printf("%s",buffer.c_str());
673     }
674     const char* cstr = stream.GetData();
675     if (log)
676     {
677         if (cstr)
678             log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
679                          static_cast<void*>(value_sp.get()), cstr);
680         else
681             log->Printf ("SBValue(%p)::GetSummary() => NULL",
682                          static_cast<void*>(value_sp.get()));
683     }
684     return cstr;
685 }
686
687 const char *
688 SBValue::GetLocation ()
689 {
690     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
691     const char *cstr = NULL;
692     ValueLocker locker;
693     lldb::ValueObjectSP value_sp(GetSP(locker));
694     if (value_sp)
695     {
696         cstr = value_sp->GetLocationAsCString();
697     }
698     if (log)
699     {
700         if (cstr)
701             log->Printf ("SBValue(%p)::GetLocation() => \"%s\"",
702                          static_cast<void*>(value_sp.get()), cstr);
703         else
704             log->Printf ("SBValue(%p)::GetLocation() => NULL",
705                          static_cast<void*>(value_sp.get()));
706     }
707     return cstr;
708 }
709
710 // Deprecated - use the one that takes an lldb::SBError
711 bool
712 SBValue::SetValueFromCString (const char *value_str)
713 {
714     lldb::SBError dummy;
715     return SetValueFromCString(value_str,dummy);
716 }
717
718 bool
719 SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
720 {
721     bool success = false;
722     ValueLocker locker;
723     lldb::ValueObjectSP value_sp(GetSP(locker));
724     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
725     if (value_sp)
726     {
727         success = value_sp->SetValueFromCString (value_str,error.ref());
728     }
729     else
730         error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString());
731
732     if (log)
733         log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i",
734                      static_cast<void*>(value_sp.get()), value_str, success);
735
736     return success;
737 }
738
739 lldb::SBTypeFormat
740 SBValue::GetTypeFormat ()
741 {
742     lldb::SBTypeFormat format;
743     ValueLocker locker;
744     lldb::ValueObjectSP value_sp(GetSP(locker));
745     if (value_sp)
746     {
747         if (value_sp->UpdateValueIfNeeded(true))
748         {
749             lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
750             if (format_sp)
751                 format.SetSP(format_sp);
752         }
753     }
754     return format;
755 }
756
757 lldb::SBTypeSummary
758 SBValue::GetTypeSummary ()
759 {
760     lldb::SBTypeSummary summary;
761     ValueLocker locker;
762     lldb::ValueObjectSP value_sp(GetSP(locker));
763     if (value_sp)
764     {
765         if (value_sp->UpdateValueIfNeeded(true))
766         {
767             lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
768             if (summary_sp)
769                 summary.SetSP(summary_sp);
770         }
771     }
772     return summary;
773 }
774
775 lldb::SBTypeFilter
776 SBValue::GetTypeFilter ()
777 {
778     lldb::SBTypeFilter filter;
779     ValueLocker locker;
780     lldb::ValueObjectSP value_sp(GetSP(locker));
781     if (value_sp)
782     {
783         if (value_sp->UpdateValueIfNeeded(true))
784         {
785             lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
786             
787             if (synthetic_sp && !synthetic_sp->IsScripted())
788             {
789                 TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
790                 filter.SetSP(filter_sp);
791             }
792         }
793     }
794     return filter;
795 }
796
797 #ifndef LLDB_DISABLE_PYTHON
798 lldb::SBTypeSynthetic
799 SBValue::GetTypeSynthetic ()
800 {
801     lldb::SBTypeSynthetic synthetic;
802     ValueLocker locker;
803     lldb::ValueObjectSP value_sp(GetSP(locker));
804     if (value_sp)
805     {
806         if (value_sp->UpdateValueIfNeeded(true))
807         {
808             lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
809             
810             if (children_sp && children_sp->IsScripted())
811             {
812                 ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
813                 synthetic.SetSP(synth_sp);
814             }
815         }
816     }
817     return synthetic;
818 }
819 #endif
820
821 lldb::SBValue
822 SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
823 {
824     lldb::SBValue sb_value;
825     ValueLocker locker;
826     lldb::ValueObjectSP value_sp(GetSP(locker));
827     lldb::ValueObjectSP new_value_sp;
828     if (value_sp)
829     {
830         TypeImplSP type_sp (type.GetSP());
831         if (type.IsValid())
832         {
833             sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetCompilerType(false), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name);
834         }
835     }
836     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
837     if (log)
838     {
839         if (new_value_sp)
840             log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"",
841                          static_cast<void*>(value_sp.get()),
842                          new_value_sp->GetName().AsCString());
843         else
844             log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL",
845                          static_cast<void*>(value_sp.get()));
846     }
847     return sb_value;
848 }
849
850 lldb::SBValue
851 SBValue::Cast (SBType type)
852 {
853     lldb::SBValue sb_value;
854     ValueLocker locker;
855     lldb::ValueObjectSP value_sp(GetSP(locker));
856     TypeImplSP type_sp (type.GetSP());
857     if (value_sp && type_sp)
858         sb_value.SetSP(value_sp->Cast(type_sp->GetCompilerType(false)),GetPreferDynamicValue(),GetPreferSyntheticValue());
859     return sb_value;
860 }
861
862 lldb::SBValue
863 SBValue::CreateValueFromExpression (const char *name, const char* expression)
864 {
865     SBExpressionOptions options;
866     options.ref().SetKeepInMemory(true);
867     return CreateValueFromExpression (name, expression, options);
868 }
869
870 lldb::SBValue
871 SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options)
872 {
873     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
874     lldb::SBValue sb_value;
875     ValueLocker locker;
876     lldb::ValueObjectSP value_sp(GetSP(locker));
877     lldb::ValueObjectSP new_value_sp;
878     if (value_sp)
879     {
880         ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
881         new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx, options.ref());
882         if (new_value_sp)
883             new_value_sp->SetName(ConstString(name));
884     }
885     sb_value.SetSP(new_value_sp);
886     if (log)
887     {
888         if (new_value_sp)
889             log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
890                          static_cast<void*>(value_sp.get()), name, expression,
891                          static_cast<void*>(new_value_sp.get()));
892         else
893             log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
894                          static_cast<void*>(value_sp.get()), name, expression);
895     }
896     return sb_value;
897 }
898
899 lldb::SBValue
900 SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
901 {
902     lldb::SBValue sb_value;
903     ValueLocker locker;
904     lldb::ValueObjectSP value_sp(GetSP(locker));
905     lldb::ValueObjectSP new_value_sp;
906     lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
907     if (value_sp && type_impl_sp)
908     {
909         CompilerType ast_type(type_impl_sp->GetCompilerType(true));
910         ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
911         new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, ast_type);
912     }
913     sb_value.SetSP(new_value_sp);
914     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
915     if (log)
916     {
917         if (new_value_sp)
918             log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"",
919                          static_cast<void*>(value_sp.get()),
920                          new_value_sp->GetName().AsCString());
921         else
922             log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL",
923                          static_cast<void*>(value_sp.get()));
924     }
925     return sb_value;
926 }
927
928 lldb::SBValue
929 SBValue::CreateValueFromData (const char* name, SBData data, SBType sb_type)
930 {
931     lldb::SBValue sb_value;
932     lldb::ValueObjectSP new_value_sp;
933     ValueLocker locker;
934     lldb::ValueObjectSP value_sp(GetSP(locker));
935     lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
936     if (value_sp && type_impl_sp)
937     {
938         ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
939         new_value_sp = ValueObject::CreateValueObjectFromData(name, **data, exe_ctx, type_impl_sp->GetCompilerType(true));
940         new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
941     }
942     sb_value.SetSP(new_value_sp);
943     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
944     if (log)
945     {
946         if (new_value_sp)
947             log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"",
948                          static_cast<void*>(value_sp.get()),
949                          new_value_sp->GetName().AsCString());
950         else
951             log->Printf ("SBValue(%p)::CreateValueFromData => NULL",
952                          static_cast<void*>(value_sp.get()));
953     }
954     return sb_value;
955 }
956
957 SBValue
958 SBValue::GetChildAtIndex (uint32_t idx)
959 {
960     const bool can_create_synthetic = false;
961     lldb::DynamicValueType use_dynamic = eNoDynamicValues;
962     TargetSP target_sp;
963     if (m_opaque_sp)
964         target_sp = m_opaque_sp->GetTargetSP();
965     
966     if (target_sp)
967         use_dynamic = target_sp->GetPreferDynamicValue();
968     
969     return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
970 }
971
972 SBValue
973 SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
974 {
975     lldb::ValueObjectSP child_sp;
976     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
977
978     ValueLocker locker;
979     lldb::ValueObjectSP value_sp(GetSP(locker));
980     if (value_sp)
981     {
982         const bool can_create = true;
983         child_sp = value_sp->GetChildAtIndex (idx, can_create);
984         if (can_create_synthetic && !child_sp)
985         {
986             child_sp = value_sp->GetSyntheticArrayMember(idx, can_create);
987         }
988     }
989
990     SBValue sb_value;
991     sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
992     if (log)
993         log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)",
994                      static_cast<void*>(value_sp.get()), idx,
995                      static_cast<void*>(value_sp.get()));
996
997     return sb_value;
998 }
999
1000 uint32_t
1001 SBValue::GetIndexOfChildWithName (const char *name)
1002 {
1003     uint32_t idx = UINT32_MAX;
1004     ValueLocker locker;
1005     lldb::ValueObjectSP value_sp(GetSP(locker));
1006     if (value_sp)
1007     {
1008         idx = value_sp->GetIndexOfChildWithName (ConstString(name));
1009     }
1010     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1011     if (log)
1012     {
1013         if (idx == UINT32_MAX)
1014             log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND",
1015                          static_cast<void*>(value_sp.get()), name);
1016         else
1017             log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u",
1018                          static_cast<void*>(value_sp.get()), name, idx);
1019     }
1020     return idx;
1021 }
1022
1023 SBValue
1024 SBValue::GetChildMemberWithName (const char *name)
1025 {
1026     lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
1027     TargetSP target_sp;
1028     if (m_opaque_sp)
1029         target_sp = m_opaque_sp->GetTargetSP();
1030
1031     if (target_sp)
1032         use_dynamic_value = target_sp->GetPreferDynamicValue();
1033     return GetChildMemberWithName (name, use_dynamic_value);
1034 }
1035
1036 SBValue
1037 SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
1038 {
1039     lldb::ValueObjectSP child_sp;
1040     const ConstString str_name (name);
1041
1042     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1043
1044     ValueLocker locker;
1045     lldb::ValueObjectSP value_sp(GetSP(locker));
1046     if (value_sp)
1047     {
1048         child_sp = value_sp->GetChildMemberWithName (str_name, true);
1049     }
1050
1051     SBValue sb_value;
1052     sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
1053
1054     if (log)
1055         log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)",
1056                      static_cast<void*>(value_sp.get()), name,
1057                      static_cast<void*>(value_sp.get()));
1058
1059     return sb_value;
1060 }
1061
1062 lldb::SBValue
1063 SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
1064 {
1065     SBValue value_sb;
1066     if (IsValid())
1067     {
1068         ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
1069         value_sb.SetSP(proxy_sp);
1070     }
1071     return value_sb;
1072 }
1073
1074 lldb::SBValue
1075 SBValue::GetStaticValue ()
1076 {
1077     SBValue value_sb;
1078     if (IsValid())
1079     {
1080         ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic()));
1081         value_sb.SetSP(proxy_sp);
1082     }
1083     return value_sb;
1084 }
1085
1086 lldb::SBValue
1087 SBValue::GetNonSyntheticValue ()
1088 {
1089     SBValue value_sb;
1090     if (IsValid())
1091     {
1092         ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
1093         value_sb.SetSP(proxy_sp);
1094     }
1095     return value_sb;
1096 }
1097
1098 lldb::DynamicValueType
1099 SBValue::GetPreferDynamicValue ()
1100 {
1101     if (!IsValid())
1102         return eNoDynamicValues;
1103     return m_opaque_sp->GetUseDynamic();
1104 }
1105
1106 void
1107 SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
1108 {
1109     if (IsValid())
1110         return m_opaque_sp->SetUseDynamic (use_dynamic);
1111 }
1112
1113 bool
1114 SBValue::GetPreferSyntheticValue ()
1115 {
1116     if (!IsValid())
1117         return false;
1118     return m_opaque_sp->GetUseSynthetic();
1119 }
1120
1121 void
1122 SBValue::SetPreferSyntheticValue (bool use_synthetic)
1123 {
1124     if (IsValid())
1125         return m_opaque_sp->SetUseSynthetic (use_synthetic);
1126 }
1127
1128 bool
1129 SBValue::IsDynamic()
1130 {
1131     ValueLocker locker;
1132     lldb::ValueObjectSP value_sp(GetSP(locker));
1133     if (value_sp)
1134         return value_sp->IsDynamic();
1135     return false;
1136 }
1137
1138 bool
1139 SBValue::IsSynthetic ()
1140 {
1141     ValueLocker locker;
1142     lldb::ValueObjectSP value_sp(GetSP(locker));
1143     if (value_sp)
1144         return value_sp->IsSynthetic();
1145     return false;
1146 }
1147
1148 bool
1149 SBValue::IsSyntheticChildrenGenerated ()
1150 {
1151     ValueLocker locker;
1152     lldb::ValueObjectSP value_sp(GetSP(locker));
1153     if (value_sp)
1154         return value_sp->IsSyntheticChildrenGenerated();
1155     return false;
1156 }
1157
1158 void
1159 SBValue::SetSyntheticChildrenGenerated (bool is)
1160 {
1161     ValueLocker locker;
1162     lldb::ValueObjectSP value_sp(GetSP(locker));
1163     if (value_sp)
1164         return value_sp->SetSyntheticChildrenGenerated(is);
1165 }
1166
1167 lldb::SBValue
1168 SBValue::GetValueForExpressionPath(const char* expr_path)
1169 {
1170     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1171     lldb::ValueObjectSP child_sp;
1172     ValueLocker locker;
1173     lldb::ValueObjectSP value_sp(GetSP(locker));
1174     if (value_sp)
1175     {
1176         // using default values for all the fancy options, just do it if you can
1177         child_sp = value_sp->GetValueForExpressionPath(expr_path);
1178     }
1179
1180     SBValue sb_value;
1181     sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
1182
1183     if (log)
1184         log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)",
1185                      static_cast<void*>(value_sp.get()), expr_path,
1186                      static_cast<void*>(value_sp.get()));
1187
1188     return sb_value;
1189 }
1190
1191 int64_t
1192 SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1193 {
1194     error.Clear();
1195     ValueLocker locker;
1196     lldb::ValueObjectSP value_sp(GetSP(locker));
1197     if (value_sp)
1198     {
1199         bool success = true;
1200         uint64_t ret_val = fail_value;
1201         ret_val = value_sp->GetValueAsSigned(fail_value, &success);
1202         if (!success)
1203             error.SetErrorString("could not resolve value");
1204         return ret_val;
1205     }
1206     else
1207         error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1208     
1209     return fail_value;
1210 }
1211
1212 uint64_t
1213 SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1214 {
1215     error.Clear();
1216     ValueLocker locker;
1217     lldb::ValueObjectSP value_sp(GetSP(locker));
1218     if (value_sp)
1219     {
1220         bool success = true;
1221         uint64_t ret_val = fail_value;
1222         ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
1223         if (!success)
1224             error.SetErrorString("could not resolve value");
1225         return ret_val;
1226     }
1227     else
1228         error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1229     
1230     return fail_value;
1231 }
1232
1233 int64_t
1234 SBValue::GetValueAsSigned(int64_t fail_value)
1235 {
1236     ValueLocker locker;
1237     lldb::ValueObjectSP value_sp(GetSP(locker));
1238     if (value_sp)
1239     {
1240         return value_sp->GetValueAsSigned(fail_value);
1241     }
1242     return fail_value;
1243 }
1244
1245 uint64_t
1246 SBValue::GetValueAsUnsigned(uint64_t fail_value)
1247 {
1248     ValueLocker locker;
1249     lldb::ValueObjectSP value_sp(GetSP(locker));
1250     if (value_sp)
1251     {
1252         return value_sp->GetValueAsUnsigned(fail_value);
1253     }
1254     return fail_value;
1255 }
1256
1257 bool
1258 SBValue::MightHaveChildren ()
1259 {
1260     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1261     bool has_children = false;
1262     ValueLocker locker;
1263     lldb::ValueObjectSP value_sp(GetSP(locker));
1264     if (value_sp)
1265         has_children = value_sp->MightHaveChildren();
1266
1267     if (log)
1268         log->Printf ("SBValue(%p)::MightHaveChildren() => %i",
1269                      static_cast<void*>(value_sp.get()), has_children);
1270     return has_children;
1271 }
1272
1273 bool
1274 SBValue::IsRuntimeSupportValue ()
1275 {
1276     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1277     bool is_support = false;
1278     ValueLocker locker;
1279     lldb::ValueObjectSP value_sp(GetSP(locker));
1280     if (value_sp)
1281         is_support = value_sp->IsRuntimeSupportValue();
1282     
1283     if (log)
1284         log->Printf ("SBValue(%p)::IsRuntimeSupportValue() => %i",
1285                      static_cast<void*>(value_sp.get()), is_support);
1286     return is_support;
1287 }
1288
1289 uint32_t
1290 SBValue::GetNumChildren ()
1291 {
1292     return GetNumChildren (UINT32_MAX);
1293 }
1294
1295 uint32_t
1296 SBValue::GetNumChildren (uint32_t max)
1297 {
1298     uint32_t num_children = 0;
1299
1300     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1301     ValueLocker locker;
1302     lldb::ValueObjectSP value_sp(GetSP(locker));
1303     if (value_sp)
1304         num_children = value_sp->GetNumChildren(max);
1305
1306     if (log)
1307         log->Printf ("SBValue(%p)::GetNumChildren (%u) => %u",
1308                      static_cast<void*>(value_sp.get()), max, num_children);
1309
1310     return num_children;
1311 }
1312
1313 SBValue
1314 SBValue::Dereference ()
1315 {
1316     SBValue sb_value;
1317     ValueLocker locker;
1318     lldb::ValueObjectSP value_sp(GetSP(locker));
1319     if (value_sp)
1320     {
1321         Error error;
1322         sb_value = value_sp->Dereference (error);
1323     }
1324     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1325     if (log)
1326         log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)",
1327                      static_cast<void*>(value_sp.get()),
1328                      static_cast<void*>(value_sp.get()));
1329
1330     return sb_value;
1331 }
1332
1333 // Deprecated - please use GetType().IsPointerType() instead.
1334 bool
1335 SBValue::TypeIsPointerType ()
1336 {
1337     return GetType().IsPointerType();
1338 }
1339
1340 void *
1341 SBValue::GetOpaqueType()
1342 {
1343     ValueLocker locker;
1344     lldb::ValueObjectSP value_sp(GetSP(locker));
1345     if (value_sp)
1346         return value_sp->GetCompilerType().GetOpaqueQualType();
1347     return NULL;
1348 }
1349
1350 lldb::SBTarget
1351 SBValue::GetTarget()
1352 {
1353     SBTarget sb_target;
1354     TargetSP target_sp;
1355     if (m_opaque_sp)
1356     {
1357         target_sp = m_opaque_sp->GetTargetSP();
1358         sb_target.SetSP (target_sp);
1359     }
1360     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1361     if (log)
1362     {
1363         if (target_sp.get() == NULL)
1364             log->Printf ("SBValue(%p)::GetTarget () => NULL",
1365                          static_cast<void*>(m_opaque_sp.get()));
1366         else
1367             log->Printf ("SBValue(%p)::GetTarget () => %p",
1368                          static_cast<void*>(m_opaque_sp.get()),
1369                          static_cast<void*>(target_sp.get()));
1370     }
1371     return sb_target;
1372 }
1373
1374 lldb::SBProcess
1375 SBValue::GetProcess()
1376 {
1377     SBProcess sb_process;
1378     ProcessSP process_sp;
1379     if (m_opaque_sp)
1380     {
1381         process_sp = m_opaque_sp->GetProcessSP();
1382         sb_process.SetSP (process_sp);
1383     }
1384     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1385     if (log)
1386     {
1387         if (process_sp.get() == NULL)
1388             log->Printf ("SBValue(%p)::GetProcess () => NULL",
1389                          static_cast<void*>(m_opaque_sp.get()));
1390         else
1391             log->Printf ("SBValue(%p)::GetProcess () => %p",
1392                          static_cast<void*>(m_opaque_sp.get()),
1393                          static_cast<void*>(process_sp.get()));
1394     }
1395     return sb_process;
1396 }
1397
1398 lldb::SBThread
1399 SBValue::GetThread()
1400 {
1401     SBThread sb_thread;
1402     ThreadSP thread_sp;
1403     if (m_opaque_sp)
1404     {
1405         thread_sp = m_opaque_sp->GetThreadSP();
1406         sb_thread.SetThread(thread_sp);
1407     }
1408     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1409     if (log)
1410     {
1411         if (thread_sp.get() == NULL)
1412             log->Printf ("SBValue(%p)::GetThread () => NULL",
1413                          static_cast<void*>(m_opaque_sp.get()));
1414         else
1415             log->Printf ("SBValue(%p)::GetThread () => %p",
1416                          static_cast<void*>(m_opaque_sp.get()),
1417                          static_cast<void*>(thread_sp.get()));
1418     }
1419     return sb_thread;
1420 }
1421
1422 lldb::SBFrame
1423 SBValue::GetFrame()
1424 {
1425     SBFrame sb_frame;
1426     StackFrameSP frame_sp;
1427     if (m_opaque_sp)
1428     {
1429         frame_sp = m_opaque_sp->GetFrameSP();
1430         sb_frame.SetFrameSP (frame_sp);
1431     }
1432     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1433     if (log)
1434     {
1435         if (frame_sp.get() == NULL)
1436             log->Printf ("SBValue(%p)::GetFrame () => NULL",
1437                          static_cast<void*>(m_opaque_sp.get()));
1438         else
1439             log->Printf ("SBValue(%p)::GetFrame () => %p",
1440                          static_cast<void*>(m_opaque_sp.get()),
1441                          static_cast<void*>(frame_sp.get()));
1442     }
1443     return sb_frame;
1444 }
1445
1446
1447 lldb::ValueObjectSP
1448 SBValue::GetSP (ValueLocker &locker) const
1449 {
1450     if (!m_opaque_sp || !m_opaque_sp->IsValid())
1451     {
1452         locker.GetError().SetErrorString("No value");
1453         return ValueObjectSP();
1454     }
1455     return locker.GetLockedSP(*m_opaque_sp.get());
1456 }
1457
1458 lldb::ValueObjectSP
1459 SBValue::GetSP () const
1460 {
1461     ValueLocker locker;
1462     return GetSP(locker);
1463 }
1464
1465 void
1466 SBValue::SetSP (ValueImplSP impl_sp)
1467 {
1468     m_opaque_sp = impl_sp;
1469 }
1470
1471 void
1472 SBValue::SetSP (const lldb::ValueObjectSP &sp)
1473 {
1474     if (sp)
1475     {
1476         lldb::TargetSP target_sp(sp->GetTargetSP());
1477         if (target_sp)
1478         {
1479             lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1480             bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1481             m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1482         }
1483         else
1484             m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
1485     }
1486     else
1487         m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
1488 }
1489
1490 void
1491 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
1492 {
1493     if (sp)
1494     {
1495         lldb::TargetSP target_sp(sp->GetTargetSP());
1496         if (target_sp)
1497         {
1498             bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1499             SetSP (sp, use_dynamic, use_synthetic);
1500         }
1501         else
1502             SetSP (sp, use_dynamic, true);
1503     }
1504     else
1505         SetSP (sp, use_dynamic, false);
1506 }
1507
1508 void
1509 SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
1510 {
1511     if (sp)
1512     {
1513         lldb::TargetSP target_sp(sp->GetTargetSP());
1514         if (target_sp)
1515         {
1516             lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1517             SetSP (sp, use_dynamic, use_synthetic);
1518         }
1519         else
1520             SetSP (sp, eNoDynamicValues, use_synthetic);
1521     }
1522     else
1523         SetSP (sp, eNoDynamicValues, use_synthetic);
1524 }
1525
1526 void
1527 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
1528 {
1529     m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
1530 }
1531
1532 void
1533 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
1534 {
1535     m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
1536 }
1537
1538 bool
1539 SBValue::GetExpressionPath (SBStream &description)
1540 {
1541     ValueLocker locker;
1542     lldb::ValueObjectSP value_sp(GetSP(locker));
1543     if (value_sp)
1544     {
1545         value_sp->GetExpressionPath (description.ref(), false);
1546         return true;
1547     }
1548     return false;
1549 }
1550
1551 bool
1552 SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1553 {
1554     ValueLocker locker;
1555     lldb::ValueObjectSP value_sp(GetSP(locker));
1556     if (value_sp)
1557     {
1558         value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
1559         return true;
1560     }
1561     return false;
1562 }
1563
1564 bool
1565 SBValue::GetDescription (SBStream &description)
1566 {
1567     Stream &strm = description.ref();
1568     
1569     ValueLocker locker;
1570     lldb::ValueObjectSP value_sp(GetSP(locker));
1571     if (value_sp)
1572         value_sp->Dump(strm);
1573     else
1574         strm.PutCString ("No value");
1575     
1576     return true;
1577 }
1578
1579 lldb::Format
1580 SBValue::GetFormat ()
1581 {
1582     ValueLocker locker;
1583     lldb::ValueObjectSP value_sp(GetSP(locker));
1584     if (value_sp)
1585         return value_sp->GetFormat();
1586     return eFormatDefault;
1587 }
1588
1589 void
1590 SBValue::SetFormat (lldb::Format format)
1591 {
1592     ValueLocker locker;
1593     lldb::ValueObjectSP value_sp(GetSP(locker));
1594     if (value_sp)
1595         value_sp->SetFormat(format);
1596 }
1597
1598 lldb::SBValue
1599 SBValue::AddressOf()
1600 {
1601     SBValue sb_value;
1602     ValueLocker locker;
1603     lldb::ValueObjectSP value_sp(GetSP(locker));
1604     if (value_sp)
1605     {
1606         Error error;
1607         sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
1608     }
1609     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1610     if (log)
1611         log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)",
1612                      static_cast<void*>(value_sp.get()),
1613                      static_cast<void*>(value_sp.get()));
1614
1615     return sb_value;
1616 }
1617
1618 lldb::addr_t
1619 SBValue::GetLoadAddress()
1620 {
1621     lldb::addr_t value = LLDB_INVALID_ADDRESS;
1622     ValueLocker locker;
1623     lldb::ValueObjectSP value_sp(GetSP(locker));
1624     if (value_sp)
1625     {
1626         TargetSP target_sp (value_sp->GetTargetSP());
1627         if (target_sp)
1628         {
1629             const bool scalar_is_load_address = true;
1630             AddressType addr_type;
1631             value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1632             if (addr_type == eAddressTypeFile)
1633             {
1634                 ModuleSP module_sp (value_sp->GetModule());
1635                 if (!module_sp)
1636                     value = LLDB_INVALID_ADDRESS;
1637                 else
1638                 {
1639                     Address addr;
1640                     module_sp->ResolveFileAddress(value, addr);
1641                     value = addr.GetLoadAddress(target_sp.get());
1642                 }
1643             }
1644             else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1645                 value = LLDB_INVALID_ADDRESS;
1646         }
1647     }
1648     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1649     if (log)
1650         log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")",
1651                      static_cast<void*>(value_sp.get()), value);
1652
1653     return value;
1654 }
1655
1656 lldb::SBAddress
1657 SBValue::GetAddress()
1658 {
1659     Address addr;
1660     ValueLocker locker;
1661     lldb::ValueObjectSP value_sp(GetSP(locker));
1662     if (value_sp)
1663     {
1664         TargetSP target_sp (value_sp->GetTargetSP());
1665         if (target_sp)
1666         {
1667             lldb::addr_t value = LLDB_INVALID_ADDRESS;
1668             const bool scalar_is_load_address = true;
1669             AddressType addr_type;
1670             value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1671             if (addr_type == eAddressTypeFile)
1672             {
1673                 ModuleSP module_sp (value_sp->GetModule());
1674                 if (module_sp)
1675                     module_sp->ResolveFileAddress(value, addr);
1676             }
1677             else if (addr_type == eAddressTypeLoad)
1678             {
1679                 // no need to check the return value on this.. if it can actually do the resolve
1680                 // addr will be in the form (section,offset), otherwise it will simply be returned
1681                 // as (NULL, value)
1682                 addr.SetLoadAddress(value, target_sp.get());
1683             }
1684         }
1685     }
1686     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1687     if (log)
1688         log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")",
1689                      static_cast<void*>(value_sp.get()),
1690                      (addr.GetSection()
1691                         ? addr.GetSection()->GetName().GetCString()
1692                         : "NULL"),
1693                      addr.GetOffset());
1694     return SBAddress(new Address(addr));
1695 }
1696
1697 lldb::SBData
1698 SBValue::GetPointeeData (uint32_t item_idx,
1699                          uint32_t item_count)
1700 {
1701     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1702     lldb::SBData sb_data;
1703     ValueLocker locker;
1704     lldb::ValueObjectSP value_sp(GetSP(locker));
1705     if (value_sp)
1706     {
1707         TargetSP target_sp (value_sp->GetTargetSP());
1708         if (target_sp)
1709         {
1710             DataExtractorSP data_sp(new DataExtractor());
1711             value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1712             if (data_sp->GetByteSize() > 0)
1713                 *sb_data = data_sp;
1714         }
1715     }
1716     if (log)
1717         log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
1718                      static_cast<void*>(value_sp.get()), item_idx, item_count,
1719                      static_cast<void*>(sb_data.get()));
1720
1721     return sb_data;
1722 }
1723
1724 lldb::SBData
1725 SBValue::GetData ()
1726 {
1727     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1728     lldb::SBData sb_data;
1729     ValueLocker locker;
1730     lldb::ValueObjectSP value_sp(GetSP(locker));
1731     if (value_sp)
1732     {
1733         DataExtractorSP data_sp(new DataExtractor());
1734         Error error;
1735         value_sp->GetData(*data_sp, error);
1736         if (error.Success())
1737             *sb_data = data_sp;
1738     }
1739     if (log)
1740         log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
1741                      static_cast<void*>(value_sp.get()),
1742                      static_cast<void*>(sb_data.get()));
1743
1744     return sb_data;
1745 }
1746
1747 bool
1748 SBValue::SetData (lldb::SBData &data, SBError &error)
1749 {
1750     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1751     ValueLocker locker;
1752     lldb::ValueObjectSP value_sp(GetSP(locker));
1753     bool ret = true;
1754
1755     if (value_sp)
1756     {
1757         DataExtractor *data_extractor = data.get();
1758
1759         if (!data_extractor)
1760         {
1761             if (log)
1762                 log->Printf ("SBValue(%p)::SetData() => error: no data to set",
1763                              static_cast<void*>(value_sp.get()));
1764
1765             error.SetErrorString("No data to set");
1766             ret = false;
1767         }
1768         else
1769         {
1770             Error set_error;
1771
1772             value_sp->SetData(*data_extractor, set_error);
1773
1774             if (!set_error.Success())
1775             {
1776                 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
1777                 ret = false;
1778             }
1779         }
1780     }
1781     else
1782     {
1783         error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
1784         ret = false;
1785     }
1786
1787     if (log)
1788         log->Printf ("SBValue(%p)::SetData (%p) => %s",
1789                      static_cast<void*>(value_sp.get()),
1790                      static_cast<void*>(data.get()), ret ? "true" : "false");
1791     return ret;
1792 }
1793
1794 lldb::SBDeclaration
1795 SBValue::GetDeclaration ()
1796 {
1797     ValueLocker locker;
1798     lldb::ValueObjectSP value_sp(GetSP(locker));
1799     SBDeclaration decl_sb;
1800     if (value_sp)
1801     {
1802         Declaration decl;
1803         if (value_sp->GetDeclaration(decl))
1804             decl_sb.SetDeclaration(decl);
1805     }
1806     return decl_sb;
1807 }
1808
1809 lldb::SBWatchpoint
1810 SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
1811 {
1812     SBWatchpoint sb_watchpoint;
1813
1814     // If the SBValue is not valid, there's no point in even trying to watch it.
1815     ValueLocker locker;
1816     lldb::ValueObjectSP value_sp(GetSP(locker));
1817     TargetSP target_sp (GetTarget().GetSP());
1818     if (value_sp && target_sp)
1819     {
1820         // Read and Write cannot both be false.
1821         if (!read && !write)
1822             return sb_watchpoint;
1823
1824         // If the value is not in scope, don't try and watch and invalid value
1825         if (!IsInScope())
1826             return sb_watchpoint;
1827
1828         addr_t addr = GetLoadAddress();
1829         if (addr == LLDB_INVALID_ADDRESS)
1830             return sb_watchpoint;
1831         size_t byte_size = GetByteSize();
1832         if (byte_size == 0)
1833             return sb_watchpoint;
1834
1835         uint32_t watch_type = 0;
1836         if (read)
1837             watch_type |= LLDB_WATCH_TYPE_READ;
1838         if (write)
1839             watch_type |= LLDB_WATCH_TYPE_WRITE;
1840
1841         Error rc;
1842         CompilerType type (value_sp->GetCompilerType());
1843         WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
1844         error.SetError(rc);
1845
1846         if (watchpoint_sp)
1847         {
1848             sb_watchpoint.SetSP (watchpoint_sp);
1849             Declaration decl;
1850             if (value_sp->GetDeclaration (decl))
1851             {
1852                 if (decl.GetFile())
1853                 {
1854                     StreamString ss;
1855                     // True to show fullpath for declaration file.
1856                     decl.DumpStopContext(&ss, true);
1857                     watchpoint_sp->SetDeclInfo(ss.GetString());
1858                 }
1859             }
1860         }
1861     }
1862     else if (target_sp)
1863     {
1864         Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1865         if (log)
1866             log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s",
1867                          static_cast<void*>(value_sp.get()),
1868                          locker.GetError().AsCString());
1869
1870         error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
1871     }
1872     else
1873     {
1874         Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1875         if (log)
1876             log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target",
1877                          static_cast<void*>(value_sp.get()));
1878         error.SetErrorString("could not set watchpoint, a target is required");
1879     }
1880
1881     return sb_watchpoint;
1882 }
1883
1884 // FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1885 // Backward compatibility fix in the interim.
1886 lldb::SBWatchpoint
1887 SBValue::Watch (bool resolve_location, bool read, bool write)
1888 {
1889     SBError error;
1890     return Watch(resolve_location, read, write, error);
1891 }
1892
1893 lldb::SBWatchpoint
1894 SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
1895 {
1896     SBWatchpoint sb_watchpoint;
1897     if (IsInScope() && GetType().IsPointerType())
1898         sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
1899     return sb_watchpoint;
1900 }
1901
1902 lldb::SBValue
1903 SBValue::Persist ()
1904 {
1905     ValueLocker locker;
1906     lldb::ValueObjectSP value_sp(GetSP(locker));
1907     SBValue persisted_sb;
1908     if (value_sp)
1909     {
1910         persisted_sb.SetSP(value_sp->Persist());
1911     }
1912     return persisted_sb;
1913 }