forked from RyannDaGreat/rp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchainsaw.py
More file actions
33 lines (33 loc) · 1.38 KB
/
chainsaw.py
File metadata and controls
33 lines (33 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#This is the ultimate debugging tool when you know something weird is happening but you don't know where.
#This is kinda like hunter.py but it doesn't hav syntax errors and it can launch a debugger
def f():
i=0
for _ in range(100) :
print('i=',i)
i+=1
i%=30
def set_pudb_trace_at_frame(frame,event,args):
import pudb
dbg = pudb._get_debugger()
dbg.set_trace(frame)
#dbg.break_here(frame)
#dbg.stop_here(frame)
dbg.trace_dispatch(frame, event, args)
def trap_namespace_tracer(**checks):
#Really, we can put any kind of condition in here. This is just a demo that simply checks to see if there's an i=1 in the namespace.
def tracer(frame,event,args):
#TODO: Use 'event' to detect function calls to make new kinds of traps, such as when we're entering a function.
#TODO: Take inspiration from hunter.py?
flag=True
print('TRACE')#For some reason this isn't printed after we exit the debugger. investigaet.\c
for key,value in checks.items():
namespace=frame.f_locals
if key not in namespace or namespace[key]!=value:
flag=False
if flag:
print('CAUGHT!!!')
set_pudb_trace_at_frame(frame,event,args)
return tracer#We must return the tracer otherwise python will lose track of it
sys.settrace(tracer)
trap_namespace_tracer(i=19)
f()