Repository navigation
test_pdb crashes when run after test_sys_settrace #108976
Copy link
Copy link
Closed
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixesrelease-blockertestsTests in the Lib/test dirTests in the Lib/test dirtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Description
Crash report
Just run two tests sequentially:
$ ./python -m test -v test_sys_settrace test_pdb
...
test_pdb_breakpoints_preserved_across_interactive_sessions (test.test_pdb)
Doctest: test.test_pdb.test_pdb_breakpoints_preserved_across_interactive_sessions ... python: Python/instrumentation.c:1293: _Py_call_instrumentation_instruction: Assertion `next_opcode != 0' failed.
Fatal Python error: Aborted
Current thread 0x00007fba31132740 (most recent call first):
File "<string>", line 1 in <module>
File "/home/serhiy/py/cpython/Lib/bdb.py", line 600 in run
File "/home/serhiy/py/cpython/Lib/pdb.py", line 1962 in run
File "<doctest test.test_pdb.test_pdb_breakpoints_preserved_across_interactive_sessions[3]>", line 7 in <module>
File "/home/serhiy/py/cpython/Lib/doctest.py", line 1374 in __run
File "/home/serhiy/py/cpython/Lib/doctest.py", line 1524 in run
File "/home/serhiy/py/cpython/Lib/doctest.py", line 2244 in runTest
File "/home/serhiy/py/cpython/Lib/unittest/case.py", line 589 in _callTestMethod
File "/home/serhiy/py/cpython/Lib/unittest/case.py", line 634 in run
File "/home/serhiy/py/cpython/Lib/unittest/case.py", line 690 in __call__
File "/home/serhiy/py/cpython/Lib/unittest/suite.py", line 122 in run
File "/home/serhiy/py/cpython/Lib/unittest/suite.py", line 84 in __call__
File "/home/serhiy/py/cpython/Lib/unittest/suite.py", line 122 in run
File "/home/serhiy/py/cpython/Lib/unittest/suite.py", line 84 in __call__
File "/home/serhiy/py/cpython/Lib/unittest/suite.py", line 122 in run
File "/home/serhiy/py/cpython/Lib/unittest/suite.py", line 84 in __call__
File "/home/serhiy/py/cpython/Lib/unittest/runner.py", line 240 in run
File "/home/serhiy/py/cpython/Lib/test/support/__init__.py", line 1142 in _run_suite
File "/home/serhiy/py/cpython/Lib/test/support/__init__.py", line 1269 in run_unittest
File "/home/serhiy/py/cpython/Lib/test/libregrtest/runtest.py", line 393 in run_unittest
File "/home/serhiy/py/cpython/Lib/test/libregrtest/runtest.py", line 447 in test_func
File "/home/serhiy/py/cpython/Lib/test/libregrtest/runtest.py", line 407 in regrtest_runner
File "/home/serhiy/py/cpython/Lib/test/libregrtest/runtest.py", line 451 in _load_run_test
File "/home/serhiy/py/cpython/Lib/test/libregrtest/runtest.py", line 491 in _runtest_env_changed_exc
File "/home/serhiy/py/cpython/Lib/test/libregrtest/runtest.py", line 348 in _runtest
File "/home/serhiy/py/cpython/Lib/test/libregrtest/runtest.py", line 375 in runtest
File "/home/serhiy/py/cpython/Lib/test/libregrtest/main.py", line 462 in run_test
File "/home/serhiy/py/cpython/Lib/test/libregrtest/main.py", line 495 in run_tests_sequentially
File "/home/serhiy/py/cpython/Lib/test/libregrtest/main.py", line 632 in run_tests
File "/home/serhiy/py/cpython/Lib/test/libregrtest/main.py", line 855 in action_run_tests
File "/home/serhiy/py/cpython/Lib/test/libregrtest/main.py", line 883 in _main
File "/home/serhiy/py/cpython/Lib/test/libregrtest/main.py", line 822 in main
File "/home/serhiy/py/cpython/Lib/test/libregrtest/main.py", line 891 in main
File "/home/serhiy/py/cpython/Lib/test/__main__.py", line 2 in <module>
File "/home/serhiy/py/cpython/Lib/runpy.py", line 88 in _run_code
File "/home/serhiy/py/cpython/Lib/runpy.py", line 198 in _run_module_as_main
It is only reproducible in 3.12+.
Linked PRs
- gh-108976: Make sure instrumentation line returns the correct opcode when instruction instrumentation is stripped #109043
- GH-108976. Keep monitoring data structures valid during de-optimization during callback. #109131
- [3.12] GH-108976. Keep monitoring data structures valid during de-optimization during callback. (GH-109131) #109268
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixesrelease-blockertestsTests in the Lib/test dirTests in the Lib/test dirtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Projects
- StatusShow more project fieldsDone
Activity
serhiy-storchaka commentedon Sep 6, 2023
test_pdbonly crashes afterRaisingTraceFuncTestCase.test_line_event_raises_before_opcode_eventor after any ofTraceOpcodesTestCasecases fromtest_sys_settrace.These tests also occur in #108982, so this all may be symptoms of the same bug.
gaogaotiantian commentedon Sep 6, 2023
I'm able to reduce the MRE:
It will bring up the pdb console, and you can just
cto trigger the SegFault.gaogaotiantian commentedon Sep 7, 2023
The crash is a bit tricky, and affects more than
sys.settrace-sys.monitoringalso suffers from it.The fundamental reason was when
INSTRUCTIONandLINEevents are both set, andINSTRUMENTATIONis turned off inLINEevent callback, the system got confused. InINSTRUMENTED_LINE, it will try to get the next opcode and would be fed a wrong one -INSTRUMENTED_INSTRUCTIONby the current design. However, the instrumentation is already stripped, which would eventually cause issues that lead to a SegFault.I have a fix which simply checks if this case happens when opcode is requested from
INSTRUMENTED_LINEand use the original opcode for the instruction.This might not be the best way to fix it, but it's clean and simple. If @markshannon has a better idea, I can do something different.
GH-108976. Keep monitoring data structures valid during de-optimizati…
pythonGH-108976. Keep monitoring data structures valid during de-opti…
[3.12] GH-108976. Keep monitoring data structures valid during de-opt…
markshannon commentedon Sep 12, 2023
This is fixed now, both in main and 3.12