From 6999f86617f371784be2b6f8d2ae38c8030dfd31 Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Wed, 29 Jun 2011 21:19:39 +0000 Subject: [PATCH] Add fuzz calls to SBType, SBValue, and SBValueList. Fixed crashes for SBValue fuzz calls. And change 'bool SBType::IsPointerType(void)' to 'bool SBType::IsAPointerType(void)' to avoid name collision with the static 'bool SBType::IsPointerType(void *)' function, which SWIG cannot handle. llvm-svn: 134096 --- lldb/include/lldb/API/SBType.h | 2 +- lldb/source/API/SBType.cpp | 6 ++-- lldb/source/API/SBValue.cpp | 18 +++++++--- .../TestDefaultConstructorForAPIObjects.py | 9 +++++ .../python_api/default-constructor/sb_type.py | 19 ++++++++++ .../default-constructor/sb_value.py | 35 +++++++++++++++++++ .../default-constructor/sb_valuelist.py | 12 +++++++ 7 files changed, 93 insertions(+), 8 deletions(-) create mode 100644 lldb/test/python_api/default-constructor/sb_type.py create mode 100644 lldb/test/python_api/default-constructor/sb_value.py create mode 100644 lldb/test/python_api/default-constructor/sb_valuelist.py diff --git a/lldb/include/lldb/API/SBType.h b/lldb/include/lldb/API/SBType.h index 97af8d213365..1dc330d6adbc 100644 --- a/lldb/include/lldb/API/SBType.h +++ b/lldb/include/lldb/API/SBType.h @@ -53,7 +53,7 @@ public: GetChildIndexForName (bool omit_empty_base_classes, const char *name); bool - IsPointerType (); + IsAPointerType (); SBType GetPointeeType (); diff --git a/lldb/source/API/SBType.cpp b/lldb/source/API/SBType.cpp index da37f6730edf..4f20124d22f4 100644 --- a/lldb/source/API/SBType.cpp +++ b/lldb/source/API/SBType.cpp @@ -165,7 +165,7 @@ SBType::GetChildIndexForName (bool omit_empty_base_classes, const char *name) } bool -SBType::IsPointerType () +SBType::IsAPointerType () { return ClangASTContext::IsPointerType (m_type); } @@ -174,7 +174,7 @@ SBType SBType::GetPointeeType () { void *pointee_type = NULL; - if (IsPointerType ()) + if (IsAPointerType ()) { pointee_type = ClangASTType::GetPointeeType (m_type); } @@ -187,7 +187,7 @@ SBType::GetDescription (SBStream &description) const char *name = GetName(); uint64_t byte_size = GetByteSize(); uint64_t num_children = GetNumberChildren (true); - bool is_ptr = IsPointerType (); + bool is_ptr = IsAPointerType (); description.Printf ("type_name: %s, size: %d bytes", (name != NULL ? name : ""), byte_size); if (is_ptr) diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index 376bd624a547..801d15d060f3 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -353,8 +353,13 @@ SBValue::SetValueFromCString (const char *value_str) SBValue SBValue::GetChildAtIndex (uint32_t idx) { - lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue(); - return GetChildAtIndex (idx, use_dynamic_value); + if (m_opaque_sp) + { + lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue(); + return GetChildAtIndex (idx, use_dynamic_value); + } + else + return GetChildAtIndex (idx, eNoDynamicValues); } SBValue @@ -416,8 +421,13 @@ SBValue::GetIndexOfChildWithName (const char *name) SBValue SBValue::GetChildMemberWithName (const char *name) { - lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue(); - return GetChildMemberWithName (name, use_dynamic_value); + if (m_opaque_sp) + { + lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTarget()->GetPreferDynamicValue(); + return GetChildMemberWithName (name, use_dynamic_value); + } + else + return GetChildMemberWithName (name, eNoDynamicValues); } SBValue diff --git a/lldb/test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py b/lldb/test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py index f46ce835abf8..f49a3a20d720 100644 --- a/lldb/test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py +++ b/lldb/test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py @@ -297,6 +297,9 @@ class APIDefaultConstructorTestCase(TestBase): if self.TraceOn(): print obj self.assertFalse(obj) + # Do fuzz testing on the invalid obj, it should not crash lldb. + import sb_type + sb_type.fuzz_obj(obj) @python_api_test def test_SBValue(self): @@ -304,6 +307,9 @@ class APIDefaultConstructorTestCase(TestBase): if self.TraceOn(): print obj self.assertFalse(obj) + # Do fuzz testing on the invalid obj, it should not crash lldb. + import sb_value + sb_value.fuzz_obj(obj) @python_api_test def test_SBValueList(self): @@ -311,6 +317,9 @@ class APIDefaultConstructorTestCase(TestBase): if self.TraceOn(): print obj self.assertFalse(obj) + # Do fuzz testing on the invalid obj, it should not crash lldb. + import sb_valuelist + sb_valuelist.fuzz_obj(obj) if __name__ == '__main__': diff --git a/lldb/test/python_api/default-constructor/sb_type.py b/lldb/test/python_api/default-constructor/sb_type.py new file mode 100644 index 000000000000..689b48cbddf4 --- /dev/null +++ b/lldb/test/python_api/default-constructor/sb_type.py @@ -0,0 +1,19 @@ +""" +Fuzz tests an object after the default construction to make sure it does not crash lldb. +""" + +import sys +import lldb + +def fuzz_obj(obj): + obj.GetName() + obj.GetByteSize() + #obj.GetEncoding(5) + obj.GetNumberChildren(True) + member = lldb.SBTypeMember() + obj.GetChildAtIndex(True, 0, member) + obj.GetChildIndexForName(True, "_member_field") + obj.IsAPointerType() + obj.GetPointeeType() + obj.GetDescription(lldb.SBStream()) + diff --git a/lldb/test/python_api/default-constructor/sb_value.py b/lldb/test/python_api/default-constructor/sb_value.py new file mode 100644 index 000000000000..f3929a6cb295 --- /dev/null +++ b/lldb/test/python_api/default-constructor/sb_value.py @@ -0,0 +1,35 @@ +""" +Fuzz tests an object after the default construction to make sure it does not crash lldb. +""" + +import sys +import lldb + +def fuzz_obj(obj): + obj.GetError() + obj.GetName() + obj.GetTypeName() + obj.GetByteSize() + obj.IsInScope() + obj.GetFormat() + obj.SetFormat(lldb.eFormatBoolean) + obj.GetValue() + obj.GetValueType() + obj.GetValueDidChange() + obj.GetSummary() + obj.GetObjectDescription() + obj.GetLocation() + obj.SetValueFromCString("my_new_value") + obj.GetChildAtIndex(1) + obj.GetChildAtIndex(2, lldb.eNoDynamicValues) + obj.GetIndexOfChildWithName("my_first_child") + obj.GetChildMemberWithName("my_first_child") + obj.GetChildMemberWithName("my_first_child", lldb.eNoDynamicValues) + obj.GetNumChildren() + obj.GetOpaqueType() + obj.Dereference() + obj.TypeIsPointerType() + stream = lldb.SBStream() + obj.GetDescription(stream) + obj.GetExpressionPath(stream) + obj.GetExpressionPath(stream, True) diff --git a/lldb/test/python_api/default-constructor/sb_valuelist.py b/lldb/test/python_api/default-constructor/sb_valuelist.py new file mode 100644 index 000000000000..6d659097c183 --- /dev/null +++ b/lldb/test/python_api/default-constructor/sb_valuelist.py @@ -0,0 +1,12 @@ +""" +Fuzz tests an object after the default construction to make sure it does not crash lldb. +""" + +import sys +import lldb + +def fuzz_obj(obj): + obj.Append(lldb.SBValue()) + obj.GetSize() + obj.GetValueAtIndex(100) + obj.FindValueObjectByUID(200)