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 if (m_valobj_sp.get() == NULL)
103 // FIXME: This check is necessary but not sufficient. We for sure don't want to touch SBValues whose owning
104 // targets have gone away. This check is a little weak in that it enforces that restriction when you call
105 // IsValid, but since IsValid doesn't lock the target, you have no guarantee that the SBValue won't go
106 // invalid after you call this...
107 // Also, an SBValue could depend on data from one of the modules in the target, and those could go away
108 // independently of the target, for instance if a module is unloaded. But right now, neither SBValues
109 // nor ValueObjects know which modules they depend on. So I have no good way to make that check without
110 // tracking that in all the ValueObject subclasses.
111 TargetSP target_sp = m_valobj_sp->GetTargetSP();
112 if (target_sp && target_sp->IsValid())
126 GetSP (Process::StopLocker &stop_locker, Mutex::Locker &api_locker, Error &error)
128 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
131 error.SetErrorString("invalid value object");
135 lldb::ValueObjectSP value_sp = m_valobj_sp;
137 Target *target = value_sp->GetTargetSP().get();
139 api_locker.Lock(target->GetAPIMutex());
141 return ValueObjectSP();
143 ProcessSP process_sp(value_sp->GetProcessSP());
144 if (process_sp && !stop_locker.TryLock (&process_sp->GetRunLock()))
146 // We don't allow people to play around with ValueObject if the process is running.
147 // If you want to look at values, pause the process, then look.
149 log->Printf ("SBValue(%p)::GetSP() => error: process is running", value_sp.get());
150 error.SetErrorString ("process must be stopped.");
151 return ValueObjectSP();
154 if (value_sp->GetDynamicValue(m_use_dynamic))
155 value_sp = value_sp->GetDynamicValue(m_use_dynamic);
156 if (value_sp->GetSyntheticValue(m_use_synthetic))
157 value_sp = value_sp->GetSyntheticValue(m_use_synthetic);
159 error.SetErrorString("invalid value object");
160 if (!m_name.IsEmpty())
161 value_sp->SetName(m_name);
167 SetUseDynamic (lldb::DynamicValueType use_dynamic)
169 m_use_dynamic = use_dynamic;
173 SetUseSynthetic (bool use_synthetic)
175 m_use_synthetic = use_synthetic;
178 lldb::DynamicValueType
181 return m_use_dynamic;
187 return m_use_synthetic;
190 // All the derived values that we would make from the m_valobj_sp will share
191 // the ExecutionContext with m_valobj_sp, so we don't need to do the calculations
192 // in GetSP to return the Target, Process, Thread or Frame. It is convenient to
193 // provide simple accessors for these, which I do here.
198 return m_valobj_sp->GetTargetSP();
207 return m_valobj_sp->GetProcessSP();
216 return m_valobj_sp->GetThreadSP();
225 return m_valobj_sp->GetFrameSP();
227 return StackFrameSP();
231 lldb::ValueObjectSP m_valobj_sp;
232 lldb::DynamicValueType m_use_dynamic;
233 bool m_use_synthetic;
245 GetLockedSP(ValueImpl &in_value)
247 return in_value.GetSP(m_stop_locker, m_api_locker, m_lock_error);
257 Process::StopLocker m_stop_locker;
258 Mutex::Locker m_api_locker;
263 SBValue::SBValue () :
268 SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
273 SBValue::SBValue(const SBValue &rhs)
275 SetSP(rhs.m_opaque_sp);
279 SBValue::operator = (const SBValue &rhs)
283 SetSP(rhs.m_opaque_sp);
295 // If this function ever changes to anything that does more than just
296 // check if the opaque shared pointer is non NULL, then we need to update
297 // all "if (m_opaque_sp)" code in this file.
298 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid() && m_opaque_sp->GetRootSP().get() != NULL;
313 lldb::ValueObjectSP value_sp(GetSP(locker));
315 sb_error.SetError(value_sp->GetError());
317 sb_error.SetErrorStringWithFormat ("error: %s", locker.GetError().AsCString());
326 lldb::ValueObjectSP value_sp(GetSP(locker));
328 return value_sp->GetID();
329 return LLDB_INVALID_UID;
335 const char *name = NULL;
337 lldb::ValueObjectSP value_sp(GetSP(locker));
339 name = value_sp->GetName().GetCString();
341 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
345 log->Printf ("SBValue(%p)::GetName () => \"%s\"", value_sp.get(), name);
347 log->Printf ("SBValue(%p)::GetName () => NULL", value_sp.get());
354 SBValue::GetTypeName ()
356 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
357 const char *name = NULL;
359 lldb::ValueObjectSP value_sp(GetSP(locker));
362 name = value_sp->GetQualifiedTypeName().GetCString();
368 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name);
370 log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get());
377 SBValue::GetByteSize ()
379 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
383 lldb::ValueObjectSP value_sp(GetSP(locker));
386 result = value_sp->GetByteSize();
390 log->Printf ("SBValue(%p)::GetByteSize () => %" PRIu64, value_sp.get(), (uint64_t)result);
396 SBValue::IsInScope ()
401 lldb::ValueObjectSP value_sp(GetSP(locker));
404 result = value_sp->IsInScope ();
407 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
409 log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result);
417 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
419 const char *cstr = NULL;
421 lldb::ValueObjectSP value_sp(GetSP(locker));
424 cstr = value_sp->GetValueAsCString ();
429 log->Printf ("SBValue(%p)::GetValue() => \"%s\"", value_sp.get(), cstr);
431 log->Printf ("SBValue(%p)::GetValue() => NULL", value_sp.get());
438 SBValue::GetValueType ()
440 ValueType result = eValueTypeInvalid;
442 lldb::ValueObjectSP value_sp(GetSP(locker));
444 result = value_sp->GetValueType();
446 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
451 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break;
452 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break;
453 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break;
454 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break;
455 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break;
456 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break;
457 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break;
458 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break;
465 SBValue::GetObjectDescription ()
467 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
468 const char *cstr = NULL;
470 lldb::ValueObjectSP value_sp(GetSP(locker));
473 cstr = value_sp->GetObjectDescription ();
478 log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"", value_sp.get(), cstr);
480 log->Printf ("SBValue(%p)::GetObjectDescription() => NULL", value_sp.get());
488 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
491 lldb::ValueObjectSP value_sp(GetSP(locker));
495 type_sp.reset (new TypeImpl(value_sp->GetTypeImpl()));
496 sb_type.SetSP(type_sp);
501 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get());
503 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get());
509 SBValue::GetValueDidChange ()
511 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
514 lldb::ValueObjectSP value_sp(GetSP(locker));
517 result = value_sp->GetValueDidChange ();
520 log->Printf ("SBValue(%p)::GetValueDidChange() => %i", value_sp.get(), result);
525 #ifndef LLDB_DISABLE_PYTHON
527 SBValue::GetSummary ()
529 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
530 const char *cstr = NULL;
532 lldb::ValueObjectSP value_sp(GetSP(locker));
535 cstr = value_sp->GetSummaryAsCString();
540 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"", value_sp.get(), cstr);
542 log->Printf ("SBValue(%p)::GetSummary() => NULL", value_sp.get());
546 #endif // LLDB_DISABLE_PYTHON
549 SBValue::GetLocation ()
551 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
552 const char *cstr = NULL;
554 lldb::ValueObjectSP value_sp(GetSP(locker));
557 cstr = value_sp->GetLocationAsCString();
562 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"", value_sp.get(), cstr);
564 log->Printf ("SBValue(%p)::GetLocation() => NULL", value_sp.get());
569 // Deprecated - use the one that takes an lldb::SBError
571 SBValue::SetValueFromCString (const char *value_str)
574 return SetValueFromCString(value_str,dummy);
578 SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
580 bool success = false;
582 lldb::ValueObjectSP value_sp(GetSP(locker));
583 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
586 success = value_sp->SetValueFromCString (value_str,error.ref());
589 error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString());
592 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i", value_sp.get(), value_str, success);
598 SBValue::GetTypeFormat ()
600 lldb::SBTypeFormat format;
602 lldb::ValueObjectSP value_sp(GetSP(locker));
605 if (value_sp->UpdateValueIfNeeded(true))
607 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
609 format.SetSP(format_sp);
615 #ifndef LLDB_DISABLE_PYTHON
617 SBValue::GetTypeSummary ()
619 lldb::SBTypeSummary summary;
621 lldb::ValueObjectSP value_sp(GetSP(locker));
624 if (value_sp->UpdateValueIfNeeded(true))
626 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
628 summary.SetSP(summary_sp);
633 #endif // LLDB_DISABLE_PYTHON
636 SBValue::GetTypeFilter ()
638 lldb::SBTypeFilter filter;
640 lldb::ValueObjectSP value_sp(GetSP(locker));
643 if (value_sp->UpdateValueIfNeeded(true))
645 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
647 if (synthetic_sp && !synthetic_sp->IsScripted())
649 TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
650 filter.SetSP(filter_sp);
657 #ifndef LLDB_DISABLE_PYTHON
658 lldb::SBTypeSynthetic
659 SBValue::GetTypeSynthetic ()
661 lldb::SBTypeSynthetic synthetic;
663 lldb::ValueObjectSP value_sp(GetSP(locker));
666 if (value_sp->UpdateValueIfNeeded(true))
668 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
670 if (children_sp && children_sp->IsScripted())
672 ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
673 synthetic.SetSP(synth_sp);
682 SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
684 lldb::SBValue sb_value;
686 lldb::ValueObjectSP value_sp(GetSP(locker));
687 lldb::ValueObjectSP new_value_sp;
690 TypeImplSP type_sp (type.GetSP());
693 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(false), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name);
696 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
700 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"",
702 new_value_sp->GetName().AsCString());
704 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL",
711 SBValue::Cast (SBType type)
713 lldb::SBValue sb_value;
715 lldb::ValueObjectSP value_sp(GetSP(locker));
716 TypeImplSP type_sp (type.GetSP());
717 if (value_sp && type_sp)
718 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType(false)),GetPreferDynamicValue(),GetPreferSyntheticValue());
723 SBValue::CreateValueFromExpression (const char *name, const char* expression)
725 SBExpressionOptions options;
726 options.ref().SetKeepInMemory(true);
727 return CreateValueFromExpression (name, expression, options);
731 SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options)
733 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
734 lldb::SBValue sb_value;
736 lldb::ValueObjectSP value_sp(GetSP(locker));
737 lldb::ValueObjectSP new_value_sp;
740 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
741 Target* target = exe_ctx.GetTargetPtr();
744 options.ref().SetKeepInMemory(true);
745 target->EvaluateExpression (expression,
746 exe_ctx.GetFramePtr(),
751 new_value_sp->SetName(ConstString(name));
752 sb_value.SetSP(new_value_sp);
759 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
765 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
774 SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
776 lldb::SBValue sb_value;
778 lldb::ValueObjectSP value_sp(GetSP(locker));
779 lldb::ValueObjectSP new_value_sp;
780 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
781 if (value_sp && type_impl_sp)
783 ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(false).GetPointerType ());
784 if (pointer_ast_type)
786 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
788 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
789 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
793 exe_ctx.GetByteOrder(),
794 exe_ctx.GetAddressByteSize()));
796 if (ptr_result_valobj_sp)
798 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
800 new_value_sp = ptr_result_valobj_sp->Dereference(err);
802 new_value_sp->SetName(ConstString(name));
804 sb_value.SetSP(new_value_sp);
807 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
811 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
813 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
819 SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
821 lldb::SBValue sb_value;
822 lldb::ValueObjectSP new_value_sp;
824 lldb::ValueObjectSP value_sp(GetSP(locker));
827 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
829 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
830 type.m_opaque_sp->GetClangASTType(false),
833 LLDB_INVALID_ADDRESS);
834 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
835 sb_value.SetSP(new_value_sp);
837 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
841 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
843 log->Printf ("SBValue(%p)::CreateValueFromData => NULL", value_sp.get());
849 SBValue::GetChildAtIndex (uint32_t idx)
851 const bool can_create_synthetic = false;
852 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
855 target_sp = m_opaque_sp->GetTargetSP();
858 use_dynamic = target_sp->GetPreferDynamicValue();
860 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
864 SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
866 lldb::ValueObjectSP child_sp;
867 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
870 lldb::ValueObjectSP value_sp(GetSP(locker));
873 const bool can_create = true;
874 child_sp = value_sp->GetChildAtIndex (idx, can_create);
875 if (can_create_synthetic && !child_sp)
877 if (value_sp->IsPointerType())
879 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
881 else if (value_sp->IsArrayType())
883 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
889 sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
891 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
897 SBValue::GetIndexOfChildWithName (const char *name)
899 uint32_t idx = UINT32_MAX;
901 lldb::ValueObjectSP value_sp(GetSP(locker));
904 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
906 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
909 if (idx == UINT32_MAX)
910 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
912 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
918 SBValue::GetChildMemberWithName (const char *name)
920 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
923 target_sp = m_opaque_sp->GetTargetSP();
926 use_dynamic_value = target_sp->GetPreferDynamicValue();
927 return GetChildMemberWithName (name, use_dynamic_value);
931 SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
933 lldb::ValueObjectSP child_sp;
934 const ConstString str_name (name);
936 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
939 lldb::ValueObjectSP value_sp(GetSP(locker));
942 child_sp = value_sp->GetChildMemberWithName (str_name, true);
946 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
949 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
955 SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
960 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
961 value_sb.SetSP(proxy_sp);
967 SBValue::GetStaticValue ()
972 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic()));
973 value_sb.SetSP(proxy_sp);
979 SBValue::GetNonSyntheticValue ()
984 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
985 value_sb.SetSP(proxy_sp);
990 lldb::DynamicValueType
991 SBValue::GetPreferDynamicValue ()
994 return eNoDynamicValues;
995 return m_opaque_sp->GetUseDynamic();
999 SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
1002 return m_opaque_sp->SetUseDynamic (use_dynamic);
1006 SBValue::GetPreferSyntheticValue ()
1010 return m_opaque_sp->GetUseSynthetic();
1014 SBValue::SetPreferSyntheticValue (bool use_synthetic)
1017 return m_opaque_sp->SetUseSynthetic (use_synthetic);
1021 SBValue::IsDynamic()
1024 lldb::ValueObjectSP value_sp(GetSP(locker));
1026 return value_sp->IsDynamic();
1031 SBValue::IsSynthetic ()
1034 lldb::ValueObjectSP value_sp(GetSP(locker));
1036 return value_sp->IsSynthetic();
1041 SBValue::GetValueForExpressionPath(const char* expr_path)
1043 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1044 lldb::ValueObjectSP child_sp;
1046 lldb::ValueObjectSP value_sp(GetSP(locker));
1049 // using default values for all the fancy options, just do it if you can
1050 child_sp = value_sp->GetValueForExpressionPath(expr_path);
1054 sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
1057 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", value_sp.get(), expr_path, value_sp.get());
1063 SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1067 lldb::ValueObjectSP value_sp(GetSP(locker));
1070 bool success = true;
1071 uint64_t ret_val = fail_value;
1072 ret_val = value_sp->GetValueAsSigned(fail_value, &success);
1074 error.SetErrorString("could not resolve value");
1078 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1084 SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1088 lldb::ValueObjectSP value_sp(GetSP(locker));
1091 bool success = true;
1092 uint64_t ret_val = fail_value;
1093 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
1095 error.SetErrorString("could not resolve value");
1099 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1105 SBValue::GetValueAsSigned(int64_t fail_value)
1108 lldb::ValueObjectSP value_sp(GetSP(locker));
1111 return value_sp->GetValueAsSigned(fail_value);
1117 SBValue::GetValueAsUnsigned(uint64_t fail_value)
1120 lldb::ValueObjectSP value_sp(GetSP(locker));
1123 return value_sp->GetValueAsUnsigned(fail_value);
1129 SBValue::MightHaveChildren ()
1131 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1132 bool has_children = false;
1134 lldb::ValueObjectSP value_sp(GetSP(locker));
1136 has_children = value_sp->MightHaveChildren();
1139 log->Printf ("SBValue(%p)::MightHaveChildren() => %i", value_sp.get(), has_children);
1140 return has_children;
1144 SBValue::GetNumChildren ()
1146 uint32_t num_children = 0;
1148 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1150 lldb::ValueObjectSP value_sp(GetSP(locker));
1152 num_children = value_sp->GetNumChildren();
1155 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
1157 return num_children;
1162 SBValue::Dereference ()
1166 lldb::ValueObjectSP value_sp(GetSP(locker));
1170 sb_value = value_sp->Dereference (error);
1172 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1174 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
1180 SBValue::TypeIsPointerType ()
1182 bool is_ptr_type = false;
1185 lldb::ValueObjectSP value_sp(GetSP(locker));
1187 is_ptr_type = value_sp->IsPointerType();
1189 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1191 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
1198 SBValue::GetOpaqueType()
1201 lldb::ValueObjectSP value_sp(GetSP(locker));
1203 return value_sp->GetClangType().GetOpaqueQualType();
1208 SBValue::GetTarget()
1214 target_sp = m_opaque_sp->GetTargetSP();
1215 sb_target.SetSP (target_sp);
1217 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1220 if (target_sp.get() == NULL)
1221 log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get());
1223 log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), target_sp.get());
1229 SBValue::GetProcess()
1231 SBProcess sb_process;
1232 ProcessSP process_sp;
1235 process_sp = m_opaque_sp->GetProcessSP();
1236 sb_process.SetSP (process_sp);
1238 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1241 if (process_sp.get() == NULL)
1242 log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get());
1244 log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), process_sp.get());
1250 SBValue::GetThread()
1256 thread_sp = m_opaque_sp->GetThreadSP();
1257 sb_thread.SetThread(thread_sp);
1259 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1262 if (thread_sp.get() == NULL)
1263 log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get());
1265 log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), thread_sp.get());
1274 StackFrameSP frame_sp;
1277 frame_sp = m_opaque_sp->GetFrameSP();
1278 sb_frame.SetFrameSP (frame_sp);
1280 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1283 if (frame_sp.get() == NULL)
1284 log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get());
1286 log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), frame_sp.get());
1293 SBValue::GetSP (ValueLocker &locker) const
1295 if (!m_opaque_sp || !m_opaque_sp->IsValid())
1296 return ValueObjectSP();
1297 return locker.GetLockedSP(*m_opaque_sp.get());
1301 SBValue::GetSP () const
1304 return GetSP(locker);
1308 SBValue::SetSP (ValueImplSP impl_sp)
1310 m_opaque_sp = impl_sp;
1314 SBValue::SetSP (const lldb::ValueObjectSP &sp)
1318 lldb::TargetSP target_sp(sp->GetTargetSP());
1321 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1322 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1323 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1326 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
1329 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
1333 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
1337 lldb::TargetSP target_sp(sp->GetTargetSP());
1340 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1341 SetSP (sp, use_dynamic, use_synthetic);
1344 SetSP (sp, use_dynamic, true);
1347 SetSP (sp, use_dynamic, false);
1351 SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
1355 lldb::TargetSP target_sp(sp->GetTargetSP());
1358 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1359 SetSP (sp, use_dynamic, use_synthetic);
1362 SetSP (sp, eNoDynamicValues, use_synthetic);
1365 SetSP (sp, eNoDynamicValues, use_synthetic);
1369 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
1371 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
1375 SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
1377 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
1381 SBValue::GetExpressionPath (SBStream &description)
1384 lldb::ValueObjectSP value_sp(GetSP(locker));
1387 value_sp->GetExpressionPath (description.ref(), false);
1394 SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1397 lldb::ValueObjectSP value_sp(GetSP(locker));
1400 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
1407 SBValue::GetDescription (SBStream &description)
1409 Stream &strm = description.ref();
1412 lldb::ValueObjectSP value_sp(GetSP(locker));
1414 value_sp->Dump(strm);
1416 strm.PutCString ("No value");
1422 SBValue::GetFormat ()
1425 lldb::ValueObjectSP value_sp(GetSP(locker));
1427 return value_sp->GetFormat();
1428 return eFormatDefault;
1432 SBValue::SetFormat (lldb::Format format)
1435 lldb::ValueObjectSP value_sp(GetSP(locker));
1437 value_sp->SetFormat(format);
1441 SBValue::AddressOf()
1445 lldb::ValueObjectSP value_sp(GetSP(locker));
1449 sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
1451 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1453 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)", value_sp.get(), value_sp.get());
1459 SBValue::GetLoadAddress()
1461 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1463 lldb::ValueObjectSP value_sp(GetSP(locker));
1466 TargetSP target_sp (value_sp->GetTargetSP());
1469 const bool scalar_is_load_address = true;
1470 AddressType addr_type;
1471 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1472 if (addr_type == eAddressTypeFile)
1474 ModuleSP module_sp (value_sp->GetModule());
1476 value = LLDB_INVALID_ADDRESS;
1480 module_sp->ResolveFileAddress(value, addr);
1481 value = addr.GetLoadAddress(target_sp.get());
1484 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1485 value = LLDB_INVALID_ADDRESS;
1488 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1490 log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")", value_sp.get(), value);
1496 SBValue::GetAddress()
1500 lldb::ValueObjectSP value_sp(GetSP(locker));
1503 TargetSP target_sp (value_sp->GetTargetSP());
1506 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1507 const bool scalar_is_load_address = true;
1508 AddressType addr_type;
1509 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1510 if (addr_type == eAddressTypeFile)
1512 ModuleSP module_sp (value_sp->GetModule());
1514 module_sp->ResolveFileAddress(value, addr);
1516 else if (addr_type == eAddressTypeLoad)
1518 // no need to check the return value on this.. if it can actually do the resolve
1519 // addr will be in the form (section,offset), otherwise it will simply be returned
1521 addr.SetLoadAddress(value, target_sp.get());
1525 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1527 log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")", value_sp.get(),
1528 (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"),
1530 return SBAddress(new Address(addr));
1534 SBValue::GetPointeeData (uint32_t item_idx,
1535 uint32_t item_count)
1537 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1538 lldb::SBData sb_data;
1540 lldb::ValueObjectSP value_sp(GetSP(locker));
1543 TargetSP target_sp (value_sp->GetTargetSP());
1546 DataExtractorSP data_sp(new DataExtractor());
1547 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1548 if (data_sp->GetByteSize() > 0)
1553 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
1565 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1566 lldb::SBData sb_data;
1568 lldb::ValueObjectSP value_sp(GetSP(locker));
1571 DataExtractorSP data_sp(new DataExtractor());
1572 value_sp->GetData(*data_sp);
1573 if (data_sp->GetByteSize() > 0)
1577 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
1585 SBValue::SetData (lldb::SBData &data, SBError &error)
1587 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1589 lldb::ValueObjectSP value_sp(GetSP(locker));
1594 DataExtractor *data_extractor = data.get();
1596 if (!data_extractor)
1599 log->Printf ("SBValue(%p)::SetData() => error: no data to set", value_sp.get());
1601 error.SetErrorString("No data to set");
1608 value_sp->SetData(*data_extractor, set_error);
1610 if (!set_error.Success())
1612 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
1619 error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
1624 log->Printf ("SBValue(%p)::SetData (%p) => %s",
1627 ret ? "true" : "false");
1632 SBValue::GetDeclaration ()
1635 lldb::ValueObjectSP value_sp(GetSP(locker));
1636 SBDeclaration decl_sb;
1640 if (value_sp->GetDeclaration(decl))
1641 decl_sb.SetDeclaration(decl);
1647 SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
1649 SBWatchpoint sb_watchpoint;
1651 // If the SBValue is not valid, there's no point in even trying to watch it.
1653 lldb::ValueObjectSP value_sp(GetSP(locker));
1654 TargetSP target_sp (GetTarget().GetSP());
1655 if (value_sp && target_sp)
1657 // Read and Write cannot both be false.
1658 if (!read && !write)
1659 return sb_watchpoint;
1661 // If the value is not in scope, don't try and watch and invalid value
1663 return sb_watchpoint;
1665 addr_t addr = GetLoadAddress();
1666 if (addr == LLDB_INVALID_ADDRESS)
1667 return sb_watchpoint;
1668 size_t byte_size = GetByteSize();
1670 return sb_watchpoint;
1672 uint32_t watch_type = 0;
1674 watch_type |= LLDB_WATCH_TYPE_READ;
1676 watch_type |= LLDB_WATCH_TYPE_WRITE;
1679 ClangASTType type (value_sp->GetClangType());
1680 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
1685 sb_watchpoint.SetSP (watchpoint_sp);
1687 if (value_sp->GetDeclaration (decl))
1692 // True to show fullpath for declaration file.
1693 decl.DumpStopContext(&ss, true);
1694 watchpoint_sp->SetDeclInfo(ss.GetString());
1701 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1703 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s", value_sp.get(), locker.GetError().AsCString());
1705 error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
1709 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1711 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target", value_sp.get());
1712 error.SetErrorString("could not set watchpoint, a target is required");
1715 return sb_watchpoint;
1718 // FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1719 // Backward compatibility fix in the interim.
1721 SBValue::Watch (bool resolve_location, bool read, bool write)
1724 return Watch(resolve_location, read, write, error);
1728 SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
1730 SBWatchpoint sb_watchpoint;
1731 if (IsInScope() && GetType().IsPointerType())
1732 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
1733 return sb_watchpoint;