Jump on C by PyEval_SetTrace Python 3.7.7
Hi everyone. I'm trying to make a simple jump on C funcion trace by frame->f_lineno. Example is simple, but not working. if (frame->f_lineno == 12){ frame->f_lineno = 8; } attached files C and python to run test. the line 12 I need to jump to line 8. Att. Leandro Müller
Hi,
It seems like you should be to modify frame->f_lasti in a trace function
FYI in a frame object, the line number is computed using
frame->f_lasti and f->f_code->co_lnotab: PyFrame_GetLineNumber().
See: https://github.com/python/cpython/blob/master/Objects/lnotab_notes.txt
Good luck ;-)
Victor
Le lun. 23 mars 2020 à 00:50, Leandro Müller
Hi everyone.
I'm trying to make a simple jump on C funcion trace by frame->f_lineno. Example is simple, but not working.
if (frame->f_lineno == 12){
frame->f_lineno = 8;
}
attached files C and python to run test. the line 12 I need to jump to line 8.
Att.
Leandro Müller
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/7RZX4MUF... Code of Conduct: http://python.org/psf/codeofconduct/
-- Night gathers, and now my watch begins. It shall not end until my death.
Hi.
When I changed frame->f_lasti change de code to back, it's work but the line in front code occurs dump, the runtime over.
Example:
I jump to 8 line and after I jump to line 10, it occurs dump.
On python trace pdb the jump works good by the frame-f_lineno.
Att.
Leandro Müller
________________________________
De: Victor Stinner
Hi everyone.
I'm trying to make a simple jump on C funcion trace by frame->f_lineno. Example is simple, but not working.
if (frame->f_lineno == 12){
frame->f_lineno = 8;
}
attached files C and python to run test. the line 12 I need to jump to line 8.
Att.
Leandro Müller
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/7RZX4MUF... Code of Conduct: http://python.org/psf/codeofconduct/
-- Night gathers, and now my watch begins. It shall not end until my death.
Hello Victor Stinner.
Thanks.
Your tip helped me a lot.
I understood that I need to get position on bycode of the line.
So I create the funcion to get position inside of the bycode.
Now I can to jump the correct position on trace.
frame->f_lasti = checkBycodePosition(frame->f_code, 11);
int checkBycodePosition(PyCodeObject *co, int fline)
{
Py_ssize_t size = PyBytes_Size(co->co_lnotab) / 2;
unsigned char *p = (unsigned char *)PyBytes_AsString(co->co_lnotab);
int line = co->co_firstlineno;
int addr = 0;
while (--size >= 0)
{
addr += *p++;
line += (signed char)*p;
if (line == fline)
break;
p++;
}
return addr;
}
Att.
Leandro Müller
________________________________
De: Leandro Müller
Hi everyone.
I'm trying to make a simple jump on C funcion trace by frame->f_lineno. Example is simple, but not working.
if (frame->f_lineno == 12){
frame->f_lineno = 8;
}
attached files C and python to run test. the line 12 I need to jump to line 8.
Att.
Leandro Müller
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/7RZX4MUF... Code of Conduct: http://python.org/psf/codeofconduct/
-- Night gathers, and now my watch begins. It shall not end until my death.
On 3/23/20 11:17 PM, Leandro Müller wrote:
Hello Victor Stinner.
Thanks. Your tip helped me a lot. I understood that I need to get position on bycode of the line. So I create the funcion to get position inside of the bycode. Now I can to jump the correct position on trace.
frame->f_lasti = checkBycodePosition(frame->f_code, 11); There are cases where it is invalid to change f_lineno to avoid a python stack corruption. See the comments of the f_lineno setter frame_setlineno() in Objects/frameobject.c, the comments at the start of the function and inside the code itself.
Xavier
participants (3)
-
Leandro Müller
-
Victor Stinner
-
Xavier de Gaye