Skip to content

Commit 381981a

Browse files
encukoupganssle
authored andcommitted
Test GDB tracebacks with various C calling conventions
1 parent 9534a80 commit 381981a

File tree

1 file changed

+42
-31
lines changed

1 file changed

+42
-31
lines changed

Lib/test/test_gdb.py

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ def test_gc(self):
838838
)
839839
self.assertIn('Garbage-collecting', gdb_output)
840840

841+
841842
@unittest.skipIf(python_is_optimized(),
842843
"Python was compiled with optimizations")
843844
# Some older versions of gdb will fail with
@@ -847,38 +848,48 @@ def test_pycfunction(self):
847848
'Verify that "py-bt" displays invocations of PyCFunction instances'
848849
# Various optimizations multiply the code paths by which these are
849850
# called, so test a variety of calling conventions.
850-
for py_name, py_args, c_name, expected_frame_number in (
851-
('gmtime', '', 'time_gmtime', 1), # METH_VARARGS
852-
('len', '[]', 'builtin_len', 1), # METH_O
853-
('locals', '', 'builtin_locals', 1), # METH_NOARGS
854-
('iter', '[]', 'builtin_iter', 1), # METH_FASTCALL
855-
('sorted', '[]', 'builtin_sorted', 1), # METH_FASTCALL|METH_KEYWORDS
851+
for func_name, args, expected_frame in (
852+
('meth_varargs', '', 1),
853+
('meth_varargs_keywords', '', 1),
854+
('meth_o', '[]', 1),
855+
('meth_noargs', '', 1),
856+
('meth_fastcall', '', 1),
857+
('meth_fastcall_keywords', '', 1),
856858
):
857-
with self.subTest(c_name):
858-
cmd = ('from time import gmtime\n' # (not always needed)
859-
'def foo():\n'
860-
f' {py_name}({py_args})\n'
861-
'def bar():\n'
862-
' foo()\n'
863-
'bar()\n')
864-
# Verify with "py-bt":
865-
gdb_output = self.get_stack_trace(
866-
cmd,
867-
breakpoint=c_name,
868-
cmds_after_breakpoint=['bt', 'py-bt'],
869-
)
870-
self.assertIn(f'<built-in method {py_name}', gdb_output)
871-
872-
# Verify with "py-bt-full":
873-
gdb_output = self.get_stack_trace(
874-
cmd,
875-
breakpoint=c_name,
876-
cmds_after_breakpoint=['py-bt-full'],
877-
)
878-
self.assertIn(
879-
f'#{expected_frame_number} <built-in method {py_name}',
880-
gdb_output,
881-
)
859+
for obj in (
860+
'_testcapi',
861+
'_testcapi.MethClass',
862+
'_testcapi.MethClass()',
863+
'_testcapi.MethStatic()',
864+
865+
# XXX: bound methods don't yet give nice tracebacks
866+
# '_testcapi.MethInstance()',
867+
):
868+
with self.subTest(f'{obj}.{func_name}'):
869+
cmd = ('import _testcapi\n' # (not always needed)
870+
'def foo():\n'
871+
f' {obj}.{func_name}({args})\n'
872+
'def bar():\n'
873+
' foo()\n'
874+
'bar()\n')
875+
# Verify with "py-bt":
876+
gdb_output = self.get_stack_trace(
877+
cmd,
878+
breakpoint=func_name,
879+
cmds_after_breakpoint=['bt', 'py-bt'],
880+
)
881+
self.assertIn(f'<built-in method {func_name}', gdb_output)
882+
883+
# Verify with "py-bt-full":
884+
gdb_output = self.get_stack_trace(
885+
cmd,
886+
breakpoint=func_name,
887+
cmds_after_breakpoint=['py-bt-full'],
888+
)
889+
self.assertIn(
890+
f'#{expected_frame} <built-in method {func_name}',
891+
gdb_output,
892+
)
882893

883894
@unittest.skipIf(python_is_optimized(),
884895
"Python was compiled with optimizations")

0 commit comments

Comments
 (0)