Created
May 6, 2020 10:21
-
-
Save Kyuuhachi/c983e590a7257f79d97b2fd935779e9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
if not sys.gettrace(): | |
# f_trace doesn't work if settrace isn't set | |
sys.settrace(lambda a, b, c: None) | |
def j(n): | |
def hook(fr, event, arg): | |
assert event == "opcode" | |
fr.f_lineno += n | |
fr.f_trace = oldhook | |
fr.f_trace_opcodes = oldtraceops | |
if oldtraceops and oldhook: | |
return oldhook(fr, event, arg) | |
fr = sys._getframe().f_back | |
oldhook = fr.f_trace | |
oldtraceops = fr.f_trace_opcodes | |
fr.f_trace = hook | |
fr.f_trace_opcodes = True | |
a = 1 | |
j(3) | |
a = 2 | |
print(1) | |
print(2) | |
if a == 1: | |
j(-4) | |
print(4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment