eric6/Debugger/CallStackViewer.py

Tue, 20 Apr 2021 19:47:39 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 20 Apr 2021 19:47:39 +0200
changeset 8257
28146736bbfc
parent 8218
7c09585bd960
child 8273
698ae46f40a4
permissions
-rw-r--r--

Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).

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
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7927
diff changeset
31 FilenameRole = Qt.ItemDataRole.UserRole + 1
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7927
diff changeset
32 LinenoRole = Qt.ItemDataRole.UserRole + 2
2622
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 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
43 super().__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)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7927
diff changeset
64 self.__callStackList.setContextMenuPolicy(
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7927
diff changeset
65 Qt.ContextMenuPolicy.CustomContextMenu)
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
66 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
67 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
68
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 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
70
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 # 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
72 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
73 # 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
74 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
75
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 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
77 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
78
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 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
80 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
81 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
82
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 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
84 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 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
86
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
87 @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
88 @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
89 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 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
91
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 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
93 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 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
95
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 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
97 path names.
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98
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
99 @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
100 @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
101 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 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
103 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
104 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
105
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 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
107 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 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
109
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
110 @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
111 @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
112 """
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
113 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
114 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
115 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
116 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
117
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
118 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
119 """
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 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
121 """
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.__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
123 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
124
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
125 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
126 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
127 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
128
2988
f53c03574697 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2732
diff changeset
129 @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
130 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
131 @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
132 @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
133 @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
134 """
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
135 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
136
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
137 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
138 for fname, fline, ffunc, fargs in stack:
8257
28146736bbfc Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
139 dfname = (
28146736bbfc Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
140 self.__project.getRelativePath(fname)
28146736bbfc Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
141 if self.__projectMode else
28146736bbfc Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
142 fname
28146736bbfc Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
143 )
28146736bbfc Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
144 itm = (
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 # use normal format
8257
28146736bbfc Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
146 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
147 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
148 [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
149 )
8257
28146736bbfc Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
150 if ffunc and not ffunc.startswith("<") else
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 # use short format
8257
28146736bbfc Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
152 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
153 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
154 [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
155 )
8257
28146736bbfc Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
156 )
2622
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 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
158 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
159
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
160 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
161
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 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
163 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 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
165
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
166 @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
167 @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
168 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 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
170 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
171 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
172 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
173 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
174
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
175 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
176 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
177
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 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
179 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 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
181 """
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
182 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
183 if itm:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 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
185
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 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
187 """
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 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
189 """
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
190 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
191 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
192 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
193 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
194 "",
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
195 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
196 None,
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 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
198 if fname:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 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
200 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
201 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
202 if ex:
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 fname += ex
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 if QFileInfo(fname).exists():
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2988
diff changeset
205 res = E5MessageBox.yesNo(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2988
diff changeset
206 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
207 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
208 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
209 " 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
210 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
211 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
212 return
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 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
214
08cc2f31c983 Added a viewer for the call stack leading to the current line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 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
216 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
217 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
218 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
219 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
220 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
221 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
222 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
223 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
224 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
225 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
226 except OSError as err:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2988
diff changeset
227 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2988
diff changeset
228 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
229 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
230 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
231 """ 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
232 """<p>Reason: {1}</p>""")
3032
927a2f8b3669 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3021
diff changeset
233 .format(fname, str(err)))

eric ide

mercurial