[Lldb-commits] [lldb] r112749 - in /lldb/trunk/test: hello_world/TestHelloWorld.py lldbtest.py

Johnny Chen johnny.chen at apple.com
Wed Sep 1 15:08:51 PDT 2010


Author: johnny
Date: Wed Sep  1 17:08:51 2010
New Revision: 112749

URL: http://llvm.org/viewvc/llvm-project?rev=112749&view=rev
Log:
Put the little dances done after SBTarget.LaunchProcess() into the base class.

Modified:
    lldb/trunk/test/hello_world/TestHelloWorld.py
    lldb/trunk/test/lldbtest.py

Modified: lldb/trunk/test/hello_world/TestHelloWorld.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/hello_world/TestHelloWorld.py?rev=112749&r1=112748&r2=112749&view=diff
==============================================================================
--- lldb/trunk/test/hello_world/TestHelloWorld.py (original)
+++ lldb/trunk/test/hello_world/TestHelloWorld.py Wed Sep  1 17:08:51 2010
@@ -18,7 +18,7 @@
         self.buildDsym()
         self.hello_world_python(useLaunchAPI = False)
 
-    @unittest2.expectedFailure
+    #@unittest2.expectedFailure
     def test_with_dwarf_and_process_launch_api(self):
         """Create target, breakpoint, launch a process, and then kill it.
 
@@ -52,38 +52,21 @@
         # SBTarget.LaunchProcess() issue (or is there some race condition)?
 
         if useLaunchAPI:
-            # The following approach of launching a process looks untidy and only
-            # works sometimes.
-            process = target.LaunchProcess([''], [''], os.ctermid(), False)
-
-            SR = process.GetThreadAtIndex(0).GetStopReason()
-            count = 0
-            while SR == StopReasonEnum("Invalid") or SR == StopReasonEnum("Signal"):
-                print >> sys.stderr, "StopReason =", StopReasonString(SR)
-
-                time.sleep(1.0)
-                print >> sys.stderr, "Continuing the process:", process
-                process.Continue()
-
-                count = count + 1
-                if count == 10:
-                    print >> sys.stderr, "Reached 10 iterations, giving up..."
-                    break
-
-                SR = process.GetThreadAtIndex(0).GetStopReason()
+            process = target.LaunchProcess([''], [''], os.ctermid(), 0, False)
+            # Apply some dances after LaunchProcess() in order to break at "main".
+            # It only works sometimes.
+            self.breakAfterLaunch(process, "main")
         else:
             # On the other hand, the following two lines of code are more reliable.
-            self.runCmd("run")
-            process = target.GetProcess()
+            self.runCmd("run", setCookie=False)
 
-        self.runCmd("thread backtrace")
-        self.runCmd("breakpoint list")
-        self.runCmd("thread list")
+        #self.runCmd("thread backtrace")
+        #self.runCmd("breakpoint list")
+        #self.runCmd("thread list")
 
-        # The stop reason of the thread should be breakpoint.
+        process = target.GetProcess()
         thread = process.GetThreadAtIndex(0)
-        
-        print >> sys.stderr, "StopReason =", StopReasonString(thread.GetStopReason())
+
         self.assertTrue(thread.GetStopReason() == StopReasonEnum("Breakpoint"),
                         STOPPED_DUE_TO_BREAKPOINT)
 

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=112749&r1=112748&r2=112749&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Wed Sep  1 17:08:51 2010
@@ -368,7 +368,6 @@
         message.  We expect the output from running the command to start with
         'startstr' and matches the substrings contained in 'substrs'.
         """
-
         trace = (True if traceAlways else trace)
 
         # First run the command.
@@ -398,7 +397,6 @@
 
     def invoke(self, obj, name, trace=False):
         """Use reflection to call a method dynamically with no argument."""
-
         trace = (True if traceAlways else trace)
         
         method = getattr(obj, name)
@@ -410,6 +408,45 @@
             print str(method) + ":",  result
         return result
 
+    def breakAfterLaunch(self, process, func, trace=False):
+        """
+        Perform some dancees after LaunchProcess() to break at func name.
+
+        Return True if we can successfully break at the func name in due time.
+        """
+        trace = (True if traceAlways else trace)
+
+        count = 0
+        while True:
+            # The stop reason of the thread should be breakpoint.
+            thread = process.GetThreadAtIndex(0)
+            SR = thread.GetStopReason()
+            if trace:
+                print >> sys.stderr, "StopReason =", StopReasonString(SR)
+
+            if SR == StopReasonEnum("Breakpoint"):
+                frame = thread.GetFrameAtIndex(0)
+                name = frame.GetFunction().GetName()
+                if (name == func):
+                    # We got what we want; now break out of the loop.
+                    return True
+
+            # The inferior is in a transient state; continue the process.
+            time.sleep(1.0)
+            if trace:
+                print >> sys.stderr, "Continuing the process:", process
+            process.Continue()
+
+            count = count + 1
+            if count == 10:
+                if trace:
+                    print >> sys.stderr, "Reached 10 iterations, giving up..."
+                # Enough iterations already, break out of the loop.
+                return False
+
+            # End of while loop.
+
+
     def buildDsym(self):
         """Platform specific way to build binaries with dsym info."""
         module = __import__(sys.platform)





More information about the lldb-commits mailing list