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/lldb-python.h"
12 #include "lldb/API/SBValue.h"
14 #include "lldb/API/SBDeclaration.h"
15 #include "lldb/API/SBStream.h"
16 #include "lldb/API/SBTypeFilter.h"
17 #include "lldb/API/SBTypeFormat.h"
18 #include "lldb/API/SBTypeSummary.h"
19 #include "lldb/API/SBTypeSynthetic.h"
21 #include "lldb/Breakpoint/Watchpoint.h"
22 #include "lldb/Core/DataExtractor.h"
23 #include "lldb/Core/Log.h"
24 #include "lldb/Core/Module.h"
25 #include "lldb/Core/Scalar.h"
26 #include "lldb/Core/Section.h"
27 #include "lldb/Core/Stream.h"
28 #include "lldb/Core/StreamFile.h"
29 #include "lldb/Core/Value.h"
30 #include "lldb/Core/ValueObject.h"
31 #include "lldb/Core/ValueObjectConstResult.h"
32 #include "lldb/DataFormatters/DataVisualization.h"
33 #include "lldb/Symbol/Block.h"
34 #include "lldb/Symbol/Declaration.h"
35 #include "lldb/Symbol/ObjectFile.h"
36 #include "lldb/Symbol/Type.h"
37 #include "lldb/Symbol/Variable.h"
38 #include "lldb/Symbol/VariableList.h"
39 #include "lldb/Target/ExecutionContext.h"
40 #include "lldb/Target/Process.h"
41 #include "lldb/Target/StackFrame.h"
42 #include "lldb/Target/Target.h"
43 #include "lldb/Target/Thread.h"
45 #include "lldb/API/SBDebugger.h"
46 #include "lldb/API/SBExpressionOptions.h"
47 #include "lldb/API/SBFrame.h"
48 #include "lldb/API/SBProcess.h"
49 #include "lldb/API/SBTarget.h"
50 #include "lldb/API/SBThread.h"
53 using namespace lldb_private;
62 ValueImpl (lldb::ValueObjectSP in_valobj_sp,
63 lldb::DynamicValueType use_dynamic,
65 const char *name = NULL) :
66 m_valobj_sp(in_valobj_sp),
67 m_use_dynamic(use_dynamic),
68 m_use_synthetic(use_synthetic),
71 if (!m_name.IsEmpty() && m_valobj_sp)
72 m_valobj_sp->SetName(m_name);
75 ValueImpl (const ValueImpl& rhs) :
76 m_valobj_sp(rhs.m_valobj_sp),
77 m_use_dynamic(rhs.m_use_dynamic),
78 m_use_synthetic(rhs.m_use_synthetic),
84 operator = (const ValueImpl &rhs)
88 m_valobj_sp = rhs.m_valobj_sp;
89 m_use_dynamic = rhs.m_use_dynamic;
90 m_use_synthetic = rhs.m_use_synthetic;
99 return m_valobj_sp.get() != NULL;
109 GetSP (Process::StopLocker &stop_locker, Mutex::Locker &api_locker, Error &error)
111 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
114 error.SetErrorString("invalid value object");
118 lldb::ValueObjectSP value_sp = m_valobj_sp;
120 Target *target = value_sp->GetTargetSP().get();
122 api_locker.Lock(target->GetAPIMutex());
124 ProcessSP process_sp(value_sp->GetProcessSP());
125 if (process_sp && !stop_locker.TryLock (&process_sp->GetRunLock()))
127 // We don't allow people to play around with ValueObject if the process is running.
128 // If you want to look at values, pause the process, then look.
130 log->Printf ("SBValue(%p)::GetSP() => error: process is running", value_sp.get());
131 error.SetErrorString ("process must be stopped.");
132 return ValueObjectSP();
135 if (value_sp->GetDynamicValue(m_use_dynamic))
136 value_sp = value_sp->GetDynamicValue(m_use_dynamic);
137 if (value_sp->GetSyntheticValue(m_use_synthetic))
138 value_sp = value_sp->GetSyntheticValue(m_use_synthetic);
140 error.SetErrorString("invalid value object");
141 if (!m_name.IsEmpty())
142 value_sp->SetName(m_name);
148 SetUseDynamic (lldb::DynamicValueType use_dynamic)
150 m_use_dynamic = use_dynamic;
154 SetUseSynthetic (bool use_synthetic)
156 m_use_synthetic = use_synthetic;
159 lldb::DynamicValueType
162 return m_use_dynamic;
168 return m_use_synthetic;
171 // All the derived values that we would make from the m_valobj_sp will share
172 // the ExecutionContext with m_valobj_sp, so we don't need to do the calculations
173 // in GetSP to return the Target, Process, Thread or Frame. It is convenient to
174 // provide simple accessors for these, which I do here.
179 return m_valobj_sp->GetTargetSP();
188 return m_valobj_sp->GetProcessSP();
197 return m_valobj_sp->GetThreadSP();
206 return m_valobj_sp->GetFrameSP();
208 return StackFrameSP();
212 lldb::ValueObjectSP m_valobj_sp;
213 lldb::DynamicValueType m_use_dynamic;
214 bool m_use_synthetic;
226 GetLockedSP(ValueImpl &in_value)
228 return in_value.GetSP(m_stop_locker, m_api_locker, m_lock_error);
238 Process::StopLocker m_stop_locker;
239 Mutex::Locker m_api_locker;
244 SBValue::SBValue () :
249 SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
254 SBValue::SBValue(const SBValue &rhs)
256 SetSP(rhs.m_opaque_sp);
260 SBValue::operator = (const SBValue &rhs)
264 SetSP(rhs.m_opaque_sp);
276 // If this function ever changes to anything that does more than just
277 // check if the opaque shared pointer is non NULL, then we need to update
278 // all "if (m_opaque_sp)" code in this file.
279 return m_opaque_sp.get() != NULL && m_opaque_sp->GetRootSP().get() != NULL;
294 lldb::ValueObjectSP value_sp(GetSP(locker));
296 sb_error.SetError(value_sp->GetError());
298 sb_error.SetErrorStringWithFormat ("error: %s", locker.GetError().AsCString());
307 lldb::ValueObjectSP value_sp(GetSP(locker));
309 return value_sp->GetID();
310 return LLDB_INVALID_UID;
316 const char *name = NULL;
318 lldb::ValueObjectSP value_sp(GetSP(locker));
320 name = value_sp->GetName().GetCString();
322 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
326 log->Printf ("SBValue(%p)::GetName () => \"%s\"", value_sp.get(), name);
328 log->Printf ("SBValue(%p)::GetName () => NULL", value_sp.get());
335 SBValue::GetTypeName ()
337 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
338 const char *name = NULL;
340 lldb::ValueObjectSP value_sp(GetSP(locker));
343 name = value_sp->GetQualifiedTypeName().GetCString();
349 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name);
351 log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get());
358 SBValue::GetByteSize ()
360 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
364 lldb::ValueObjectSP value_sp(GetSP(locker));
367 result = value_sp->GetByteSize();
371 log->Printf ("SBValue(%p)::GetByteSize () => %" PRIu64, value_sp.get(), (uint64_t)result);
377 SBValue::IsInScope ()
382 lldb::ValueObjectSP value_sp(GetSP(locker));
385 result = value_sp->IsInScope ();
388 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
390 log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result);
398 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
400 const char *cstr = NULL;
402 lldb::ValueObjectSP value_sp(GetSP(locker));
405 cstr = value_sp->GetValueAsCString ();
410 log->Printf ("SBValue(%p)::GetValue() => \"%s\"", value_sp.get(), cstr);
412 log->Printf ("SBValue(%p)::GetValue() => NULL", value_sp.get());
419 SBValue::GetValueType ()
421 ValueType result = eValueTypeInvalid;
423 lldb::ValueObjectSP value_sp(GetSP(locker));
425 result = value_sp->GetValueType();
427 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
432 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break;
433 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break;
434 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break;
435 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break;
436 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break;
437 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break;
438 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break;
439 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break;
446 SBValue::GetObjectDescription ()
448 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
449 const char *cstr = NULL;
451 lldb::ValueObjectSP value_sp(GetSP(locker));
454 cstr = value_sp->GetObjectDescription ();
459 log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"", value_sp.get(), cstr);
461 log->Printf ("SBValue(%p)::GetObjectDescription() => NULL", value_sp.get());
469 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
472 lldb::ValueObjectSP value_sp(GetSP(locker));
476 type_sp.reset (new TypeImpl(value_sp->GetClangType()));
477 sb_type.SetSP(type_sp);
482 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get());
484 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get());
490 SBValue::GetValueDidChange ()
492 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
495 lldb::ValueObjectSP value_sp(GetSP(locker));
498 result = value_sp->GetValueDidChange ();
501 log->Printf ("SBValue(%p)::GetValueDidChange() => %i", value_sp.get(), result);
506 #ifndef LLDB_DISABLE_PYTHON
508 SBValue::GetSummary ()
510 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
511 const char *cstr = NULL;
513 lldb::ValueObjectSP value_sp(GetSP(locker));
516 cstr = value_sp->GetSummaryAsCString();
521 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"", value_sp.get(), cstr);
523 log->Printf ("SBValue(%p)::GetSummary() => NULL", value_sp.get());
527 #endif // LLDB_DISABLE_PYTHON
530 SBValue::GetLocation ()
532 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
533 const char *cstr = NULL;
535 lldb::ValueObjectSP value_sp(GetSP(locker));
538 cstr = value_sp->GetLocationAsCString();
543 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"", value_sp.get(), cstr);
545 log->Printf ("SBValue(%p)::GetLocation() => NULL", value_sp.get());
550 // Deprecated - use the one that takes an lldb::SBError
552 SBValue::SetValueFromCString (const char *value_str)
555 return SetValueFromCString(value_str,dummy);
559 SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
561 bool success = false;
563 lldb::ValueObjectSP value_sp(GetSP(locker));
564 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
567 success = value_sp->SetValueFromCString (value_str,error.ref());
570 error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString());
573 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i", value_sp.get(), value_str, success);
579 SBValue::GetTypeFormat ()
581 lldb::SBTypeFormat format;
583 lldb::ValueObjectSP value_sp(GetSP(locker));
586 if (value_sp->UpdateValueIfNeeded(true))
588 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
590 format.SetSP(format_sp);
596 #ifndef LLDB_DISABLE_PYTHON
598 SBValue::GetTypeSummary ()
600 lldb::SBTypeSummary summary;
602 lldb::ValueObjectSP value_sp(GetSP(locker));
605 if (value_sp->UpdateValueIfNeeded(true))
607 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
609 summary.SetSP(summary_sp);
614 #endif // LLDB_DISABLE_PYTHON
617 SBValue::GetTypeFilter ()
619 lldb::SBTypeFilter filter;
621 lldb::ValueObjectSP value_sp(GetSP(locker));
624 if (value_sp->UpdateValueIfNeeded(true))
626 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
628 if (synthetic_sp && !synthetic_sp->IsScripted())
630 TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
631 filter.SetSP(filter_sp);
638 #ifndef LLDB_DISABLE_PYTHON
639 lldb::SBTypeSynthetic
640 SBValue::GetTypeSynthetic ()
642 lldb::SBTypeSynthetic synthetic;
644 lldb::ValueObjectSP value_sp(GetSP(locker));
647 if (value_sp->UpdateValueIfNeeded(true))
649 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
651 if (children_sp && children_sp->IsScripted())
653 ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
654 synthetic.SetSP(synth_sp);
663 SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
665 lldb::SBValue sb_value;
667 lldb::ValueObjectSP value_sp(GetSP(locker));
668 lldb::ValueObjectSP new_value_sp;
671 TypeImplSP type_sp (type.GetSP());
674 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name);
677 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
681 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"",
683 new_value_sp->GetName().AsCString());
685 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL",
692 SBValue::Cast (SBType type)
694 lldb::SBValue sb_value;
696 lldb::ValueObjectSP value_sp(GetSP(locker));
697 TypeImplSP type_sp (type.GetSP());
698 if (value_sp && type_sp)
699 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()),GetPreferDynamicValue(),GetPreferSyntheticValue());
704 SBValue::CreateValueFromExpression (const char *name, const char* expression)
706 SBExpressionOptions options;
707 options.ref().SetKeepInMemory(true);
708 return CreateValueFromExpression (name, expression, options);
712 SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options)
714 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
715 lldb::SBValue sb_value;
717 lldb::ValueObjectSP value_sp(GetSP(locker));
718 lldb::ValueObjectSP new_value_sp;
721 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
722 Target* target = exe_ctx.GetTargetPtr();
725 options.ref().SetKeepInMemory(true);
726 target->EvaluateExpression (expression,
727 exe_ctx.GetFramePtr(),
732 new_value_sp->SetName(ConstString(name));
733 sb_value.SetSP(new_value_sp);
740 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
746 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
755 SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
757 lldb::SBValue sb_value;
759 lldb::ValueObjectSP value_sp(GetSP(locker));
760 lldb::ValueObjectSP new_value_sp;
761 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
762 if (value_sp && type_impl_sp)
764 ClangASTType pointee_ast_type(type_impl_sp->GetClangASTType().GetPointerType ());
765 if (pointee_ast_type)
767 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
769 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
770 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
774 lldb::endian::InlHostByteOrder(),
775 exe_ctx.GetAddressByteSize()));
777 if (ptr_result_valobj_sp)
779 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
781 new_value_sp = ptr_result_valobj_sp->Dereference(err);
783 new_value_sp->SetName(ConstString(name));
785 sb_value.SetSP(new_value_sp);
788 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
792 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
794 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
800 SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
802 lldb::SBValue sb_value;
803 lldb::ValueObjectSP new_value_sp;
805 lldb::ValueObjectSP value_sp(GetSP(locker));
808 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
810 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
811 type.m_opaque_sp->GetClangASTType(),
814 LLDB_INVALID_ADDRESS);
815 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
816 sb_value.SetSP(new_value_sp);
818 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
822 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
824 log->Printf ("SBValue(%p)::CreateValueFromData => NULL", value_sp.get());
830 SBValue::GetChildAtIndex (uint32_t idx)
832 const bool can_create_synthetic = false;
833 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
836 target_sp = m_opaque_sp->GetTargetSP();
839 use_dynamic = target_sp->GetPreferDynamicValue();
841 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
845 SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
847 lldb::ValueObjectSP child_sp;
848 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
851 lldb::ValueObjectSP value_sp(GetSP(locker));
854 const bool can_create = true;
855 child_sp = value_sp->GetChildAtIndex (idx, can_create);
856 if (can_create_synthetic && !child_sp)
858 if (value_sp->IsPointerType())
860 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
862 else if (value_sp->IsArrayType())
864 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
870 sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
872 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
878 SBValue::GetIndexOfChildWithName (const char *name)
880 uint32_t idx = UINT32_MAX;
882 lldb::ValueObjectSP value_sp(GetSP(locker));
885 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
887 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
890 if (idx == UINT32_MAX)
891 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
893 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
899 SBValue::GetChildMemberWithName (const char *name)
901 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
904 target_sp = m_opaque_sp->GetTargetSP();
907 use_dynamic_value = target_sp->GetPreferDynamicValue();
908 return GetChildMemberWithName (name, use_dynamic_value);
912 SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
914 lldb::ValueObjectSP child_sp;
915 const ConstString str_name (name);
917 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
920 lldb::ValueObjectSP value_sp(GetSP(locker));
923 child_sp = value_sp->GetChildMemberWithName (str_name, true);
927 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
930 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
936 SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
941 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
942 value_sb.SetSP(proxy_sp);
948 SBValue::GetStaticValue ()
953 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic()));
954 value_sb.SetSP(proxy_sp);
960 SBValue::GetNonSyntheticValue ()
965 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
966 value_sb.SetSP(proxy_sp);
971 lldb::DynamicValueType
972 SBValue::GetPreferDynamicValue ()
975 return eNoDynamicValues;
976 return m_opaque_sp->GetUseDynamic();
980 SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
983 return m_opaque_sp->SetUseDynamic (use_dynamic);
987 SBValue::GetPreferSyntheticValue ()
991 return m_opaque_sp->GetUseSynthetic();
995 SBValue::SetPreferSyntheticValue (bool use_synthetic)
998 return m_opaque_sp->SetUseSynthetic (use_synthetic);
1002 SBValue::IsDynamic()
1005 lldb::ValueObjectSP value_sp(GetSP(locker));
1007 return value_sp->IsDynamic();
1012 SBValue::IsSynthetic ()
1015 lldb::ValueObjectSP value_sp(GetSP(locker));
1017 return value_sp->IsSynthetic();
1022 SBValue::GetValueForExpressionPath(const char* expr_path)
1024 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1025 lldb::ValueObjectSP child_sp;
1027 lldb::ValueObjectSP value_sp(GetSP(locker));
1030 // using default values for all the fancy options, just do it if you can
1031 child_sp = value_sp->GetValueForExpressionPath(expr_path);
1035 sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
1038 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", value_sp.get(), expr_path, value_sp.get());
1044 SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1048 lldb::ValueObjectSP value_sp(GetSP(locker));
1052 if (value_sp->ResolveValue (scalar))
1053 return scalar.SLongLong (fail_value);
1055 error.SetErrorString ("could not resolve value");
1058 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1064 SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1068 lldb::ValueObjectSP value_sp(GetSP(locker));
1072 if (value_sp->ResolveValue (scalar))
1073 return scalar.ULongLong(fail_value);
1075 error.SetErrorString("could not resolve value");
1078 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1084 SBValue::GetValueAsSigned(int64_t fail_value)
1087 lldb::ValueObjectSP value_sp(GetSP(locker));
1091 if (value_sp->ResolveValue (scalar))
1092 return scalar.SLongLong(fail_value);
1098 SBValue::GetValueAsUnsigned(uint64_t fail_value)
1101 lldb::ValueObjectSP value_sp(GetSP(locker));
1105 if (value_sp->ResolveValue (scalar))
1106 return scalar.ULongLong(fail_value);
1112 SBValue::MightHaveChildren ()
1114 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1115 bool has_children = false;
1117 lldb::ValueObjectSP value_sp(GetSP(locker));
1119 has_children = value_sp->MightHaveChildren();
1122 log->Printf ("SBValue(%p)::MightHaveChildren() => %i", value_sp.get(), has_children);
1123 return has_children;
1127 SBValue::GetNumChildren ()
1129 uint32_t num_children = 0;
1131 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1133 lldb::ValueObjectSP value_sp(GetSP(locker));
1135 num_children = value_sp->GetNumChildren();
1138 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
1140 return num_children;
1145 SBValue::Dereference ()
1149 lldb::ValueObjectSP value_sp(GetSP(locker));
1153 sb_value = value_sp->Dereference (error);
1155 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1157 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
1163 SBValue::TypeIsPointerType ()
1165 bool is_ptr_type = false;
1168 lldb::ValueObjectSP value_sp(GetSP(locker));
1170 is_ptr_type = value_sp->IsPointerType();
1172 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1174 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
1181 SBValue::GetOpaqueType()
1184 lldb::ValueObjectSP value_sp(GetSP(locker));
1186 return value_sp->GetClangType().GetOpaqueQualType();
1191 SBValue::GetTarget()
1197 target_sp = m_opaque_sp->GetTargetSP();
1198 sb_target.SetSP (target_sp);
1200 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1203 if (target_sp.get() == NULL)
1204 log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get());
1206 log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), target_sp.get());
1212 SBValue::GetProcess()
1214 SBProcess sb_process;
1215 ProcessSP process_sp;
1218 process_sp = m_opaque_sp->GetProcessSP();
1219 sb_process.SetSP (process_sp);
1221 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1224 if (process_sp.get() == NULL)
1225 log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get());
1227 log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), process_sp.get());
1233 SBValue::GetThread()
1239 thread_sp = m_opaque_sp->GetThreadSP();
1240 sb_thread.SetThread(thread_sp);
1242 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1245 if (thread_sp.get() == NULL)
1246 log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get());
1248 log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), thread_sp.get());
1257 StackFrameSP frame_sp;
1260 frame_sp = m_opaque_sp->GetFrameSP();
1261 sb_frame.SetFrameSP (frame_sp);
1263 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1266 if (frame_sp.get() == NULL)
1267 log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get());
1269 log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), frame_sp.get());
1276 SBValue::GetSP (ValueLocker &locker) const
1278 if (!m_opaque_sp || !m_opaque_sp->IsValid())
1279 return ValueObjectSP();
1280 return locker.GetLockedSP(*m_opaque_sp.get());
1284 SBValue::GetSP () const
1287 return GetSP(locker);
1291 SBValue::SetSP (ValueImplSP impl_sp)
1293 m_opaque_sp = impl_sp;
1297 SBValue::SetSP (const lldb::ValueObjectSP &sp)
1301 lldb::TargetSP target_sp(sp->GetTargetSP());
1304 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1305 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1306 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1309 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
1312 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
1316 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
1320 lldb::TargetSP target_sp(sp->GetTargetSP());
1323 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1324 SetSP (sp, use_dynamic, use_synthetic);
1327 SetSP (sp, use_dynamic, true);
1330 SetSP (sp, use_dynamic, false);
1334 SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
1338 lldb::TargetSP target_sp(sp->GetTargetSP());
1341 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1342 SetSP (sp, use_dynamic, use_synthetic);
1345 SetSP (sp, eNoDynamicValues, use_synthetic);
1348 SetSP (sp, eNoDynamicValues, use_synthetic);
1352 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
1354 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
1358 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
1360 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
1364 SBValue::GetExpressionPath (SBStream &description)
1367 lldb::ValueObjectSP value_sp(GetSP(locker));
1370 value_sp->GetExpressionPath (description.ref(), false);
1377 SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1380 lldb::ValueObjectSP value_sp(GetSP(locker));
1383 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
1390 SBValue::GetDescription (SBStream &description)
1392 Stream &strm = description.ref();
1395 lldb::ValueObjectSP value_sp(GetSP(locker));
1398 ValueObject::DumpValueObject (strm, value_sp.get());
1401 strm.PutCString ("No value");
1407 SBValue::GetFormat ()
1410 lldb::ValueObjectSP value_sp(GetSP(locker));
1412 return value_sp->GetFormat();
1413 return eFormatDefault;
1417 SBValue::SetFormat (lldb::Format format)
1420 lldb::ValueObjectSP value_sp(GetSP(locker));
1422 value_sp->SetFormat(format);
1426 SBValue::AddressOf()
1430 lldb::ValueObjectSP value_sp(GetSP(locker));
1434 sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
1436 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1438 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)", value_sp.get(), value_sp.get());
1444 SBValue::GetLoadAddress()
1446 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1448 lldb::ValueObjectSP value_sp(GetSP(locker));
1451 TargetSP target_sp (value_sp->GetTargetSP());
1454 const bool scalar_is_load_address = true;
1455 AddressType addr_type;
1456 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1457 if (addr_type == eAddressTypeFile)
1459 ModuleSP module_sp (value_sp->GetModule());
1461 value = LLDB_INVALID_ADDRESS;
1465 module_sp->ResolveFileAddress(value, addr);
1466 value = addr.GetLoadAddress(target_sp.get());
1469 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1470 value = LLDB_INVALID_ADDRESS;
1473 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1475 log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")", value_sp.get(), value);
1481 SBValue::GetAddress()
1485 lldb::ValueObjectSP value_sp(GetSP(locker));
1488 TargetSP target_sp (value_sp->GetTargetSP());
1491 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1492 const bool scalar_is_load_address = true;
1493 AddressType addr_type;
1494 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1495 if (addr_type == eAddressTypeFile)
1497 ModuleSP module_sp (value_sp->GetModule());
1499 module_sp->ResolveFileAddress(value, addr);
1501 else if (addr_type == eAddressTypeLoad)
1503 // no need to check the return value on this.. if it can actually do the resolve
1504 // addr will be in the form (section,offset), otherwise it will simply be returned
1506 addr.SetLoadAddress(value, target_sp.get());
1510 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1512 log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")", value_sp.get(),
1513 (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"),
1515 return SBAddress(new Address(addr));
1519 SBValue::GetPointeeData (uint32_t item_idx,
1520 uint32_t item_count)
1522 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1523 lldb::SBData sb_data;
1525 lldb::ValueObjectSP value_sp(GetSP(locker));
1528 TargetSP target_sp (value_sp->GetTargetSP());
1531 DataExtractorSP data_sp(new DataExtractor());
1532 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1533 if (data_sp->GetByteSize() > 0)
1538 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
1550 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1551 lldb::SBData sb_data;
1553 lldb::ValueObjectSP value_sp(GetSP(locker));
1556 DataExtractorSP data_sp(new DataExtractor());
1557 value_sp->GetData(*data_sp);
1558 if (data_sp->GetByteSize() > 0)
1562 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
1570 SBValue::SetData (lldb::SBData &data, SBError &error)
1572 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1574 lldb::ValueObjectSP value_sp(GetSP(locker));
1579 DataExtractor *data_extractor = data.get();
1581 if (!data_extractor)
1584 log->Printf ("SBValue(%p)::SetData() => error: no data to set", value_sp.get());
1586 error.SetErrorString("No data to set");
1593 value_sp->SetData(*data_extractor, set_error);
1595 if (!set_error.Success())
1597 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
1604 error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
1609 log->Printf ("SBValue(%p)::SetData (%p) => %s",
1612 ret ? "true" : "false");
1617 SBValue::GetDeclaration ()
1620 lldb::ValueObjectSP value_sp(GetSP(locker));
1621 SBDeclaration decl_sb;
1625 if (value_sp->GetDeclaration(decl))
1626 decl_sb.SetDeclaration(decl);
1632 SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
1634 SBWatchpoint sb_watchpoint;
1636 // If the SBValue is not valid, there's no point in even trying to watch it.
1638 lldb::ValueObjectSP value_sp(GetSP(locker));
1639 TargetSP target_sp (GetTarget().GetSP());
1640 if (value_sp && target_sp)
1642 // Read and Write cannot both be false.
1643 if (!read && !write)
1644 return sb_watchpoint;
1646 // If the value is not in scope, don't try and watch and invalid value
1648 return sb_watchpoint;
1650 addr_t addr = GetLoadAddress();
1651 if (addr == LLDB_INVALID_ADDRESS)
1652 return sb_watchpoint;
1653 size_t byte_size = GetByteSize();
1655 return sb_watchpoint;
1657 uint32_t watch_type = 0;
1659 watch_type |= LLDB_WATCH_TYPE_READ;
1661 watch_type |= LLDB_WATCH_TYPE_WRITE;
1664 ClangASTType type (value_sp->GetClangType());
1665 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
1670 sb_watchpoint.SetSP (watchpoint_sp);
1672 if (value_sp->GetDeclaration (decl))
1677 // True to show fullpath for declaration file.
1678 decl.DumpStopContext(&ss, true);
1679 watchpoint_sp->SetDeclInfo(ss.GetString());
1686 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1688 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s", value_sp.get(), locker.GetError().AsCString());
1690 error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
1694 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1696 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target", value_sp.get());
1697 error.SetErrorString("could not set watchpoint, a target is required");
1700 return sb_watchpoint;
1703 // FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1704 // Backward compatibility fix in the interim.
1706 SBValue::Watch (bool resolve_location, bool read, bool write)
1709 return Watch(resolve_location, read, write, error);
1713 SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
1715 SBWatchpoint sb_watchpoint;
1716 if (IsInScope() && GetType().IsPointerType())
1717 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
1718 return sb_watchpoint;