Skip to content

Conversation

chgnrdv
Copy link
Contributor

@chgnrdv chgnrdv commented Apr 27, 2023

check if call to `linecache.getline` returns non-empty string
otherwise print only filename with lineno
@chgnrdv
Copy link
Contributor Author

chgnrdv commented Apr 27, 2023

With this fix the output for frames with missing source files will look like this:

 --- modulename: example, funcname: <module>
example.py(2): import signal
 --- modulename: _bootstrap, funcname: _find_and_load
<frozen importlib._bootstrap>(1299)
<frozen importlib._bootstrap>(1300)
<frozen importlib._bootstrap>(1302)
 --- modulename: _bootstrap, funcname: __init__
<frozen importlib._bootstrap>(325)
<frozen importlib._bootstrap>(326)
 --- modulename: _bootstrap, funcname: __enter__
<frozen importlib._bootstrap>(329)
 --- modulename: _bootstrap, funcname: _get_module_lock
<frozen importlib._bootstrap>(344)
<frozen importlib._bootstrap>(345)
<frozen importlib._bootstrap>(346)
<frozen importlib._bootstrap>(347)
<frozen importlib._bootstrap>(348)
<frozen importlib._bootstrap>(349)
<frozen importlib._bootstrap>(351)
<frozen importlib._bootstrap>(352)
<frozen importlib._bootstrap>(355)
 --- modulename: _bootstrap, funcname: __init__
<frozen importlib._bootstrap>(165)
<frozen importlib._bootstrap>(166)
<frozen importlib._bootstrap>(169)
<frozen importlib._bootstrap>(173)
<frozen importlib._bootstrap>(184)
<frozen importlib._bootstrap>(198)
<frozen importlib._bootstrap>(357)
<frozen importlib._bootstrap>(368)
<frozen importlib._bootstrap>(370)
<frozen importlib._bootstrap>(372)
<frozen importlib._bootstrap>(330)
 --- modulename: _bootstrap, funcname: acquire
<frozen importlib._bootstrap>(222)
<frozen importlib._bootstrap>(223)
 --- modulename: _bootstrap, funcname: __init__
<frozen importlib._bootstrap>(71)
<frozen importlib._bootstrap>(72)
 --- modulename: _bootstrap, funcname: __enter__
<frozen importlib._bootstrap>(82)
<frozen importlib._bootstrap>(83)
<frozen importlib._bootstrap>(224)
<frozen importlib._bootstrap>(228)
<frozen importlib._bootstrap>(229)
<frozen importlib._bootstrap>(236)
<frozen importlib._bootstrap>(237)
<frozen importlib._bootstrap>(238)
<frozen importlib._bootstrap>(228)
<frozen importlib._bootstrap>(223)
 --- modulename: _bootstrap, funcname: __exit__
<frozen importlib._bootstrap>(87)
<frozen importlib._bootstrap>(1303)
<frozen importlib._bootstrap>(1304)
<frozen importlib._bootstrap>(1305)
 --- modulename: _bootstrap, funcname: _find_and_load_unlocked
<frozen importlib._bootstrap>(1250)
<frozen importlib._bootstrap>(1251)
<frozen importlib._bootstrap>(1252)
<frozen importlib._bootstrap>(1253)
<frozen importlib._bootstrap>(1267)
 --- modulename: _bootstrap, funcname: _find_spec
<frozen importlib._bootstrap>(1185)
<frozen importlib._bootstrap>(1186)
<frozen importlib._bootstrap>(1191)
<frozen importlib._bootstrap>(1197)
<frozen importlib._bootstrap>(1198)
<frozen importlib._bootstrap>(1199)
 --- modulename: _bootstrap, funcname: __enter__
<frozen importlib._bootstrap>(1157)
<frozen importlib._bootstrap>(1200)
<frozen importlib._bootstrap>(1201)
<frozen importlib._bootstrap>(1207)

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Could you please add some tests?

@chgnrdv
Copy link
Contributor Author

chgnrdv commented Feb 10, 2024

It turned out that line tracing isn't tested at all. I will open a separate issue to handle it.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM!

@serhiy-storchaka serhiy-storchaka merged commit 7c87ce7 into python:main May 9, 2024
@miss-islington-app
Copy link

Thanks @chgnrdv for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 9, 2024
…ythonGH-103958)

Print only filename with lineno if linecache.getline() returns an empty string.
(cherry picked from commit 7c87ce7)

Co-authored-by: Radislav Chugunov <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 9, 2024
…ythonGH-103958)

Print only filename with lineno if linecache.getline() returns an empty string.
(cherry picked from commit 7c87ce7)

Co-authored-by: Radislav Chugunov <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented May 9, 2024

GH-118832 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label May 9, 2024
@bedevere-app
Copy link

bedevere-app bot commented May 9, 2024

GH-118833 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.11 only security fixes label May 9, 2024
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.13 bugs and security fixes label May 9, 2024
@miss-islington-app
Copy link

Thanks @chgnrdv for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 9, 2024
…ythonGH-103958)

Print only filename with lineno if linecache.getline() returns an empty string.
(cherry picked from commit 7c87ce7)

Co-authored-by: Radislav Chugunov <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented May 9, 2024

GH-118834 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label May 9, 2024
@serhiy-storchaka
Copy link
Member

It is too late for the 3.11 backport, but it should now be backported to 3.13.

serhiy-storchaka pushed a commit that referenced this pull request May 9, 2024
…H-103958) (GH-118832)

Print only filename with lineno if linecache.getline() returns an empty string.
(cherry picked from commit 7c87ce7)

Co-authored-by: Radislav Chugunov <[email protected]>
serhiy-storchaka pushed a commit that referenced this pull request May 9, 2024
…H-103958) (GH-118834)

Print only filename with lineno if linecache.getline() returns an empty string.
(cherry picked from commit 7c87ce7)

Co-authored-by: Radislav Chugunov <[email protected]>
SonicField pushed a commit to SonicField/cpython that referenced this pull request May 9, 2024
…ythonGH-103958)

Print only filename with lineno if linecache.getline() returns an empty string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

trace: line tracing output lacks newlines if source lines are not available
3 participants