Skip to content

test_lltrace fails on non-UTF-8 locale #91924

Closed

Description

@serhiy-storchaka
$ LC_ALL=en_US.iso88591 ./python -m test -vuall test_lltrace
...
======================================================================
FAIL: test_lltrace (test.test_lltrace.TestLLTrace.test_lltrace)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/test/test_lltrace.py", line 56, in test_lltrace
    self.assertIn("GET_ITER", stdout)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'GET_ITER' not found in "\nResuming frame for 'trace_me' in module '__main__'\n\nResuming frame for '<module>'\n    stack=[None]\n62: POP_TOP\n    stack=[]\n64: DELETE_NAME 3\n    stack=[]\n66: PUSH_NULL\n    stack=[<nil>]\n68: LOAD_NAME 2\n    stack=[<nil>, <function dont_trace_2 at 0x7feae8a28890>]\n70: PRECALL 0\n    stack=[<nil>, <function dont_trace_2 at 0x7feae8a28890>]\n74: CALL 0\n"

======================================================================
FAIL: test_lltrace_different_module (test.test_lltrace.TestLLTrace.test_lltrace_different_module)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/test/test_lltrace.py", line 74, in test_lltrace_different_module
    self.assertIn('LOAD_CONST', stdout)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'LOAD_CONST' not found in "\nResuming frame for 'example' in module 'test.test_lltrace'\nthis is an example\n"

----------------------------------------------------------------------

Activity

  1. sweeneyde commented on Apr 26, 2022

    @sweeneyde
    Member

    How strange: I don't know how the encoding is preventing printf() from working.

    Resuming frame for 'trace_me' in module '__main__'
                              <----------------------------There should be stuff here
    Resuming frame for '<module>'
        stack=[None]
    62: POP_TOP
        stack=[]
    64: DELETE_NAME 3
        stack=[]
    66: PUSH_NULL
        stack=[<nil>]
    68: LOAD_NAME 2
        stack=[<nil>, <function dont_trace_2 at 0x7feae8a28890>]
    70: PRECALL 0
        stack=[<nil>, <function dont_trace_2 at 0x7feae8a28890>]
    74: CALL 0
    
  2. serhiy-storchaka commented on Apr 26, 2022

    @serhiy-storchaka
    MemberAuthor

    It may fail to decode a non-UTF-8 file path with UTF-8 and then silence all errors. It may be similar to #91922.

  3. vstinner commented on May 25, 2022

    @vstinner
    Member

    It's a subtle bug related to unicode_check_encoding_errors().

    lltrace_resume_frame() => PyObject_Print() => PyUnicode_AsEncodedString() => unicode_check_encoding_errors() => _PyCodec_Lookup() => (...) => _PyEval_EvalFrame()

    The _PyEval_EvalFrame() call executes encodings.search_function() which sets lltrace to 0.

    I propose #93199 to fix it.

  4. sweeneyde commented on May 25, 2022

    @sweeneyde
    Member

    Thanks for the detective work!

    Could we instead make lltrace a local variable for PyEval_EvalFrameDefault? I think that would be a beneficial change anyway: you then only trace functions in modules marked with __lltrace__, and it stays on after a call to a different module finishes.

  5. vstinner commented on May 25, 2022

    @vstinner
    Member

    Could we instead make lltrace a local variable for PyEval_EvalFrameDefault?

    Let's discuss that in the PR instead.

  6. added a commit that references this issue on May 25, 2022
  7. added a commit that references this issue on May 25, 2022
  8. added a commit that references this issue on May 25, 2022
  9. added a commit that references this issue on May 25, 2022
  10. vstinner commented on May 25, 2022

    @vstinner
    Member

    Fixed by:

  11. added a commit that references this issue on May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10 (EOL)end of life3.11only security fixes3.9 (EOL)end of lifetestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions