Rev 2424: C-\ drops bzr into the debugger in http://sourcefrog.net/bzr/breakin

Martin Pool mbp at sourcefrog.net
Tue Apr 17 05:47:00 BST 2007


At http://sourcefrog.net/bzr/breakin

------------------------------------------------------------
revno: 2424
revision-id: mbp at sourcefrog.net-20070417043912-2mwgd3htam3a5uq2
parent: pqm at pqm.ubuntu.com-20070417005930-rofskshyjsfzrahh
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: breakin
timestamp: Tue 2007-04-17 14:39:12 +1000
message:
  C-\ drops bzr into the debugger
added:
  bzrlib/breakin.py              breakin.py-20070417043829-so46nevf978u713k-1
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzr                            bzr.py-20050313053754-5485f144c7006fa6
  bzrlib/tests/blackbox/test_debug.py test_debug.py-20061026142942-q76cgg41785b3mdk-1
=== added file 'bzrlib/breakin.py'
--- a/bzrlib/breakin.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/breakin.py	2007-04-17 04:39:12 +0000
@@ -0,0 +1,17 @@
+# Copyright (C) 2006 Canonical Ltd
+
+import pdb
+import signal
+import sys
+
+def _debug(signal_number, interrupted_frame):
+    sys.stderr.write("** SIGQUIT received, entering debugger\n"
+            "** Type 'c' to continue or 'q' to stop the process\n")
+    pdb.set_trace()
+
+def hook_sigquit():
+    # when sigquit (C-\) is received go into pdb
+    # XXX: is this meaningful on Windows?
+    signal.signal(signal.SIGQUIT, _debug)
+
+

=== modified file 'NEWS'
--- a/NEWS	2007-04-17 00:59:30 +0000
+++ b/NEWS	2007-04-17 04:39:12 +0000
@@ -5,6 +5,10 @@
     * Merge directives can now be supplied as input to `merge` and `pull`,
       like bundles can.  (Aaron Bentley)
 
+    * Sending the SIGQUIT signal to bzr, which can be done on Unix by
+      pressing Control-Backspace, drops bzr into a debugger.  Type `c`
+      to continue.  (Martin Pool)
+
   INTERNALS:
 
     * bzrlib API compatability with 0.8 has been dropped, cleaning up some

=== modified file 'bzr'
--- a/bzr	2007-04-01 06:19:16 +0000
+++ b/bzr	2007-04-17 04:39:12 +0000
@@ -73,6 +73,9 @@
 import bzrlib.lazy_regex
 bzrlib.lazy_regex.install_lazy_compile()
 
+import bzrlib.breakin
+bzrlib.breakin.hook_sigquit()
+
 import bzrlib.decorators
 if ('--lsprof' in sys.argv
     or '--lsprof-file' in sys.argv

=== modified file 'bzrlib/tests/blackbox/test_debug.py'
--- a/bzrlib/tests/blackbox/test_debug.py	2007-03-04 01:47:18 +0000
+++ b/bzrlib/tests/blackbox/test_debug.py	2007-04-17 04:39:12 +0000
@@ -17,8 +17,12 @@
 """Blackbox tests for -D debug options"""
 
 import os
+import signal
+import subprocess
+import sys
+import time
 
-from bzrlib.tests import TestCase
+from bzrlib.tests import TestCase, TestSkipped
 
 class TestDebugOption(TestCase):
 
@@ -30,3 +34,23 @@
         # here but it may be missing if the source is not in sync with the
         # pyc file.
         self.assertContainsRe(err, "Traceback \\(most recent call last\\)")
+
+class TestBreakin(TestCase):
+
+    def test_breakin(self):
+        # Break in to a debugger while bzr is running
+        # we need to test against a command that will wait for 
+        # a while -- bzr serve should do
+        #
+        # this may not work on windows but i don't think this use of signals
+        # will work there
+        if sys.platform == 'win32':
+            raise TestSkipped('breakin signal not tested on win32')
+        proc = self.start_bzr_subprocess(['serve'])
+        time.sleep(.5)
+        os.kill(proc.pid, signal.SIGQUIT)
+        time.sleep(.5)
+        proc.stdin.write('q\n')
+        err = proc.stderr.read()
+        self.assertContainsRe(err, r'entering debugger')
+        proc.wait()




More information about the bazaar-commits mailing list