diff -r f5a7d413638d Lib/test/test_gdb.py --- a/Lib/test/test_gdb.py Thu Jul 21 19:41:04 2011 +0200 +++ b/Lib/test/test_gdb.py Thu Jul 21 17:00:03 2011 -0400 @@ -639,6 +639,64 @@ foo\(1, 2, 3\) ''') + def test_threads(self): + 'Verify that "py-bt" indicates threads that are waiting for the GIL' + cmd = ''' +from threading import Thread + +class TestThread(Thread): + # These threads would run forever, but we'll interrupt things with the + # debugger + def run(self): + i = 0 + while 1: + i += 1 + +t = {} +for i in range(4): + t[i] = TestThread() + t[i].start() + +# Trigger a breakpoint on the main thread +id(42) + +''' + # Verify with "py-bt": + gdb_output = self.get_stack_trace(cmd, import_site=True, + breakpoint='builtin_id', + cmds_after_breakpoint=['thread apply all py-bt']) + self.assertIn('Waiting for a lock', gdb_output) + + def test_gc(self): + 'Verify that "py-bt" indicates if a thread is garbage-collecting' + cmd = ('from gc import collect\n' + 'id(42)\n' + 'def foo():\n' + ' collect()\n' + 'def bar():\n' + ' foo()\n' + 'bar()\n') + # Verify with "py-bt": + gdb_output = self.get_stack_trace(cmd, import_site=True, + breakpoint='builtin_id', + cmds_after_breakpoint=['break update_refs', 'continue', 'py-bt']) + self.assertIn('Garbage-collecting', gdb_output) + + def test_pycfunction(self): + 'Verify that "py-bt" displays invocations of PyCFunction instances' + cmd = ('from time import sleep\n' + 'def foo():\n' + ' sleep(1)\n' + 'def bar():\n' + ' foo()\n' + 'bar()\n') + # Verify with "py-bt": + gdb_output = self.get_stack_trace(cmd, import_site=True, + breakpoint='time_sleep', + cmds_after_breakpoint=['py-bt']) + self.assertIn('#0