|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2002 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the debugger UI. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 from PyQt4.QtCore import * |
|
13 from PyQt4.QtGui import * |
|
14 |
|
15 from UI.Info import * |
|
16 from VariablesFilterDialog import * |
|
17 from ExceptionsFilterDialog import * |
|
18 from StartDialog import * |
|
19 from EditBreakpointDialog import EditBreakpointDialog |
|
20 |
|
21 from DebugClientCapabilities import * |
|
22 import Preferences |
|
23 import Utilities |
|
24 import UI.PixmapCache |
|
25 import UI.Config |
|
26 |
|
27 from E4Gui.E4Action import E4Action, createActionGroup |
|
28 |
|
29 from eric4config import getConfig |
|
30 |
|
31 class DebugUI(QObject): |
|
32 """ |
|
33 Class implementing the debugger part of the UI. |
|
34 |
|
35 @signal clientStack(stack) emitted at breaking after a reported exception |
|
36 @signal compileForms() emitted if changed project forms should be compiled |
|
37 @signal compileResources() emitted if changed project resources should be compiled |
|
38 @signal debuggingStarted(filename) emitted when a debugging session was started |
|
39 @signal resetUI() emitted to reset the UI |
|
40 @signal exceptionInterrupt() emitted after the execution was interrupted by an |
|
41 exception and acknowledged by the user |
|
42 """ |
|
43 def __init__(self, ui, vm, debugServer, debugViewer, project): |
|
44 """ |
|
45 Constructor |
|
46 |
|
47 @param ui reference to the main UI |
|
48 @param vm reference to the viewmanager |
|
49 @param debugServer reference to the debug server |
|
50 @param debugViewer reference to the debug viewer widget |
|
51 @param project reference to the project object |
|
52 """ |
|
53 QObject.__init__(self, ui) |
|
54 |
|
55 self.ui = ui |
|
56 self.viewmanager = vm |
|
57 self.debugServer = debugServer |
|
58 self.debugViewer = debugViewer |
|
59 self.project = project |
|
60 |
|
61 # Clear some variables |
|
62 self.projectOpen = False |
|
63 self.editorOpen = False |
|
64 |
|
65 # Generate the variables filter dialog |
|
66 self.dbgFilterDialog = VariablesFilterDialog(self.ui, 'Filter Dialog', True) |
|
67 |
|
68 # read the saved debug info values |
|
69 self.argvHistory = \ |
|
70 Preferences.Prefs.settings \ |
|
71 .value('DebugInfo/ArgumentsHistory').toStringList() |
|
72 self.wdHistory = \ |
|
73 Preferences.Prefs.settings \ |
|
74 .value('DebugInfo/WorkingDirectoryHistory').toStringList() |
|
75 self.envHistory = \ |
|
76 Preferences.Prefs.settings \ |
|
77 .value('DebugInfo/EnvironmentHistory').toStringList() |
|
78 self.excList = \ |
|
79 Preferences.Prefs.settings \ |
|
80 .value('DebugInfo/Exceptions').toStringList() |
|
81 self.excIgnoreList = \ |
|
82 Preferences.Prefs.settings \ |
|
83 .value('DebugInfo/IgnoredExceptions').toStringList() |
|
84 self.exceptions = \ |
|
85 Preferences.Prefs.settings.value('DebugInfo/ReportExceptions', |
|
86 QVariant(True)).toBool() |
|
87 self.autoClearShell = Preferences.Prefs.settings.value('DebugInfo/AutoClearShell', |
|
88 QVariant(True)).toBool() |
|
89 self.tracePython = Preferences.Prefs.settings.value('DebugInfo/TracePython', |
|
90 QVariant(False)).toBool() |
|
91 self.autoContinue = Preferences.Prefs.settings.value('DebugInfo/AutoContinue', |
|
92 QVariant(True)).toBool() |
|
93 self.forkAutomatically = Preferences.Prefs.settings.value( |
|
94 'DebugInfo/ForkAutomatically', QVariant(False)).toBool() |
|
95 self.forkIntoChild = Preferences.Prefs.settings.value('DebugInfo/ForkIntoChild', |
|
96 QVariant(False)).toBool() |
|
97 |
|
98 self.evalHistory = [] |
|
99 self.execHistory = [] |
|
100 self.lastDebuggedFile = None |
|
101 self.lastStartAction = 0 # 0=None, 1=Script, 2=Project |
|
102 self.lastAction = -1 |
|
103 self.debugActions = [self.__continue, self.__step,\ |
|
104 self.__stepOver, self.__stepOut,\ |
|
105 self.__stepQuit, self.__runToCursor] |
|
106 self.localsVarFilter, self.globalsVarFilter = Preferences.getVarFilters() |
|
107 self.debugViewer.setVariablesFilter(self.globalsVarFilter, self.localsVarFilter) |
|
108 |
|
109 # Connect the signals emitted by the debug-server |
|
110 self.connect(debugServer, SIGNAL('clientGone'), self.__clientGone) |
|
111 self.connect(debugServer, SIGNAL('clientLine'), self.__clientLine) |
|
112 self.connect(debugServer, SIGNAL('clientExit(int)'), self.__clientExit) |
|
113 self.connect(debugServer, SIGNAL('clientSyntaxError'), self.__clientSyntaxError) |
|
114 self.connect(debugServer, SIGNAL('clientException'), self.__clientException) |
|
115 self.connect(debugServer, SIGNAL('clientVariables'), self.__clientVariables) |
|
116 self.connect(debugServer, SIGNAL('clientVariable'), self.__clientVariable) |
|
117 self.connect(debugServer, SIGNAL('clientBreakConditionError'), |
|
118 self.__clientBreakConditionError) |
|
119 self.connect(debugServer, SIGNAL('clientWatchConditionError'), |
|
120 self.__clientWatchConditionError) |
|
121 self.connect(debugServer, SIGNAL('passiveDebugStarted'), |
|
122 self.__passiveDebugStarted) |
|
123 self.connect(debugServer, SIGNAL('clientThreadSet'), self.__clientThreadSet) |
|
124 |
|
125 self.connect(debugServer, SIGNAL('clientRawInput'), debugViewer.handleRawInput) |
|
126 self.connect(debugServer, SIGNAL('clientRawInputSent'), |
|
127 debugViewer.restoreCurrentPage) |
|
128 self.connect(debugServer, SIGNAL('clientThreadList'), debugViewer.showThreadList) |
|
129 |
|
130 # Connect the signals emitted by the viewmanager |
|
131 self.connect(vm, SIGNAL('editorOpened'), self.__editorOpened) |
|
132 self.connect(vm, SIGNAL('lastEditorClosed'), self.__lastEditorClosed) |
|
133 self.connect(vm, SIGNAL('checkActions'), self.__checkActions) |
|
134 self.connect(vm, SIGNAL('cursorChanged'), self.__cursorChanged) |
|
135 self.connect(vm, SIGNAL('breakpointToggled'), self.__cursorChanged) |
|
136 |
|
137 # Connect the signals emitted by the project |
|
138 self.connect(project, SIGNAL('projectOpened'), self.__projectOpened) |
|
139 self.connect(project, SIGNAL('newProject'), self.__projectOpened) |
|
140 self.connect(project, SIGNAL('projectClosed'), self.__projectClosed) |
|
141 self.connect(project, SIGNAL('projectSessionLoaded'), |
|
142 self.__projectSessionLoaded) |
|
143 |
|
144 # Set a flag for the passive debug mode |
|
145 self.passive = Preferences.getDebugger("PassiveDbgEnabled") |
|
146 |
|
147 def variablesFilter(self, scope): |
|
148 """ |
|
149 Public method to get the variables filter for a scope. |
|
150 |
|
151 @param scope flag indicating global (True) or local (False) scope |
|
152 @return filters list (list of integers) |
|
153 """ |
|
154 if scope: |
|
155 return self.globalsVarFilter[:] |
|
156 else: |
|
157 return self.localsVarFilter[:] |
|
158 |
|
159 def initActions(self): |
|
160 """ |
|
161 Method defining the user interface actions. |
|
162 """ |
|
163 self.actions = [] |
|
164 |
|
165 self.runAct = E4Action(self.trUtf8('Run Script'), |
|
166 UI.PixmapCache.getIcon("runScript.png"), |
|
167 self.trUtf8('&Run Script...'),Qt.Key_F2,0,self,'dbg_run_script') |
|
168 self.runAct.setStatusTip(self.trUtf8('Run the current Script')) |
|
169 self.runAct.setWhatsThis(self.trUtf8( |
|
170 """<b>Run Script</b>""" |
|
171 """<p>Set the command line arguments and run the script outside the""" |
|
172 """ debugger. If the file has unsaved changes it may be saved first.</p>""" |
|
173 )) |
|
174 self.connect(self.runAct, SIGNAL('triggered()'), self.__runScript) |
|
175 self.actions.append(self.runAct) |
|
176 |
|
177 self.runProjectAct = E4Action(self.trUtf8('Run Project'), |
|
178 UI.PixmapCache.getIcon("runProject.png"), |
|
179 self.trUtf8('Run &Project...'),Qt.SHIFT + Qt.Key_F2,0,self, |
|
180 'dbg_run_project') |
|
181 self.runProjectAct.setStatusTip(self.trUtf8('Run the current Project')) |
|
182 self.runProjectAct.setWhatsThis(self.trUtf8( |
|
183 """<b>Run Project</b>""" |
|
184 """<p>Set the command line arguments and run the current project""" |
|
185 """ outside the debugger.""" |
|
186 """ If files of the current project have unsaved changes they may""" |
|
187 """ be saved first.</p>""" |
|
188 )) |
|
189 self.connect(self.runProjectAct, SIGNAL('triggered()'), self.__runProject) |
|
190 self.actions.append(self.runProjectAct) |
|
191 |
|
192 self.coverageAct = E4Action(self.trUtf8('Coverage run of Script'), |
|
193 UI.PixmapCache.getIcon("coverageScript.png"), |
|
194 self.trUtf8('Coverage run of Script...'),0,0,self,'dbg_coverage_script') |
|
195 self.coverageAct.setStatusTip(\ |
|
196 self.trUtf8('Perform a coverage run of the current Script')) |
|
197 self.coverageAct.setWhatsThis(self.trUtf8( |
|
198 """<b>Coverage run of Script</b>""" |
|
199 """<p>Set the command line arguments and run the script under the control""" |
|
200 """ of a coverage analysis tool. If the file has unsaved changes it may be""" |
|
201 """ saved first.</p>""" |
|
202 )) |
|
203 self.connect(self.coverageAct, SIGNAL('triggered()'), self.__coverageScript) |
|
204 self.actions.append(self.coverageAct) |
|
205 |
|
206 self.coverageProjectAct = E4Action(self.trUtf8('Coverage run of Project'), |
|
207 UI.PixmapCache.getIcon("coverageProject.png"), |
|
208 self.trUtf8('Coverage run of Project...'),0,0,self,'dbg_coverage_project') |
|
209 self.coverageProjectAct.setStatusTip(\ |
|
210 self.trUtf8('Perform a coverage run of the current Project')) |
|
211 self.coverageProjectAct.setWhatsThis(self.trUtf8( |
|
212 """<b>Coverage run of Project</b>""" |
|
213 """<p>Set the command line arguments and run the current project""" |
|
214 """ under the control of a coverage analysis tool.""" |
|
215 """ If files of the current project have unsaved changes they may""" |
|
216 """ be saved first.</p>""" |
|
217 )) |
|
218 self.connect(self.coverageProjectAct, SIGNAL('triggered()'), self.__coverageProject) |
|
219 self.actions.append(self.coverageProjectAct) |
|
220 |
|
221 self.profileAct = E4Action(self.trUtf8('Profile Script'), |
|
222 UI.PixmapCache.getIcon("profileScript.png"), |
|
223 self.trUtf8('Profile Script...'),0,0,self,'dbg_profile_script') |
|
224 self.profileAct.setStatusTip(self.trUtf8('Profile the current Script')) |
|
225 self.profileAct.setWhatsThis(self.trUtf8( |
|
226 """<b>Profile Script</b>""" |
|
227 """<p>Set the command line arguments and profile the script.""" |
|
228 """ If the file has unsaved changes it may be saved first.</p>""" |
|
229 )) |
|
230 self.connect(self.profileAct, SIGNAL('triggered()'), self.__profileScript) |
|
231 self.actions.append(self.profileAct) |
|
232 |
|
233 self.profileProjectAct = E4Action(self.trUtf8('Profile Project'), |
|
234 UI.PixmapCache.getIcon("profileProject.png"), |
|
235 self.trUtf8('Profile Project...'),0,0,self,'dbg_profile_project') |
|
236 self.profileProjectAct.setStatusTip(self.trUtf8('Profile the current Project')) |
|
237 self.profileProjectAct.setWhatsThis(self.trUtf8( |
|
238 """<b>Profile Project</b>""" |
|
239 """<p>Set the command line arguments and profile the current project.""" |
|
240 """ If files of the current project have unsaved changes they may""" |
|
241 """ be saved first.</p>""" |
|
242 )) |
|
243 self.connect(self.profileProjectAct, SIGNAL('triggered()'), self.__profileProject) |
|
244 self.actions.append(self.profileProjectAct) |
|
245 |
|
246 self.debugAct = E4Action(self.trUtf8('Debug Script'), |
|
247 UI.PixmapCache.getIcon("debugScript.png"), |
|
248 self.trUtf8('&Debug Script...'),Qt.Key_F5,0,self,'dbg_debug_script') |
|
249 self.debugAct.setStatusTip(self.trUtf8('Debug the current Script')) |
|
250 self.debugAct.setWhatsThis(self.trUtf8( |
|
251 """<b>Debug Script</b>""" |
|
252 """<p>Set the command line arguments and set the current line to be the""" |
|
253 """ first executable Python statement of the current editor window.""" |
|
254 """ If the file has unsaved changes it may be saved first.</p>""" |
|
255 )) |
|
256 self.connect(self.debugAct, SIGNAL('triggered()'), self.__debugScript) |
|
257 self.actions.append(self.debugAct) |
|
258 |
|
259 self.debugProjectAct = E4Action(self.trUtf8('Debug Project'), |
|
260 UI.PixmapCache.getIcon("debugProject.png"), |
|
261 self.trUtf8('Debug &Project...'),Qt.SHIFT + Qt.Key_F5,0,self, |
|
262 'dbg_debug_project') |
|
263 self.debugProjectAct.setStatusTip(self.trUtf8('Debug the current Project')) |
|
264 self.debugProjectAct.setWhatsThis(self.trUtf8( |
|
265 """<b>Debug Project</b>""" |
|
266 """<p>Set the command line arguments and set the current line to be the""" |
|
267 """ first executable Python statement of the main script of the current""" |
|
268 """ project. If files of the current project have unsaved changes they may""" |
|
269 """ be saved first.</p>""" |
|
270 )) |
|
271 self.connect(self.debugProjectAct, SIGNAL('triggered()'), self.__debugProject) |
|
272 self.actions.append(self.debugProjectAct) |
|
273 |
|
274 self.restartAct = E4Action(self.trUtf8('Restart Script'), |
|
275 UI.PixmapCache.getIcon("restart.png"), |
|
276 self.trUtf8('Restart Script'),Qt.Key_F4,0,self,'dbg_restart_script') |
|
277 self.restartAct.setStatusTip(self.trUtf8('Restart the last debugged script')) |
|
278 self.restartAct.setWhatsThis(self.trUtf8( |
|
279 """<b>Restart Script</b>""" |
|
280 """<p>Set the command line arguments and set the current line to be the""" |
|
281 """ first executable Python statement of the script that was debugged last.""" |
|
282 """ If there are unsaved changes, they may be saved first.</p>""" |
|
283 )) |
|
284 self.connect(self.restartAct, SIGNAL('triggered()'), self.__doRestart) |
|
285 self.actions.append(self.restartAct) |
|
286 |
|
287 self.stopAct = E4Action(self.trUtf8('Stop Script'), |
|
288 UI.PixmapCache.getIcon("stopScript.png"), |
|
289 self.trUtf8('Stop Script'),Qt.SHIFT + Qt.Key_F10,0, |
|
290 self,'dbg_stop_script') |
|
291 self.stopAct.setStatusTip(self.trUtf8("""Stop the running script.""")) |
|
292 self.stopAct.setWhatsThis(self.trUtf8( |
|
293 """<b>Stop Script</b>""" |
|
294 """<p>This stops the script running in the debugger backend.</p>""" |
|
295 )) |
|
296 self.connect(self.stopAct, SIGNAL('triggered()'), self.__stopScript) |
|
297 self.actions.append(self.stopAct) |
|
298 |
|
299 self.debugActGrp = createActionGroup(self) |
|
300 |
|
301 act = E4Action(self.trUtf8('Continue'), |
|
302 UI.PixmapCache.getIcon("continue.png"), |
|
303 self.trUtf8('&Continue'),Qt.Key_F6,0, |
|
304 self.debugActGrp,'dbg_continue') |
|
305 act.setStatusTip(\ |
|
306 self.trUtf8('Continue running the program from the current line')) |
|
307 act.setWhatsThis(self.trUtf8( |
|
308 """<b>Continue</b>""" |
|
309 """<p>Continue running the program from the current line. The program will""" |
|
310 """ stop when it terminates or when a breakpoint is reached.</p>""" |
|
311 )) |
|
312 self.connect(act, SIGNAL('triggered()'), self.__continue) |
|
313 self.actions.append(act) |
|
314 |
|
315 act = E4Action(self.trUtf8('Continue to Cursor'), |
|
316 UI.PixmapCache.getIcon("continueToCursor.png"), |
|
317 self.trUtf8('Continue &To Cursor'),Qt.SHIFT + Qt.Key_F6,0, |
|
318 self.debugActGrp,'dbg_continue_to_cursor') |
|
319 act.setStatusTip(self.trUtf8("""Continue running the program from the""" |
|
320 """ current line to the current cursor position""")) |
|
321 act.setWhatsThis(self.trUtf8( |
|
322 """<b>Continue To Cursor</b>""" |
|
323 """<p>Continue running the program from the current line to the""" |
|
324 """ current cursor position.</p>""" |
|
325 )) |
|
326 self.connect(act, SIGNAL('triggered()'), self.__runToCursor) |
|
327 self.actions.append(act) |
|
328 |
|
329 act = E4Action(self.trUtf8('Single Step'), |
|
330 UI.PixmapCache.getIcon("step.png"), |
|
331 self.trUtf8('Sin&gle Step'),Qt.Key_F7,0, |
|
332 self.debugActGrp,'dbg_single_step') |
|
333 act.setStatusTip(self.trUtf8('Execute a single Python statement')) |
|
334 act.setWhatsThis(self.trUtf8( |
|
335 """<b>Single Step</b>""" |
|
336 """<p>Execute a single Python statement. If the statement""" |
|
337 """ is an <tt>import</tt> statement, a class constructor, or a""" |
|
338 """ method or function call then control is returned to the debugger at""" |
|
339 """ the next statement.</p>""" |
|
340 )) |
|
341 self.connect(act, SIGNAL('triggered()'), self.__step) |
|
342 self.actions.append(act) |
|
343 |
|
344 act = E4Action(self.trUtf8('Step Over'), |
|
345 UI.PixmapCache.getIcon("stepOver.png"), |
|
346 self.trUtf8('Step &Over'),Qt.Key_F8,0, |
|
347 self.debugActGrp,'dbg_step_over') |
|
348 act.setStatusTip(self.trUtf8("""Execute a single Python statement staying""" |
|
349 """ in the current frame""")) |
|
350 act.setWhatsThis(self.trUtf8( |
|
351 """<b>Step Over</b>""" |
|
352 """<p>Execute a single Python statement staying in the same frame. If""" |
|
353 """ the statement is an <tt>import</tt> statement, a class constructor,""" |
|
354 """ or a method or function call then control is returned to the debugger""" |
|
355 """ after the statement has completed.</p>""" |
|
356 )) |
|
357 self.connect(act, SIGNAL('triggered()'), self.__stepOver) |
|
358 self.actions.append(act) |
|
359 |
|
360 act = E4Action(self.trUtf8('Step Out'), |
|
361 UI.PixmapCache.getIcon("stepOut.png"), |
|
362 self.trUtf8('Step Ou&t'),Qt.Key_F9,0, |
|
363 self.debugActGrp,'dbg_step_out') |
|
364 act.setStatusTip(self.trUtf8("""Execute Python statements until leaving""" |
|
365 """ the current frame""")) |
|
366 act.setWhatsThis(self.trUtf8( |
|
367 """<b>Step Out</b>""" |
|
368 """<p>Execute Python statements until leaving the current frame. If""" |
|
369 """ the statements are inside an <tt>import</tt> statement, a class""" |
|
370 """ constructor, or a method or function call then control is returned""" |
|
371 """ to the debugger after the current frame has been left.</p>""" |
|
372 )) |
|
373 self.connect(act, SIGNAL('triggered()'), self.__stepOut) |
|
374 self.actions.append(act) |
|
375 |
|
376 act = E4Action(self.trUtf8('Stop'), |
|
377 UI.PixmapCache.getIcon("stepQuit.png"), |
|
378 self.trUtf8('&Stop'),Qt.Key_F10,0, |
|
379 self.debugActGrp,'dbg_stop') |
|
380 act.setStatusTip(self.trUtf8('Stop debugging')) |
|
381 act.setWhatsThis(self.trUtf8( |
|
382 """<b>Stop</b>""" |
|
383 """<p>Stop the running debugging session.</p>""" |
|
384 )) |
|
385 self.connect(act, SIGNAL('triggered()'), self.__stepQuit) |
|
386 self.actions.append(act) |
|
387 |
|
388 self.debugActGrp2 = createActionGroup(self) |
|
389 |
|
390 act = E4Action(self.trUtf8('Evaluate'), |
|
391 self.trUtf8('E&valuate...'), |
|
392 0,0,self.debugActGrp2,'dbg_evaluate') |
|
393 act.setStatusTip(self.trUtf8('Evaluate in current context')) |
|
394 act.setWhatsThis(self.trUtf8( |
|
395 """<b>Evaluate</b>""" |
|
396 """<p>Evaluate an expression in the current context of the""" |
|
397 """ debugged program. The result is displayed in the""" |
|
398 """ shell window.</p>""" |
|
399 )) |
|
400 self.connect(act, SIGNAL('triggered()'), self.__eval) |
|
401 self.actions.append(act) |
|
402 |
|
403 act = E4Action(self.trUtf8('Execute'), |
|
404 self.trUtf8('E&xecute...'), |
|
405 0,0,self.debugActGrp2,'dbg_execute') |
|
406 act.setStatusTip(\ |
|
407 self.trUtf8('Execute a one line statement in the current context')) |
|
408 act.setWhatsThis(self.trUtf8( |
|
409 """<b>Execute</b>""" |
|
410 """<p>Execute a one line statement in the current context""" |
|
411 """ of the debugged program.</p>""" |
|
412 )) |
|
413 self.connect(act, SIGNAL('triggered()'), self.__exec) |
|
414 self.actions.append(act) |
|
415 |
|
416 self.dbgFilterAct = E4Action(self.trUtf8('Variables Type Filter'), |
|
417 self.trUtf8('Varia&bles Type Filter...'), 0, 0, self, |
|
418 'dbg_variables_filter') |
|
419 self.dbgFilterAct.setStatusTip(self.trUtf8('Configure variables type filter')) |
|
420 self.dbgFilterAct.setWhatsThis(self.trUtf8( |
|
421 """<b>Variables Type Filter</b>""" |
|
422 """<p>Configure the variables type filter. Only variable types that are not""" |
|
423 """ selected are displayed in the global or local variables window""" |
|
424 """ during a debugging session.</p>""" |
|
425 )) |
|
426 self.connect(self.dbgFilterAct, SIGNAL('triggered()'), |
|
427 self.__configureVariablesFilters) |
|
428 self.actions.append(self.dbgFilterAct) |
|
429 |
|
430 self.excFilterAct = E4Action(self.trUtf8('Exceptions Filter'), |
|
431 self.trUtf8('&Exceptions Filter...'), 0, 0, self, 'dbg_exceptions_filter') |
|
432 self.excFilterAct.setStatusTip(self.trUtf8('Configure exceptions filter')) |
|
433 self.excFilterAct.setWhatsThis(self.trUtf8( |
|
434 """<b>Exceptions Filter</b>""" |
|
435 """<p>Configure the exceptions filter. Only exception types that are""" |
|
436 """ listed are highlighted during a debugging session.</p>""" |
|
437 """<p>Please note, that all unhandled exceptions are highlighted""" |
|
438 """ indepent from the filter list.</p>""" |
|
439 )) |
|
440 self.connect(self.excFilterAct, SIGNAL('triggered()'), |
|
441 self.__configureExceptionsFilter) |
|
442 self.actions.append(self.excFilterAct) |
|
443 |
|
444 self.excIgnoreFilterAct = E4Action(self.trUtf8('Ignored Exceptions'), |
|
445 self.trUtf8('&Ignored Exceptions...'), 0, 0, |
|
446 self, 'dbg_ignored_exceptions') |
|
447 self.excIgnoreFilterAct.setStatusTip(self.trUtf8('Configure ignored exceptions')) |
|
448 self.excIgnoreFilterAct.setWhatsThis(self.trUtf8( |
|
449 """<b>Ignored Exceptions</b>""" |
|
450 """<p>Configure the ignored exceptions. Only exception types that are""" |
|
451 """ not listed are highlighted during a debugging session.</p>""" |
|
452 """<p>Please note, that unhandled exceptions cannot be ignored.</p>""" |
|
453 )) |
|
454 self.connect(self.excIgnoreFilterAct, SIGNAL('triggered()'), |
|
455 self.__configureIgnoredExceptions) |
|
456 self.actions.append(self.excIgnoreFilterAct) |
|
457 |
|
458 self.dbgSetBpActGrp = createActionGroup(self) |
|
459 |
|
460 self.dbgToggleBpAct = E4Action(self.trUtf8('Toggle Breakpoint'), |
|
461 UI.PixmapCache.getIcon("breakpointToggle.png"), |
|
462 self.trUtf8('Toggle Breakpoint'), |
|
463 QKeySequence(self.trUtf8("Shift+F11","Debug|Toggle Breakpoint")), 0, |
|
464 self.dbgSetBpActGrp, 'dbg_toggle_breakpoint') |
|
465 self.dbgToggleBpAct.setStatusTip(self.trUtf8('Toggle Breakpoint')) |
|
466 self.dbgToggleBpAct.setWhatsThis(self.trUtf8( |
|
467 """<b>Toggle Breakpoint</b>""" |
|
468 """<p>Toggles a breakpoint at the current line of the""" |
|
469 """ current editor.</p>""" |
|
470 )) |
|
471 self.connect(self.dbgToggleBpAct, SIGNAL('triggered()'), self.__toggleBreakpoint) |
|
472 self.actions.append(self.dbgToggleBpAct) |
|
473 |
|
474 self.dbgEditBpAct = E4Action(self.trUtf8('Edit Breakpoint'), |
|
475 UI.PixmapCache.getIcon("cBreakpointToggle.png"), |
|
476 self.trUtf8('Edit Breakpoint...'), |
|
477 QKeySequence(self.trUtf8("Shift+F12","Debug|Edit Breakpoint")), 0, |
|
478 self.dbgSetBpActGrp, 'dbg_edit_breakpoint') |
|
479 self.dbgEditBpAct.setStatusTip(self.trUtf8('Edit Breakpoint')) |
|
480 self.dbgEditBpAct.setWhatsThis(self.trUtf8( |
|
481 """<b>Edit Breakpoint</b>""" |
|
482 """<p>Opens a dialog to edit the breakpoints properties.""" |
|
483 """ It works at the current line of the current editor.</p>""" |
|
484 )) |
|
485 self.connect(self.dbgEditBpAct, SIGNAL('triggered()'), self.__editBreakpoint) |
|
486 self.actions.append(self.dbgEditBpAct) |
|
487 |
|
488 self.dbgNextBpAct = E4Action(self.trUtf8('Next Breakpoint'), |
|
489 UI.PixmapCache.getIcon("breakpointNext.png"), |
|
490 self.trUtf8('Next Breakpoint'), |
|
491 QKeySequence(self.trUtf8("Ctrl+Shift+PgDown","Debug|Next Breakpoint")), 0, |
|
492 self.dbgSetBpActGrp, 'dbg_next_breakpoint') |
|
493 self.dbgNextBpAct.setStatusTip(self.trUtf8('Next Breakpoint')) |
|
494 self.dbgNextBpAct.setWhatsThis(self.trUtf8( |
|
495 """<b>Next Breakpoint</b>""" |
|
496 """<p>Go to next breakpoint of the current editor.</p>""" |
|
497 )) |
|
498 self.connect(self.dbgNextBpAct, SIGNAL('triggered()'), self.__nextBreakpoint) |
|
499 self.actions.append(self.dbgNextBpAct) |
|
500 |
|
501 self.dbgPrevBpAct = E4Action(self.trUtf8('Previous Breakpoint'), |
|
502 UI.PixmapCache.getIcon("breakpointPrevious.png"), |
|
503 self.trUtf8('Previous Breakpoint'), |
|
504 QKeySequence(self.trUtf8("Ctrl+Shift+PgUp","Debug|Previous Breakpoint")), |
|
505 0, self.dbgSetBpActGrp, 'dbg_previous_breakpoint') |
|
506 self.dbgPrevBpAct.setStatusTip(self.trUtf8('Previous Breakpoint')) |
|
507 self.dbgPrevBpAct.setWhatsThis(self.trUtf8( |
|
508 """<b>Previous Breakpoint</b>""" |
|
509 """<p>Go to previous breakpoint of the current editor.</p>""" |
|
510 )) |
|
511 self.connect(self.dbgPrevBpAct, SIGNAL('triggered()'), self.__previousBreakpoint) |
|
512 self.actions.append(self.dbgPrevBpAct) |
|
513 |
|
514 act = E4Action(self.trUtf8('Clear Breakpoints'), |
|
515 self.trUtf8('Clear Breakpoints'), |
|
516 QKeySequence(self.trUtf8("Ctrl+Shift+C","Debug|Clear Breakpoints")), 0, |
|
517 self.dbgSetBpActGrp, 'dbg_clear_breakpoint') |
|
518 act.setStatusTip(self.trUtf8('Clear Breakpoints')) |
|
519 act.setWhatsThis(self.trUtf8( |
|
520 """<b>Clear Breakpoints</b>""" |
|
521 """<p>Clear breakpoints of all editors.</p>""" |
|
522 )) |
|
523 self.connect(act, SIGNAL('triggered()'), self.__clearBreakpoints) |
|
524 self.actions.append(act) |
|
525 |
|
526 self.debugActGrp.setEnabled(False) |
|
527 self.debugActGrp2.setEnabled(False) |
|
528 self.dbgSetBpActGrp.setEnabled(False) |
|
529 self.runAct.setEnabled(False) |
|
530 self.runProjectAct.setEnabled(False) |
|
531 self.profileAct.setEnabled(False) |
|
532 self.profileProjectAct.setEnabled(False) |
|
533 self.coverageAct.setEnabled(False) |
|
534 self.coverageProjectAct.setEnabled(False) |
|
535 self.debugAct.setEnabled(False) |
|
536 self.debugProjectAct.setEnabled(False) |
|
537 self.restartAct.setEnabled(False) |
|
538 self.stopAct.setEnabled(False) |
|
539 |
|
540 def initMenus(self): |
|
541 """ |
|
542 Public slot to initialize the project menu. |
|
543 |
|
544 @return the generated menu |
|
545 """ |
|
546 dmenu = QMenu(self.trUtf8('&Debug'), self.parent()) |
|
547 dmenu.setTearOffEnabled(True) |
|
548 smenu = QMenu(self.trUtf8('&Start'), self.parent()) |
|
549 smenu.setTearOffEnabled(True) |
|
550 self.breakpointsMenu = QMenu(self.trUtf8('&Breakpoints'), dmenu) |
|
551 |
|
552 smenu.addAction(self.restartAct) |
|
553 smenu.addAction(self.stopAct) |
|
554 smenu.addSeparator() |
|
555 smenu.addAction(self.runAct) |
|
556 smenu.addAction(self.runProjectAct) |
|
557 smenu.addSeparator() |
|
558 smenu.addAction(self.debugAct) |
|
559 smenu.addAction(self.debugProjectAct) |
|
560 smenu.addSeparator() |
|
561 smenu.addAction(self.profileAct) |
|
562 smenu.addAction(self.profileProjectAct) |
|
563 smenu.addSeparator() |
|
564 smenu.addAction(self.coverageAct) |
|
565 smenu.addAction(self.coverageProjectAct) |
|
566 |
|
567 dmenu.addActions(self.debugActGrp.actions()) |
|
568 dmenu.addSeparator() |
|
569 dmenu.addActions(self.debugActGrp2.actions()) |
|
570 dmenu.addSeparator() |
|
571 dmenu.addActions(self.dbgSetBpActGrp.actions()) |
|
572 self.menuBreakpointsAct = dmenu.addMenu(self.breakpointsMenu) |
|
573 dmenu.addSeparator() |
|
574 dmenu.addAction(self.dbgFilterAct) |
|
575 dmenu.addAction(self.excFilterAct) |
|
576 dmenu.addAction(self.excIgnoreFilterAct) |
|
577 |
|
578 self.connect(self.breakpointsMenu, SIGNAL('aboutToShow()'), |
|
579 self.__showBreakpointsMenu) |
|
580 self.connect(self.breakpointsMenu, SIGNAL('triggered(QAction *)'), |
|
581 self.__breakpointSelected) |
|
582 self.connect(dmenu, SIGNAL('aboutToShow()'), self.__showDebugMenu) |
|
583 |
|
584 return smenu, dmenu |
|
585 |
|
586 def initToolbars(self, toolbarManager): |
|
587 """ |
|
588 Public slot to initialize the debug toolbars. |
|
589 |
|
590 @param toolbarManager reference to a toolbar manager object (E4ToolBarManager) |
|
591 @return the generated toolbars (list of QToolBar) |
|
592 """ |
|
593 starttb = QToolBar(self.trUtf8("Start"), self.parent()) |
|
594 starttb.setIconSize(UI.Config.ToolBarIconSize) |
|
595 starttb.setObjectName("StartToolbar") |
|
596 starttb.setToolTip(self.trUtf8('Start')) |
|
597 |
|
598 starttb.addAction(self.restartAct) |
|
599 starttb.addAction(self.stopAct) |
|
600 starttb.addSeparator() |
|
601 starttb.addAction(self.runAct) |
|
602 starttb.addAction(self.runProjectAct) |
|
603 starttb.addSeparator() |
|
604 starttb.addAction(self.debugAct) |
|
605 starttb.addAction(self.debugProjectAct) |
|
606 |
|
607 debugtb = QToolBar(self.trUtf8("Debug"), self.parent()) |
|
608 debugtb.setIconSize(UI.Config.ToolBarIconSize) |
|
609 debugtb.setObjectName("DebugToolbar") |
|
610 debugtb.setToolTip(self.trUtf8('Debug')) |
|
611 |
|
612 debugtb.addActions(self.debugActGrp.actions()) |
|
613 debugtb.addSeparator() |
|
614 debugtb.addAction(self.dbgToggleBpAct) |
|
615 debugtb.addAction(self.dbgEditBpAct) |
|
616 debugtb.addAction(self.dbgNextBpAct) |
|
617 debugtb.addAction(self.dbgPrevBpAct) |
|
618 |
|
619 toolbarManager.addToolBar(starttb, starttb.windowTitle()) |
|
620 toolbarManager.addToolBar(debugtb, debugtb.windowTitle()) |
|
621 toolbarManager.addAction(self.profileAct, starttb.windowTitle()) |
|
622 toolbarManager.addAction(self.profileProjectAct, starttb.windowTitle()) |
|
623 toolbarManager.addAction(self.coverageAct, starttb.windowTitle()) |
|
624 toolbarManager.addAction(self.coverageProjectAct, starttb.windowTitle()) |
|
625 |
|
626 return [starttb, debugtb] |
|
627 |
|
628 def setArgvHistory(self, argsStr, clearHistories = False): |
|
629 """ |
|
630 Public slot to initialize the argv history. |
|
631 |
|
632 @param argsStr the commandline arguments (string) |
|
633 @param clearHistories flag indicating, that the list should |
|
634 be cleared (boolean) |
|
635 """ |
|
636 if clearHistories: |
|
637 self.argvHistory = [] |
|
638 else: |
|
639 if argsStr in self.argvHistory: |
|
640 self.argvHistory.remove(argsStr) |
|
641 self.argvHistory.insert(0, argsStr) |
|
642 |
|
643 def setWdHistory(self, wdStr, clearHistories = False): |
|
644 """ |
|
645 Public slot to initialize the wd history. |
|
646 |
|
647 @param wdStr the working directory (string) |
|
648 @param clearHistories flag indicating, that the list should |
|
649 be cleared (boolean) |
|
650 """ |
|
651 if clearHistories: |
|
652 self.wdHistory = [] |
|
653 else: |
|
654 if wdStr in self.wdHistory: |
|
655 self.wdHistory.remove(wdStr) |
|
656 self.wdHistory.insert(0, wdStr) |
|
657 |
|
658 def setEnvHistory(self, envStr, clearHistories = False): |
|
659 """ |
|
660 Public slot to initialize the env history. |
|
661 |
|
662 @param envStr the environment settings (string) |
|
663 @param clearHistories flag indicating, that the list should |
|
664 be cleared (boolean) |
|
665 """ |
|
666 if clearHistories: |
|
667 self.envHistory = [] |
|
668 else: |
|
669 if envStr in self.envHistory: |
|
670 self.envHistory.remove(envStr) |
|
671 self.envHistory.insert(0, envStr) |
|
672 |
|
673 def setExceptionReporting(self, exceptions): |
|
674 """ |
|
675 Public slot to initialize the exception reporting flag. |
|
676 |
|
677 @param exceptions flag indicating exception reporting status (boolean) |
|
678 """ |
|
679 self.exceptions = exceptions |
|
680 |
|
681 def setExcList(self, excList): |
|
682 """ |
|
683 Public slot to initialize the exceptions type list. |
|
684 |
|
685 @param excList list of exception types (list of strings) |
|
686 """ |
|
687 self.excList = excList[:] # keep a copy |
|
688 |
|
689 def setExcIgnoreList(self, excIgnoreList): |
|
690 """ |
|
691 Public slot to initialize the ignored exceptions type list. |
|
692 |
|
693 @param excIgnoreList list of ignored exception types (list of strings) |
|
694 """ |
|
695 self.excIgnoreList = excIgnoreList[:] # keep a copy |
|
696 |
|
697 def setAutoClearShell(self, autoClearShell): |
|
698 """ |
|
699 Public slot to initialize the autoClearShell flag. |
|
700 |
|
701 @param autoClearShell flag indicating, that the interpreter window |
|
702 should be cleared (boolean) |
|
703 """ |
|
704 self.autoClearShell = autoClearShell |
|
705 |
|
706 def setTracePython(self, tracePython): |
|
707 """ |
|
708 Public slot to initialize the trace Python flag. |
|
709 |
|
710 @param tracePython flag indicating if the Python library should be |
|
711 traced as well (boolean) |
|
712 """ |
|
713 self.tracePython = tracePython |
|
714 |
|
715 def setAutoContinue(self, autoContinue): |
|
716 """ |
|
717 Public slot to initialize the autoContinue flag. |
|
718 |
|
719 @param autoContinue flag indicating, that the debugger should not stop at |
|
720 the first executable line (boolean) |
|
721 """ |
|
722 self.autoContinue = autoContinue |
|
723 |
|
724 def __editorOpened(self, fn): |
|
725 """ |
|
726 Private slot to handle the editorOpened signal. |
|
727 |
|
728 @param fn filename of the opened editor |
|
729 """ |
|
730 self.editorOpen = True |
|
731 |
|
732 if fn: |
|
733 editor = self.viewmanager.getOpenEditor(fn) |
|
734 else: |
|
735 editor = None |
|
736 self.__checkActions(editor) |
|
737 |
|
738 def __lastEditorClosed(self): |
|
739 """ |
|
740 Private slot to handle the closeProgram signal. |
|
741 """ |
|
742 self.editorOpen = False |
|
743 self.debugAct.setEnabled(False) |
|
744 self.runAct.setEnabled(False) |
|
745 self.profileAct.setEnabled(False) |
|
746 self.coverageAct.setEnabled(False) |
|
747 self.debugActGrp.setEnabled(False) |
|
748 self.debugActGrp2.setEnabled(False) |
|
749 self.dbgSetBpActGrp.setEnabled(False) |
|
750 self.lastAction = -1 |
|
751 if not self.projectOpen: |
|
752 self.restartAct.setEnabled(False) |
|
753 self.lastDebuggedFile = None |
|
754 self.lastStartAction = 0 |
|
755 |
|
756 def __checkActions(self, editor): |
|
757 """ |
|
758 Private slot to check some actions for their enable/disable status. |
|
759 |
|
760 @param editor editor window |
|
761 """ |
|
762 if editor: |
|
763 fn = editor.getFileName() |
|
764 else: |
|
765 fn = None |
|
766 |
|
767 cap = 0 |
|
768 if fn: |
|
769 for language in self.debugServer.getSupportedLanguages(): |
|
770 exts = self.debugServer.getExtensions(language) |
|
771 if fn.endswith(exts): |
|
772 cap = self.debugServer.getClientCapabilities(language) |
|
773 break |
|
774 else: |
|
775 if editor.isPyFile(): |
|
776 cap = self.debugServer.getClientCapabilities('Python') |
|
777 elif editor.isPy3File(): |
|
778 cap = self.debugServer.getClientCapabilities('Python3') |
|
779 elif editor.isRubyFile(): |
|
780 cap = self.debugServer.getClientCapabilities('Ruby') |
|
781 |
|
782 if not self.passive: |
|
783 self.runAct.setEnabled(cap & HasInterpreter) |
|
784 self.coverageAct.setEnabled(cap & HasCoverage) |
|
785 self.profileAct.setEnabled(cap & HasProfiler) |
|
786 self.debugAct.setEnabled(cap & HasDebugger) |
|
787 self.dbgSetBpActGrp.setEnabled(cap & HasDebugger) |
|
788 if editor.curLineHasBreakpoint(): |
|
789 self.dbgEditBpAct.setEnabled(True) |
|
790 else: |
|
791 self.dbgEditBpAct.setEnabled(False) |
|
792 if editor.hasBreakpoints(): |
|
793 self.dbgNextBpAct.setEnabled(True) |
|
794 self.dbgPrevBpAct.setEnabled(True) |
|
795 else: |
|
796 self.dbgNextBpAct.setEnabled(False) |
|
797 self.dbgPrevBpAct.setEnabled(False) |
|
798 else: |
|
799 self.runAct.setEnabled(False) |
|
800 self.coverageAct.setEnabled(False) |
|
801 self.profileAct.setEnabled(False) |
|
802 self.debugAct.setEnabled(False) |
|
803 self.dbgSetBpActGrp.setEnabled(False) |
|
804 |
|
805 def __cursorChanged(self, editor): |
|
806 """ |
|
807 Private slot handling the cursorChanged signal of the viewmanager. |
|
808 |
|
809 @param editor editor window |
|
810 """ |
|
811 if editor is None: |
|
812 return |
|
813 |
|
814 if editor.isPyFile() or editor.isPy3File() or editor.isRubyFile(): |
|
815 if editor.curLineHasBreakpoint(): |
|
816 self.dbgEditBpAct.setEnabled(True) |
|
817 else: |
|
818 self.dbgEditBpAct.setEnabled(False) |
|
819 if editor.hasBreakpoints(): |
|
820 self.dbgNextBpAct.setEnabled(True) |
|
821 self.dbgPrevBpAct.setEnabled(True) |
|
822 else: |
|
823 self.dbgNextBpAct.setEnabled(False) |
|
824 self.dbgPrevBpAct.setEnabled(False) |
|
825 |
|
826 def __projectOpened(self): |
|
827 """ |
|
828 Private slot to handle the projectOpened signal. |
|
829 """ |
|
830 self.projectOpen = True |
|
831 cap = self.debugServer.getClientCapabilities(\ |
|
832 self.project.pdata["PROGLANGUAGE"][0]) |
|
833 if not self.passive: |
|
834 self.debugProjectAct.setEnabled(cap & HasDebugger) |
|
835 self.runProjectAct.setEnabled(cap & HasInterpreter) |
|
836 self.profileProjectAct.setEnabled(cap & HasProfiler) |
|
837 self.coverageProjectAct.setEnabled(cap & HasCoverage) |
|
838 |
|
839 def __projectClosed(self): |
|
840 """ |
|
841 Private slot to handle the projectClosed signal. |
|
842 """ |
|
843 self.projectOpen = False |
|
844 self.runProjectAct.setEnabled(False) |
|
845 self.profileProjectAct.setEnabled(False) |
|
846 self.coverageProjectAct.setEnabled(False) |
|
847 self.debugProjectAct.setEnabled(False) |
|
848 |
|
849 if not self.editorOpen: |
|
850 self.restartAct.setEnabled(False) |
|
851 self.lastDebuggedFile = None |
|
852 self.lastStartAction = 0 |
|
853 |
|
854 def __projectSessionLoaded(self): |
|
855 """ |
|
856 Private slot to handle the projectSessionLoaded signal. |
|
857 """ |
|
858 fn = self.project.getMainScript(True) |
|
859 if fn is not None: |
|
860 self.lastStartAction = 2 |
|
861 self.lastDebuggedFile = fn |
|
862 self.restartAct.setEnabled(True) |
|
863 |
|
864 def shutdown(self): |
|
865 """ |
|
866 Public method to perform shutdown actions. |
|
867 """ |
|
868 # Just save the 10 most recent entries |
|
869 del self.argvHistory[10:] |
|
870 del self.wdHistory[10:] |
|
871 del self.envHistory[10:] |
|
872 |
|
873 Preferences.Prefs.settings.setValue('DebugInfo/ArgumentsHistory', |
|
874 QVariant(self.argvHistory)) |
|
875 Preferences.Prefs.settings.setValue('DebugInfo/WorkingDirectoryHistory', |
|
876 QVariant(self.wdHistory)) |
|
877 Preferences.Prefs.settings.setValue('DebugInfo/EnvironmentHistory', |
|
878 QVariant(self.envHistory)) |
|
879 Preferences.Prefs.settings.setValue('DebugInfo/Exceptions', |
|
880 QVariant(self.excList)) |
|
881 Preferences.Prefs.settings.setValue('DebugInfo/IgnoredExceptions', |
|
882 QVariant(self.excIgnoreList)) |
|
883 Preferences.Prefs.settings.setValue('DebugInfo/ReportExceptions', |
|
884 QVariant(self.exceptions)) |
|
885 Preferences.Prefs.settings.setValue('DebugInfo/AutoClearShell', |
|
886 QVariant(self.autoClearShell)) |
|
887 Preferences.Prefs.settings.setValue('DebugInfo/TracePython', |
|
888 QVariant(self.tracePython)) |
|
889 Preferences.Prefs.settings.setValue('DebugInfo/AutoContinue', |
|
890 QVariant(self.autoContinue)) |
|
891 Preferences.Prefs.settings.setValue('DebugInfo/ForkAutomatically', |
|
892 QVariant(self.forkAutomatically)) |
|
893 Preferences.Prefs.settings.setValue('DebugInfo/ForkIntoChild', |
|
894 QVariant(self.forkIntoChild)) |
|
895 |
|
896 def shutdownServer(self): |
|
897 """ |
|
898 Public method to shut down the debug server. |
|
899 |
|
900 This is needed to cleanly close the sockets on Win OS. |
|
901 |
|
902 @return always true |
|
903 """ |
|
904 self.debugServer.shutdownServer() |
|
905 return True |
|
906 |
|
907 def __resetUI(self): |
|
908 """ |
|
909 Private slot to reset the user interface. |
|
910 """ |
|
911 self.lastAction = -1 |
|
912 self.debugActGrp.setEnabled(False) |
|
913 self.debugActGrp2.setEnabled(False) |
|
914 if not self.passive: |
|
915 if self.editorOpen: |
|
916 editor = self.viewmanager.activeWindow() |
|
917 else: |
|
918 editor = None |
|
919 self.__checkActions(editor) |
|
920 |
|
921 self.debugProjectAct.setEnabled(self.projectOpen) |
|
922 self.runProjectAct.setEnabled(self.projectOpen) |
|
923 self.profileProjectAct.setEnabled(self.projectOpen) |
|
924 self.coverageProjectAct.setEnabled(self.projectOpen) |
|
925 if self.lastDebuggedFile is not None and \ |
|
926 (self.editorOpen or self.projectOpen): |
|
927 self.restartAct.setEnabled(True) |
|
928 else: |
|
929 self.restartAct.setEnabled(False) |
|
930 self.stopAct.setEnabled(False) |
|
931 self.emit(SIGNAL('resetUI')) |
|
932 |
|
933 def __clientLine(self, fn, line, forStack): |
|
934 """ |
|
935 Private method to handle a change to the current line. |
|
936 |
|
937 @param fn filename (string) |
|
938 @param line linenumber (int) |
|
939 @param forStack flag indicating this is for a stack dump (boolean) |
|
940 """ |
|
941 self.ui.raise_() |
|
942 self.ui.activateWindow() |
|
943 if self.ui.getViewProfile() != "debug": |
|
944 self.ui.setDebugProfile() |
|
945 self.viewmanager.setFileLine(fn, line) |
|
946 if not forStack: |
|
947 self.__getThreadList() |
|
948 self.__getClientVariables() |
|
949 |
|
950 def __clientExit(self, status): |
|
951 """ |
|
952 Private method to handle the debugged program terminating. |
|
953 |
|
954 @param status exit code of the debugged program (int) |
|
955 """ |
|
956 self.viewmanager.exit() |
|
957 |
|
958 self.__resetUI() |
|
959 |
|
960 if not Preferences.getDebugger("SuppressClientExit") or status != 0: |
|
961 if self.ui.currentProg is None: |
|
962 QMessageBox.information(self.ui,Program, |
|
963 self.trUtf8('<p>The program has terminated with an exit' |
|
964 ' status of {0}.</p>').format(status)) |
|
965 else: |
|
966 QMessageBox.information(self.ui,Program, |
|
967 self.trUtf8('<p><b>{0}</b> has terminated with an exit' |
|
968 ' status of {1}.</p>') |
|
969 .format(Utilities.normabspath(self.ui.currentProg), status)) |
|
970 |
|
971 def __clientSyntaxError(self, message, filename, lineNo, characterNo): |
|
972 """ |
|
973 Private method to handle a syntax error in the debugged program. |
|
974 |
|
975 @param message message of the syntax error (string) |
|
976 @param filename translated filename of the syntax error position (string) |
|
977 @param lineNo line number of the syntax error position (integer) |
|
978 @param characterNo character number of the syntax error position (integer) |
|
979 """ |
|
980 self.__resetUI() |
|
981 self.ui.raise_() |
|
982 self.ui.activateWindow() |
|
983 |
|
984 if message is None: |
|
985 QMessageBox.critical(self.ui,Program, |
|
986 self.trUtf8('The program being debugged contains an unspecified' |
|
987 ' syntax error.')) |
|
988 return |
|
989 |
|
990 self.viewmanager.setFileLine(filename, lineNo, True, True) |
|
991 QMessageBox.critical(self.ui,Program, |
|
992 self.trUtf8('<p>The file <b>{0}</b> contains the syntax error' |
|
993 ' <b>{1}</b> at line <b>{2}</b>, character <b>{3}</b>.</p>') |
|
994 .format(filename, message, lineNo, characterNo)) |
|
995 |
|
996 def __clientException(self, exceptionType, exceptionMessage, stackTrace): |
|
997 """ |
|
998 Private method to handle an exception of the debugged program. |
|
999 |
|
1000 @param exceptionType type of exception raised (string) |
|
1001 @param exceptionMessage message given by the exception (string) |
|
1002 @param stackTrace list of stack entries. |
|
1003 """ |
|
1004 self.ui.raise_() |
|
1005 self.ui.activateWindow() |
|
1006 QApplication.processEvents() |
|
1007 if exceptionType is None: |
|
1008 QMessageBox.critical(self.ui,Program, |
|
1009 self.trUtf8('An unhandled exception occured.' |
|
1010 ' See the shell window for details.')) |
|
1011 return |
|
1012 |
|
1013 if (self.exceptions and \ |
|
1014 exceptionType not in self.excIgnoreList and \ |
|
1015 (not len(self.excList) or \ |
|
1016 (len(self.excList) and exceptionType in self.excList)))\ |
|
1017 or exceptionType.startswith('unhandled'): |
|
1018 if stackTrace: |
|
1019 self.viewmanager.setFileLine(stackTrace[0][0], stackTrace[0][1], True) |
|
1020 if Preferences.getDebugger("BreakAlways"): |
|
1021 res = QMessageBox.Yes |
|
1022 else: |
|
1023 if stackTrace: |
|
1024 if exceptionType.startswith('unhandled'): |
|
1025 buttons = QMessageBox.StandardButtons(\ |
|
1026 QMessageBox.No | \ |
|
1027 QMessageBox.Yes) |
|
1028 else: |
|
1029 buttons = QMessageBox.StandardButtons(\ |
|
1030 QMessageBox.No | \ |
|
1031 QMessageBox.Yes | \ |
|
1032 QMessageBox.Ignore) |
|
1033 res = QMessageBox.critical(self.ui, Program, |
|
1034 self.trUtf8('<p>The debugged program raised the exception' |
|
1035 ' <b>{0}</b><br>"<b>{1}</b>"<br>File: <b>{2}</b>,' |
|
1036 ' Line: <b>{3}</b></p><p>Break here?</p>') |
|
1037 .format(exceptionType, |
|
1038 Utilities.html_encode(exceptionMessage), |
|
1039 stackTrace[0][0], |
|
1040 stackTrace[0][1]), |
|
1041 buttons, |
|
1042 QMessageBox.No) |
|
1043 else: |
|
1044 res = QMessageBox.critical(self.ui, Program, |
|
1045 self.trUtf8('<p>The debugged program raised the exception' |
|
1046 ' <b>{0}</b><br>"<b>{1}</b>"</p>') |
|
1047 .format(exceptionType, |
|
1048 Utilities.html_encode(exceptionMessage))) |
|
1049 if res == QMessageBox.Yes: |
|
1050 self.emit(SIGNAL('exceptionInterrupt')) |
|
1051 stack = [] |
|
1052 for fn, ln in stackTrace: |
|
1053 stack.append((fn, ln, '')) |
|
1054 self.emit(SIGNAL('clientStack'), stack) |
|
1055 self.__getClientVariables() |
|
1056 self.ui.setDebugProfile() |
|
1057 return |
|
1058 elif res == QMessageBox.Ignore: |
|
1059 if exceptionType not in self.excIgnoreList: |
|
1060 self.excIgnoreList.append(exceptionType) |
|
1061 |
|
1062 if self.lastAction != -1: |
|
1063 if self.lastAction == 2: |
|
1064 self.__specialContinue() |
|
1065 else: |
|
1066 self.debugActions[self.lastAction]() |
|
1067 else: |
|
1068 self.__continue() |
|
1069 |
|
1070 def __clientGone(self,unplanned): |
|
1071 """ |
|
1072 Private method to handle the disconnection of the debugger client. |
|
1073 |
|
1074 @param unplanned 1 if the client died, 0 otherwise |
|
1075 """ |
|
1076 self.__resetUI() |
|
1077 if unplanned: |
|
1078 QMessageBox.information(self.ui,Program, |
|
1079 self.trUtf8('The program being debugged has terminated unexpectedly.')) |
|
1080 |
|
1081 def __getThreadList(self): |
|
1082 """ |
|
1083 Private method to get the list of threads from the client. |
|
1084 """ |
|
1085 self.debugServer.remoteThreadList() |
|
1086 |
|
1087 def __clientThreadSet(self): |
|
1088 """ |
|
1089 Private method to handle a change of the client's current thread. |
|
1090 """ |
|
1091 self.debugServer.remoteClientVariables(0, self.localsVarFilter) |
|
1092 |
|
1093 def __getClientVariables(self): |
|
1094 """ |
|
1095 Private method to request the global and local variables. |
|
1096 |
|
1097 In the first step, the global variables are requested from the client. |
|
1098 Once these have been received, the local variables are requested. |
|
1099 This happens in the method '__clientVariables'. |
|
1100 """ |
|
1101 # get globals first |
|
1102 self.debugServer.remoteClientVariables(1, self.globalsVarFilter) |
|
1103 # the local variables are requested once we have received the globals |
|
1104 |
|
1105 def __clientVariables(self, scope, variables): |
|
1106 """ |
|
1107 Private method to write the clients variables to the user interface. |
|
1108 |
|
1109 @param scope scope of the variables (-1 = empty global, 1 = global, 0 = local) |
|
1110 @param variables the list of variables from the client |
|
1111 """ |
|
1112 if scope > 0: |
|
1113 self.debugViewer.showVariables(variables, True) |
|
1114 if scope == 1: |
|
1115 # now get the local variables |
|
1116 self.debugServer.remoteClientVariables(0, self.localsVarFilter) |
|
1117 elif scope == 0: |
|
1118 self.debugViewer.showVariables(variables, False) |
|
1119 elif scope == -1: |
|
1120 vlist = [('None','','')] |
|
1121 self.debugViewer.showVariables(vlist, False) |
|
1122 |
|
1123 if scope < 1: |
|
1124 self.debugActGrp.setEnabled(True) |
|
1125 self.debugActGrp2.setEnabled(True) |
|
1126 |
|
1127 def __clientVariable(self, scope, variables): |
|
1128 """ |
|
1129 Private method to write the contents of a clients classvariable to the user |
|
1130 interface. |
|
1131 |
|
1132 @param scope scope of the variables (-1 = empty global, 1 = global, 0 = local) |
|
1133 @param variables the list of members of a classvariable from the client |
|
1134 """ |
|
1135 if scope == 1: |
|
1136 self.debugViewer.showVariable(variables, 1) |
|
1137 elif scope == 0: |
|
1138 self.debugViewer.showVariable(variables, 0) |
|
1139 |
|
1140 def __clientBreakConditionError(self, filename, lineno): |
|
1141 """ |
|
1142 Private method to handle a condition error of a breakpoint. |
|
1143 |
|
1144 @param filename filename of the breakpoint (string) |
|
1145 @param lineno linenumber of the breakpoint (integer) |
|
1146 """ |
|
1147 QMessageBox.critical(None, |
|
1148 self.trUtf8("Breakpoint Condition Error"), |
|
1149 self.trUtf8("""<p>The condition of the breakpoint <b>{0}, {1}</b>""" |
|
1150 """ contains a syntax error.</p>""")\ |
|
1151 .format(filename, lineno)) |
|
1152 |
|
1153 model = self.debugServer.getBreakPointModel() |
|
1154 index = model.getBreakPointIndex(filename, lineno) |
|
1155 if not index.isValid(): |
|
1156 return |
|
1157 |
|
1158 bp = model.getBreakPointByIndex(index) |
|
1159 if not bp: |
|
1160 return |
|
1161 |
|
1162 fn, line, cond, temp, enabled, count = bp[:6] |
|
1163 |
|
1164 dlg = EditBreakpointDialog((fn, line), (cond, temp, enabled, count), |
|
1165 [], self.ui, modal = True) |
|
1166 if dlg.exec_() == QDialog.Accepted: |
|
1167 cond, temp, enabled, count = dlg.getData() |
|
1168 model.setBreakPointByIndex(index, fn, line, (cond, temp, enabled, count)) |
|
1169 |
|
1170 def __clientWatchConditionError(self, cond): |
|
1171 """ |
|
1172 Public method to handle a expression error of a watch expression. |
|
1173 |
|
1174 Note: This can only happen for normal watch expressions |
|
1175 |
|
1176 @param cond expression of the watch expression (string) |
|
1177 """ |
|
1178 QMessageBox.critical(None, |
|
1179 self.trUtf8("Watch Expression Error"), |
|
1180 self.trUtf8("""<p>The watch expression <b>{0}</b>""" |
|
1181 """ contains a syntax error.</p>""")\ |
|
1182 .format(cond)) |
|
1183 |
|
1184 model = self.debugServer.getWatchPointModel() |
|
1185 index = model.getWatchPointIndex(cond) |
|
1186 if not index.isValid(): |
|
1187 return |
|
1188 |
|
1189 wp = model.getWatchPointByIndex(index) |
|
1190 if not wp: |
|
1191 return |
|
1192 |
|
1193 cond, special, temp, enabled, count = wp[:5] |
|
1194 |
|
1195 dlg = EditWatchpointDialog(\ |
|
1196 (cond, temp, enabled, count, special), self) |
|
1197 if dlg.exec_() == QDialog.Accepted: |
|
1198 cond, temp, enabled, count, special = dlg.getData() |
|
1199 |
|
1200 # check for duplicates |
|
1201 idx = self.__model.getWatchPointIndex(cond, special) |
|
1202 duplicate = idx.isValid() and idx.internalPointer() != index.internalPointer() |
|
1203 if duplicate: |
|
1204 if not special: |
|
1205 msg = self.trUtf8("""<p>A watch expression '<b>{0}</b>'""" |
|
1206 """ already exists.</p>""")\ |
|
1207 .format(Utilities.html_encode(cond)) |
|
1208 else: |
|
1209 msg = self.trUtf8("""<p>A watch expression '<b>{0}</b>'""" |
|
1210 """ for the variable <b>{1}</b> already exists.</p>""")\ |
|
1211 .format(special, |
|
1212 Utilities.html_encode(cond)) |
|
1213 QMessageBox.warning(None, |
|
1214 self.trUtf8("Watch expression already exists"), |
|
1215 msg) |
|
1216 model.deleteWatchPointByIndex(index) |
|
1217 else: |
|
1218 model.setWatchPointByIndex(index, cond, special, |
|
1219 (temp, enabled, count)) |
|
1220 |
|
1221 def __configureVariablesFilters(self): |
|
1222 """ |
|
1223 Private slot for displaying the variables filter configuration dialog. |
|
1224 """ |
|
1225 result = self.dbgFilterDialog.exec_() |
|
1226 if result == QDialog.Accepted: |
|
1227 self.localsVarFilter, self.globalsVarFilter = \ |
|
1228 self.dbgFilterDialog.getSelection() |
|
1229 else: |
|
1230 self.dbgFilterDialog.setSelection( |
|
1231 self.localsVarFilter, self.globalsVarFilter) |
|
1232 self.debugViewer.setVariablesFilter(self.globalsVarFilter, self.localsVarFilter) |
|
1233 |
|
1234 def __configureExceptionsFilter(self): |
|
1235 """ |
|
1236 Private slot for displaying the exception filter dialog. |
|
1237 """ |
|
1238 dlg = ExceptionsFilterDialog(self.excList, ignore = False) |
|
1239 if dlg.exec_() == QDialog.Accepted: |
|
1240 self.excList = dlg.getExceptionsList()[:] # keep a copy |
|
1241 |
|
1242 def __configureIgnoredExceptions(self): |
|
1243 """ |
|
1244 Private slot for displaying the ignored exceptions dialog. |
|
1245 """ |
|
1246 dlg = ExceptionsFilterDialog(self.excIgnoreList, ignore = True) |
|
1247 if dlg.exec_() == QDialog.Accepted: |
|
1248 self.excIgnoreList = dlg.getExceptionsList()[:] # keep a copy |
|
1249 |
|
1250 def __toggleBreakpoint(self): |
|
1251 """ |
|
1252 Private slot to handle the 'Set/Reset breakpoint' action. |
|
1253 """ |
|
1254 self.viewmanager.activeWindow().menuToggleBreakpoint() |
|
1255 |
|
1256 def __editBreakpoint(self): |
|
1257 """ |
|
1258 Private slot to handle the 'Edit breakpoint' action. |
|
1259 """ |
|
1260 self.viewmanager.activeWindow().menuEditBreakpoint() |
|
1261 |
|
1262 def __nextBreakpoint(self): |
|
1263 """ |
|
1264 Private slot to handle the 'Next breakpoint' action. |
|
1265 """ |
|
1266 self.viewmanager.activeWindow().menuNextBreakpoint() |
|
1267 |
|
1268 def __previousBreakpoint(self): |
|
1269 """ |
|
1270 Private slot to handle the 'Previous breakpoint' action. |
|
1271 """ |
|
1272 self.viewmanager.activeWindow().menuPreviousBreakpoint() |
|
1273 |
|
1274 def __clearBreakpoints(self): |
|
1275 """ |
|
1276 Private slot to handle the 'Clear breakpoints' action. |
|
1277 """ |
|
1278 self.debugServer.getBreakPointModel().deleteAll() |
|
1279 |
|
1280 def __showDebugMenu(self): |
|
1281 """ |
|
1282 Private method to set up the debug menu. |
|
1283 """ |
|
1284 bpCount = self.debugServer.getBreakPointModel().rowCount() |
|
1285 self.menuBreakpointsAct.setEnabled(bpCount > 0) |
|
1286 |
|
1287 def __showBreakpointsMenu(self): |
|
1288 """ |
|
1289 Private method to handle the show breakpoints menu signal. |
|
1290 """ |
|
1291 self.breakpointsMenu.clear() |
|
1292 |
|
1293 model = self.debugServer.getBreakPointModel() |
|
1294 for row in range(model.rowCount()): |
|
1295 index = model.index(row, 0) |
|
1296 filename, line, cond = model.getBreakPointByIndex(index)[:3] |
|
1297 if not cond: |
|
1298 formattedCond = "" |
|
1299 else: |
|
1300 formattedCond = " : %s" % cond[:20] |
|
1301 bpSuffix = " : %d%s" % (line, formattedCond) |
|
1302 act = self.breakpointsMenu.addAction( |
|
1303 "%s%s" % ( |
|
1304 Utilities.compactPath( |
|
1305 filename, |
|
1306 self.ui.maxMenuFilePathLen - len(bpSuffix)), |
|
1307 bpSuffix)) |
|
1308 act.setData(QVariant([QVariant(filename), QVariant(line)])) |
|
1309 |
|
1310 def __breakpointSelected(self, act): |
|
1311 """ |
|
1312 Private method to handle the breakpoint selected signal. |
|
1313 |
|
1314 @param act reference to the action that triggered (QAction) |
|
1315 """ |
|
1316 try: |
|
1317 qvList = act.data().toPyObject() |
|
1318 filename = qvList[0] |
|
1319 line = qvList[1] |
|
1320 except AttributeError: |
|
1321 qvList = act.data().toList() |
|
1322 filename = qvList[0].toString() |
|
1323 line = qvList[1].toInt()[0] |
|
1324 self.viewmanager.openSourceFile(filename, line) |
|
1325 |
|
1326 def __compileChangedProjectFiles(self): |
|
1327 """ |
|
1328 Private method to signal compilation of changed forms and resources |
|
1329 is wanted. |
|
1330 """ |
|
1331 if Preferences.getProject("AutoCompileForms"): |
|
1332 self.emit(SIGNAL('compileForms')) |
|
1333 if Preferences.getProject("AutoCompileResources"): |
|
1334 self.emit(SIGNAL('compileResources')) |
|
1335 QApplication.processEvents() |
|
1336 |
|
1337 def __coverageScript(self): |
|
1338 """ |
|
1339 Private slot to handle the coverage of script action. |
|
1340 """ |
|
1341 self.__doCoverage(False) |
|
1342 |
|
1343 def __coverageProject(self): |
|
1344 """ |
|
1345 Private slot to handle the coverage of project action. |
|
1346 """ |
|
1347 self.__compileChangedProjectFiles() |
|
1348 self.__doCoverage(True) |
|
1349 |
|
1350 def __doCoverage(self, runProject): |
|
1351 """ |
|
1352 Private method to handle the coverage actions. |
|
1353 |
|
1354 @param runProject flag indicating coverage of the current project (True) |
|
1355 or script (false) |
|
1356 """ |
|
1357 self.__resetUI() |
|
1358 doNotStart = False |
|
1359 |
|
1360 # Get the command line arguments, the working directory and the |
|
1361 # exception reporting flag. |
|
1362 if runProject: |
|
1363 cap = self.trUtf8("Coverage of Project") |
|
1364 else: |
|
1365 cap = self.trUtf8("Coverage of Script") |
|
1366 dlg = StartDialog(cap, self.argvHistory, self.wdHistory, self.envHistory, |
|
1367 self.exceptions, self.ui, 2, autoClearShell = self.autoClearShell) |
|
1368 if dlg.exec_() == QDialog.Accepted: |
|
1369 argv, wd, env, exceptions, clearShell, clearHistories, console = dlg.getData() |
|
1370 eraseCoverage = dlg.getCoverageData() |
|
1371 |
|
1372 if runProject: |
|
1373 fn = self.project.getMainScript(1) |
|
1374 if fn is None: |
|
1375 QMessageBox.critical(self.ui, |
|
1376 self.trUtf8("Coverage of Project"), |
|
1377 self.trUtf8("There is no main script defined for the" |
|
1378 " current project. Aborting")) |
|
1379 return |
|
1380 |
|
1381 if Preferences.getDebugger("Autosave") and \ |
|
1382 not self.project.saveAllScripts(reportSyntaxErrors = True): |
|
1383 doNotStart = True |
|
1384 |
|
1385 # save the info for later use |
|
1386 self.project.setDbgInfo(argv, wd, env, exceptions, self.excList, |
|
1387 self.excIgnoreList, clearShell) |
|
1388 |
|
1389 self.lastStartAction = 6 |
|
1390 else: |
|
1391 editor = self.viewmanager.activeWindow() |
|
1392 if editor is None: |
|
1393 return |
|
1394 |
|
1395 if not self.viewmanager.checkDirty(editor, |
|
1396 Preferences.getDebugger("Autosave")) or \ |
|
1397 editor.getFileName() is None: |
|
1398 return |
|
1399 |
|
1400 fn = editor.getFileName() |
|
1401 self.lastStartAction = 5 |
|
1402 |
|
1403 # save the filename for use by the restart method |
|
1404 self.lastDebuggedFile = fn |
|
1405 self.restartAct.setEnabled(True) |
|
1406 |
|
1407 # This moves any previous occurrence of these arguments to the head |
|
1408 # of the list. |
|
1409 self.setArgvHistory(argv, clearHistories) |
|
1410 self.setWdHistory(wd, clearHistories) |
|
1411 self.setEnvHistory(env, clearHistories) |
|
1412 |
|
1413 # Save the exception flags |
|
1414 self.exceptions = exceptions |
|
1415 |
|
1416 # Save the erase coverage flag |
|
1417 self.eraseCoverage = eraseCoverage |
|
1418 |
|
1419 # Save the clear interpreter flag |
|
1420 self.autoClearShell = clearShell |
|
1421 |
|
1422 # Save the run in console flag |
|
1423 self.runInConsole = console |
|
1424 |
|
1425 # Hide all error highlights |
|
1426 self.viewmanager.unhighlight() |
|
1427 |
|
1428 if not doNotStart: |
|
1429 if runProject and self.project.getProjectType() == "E4Plugin": |
|
1430 argv.insert(0, "--plugin=%s " % fn) |
|
1431 fn = os.path.join(getConfig('ericDir'), "eric4.py") |
|
1432 |
|
1433 # Ask the client to open the new program. |
|
1434 self.debugServer.remoteCoverage(fn, argv, wd, env, |
|
1435 autoClearShell = self.autoClearShell, erase = eraseCoverage, |
|
1436 forProject = runProject, runInConsole = console) |
|
1437 |
|
1438 self.stopAct.setEnabled(True) |
|
1439 |
|
1440 def __profileScript(self): |
|
1441 """ |
|
1442 Private slot to handle the profile script action. |
|
1443 """ |
|
1444 self.__doProfile(False) |
|
1445 |
|
1446 def __profileProject(self): |
|
1447 """ |
|
1448 Private slot to handle the profile project action. |
|
1449 """ |
|
1450 self.__compileChangedProjectFiles() |
|
1451 self.__doProfile(True) |
|
1452 |
|
1453 def __doProfile(self, runProject): |
|
1454 """ |
|
1455 Private method to handle the profile actions. |
|
1456 |
|
1457 @param runProject flag indicating profiling of the current project (True) |
|
1458 or script (False) |
|
1459 """ |
|
1460 self.__resetUI() |
|
1461 doNotStart = False |
|
1462 |
|
1463 # Get the command line arguments, the working directory and the |
|
1464 # exception reporting flag. |
|
1465 if runProject: |
|
1466 cap = self.trUtf8("Profile of Project") |
|
1467 else: |
|
1468 cap = self.trUtf8("Profile of Script") |
|
1469 dlg = StartDialog(cap, self.argvHistory, self.wdHistory, self.envHistory, |
|
1470 self.exceptions, self.ui, 3, |
|
1471 autoClearShell = self.autoClearShell) |
|
1472 if dlg.exec_() == QDialog.Accepted: |
|
1473 argv, wd, env, exceptions, clearShell, clearHistories, console = dlg.getData() |
|
1474 eraseTimings = dlg.getProfilingData() |
|
1475 |
|
1476 if runProject: |
|
1477 fn = self.project.getMainScript(1) |
|
1478 if fn is None: |
|
1479 QMessageBox.critical(self.ui, |
|
1480 self.trUtf8("Profile of Project"), |
|
1481 self.trUtf8("There is no main script defined for the" |
|
1482 " current project. Aborting")) |
|
1483 return |
|
1484 |
|
1485 if Preferences.getDebugger("Autosave") and \ |
|
1486 not self.project.saveAllScripts(reportSyntaxErrors = True): |
|
1487 doNotStart = True |
|
1488 |
|
1489 # save the info for later use |
|
1490 self.project.setDbgInfo(argv, wd, env, exceptions, self.excList, |
|
1491 self.excIgnoreList, clearShell) |
|
1492 |
|
1493 self.lastStartAction = 8 |
|
1494 else: |
|
1495 editor = self.viewmanager.activeWindow() |
|
1496 if editor is None: |
|
1497 return |
|
1498 |
|
1499 if not self.viewmanager.checkDirty(editor, |
|
1500 Preferences.getDebugger("Autosave")) or \ |
|
1501 editor.getFileName() is None: |
|
1502 return |
|
1503 |
|
1504 fn = editor.getFileName() |
|
1505 self.lastStartAction = 7 |
|
1506 |
|
1507 # save the filename for use by the restart method |
|
1508 self.lastDebuggedFile = fn |
|
1509 self.restartAct.setEnabled(True) |
|
1510 |
|
1511 # This moves any previous occurrence of these arguments to the head |
|
1512 # of the list. |
|
1513 self.setArgvHistory(argv, clearHistories) |
|
1514 self.setWdHistory(wd, clearHistories) |
|
1515 self.setEnvHistory(env, clearHistories) |
|
1516 |
|
1517 # Save the exception flags |
|
1518 self.exceptions = exceptions |
|
1519 |
|
1520 # Save the erase timing flag |
|
1521 self.eraseTimings = eraseTimings |
|
1522 |
|
1523 # Save the clear interpreter flag |
|
1524 self.autoClearShell = clearShell |
|
1525 |
|
1526 # Save the run in console flag |
|
1527 self.runInConsole = console |
|
1528 |
|
1529 # Hide all error highlights |
|
1530 self.viewmanager.unhighlight() |
|
1531 |
|
1532 if not doNotStart: |
|
1533 if runProject and self.project.getProjectType() == "E4Plugin": |
|
1534 argv.insert(0, "--plugin=%s " % fn) |
|
1535 fn = os.path.join(getConfig('ericDir'), "eric4.py") |
|
1536 |
|
1537 # Ask the client to open the new program. |
|
1538 self.debugServer.remoteProfile(fn, argv, wd, env, |
|
1539 autoClearShell = self.autoClearShell, erase = eraseTimings, |
|
1540 forProject = runProject, runInConsole = console) |
|
1541 |
|
1542 self.stopAct.setEnabled(True) |
|
1543 |
|
1544 def __runScript(self): |
|
1545 """ |
|
1546 Private slot to handle the run script action. |
|
1547 """ |
|
1548 self.__doRun(False) |
|
1549 |
|
1550 def __runProject(self): |
|
1551 """ |
|
1552 Private slot to handle the run project action. |
|
1553 """ |
|
1554 self.__compileChangedProjectFiles() |
|
1555 self.__doRun(True) |
|
1556 |
|
1557 def __doRun(self, runProject): |
|
1558 """ |
|
1559 Private method to handle the run actions. |
|
1560 |
|
1561 @param runProject flag indicating running the current project (True) |
|
1562 or script (False) |
|
1563 """ |
|
1564 self.__resetUI() |
|
1565 doNotStart = False |
|
1566 |
|
1567 # Get the command line arguments, the working directory and the |
|
1568 # exception reporting flag. |
|
1569 if runProject: |
|
1570 cap = self.trUtf8("Run Project") |
|
1571 else: |
|
1572 cap = self.trUtf8("Run Script") |
|
1573 dlg = StartDialog(cap, self.argvHistory, self.wdHistory, self.envHistory, |
|
1574 self.exceptions, self.ui, 1, |
|
1575 autoClearShell = self.autoClearShell) |
|
1576 if dlg.exec_() == QDialog.Accepted: |
|
1577 argv, wd, env, exceptions, clearShell, clearHistories, console = dlg.getData() |
|
1578 |
|
1579 if runProject: |
|
1580 fn = self.project.getMainScript(1) |
|
1581 if fn is None: |
|
1582 QMessageBox.critical(self.ui, |
|
1583 self.trUtf8("Run Project"), |
|
1584 self.trUtf8("There is no main script defined for the" |
|
1585 " current project. Aborting")) |
|
1586 return |
|
1587 |
|
1588 if Preferences.getDebugger("Autosave") and \ |
|
1589 not self.project.saveAllScripts(reportSyntaxErrors = True): |
|
1590 doNotStart = True |
|
1591 |
|
1592 # save the info for later use |
|
1593 self.project.setDbgInfo(argv, wd, env, exceptions, self.excList, |
|
1594 self.excIgnoreList, clearShell) |
|
1595 |
|
1596 self.lastStartAction = 4 |
|
1597 else: |
|
1598 editor = self.viewmanager.activeWindow() |
|
1599 if editor is None: |
|
1600 return |
|
1601 |
|
1602 if not self.viewmanager.checkDirty(editor, |
|
1603 Preferences.getDebugger("Autosave")) or \ |
|
1604 editor.getFileName() is None: |
|
1605 return |
|
1606 |
|
1607 fn = editor.getFileName() |
|
1608 self.lastStartAction = 3 |
|
1609 |
|
1610 # save the filename for use by the restart method |
|
1611 self.lastDebuggedFile = fn |
|
1612 self.restartAct.setEnabled(True) |
|
1613 |
|
1614 # This moves any previous occurrence of these arguments to the head |
|
1615 # of the list. |
|
1616 self.setArgvHistory(argv, clearHistories) |
|
1617 self.setWdHistory(wd, clearHistories) |
|
1618 self.setEnvHistory(env, clearHistories) |
|
1619 |
|
1620 # Save the exception flags |
|
1621 self.exceptions = exceptions |
|
1622 |
|
1623 # Save the clear interpreter flag |
|
1624 self.autoClearShell = clearShell |
|
1625 |
|
1626 # Save the run in console flag |
|
1627 self.runInConsole = console |
|
1628 |
|
1629 # Hide all error highlights |
|
1630 self.viewmanager.unhighlight() |
|
1631 |
|
1632 if not doNotStart: |
|
1633 if runProject and self.project.getProjectType() == "E4Plugin": |
|
1634 argv.insert(0, "--plugin=%s " % fn) |
|
1635 fn = os.path.join(getConfig('ericDir'), "eric4.py") |
|
1636 |
|
1637 # Ask the client to open the new program. |
|
1638 self.debugServer.remoteRun(fn, argv, wd, env, |
|
1639 autoClearShell = self.autoClearShell, forProject = runProject, |
|
1640 runInConsole = console) |
|
1641 |
|
1642 self.stopAct.setEnabled(True) |
|
1643 |
|
1644 def __debugScript(self): |
|
1645 """ |
|
1646 Private slot to handle the debug script action. |
|
1647 """ |
|
1648 self.__doDebug(False) |
|
1649 |
|
1650 def __debugProject(self): |
|
1651 """ |
|
1652 Private slot to handle the debug project action. |
|
1653 """ |
|
1654 self.__compileChangedProjectFiles() |
|
1655 self.__doDebug(True) |
|
1656 |
|
1657 def __doDebug(self, debugProject): |
|
1658 """ |
|
1659 Private method to handle the debug actions. |
|
1660 |
|
1661 @param debugProject flag indicating debugging the current project (True) |
|
1662 or script (False) |
|
1663 """ |
|
1664 self.__resetUI() |
|
1665 doNotStart = False |
|
1666 |
|
1667 # Get the command line arguments, the working directory and the |
|
1668 # exception reporting flag. |
|
1669 if debugProject: |
|
1670 cap = self.trUtf8("Debug Project") |
|
1671 else: |
|
1672 cap = self.trUtf8("Debug Script") |
|
1673 dlg = StartDialog(cap, self.argvHistory, self.wdHistory, self.envHistory, |
|
1674 self.exceptions, self.ui, 0, tracePython = self.tracePython, |
|
1675 autoClearShell = self.autoClearShell, autoContinue = self.autoContinue, |
|
1676 autoFork = self.forkAutomatically, forkChild = self.forkIntoChild) |
|
1677 if dlg.exec_() == QDialog.Accepted: |
|
1678 argv, wd, env, exceptions, clearShell, clearHistories, console = dlg.getData() |
|
1679 tracePython, autoContinue, forkAutomatically, forkIntoChild = \ |
|
1680 dlg.getDebugData() |
|
1681 |
|
1682 if debugProject: |
|
1683 fn = self.project.getMainScript(True) |
|
1684 if fn is None: |
|
1685 QMessageBox.critical(self.ui, |
|
1686 self.trUtf8("Debug Project"), |
|
1687 self.trUtf8("There is no main script defined for the" |
|
1688 " current project. No debugging possible.")) |
|
1689 return |
|
1690 |
|
1691 if Preferences.getDebugger("Autosave") and \ |
|
1692 not self.project.saveAllScripts(reportSyntaxErrors = True): |
|
1693 doNotStart = True |
|
1694 |
|
1695 # save the info for later use |
|
1696 self.project.setDbgInfo(argv, wd, env, exceptions, self.excList, |
|
1697 self.excIgnoreList, clearShell, tracePython = tracePython, |
|
1698 autoContinue = self.autoContinue) |
|
1699 |
|
1700 self.lastStartAction = 2 |
|
1701 else: |
|
1702 editor = self.viewmanager.activeWindow() |
|
1703 if editor is None: |
|
1704 return |
|
1705 |
|
1706 if not self.viewmanager.checkDirty(editor, |
|
1707 Preferences.getDebugger("Autosave")) or \ |
|
1708 editor.getFileName() is None: |
|
1709 return |
|
1710 |
|
1711 fn = editor.getFileName() |
|
1712 self.lastStartAction = 1 |
|
1713 |
|
1714 # save the filename for use by the restart method |
|
1715 self.lastDebuggedFile = fn |
|
1716 self.restartAct.setEnabled(True) |
|
1717 |
|
1718 # This moves any previous occurrence of these arguments to the head |
|
1719 # of the list. |
|
1720 self.setArgvHistory(argv, clearHistories) |
|
1721 self.setWdHistory(wd, clearHistories) |
|
1722 self.setEnvHistory(env, clearHistories) |
|
1723 |
|
1724 # Save the exception flags |
|
1725 self.exceptions = exceptions |
|
1726 |
|
1727 # Save the tracePython flag |
|
1728 self.tracePython = tracePython |
|
1729 |
|
1730 # Save the clear interpreter flag |
|
1731 self.autoClearShell = clearShell |
|
1732 |
|
1733 # Save the run in console flag |
|
1734 self.runInConsole = console |
|
1735 |
|
1736 # Save the auto continue flag |
|
1737 self.autoContinue = autoContinue |
|
1738 |
|
1739 # Save the forking flags |
|
1740 self.forkAutomatically = forkAutomatically |
|
1741 self.forkIntoChild = forkIntoChild |
|
1742 |
|
1743 # Hide all error highlights |
|
1744 self.viewmanager.unhighlight() |
|
1745 |
|
1746 if not doNotStart: |
|
1747 if debugProject and self.project.getProjectType() == "E4Plugin": |
|
1748 argv.insert(0, "--plugin=%s " % fn) |
|
1749 fn = os.path.join(getConfig('ericDir'), "eric4.py") |
|
1750 tracePython = True # override flag because it must be true |
|
1751 |
|
1752 # Ask the client to open the new program. |
|
1753 self.debugServer.remoteLoad(fn, argv, wd, env, |
|
1754 autoClearShell = self.autoClearShell, tracePython = tracePython, |
|
1755 autoContinue = autoContinue, forProject = debugProject, |
|
1756 runInConsole = console, autoFork = forkAutomatically, |
|
1757 forkChild = forkIntoChild) |
|
1758 |
|
1759 # Signal that we have started a debugging session |
|
1760 self.emit(SIGNAL('debuggingStarted'), fn) |
|
1761 |
|
1762 self.stopAct.setEnabled(True) |
|
1763 |
|
1764 def __doRestart(self): |
|
1765 """ |
|
1766 Private slot to handle the restart action to restart the last debugged file. |
|
1767 """ |
|
1768 self.__resetUI() |
|
1769 doNotStart = False |
|
1770 |
|
1771 # first save any changes |
|
1772 if self.lastStartAction in [1, 3, 5, 7, 9]: |
|
1773 editor = self.viewmanager.getOpenEditor(self.lastDebuggedFile) |
|
1774 if editor and \ |
|
1775 not self.viewmanager.checkDirty(editor, |
|
1776 Preferences.getDebugger("Autosave")): |
|
1777 return |
|
1778 forProject = False |
|
1779 elif self.lastStartAction in [2, 4, 6, 8, 10]: |
|
1780 if Preferences.getDebugger("Autosave") and \ |
|
1781 not self.project.saveAllScripts(reportSyntaxErrors = True): |
|
1782 doNotStart = True |
|
1783 self.__compileChangedProjectFiles() |
|
1784 forProject = True |
|
1785 else: |
|
1786 return # should not happen |
|
1787 |
|
1788 # get the saved stuff |
|
1789 wd = self.wdHistory[0] |
|
1790 argv = self.argvHistory[0] |
|
1791 fn = self.lastDebuggedFile |
|
1792 env = self.envHistory[0] |
|
1793 |
|
1794 # Hide all error highlights |
|
1795 self.viewmanager.unhighlight() |
|
1796 |
|
1797 if not doNotStart: |
|
1798 if forProject and self.project.getProjectType() == "E4Plugin": |
|
1799 argv.insert(0, "--plugin=%s " % fn) |
|
1800 fn = os.path.join(getConfig('ericDir'), "eric4.py") |
|
1801 |
|
1802 if self.lastStartAction in [1, 2]: |
|
1803 # Ask the client to debug the new program. |
|
1804 self.debugServer.remoteLoad(fn, argv, wd, env, |
|
1805 autoClearShell = self.autoClearShell, tracePython = self.tracePython, |
|
1806 autoContinue = self.autoContinue, forProject = forProject, |
|
1807 runInConsole = self.runInConsole) |
|
1808 |
|
1809 # Signal that we have started a debugging session |
|
1810 self.emit(SIGNAL('debuggingStarted'), fn) |
|
1811 elif self.lastStartAction in [3, 4]: |
|
1812 # Ask the client to run the new program. |
|
1813 self.debugServer.remoteRun(fn, argv, wd, env, |
|
1814 autoClearShell = self.autoClearShell, forProject = forProject, |
|
1815 runInConsole = self.runInConsole) |
|
1816 elif self.lastStartAction in [5, 6]: |
|
1817 # Ask the client to coverage run the new program. |
|
1818 self.debugServer.remoteCoverage(fn, argv, wd, env, |
|
1819 autoClearShell = self.autoClearShell, erase = self.eraseCoverage, |
|
1820 forProject = forProject, runInConsole = self.runInConsole) |
|
1821 elif self.lastStartAction in [7, 8]: |
|
1822 # Ask the client to profile run the new program. |
|
1823 self.debugServer.remoteProfile(fn, argv, wd, env, |
|
1824 autoClearShell = self.autoClearShell, erase = self.eraseTimings, |
|
1825 forProject = forProject, runInConsole = self.runInConsole) |
|
1826 |
|
1827 self.stopAct.setEnabled(True) |
|
1828 |
|
1829 def __stopScript(self): |
|
1830 """ |
|
1831 Private slot to stop the running script. |
|
1832 """ |
|
1833 self.debugServer.startClient(False) |
|
1834 |
|
1835 def __passiveDebugStarted(self, fn, exc): |
|
1836 """ |
|
1837 Private slot to handle a passive debug session start. |
|
1838 |
|
1839 @param fn filename of the debugged script |
|
1840 @param exc flag to enable exception reporting of the IDE (boolean) |
|
1841 """ |
|
1842 # Hide all error highlights |
|
1843 self.viewmanager.unhighlight() |
|
1844 |
|
1845 # Set filename of script being debugged |
|
1846 self.ui.currentProg = fn |
|
1847 |
|
1848 # Set exception reporting |
|
1849 self.setExceptionReporting(exc) |
|
1850 |
|
1851 # Signal that we have started a debugging session |
|
1852 self.emit(SIGNAL('debuggingStarted'), fn) |
|
1853 |
|
1854 def __continue(self): |
|
1855 """ |
|
1856 Private method to handle the Continue action. |
|
1857 """ |
|
1858 self.lastAction = 0 |
|
1859 self.__enterRemote() |
|
1860 self.debugServer.remoteContinue() |
|
1861 |
|
1862 def __specialContinue(self): |
|
1863 """ |
|
1864 Private method to handle the Special Continue action. |
|
1865 """ |
|
1866 self.lastAction = 2 |
|
1867 self.__enterRemote() |
|
1868 self.debugServer.remoteContinue(1) |
|
1869 |
|
1870 def __step(self): |
|
1871 """ |
|
1872 Private method to handle the Step action. |
|
1873 """ |
|
1874 self.lastAction = 1 |
|
1875 self.__enterRemote() |
|
1876 self.debugServer.remoteStep() |
|
1877 |
|
1878 def __stepOver(self): |
|
1879 """ |
|
1880 Private method to handle the Step Over action. |
|
1881 """ |
|
1882 self.lastAction = 2 |
|
1883 self.__enterRemote() |
|
1884 self.debugServer.remoteStepOver() |
|
1885 |
|
1886 def __stepOut(self): |
|
1887 """ |
|
1888 Private method to handle the Step Out action. |
|
1889 """ |
|
1890 self.lastAction = 3 |
|
1891 self.__enterRemote() |
|
1892 self.debugServer.remoteStepOut() |
|
1893 |
|
1894 def __stepQuit(self): |
|
1895 """ |
|
1896 Private method to handle the Step Quit action. |
|
1897 """ |
|
1898 self.lastAction = 4 |
|
1899 self.__enterRemote() |
|
1900 self.debugServer.remoteStepQuit() |
|
1901 self.__resetUI() |
|
1902 |
|
1903 def __runToCursor(self): |
|
1904 """ |
|
1905 Private method to handle the Run to Cursor action. |
|
1906 """ |
|
1907 self.lastAction = 0 |
|
1908 aw = self.viewmanager.activeWindow() |
|
1909 line = aw.getCursorPosition()[0] + 1 |
|
1910 self.__enterRemote() |
|
1911 self.debugServer.remoteBreakpoint(aw.getFileName(), |
|
1912 line, 1, None, 1) |
|
1913 self.debugServer.remoteContinue() |
|
1914 |
|
1915 def __eval(self): |
|
1916 """ |
|
1917 Private method to handle the Eval action. |
|
1918 """ |
|
1919 # Get the command line arguments. |
|
1920 if len(self.evalHistory) > 0: |
|
1921 curr = 0 |
|
1922 else: |
|
1923 curr = -1 |
|
1924 |
|
1925 arg, ok = QInputDialog.getItem(\ |
|
1926 self.ui, |
|
1927 self.trUtf8("Evaluate"), |
|
1928 self.trUtf8("Enter the statement to evaluate"), |
|
1929 self.evalHistory, |
|
1930 curr, True) |
|
1931 |
|
1932 if ok: |
|
1933 if arg.isNull(): |
|
1934 return |
|
1935 |
|
1936 # This moves any previous occurrence of this expression to the head |
|
1937 # of the list. |
|
1938 if arg in self.evalHistory: |
|
1939 self.evalHistory.remove(arg) |
|
1940 self.evalHistory.insert(0, arg) |
|
1941 |
|
1942 self.debugServer.remoteEval(arg) |
|
1943 |
|
1944 def __exec(self): |
|
1945 """ |
|
1946 Private method to handle the Exec action. |
|
1947 """ |
|
1948 # Get the command line arguments. |
|
1949 if len(self.execHistory) > 0: |
|
1950 curr = 0 |
|
1951 else: |
|
1952 curr = -1 |
|
1953 |
|
1954 stmt, ok = QInputDialog.getItem(\ |
|
1955 self.ui, |
|
1956 self.trUtf8("Execute"), |
|
1957 self.trUtf8("Enter the statement to execute"), |
|
1958 self.execHistory, |
|
1959 curr, True) |
|
1960 |
|
1961 if ok: |
|
1962 if stmt.isNull(): |
|
1963 return |
|
1964 |
|
1965 # This moves any previous occurrence of this statement to the head |
|
1966 # of the list. |
|
1967 if stmt in self.execHistory: |
|
1968 self.execHistory.remove(stmt) |
|
1969 self.execHistory.insert(0, stmt) |
|
1970 |
|
1971 self.debugServer.remoteExec(stmt) |
|
1972 |
|
1973 def __enterRemote(self): |
|
1974 """ |
|
1975 Private method to update the user interface. |
|
1976 |
|
1977 This method is called just prior to executing some of |
|
1978 the program being debugged. |
|
1979 """ |
|
1980 # Disable further debug commands from the user. |
|
1981 self.debugActGrp.setEnabled(False) |
|
1982 self.debugActGrp2.setEnabled(False) |
|
1983 |
|
1984 self.viewmanager.unhighlight(True) |
|
1985 |
|
1986 def getActions(self): |
|
1987 """ |
|
1988 Public method to get a list of all actions. |
|
1989 |
|
1990 @return list of all actions (list of E4Action) |
|
1991 """ |
|
1992 return self.actions[:] |