[Lldb-commits] [lldb] r133279 - in /lldb/trunk: source/API/SBTarget.cpp test/hello_world/TestHelloWorld.py

Johnny Chen johnny.chen at apple.com
Fri Jun 17 12:21:30 PDT 2011


Author: johnny
Date: Fri Jun 17 14:21:30 2011
New Revision: 133279

URL: http://llvm.org/viewvc/llvm-project?rev=133279&view=rev
Log:
Add a bunch of test cases to TestHelloWorld.py to exercise combinations of dwarf/dsym debug setup.
Among them are test cases to exercise SBTarget.AttachToProcessWithName(); we attach to "hello_world",
and verify that, after attachment, the currently selected target indeed matches "hello_world".

Modified:
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/test/hello_world/TestHelloWorld.py

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=133279&r1=133278&r2=133279&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Fri Jun 17 14:21:30 2011
@@ -330,6 +330,10 @@
         if (sb_process.IsValid())
         {
             error.SetError (sb_process->Attach (name, wait_for));
+            // If we are doing synchronous mode, then wait for the
+            // process to stop!
+            if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
+                sb_process->WaitForProcessToStop (NULL);
         }
         else
         {

Modified: lldb/trunk/test/hello_world/TestHelloWorld.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/hello_world/TestHelloWorld.py?rev=133279&r1=133278&r2=133279&view=diff
==============================================================================
--- lldb/trunk/test/hello_world/TestHelloWorld.py (original)
+++ lldb/trunk/test/hello_world/TestHelloWorld.py Fri Jun 17 14:21:30 2011
@@ -1,4 +1,4 @@
-"""Test Python APIs for target, breakpoint, and process."""
+"""Test Python APIs for target (launch and attach), breakpoint, and process."""
 
 import os, sys, time
 import unittest2
@@ -18,23 +18,70 @@
         self.buildDsym()
         self.hello_world_python(useLaunchAPI = False)
 
+    def test_with_dwarf_and_run_command(self):
+        """Create target, breakpoint, launch a process, and then kill it.
+
+        Use dwarf debug map and lldb "run" command.
+        """
+        self.buildDwarf()
+        self.hello_world_python(useLaunchAPI = False)
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    @python_api_test
+    def test_with_dsym_and_process_launch_api(self):
+        """Create target, breakpoint, launch a process, and then kill it.
+
+        Use dsym info and process launch API.
+        """
+        self.buildDsym()
+        self.hello_world_python(useLaunchAPI = True)
+
     @python_api_test
     def test_with_dwarf_and_process_launch_api(self):
         """Create target, breakpoint, launch a process, and then kill it.
 
-        Use dwarf map (no dsym) and process launch API.
+        Use dwarf debug map and process launch API.
         """
         self.buildDwarf()
         self.hello_world_python(useLaunchAPI = True)
 
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    @python_api_test
+    def test_with_dsym_and_attach_to_process_with_id_api(self):
+        """Create target, breakpoint, spawn a process, and attach to it with process id.
+
+        Use dsym info and attach to process with id API.
+        """
+        self.buildDsym()
+        self.hello_world_attach_with_id_api()
+
     @python_api_test
     def test_with_dwarf_and_attach_to_process_with_id_api(self):
-        """Create target, breakpoint, spawn a process, and attach to it.
+        """Create target, breakpoint, spawn a process, and attach to it with process id.
 
         Use dwarf map (no dsym) and attach to process with id API.
         """
         self.buildDwarf()
-        self.hello_world_attach_api()
+        self.hello_world_attach_with_id_api()
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    @python_api_test
+    def test_with_dsym_and_attach_to_process_with_name_api(self):
+        """Create target, breakpoint, spawn a process, and attach to it with process name.
+
+        Use dsym info and attach to process with name API.
+        """
+        self.buildDsym()
+        self.hello_world_attach_with_name_api()
+
+    @python_api_test
+    def test_with_dwarf_and_attach_to_process_with_name_api(self):
+        """Create target, breakpoint, spawn a process, and attach to it with process name.
+
+        Use dwarf map (no dsym) and attach to process with name API.
+        """
+        self.buildDwarf()
+        self.hello_world_attach_with_name_api()
 
     def setUp(self):
         # Call super's setUp().
@@ -90,8 +137,8 @@
         # The breakpoint should have a hit count of 1.
         self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)
 
-    def hello_world_attach_api(self):
-        """Create target, breakpoint, spawn a process, and attach to it."""
+    def hello_world_attach_with_id_api(self):
+        """Create target, breakpoint, spawn a process, and attach to it by id."""
 
         target = self.dbg.CreateTarget(self.exe)
 
@@ -113,6 +160,35 @@
             substrs = ['main.c:%d' % self.line2,
                        '(int)argc=3'])
 
+    def hello_world_attach_with_name_api(self):
+        """Create target, breakpoint, spawn a process, and attach to it by name."""
+
+        target = self.dbg.CreateTarget(self.exe)
+
+        # Spawn a new process.
+        import subprocess
+        popen = subprocess.Popen([self.exe, "abc", "xyz"])
+        #print "pid of spawned process: %d" % popen.pid
+
+        listener = lldb.SBListener("my.attach.listener")
+        error = lldb.SBError()
+        # Pass 'False' since we don't want to wait for new instance of "hello_world" to be launched.
+        name = os.path.basename(self.exe)
+        process = target.AttachToProcessWithName(listener, name, False, error)
+
+        self.assertTrue(process, PROCESS_IS_VALID)
+
+        # Verify that after attach, our selected target indeed matches name.
+        self.expect(self.dbg.GetSelectedTarget().GetExecutable().GetFilename(), exe=False,
+            startstr = name)
+
+        # Let's check the stack traces of the attached process.
+        import lldbutil
+        stacktraces = lldbutil.print_stacktraces(process, string_buffer=True)
+        self.expect(stacktraces, exe=False,
+            substrs = ['main.c:%d' % self.line2,
+                       '(int)argc=3'])
+
 
 if __name__ == '__main__':
     import atexit





More information about the lldb-commits mailing list