forked from vim-vdebug/vdebug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_vdebug.py
More file actions
250 lines (215 loc) · 7.27 KB
/
Copy pathstart_vdebug.py
File metadata and controls
250 lines (215 loc) · 7.27 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import sys
import os
import inspect
directory = os.path.dirname(inspect.getfile(inspect.currentframe()))
sys.path.append(directory)
import socket
import traceback
import vdebug.runner
import vdebug.event
import vim
class DebuggerInterface:
"""Acts as a facade layer to the debugger client.
Most methods are just redirected to the Runner class. Fatal
exceptions are caught and handled here.
"""
def __init__(self):
self.runner = vdebug.runner.Runner()
self.event_dispatcher = vdebug.event.Dispatcher(self.runner)
def __del__(self):
self.runner.close_connection()
def run(self):
"""Tell the debugger to run, until the next breakpoint or end of script.
"""
try:
self.runner.run()
except Exception as e:
self.handle_exception(e)
def run_to_cursor(self):
"""Run to the current VIM cursor position.
"""
try:
self.runner.run_to_cursor()
except Exception as e:
self.handle_exception(e)
def step_over(self):
"""Step over to the next statement.
"""
try:
self.runner.step_over()
except Exception as e:
self.handle_exception(e)
def step_into(self):
"""Step into a statement on the current line.
"""
try:
self.runner.step_into()
except Exception as e:
self.handle_exception(e)
def step_out(self):
"""Step out of the current statement.
"""
try:
self.runner.step_out()
except Exception as e:
self.handle_exception(e)
def handle_opt(self,option,value = None):
"""Set an option, overwriting the existing value.
"""
try:
if value is None:
return self.runner.ui.say(vdebug.opts.Options.get(option))
else:
self.runner.ui.say("Setting vdebug option '%s' to: %s"\
%(option,value))
vim.command('let g:vdebug_options["%s"] = "%s"' %(option,value))
return vdebug.opts.Options.overwrite(option,value)
except Exception as e:
self.handle_exception(e)
def handle_return_keypress(self):
"""React to a <enter> keypress event.
"""
try:
return self.event_dispatcher.by_position()
except Exception as e:
self.handle_exception(e)
def handle_double_click(self):
"""React to a mouse double click event.
"""
try:
return self.event_dispatcher.by_position()
except Exception as e:
self.handle_exception(e)
def handle_visual_eval(self):
"""React to eval during visual selection.
"""
try:
return self.event_dispatcher.visual_eval()
except Exception as e:
self.handle_exception(e)
def handle_eval(self,args):
"""Evaluate a code snippet specified by args.
"""
try:
return self.runner.eval(args)
except Exception as e:
self.handle_exception(e)
def eval_under_cursor(self):
"""Evaluate the property under the cursor.
"""
try:
return self.event_dispatcher.eval_under_cursor()
except Exception as e:
self.handle_exception(e)
def toggle_breakpoint_window(self):
"""Open or close the breakpoint window.
"""
try:
return self.runner.toggle_breakpoint_window()
except Exception as e:
self.handle_exception(e)
def set_breakpoint(self,args = None):
"""Set a breakpoint, specified by args.
"""
try:
self.runner.set_breakpoint(args)
except Exception as e:
self.handle_exception(e)
def remove_breakpoint(self,args = None):
"""Remove one or more breakpoints, specified by args.
"""
try:
self.runner.remove_breakpoint(args)
except Exception as e:
self.handle_exception(e)
def get_context(self):
"""Get all the variables in the default context
"""
try:
self.runner.get_context()
except Exception as e:
self.handle_exception(e)
def detach(self):
"""Detach the debugger, so the script runs to the end.
"""
try:
self.runner.detach()
self.runner.close_connection()
except Exception as e:
self.handle_exception(e)
def close(self):
"""Close the connection, or the UI if already closed.
"""
if self.runner.is_alive():
self.runner.close_connection()
else:
self.runner.close()
""" Exception handlers """
def handle_timeout(self):
"""Handle a timeout, which is pretty normal.
"""
self.runner.close()
self.runner.ui.say("No connection was made")
def handle_interrupt(self):
"""Handle a user interrupt, which is pretty normal.
"""
self.runner.close()
self.runner.ui.say("Connection cancelled")
def handle_socket_end(self):
"""Handle a socket closing, which is pretty normal.
"""
self.runner.ui.say("Connection to the debugger has been closed")
self.runner.close_connection()
def handle_vim_error(self,e):
"""Handle a VIM error.
This should NOT occur under normal circumstances.
"""
self.runner.ui.error("A Vim error occured: "+\
str(e)+\
"\n"+ traceback.format_exc())
def handle_readable_error(self,e):
"""Simply print an error, since it is human readable enough.
"""
self.runner.ui.error(str(e))
def handle_dbgp_error(self,e):
"""Simply print an error, since it is human readable enough.
"""
self.runner.ui.error(str(e.args[0]))
def handle_general_exception(self):
"""Handle an unknown error of any kind.
"""
self.runner.ui.error("An error occured: "+\
str(sys.exc_info()[0])+\
"\n"+ traceback.format_exc())
def handle_exception(self,e):
"""Switch on the exception type to work out how to handle it.
"""
if isinstance(e,vdebug.dbgp.TimeoutError):
self.handle_timeout()
elif isinstance(e,vdebug.util.UserInterrupt):
try:
self.handle_interrupt()
except:
pass
elif isinstance(e,vdebug.event.EventError):
self.handle_readable_error(e)
elif isinstance(e,vdebug.breakpoint.BreakpointError):
self.handle_readable_error(e)
elif isinstance(e,vdebug.log.LogError):
self.handle_readable_error(e)
elif isinstance(e,vdebug.dbgp.DBGPError):
self.handle_dbgp_error(e)
elif isinstance(e,(EOFError,socket.error)):
self.handle_socket_end()
elif isinstance(e,KeyboardInterrupt):
print "Keyboard interrupt - debugging session cancelled"
try:
self.runner.close()
except:
pass
else:
self.handle_general_exception()
"""
elif isinstance(e,vim.error):
self.handle_vim_error(e)
"""