eric6/Debugger/CallStackViewer.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7927
866ddf957461
child 8043
0acf98cd089a
child 8143
2c730d5fd177
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7853
diff changeset
3 # Copyright (c) 2013 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the Call Stack viewer widget.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
10 from PyQt5.QtCore import pyqtSignal, Qt, QFileInfo
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
11 from PyQt5.QtWidgets import (
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
12 QTreeWidget, QTreeWidgetItem, QMenu, QWidget, QVBoxLayout, QLabel
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
13 )
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from E5Gui.E5Application import e5App
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from E5Gui import E5FileDialog, E5MessageBox
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 import Utilities
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
21 class CallStackViewer(QWidget):
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Class implementing the Call Stack viewer widget.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 @signal sourceFile(str, int) emitted to show the source of a stack entry
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @signal frameSelected(int) emitted to signal the selection of a frame entry
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 sourceFile = pyqtSignal(str, int)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 frameSelected = pyqtSignal(int)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 FilenameRole = Qt.UserRole + 1
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 LinenoRole = Qt.UserRole + 2
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 def __init__(self, debugServer, parent=None):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 Constructor
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
38 @param debugServer reference to the debug server object
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
39 @type DebugServer
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
40 @param parent reference to the parent widget
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
41 @type QWidget
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
2677
3d4277929fb3 Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2622
diff changeset
43 super(CallStackViewer, self).__init__(parent)
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
45 self.__layout = QVBoxLayout(self)
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
46 self.setLayout(self.__layout)
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
47 self.__debuggerLabel = QLabel(self)
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
48 self.__layout.addWidget(self.__debuggerLabel)
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
49 self.__callStackList = QTreeWidget(self)
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
50 self.__layout.addWidget(self.__callStackList)
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
51
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
52 self.__callStackList.setHeaderHidden(True)
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
53 self.__callStackList.setAlternatingRowColors(True)
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
54 self.__callStackList.setItemsExpandable(False)
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
55 self.__callStackList.setRootIsDecorated(False)
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
56 self.setWindowTitle(self.tr("Call Stack"))
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
58 self.__menu = QMenu(self.__callStackList)
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.__sourceAct = self.__menu.addAction(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
60 self.tr("Show source"), self.__openSource)
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
61 self.__menu.addAction(self.tr("Clear"), self.__callStackList.clear)
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 self.__menu.addSeparator()
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
63 self.__menu.addAction(self.tr("Save"), self.__saveStackTrace)
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
64 self.__callStackList.setContextMenuPolicy(Qt.CustomContextMenu)
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
65 self.__callStackList.customContextMenuRequested.connect(
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
66 self.__showContextMenu)
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 self.__dbs = debugServer
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 # file name, line number, function name, arguments
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
71 self.__entryFormat = self.tr("File: {0}\nLine: {1}\n{2}{3}")
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 # file name, line number
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
73 self.__entryFormatShort = self.tr("File: {0}\nLine: {1}")
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.__projectMode = False
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.__project = None
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 self.__dbs.clientStack.connect(self.__showCallStack)
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
79 self.__callStackList.itemDoubleClicked.connect(
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
80 self.__itemDoubleClicked)
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 def setDebugger(self, debugUI):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 Public method to set a reference to the Debug UI.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
86 @param debugUI reference to the DebugUI object
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
87 @type DebugUI
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 debugUI.clientStack.connect(self.__showCallStack)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 def setProjectMode(self, enabled):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 Public slot to set the call trace viewer to project mode.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 In project mode the call trace info is shown with project relative
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 path names.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
98 @param enabled flag indicating to enable the project mode
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
99 @type bool
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 self.__projectMode = enabled
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 if enabled and self.__project is None:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 self.__project = e5App().getObject("Project")
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 def __showContextMenu(self, coord):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 Private slot to show the context menu.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
109 @param coord the position of the mouse pointer
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
110 @type QPoint
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 """
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
112 if self.__callStackList.topLevelItemCount() > 0:
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
113 itm = self.__callStackList.currentItem()
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 self.__sourceAct.setEnabled(itm is not None)
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
115 self.__menu.popup(self.__callStackList.mapToGlobal(coord))
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
117 def clear(self):
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
118 """
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
119 Public method to clear the stack viewer data.
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
120 """
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
121 self.__debuggerLabel.clear()
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
122 self.__callStackList.clear()
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
123
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
124 def __showCallStack(self, stack, debuggerId):
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
126 Private slot to show the call stack of the program being debugged.
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
2988
f53c03574697 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2732
diff changeset
128 @param stack list of tuples with call stack data (file name,
f53c03574697 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2732
diff changeset
129 line number, function name, formatted argument/values list)
7377
cc920e534ac0 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
130 @type list of tuples of (str, str, str, str)
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
131 @param debuggerId ID of the debugger backend
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
132 @type str
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 """
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
134 self.__debuggerLabel.setText(debuggerId)
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
135
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
136 self.__callStackList.clear()
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 for fname, fline, ffunc, fargs in stack:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 if self.__projectMode:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 dfname = self.__project.getRelativePath(fname)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 else:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 dfname = fname
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 if ffunc and not ffunc.startswith("<"):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 # use normal format
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
144 itm = QTreeWidgetItem(
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
145 self.__callStackList,
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
146 [self.__entryFormat.format(dfname, fline, ffunc, fargs)]
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
147 )
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 else:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 # use short format
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
150 itm = QTreeWidgetItem(
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
151 self.__callStackList,
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
152 [self.__entryFormatShort.format(dfname, fline)]
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
153 )
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 itm.setData(0, self.FilenameRole, fname)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 itm.setData(0, self.LinenoRole, fline)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
157 self.__callStackList.resizeColumnToContents(0)
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 def __itemDoubleClicked(self, itm):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 Private slot to handle a double click of a stack entry.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
163 @param itm reference to the double clicked item
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
164 @type QTreeWidgetItem
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 fname = itm.data(0, self.FilenameRole)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 fline = itm.data(0, self.LinenoRole)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 if self.__projectMode:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 fname = self.__project.getAbsolutePath(fname)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 self.sourceFile.emit(fname, fline)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
172 index = self.__callStackList.indexOfTopLevelItem(itm)
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 self.frameSelected.emit(index)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 def __openSource(self):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 Private slot to show the source for the selected stack entry.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 """
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
179 itm = self.__callStackList.currentItem()
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 if itm:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 self.__itemDoubleClicked(itm)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 def __saveStackTrace(self):
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 Private slot to save the stack trace info to a file.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 """
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
187 if self.__callStackList.topLevelItemCount() > 0:
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
190 self.tr("Save Call Stack Info"),
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 "",
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
192 self.tr("Text Files (*.txt);;All Files (*)"),
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 None,
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 if fname:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 ext = QFileInfo(fname).suffix()
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 if not ext:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 ex = selectedFilter.split("(*")[1].split(")")[0]
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 if ex:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 fname += ex
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 if QFileInfo(fname).exists():
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2988
diff changeset
202 res = E5MessageBox.yesNo(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2988
diff changeset
203 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
204 self.tr("Save Call Stack Info"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
205 self.tr("<p>The file <b>{0}</b> already exists."
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
206 " Overwrite it?</p>").format(fname),
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 icon=E5MessageBox.Warning)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 if not res:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 return
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 fname = Utilities.toNativeSeparators(fname)
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 try:
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
213 title = self.tr("Call Stack of '{0}'").format(
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
214 self.__debuggerLabel.text())
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
215 with open(fname, "w", encoding="utf-8") as f:
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
216 f.write("{0}\n".format(title))
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
217 f.write("{0}\n\n".format(len(title) * "="))
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
218 itm = self.__callStackList.topLevelItem(0)
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
219 while itm is not None:
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
220 f.write("{0}\n".format(itm.text(0)))
7927
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
221 f.write("{0}\n".format(78 * "="))
866ddf957461 Call Trace Viewer, Call Stack Viewer: some refinements and further adaptions to the multi-process debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
222 itm = self.__callStackList.itemBelow(itm)
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7785
diff changeset
223 except OSError as err:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2988
diff changeset
224 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2988
diff changeset
225 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
226 self.tr("Error saving Call Stack Info"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
227 self.tr("""<p>The call stack info could not be"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
228 """ written to <b>{0}</b></p>"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
229 """<p>Reason: {1}</p>""")
3032
927a2f8b3669 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3021
diff changeset
230 .format(fname, str(err)))

eric ide

mercurial