Rev 2450: Press C-\ to break into pdb in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Apr 24 06:42:52 BST 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2450
revision-id: pqm at pqm.ubuntu.com-20070424054249-bpkw4wwywqjt2nel
parent: pqm at pqm.ubuntu.com-20070424033735-s0igieajv2czb2tt
parent: mbp at sourcefrog.net-20070424050204-bfkc1qiq0axt5f14
committer: Canonical.com Patch Queue Manager<pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2007-04-24 06:42:49 +0100
message:
  Press C-\ to break into pdb
added:
  bzrlib/breakin.py              breakin.py-20070417043829-so46nevf978u713k-1
  bzrlib/tests/blackbox/test_breakin.py test_breakin.py-20070424043903-qyy6zm4pj3h4sbp3-1
modified:
  HACKING                        HACKING-20050805200004-2a5dc975d870f78c
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzr                            bzr.py-20050313053754-5485f144c7006fa6
  bzrlib/tests/blackbox/__init__.py __init__.py-20051128053524-eba30d8255e08dc3
  bzrlib/tests/blackbox/test_debug.py test_debug.py-20061026142942-q76cgg41785b3mdk-1
    ------------------------------------------------------------
    revno: 2423.3.8
    merged: mbp at sourcefrog.net-20070424050204-bfkc1qiq0axt5f14
    parent: mbp at sourcefrog.net-20070424045131-gyjo7l8oa99ndyrv
    parent: pqm at pqm.ubuntu.com-20070424033735-s0igieajv2czb2tt
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: breakin
    timestamp: Tue 2007-04-24 15:02:04 +1000
    message:
      Merge trunk & fix NEWS conflict
    ------------------------------------------------------------
    revno: 2423.3.7
    merged: mbp at sourcefrog.net-20070424045131-gyjo7l8oa99ndyrv
    parent: mbp at sourcefrog.net-20070417092535-n711rw7qtt6irrye
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: breakin
    timestamp: Tue 2007-04-24 14:51:31 +1000
    message:
      Add BZR_SIGQUIT_PDB=0 option to disable breakin.
      
      Split tests for this into test_breakin, and make them a bit more robust.
    ------------------------------------------------------------
    revno: 2423.3.6
    merged: mbp at sourcefrog.net-20070417092535-n711rw7qtt6irrye
    parent: mbp at sourcefrog.net-20070417073222-l20nvpvkfr8ak12d
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: breakin
    timestamp: Tue 2007-04-17 19:25:35 +1000
    message:
      Correct the mention of C-\ in NEWS (Daniel Silverstone)
    ------------------------------------------------------------
    revno: 2423.3.5
    merged: mbp at sourcefrog.net-20070417073222-l20nvpvkfr8ak12d
    parent: mbp at sourcefrog.net-20070417065755-lgvnd360eqfs8cfz
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: breakin
    timestamp: Tue 2007-04-17 17:32:22 +1000
    message:
      Second sigquit goes through to the default handler
    ------------------------------------------------------------
    revno: 2423.3.4
    merged: mbp at sourcefrog.net-20070417065755-lgvnd360eqfs8cfz
    parent: mbp at sourcefrog.net-20070417065314-r4zeer3hcw8j77rw
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: breakin
    timestamp: Tue 2007-04-17 16:57:55 +1000
    message:
      Late load pdb for breakin; fix copyright
    ------------------------------------------------------------
    revno: 2423.3.3
    merged: mbp at sourcefrog.net-20070417065314-r4zeer3hcw8j77rw
    parent: mbp at sourcefrog.net-20070417052419-x9erzvt3xtzuhdvf
    parent: mbp at sourcefrog.net-20070417065102-zabhms9y28q2ik00
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: breakin
    timestamp: Tue 2007-04-17 16:53:14 +1000
    message:
      merge benchmark fix
    ------------------------------------------------------------
    revno: 2423.3.2
    merged: mbp at sourcefrog.net-20070417052419-x9erzvt3xtzuhdvf
    parent: mbp at sourcefrog.net-20070417043912-2mwgd3htam3a5uq2
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: breakin
    timestamp: Tue 2007-04-17 15:24:19 +1000
    message:
      doc BZR_PDB and sigquit
    ------------------------------------------------------------
    revno: 2423.3.1
    merged: 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 file 'bzrlib/breakin.py'
--- a/bzrlib/breakin.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/breakin.py	2007-04-24 04:51:31 +0000
@@ -0,0 +1,41 @@
+# Copyright (C) 2006, 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import os
+import signal
+
+def _debug(signal_number, interrupted_frame):
+    import pdb
+    import sys
+    sys.stderr.write("** SIGQUIT received, entering debugger\n"
+            "** Type 'c' to continue or 'q' to stop the process\n"
+            "** Or SIGQUIT again to quit (and possibly dump core)\n"
+            )
+    # restore default meaning so that you can kill the process by hitting it
+    # twice
+    signal.signal(signal.SIGQUIT, signal.SIG_DFL)
+    try:
+        pdb.set_trace()
+    finally:
+        signal.signal(signal.SIGQUIT, _debug)
+
+
+def hook_sigquit():
+    # when sigquit (C-\) is received go into pdb
+    # XXX: is this meaningful on Windows?
+    if os.environ.get('BZR_SIGQUIT_PDB', '1') == '0':
+        return
+    signal.signal(signal.SIGQUIT, _debug)

=== added file 'bzrlib/tests/blackbox/test_breakin.py'
--- a/bzrlib/tests/blackbox/test_breakin.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/blackbox/test_breakin.py	2007-04-24 04:51:31 +0000
@@ -0,0 +1,74 @@
+# Copyright (C) 2006, 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Blackbox tests for debugger breakin"""
+
+import os
+import signal
+import subprocess
+import sys
+import time
+
+from bzrlib.tests import TestCase, TestSkipped
+
+
+class TestBreakin(TestCase):
+    # FIXME: If something is broken, these tests may just hang indefinitely in
+    # wait() waiting for the child to exit when it's not going to.
+
+    def setUp(self):
+        if sys.platform == 'win32':
+            raise TestSkipped('breakin signal not tested on win32')
+        super(TestBreakin, self).setUp()
+
+    # port 0 means to allocate any port
+    _test_process_args = ['serve', '--port', 'localhost:0']
+
+    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
+        proc = self.start_bzr_subprocess(self._test_process_args,
+                env_changes=dict(BZR_SIGQUIT_PDB=None))
+        # wait for it to get started, and print the 'listening' line
+        proc.stdout.readline()
+        # first sigquit pops into debugger
+        os.kill(proc.pid, signal.SIGQUIT)
+        proc.stdin.write("q\n")
+        time.sleep(.5)
+        err = proc.stderr.readline()
+        self.assertContainsRe(err, r'entering debugger')
+
+    def test_breakin_harder(self):
+        proc = self.start_bzr_subprocess(self._test_process_args,
+                env_changes=dict(BZR_SIGQUIT_PDB=None))
+        # wait for it to get started, and print the 'listening' line
+        proc.stdout.readline()
+        # another hit gives the default behaviour of terminating it
+        os.kill(proc.pid, signal.SIGQUIT)
+        # wait for it to go into pdb
+        time.sleep(.5)
+        os.kill(proc.pid, signal.SIGQUIT)
+        proc.wait()
+
+    def test_breakin_disabled(self):
+        proc = self.start_bzr_subprocess(self._test_process_args,
+                env_changes=dict(BZR_SIGQUIT_PDB='0'))
+        # wait for it to get started, and print the 'listening' line
+        proc.stdout.readline()
+        # first hit should just kill it
+        os.kill(proc.pid, signal.SIGQUIT)
+        proc.wait()

=== modified file 'HACKING'
--- a/HACKING	2007-04-24 02:43:56 +0000
+++ b/HACKING	2007-04-24 05:02:04 +0000
@@ -493,6 +493,25 @@
 
 
 
+Debugging
+=========
+
+Bazaar has a few facilities to help debug problems by going into pdb_, the
+Python debugger.
+
+.. _pdb: http://docs.python.org/lib/debugger-commands.html
+
+If the ``BZR_PDB`` environment variable is set 
+then bzr will go into pdb post-mortem mode when an unhandled exception
+occurs.
+
+If you send a SIGQUIT signal to bzr, which can be done by pressing C-\ on Unix,
+bzr will go into the debugger immediately.  You can continue execution by
+typing ``c``.  This can be disabled if necessary by setting the
+environment variable ``BZR_SIGQUIT_PDB=0``.
+
+
+
 Jargon
 ======
 

=== modified file 'NEWS'
--- a/NEWS	2007-04-24 02:43:56 +0000
+++ b/NEWS	2007-04-24 05:02:04 +0000
@@ -5,6 +5,11 @@
     * 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-Backslash, drops bzr into a debugger.  Type `c`
+      to continue.  This can be disabled by setting the environment variable
+      BZR_SIGQUIT_PDB=0.  (Martin Pool)
+
     * selftest now supports --list-only to list tests instead of running
       them. (Ian Clatworthy)
 

=== 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/__init__.py'
--- a/bzrlib/tests/blackbox/__init__.py	2007-04-10 21:05:17 +0000
+++ b/bzrlib/tests/blackbox/__init__.py	2007-04-24 04:51:31 +0000
@@ -44,6 +44,7 @@
                      'bzrlib.tests.blackbox.test_annotate',
                      'bzrlib.tests.blackbox.test_branch',
                      'bzrlib.tests.blackbox.test_break_lock',
+                     'bzrlib.tests.blackbox.test_breakin',
                      'bzrlib.tests.blackbox.test_bound_branches',
                      'bzrlib.tests.blackbox.test_bundle',
                      'bzrlib.tests.blackbox.test_cat',

=== 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-24 04:51:31 +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):
 




More information about the bazaar-commits mailing list