1 //===-- SBValue.cpp ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBValue.h"
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"
19 #include "lldb/Breakpoint/Watchpoint.h"
20 #include "lldb/Core/DataExtractor.h"
21 #include "lldb/Core/Log.h"
22 #include "lldb/Core/Module.h"
23 #include "lldb/Core/Scalar.h"
24 #include "lldb/Core/Section.h"
25 #include "lldb/Core/Stream.h"
26 #include "lldb/Core/StreamFile.h"
27 #include "lldb/Core/Value.h"
28 #include "lldb/Core/ValueObject.h"
29 #include "lldb/Core/ValueObjectConstResult.h"
30 #include "lldb/DataFormatters/DataVisualization.h"
31 #include "lldb/Symbol/Block.h"
32 #include "lldb/Symbol/Declaration.h"
33 #include "lldb/Symbol/ObjectFile.h"
34 #include "lldb/Symbol/Type.h"
35 #include "lldb/Symbol/Variable.h"
36 #include "lldb/Symbol/VariableList.h"
37 #include "lldb/Target/ExecutionContext.h"
38 #include "lldb/Target/Process.h"
39 #include "lldb/Target/StackFrame.h"
40 #include "lldb/Target/Target.h"
41 #include "lldb/Target/Thread.h"
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"
51 using namespace lldb_private;
60 ValueImpl (lldb::ValueObjectSP in_valobj_sp,
61 lldb::DynamicValueType use_dynamic,
63 const char *name = NULL) :
65 m_use_dynamic(use_dynamic),
66 m_use_synthetic(use_synthetic),
71 if ( (m_valobj_sp = in_valobj_sp->GetQualifiedRepresentationIfAvailable(lldb::eNoDynamicValues, false)) )
73 if (!m_name.IsEmpty())
74 m_valobj_sp->SetName(m_name);
79 ValueImpl (const ValueImpl& rhs) :
80 m_valobj_sp(rhs.m_valobj_sp),
81 m_use_dynamic(rhs.m_use_dynamic),
82 m_use_synthetic(rhs.m_use_synthetic),
88 operator = (const ValueImpl &rhs)
92 m_valobj_sp = rhs.m_valobj_sp;
93 m_use_dynamic = rhs.m_use_dynamic;
94 m_use_synthetic = rhs.m_use_synthetic;
103 if (m_valobj_sp.get() == NULL)
107 // FIXME: This check is necessary but not sufficient. We for sure don't want to touch SBValues whose owning
108 // targets have gone away. This check is a little weak in that it enforces that restriction when you call
109 // IsValid, but since IsValid doesn't lock the target, you have no guarantee that the SBValue won't go
110 // invalid after you call this...
111 // Also, an SBValue could depend on data from one of the modules in the target, and those could go away
112 // independently of the target, for instance if a module is unloaded. But right now, neither SBValues
113 // nor ValueObjects know which modules they depend on. So I have no good way to make that check without
114 // tracking that in all the ValueObject subclasses.
115 TargetSP target_sp = m_valobj_sp->GetTargetSP();
116 if (target_sp && target_sp->IsValid())
130 GetSP(Process::StopLocker &stop_locker, std::unique_lock<std::recursive_mutex> &lock, Error &error)
132 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
135 error.SetErrorString("invalid value object");
139 lldb::ValueObjectSP value_sp = m_valobj_sp;
141 Target *target = value_sp->GetTargetSP().get();
143 return ValueObjectSP();
145 lock = std::unique_lock<std::recursive_mutex>(target->GetAPIMutex());
147 ProcessSP process_sp(value_sp->GetProcessSP());
148 if (process_sp && !stop_locker.TryLock (&process_sp->GetRunLock()))
150 // We don't allow people to play around with ValueObject if the process is running.
151 // If you want to look at values, pause the process, then look.
153 log->Printf ("SBValue(%p)::GetSP() => error: process is running",
154 static_cast<void*>(value_sp.get()));
155 error.SetErrorString ("process must be stopped.");
156 return ValueObjectSP();
159 if (m_use_dynamic != eNoDynamicValues)
161 ValueObjectSP dynamic_sp = value_sp->GetDynamicValue(m_use_dynamic);
163 value_sp = dynamic_sp;
168 ValueObjectSP synthetic_sp = value_sp->GetSyntheticValue(m_use_synthetic);
170 value_sp = synthetic_sp;
174 error.SetErrorString("invalid value object");
175 if (!m_name.IsEmpty())
176 value_sp->SetName(m_name);
182 SetUseDynamic (lldb::DynamicValueType use_dynamic)
184 m_use_dynamic = use_dynamic;
188 SetUseSynthetic (bool use_synthetic)
190 m_use_synthetic = use_synthetic;
193 lldb::DynamicValueType
196 return m_use_dynamic;
202 return m_use_synthetic;
205 // All the derived values that we would make from the m_valobj_sp will share
206 // the ExecutionContext with m_valobj_sp, so we don't need to do the calculations
207 // in GetSP to return the Target, Process, Thread or Frame. It is convenient to
208 // provide simple accessors for these, which I do here.
213 return m_valobj_sp->GetTargetSP();
222 return m_valobj_sp->GetProcessSP();
231 return m_valobj_sp->GetThreadSP();
240 return m_valobj_sp->GetFrameSP();
242 return StackFrameSP();
246 lldb::ValueObjectSP m_valobj_sp;
247 lldb::DynamicValueType m_use_dynamic;
248 bool m_use_synthetic;
260 GetLockedSP(ValueImpl &in_value)
262 return in_value.GetSP(m_stop_locker, m_lock, m_lock_error);
272 Process::StopLocker m_stop_locker;
273 std::unique_lock<std::recursive_mutex> m_lock;
277 SBValue::SBValue () :
282 SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
287 SBValue::SBValue(const SBValue &rhs)
289 SetSP(rhs.m_opaque_sp);
293 SBValue::operator = (const SBValue &rhs)
297 SetSP(rhs.m_opaque_sp);
309 // If this function ever changes to anything that does more than just
310 // check if the opaque shared pointer is non NULL, then we need to update
311 // all "if (m_opaque_sp)" code in this file.
312 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid() && m_opaque_sp->GetRootSP().get() != NULL;
327 lldb::ValueObjectSP value_sp(GetSP(locker));
329 sb_error.SetError(value_sp->GetError());
331 sb_error.SetErrorStringWithFormat ("error: %s", locker.GetError().AsCString());
340 lldb::ValueObjectSP value_sp(GetSP(locker));
342 return value_sp->GetID();
343 return LLDB_INVALID_UID;
349 const char *name = NULL;
351 lldb::ValueObjectSP value_sp(GetSP(locker));
353 name = value_sp->GetName().GetCString();
355 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
359 log->Printf ("SBValue(%p)::GetName () => \"%s\"",
360 static_cast<void*>(value_sp.get()), name);
362 log->Printf ("SBValue(%p)::GetName () => NULL",
363 static_cast<void*>(value_sp.get()));
370 SBValue::GetTypeName ()
372 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
373 const char *name = NULL;
375 lldb::ValueObjectSP value_sp(GetSP(locker));
378 name = value_sp->GetQualifiedTypeName().GetCString();
384 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"",
385 static_cast<void*>(value_sp.get()), name);
387 log->Printf ("SBValue(%p)::GetTypeName () => NULL",
388 static_cast<void*>(value_sp.get()));
395 SBValue::GetDisplayTypeName ()
397 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
398 const char *name = NULL;
400 lldb::ValueObjectSP value_sp(GetSP(locker));
403 name = value_sp->GetDisplayTypeName().GetCString();
409 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"",
410 static_cast<void*>(value_sp.get()), name);
412 log->Printf ("SBValue(%p)::GetTypeName () => NULL",
413 static_cast<void*>(value_sp.get()));
420 SBValue::GetByteSize ()
422 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
426 lldb::ValueObjectSP value_sp(GetSP(locker));
429 result = value_sp->GetByteSize();
433 log->Printf ("SBValue(%p)::GetByteSize () => %" PRIu64,
434 static_cast<void*>(value_sp.get()),
435 static_cast<uint64_t>(result));
441 SBValue::IsInScope ()
446 lldb::ValueObjectSP value_sp(GetSP(locker));
449 result = value_sp->IsInScope ();
452 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
454 log->Printf ("SBValue(%p)::IsInScope () => %i",
455 static_cast<void*>(value_sp.get()), result);
463 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
465 const char *cstr = NULL;
467 lldb::ValueObjectSP value_sp(GetSP(locker));
470 cstr = value_sp->GetValueAsCString ();
475 log->Printf ("SBValue(%p)::GetValue() => \"%s\"",
476 static_cast<void*>(value_sp.get()), cstr);
478 log->Printf ("SBValue(%p)::GetValue() => NULL",
479 static_cast<void*>(value_sp.get()));
486 SBValue::GetValueType ()
488 ValueType result = eValueTypeInvalid;
490 lldb::ValueObjectSP value_sp(GetSP(locker));
492 result = value_sp->GetValueType();
494 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
499 case eValueTypeInvalid:
500 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid",
501 static_cast<void*>(value_sp.get()));
503 case eValueTypeVariableGlobal:
504 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal",
505 static_cast<void*>(value_sp.get()));
507 case eValueTypeVariableStatic:
508 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic",
509 static_cast<void*>(value_sp.get()));
511 case eValueTypeVariableArgument:
512 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument",
513 static_cast<void*>(value_sp.get()));
515 case eValueTypeVariableLocal:
516 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal",
517 static_cast<void*>(value_sp.get()));
519 case eValueTypeRegister:
520 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister",
521 static_cast<void*>(value_sp.get()));
523 case eValueTypeRegisterSet:
524 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet",
525 static_cast<void*>(value_sp.get()));
527 case eValueTypeConstResult:
528 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult",
529 static_cast<void*>(value_sp.get()));
531 case eValueTypeVariableThreadLocal:
532 log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableThreadLocal",
533 static_cast<void *>(value_sp.get()));
541 SBValue::GetObjectDescription ()
543 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
544 const char *cstr = NULL;
546 lldb::ValueObjectSP value_sp(GetSP(locker));
549 cstr = value_sp->GetObjectDescription ();
554 log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"",
555 static_cast<void*>(value_sp.get()), cstr);
557 log->Printf ("SBValue(%p)::GetObjectDescription() => NULL",
558 static_cast<void*>(value_sp.get()));
564 SBValue::GetTypeValidatorResult ()
566 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
567 const char *cstr = NULL;
569 lldb::ValueObjectSP value_sp(GetSP(locker));
572 const auto& validation(value_sp->GetValidationStatus());
573 if (TypeValidatorResult::Failure == validation.first)
575 if (validation.second.empty())
576 cstr = "unknown error";
578 cstr = validation.second.c_str();
584 log->Printf ("SBValue(%p)::GetTypeValidatorResult() => \"%s\"",
585 static_cast<void*>(value_sp.get()), cstr);
587 log->Printf ("SBValue(%p)::GetTypeValidatorResult() => NULL",
588 static_cast<void*>(value_sp.get()));
596 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
599 lldb::ValueObjectSP value_sp(GetSP(locker));
603 type_sp.reset (new TypeImpl(value_sp->GetTypeImpl()));
604 sb_type.SetSP(type_sp);
609 log->Printf ("SBValue(%p)::GetType => SBType(%p)",
610 static_cast<void*>(value_sp.get()),
611 static_cast<void*>(type_sp.get()));
613 log->Printf ("SBValue(%p)::GetType => NULL",
614 static_cast<void*>(value_sp.get()));
620 SBValue::GetValueDidChange ()
622 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
625 lldb::ValueObjectSP value_sp(GetSP(locker));
628 if (value_sp->UpdateValueIfNeeded(false))
629 result = value_sp->GetValueDidChange ();
632 log->Printf ("SBValue(%p)::GetValueDidChange() => %i",
633 static_cast<void*>(value_sp.get()), result);
639 SBValue::GetSummary ()
641 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
642 const char *cstr = NULL;
644 lldb::ValueObjectSP value_sp(GetSP(locker));
647 cstr = value_sp->GetSummaryAsCString();
652 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
653 static_cast<void*>(value_sp.get()), cstr);
655 log->Printf ("SBValue(%p)::GetSummary() => NULL",
656 static_cast<void*>(value_sp.get()));
662 SBValue::GetSummary (lldb::SBStream& stream,
663 lldb::SBTypeSummaryOptions& options)
665 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
667 lldb::ValueObjectSP value_sp(GetSP(locker));
671 if (value_sp->GetSummaryAsCString(buffer,options.ref()) && !buffer.empty())
672 stream.Printf("%s",buffer.c_str());
674 const char* cstr = stream.GetData();
678 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
679 static_cast<void*>(value_sp.get()), cstr);
681 log->Printf ("SBValue(%p)::GetSummary() => NULL",
682 static_cast<void*>(value_sp.get()));
688 SBValue::GetLocation ()
690 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
691 const char *cstr = NULL;
693 lldb::ValueObjectSP value_sp(GetSP(locker));
696 cstr = value_sp->GetLocationAsCString();
701 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"",
702 static_cast<void*>(value_sp.get()), cstr);
704 log->Printf ("SBValue(%p)::GetLocation() => NULL",
705 static_cast<void*>(value_sp.get()));
710 // Deprecated - use the one that takes an lldb::SBError
712 SBValue::SetValueFromCString (const char *value_str)
715 return SetValueFromCString(value_str,dummy);
719 SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
721 bool success = false;
723 lldb::ValueObjectSP value_sp(GetSP(locker));
724 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
727 success = value_sp->SetValueFromCString (value_str,error.ref());
730 error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString());
733 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i",
734 static_cast<void*>(value_sp.get()), value_str, success);
740 SBValue::GetTypeFormat ()
742 lldb::SBTypeFormat format;
744 lldb::ValueObjectSP value_sp(GetSP(locker));
747 if (value_sp->UpdateValueIfNeeded(true))
749 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
751 format.SetSP(format_sp);
758 SBValue::GetTypeSummary ()
760 lldb::SBTypeSummary summary;
762 lldb::ValueObjectSP value_sp(GetSP(locker));
765 if (value_sp->UpdateValueIfNeeded(true))
767 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
769 summary.SetSP(summary_sp);
776 SBValue::GetTypeFilter ()
778 lldb::SBTypeFilter filter;
780 lldb::ValueObjectSP value_sp(GetSP(locker));
783 if (value_sp->UpdateValueIfNeeded(true))
785 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
787 if (synthetic_sp && !synthetic_sp->IsScripted())
789 TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
790 filter.SetSP(filter_sp);
797 #ifndef LLDB_DISABLE_PYTHON
798 lldb::SBTypeSynthetic
799 SBValue::GetTypeSynthetic ()
801 lldb::SBTypeSynthetic synthetic;
803 lldb::ValueObjectSP value_sp(GetSP(locker));
806 if (value_sp->UpdateValueIfNeeded(true))
808 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
810 if (children_sp && children_sp->IsScripted())
812 ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
813 synthetic.SetSP(synth_sp);
822 SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
824 lldb::SBValue sb_value;
826 lldb::ValueObjectSP value_sp(GetSP(locker));
827 lldb::ValueObjectSP new_value_sp;
830 TypeImplSP type_sp (type.GetSP());
833 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetCompilerType(false), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name);
836 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
840 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"",
841 static_cast<void*>(value_sp.get()),
842 new_value_sp->GetName().AsCString());
844 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL",
845 static_cast<void*>(value_sp.get()));
851 SBValue::Cast (SBType type)
853 lldb::SBValue sb_value;
855 lldb::ValueObjectSP value_sp(GetSP(locker));
856 TypeImplSP type_sp (type.GetSP());
857 if (value_sp && type_sp)
858 sb_value.SetSP(value_sp->Cast(type_sp->GetCompilerType(false)),GetPreferDynamicValue(),GetPreferSyntheticValue());
863 SBValue::CreateValueFromExpression (const char *name, const char* expression)
865 SBExpressionOptions options;
866 options.ref().SetKeepInMemory(true);
867 return CreateValueFromExpression (name, expression, options);
871 SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options)
873 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
874 lldb::SBValue sb_value;
876 lldb::ValueObjectSP value_sp(GetSP(locker));
877 lldb::ValueObjectSP new_value_sp;
880 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
881 new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx, options.ref());
883 new_value_sp->SetName(ConstString(name));
885 sb_value.SetSP(new_value_sp);
889 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
890 static_cast<void*>(value_sp.get()), name, expression,
891 static_cast<void*>(new_value_sp.get()));
893 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
894 static_cast<void*>(value_sp.get()), name, expression);
900 SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
902 lldb::SBValue sb_value;
904 lldb::ValueObjectSP value_sp(GetSP(locker));
905 lldb::ValueObjectSP new_value_sp;
906 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
907 if (value_sp && type_impl_sp)
909 CompilerType ast_type(type_impl_sp->GetCompilerType(true));
910 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
911 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, ast_type);
913 sb_value.SetSP(new_value_sp);
914 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
918 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"",
919 static_cast<void*>(value_sp.get()),
920 new_value_sp->GetName().AsCString());
922 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL",
923 static_cast<void*>(value_sp.get()));
929 SBValue::CreateValueFromData (const char* name, SBData data, SBType sb_type)
931 lldb::SBValue sb_value;
932 lldb::ValueObjectSP new_value_sp;
934 lldb::ValueObjectSP value_sp(GetSP(locker));
935 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
936 if (value_sp && type_impl_sp)
938 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
939 new_value_sp = ValueObject::CreateValueObjectFromData(name, **data, exe_ctx, type_impl_sp->GetCompilerType(true));
940 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
942 sb_value.SetSP(new_value_sp);
943 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
947 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"",
948 static_cast<void*>(value_sp.get()),
949 new_value_sp->GetName().AsCString());
951 log->Printf ("SBValue(%p)::CreateValueFromData => NULL",
952 static_cast<void*>(value_sp.get()));
958 SBValue::GetChildAtIndex (uint32_t idx)
960 const bool can_create_synthetic = false;
961 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
964 target_sp = m_opaque_sp->GetTargetSP();
967 use_dynamic = target_sp->GetPreferDynamicValue();
969 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
973 SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
975 lldb::ValueObjectSP child_sp;
976 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
979 lldb::ValueObjectSP value_sp(GetSP(locker));
982 const bool can_create = true;
983 child_sp = value_sp->GetChildAtIndex (idx, can_create);
984 if (can_create_synthetic && !child_sp)
986 child_sp = value_sp->GetSyntheticArrayMember(idx, can_create);
991 sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
993 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)",
994 static_cast<void*>(value_sp.get()), idx,
995 static_cast<void*>(value_sp.get()));
1001 SBValue::GetIndexOfChildWithName (const char *name)
1003 uint32_t idx = UINT32_MAX;
1005 lldb::ValueObjectSP value_sp(GetSP(locker));
1008 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
1010 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1013 if (idx == UINT32_MAX)
1014 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND",
1015 static_cast<void*>(value_sp.get()), name);
1017 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u",
1018 static_cast<void*>(value_sp.get()), name, idx);
1024 SBValue::GetChildMemberWithName (const char *name)
1026 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
1029 target_sp = m_opaque_sp->GetTargetSP();
1032 use_dynamic_value = target_sp->GetPreferDynamicValue();
1033 return GetChildMemberWithName (name, use_dynamic_value);
1037 SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
1039 lldb::ValueObjectSP child_sp;
1040 const ConstString str_name (name);
1042 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1045 lldb::ValueObjectSP value_sp(GetSP(locker));
1048 child_sp = value_sp->GetChildMemberWithName (str_name, true);
1052 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
1055 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)",
1056 static_cast<void*>(value_sp.get()), name,
1057 static_cast<void*>(value_sp.get()));
1063 SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
1068 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
1069 value_sb.SetSP(proxy_sp);
1075 SBValue::GetStaticValue ()
1080 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic()));
1081 value_sb.SetSP(proxy_sp);
1087 SBValue::GetNonSyntheticValue ()
1092 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
1093 value_sb.SetSP(proxy_sp);
1098 lldb::DynamicValueType
1099 SBValue::GetPreferDynamicValue ()
1102 return eNoDynamicValues;
1103 return m_opaque_sp->GetUseDynamic();
1107 SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
1110 return m_opaque_sp->SetUseDynamic (use_dynamic);
1114 SBValue::GetPreferSyntheticValue ()
1118 return m_opaque_sp->GetUseSynthetic();
1122 SBValue::SetPreferSyntheticValue (bool use_synthetic)
1125 return m_opaque_sp->SetUseSynthetic (use_synthetic);
1129 SBValue::IsDynamic()
1132 lldb::ValueObjectSP value_sp(GetSP(locker));
1134 return value_sp->IsDynamic();
1139 SBValue::IsSynthetic ()
1142 lldb::ValueObjectSP value_sp(GetSP(locker));
1144 return value_sp->IsSynthetic();
1149 SBValue::IsSyntheticChildrenGenerated ()
1152 lldb::ValueObjectSP value_sp(GetSP(locker));
1154 return value_sp->IsSyntheticChildrenGenerated();
1159 SBValue::SetSyntheticChildrenGenerated (bool is)
1162 lldb::ValueObjectSP value_sp(GetSP(locker));
1164 return value_sp->SetSyntheticChildrenGenerated(is);
1168 SBValue::GetValueForExpressionPath(const char* expr_path)
1170 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1171 lldb::ValueObjectSP child_sp;
1173 lldb::ValueObjectSP value_sp(GetSP(locker));
1176 // using default values for all the fancy options, just do it if you can
1177 child_sp = value_sp->GetValueForExpressionPath(expr_path);
1181 sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
1184 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)",
1185 static_cast<void*>(value_sp.get()), expr_path,
1186 static_cast<void*>(value_sp.get()));
1192 SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1196 lldb::ValueObjectSP value_sp(GetSP(locker));
1199 bool success = true;
1200 uint64_t ret_val = fail_value;
1201 ret_val = value_sp->GetValueAsSigned(fail_value, &success);
1203 error.SetErrorString("could not resolve value");
1207 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1213 SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1217 lldb::ValueObjectSP value_sp(GetSP(locker));
1220 bool success = true;
1221 uint64_t ret_val = fail_value;
1222 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
1224 error.SetErrorString("could not resolve value");
1228 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1234 SBValue::GetValueAsSigned(int64_t fail_value)
1237 lldb::ValueObjectSP value_sp(GetSP(locker));
1240 return value_sp->GetValueAsSigned(fail_value);
1246 SBValue::GetValueAsUnsigned(uint64_t fail_value)
1249 lldb::ValueObjectSP value_sp(GetSP(locker));
1252 return value_sp->GetValueAsUnsigned(fail_value);
1258 SBValue::MightHaveChildren ()
1260 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1261 bool has_children = false;
1263 lldb::ValueObjectSP value_sp(GetSP(locker));
1265 has_children = value_sp->MightHaveChildren();
1268 log->Printf ("SBValue(%p)::MightHaveChildren() => %i",
1269 static_cast<void*>(value_sp.get()), has_children);
1270 return has_children;
1274 SBValue::IsRuntimeSupportValue ()
1276 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1277 bool is_support = false;
1279 lldb::ValueObjectSP value_sp(GetSP(locker));
1281 is_support = value_sp->IsRuntimeSupportValue();
1284 log->Printf ("SBValue(%p)::IsRuntimeSupportValue() => %i",
1285 static_cast<void*>(value_sp.get()), is_support);
1290 SBValue::GetNumChildren ()
1292 return GetNumChildren (UINT32_MAX);
1296 SBValue::GetNumChildren (uint32_t max)
1298 uint32_t num_children = 0;
1300 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1302 lldb::ValueObjectSP value_sp(GetSP(locker));
1304 num_children = value_sp->GetNumChildren(max);
1307 log->Printf ("SBValue(%p)::GetNumChildren (%u) => %u",
1308 static_cast<void*>(value_sp.get()), max, num_children);
1310 return num_children;
1314 SBValue::Dereference ()
1318 lldb::ValueObjectSP value_sp(GetSP(locker));
1322 sb_value = value_sp->Dereference (error);
1324 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1326 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)",
1327 static_cast<void*>(value_sp.get()),
1328 static_cast<void*>(value_sp.get()));
1333 // Deprecated - please use GetType().IsPointerType() instead.
1335 SBValue::TypeIsPointerType ()
1337 return GetType().IsPointerType();
1341 SBValue::GetOpaqueType()
1344 lldb::ValueObjectSP value_sp(GetSP(locker));
1346 return value_sp->GetCompilerType().GetOpaqueQualType();
1351 SBValue::GetTarget()
1357 target_sp = m_opaque_sp->GetTargetSP();
1358 sb_target.SetSP (target_sp);
1360 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1363 if (target_sp.get() == NULL)
1364 log->Printf ("SBValue(%p)::GetTarget () => NULL",
1365 static_cast<void*>(m_opaque_sp.get()));
1367 log->Printf ("SBValue(%p)::GetTarget () => %p",
1368 static_cast<void*>(m_opaque_sp.get()),
1369 static_cast<void*>(target_sp.get()));
1375 SBValue::GetProcess()
1377 SBProcess sb_process;
1378 ProcessSP process_sp;
1381 process_sp = m_opaque_sp->GetProcessSP();
1382 sb_process.SetSP (process_sp);
1384 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1387 if (process_sp.get() == NULL)
1388 log->Printf ("SBValue(%p)::GetProcess () => NULL",
1389 static_cast<void*>(m_opaque_sp.get()));
1391 log->Printf ("SBValue(%p)::GetProcess () => %p",
1392 static_cast<void*>(m_opaque_sp.get()),
1393 static_cast<void*>(process_sp.get()));
1399 SBValue::GetThread()
1405 thread_sp = m_opaque_sp->GetThreadSP();
1406 sb_thread.SetThread(thread_sp);
1408 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1411 if (thread_sp.get() == NULL)
1412 log->Printf ("SBValue(%p)::GetThread () => NULL",
1413 static_cast<void*>(m_opaque_sp.get()));
1415 log->Printf ("SBValue(%p)::GetThread () => %p",
1416 static_cast<void*>(m_opaque_sp.get()),
1417 static_cast<void*>(thread_sp.get()));
1426 StackFrameSP frame_sp;
1429 frame_sp = m_opaque_sp->GetFrameSP();
1430 sb_frame.SetFrameSP (frame_sp);
1432 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1435 if (frame_sp.get() == NULL)
1436 log->Printf ("SBValue(%p)::GetFrame () => NULL",
1437 static_cast<void*>(m_opaque_sp.get()));
1439 log->Printf ("SBValue(%p)::GetFrame () => %p",
1440 static_cast<void*>(m_opaque_sp.get()),
1441 static_cast<void*>(frame_sp.get()));
1448 SBValue::GetSP (ValueLocker &locker) const
1450 if (!m_opaque_sp || !m_opaque_sp->IsValid())
1452 locker.GetError().SetErrorString("No value");
1453 return ValueObjectSP();
1455 return locker.GetLockedSP(*m_opaque_sp.get());
1459 SBValue::GetSP () const
1462 return GetSP(locker);
1466 SBValue::SetSP (ValueImplSP impl_sp)
1468 m_opaque_sp = impl_sp;
1472 SBValue::SetSP (const lldb::ValueObjectSP &sp)
1476 lldb::TargetSP target_sp(sp->GetTargetSP());
1479 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1480 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1481 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1484 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
1487 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
1491 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
1495 lldb::TargetSP target_sp(sp->GetTargetSP());
1498 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1499 SetSP (sp, use_dynamic, use_synthetic);
1502 SetSP (sp, use_dynamic, true);
1505 SetSP (sp, use_dynamic, false);
1509 SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
1513 lldb::TargetSP target_sp(sp->GetTargetSP());
1516 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1517 SetSP (sp, use_dynamic, use_synthetic);
1520 SetSP (sp, eNoDynamicValues, use_synthetic);
1523 SetSP (sp, eNoDynamicValues, use_synthetic);
1527 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
1529 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
1533 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
1535 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
1539 SBValue::GetExpressionPath (SBStream &description)
1542 lldb::ValueObjectSP value_sp(GetSP(locker));
1545 value_sp->GetExpressionPath (description.ref(), false);
1552 SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1555 lldb::ValueObjectSP value_sp(GetSP(locker));
1558 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
1565 SBValue::GetDescription (SBStream &description)
1567 Stream &strm = description.ref();
1570 lldb::ValueObjectSP value_sp(GetSP(locker));
1572 value_sp->Dump(strm);
1574 strm.PutCString ("No value");
1580 SBValue::GetFormat ()
1583 lldb::ValueObjectSP value_sp(GetSP(locker));
1585 return value_sp->GetFormat();
1586 return eFormatDefault;
1590 SBValue::SetFormat (lldb::Format format)
1593 lldb::ValueObjectSP value_sp(GetSP(locker));
1595 value_sp->SetFormat(format);
1599 SBValue::AddressOf()
1603 lldb::ValueObjectSP value_sp(GetSP(locker));
1607 sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
1609 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1611 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)",
1612 static_cast<void*>(value_sp.get()),
1613 static_cast<void*>(value_sp.get()));
1619 SBValue::GetLoadAddress()
1621 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1623 lldb::ValueObjectSP value_sp(GetSP(locker));
1626 TargetSP target_sp (value_sp->GetTargetSP());
1629 const bool scalar_is_load_address = true;
1630 AddressType addr_type;
1631 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1632 if (addr_type == eAddressTypeFile)
1634 ModuleSP module_sp (value_sp->GetModule());
1636 value = LLDB_INVALID_ADDRESS;
1640 module_sp->ResolveFileAddress(value, addr);
1641 value = addr.GetLoadAddress(target_sp.get());
1644 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1645 value = LLDB_INVALID_ADDRESS;
1648 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1650 log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")",
1651 static_cast<void*>(value_sp.get()), value);
1657 SBValue::GetAddress()
1661 lldb::ValueObjectSP value_sp(GetSP(locker));
1664 TargetSP target_sp (value_sp->GetTargetSP());
1667 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1668 const bool scalar_is_load_address = true;
1669 AddressType addr_type;
1670 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1671 if (addr_type == eAddressTypeFile)
1673 ModuleSP module_sp (value_sp->GetModule());
1675 module_sp->ResolveFileAddress(value, addr);
1677 else if (addr_type == eAddressTypeLoad)
1679 // no need to check the return value on this.. if it can actually do the resolve
1680 // addr will be in the form (section,offset), otherwise it will simply be returned
1682 addr.SetLoadAddress(value, target_sp.get());
1686 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1688 log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")",
1689 static_cast<void*>(value_sp.get()),
1691 ? addr.GetSection()->GetName().GetCString()
1694 return SBAddress(new Address(addr));
1698 SBValue::GetPointeeData (uint32_t item_idx,
1699 uint32_t item_count)
1701 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1702 lldb::SBData sb_data;
1704 lldb::ValueObjectSP value_sp(GetSP(locker));
1707 TargetSP target_sp (value_sp->GetTargetSP());
1710 DataExtractorSP data_sp(new DataExtractor());
1711 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1712 if (data_sp->GetByteSize() > 0)
1717 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
1718 static_cast<void*>(value_sp.get()), item_idx, item_count,
1719 static_cast<void*>(sb_data.get()));
1727 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1728 lldb::SBData sb_data;
1730 lldb::ValueObjectSP value_sp(GetSP(locker));
1733 DataExtractorSP data_sp(new DataExtractor());
1735 value_sp->GetData(*data_sp, error);
1736 if (error.Success())
1740 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
1741 static_cast<void*>(value_sp.get()),
1742 static_cast<void*>(sb_data.get()));
1748 SBValue::SetData (lldb::SBData &data, SBError &error)
1750 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1752 lldb::ValueObjectSP value_sp(GetSP(locker));
1757 DataExtractor *data_extractor = data.get();
1759 if (!data_extractor)
1762 log->Printf ("SBValue(%p)::SetData() => error: no data to set",
1763 static_cast<void*>(value_sp.get()));
1765 error.SetErrorString("No data to set");
1772 value_sp->SetData(*data_extractor, set_error);
1774 if (!set_error.Success())
1776 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
1783 error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
1788 log->Printf ("SBValue(%p)::SetData (%p) => %s",
1789 static_cast<void*>(value_sp.get()),
1790 static_cast<void*>(data.get()), ret ? "true" : "false");
1795 SBValue::GetDeclaration ()
1798 lldb::ValueObjectSP value_sp(GetSP(locker));
1799 SBDeclaration decl_sb;
1803 if (value_sp->GetDeclaration(decl))
1804 decl_sb.SetDeclaration(decl);
1810 SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
1812 SBWatchpoint sb_watchpoint;
1814 // If the SBValue is not valid, there's no point in even trying to watch it.
1816 lldb::ValueObjectSP value_sp(GetSP(locker));
1817 TargetSP target_sp (GetTarget().GetSP());
1818 if (value_sp && target_sp)
1820 // Read and Write cannot both be false.
1821 if (!read && !write)
1822 return sb_watchpoint;
1824 // If the value is not in scope, don't try and watch and invalid value
1826 return sb_watchpoint;
1828 addr_t addr = GetLoadAddress();
1829 if (addr == LLDB_INVALID_ADDRESS)
1830 return sb_watchpoint;
1831 size_t byte_size = GetByteSize();
1833 return sb_watchpoint;
1835 uint32_t watch_type = 0;
1837 watch_type |= LLDB_WATCH_TYPE_READ;
1839 watch_type |= LLDB_WATCH_TYPE_WRITE;
1842 CompilerType type (value_sp->GetCompilerType());
1843 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
1848 sb_watchpoint.SetSP (watchpoint_sp);
1850 if (value_sp->GetDeclaration (decl))
1855 // True to show fullpath for declaration file.
1856 decl.DumpStopContext(&ss, true);
1857 watchpoint_sp->SetDeclInfo(ss.GetString());
1864 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1866 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s",
1867 static_cast<void*>(value_sp.get()),
1868 locker.GetError().AsCString());
1870 error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
1874 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1876 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target",
1877 static_cast<void*>(value_sp.get()));
1878 error.SetErrorString("could not set watchpoint, a target is required");
1881 return sb_watchpoint;
1884 // FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1885 // Backward compatibility fix in the interim.
1887 SBValue::Watch (bool resolve_location, bool read, bool write)
1890 return Watch(resolve_location, read, write, error);
1894 SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
1896 SBWatchpoint sb_watchpoint;
1897 if (IsInScope() && GetType().IsPointerType())
1898 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
1899 return sb_watchpoint;
1906 lldb::ValueObjectSP value_sp(GetSP(locker));
1907 SBValue persisted_sb;
1910 persisted_sb.SetSP(value_sp->Persist());
1912 return persisted_sb;