Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-91960: Skip test_gdb if gdb cannot retrive Python frames
Skip test_gdb if gdb is unable to retrieve Python frame objects: if a
frame is "<optimized out>". When Python is built with "clang -Og",
gdb can fail to retrive the 'frame' parameter of
_PyEval_EvalFrameDefault(). In this case, tests like py_bt() are
likely to fail. Without getting access to Python frames,
python-gdb.py is mostly clueless on retrieving the Python traceback.
Moreover, test_gdb is no longer skipped on macOS if Python is built
with Clang.
  • Loading branch information
vstinner committed Sep 6, 2023
commit 66a5f76ed50a79aa5d1b0ac484ee06491716606b
7 changes: 3 additions & 4 deletions Lib/test/test_gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ def get_gdb_version():
if not sysconfig.is_python_build():
raise unittest.SkipTest("test_gdb only works on source builds at the moment.")

if 'Clang' in platform.python_compiler() and sys.platform == 'darwin':
raise unittest.SkipTest("test_gdb doesn't work correctly when python is"
" built with LLVM clang")

if ((sysconfig.get_config_var('PGO_PROF_USE_FLAG') or 'xxx') in
(sysconfig.get_config_var('PY_CORE_CFLAGS') or '')):
raise unittest.SkipTest("test_gdb is not reliable on PGO builds")
Expand Down Expand Up @@ -247,6 +243,9 @@ def get_stack_trace(self, source=None, script=None,
for pattern in (
'(frame information optimized out)',
'Unable to read information on python frame',
# gh-91960: On Python built with "clang -Og", gdb gets
# "frame=<optimized out>" for _PyEval_EvalFrameDefault() parameter
'(unable to read python frame information)',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why libpython.py prints this rather than "Unable to read information on python frame"? It's possible that there are just some spots that you missed back in #19081

I'm also afraid that this speaks of a fragility of this approach. When optimizations are enabled, it's not easy to predict exactly what is going to be missing. But I'm happy that this allows to re-enable tests on platforms that were entirely ignored.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why libpython.py prints this rather than "Unable to read information on python frame"? It's possible that there are just some spots that you missed back in #19081

It's likely possible to unify python-gdb.py logs, or use a different regex to match both cases :-) The (unable to read ...) format is for py-bt command. Depending on the command, the log is displayed differently. I took the lazy way of just matching the two strings.

):
if pattern in out:
raise unittest.SkipTest(f"{pattern!r} found in gdb output")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Skip ``test_gdb`` if gdb is unable to retrieve Python frame objects: if a
frame is ``<optimized out>``. When Python is built with "clang -Og", gdb can
fail to retrive the *frame* parameter of ``_PyEval_EvalFrameDefault()``. In
this case, tests like ``py_bt()`` are likely to fail. Without getting access
to Python frames, ``python-gdb.py`` is mostly clueless on retrieving the
Python traceback. Moreover, ``test_gdb`` is no longer skipped on macOS if
Python is built with Clang. Patch by Victor Stinner.