eric6/Debugger/DebugUI.py

changeset 7251
bc5b1b00560a
parent 7229
53054eb5b15a
child 7360
9190402e4505
equal deleted inserted replaced
7250:d8bdc55aee1a 7251:bc5b1b00560a
14 from PyQt5.QtGui import QKeySequence 14 from PyQt5.QtGui import QKeySequence
15 from PyQt5.QtWidgets import QMenu, QToolBar, QApplication, QDialog 15 from PyQt5.QtWidgets import QMenu, QToolBar, QApplication, QDialog
16 16
17 from UI.Info import Program 17 from UI.Info import Program
18 18
19 from .DebugClientCapabilities import HasDebugger, HasInterpreter, \ 19 from .DebugClientCapabilities import (
20 HasProfiler, HasCoverage 20 HasDebugger, HasInterpreter, HasProfiler, HasCoverage
21 )
21 import Preferences 22 import Preferences
22 import Utilities 23 import Utilities
23 import UI.PixmapCache 24 import UI.PixmapCache
24 import UI.Config 25 import UI.Config
25 26
113 self.lastAction = -1 114 self.lastAction = -1
114 self.debugActions = [ 115 self.debugActions = [
115 self.__continue, self.__step, self.__stepOver, self.__stepOut, 116 self.__continue, self.__step, self.__stepOver, self.__stepOut,
116 self.__stepQuit, self.__runToCursor, self.__moveInstructionPointer 117 self.__stepQuit, self.__runToCursor, self.__moveInstructionPointer
117 ] 118 ]
118 self.localsVarFilter, self.globalsVarFilter = \ 119 self.localsVarFilter, self.globalsVarFilter = (
119 Preferences.getVarFilters() 120 Preferences.getVarFilters())
120 self.debugViewer.setVariablesFilter( 121 self.debugViewer.setVariablesFilter(
121 self.globalsVarFilter, self.localsVarFilter) 122 self.globalsVarFilter, self.localsVarFilter)
122 123
123 # Connect the signals emitted by the debug-server 124 # Connect the signals emitted by the debug-server
124 debugServer.clientGone.connect(self.__clientGone) 125 debugServer.clientGone.connect(self.__clientGone)
982 983
983 self.debugProjectAct.setEnabled(self.projectOpen) 984 self.debugProjectAct.setEnabled(self.projectOpen)
984 self.runProjectAct.setEnabled(self.projectOpen) 985 self.runProjectAct.setEnabled(self.projectOpen)
985 self.profileProjectAct.setEnabled(self.projectOpen) 986 self.profileProjectAct.setEnabled(self.projectOpen)
986 self.coverageProjectAct.setEnabled(self.projectOpen) 987 self.coverageProjectAct.setEnabled(self.projectOpen)
987 if self.lastDebuggedFile is not None and \ 988 if (
988 (self.editorOpen or self.projectOpen): 989 self.lastDebuggedFile is not None and
990 (self.editorOpen or self.projectOpen)
991 ):
989 self.restartAct.setEnabled(True) 992 self.restartAct.setEnabled(True)
990 else: 993 else:
991 self.restartAct.setEnabled(False) 994 self.restartAct.setEnabled(False)
992 self.stopAct.setEnabled(False) 995 self.stopAct.setEnabled(False)
993 self.resetUI.emit() 996 self.resetUI.emit()
1025 self.viewmanager.exit() 1028 self.viewmanager.exit()
1026 1029
1027 self.__resetUI() 1030 self.__resetUI()
1028 1031
1029 if not quiet: 1032 if not quiet:
1030 if not Preferences.getDebugger("SuppressClientExit") or \ 1033 if (
1031 status != 0: 1034 not Preferences.getDebugger("SuppressClientExit") or
1035 status != 0
1036 ):
1032 if message: 1037 if message:
1033 info = self.tr("<p>Message: {0}</p>").format( 1038 info = self.tr("<p>Message: {0}</p>").format(
1034 Utilities.html_uencode(message)) 1039 Utilities.html_uencode(message))
1035 else: 1040 else:
1036 info = "" 1041 info = ""
1135 self.ui, Program, 1140 self.ui, Program,
1136 self.tr('An unhandled exception occured.' 1141 self.tr('An unhandled exception occured.'
1137 ' See the shell window for details.')) 1142 ' See the shell window for details.'))
1138 return 1143 return
1139 1144
1140 if (self.exceptions and 1145 if (
1141 exceptionType not in self.excIgnoreList and 1146 (self.exceptions and
1142 (not len(self.excList) or 1147 exceptionType not in self.excIgnoreList and
1143 (len(self.excList) and exceptionType in self.excList)))\ 1148 (not len(self.excList) or
1144 or exceptionType.startswith('unhandled'): 1149 (len(self.excList) and exceptionType in self.excList)
1150 )
1151 ) or exceptionType.startswith('unhandled')
1152 ):
1145 res = None 1153 res = None
1146 if stackTrace: 1154 if stackTrace:
1147 try: 1155 try:
1148 file, line = stackTrace[0][:2] 1156 file, line = stackTrace[0][:2]
1149 source, encoding = Utilities.readEncodedFile(file) 1157 source, encoding = Utilities.readEncodedFile(file)
1388 if dlg.exec_() == QDialog.Accepted: 1396 if dlg.exec_() == QDialog.Accepted:
1389 cond, temp, enabled, count, special = dlg.getData() 1397 cond, temp, enabled, count, special = dlg.getData()
1390 1398
1391 # check for duplicates 1399 # check for duplicates
1392 idx = self.__model.getWatchPointIndex(cond, special) 1400 idx = self.__model.getWatchPointIndex(cond, special)
1393 duplicate = idx.isValid() and \ 1401 duplicate = (idx.isValid() and
1394 idx.internalPointer() != index.internalPointer() 1402 idx.internalPointer() != index.internalPointer())
1395 if duplicate: 1403 if duplicate:
1396 if not special: 1404 if not special:
1397 msg = self.tr("""<p>A watch expression '<b>{0}</b>'""" 1405 msg = self.tr(
1398 """ already exists.</p>""")\ 1406 """<p>A watch expression '<b>{0}</b>'"""
1399 .format(Utilities.html_encode(cond)) 1407 """ already exists.</p>"""
1408 ).format(Utilities.html_encode(cond))
1400 else: 1409 else:
1401 msg = self.tr( 1410 msg = self.tr(
1402 """<p>A watch expression '<b>{0}</b>'""" 1411 """<p>A watch expression '<b>{0}</b>'"""
1403 """ for the variable <b>{1}</b> already""" 1412 """ for the variable <b>{1}</b> already"""
1404 """ exists.</p>""")\ 1413 """ exists.</p>"""
1405 .format(special, 1414 ).format(special, Utilities.html_encode(cond))
1406 Utilities.html_encode(cond))
1407 E5MessageBox.warning( 1415 E5MessageBox.warning(
1408 self.ui, 1416 self.ui,
1409 self.tr("Watch expression already exists"), 1417 self.tr("Watch expression already exists"),
1410 msg) 1418 msg)
1411 model.deleteWatchPointByIndex(index) 1419 model.deleteWatchPointByIndex(index)
1576 self.tr( 1584 self.tr(
1577 "There is no main script defined for the" 1585 "There is no main script defined for the"
1578 " current project. Aborting")) 1586 " current project. Aborting"))
1579 return 1587 return
1580 1588
1581 if Preferences.getDebugger("Autosave") and \ 1589 if (
1582 not self.project.saveAllScripts(reportSyntaxErrors=True): 1590 Preferences.getDebugger("Autosave") and
1591 not self.project.saveAllScripts(reportSyntaxErrors=True)
1592 ):
1583 doNotStart = True 1593 doNotStart = True
1584 1594
1585 # save the info for later use 1595 # save the info for later use
1586 self.project.setDbgInfo( 1596 self.project.setDbgInfo(
1587 lastUsedVenvName, argv, wd, env, exceptions, self.excList, 1597 lastUsedVenvName, argv, wd, env, exceptions, self.excList,
1592 else: 1602 else:
1593 editor = self.viewmanager.activeWindow() 1603 editor = self.viewmanager.activeWindow()
1594 if editor is None: 1604 if editor is None:
1595 return 1605 return
1596 1606
1597 if not self.viewmanager.checkDirty( 1607 if (
1598 editor, 1608 not self.viewmanager.checkDirty(
1599 Preferences.getDebugger("Autosave")) or \ 1609 editor, Preferences.getDebugger("Autosave")) or
1600 editor.getFileName() is None: 1610 editor.getFileName() is None
1611 ):
1601 return 1612 return
1602 1613
1603 fn = editor.getFileName() 1614 fn = editor.getFileName()
1604 self.lastStartAction = 5 1615 self.lastStartAction = 5
1605 self.clientType = editor.determineFileType() 1616 self.clientType = editor.determineFileType()
1708 self.tr( 1719 self.tr(
1709 "There is no main script defined for the" 1720 "There is no main script defined for the"
1710 " current project. Aborting")) 1721 " current project. Aborting"))
1711 return 1722 return
1712 1723
1713 if Preferences.getDebugger("Autosave") and \ 1724 if (
1714 not self.project.saveAllScripts(reportSyntaxErrors=True): 1725 Preferences.getDebugger("Autosave") and
1726 not self.project.saveAllScripts(reportSyntaxErrors=True)
1727 ):
1715 doNotStart = True 1728 doNotStart = True
1716 1729
1717 # save the info for later use 1730 # save the info for later use
1718 self.project.setDbgInfo( 1731 self.project.setDbgInfo(
1719 lastUsedVenvName, argv, wd, env, exceptions, self.excList, 1732 lastUsedVenvName, argv, wd, env, exceptions, self.excList,
1724 else: 1737 else:
1725 editor = self.viewmanager.activeWindow() 1738 editor = self.viewmanager.activeWindow()
1726 if editor is None: 1739 if editor is None:
1727 return 1740 return
1728 1741
1729 if not self.viewmanager.checkDirty( 1742 if (
1730 editor, 1743 not self.viewmanager.checkDirty(
1731 Preferences.getDebugger("Autosave")) or \ 1744 editor, Preferences.getDebugger("Autosave")) or
1732 editor.getFileName() is None: 1745 editor.getFileName() is None
1746 ):
1733 return 1747 return
1734 1748
1735 fn = editor.getFileName() 1749 fn = editor.getFileName()
1736 self.lastStartAction = 7 1750 self.lastStartAction = 7
1737 self.clientType = editor.determineFileType() 1751 self.clientType = editor.determineFileType()
1842 self.tr( 1856 self.tr(
1843 "There is no main script defined for the" 1857 "There is no main script defined for the"
1844 " current project. Aborting")) 1858 " current project. Aborting"))
1845 return 1859 return
1846 1860
1847 if Preferences.getDebugger("Autosave") and \ 1861 if (
1848 not self.project.saveAllScripts(reportSyntaxErrors=True): 1862 Preferences.getDebugger("Autosave") and
1863 not self.project.saveAllScripts(reportSyntaxErrors=True)
1864 ):
1849 doNotStart = True 1865 doNotStart = True
1850 1866
1851 # save the info for later use 1867 # save the info for later use
1852 self.project.setDbgInfo( 1868 self.project.setDbgInfo(
1853 lastUsedVenvName, argv, wd, env, exceptions, self.excList, 1869 lastUsedVenvName, argv, wd, env, exceptions, self.excList,
1858 else: 1874 else:
1859 editor = self.viewmanager.activeWindow() 1875 editor = self.viewmanager.activeWindow()
1860 if editor is None: 1876 if editor is None:
1861 return 1877 return
1862 1878
1863 if not self.viewmanager.checkDirty( 1879 if (
1880 not self.viewmanager.checkDirty(
1864 editor, 1881 editor,
1865 Preferences.getDebugger("Autosave")) or \ 1882 Preferences.getDebugger("Autosave")) or
1866 editor.getFileName() is None: 1883 editor.getFileName() is None
1884 ):
1867 return 1885 return
1868 1886
1869 fn = editor.getFileName() 1887 fn = editor.getFileName()
1870 self.lastStartAction = 3 1888 self.lastStartAction = 3
1871 self.clientType = editor.determineFileType() 1889 self.clientType = editor.determineFileType()
1964 autoContinue=self.autoContinue, autoFork=self.forkAutomatically, 1982 autoContinue=self.autoContinue, autoFork=self.forkAutomatically,
1965 forkChild=self.forkIntoChild) 1983 forkChild=self.forkIntoChild)
1966 if dlg.exec_() == QDialog.Accepted: 1984 if dlg.exec_() == QDialog.Accepted:
1967 (lastUsedVenvName, argv, wd, env, exceptions, clearShell, 1985 (lastUsedVenvName, argv, wd, env, exceptions, clearShell,
1968 console) = dlg.getData() 1986 console) = dlg.getData()
1969 tracePython, autoContinue, forkAutomatically, forkIntoChild = \ 1987 tracePython, autoContinue, forkAutomatically, forkIntoChild = (
1970 dlg.getDebugData() 1988 dlg.getDebugData())
1971 1989
1972 if debugProject: 1990 if debugProject:
1973 fn = self.project.getMainScript(True) 1991 fn = self.project.getMainScript(True)
1974 if fn is None: 1992 if fn is None:
1975 E5MessageBox.critical( 1993 E5MessageBox.critical(
1978 self.tr( 1996 self.tr(
1979 "There is no main script defined for the" 1997 "There is no main script defined for the"
1980 " current project. No debugging possible.")) 1998 " current project. No debugging possible."))
1981 return 1999 return
1982 2000
1983 if Preferences.getDebugger("Autosave") and \ 2001 if (
1984 not self.project.saveAllScripts(reportSyntaxErrors=True): 2002 Preferences.getDebugger("Autosave") and
2003 not self.project.saveAllScripts(reportSyntaxErrors=True)
2004 ):
1985 doNotStart = True 2005 doNotStart = True
1986 2006
1987 # save the info for later use 2007 # save the info for later use
1988 self.project.setDbgInfo( 2008 self.project.setDbgInfo(
1989 lastUsedVenvName, argv, wd, env, exceptions, self.excList, 2009 lastUsedVenvName, argv, wd, env, exceptions, self.excList,
1995 else: 2015 else:
1996 editor = self.viewmanager.activeWindow() 2016 editor = self.viewmanager.activeWindow()
1997 if editor is None: 2017 if editor is None:
1998 return 2018 return
1999 2019
2000 if not self.viewmanager.checkDirty( 2020 if (
2001 editor, 2021 not self.viewmanager.checkDirty(
2002 Preferences.getDebugger("Autosave")) or \ 2022 editor, Preferences.getDebugger("Autosave")) or
2003 editor.getFileName() is None: 2023 editor.getFileName() is None
2024 ):
2004 return 2025 return
2005 2026
2006 fn = editor.getFileName() 2027 fn = editor.getFileName()
2007 self.lastStartAction = 1 2028 self.lastStartAction = 1
2008 self.clientType = editor.determineFileType() 2029 self.clientType = editor.determineFileType()
2064 autoContinue=autoContinue, forProject=debugProject, 2085 autoContinue=autoContinue, forProject=debugProject,
2065 runInConsole=console, autoFork=forkAutomatically, 2086 runInConsole=console, autoFork=forkAutomatically,
2066 forkChild=forkIntoChild, clientType=self.clientType, 2087 forkChild=forkIntoChild, clientType=self.clientType,
2067 enableCallTrace=enableCallTrace) 2088 enableCallTrace=enableCallTrace)
2068 2089
2069 if self.debugServer.isClientProcessUp() and \ 2090 if (
2070 self.debugServer.getClientType() == self.clientType: 2091 self.debugServer.isClientProcessUp() and
2092 self.debugServer.getClientType() == self.clientType
2093 ):
2071 # Signal that we have started a debugging session 2094 # Signal that we have started a debugging session
2072 self.debuggingStarted.emit(fn) 2095 self.debuggingStarted.emit(fn)
2073 2096
2074 self.stopAct.setEnabled(True) 2097 self.stopAct.setEnabled(True)
2075 2098
2092 doNotStart = False 2115 doNotStart = False
2093 2116
2094 # first save any changes 2117 # first save any changes
2095 if self.lastStartAction in [1, 3, 5, 7, 9]: 2118 if self.lastStartAction in [1, 3, 5, 7, 9]:
2096 editor = self.viewmanager.getOpenEditor(self.lastDebuggedFile) 2119 editor = self.viewmanager.getOpenEditor(self.lastDebuggedFile)
2097 if editor and \ 2120 if (
2098 not self.viewmanager.checkDirty( 2121 editor and
2099 editor, Preferences.getDebugger("Autosave")): 2122 not self.viewmanager.checkDirty(
2123 editor, Preferences.getDebugger("Autosave"))
2124 ):
2100 return 2125 return
2101 forProject = False 2126 forProject = False
2102 elif self.lastStartAction in [2, 4, 6, 8, 10]: 2127 elif self.lastStartAction in [2, 4, 6, 8, 10]:
2103 if Preferences.getDebugger("Autosave") and \ 2128 if (
2104 not self.project.saveAllScripts(reportSyntaxErrors=True): 2129 Preferences.getDebugger("Autosave") and
2130 not self.project.saveAllScripts(reportSyntaxErrors=True)
2131 ):
2105 doNotStart = True 2132 doNotStart = True
2106 self.__compileChangedProjectFiles() 2133 self.__compileChangedProjectFiles()
2107 forProject = True 2134 forProject = True
2108 else: 2135 else:
2109 return # should not happen 2136 return # should not happen

eric ide

mercurial