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.
This commit is contained in:
Victor Stinner 2022-02-01 18:12:26 +01:00 committed by GitHub
parent f78be59c83
commit bebaa95fd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 11 deletions

View file

@ -897,15 +897,19 @@ id(42)
# to suppress these. See also the comment in DebuggerTests.get_stack_trace # to suppress these. See also the comment in DebuggerTests.get_stack_trace
def test_pycfunction(self): def test_pycfunction(self):
'Verify that "py-bt" displays invocations of PyCFunction instances' 'Verify that "py-bt" displays invocations of PyCFunction instances'
# bpo-46600: If the compiler inlines _null_to_none() in meth_varargs()
# (ex: clang -Og), _null_to_none() is the frame #1. Otherwise,
# meth_varargs() is the frame #1.
expected_frame = r'#(1|2)'
# Various optimizations multiply the code paths by which these are # Various optimizations multiply the code paths by which these are
# called, so test a variety of calling conventions. # called, so test a variety of calling conventions.
for func_name, args, expected_frame in ( for func_name, args in (
('meth_varargs', '', 1), ('meth_varargs', ''),
('meth_varargs_keywords', '', 1), ('meth_varargs_keywords', ''),
('meth_o', '[]', 1), ('meth_o', '[]'),
('meth_noargs', '', 1), ('meth_noargs', ''),
('meth_fastcall', '', 1), ('meth_fastcall', ''),
('meth_fastcall_keywords', '', 1), ('meth_fastcall_keywords', ''),
): ):
for obj in ( for obj in (
'_testcapi', '_testcapi',
@ -945,10 +949,9 @@ id(42)
# defined.' message in stderr. # defined.' message in stderr.
ignore_stderr=True, ignore_stderr=True,
) )
self.assertIn( regex = expected_frame
f'#{expected_frame} <built-in method {func_name}', regex += re.escape(f' <built-in method {func_name}')
gdb_output, self.assertRegex(gdb_output, regex)
)
@unittest.skipIf(python_is_optimized(), @unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations") "Python was compiled with optimizations")

View file

@ -0,0 +1,2 @@
Fix test_gdb.test_pycfunction() for Python built with ``clang -Og``.
Tolerate inlined functions in the gdb traceback. Patch by Victor Stinner.