Rev 2430: Add BZR_SIGQUIT_PDB=0 option to disable breakin. in http://sourcefrog.net/bzr/breakin
Martin Pool
mbp at sourcefrog.net
Tue Apr 24 05:51:33 BST 2007
At http://sourcefrog.net/bzr/breakin
------------------------------------------------------------
revno: 2430
revision-id: 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.
added:
bzrlib/tests/blackbox/test_breakin.py test_breakin.py-20070424043903-qyy6zm4pj3h4sbp3-1
modified:
HACKING HACKING-20050805200004-2a5dc975d870f78c
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/breakin.py breakin.py-20070417043829-so46nevf978u713k-1
bzrlib/tests/blackbox/__init__.py __init__.py-20051128053524-eba30d8255e08dc3
bzrlib/tests/blackbox/test_debug.py test_debug.py-20061026142942-q76cgg41785b3mdk-1
=== 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-17 05:24:19 +0000
+++ b/HACKING 2007-04-24 04:51:31 +0000
@@ -481,7 +481,7 @@
Bazaar has a few facilities to help debug problems by going into pdb_, the
Python debugger.
-http://docs.python.org/lib/debugger-commands.html
+.. _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
@@ -489,7 +489,8 @@
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``.
+typing ``c``. This can be disabled if necessary by setting the
+environment variable ``BZR_SIGQUIT_PDB=0``.
=== modified file 'NEWS'
--- a/NEWS 2007-04-17 09:25:35 +0000
+++ b/NEWS 2007-04-24 04:51:31 +0000
@@ -7,7 +7,8 @@
* 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. (Martin Pool)
+ to continue. This can be disabled by setting the environment variable
+ BZR_SIGQUIT_PDB=0. (Martin Pool)
INTERNALS:
=== modified file 'bzrlib/breakin.py'
--- a/bzrlib/breakin.py 2007-04-17 07:32:22 +0000
+++ b/bzrlib/breakin.py 2007-04-24 04:51:31 +0000
@@ -14,6 +14,7 @@
# 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):
@@ -23,12 +24,18 @@
"** 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)
- pdb.set_trace()
- signal.signal(signal.SIGQUIT, _debug)
+ 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)
=== 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-04-17 07:32:22 +0000
+++ b/bzrlib/tests/blackbox/test_debug.py 2007-04-24 04:51:31 +0000
@@ -34,37 +34,3 @@
# 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'])
- # wait for it to get started
- time.sleep(.5)
- # 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):
- if sys.platform == 'win32':
- raise TestSkipped('breakin signal not tested on win32')
- proc = self.start_bzr_subprocess(['serve'])
- # wait for it to get started
- time.sleep(.5)
- # 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()
More information about the bazaar-commits
mailing list