[Lldb-commits] [lldb] r133091 - in /lldb/trunk: include/lldb/API/SBDebugger.h include/lldb/API/SBTarget.h source/API/SBDebugger.cpp source/API/SBTarget.cpp test/lldbtest.py

Johnny Chen johnny.chen at apple.com
Wed Jun 15 14:24:24 PDT 2011


Author: johnny
Date: Wed Jun 15 16:24:24 2011
New Revision: 133091

URL: http://llvm.org/viewvc/llvm-project?rev=133091&view=rev
Log:
Add an API to SBDebugger class:

    bool SBDebugger::DeleteTarget(lldb::SBTarget &target);

which is used in the test tearDown() phase to cleanup the debugger's target list
so that it won't grow larger and larger as test cases are executed.  This is also
a good opportunity to get rid of the arcane requirement that test cases exercising
the Python API must assign the process object to self.process so that it gets
shutdown gracefully.  Instead, the shutdown of the process associated with each
target is now being now automatically.

Also get rid of an API from SBTarget class:

    SBTarget::DeleteTargetFromList(lldb_private::TargetList *list);

Modified:
    lldb/trunk/include/lldb/API/SBDebugger.h
    lldb/trunk/include/lldb/API/SBTarget.h
    lldb/trunk/source/API/SBDebugger.cpp
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/test/lldbtest.py

Modified: lldb/trunk/include/lldb/API/SBDebugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDebugger.h?rev=133091&r1=133090&r2=133091&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBDebugger.h (original)
+++ lldb/trunk/include/lldb/API/SBDebugger.h Wed Jun 15 16:24:24 2011
@@ -98,6 +98,10 @@
     lldb::SBTarget
     CreateTarget (const char *filename);
 
+    // Return true if target is deleted from the target list of the debugger.
+    bool
+    DeleteTarget (lldb::SBTarget &target);
+
     lldb::SBTarget
     GetTargetAtIndex (uint32_t idx);
 

Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=133091&r1=133090&r2=133091&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Wed Jun 15 16:24:24 2011
@@ -187,9 +187,6 @@
     Clear ();
 
     bool
-    DeleteTargetFromList (lldb_private::TargetList *list);
-    
-    bool
     ResolveLoadAddress (lldb::addr_t vm_addr, 
                         lldb::SBAddress& addr);
 

Modified: lldb/trunk/source/API/SBDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=133091&r1=133090&r2=133091&view=diff
==============================================================================
--- lldb/trunk/source/API/SBDebugger.cpp (original)
+++ lldb/trunk/source/API/SBDebugger.cpp Wed Jun 15 16:24:24 2011
@@ -508,6 +508,24 @@
     return target;
 }
 
+bool
+SBDebugger::DeleteTarget (lldb::SBTarget &target)
+{
+    bool result = false;
+    if (m_opaque_sp)
+    {
+        // No need to lock, the target list is thread safe
+        result = m_opaque_sp->GetTargetList().DeleteTarget (target.m_opaque_sp);
+    }
+
+    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+    if (log)
+    {
+        log->Printf ("SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i", m_opaque_sp.get(), target.m_opaque_sp.get(), result);
+    }
+
+    return result;
+}
 SBTarget
 SBDebugger::GetTargetAtIndex (uint32_t idx)
 {

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=133091&r1=133090&r2=133091&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Wed Jun 15 16:24:24 2011
@@ -397,16 +397,6 @@
     return exe_file_spec;
 }
 
-
-bool
-SBTarget::DeleteTargetFromList (TargetList *list)
-{
-    if (m_opaque_sp)
-        return list->DeleteTarget (m_opaque_sp);
-    else
-        return false;
-}
-
 bool
 SBTarget::operator == (const SBTarget &rhs) const
 {

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=133091&r1=133090&r2=133091&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Wed Jun 15 16:24:24 2011
@@ -365,12 +365,8 @@
               - execute any tearDown hooks registered by the test method with
                 TestBase.addTearDownHook(); examples can be found in
                 settings/TestSettings.py
-              - kill the inferior process launched during the test method
-                    - if by 'run' or 'process launch' command, 'process kill'
-                      command is used
-                    - if the test method uses LLDB Python API to launch process,
-                      it should assign the process object to self.process; that
-                      way, tearDown will use self.process.Kill() on the object
+              - kill the inferior process associated with each target, if any,
+                and, then delete the target from the debugger's target list
               - perform build cleanup before running the next test method in the
                 same test class; examples of registering for this service can be
                 found in types/TestIntegerTypes.py with the call:
@@ -537,11 +533,6 @@
         # interpreter.
         self.child_in_script_interpreter = False
 
-        # There is no process associated with the debugger as yet.
-        # See also self.tearDown() where it checks whether self.process has a
-        # valid reference and calls self.process.Kill() to kill the process.
-        self.process = None
-
         # Retrieve the associated command interpreter instance.
         self.ci = self.dbg.GetCommandInterpreter()
         if not self.ci:
@@ -712,13 +703,20 @@
             except:
                 pass
 
-        # Terminate the current process being debugged, if any.
-        if self.runStarted:
-            self.runCmd("process kill", PROCESS_KILLED, check=False)
-        elif self.process:
-            rc = self.invoke(self.process, "Kill")
-            self.assertTrue(rc.Success(), PROCESS_KILLED)
-            del self.process
+        # Delete the target(s) from the debugger as a general cleanup step.
+        # This includes terminating the process for each target, if any.
+        # We'd like to reuse the debugger for our next test without incurring
+        # the initialization overhead.
+        targets = []
+        for target in self.dbg:
+            if target:
+                targets.append(target)
+                process = target.GetProcess()
+                if process:
+                    rc = self.invoke(process, "Kill")
+                    self.assertTrue(rc.Success(), PROCESS_KILLED)
+        for target in targets:
+            self.dbg.DeleteTarget(target)
 
         del self.dbg
         del self.hooks





More information about the lldb-commits mailing list