This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: test_gdb should better detect when Python is optimized
Type: Stage: resolved
Components: Tests Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, vstinner
Priority: normal Keywords: patch

Created on 2020-03-19 23:20 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19081 merged vstinner, 2020-03-19 23:30
PR 19255 merged miss-islington, 2020-03-31 17:10
PR 19256 merged miss-islington, 2020-03-31 17:10
Messages (7)
msg364640 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-19 23:20
On my PR 19077 which changes Python/ceval.c, test_gdb fails on Travis CI with Python compiled with clang -Og.

The -Og optimization level is a compromise between performance and the ability to debug Python. The problem is that gdb fails to retrieve some information and so test_gdb fails.

I proposed bpo-38350 "./configure --with-pydebug should use -O0 rather than -Og", but the status quo is to continue to use -Og by default.

See examples of test_gdb failures from PR 19077 below.

I propose to skip a test if one of the follow pattern is found in gdb output:

* '<optimized out>',
* '(frame information optimized out)',
* 'Unable to read information on python frame',

======================================================================
FAIL: test_basic_command (test.test_gdb.PyListTests)
Verify that the "py-list" command works
----------------------------------------------------------------------
(...)

AssertionError: (...)

'Breakpoint 1 at 0x5aabf1: file Python/bltinmodule.c, line 1173.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, builtin_id (self=, v=42) at Python/bltinmodule.c:1173
1173\t    PyObject *id = PyLong_FromVoidPtr(v);
Unable to read information on python frame
'

did not end with

'   5
   6    def bar(a, b, c):
   7        baz(a, b, c)
   8
   9    def baz(*args):
 >10        id(42)
  11
  12    foo(1, 2, 3)
'


======================================================================
FAIL: test_bt (test.test_gdb.PyBtTests)
Verify that the "py-bt" command works
----------------------------------------------------------------------
(...)
AssertionError:

'Breakpoint 1 at 0x5aabf1: file Python/bltinmodule.c, line 1173.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, builtin_id (self=, v=42) at Python/bltinmodule.c:1173
1173\t    PyObject *id = PyLong_FromVoidPtr(v);
Traceback (most recent call first):
  <built-in method id of module object at remote 0x7ffff7f87050>
  (frame information optimized out)
  File "/home/travis/build/python/cpython/Lib/test/gdb_sample.py", line 7, in bar
    baz(a, b, c)
  File "/home/travis/build/python/cpython/Lib/test/gdb_sample.py", line 4, in foo
    bar(a, b, c)
  (frame information optimized out)
'

did not match

'^.*
Traceback \\(most recent call first\\):
  <built-in method id of module object .*>
  File ".*gdb_sample.py", line 10, in baz
    id\\(42\\)
  File ".*gdb_sample.py", line 7, in bar
    baz\\(a, b, c\\)
  File ".*gdb_sample.py", line 4, in foo
    bar\\(a, b, c\\)
  File ".*gdb_sample.py", line 12, in <module>
    foo\\(1, 2, 3\\)
'
msg364650 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-20 07:23
New changeset 7bf069b6110278102c8f4719975a5eb5a5af25f9 by Victor Stinner in branch 'master':
bpo-40019: Skip test_gdb if Python was optimized (GH-19081)
https://github.com/python/cpython/commit/7bf069b6110278102c8f4719975a5eb5a5af25f9
msg364660 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-20 08:30
The fix works as expected: test_gdb passed on PR 19077. Well, likely because a few tests have been skipped. I don't think that in test_gdb can do better than skipping the test if gdb fails to read debug information.
msg365400 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-31 17:15
We have this issue in Fedora Rawhide. test_gdb of Python 3.8 fails on s390x and armv7hl architectures with GCC 10:
https://bugzilla.redhat.com/show_bug.cgi?id=1818857

I tested manually that my change fix test_gdb: tests are skipped as expected:
https://src.fedoraproject.org/rpms/python3/pull-request/182

So I backported the change to 3.7 and 3.8.

This change only fix test_gdb. To get a fully working python-gdb.py, IMHO the best is to disable all compiler optimization using -O0 optimization level.
msg365404 - (view) Author: miss-islington (miss-islington) Date: 2020-03-31 17:27
New changeset 4ced9a7611ddfd923bd8f72aa61121d0e5aeb8fc by Miss Islington (bot) in branch '3.8':
bpo-40019: Skip test_gdb if Python was optimized (GH-19081)
https://github.com/python/cpython/commit/4ced9a7611ddfd923bd8f72aa61121d0e5aeb8fc
msg365405 - (view) Author: miss-islington (miss-islington) Date: 2020-03-31 17:28
New changeset a764a1cc663708361300cdf88fcf697633142319 by Miss Islington (bot) in branch '3.7':
bpo-40019: Skip test_gdb if Python was optimized (GH-19081)
https://github.com/python/cpython/commit/a764a1cc663708361300cdf88fcf697633142319
msg365407 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-31 17:31
Ok, test_gdb should now be more reliable with various compilers and compiler optimization levels.

I chose to not skip a test if '<optimized out>' is found in the gdb output. If it becomes an issue, test_gdb can easily be modified to also be skipped in this case.
History
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84200
2020-03-31 17:31:29vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg365407

stage: patch review -> resolved
2020-03-31 17:28:39miss-islingtonsetmessages: + msg365405
2020-03-31 17:27:48miss-islingtonsetmessages: + msg365404
2020-03-31 17:15:52vstinnersetmessages: + msg365400
2020-03-31 17:10:58miss-islingtonsetpull_requests: + pull_request18614
2020-03-31 17:10:29miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request18613
2020-03-20 08:30:59vstinnersetmessages: + msg364660
2020-03-20 07:23:39vstinnersetmessages: + msg364650
2020-03-19 23:30:59vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request18440
2020-03-19 23:20:34vstinnercreate