1
2
3
4 """
5 | This file is part of the web2py Web Framework
6 | Developed by Massimo Di Pierro <mdipierro@cs.depaul.edu>,
7 | limodou <limodou@gmail.com> and srackham <srackham@gmail.com>.
8 | License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
9
10 Debugger support classes
11 ------------------------
12 """
13
14 import logging
15 import pdb
16 import Queue
17 import sys
18
19 logger = logging.getLogger("web2py")
20
21
22 -class Pipe(Queue.Queue):
23 - def __init__(self, name, mode='r', *args, **kwargs):
24 self.__name = name
25 Queue.Queue.__init__(self, *args, **kwargs)
26
28 logger.debug("debug %s writing %s" % (self.__name, data))
29 self.put(data)
30
32
33 logger.debug("debug %s flushing..." % self.__name)
34 self.put(None)
35
36 self.join()
37 logger.debug("debug %s flush done" % self.__name)
38
39 - def read(self, count=None, timeout=None):
40 logger.debug("debug %s reading..." % (self.__name, ))
41 data = self.get(block=True, timeout=timeout)
42
43 self.task_done()
44 logger.debug("debug %s read %s" % (self.__name, data))
45 return data
46
48 logger.debug("debug %s readline..." % (self.__name, ))
49 return self.read()
50
51
52 pipe_in = Pipe('in')
53 pipe_out = Pipe('out')
54
55 debugger = pdb.Pdb(completekey=None, stdin=pipe_in, stdout=pipe_out,)
59 "breakpoint shortcut (like pdb)"
60 logger.info("DEBUG: set_trace!")
61 debugger.set_trace(sys._getframe().f_back)
62
71
75 "send command to debbuger, wait result"
76 if command is not None:
77 logger.info("DEBUG: sending command %s" % command)
78 pipe_in.write(command)
79
80 result = []
81 while True:
82 data = pipe_out.read()
83 if data is None:
84 break
85 result.append(data)
86 logger.info("DEBUG: result %s" % repr(result))
87 return ''.join(result)
88
89
90
91
92 import gluon.contrib.qdb as qdb
93 from threading import RLock
94
95 interact_lock = RLock()
96 run_lock = RLock()
109 return check_fn
110
113 "Qdb web2py interface"
114
115 - def __init__(self, pipe, completekey='tab', stdin=None, stdout=None):
118
120 self.filename = None
121 self.lineno = None
122 self.exception_info = None
123 self.context = None
124
125
126
134
135 - def interaction(self, filename, lineno, line, **context):
144
145 - def exception(self, title, extype, exvalue, trace, request):
146 self.exception_info = {'title': title,
147 'extype': extype, 'exvalue': exvalue,
148 'trace': trace, 'request': request}
149
150 @check_interaction
153
154 @check_interaction
157
158 @check_interaction
161
162 @check_interaction
165
166 @check_interaction
169
181
182
183
184 parent_queue, child_queue = Queue.Queue(), Queue.Queue()
185 front_conn = qdb.QueuePipe("parent", parent_queue, child_queue)
186 child_conn = qdb.QueuePipe("child", child_queue, parent_queue)
187
188 web_debugger = WebDebugger(front_conn)
189 qdb_debugger = qdb.Qdb(pipe=child_conn, redirect_stdio=False, skip=None)
190 dbg = qdb_debugger
191
192
193 qdb_debugger.set_params(dict(call_stack=True, environment=True))
194
195 import gluon.main
196 gluon.main.global_settings.debugging = True
197