[Python-Dev] Set PyEval_SetTrace to method from class

2020-04-04 Thread Leandro Müller
Hello.

I need to set a PyEval_SetTrace with a new class instance.
All examples use simple function.
PyEval_SetTrace(trace_trampoline, obj);

Following my problem:
I start three threads, but I need to check trace C just one thread.
If I run a while on C trace on thread, it stops all threads.

So, I've been thinking to run Trace with a new instance class C.

Any suggestions?



Att.

Leandro Müller
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@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/CDH7BTAYPJ6QRTXI32QRJVEPKWXEPYF4/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Debug C++

2020-03-30 Thread Leandro Müller
Hi
Are there any away to debug C module during python debug?

Att.
Leandro Müller
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@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/5NO3SO3MOWCRQD7EJ6IS55O5UMG42W7X/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: sys.trace without alert or remove trace by C

2020-03-27 Thread Leandro Müller
Hello Victor.
Thank you.
The tips help me a lot.
I think the tip needs to stay inside on document to reduce time to seach 
soluction.
Thanks.

Att.
Leandro Müller

De: Victor Stinner 
Enviado: Thursday, March 26, 2020 7:08:42 PM
Para: Leandro Müller 
Cc: python-dev@python.org 
Assunto: Re: [Python-Dev] sys.trace without alert or remove trace by C

Hi,

I understand that you are looking for PyEval_SetTrace(NULL, NULL) to
unregister a trace function set previously.

Maybe the documentation should be enhanced to explain that. Do you
want to propose a PR to enhance the doc?

https://docs.python.org/dev/c-api/init.html?highlight=pyeval_settrace#c.PyEval_SetTrace

Victor

Le jeu. 26 mars 2020 à 22:47, Leandro Müller
 a écrit :
>
> Hello.
> I need to remove the trace on thread, but I tried to run sys.settrace(None) 
> and return alert on console.
> I didn't find any soluction to remove by C, example PyEval_SetTrace(Py_None, 
> obj), but it not works.
>
> Are there any soluction to remove without alert or by C?
> C is better for me.
>
> Thanks.
>
> Att.
>
> Leandro Müller
>
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@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/HJNC3UOXDBOYF6XJ3MFJX647WKCICK7P/
> Code of Conduct: http://python.org/psf/codeofconduct/



--
Night gathers, and now my watch begins. It shall not end until my death.
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@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/YPL636CCLIRXCJ7VXSFMVAN262FJYQ22/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Clean memory on C trace

2020-03-27 Thread Leandro Müller
Hi.

I need to clean memory on function on PyEval_SetTrace.
When the python code run a while test, the memory consumption goes up a lot 
(99% of the system).
exemple:
while 1 == 1:
 pass

My trace function is simple.

static map session_debug_user;
char *user_console;

int trace_trampoline(
PyObject *obj, PyFrameObject *frame, int event, PyObject *arg)
{
try
{
//check if user has debug session
if (session_debug_user.count(user_console) == 0)
{
return 0;
}
  return 0;
}

PyObject *sys_settrace(PyObject *mod, PyObject *obj)
{
user_console = get_variable_char(obj, 0);
PyEval_SetTrace(trace_trampoline, obj);
return Py_None;
}


[cid:607bbc5e-5dd8-4a8b-ad96-dc31dce274a9]


Att.

Leandro Müller
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@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/AZEYSU733IWYCPVID2BABY2K33QGUHFP/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] C trace after start runtime

2020-03-27 Thread Leandro Müller
Hello.
I need to start C trace the thread after to start, its to reduce of the time of 
the process.
I had a lot performance changes sys.trace to C trace, but I need to reduce more 
time.

Are there any soluction to set trace during thead runtime?


Att.
Leandro Müller
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@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/G3IPGNHDQ2DNJY2CLAIAGN2GREDMGFCW/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] sys.trace without alert or remove trace by C

2020-03-26 Thread Leandro Müller
Hello.
I need to remove the trace on thread, but I tried to run sys.settrace(None) and 
return alert on console.
I didn't find any soluction to remove by C, example PyEval_SetTrace(Py_None, 
obj), but it not works.

Are there any soluction to remove without alert or by C?
C is better for me.

Thanks.


Att.

Leandro Müller
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@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/HJNC3UOXDBOYF6XJ3MFJX647WKCICK7P/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Jump on C by PyEval_SetTrace Python 3.7.7 - SOLUTION

2020-03-23 Thread Leandro Müller
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 
Enviado: segunda-feira, 23 de março de 2020 13:45
Para: Victor Stinner 
Cc: python-dev@python.org 
Assunto: [Python-Dev] Re: Jump on C by PyEval_SetTrace Python 3.7.7

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 
Enviado: segunda-feira, 23 de março de 2020 13:01
Para: Leandro Müller 
Cc: python-dev@python.org 
Assunto: Re: [Python-Dev] Jump on C by PyEval_SetTrace Python 3.7.7

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
 a écrit :
>
> 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-le...@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/7RZX4MUF6GLPU4DVXLRTQ534TDRXRL36/
> Code of Conduct: http://python.org/psf/codeofconduct/



--
Night gathers, and now my watch begins. It shall not end until my death.
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@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/2IYHZ3KU62JAT4MPDWVNUJJASTHCWF36/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Jump on C by PyEval_SetTrace Python 3.7.7

2020-03-23 Thread Leandro Müller
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 
Enviado: segunda-feira, 23 de março de 2020 13:01
Para: Leandro Müller 
Cc: python-dev@python.org 
Assunto: Re: [Python-Dev] Jump on C by PyEval_SetTrace Python 3.7.7

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
 a écrit :
>
> 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-le...@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/7RZX4MUF6GLPU4DVXLRTQ534TDRXRL36/
> Code of Conduct: http://python.org/psf/codeofconduct/



--
Night gathers, and now my watch begins. It shall not end until my death.
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@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/GMQE4A2A3AEDNXKJA67MSTEZXZ3XRC7Y/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Jump on C by PyEval_SetTrace Python 3.7.7

2020-03-22 Thread 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
import importlib
import tracesys
import sys
import os

def teste(): 
print("7") 
print("8")
print("9")
print("10")
print("11")
print("12")
print("13")
print("14")


 
def get_module_to_file( ):
SY_BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)) + 
"/%s" % ("W64"))
SY_BASE_DIR = SY_BASE_DIR.replace("\\", "/") 
path1 = os.path.join(SY_BASE_DIR)
path1 = path1 +  "/check.py" 
filename = os.path.realpath(path1) 
filename = filename.replace("\\", "/")  
filename = filename.replace(SY_BASE_DIR, ".")
return filename

file = get_module_to_file()
# print(file)
# from threading import Thread
# t = Thread(target=teste)
# t.start()

tracesys.sys_settrace("lmuller", "session_login" )
tracesys.add_debug("lmuller", file,8, "lmuller", "session_login" )
teste()
print("fim")
# t = input()
from distutils.core import setup, Extension

module = Extension("tracesys",sources = ["trace.cpp"])
setup(name="Traca Package", version="1.0",description="Trace process",
ext_modules= [module]) 
#include "Python.h"
#include "frameobject.h" 
#include 
#include 
#include 
using namespace std;
typedef struct t_debug
{
char *user_debug;
char *user_console;
char *file;
int line;
char *id_wp;
char *session_login;
char *sessionid;
int *last;

} * st_debug;

static vector *list_debug = new vector();
static vector *list_debug_urgent = new vector();

char *user_console;
char *session_login;
char *sessionid;
static int conta = 0;

char *ReplaceAll(char *str1, const std::string , const std::string )
{
size_t start_pos = 0;
std::string str = str1;
while ((start_pos = str.find(from, start_pos)) != std::string::npos)
{
str.replace(start_pos, from.length(), to);
start_pos += to.length();
}
char *cstr = new char[str.length() + 1];
strcpy(cstr, str.c_str());

return cstr;
}

char *get_variable_char(PyObject *obj, int position)
{
PyObject *repr = PyObject_Repr(PyTuple_GetItem(obj, position));
PyObject *str = PyUnicode_AsEncodedString(repr, "utf-8", NULL);
char *s = PyBytes_AS_STRING(str);
string st = s;
if (st.length() < 2)
{
return "";
}
st = st.substr(1, st.length() - 2);
s = new char[st.length() + 1];
strcpy(s, st.c_str());
printf("%s \n", s);
return s;
}
int get_variable_int(PyObject *obj, int position)
{

return PyLong_AsLong(PyTuple_GetItem(obj, position));
}

int has_debug_session(char *user_console, char *file, int line, char 
*session_login)
{
int ret = -1;
try
{
size_t size = list_debug->size();
for (size_t i = 0; i < size; i++)
{
t_debug objl = list_debug->at(i);

if (strcmp(objl.user_console, user_console) == 0 &&
strcmp(objl.file, file) == 0 && (objl.line == line) &&
strcmp(objl.session_login, session_login) == 0)

{
ret = 0;
break;
}
}
}
catch (exception )
{
cout << "error process " << e.what() << '\n';
}
return ret;
}

int can_debug_session(char *user_c, char *file, int line, char *session_login)
{

try
{
size_t size = list_debug->size();
for (size_t i = 0; i < size; i++)
{
t_debug objl = list_debug->at(i);

if (strcmp(objl.user_console, user_c) == 0 &&
strcmp(objl.user_debug, user_c) == 0 &&
strcmp(objl.file, file) == 0 && (objl.line == line) &&
strcmp(objl.session_login, session_login) == 0)

{
return 0;
}

if (strcmp(objl.user_console, user_c) == 0 &&
!strcmp(objl.user_debug, user_c) == 0 &&
strcmp(objl.file, file) == 0 && (objl.line == line) &&
!strcmp(objl.session_login, session_login) == 0)

{
return 0;
}
}
}
catch (exception )
{
cout << "error process " << e.what() << '\n';
}
return -1;
}

int has_debug_urgent(char *sessionid)
{
int ret = -1;
try
{
size_t size = list_debug