[Lldb-commits] [lldb] r134046 - in /lldb/trunk: source/API/SBTarget.cpp test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py test/python_api/default-constructor/sb_target.py test/python_api/default-constructor/sb_thread.py

Johnny Chen johnny.chen at apple.com
Tue Jun 28 17:05:40 PDT 2011


Author: johnny
Date: Tue Jun 28 19:05:40 2011
New Revision: 134046

URL: http://llvm.org/viewvc/llvm-project?rev=134046&view=rev
Log:
Add fuzz calls for SBTarget and SBThread.

Added:
    lldb/trunk/test/python_api/default-constructor/sb_target.py
    lldb/trunk/test/python_api/default-constructor/sb_thread.py
Modified:
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=134046&r1=134045&r2=134046&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Tue Jun 28 19:05:40 2011
@@ -504,13 +504,14 @@
 SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr, 
                               lldb::SBAddress& addr)
 {
-    if (m_opaque_sp)
+    if (m_opaque_sp && addr.IsValid())
     {
         Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
         return m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, *addr);
     }
 
-    addr->Clear();
+    if (addr.IsValid())
+        addr->Clear();
     return false;    
 }
 
@@ -518,7 +519,7 @@
 SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
 {
     SBSymbolContext sc;
-    if (m_opaque_sp)
+    if (m_opaque_sp && addr.IsValid())
         m_opaque_sp->GetImages().ResolveSymbolContextForAddress (*addr, resolve_scope, sc.ref());
     return sc;
 }

Modified: lldb/trunk/test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py?rev=134046&r1=134045&r2=134046&view=diff
==============================================================================
--- lldb/trunk/test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py (original)
+++ lldb/trunk/test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py Tue Jun 28 19:05:40 2011
@@ -277,6 +277,9 @@
         if self.TraceOn():
             print obj
         self.assertFalse(obj)
+        # Do fuzz testing on the invalid obj, it should not crash lldb.
+        import sb_target
+        sb_target.fuzz_obj(obj)
 
     @python_api_test
     def test_SBThread(self):
@@ -284,6 +287,9 @@
         if self.TraceOn():
             print obj
         self.assertFalse(obj)
+        # Do fuzz testing on the invalid obj, it should not crash lldb.
+        import sb_thread
+        sb_thread.fuzz_obj(obj)
 
     @python_api_test
     def test_SBType(self):

Added: lldb/trunk/test/python_api/default-constructor/sb_target.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/sb_target.py?rev=134046&view=auto
==============================================================================
--- lldb/trunk/test/python_api/default-constructor/sb_target.py (added)
+++ lldb/trunk/test/python_api/default-constructor/sb_target.py Tue Jun 28 19:05:40 2011
@@ -0,0 +1,42 @@
+"""
+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.GetProcess()
+    listener = lldb.SBListener()
+    error = lldb.SBError()
+    obj.Launch(listener, None, None, None, None, None, None, 0, True, error)
+    obj.LaunchSimple(None, None, None)
+    obj.AttachToProcessWithID(listener, 123, error)
+    obj.AttachToProcessWithName(listener, 'lldb', False, error)
+    obj.ConnectRemote(listener, "connect://to/here", None, error)
+    obj.GetExecutable()
+    obj.GetNumModules()
+    obj.GetModuleAtIndex(0xffffffff)
+    obj.GetDebugger()
+    filespec = lldb.SBFileSpec()
+    obj.FindModule(filespec)
+    contextlist = lldb.SBSymbolContextList()
+    obj.FindFunctions("the_func", 0xff, True, contextlist)
+    address = lldb.SBAddress()
+    obj.ResolveLoadAddress(0xffff, address)
+    obj.ResolveSymbolContextForAddress(address, 0)
+    obj.BreakpointCreateByLocation("filename", 20)
+    obj.BreakpointCreateByLocation(filespec, 20)
+    obj.BreakpointCreateByName("func", None)
+    obj.BreakpointCreateByRegex("func.", None)
+    obj.BreakpointCreateByAddress(0xf0f0)
+    obj.GetNumBreakpoints()
+    obj.GetBreakpointAtIndex(0)
+    obj.BreakpointDelete(0)
+    obj.FindBreakpointByID(0)
+    obj.EnableAllBreakpoints()
+    obj.DisableAllBreakpoints()
+    obj.DeleteAllBreakpoints()
+    obj.GetBroadcaster()
+    obj.GetDescription(lldb.SBStream(), lldb.eDescriptionLevelBrief)
+    obj.Clear()

Added: lldb/trunk/test/python_api/default-constructor/sb_thread.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/sb_thread.py?rev=134046&view=auto
==============================================================================
--- lldb/trunk/test/python_api/default-constructor/sb_thread.py (added)
+++ lldb/trunk/test/python_api/default-constructor/sb_thread.py Tue Jun 28 19:05:40 2011
@@ -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.GetStopReason()
+    obj.GetStopReasonDataCount()
+    obj.GetStopReasonDataAtIndex(100)
+    obj.GetStopDescription(256)
+    obj.GetThreadID()
+    obj.GetIndexID()
+    obj.GetName()
+    obj.GetQueueName()
+    obj.StepOver(lldb.eOnlyDuringStepping)
+    obj.StepInto(lldb.eOnlyDuringStepping)
+    obj.StepOut()
+    frame = lldb.SBFrame()
+    obj.StepOutOfFrame(frame)
+    obj.StepInstruction(True)
+    filespec = lldb.SBFileSpec()
+    obj.StepOverUntil(frame, filespec, 1234)
+    obj.RunToAddress(0xabcd)
+    obj.Suspend()
+    obj.Resume()
+    obj.IsSuspended()
+    obj.GetNumFrames()
+    obj.GetFrameAtIndex(200)
+    obj.GetSelectedFrame()
+    obj.SetSelectedFrame(999)
+    obj.GetProcess()
+    obj.GetDescription(lldb.SBStream())
+    obj.Clear()





More information about the lldb-commits mailing list