SBValue.cpp revision a713b869459b1d4a62c54a68535e6a8fd71c8a62
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#include "lldb/API/SBStream.h"
12
13#include "lldb/Core/DataExtractor.h"
14#include "lldb/Core/Log.h"
15#include "lldb/Core/Module.h"
16#include "lldb/Core/Scalar.h"
17#include "lldb/Core/Stream.h"
18#include "lldb/Core/StreamFile.h"
19#include "lldb/Core/Value.h"
20#include "lldb/Core/ValueObject.h"
21#include "lldb/Core/ValueObjectConstResult.h"
22#include "lldb/Symbol/Block.h"
23#include "lldb/Symbol/ObjectFile.h"
24#include "lldb/Symbol/Variable.h"
25#include "lldb/Target/ExecutionContext.h"
26#include "lldb/Target/Process.h"
27#include "lldb/Target/StackFrame.h"
28#include "lldb/Target/Target.h"
29#include "lldb/Target/Thread.h"
30
31#include "lldb/API/SBProcess.h"
32#include "lldb/API/SBTarget.h"
33#include "lldb/API/SBThread.h"
34#include "lldb/API/SBFrame.h"
35#include "lldb/API/SBDebugger.h"
36
37using namespace lldb;
38using namespace lldb_private;
39
40SBValue::SBValue () :
41    m_opaque_sp ()
42{
43}
44
45SBValue::SBValue (const lldb::ValueObjectSP &value_sp) :
46    m_opaque_sp (value_sp)
47{
48}
49
50SBValue::SBValue(const SBValue &rhs) :
51    m_opaque_sp (rhs.m_opaque_sp)
52{
53}
54
55const SBValue &
56SBValue::operator = (const SBValue &rhs)
57{
58    if (this != &rhs)
59        m_opaque_sp = rhs.m_opaque_sp;
60    return *this;
61}
62
63SBValue::~SBValue()
64{
65}
66
67bool
68SBValue::IsValid () const
69{
70    // If this function ever changes to anything that does more than just
71    // check if the opaque shared pointer is non NULL, then we need to update
72    // all "if (m_opaque_sp)" code in this file.
73    return m_opaque_sp.get() != NULL;
74}
75
76SBError
77SBValue::GetError()
78{
79    SBError sb_error;
80
81    if (m_opaque_sp.get())
82        sb_error.SetError(m_opaque_sp->GetError());
83
84    return sb_error;
85}
86
87user_id_t
88SBValue::GetID()
89{
90    if (m_opaque_sp)
91        return m_opaque_sp->GetID();
92    return LLDB_INVALID_UID;
93}
94
95const char *
96SBValue::GetName()
97{
98
99    const char *name = NULL;
100    if (m_opaque_sp)
101        name = m_opaque_sp->GetName().GetCString();
102
103    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
104    if (log)
105    {
106        if (name)
107            log->Printf ("SBValue(%p)::GetName () => \"%s\"", m_opaque_sp.get(), name);
108        else
109            log->Printf ("SBValue(%p)::GetName () => NULL", m_opaque_sp.get(), name);
110    }
111
112    return name;
113}
114
115const char *
116SBValue::GetTypeName ()
117{
118    const char *name = NULL;
119    if (m_opaque_sp)
120        name = m_opaque_sp->GetTypeName().GetCString();
121    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
122    if (log)
123    {
124        if (name)
125            log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", m_opaque_sp.get(), name);
126        else
127            log->Printf ("SBValue(%p)::GetTypeName () => NULL", m_opaque_sp.get());
128    }
129
130    return name;
131}
132
133size_t
134SBValue::GetByteSize ()
135{
136    size_t result = 0;
137
138    if (m_opaque_sp)
139        result = m_opaque_sp->GetByteSize();
140
141    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
142    if (log)
143        log->Printf ("SBValue(%p)::GetByteSize () => %zu", m_opaque_sp.get(), result);
144
145    return result;
146}
147
148bool
149SBValue::IsInScope (const SBFrame &sb_frame)
150{
151    return IsInScope();
152}
153
154bool
155SBValue::IsInScope ()
156{
157    bool result = false;
158
159    if (m_opaque_sp)
160    {
161        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
162        {
163            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
164            result = m_opaque_sp->IsInScope ();
165        }
166    }
167
168    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
169    if (log)
170        log->Printf ("SBValue(%p)::IsInScope () => %i", m_opaque_sp.get(), result);
171
172    return result;
173}
174
175const char *
176SBValue::GetValue (const SBFrame &sb_frame)
177{
178    return GetValue();
179}
180
181const char *
182SBValue::GetValue ()
183{
184    const char *cstr = NULL;
185    if (m_opaque_sp)
186    {
187        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
188        {
189            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
190            cstr = m_opaque_sp->GetValueAsCString ();
191        }
192    }
193    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
194    if (log)
195    {
196        if (cstr)
197            log->Printf ("SBValue(%p)::GetValue => \"%s\"", m_opaque_sp.get(), cstr);
198        else
199            log->Printf ("SBValue(%p)::GetValue => NULL", m_opaque_sp.get());
200    }
201
202    return cstr;
203}
204
205ValueType
206SBValue::GetValueType ()
207{
208    ValueType result = eValueTypeInvalid;
209    if (m_opaque_sp)
210        result = m_opaque_sp->GetValueType();
211    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
212    if (log)
213    {
214        switch (result)
215        {
216        case eValueTypeInvalid:         log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", m_opaque_sp.get()); break;
217        case eValueTypeVariableGlobal:  log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", m_opaque_sp.get()); break;
218        case eValueTypeVariableStatic:  log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", m_opaque_sp.get()); break;
219        case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", m_opaque_sp.get()); break;
220        case eValueTypeVariableLocal:   log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", m_opaque_sp.get()); break;
221        case eValueTypeRegister:        log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", m_opaque_sp.get()); break;
222        case eValueTypeRegisterSet:     log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", m_opaque_sp.get()); break;
223        case eValueTypeConstResult:     log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", m_opaque_sp.get()); break;
224        default:     log->Printf ("SBValue(%p)::GetValueType () => %i ???", m_opaque_sp.get(), result); break;
225        }
226    }
227    return result;
228}
229
230const char *
231SBValue::GetObjectDescription (const SBFrame &sb_frame)
232{
233    return GetObjectDescription ();
234}
235
236const char *
237SBValue::GetObjectDescription ()
238{
239    const char *cstr = NULL;
240    if (m_opaque_sp)
241    {
242        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
243        {
244            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
245            cstr = m_opaque_sp->GetObjectDescription ();
246        }
247    }
248    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
249    if (log)
250    {
251        if (cstr)
252            log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", m_opaque_sp.get(), cstr);
253        else
254            log->Printf ("SBValue(%p)::GetObjectDescription => NULL", m_opaque_sp.get());
255    }
256    return cstr;
257}
258
259bool
260SBValue::GetValueDidChange (const SBFrame &sb_frame)
261{
262    return GetValueDidChange ();
263}
264
265SBType
266SBValue::GetType()
267{
268    SBType result;
269    if (m_opaque_sp)
270    {
271        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
272        {
273            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
274            result = SBType(ClangASTType (m_opaque_sp->GetClangAST(), m_opaque_sp->GetClangType()));
275        }
276    }
277    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
278    if (log)
279    {
280        if (result.IsValid())
281            log->Printf ("SBValue(%p)::GetType => %p", m_opaque_sp.get(), &result);
282        else
283            log->Printf ("SBValue(%p)::GetType => NULL", m_opaque_sp.get());
284    }
285    return result;
286}
287
288bool
289SBValue::GetValueDidChange ()
290{
291    bool result = false;
292    if (m_opaque_sp)
293    {
294        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
295        {
296            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
297            result = m_opaque_sp->GetValueDidChange ();
298        }
299    }
300    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
301    if (log)
302        log->Printf ("SBValue(%p)::GetValueDidChange => %i", m_opaque_sp.get(), result);
303
304    return result;
305}
306
307const char *
308SBValue::GetSummary (const SBFrame &sb_frame)
309{
310    return GetSummary ();
311}
312
313const char *
314SBValue::GetSummary ()
315{
316    const char *cstr = NULL;
317    if (m_opaque_sp)
318    {
319        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
320        {
321            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
322            cstr = m_opaque_sp->GetSummaryAsCString();
323        }
324    }
325    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
326    if (log)
327    {
328        if (cstr)
329            log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
330        else
331            log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
332    }
333    return cstr;
334}
335
336const char *
337SBValue::GetLocation (const SBFrame &sb_frame)
338{
339    return GetLocation ();
340}
341
342const char *
343SBValue::GetLocation ()
344{
345    const char *cstr = NULL;
346    if (m_opaque_sp)
347    {
348        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
349        {
350            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
351            cstr = m_opaque_sp->GetLocationAsCString();
352        }
353    }
354    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
355    if (log)
356    {
357        if (cstr)
358            log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
359        else
360            log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
361    }
362    return cstr;
363}
364
365bool
366SBValue::SetValueFromCString (const SBFrame &sb_frame, const char *value_str)
367{
368    return SetValueFromCString (value_str);
369}
370
371bool
372SBValue::SetValueFromCString (const char *value_str)
373{
374    bool success = false;
375    if (m_opaque_sp)
376    {
377        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
378        {
379            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
380            success = m_opaque_sp->SetValueFromCString (value_str);
381        }
382    }
383    return success;
384}
385
386lldb::SBValue
387SBValue::CreateChildAtOffset (const char *name, uint32_t offset, const SBType& type)
388{
389    lldb::SBValue result;
390    if (m_opaque_sp)
391    {
392        if (type.IsValid())
393        {
394            result = SBValue(m_opaque_sp->GetSyntheticChildAtOffset(offset, type.m_opaque_sp->GetClangASTType(), true));
395            result.m_opaque_sp->SetName(ConstString(name));
396        }
397    }
398    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
399    if (log)
400    {
401        if (result.IsValid())
402            log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp.get());
403        else
404            log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", m_opaque_sp.get());
405    }
406    return result;
407}
408
409lldb::SBValue
410SBValue::Cast(const SBType& type)
411{
412    return CreateChildAtOffset(m_opaque_sp->GetName().GetCString(), 0, type);
413}
414
415lldb::SBValue
416SBValue::CreateValueFromExpression (const char *name, const char* expression)
417{
418    lldb::SBValue result;
419    if (m_opaque_sp)
420    {
421        ValueObjectSP result_valobj_sp;
422        m_opaque_sp->GetUpdatePoint().GetTargetSP()->EvaluateExpression(expression,
423                                                                      m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateStackFrame(),
424                                                                      true, true, eNoDynamicValues,
425                                                                      result_valobj_sp);
426        result_valobj_sp->SetName(ConstString(name));
427        result = SBValue(result_valobj_sp);
428    }
429    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
430    if (log)
431    {
432        if (result.IsValid())
433            log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp.get());
434        else
435            log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get());
436    }
437    return result;
438}
439
440lldb::SBValue
441SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, const SBType& type)
442{
443    lldb::SBValue result;
444    if (m_opaque_sp)
445    {
446
447        SBType real_type(type.GetPointerType());
448
449        lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
450
451        ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create(m_opaque_sp->GetUpdatePoint().GetExecutionContextScope(),
452                                                                          real_type.m_opaque_sp->GetASTContext(),
453                                                                          real_type.m_opaque_sp->GetOpaqueQualType(),
454                                                                          ConstString(name),
455                                                                          buffer,
456                                                                          lldb::endian::InlHostByteOrder(),
457                                                                          GetTarget().GetProcess().GetAddressByteSize()));
458
459        ValueObjectSP result_valobj_sp;
460
461        ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
462        if (ptr_result_valobj_sp)
463        {
464            Error err;
465            result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
466            if (result_valobj_sp)
467                result_valobj_sp->SetName(ConstString(name));
468        }
469        result = SBValue(result_valobj_sp);
470    }
471    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
472    if (log)
473    {
474        if (result.IsValid())
475            log->Printf ("SBValue(%p)::GetChildFromAddress => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp.get());
476        else
477            log->Printf ("SBValue(%p)::GetChildFromAddress => NULL", m_opaque_sp.get());
478    }
479    return result;
480}
481
482SBValue
483SBValue::GetChildAtIndex (uint32_t idx)
484{
485    const bool can_create_synthetic = false;
486    lldb::DynamicValueType use_dynamic = eNoDynamicValues;
487    if (m_opaque_sp)
488        use_dynamic = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
489    return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
490}
491
492SBValue
493SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
494{
495    lldb::ValueObjectSP child_sp;
496
497    if (m_opaque_sp)
498    {
499        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
500        {
501            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
502            const bool can_create = true;
503            child_sp = m_opaque_sp->GetChildAtIndex (idx, can_create);
504            if (can_create_synthetic && !child_sp)
505            {
506                if (m_opaque_sp->IsPointerType())
507                {
508                    child_sp = m_opaque_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
509                }
510                else if (m_opaque_sp->IsArrayType())
511                {
512                    child_sp = m_opaque_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
513                }
514            }
515
516            if (child_sp)
517            {
518                if (use_dynamic != lldb::eNoDynamicValues)
519                {
520                    lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
521                    if (dynamic_sp)
522                        child_sp = dynamic_sp;
523                }
524            }
525        }
526    }
527
528    SBValue sb_value (child_sp);
529    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
530    if (log)
531        log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get());
532
533    return sb_value;
534}
535
536uint32_t
537SBValue::GetIndexOfChildWithName (const char *name)
538{
539    uint32_t idx = UINT32_MAX;
540    if (m_opaque_sp)
541    {
542        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
543        {
544            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
545
546            idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
547        }
548    }
549    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
550    if (log)
551    {
552        if (idx == UINT32_MAX)
553            log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name, idx);
554        else
555            log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx);
556    }
557    return idx;
558}
559
560SBValue
561SBValue::GetChildMemberWithName (const char *name)
562{
563    if (m_opaque_sp)
564    {
565        lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
566        return GetChildMemberWithName (name, use_dynamic_value);
567    }
568    else
569        return GetChildMemberWithName (name, eNoDynamicValues);
570}
571
572SBValue
573SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
574{
575    lldb::ValueObjectSP child_sp;
576    const ConstString str_name (name);
577
578
579    if (m_opaque_sp)
580    {
581        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
582        {
583            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
584            child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
585            if (use_dynamic_value != lldb::eNoDynamicValues)
586            {
587                if (child_sp)
588                {
589                    lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
590                    if (dynamic_sp)
591                        child_sp = dynamic_sp;
592                }
593            }
594        }
595    }
596
597    SBValue sb_value (child_sp);
598
599    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
600    if (log)
601        log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get());
602
603    return sb_value;
604}
605
606lldb::SBValue
607SBValue::GetValueForExpressionPath(const char* expr_path)
608{
609    lldb::ValueObjectSP child_sp;
610    if (m_opaque_sp)
611    {
612        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
613        {
614            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
615            // using default values for all the fancy options, just do it if you can
616            child_sp = m_opaque_sp->GetValueForExpressionPath(expr_path);
617        }
618    }
619
620    SBValue sb_value (child_sp);
621
622    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
623    if (log)
624        log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", m_opaque_sp.get(), expr_path, sb_value.get());
625
626    return sb_value;
627}
628
629int64_t
630SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
631{
632    if (m_opaque_sp)
633    {
634        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
635        {
636            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
637            Scalar scalar;
638            if (m_opaque_sp->ResolveValue (scalar))
639                return scalar.GetRawBits64(fail_value);
640            else
641                error.SetErrorString("could not get value");
642        }
643        else
644            error.SetErrorString("could not get target");
645    }
646    error.SetErrorString("invalid SBValue");
647    return fail_value;
648}
649
650uint64_t
651SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
652{
653    if (m_opaque_sp)
654    {
655        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
656        {
657            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
658            Scalar scalar;
659            if (m_opaque_sp->ResolveValue (scalar))
660                return scalar.GetRawBits64(fail_value);
661            else
662                error.SetErrorString("could not get value");
663        }
664        else
665            error.SetErrorString("could not get target");
666    }
667    error.SetErrorString("invalid SBValue");
668    return fail_value;
669}
670
671int64_t
672SBValue::GetValueAsSigned(int64_t fail_value)
673{
674    if (m_opaque_sp)
675    {
676        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
677        {
678            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
679            Scalar scalar;
680            if (m_opaque_sp->ResolveValue (scalar))
681                return scalar.GetRawBits64(fail_value);
682        }
683    }
684    return fail_value;
685}
686
687uint64_t
688SBValue::GetValueAsUnsigned(uint64_t fail_value)
689{
690    if (m_opaque_sp)
691    {
692        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
693        {
694            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
695            Scalar scalar;
696            if (m_opaque_sp->ResolveValue (scalar))
697                return scalar.GetRawBits64(fail_value);
698        }
699    }
700    return fail_value;
701}
702
703uint32_t
704SBValue::GetNumChildren ()
705{
706    uint32_t num_children = 0;
707
708    if (m_opaque_sp)
709    {
710        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
711        {
712            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
713
714            num_children = m_opaque_sp->GetNumChildren();
715        }
716    }
717
718    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
719    if (log)
720        log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children);
721
722    return num_children;
723}
724
725
726SBValue
727SBValue::Dereference ()
728{
729    SBValue sb_value;
730    if (m_opaque_sp)
731    {
732        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
733        {
734            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
735
736            Error error;
737            sb_value = m_opaque_sp->Dereference (error);
738        }
739    }
740    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
741    if (log)
742        log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
743
744    return sb_value;
745}
746
747bool
748SBValue::TypeIsPointerType ()
749{
750    bool is_ptr_type = false;
751
752    if (m_opaque_sp)
753    {
754        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
755        {
756            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
757
758            is_ptr_type = m_opaque_sp->IsPointerType();
759        }
760    }
761
762    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
763    if (log)
764        log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type);
765
766
767    return is_ptr_type;
768}
769
770void *
771SBValue::GetOpaqueType()
772{
773    if (m_opaque_sp)
774    {
775        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
776        {
777            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
778
779            return m_opaque_sp->GetClangType();
780        }
781    }
782    return NULL;
783}
784
785lldb::SBTarget
786SBValue::GetTarget()
787{
788    SBTarget result;
789    if (m_opaque_sp)
790    {
791        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
792        {
793            result = SBTarget(lldb::TargetSP(m_opaque_sp->GetUpdatePoint().GetTargetSP()));
794        }
795    }
796    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
797    if (log)
798    {
799        if (result.get() == NULL)
800            log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get());
801        else
802            log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), result.get());
803    }
804    return result;
805}
806
807lldb::SBProcess
808SBValue::GetProcess()
809{
810    SBProcess result;
811    if (m_opaque_sp)
812    {
813        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
814        {
815            result = SBProcess(lldb::ProcessSP(m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetProcessSP()));
816        }
817    }
818    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
819    if (log)
820    {
821        if (result.get() == NULL)
822            log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get());
823        else
824            log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), result.get());
825    }
826    return result;
827}
828
829lldb::SBThread
830SBValue::GetThread()
831{
832    SBThread result;
833    if (m_opaque_sp)
834    {
835        if (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope())
836        {
837            result = SBThread(lldb::ThreadSP(m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateThread()));
838        }
839    }
840    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
841    if (log)
842    {
843        if (result.get() == NULL)
844            log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get());
845        else
846            log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), result.get());
847    }
848    return result;
849}
850
851lldb::SBFrame
852SBValue::GetFrame()
853{
854    SBFrame result;
855    if (m_opaque_sp)
856    {
857        if (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope())
858        {
859            result = SBFrame(lldb::StackFrameSP(m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateStackFrame()));
860        }
861    }
862    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
863    if (log)
864    {
865        if (result.get() == NULL)
866            log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get());
867        else
868            log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), result.get());
869    }
870    return result;
871}
872
873
874// Mimic shared pointer...
875lldb_private::ValueObject *
876SBValue::get() const
877{
878    return m_opaque_sp.get();
879}
880
881lldb_private::ValueObject *
882SBValue::operator->() const
883{
884    return m_opaque_sp.get();
885}
886
887lldb::ValueObjectSP &
888SBValue::operator*()
889{
890    return m_opaque_sp;
891}
892
893const lldb::ValueObjectSP &
894SBValue::operator*() const
895{
896    return m_opaque_sp;
897}
898
899bool
900SBValue::GetExpressionPath (SBStream &description)
901{
902    if (m_opaque_sp)
903    {
904        m_opaque_sp->GetExpressionPath (description.ref(), false);
905        return true;
906    }
907    return false;
908}
909
910bool
911SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
912{
913    if (m_opaque_sp)
914    {
915        m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
916        return true;
917    }
918    return false;
919}
920
921bool
922SBValue::GetDescription (SBStream &description)
923{
924    if (m_opaque_sp)
925    {
926        uint32_t ptr_depth = 0;
927        uint32_t curr_depth = 0;
928        uint32_t max_depth = UINT32_MAX;
929        bool show_types = false;
930        bool show_location = false;
931        bool use_objc = false;
932        lldb::DynamicValueType use_dynamic = eNoDynamicValues;
933        bool scope_already_checked = false;
934        bool flat_output = false;
935        bool use_synthetic = true;
936        uint32_t no_summary_depth = 0;
937        ValueObject::DumpValueObject (description.ref(),
938                                      m_opaque_sp.get(),
939                                      m_opaque_sp->GetName().GetCString(),
940                                      ptr_depth,
941                                      curr_depth,
942                                      max_depth,
943                                      show_types, show_location,
944                                      use_objc,
945                                      use_dynamic,
946                                      use_synthetic,
947                                      scope_already_checked,
948                                      flat_output,
949                                      no_summary_depth);
950    }
951    else
952        description.Printf ("No value");
953
954    return true;
955}
956
957lldb::Format
958SBValue::GetFormat () const
959{
960    if (m_opaque_sp)
961        return m_opaque_sp->GetFormat();
962    return eFormatDefault;
963}
964
965void
966SBValue::SetFormat (lldb::Format format)
967{
968    if (m_opaque_sp)
969        m_opaque_sp->SetFormat(format);
970}
971
972lldb::SBValue
973SBValue::AddressOf()
974{
975    SBValue sb_value;
976    if (m_opaque_sp)
977    {
978        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
979        {
980            Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
981
982            Error error;
983            sb_value = m_opaque_sp->AddressOf (error);
984        }
985    }
986    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
987    if (log)
988        log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
989
990    return sb_value;
991}
992