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