Skip to content

Commit bebaa95

Browse files
authored
bpo-46600: Fix test_gdb.test_pycfunction() for clang -Og (GH-31058)
Fix test_gdb.test_pycfunction() for Python built with clang -Og. Tolerate inlined functions in the gdb traceback. When _testcapimodule.c is built by clang -Og, _null_to_none() is inlined in meth_varargs() and so gdb returns _null_to_none() as the frame #1. If it's not inlined, meth_varargs() is the frame #1.
1 parent f78be59 commit bebaa95

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

Lib/test/test_gdb.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -897,15 +897,19 @@ def test_gc(self):
897897
# to suppress these. See also the comment in DebuggerTests.get_stack_trace
898898
def test_pycfunction(self):
899899
'Verify that "py-bt" displays invocations of PyCFunction instances'
900+
# bpo-46600: If the compiler inlines _null_to_none() in meth_varargs()
901+
# (ex: clang -Og), _null_to_none() is the frame #1. Otherwise,
902+
# meth_varargs() is the frame #1.
903+
expected_frame = r'#(1|2)'
900904
# Various optimizations multiply the code paths by which these are
901905
# called, so test a variety of calling conventions.
902-
for func_name, args, expected_frame in (
903-
('meth_varargs', '', 1),
904-
('meth_varargs_keywords', '', 1),
905-
('meth_o', '[]', 1),
906-
('meth_noargs', '', 1),
907-
('meth_fastcall', '', 1),
908-
('meth_fastcall_keywords', '', 1),
906+
for func_name, args in (
907+
('meth_varargs', ''),
908+
('meth_varargs_keywords', ''),
909+
('meth_o', '[]'),
910+
('meth_noargs', ''),
911+
('meth_fastcall', ''),
912+
('meth_fastcall_keywords', ''),
909913
):
910914
for obj in (
911915
'_testcapi',
@@ -945,10 +949,9 @@ def bar():
945949
# defined.' message in stderr.
946950
ignore_stderr=True,
947951
)
948-
self.assertIn(
949-
f'#{expected_frame} <built-in method {func_name}',
950-
gdb_output,
951-
)
952+
regex = expected_frame
953+
regex += re.escape(f' <built-in method {func_name}')
954+
self.assertRegex(gdb_output, regex)
952955

953956
@unittest.skipIf(python_is_optimized(),
954957
"Python was compiled with optimizations")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix test_gdb.test_pycfunction() for Python built with ``clang -Og``.
2+
Tolerate inlined functions in the gdb traceback. Patch by Victor Stinner.

0 commit comments

Comments
 (0)