[Python-checkins] bpo-46600: Fix test_gdb.test_pycfunction() for clang -Og (GH-31058)

vstinner webhook-mailer at python.org
Tue Feb 1 12:12:36 EST 2022


https://github.com/python/cpython/commit/bebaa95fd0f44babf8b6bcffd8f2908c73ca259e
commit: bebaa95fd0f44babf8b6bcffd8f2908c73ca259e
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-02-01T18:12:26+01:00
summary:

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.

files:
A Misc/NEWS.d/next/Tests/2022-02-01-17-13-53.bpo-46600.FMCk8Z.rst
M Lib/test/test_gdb.py

diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py
index eaeb6fb8ff568..344fd3dd3f7fc 100644
--- a/Lib/test/test_gdb.py
+++ b/Lib/test/test_gdb.py
@@ -897,15 +897,19 @@ def test_gc(self):
     # to suppress these. See also the comment in DebuggerTests.get_stack_trace
     def test_pycfunction(self):
         '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
         # called, so test a variety of calling conventions.
-        for func_name, args, expected_frame in (
-            ('meth_varargs', '', 1),
-            ('meth_varargs_keywords', '', 1),
-            ('meth_o', '[]', 1),
-            ('meth_noargs', '', 1),
-            ('meth_fastcall', '', 1),
-            ('meth_fastcall_keywords', '', 1),
+        for func_name, args in (
+            ('meth_varargs', ''),
+            ('meth_varargs_keywords', ''),
+            ('meth_o', '[]'),
+            ('meth_noargs', ''),
+            ('meth_fastcall', ''),
+            ('meth_fastcall_keywords', ''),
         ):
             for obj in (
                 '_testcapi',
@@ -945,10 +949,9 @@ def bar():
                         # defined.' message in stderr.
                         ignore_stderr=True,
                     )
-                    self.assertIn(
-                        f'#{expected_frame} <built-in method {func_name}',
-                        gdb_output,
-                    )
+                    regex = expected_frame
+                    regex += re.escape(f' <built-in method {func_name}')
+                    self.assertRegex(gdb_output, regex)
 
     @unittest.skipIf(python_is_optimized(),
                      "Python was compiled with optimizations")
diff --git a/Misc/NEWS.d/next/Tests/2022-02-01-17-13-53.bpo-46600.FMCk8Z.rst b/Misc/NEWS.d/next/Tests/2022-02-01-17-13-53.bpo-46600.FMCk8Z.rst
new file mode 100644
index 0000000000000..0ae1d4d181d42
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2022-02-01-17-13-53.bpo-46600.FMCk8Z.rst
@@ -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.



More information about the Python-checkins mailing list