-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Document PyCode_Addr2Line function. #25111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Doc/c-api/code.rst
Outdated
.. c:function:: int PyCode_Addr2Line(PyCodeObject *co, int byte_offset) | ||
|
||
Return the line number of the of instruction that occurs on or before ``byte_offset`` and ends after it. | ||
This function is kept for backwards compatibility, its use is not recommended. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this function should not be used, I suggest to officially deprecate it. Add ".. deprecated:: 3.10", add it to https://docs.python.org/dev/whatsnew/3.10.html#id3 and add Py_DEPRECATED() in the header file where it's defined. Usually, we wait at two Python releases before removing a function (PEP 387).
I checked Tools/gdb/libpython.py: it reimplements this function :-)
def addr2line(self, addrq):
'''
Get the line number for a given bytecode offset
Analogous to PyCode_Addr2Line; translated from pseudocode in
Objects/lnotab_notes.txt
'''
Doc/c-api/code.rst
Outdated
For determining line numbers in a code object, use the API described in PEP 626: | ||
https://www.python.org/dev/peps/pep-0626/#out-of-process-debuggers-and-profilers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For determining line numbers in a code object, use the API described in PEP 626: | |
https://www.python.org/dev/peps/pep-0626/#out-of-process-debuggers-and-profilers | |
For determining line numbers in a code object, use `the API described in the PEP 626 | |
<https://www.python.org/dev/peps/pep-0626/#out-of-process-debuggers-and-profilers>`_. |
557dc94
to
5481eef
Compare
@vstinner Since the functions in PEP 626 aren't technically part of the API. We probably don't want to deprecate this. |
If you just need the line number of a frame, use :c:func:`PyFrame_GetLineNumber` instead. | ||
|
||
For effciently determining line numbers in a code object, use `the API described in PEP 626 | ||
<https://www.python.org/dev/peps/pep-0626/#out-of-process-debuggers-and-profilers>`_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand. PyLineTable_InitAddressRange() doesn't seem to be implemented in Python 3.10. Do you plan to implement it?
If it's not implemented yet, I suggest to remove this paragraph, and add it once it will be implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is implemented https://github.com/python/cpython/blob/master/Objects/codeobject.c#L1259
It isn't part of the API, though. Which is why we need to keep PyCode_Addr2Line
Doc/c-api/code.rst
Outdated
|
||
.. c:function:: int PyCode_Addr2Line(PyCodeObject *co, int byte_offset) | ||
|
||
Return the line number of the of instruction that occurs on or before ``byte_offset`` and ends after it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return the line number of the of instruction that occurs on or before ``byte_offset`` and ends after it. | |
Return the line number of the instruction that occurs on or before ``byte_offset`` and ends after it. |
Doc/c-api/code.rst
Outdated
Return the line number of the of instruction that occurs on or before ``byte_offset`` and ends after it. | ||
If you just need the line number of a frame, use :c:func:`PyFrame_GetLineNumber` instead. | ||
|
||
For effciently determining line numbers in a code object, use `the API described in PEP 626 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For effciently determining line numbers in a code object, use `the API described in PEP 626 | |
For effeciently determining line numbers in a code object, use `the API described in PEP 626 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
No "versionadded" is needed, it exists since Python 3.0 (and nothing exists before Python 3).
No description provided.