-
Notifications
You must be signed in to change notification settings - Fork 0
/
debugger.py
48 lines (41 loc) · 1.84 KB
/
debugger.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# coding=UTF-8
from Foundation import *
from AppKit import *
import bdb
# http://docs.python.org/library/bdb.html
class Debugger(bdb.Bdb):
go = False
#def user_call(self, frame, argument_list):
# return
def dispatch_exception(self, frame, arg):
print 'exception'
self.user_exception(frame, arg)
def user_line(self, frame):
"""This function is called when we stop or break at this line."""
print 'waiting...'
self.delegate.outputFrame(frame)
while not self.go:
#NSRunLoop.currentRunLoop().runMode_beforeDate_(NSDefaultRunLoopMode, NSDate.dateWithTimeIntervalSinceNow_(0.1))
NSThread.sleepForTimeInterval_(0.1)
self.go = False
print 'broke out of user_line'
def runscript(self, filename):
# Start with fresh empty copy of globals and locals and tell the script
# that it's being run as __main__ to avoid scripts being able to access
# the debugger's namespace.
globals_ = {"__name__" : "__main__", "__file__": filename}
locals_ = globals_
import sys
import os
if os.path.basename(filename) not in sys.path:
print 'adding python path:',os.path.basename(filename)
sys.path.append(os.path.basename(filename))
# When bdb sets tracing, a number of call and line events happens
# BEFORE debugger even reaches user's code (and the exact sequence of
# events depends on python version). So we take special measures to
# avoid stopping before we reach the main script (see user_line and
# user_call for details).
self._wait_for_mainpyfile = 1
self.mainpyfile = self.canonic(filename)
statement = 'execfile( "%s")' % filename
self.run(statement, globals=globals_, locals=locals_)