python-afl
python-afl copied to clipboard
opcode tracing
Hey,
I was wondering if the opcode tracing added with Python 3.7 might be useful:
def wrap(frame, event, arg):
frame.f_trace_lines = False
frame.f_trace_opcodes = True
code = frame.f_code
if event == "opcode":
filename = code.co_filename
linenumber = frame.f_lineno
opcode = dis.opname[code.co_code[frame.f_lasti]]
print(level * 4 * " ", [event, filename, linenumber, opcode])
else:
....
['call', <frame at 0x7f1dfd1cb040, file 'settrace.py', line 44, code mytestfunction>, None]
['opcode', 'settrace.py', 45, 'LOAD_CONST']
['opcode', 'settrace.py', 45, 'LOAD_FAST']
['opcode', 'settrace.py', 45, 'COMPARE_OP']
['opcode', 'settrace.py', 45, 'POP_JUMP_IF_FALSE']
['opcode', 'settrace.py', 45, 'LOAD_CONST']
['opcode', 'settrace.py', 45, 'LOAD_FAST']
['opcode', 'settrace.py', 45, 'COMPARE_OP']
['opcode', 'settrace.py', 45, 'POP_JUMP_IF_FALSE']
['opcode', 'settrace.py', 45, 'LOAD_CONST']
['opcode', 'settrace.py', 45, 'LOAD_FAST']
['opcode', 'settrace.py', 45, 'COMPARE_OP']
['opcode', 'settrace.py', 45, 'POP_JUMP_IF_FALSE']
['opcode', 'settrace.py', 45, 'LOAD_CONST']
['opcode', 'settrace.py', 45, 'RETURN_VALUE']
['return', <frame at 0x7f1dfd1cb040, file 'settrace.py', line 45, code mytestfunction>, None]
From what I understand it would make it easier to get coverage for multipl conditions per line like
if foo and bar and quux:
...
But not sure and not sure what the performance impact is.
Sounds interesting, but I won't have time to work on this any time soon.
Thanks, maybe I will
After fixing the 1000 bugs this has found for me :P, in other words, thanks for this!