classification
Title: Make setting line number in frame more robust.
Type: Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Mark.Shannon, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2020-04-08 15:47 by Mark.Shannon, last changed 2021-04-07 09:27 by Mark.Shannon. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19437 merged Mark.Shannon, 2020-04-08 15:59
Messages (3)
msg365990 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2020-04-08 15:47
Debuggers are allowed to change the line number of the currently executing frame. Regardless of whether this is sensible or not, the current implementation rather fragile.

The code makes various assumptions about the layout of the bytecode that may not be true in the future, and I suspect, are not true now.

We should use a more brute-force approach of computing the exception stack for the whole function and then searching for a safe place to jump to. This is not only more robust it allows more jumps.

For example, it is safe to jump from one exception handler to another.
It may not be sensible, but it is safe.
msg367666 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2020-04-29 15:49
New changeset 57697245e1deafdedf68e5f21ad8890be591efc0 by Mark Shannon in branch 'master':
bpo-40228: More robust frame.setlineno. (GH-19437)
https://github.com/python/cpython/commit/57697245e1deafdedf68e5f21ad8890be591efc0
msg368383 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-05-07 21:53
Windows 64-bit emits a compiler warning on this line:

    int len = PyBytes_GET_SIZE(f->f_code->co_code)/sizeof(_Py_CODEUNIT);

Warning:

D:\a\cpython\cpython\Objects\frameobject.c(400,1): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Either the code should be rewritten to to Py_ssize_t, or the result should be downcasted to int.

Technically, it seems possible to create a code object larger than INT_MAX instructors: PyCode_New() has no limit on the bytecode length.
History
Date User Action Args
2021-04-07 09:27:15Mark.Shannonsetstatus: open -> closed
resolution: fixed
2020-05-07 21:53:59vstinnersetstatus: closed -> open
resolution: fixed -> (no value)
2020-05-07 21:53:51vstinnersetnosy: + vstinner
messages: + msg368383
2020-05-07 14:03:05Mark.Shannonsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-04-29 15:49:49Mark.Shannonsetmessages: + msg367666
2020-04-08 16:02:40serhiy.storchakasetnosy: + serhiy.storchaka
2020-04-08 15:59:37Mark.Shannonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request18791
2020-04-08 15:47:35Mark.Shannoncreate