summaryrefslogtreecommitdiffstats
path: root/lldb/source/API/SBValue.cpp
diff options
context:
space:
mode:
authorEnrico Granata <egranata@apple.com>2012-10-22 18:18:36 +0000
committerEnrico Granata <egranata@apple.com>2012-10-22 18:18:36 +0000
commite3e91517ffd7e63bcb5b9d196f85e2b09802b414 (patch)
tree16ba51bd013c2fb1d9753e2c6a6aae958202f892 /lldb/source/API/SBValue.cpp
parent2f758cf8bafb527e9a709043d9704449a5f767b8 (diff)
downloadbcm5719-llvm-e3e91517ffd7e63bcb5b9d196f85e2b09802b414.tar.gz
bcm5719-llvm-e3e91517ffd7e63bcb5b9d196f85e2b09802b414.zip
<rdar://problem/12437442>
Given our implementation of ValueObjects we could have a scenario where a ValueObject has a dynamic type of Foo* at one point, and then its dynamic type changes to Bar* If Bar* has synthetic children enabled, by the time we figure that out, our public API is already vending SBValues wrapping a DynamicVO, instead of a SyntheticVO and there was no trivial way for us to change the SP inside an SBValue on the fly This checkin reimplements SBValue in terms of a wrapper, ValueImpl, that allows this substitutions on-the-fly by overriding GetSP() to do The Right Thing (TM) As an additional bonus, GetNonSyntheticValue() now works, and we can get rid of the ForceDisableSyntheticChildren idiom in ScriptInterpreterPython Lastly, this checkin makes sure the synthetic VOs get the correct m_value and m_data from their parents (prevented summaries from working in some cases) llvm-svn: 166426
Diffstat (limited to 'lldb/source/API/SBValue.cpp')
-rw-r--r--lldb/source/API/SBValue.cpp307
1 files changed, 228 insertions, 79 deletions
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 5b38bc5e14a..318029fdc43 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -50,6 +50,98 @@
using namespace lldb;
using namespace lldb_private;
+namespace {
+ class ValueImpl
+ {
+ public:
+ ValueImpl ()
+ {
+ }
+
+ ValueImpl (lldb::ValueObjectSP opaque_sp,
+ lldb::DynamicValueType use_dynamic,
+ bool use_synthetic) :
+ m_opaque_sp(opaque_sp),
+ m_use_dynamic(use_dynamic),
+ m_use_synthetic(use_synthetic)
+ {
+ }
+
+ ValueImpl (const ValueImpl& rhs) :
+ m_opaque_sp(rhs.m_opaque_sp),
+ m_use_dynamic(rhs.m_use_dynamic),
+ m_use_synthetic(rhs.m_use_synthetic)
+ {
+ }
+
+ ValueImpl &
+ operator = (const ValueImpl &rhs)
+ {
+ if (this != &rhs)
+ {
+ m_opaque_sp = rhs.m_opaque_sp;
+ m_use_dynamic = rhs.m_use_dynamic;
+ m_use_synthetic = rhs.m_use_synthetic;
+ }
+ return *this;
+ }
+
+ bool
+ IsValid ()
+ {
+ return m_opaque_sp.get() != NULL;
+ }
+
+ lldb::ValueObjectSP
+ GetRootSP ()
+ {
+ return m_opaque_sp;
+ }
+
+ lldb::ValueObjectSP
+ GetSP ()
+ {
+ if (!m_opaque_sp)
+ return m_opaque_sp;
+ lldb::ValueObjectSP value_sp = m_opaque_sp;
+ if (value_sp->GetDynamicValue(m_use_dynamic))
+ value_sp = value_sp->GetDynamicValue(m_use_dynamic);
+ if (value_sp->GetSyntheticValue(m_use_synthetic))
+ value_sp = value_sp->GetSyntheticValue(m_use_synthetic);
+ return value_sp;
+ }
+
+ void
+ SetUseDynamic (lldb::DynamicValueType use_dynamic)
+ {
+ m_use_dynamic = use_dynamic;
+ }
+
+ void
+ SetUseSynthetic (bool use_synthetic)
+ {
+ m_use_synthetic = use_synthetic;
+ }
+
+ lldb::DynamicValueType
+ GetUseDynamic ()
+ {
+ return m_use_dynamic;
+ }
+
+ bool
+ GetUseSynthetic ()
+ {
+ return m_use_synthetic;
+ }
+
+ private:
+ lldb::ValueObjectSP m_opaque_sp;
+ lldb::DynamicValueType m_use_dynamic;
+ bool m_use_synthetic;
+ };
+}
+
SBValue::SBValue () :
m_opaque_sp ()
{
@@ -57,12 +149,12 @@ SBValue::SBValue () :
SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
{
- SetSP(value_sp); // whenever setting the SP call SetSP() since it knows how to deal with synthetic values properly
+ SetSP(value_sp);
}
SBValue::SBValue(const SBValue &rhs)
{
- SetSP(rhs.m_opaque_sp); // whenever setting the SP call SetSP() since it knows how to deal with synthetic values properly
+ SetSP(rhs.m_opaque_sp);
}
SBValue &
@@ -70,7 +162,7 @@ SBValue::operator = (const SBValue &rhs)
{
if (this != &rhs)
{
- SetSP(rhs.m_opaque_sp); // whenever setting the SP call SetSP() since it knows how to deal with synthetic values properly
+ SetSP(rhs.m_opaque_sp);
}
return *this;
}
@@ -85,7 +177,7 @@ SBValue::IsValid ()
// If this function ever changes to anything that does more than just
// check if the opaque shared pointer is non NULL, then we need to update
// all "if (m_opaque_sp)" code in this file.
- return m_opaque_sp.get() != NULL;
+ return m_opaque_sp.get() != NULL && m_opaque_sp->GetRootSP().get() != NULL;
}
void
@@ -683,7 +775,7 @@ SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
TypeImplSP type_sp (type.GetSP());
if (type.IsValid())
{
- sb_value = SBValue(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true));
+ sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true),GetPreferDynamicValue(),GetPreferSyntheticValue());
new_value_sp = sb_value.GetSP();
if (new_value_sp)
new_value_sp->SetName(ConstString(name));
@@ -712,7 +804,7 @@ SBValue::Cast (SBType type)
lldb::ValueObjectSP value_sp(GetSP());
TypeImplSP type_sp (type.GetSP());
if (value_sp && type_sp)
- sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()));
+ sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()),GetPreferDynamicValue(),GetPreferSyntheticValue());
return sb_value;
}
@@ -904,20 +996,12 @@ SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool
}
}
- if (child_sp)
- {
- if (use_dynamic != lldb::eNoDynamicValues)
- {
- lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
- if (dynamic_sp)
- child_sp = dynamic_sp;
- }
- }
}
}
}
- SBValue sb_value (child_sp);
+ SBValue sb_value;
+ sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
if (log)
log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
@@ -993,20 +1077,12 @@ SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dy
{
Mutex::Locker api_locker (target_sp->GetAPIMutex());
child_sp = value_sp->GetChildMemberWithName (str_name, true);
- if (use_dynamic_value != lldb::eNoDynamicValues)
- {
- if (child_sp)
- {
- lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
- if (dynamic_sp)
- child_sp = dynamic_sp;
- }
- }
}
}
}
- SBValue sb_value (child_sp);
+ SBValue sb_value;
+ sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
if (log)
log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
@@ -1017,74 +1093,87 @@ SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dy
lldb::SBValue
SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
{
- lldb::ValueObjectSP value_sp(GetSP());
- if (value_sp)
+ SBValue value_sb;
+ if (IsValid())
{
- ProcessSP process_sp(value_sp->GetProcessSP());
- Process::StopLocker stop_locker;
- if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
- {
- LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
- if (log)
- log->Printf ("SBValue(%p)::GetDynamicValue() => error: process is running", value_sp.get());
- }
- else
- {
- TargetSP target_sp(value_sp->GetTargetSP());
- if (target_sp)
- {
- Mutex::Locker api_locker (target_sp->GetAPIMutex());
- return SBValue (value_sp->GetDynamicValue(use_dynamic));
- }
- }
+ ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
+ value_sb.SetSP(proxy_sp);
}
-
- return SBValue();
+ return value_sb;
}
lldb::SBValue
SBValue::GetStaticValue ()
{
- lldb::ValueObjectSP value_sp(GetSP());
- if (value_sp)
+ SBValue value_sb;
+ if (IsValid())
{
- TargetSP target_sp(value_sp->GetTargetSP());
- if (target_sp)
- {
- Mutex::Locker api_locker (target_sp->GetAPIMutex());
- return SBValue(value_sp->GetStaticValue());
- }
+ ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic()));
+ value_sb.SetSP(proxy_sp);
}
-
- return SBValue();
+ return value_sb;
}
lldb::SBValue
SBValue::GetNonSyntheticValue ()
{
- SBValue sb_value;
+ SBValue value_sb;
+ if (IsValid())
+ {
+ ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
+ value_sb.SetSP(proxy_sp);
+ }
+ return value_sb;
+}
+
+lldb::DynamicValueType
+SBValue::GetPreferDynamicValue ()
+{
+ if (!IsValid())
+ return eNoDynamicValues;
+ return m_opaque_sp->GetUseDynamic();
+}
+
+void
+SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
+{
+ if (IsValid())
+ return m_opaque_sp->SetUseDynamic (use_dynamic);
+}
+
+bool
+SBValue::GetPreferSyntheticValue ()
+{
+ if (!IsValid())
+ return false;
+ return m_opaque_sp->GetUseSynthetic();
+}
+
+void
+SBValue::SetPreferSyntheticValue (bool use_synthetic)
+{
+ if (IsValid())
+ return m_opaque_sp->SetUseSynthetic (use_synthetic);
+}
+
+bool
+SBValue::IsDynamic()
+{
lldb::ValueObjectSP value_sp(GetSP());
if (value_sp)
{
- if (value_sp->IsSynthetic())
+ TargetSP target_sp(value_sp->GetTargetSP());
+ if (target_sp)
{
- TargetSP target_sp(value_sp->GetTargetSP());
- if (target_sp)
- {
- Mutex::Locker api_locker (target_sp->GetAPIMutex());
- // deliberately breaking the rules here to optimize the case where we DO NOT want
- // the synthetic value to be returned to the user - if we did not do this, we would have to tell
- // the target to suppress the synthetic value, and then return the flag to its original value
- if (value_sp->GetNonSyntheticValue())
- sb_value.m_opaque_sp = value_sp->GetNonSyntheticValue();
- }
+ Mutex::Locker api_locker (target_sp->GetAPIMutex());
+ return value_sp->IsDynamic();
}
}
- return sb_value;
+ return false;
}
bool
-SBValue::IsDynamic()
+SBValue::IsSynthetic ()
{
lldb::ValueObjectSP value_sp(GetSP());
if (value_sp)
@@ -1093,7 +1182,7 @@ SBValue::IsDynamic()
if (target_sp)
{
Mutex::Locker api_locker (target_sp->GetAPIMutex());
- return value_sp->IsDynamic();
+ return value_sp->IsSynthetic();
}
}
return false;
@@ -1126,7 +1215,8 @@ SBValue::GetValueForExpressionPath(const char* expr_path)
}
}
- SBValue sb_value (child_sp);
+ SBValue sb_value;
+ sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
if (log)
log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", value_sp.get(), expr_path, value_sp.get());
@@ -1457,17 +1547,77 @@ SBValue::GetFrame()
lldb::ValueObjectSP
SBValue::GetSP () const
{
- return m_opaque_sp;
+ if (!m_opaque_sp || !m_opaque_sp->IsValid())
+ return ValueObjectSP();
+ return m_opaque_sp->GetSP();
+}
+
+void
+SBValue::SetSP (ValueImplSP impl_sp)
+{
+ m_opaque_sp = impl_sp;
}
void
SBValue::SetSP (const lldb::ValueObjectSP &sp)
{
- m_opaque_sp = sp;
- if (IsValid() && m_opaque_sp->HasSyntheticValue())
- m_opaque_sp = m_opaque_sp->GetSyntheticValue();
+ if (sp)
+ {
+ lldb::TargetSP target_sp(sp->GetTargetSP());
+ if (target_sp)
+ {
+ lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
+ bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
+ m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
+ }
+ else
+ m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
+ }
+ else
+ m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
}
+void
+SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
+{
+ if (sp)
+ {
+ lldb::TargetSP target_sp(sp->GetTargetSP());
+ if (target_sp)
+ {
+ bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
+ SetSP (sp, use_dynamic, use_synthetic);
+ }
+ else
+ SetSP (sp, use_dynamic, true);
+ }
+ else
+ SetSP (sp, use_dynamic, false);
+}
+
+void
+SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
+{
+ if (sp)
+ {
+ lldb::TargetSP target_sp(sp->GetTargetSP());
+ if (target_sp)
+ {
+ lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
+ SetSP (sp, use_dynamic, use_synthetic);
+ }
+ else
+ SetSP (sp, eNoDynamicValues, use_synthetic);
+ }
+ else
+ SetSP (sp, eNoDynamicValues, use_synthetic);
+}
+
+void
+SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
+{
+ m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
+}
bool
SBValue::GetExpressionPath (SBStream &description)
@@ -1549,7 +1699,7 @@ SBValue::AddressOf()
{
Mutex::Locker api_locker (target_sp->GetAPIMutex());
Error error;
- sb_value = value_sp->AddressOf (error);
+ sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
}
}
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
@@ -1805,4 +1955,3 @@ SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &er
sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
return sb_watchpoint;
}
-
OpenPOWER on IntegriCloud