Add a test directory stop-hook to test the newly added "target stop-hook" command.
This uses pexpect module to spawn a 'lldb' program and uses pseudo-TTY to talk to
the child application.

The test cases test setting breakpoints, adding a stop-hook with line range, and
verifies that when the inferior stops, the stop-hook will fire off when it is
within range and will not fire off when it is out of range.


git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@127519 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/lldbtest.py b/test/lldbtest.py
index dab2717..cba495b 100644
--- a/test/lldbtest.py
+++ b/test/lldbtest.py
@@ -523,6 +523,10 @@
         # We want our debugger to be synchronous.
         self.dbg.SetAsync(False)
 
+        # This is for the case of directly spawning 'lldb' and interacting with it
+        # using pexpect.
+        self.child = None
+
         # 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.
@@ -658,6 +662,12 @@
                 print >> sbuf, "Executing tearDown hook:", getsource_if_available(hook)
             hook()
 
+        # This is for the case of directly spawning 'lldb' and interacting with it
+        # using pexpect.
+        if self.child and self.child.isalive():
+            self.child.sendline('quit')
+            self.child.close()
+
         # Terminate the current process being debugged, if any.
         if self.runStarted:
             self.runCmd("process kill", PROCESS_KILLED, check=False)
@@ -916,3 +926,9 @@
         err.write('\t' + "IsPointerType -> " + str(val.TypeIsPointerType()) + '\n')
         err.write('\t' + "Location      -> " + val.GetLocation(frame)       + '\n')
 
+    def DebugPExpect(self, child):
+        """Debug the spwaned pexpect object."""
+        if not traceAlways:
+            return
+
+        print child