-
Notifications
You must be signed in to change notification settings - Fork 0
/
debugger.py
executable file
·143 lines (123 loc) · 4.85 KB
/
debugger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#! /usr/bin/python
# A PyQt tool to help in the debugging of Sage.
# Copyright 2013 Miguel Angel Marco Buzunariz.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import sys
import dbus
from PyQt5 import QtCore, QtGui, uic, QtWidgets
import time
class Debugger(QtWidgets.QDialog):
def __init__(self, parent=None):
QtWidgets.QDialog.__init__(self)
self.ui = uic.loadUi("debugger.ui")
self.history = []
self.nhistory = 0
self.ui.show()
def tracecommand(*args):
window.history = []
window.nhistory = 0
konsoleproxy.runCommand(
'trace(\''+str(window.ui.tracecommand.text())+'\')')
window.prints()
def printn(*args):
konsoleproxy.runCommand('next')
window.actualize()
def printuntil(*args):
konsoleproxy.runCommand('until')
window.actualize()
def printr(*args):
konsoleproxy.runCommand('return')
window.actualize()
def printq(*args):
konsoleproxy.runCommand('quit')
def prints(*args):
konsoleproxy.runCommand('step')
window.actualize()
def backbutton(*args):
window.nhistory -= 1
window.showhistory()
def forwardbutton(*args):
window.nhistory += 1
window.showhistory()
def showhistory(*args):
katefilestring = window.history[window.nhistory][0]
katefileline = window.history[window.nhistory][1]
kateproxy.openUrl(u"file:/"+katefilestring, "ascii")
kateproxy.setCursor(katefileline-1, 0)
window.ui.localslist.setRowCount(0)
listparsed = window.history[window.nhistory][2]
for entry in listparsed:
rowNum = window.ui.localslist.rowCount()
window.ui.localslist.insertRow(rowNum)
window.ui.localslist.setItem(
rowNum, 0, QtWidgets.QTableWidgetItem(entry[0]))
window.ui.localslist.setItem(
rowNum, 1, QtWidgets.QTableWidgetItem(entry[1]))
# window.ui.localslist.resizeColumnsToContents()
if window.nhistory == 0:
window.ui.backbutton.setDisabled(True)
else:
window.ui.backbutton.setEnabled(True)
if window.nhistory == len(window.history)-1:
window.ui.forwardbutton.setDisabled(True)
else:
window.ui.forwardbutton.setEnabled(True)
def actualize(*args):
tries = 0
while True:
tries += 1
if tries > 20:
return
try:
time.sleep(0.1)
logfile = open(str(window.ui.logfilerequester.text()))
logfilelines = logfile.readlines()
stringparsed = logfilelines[-8]
a = stringparsed.index('(')
b = stringparsed.index(')')
katefilestring = stringparsed[10:a-4]
katefileline = int(stringparsed[a+1:b])
logfile.close()
break
except (ValueError):
pass
konsoleproxy.runCommand('[(a[0],str(a[1])) for a in locals().items()]')
time.sleep(0.2)
logfile = open(str(window.ui.logfilerequester.text()))
logfilelines = logfile.readlines()
stringparsed = logfilelines[-2]
logfile.close()
try:
listparsed = eval(stringparsed)
except:
listparsed = []
listparsed.sort()
window.history.append([katefilestring, katefileline, listparsed])
window.nhistory = len(window.history)-1
window.showhistory()
# konsoleproxy.runCommand('globals()')
if __name__ == "__main__":
bus = dbus.SessionBus()
katebus = list(filter(lambda i: 'kate' in i, [
aa.__str__() for aa in bus.list_names()]))[0]
konsoleproxy = bus.get_object(katebus, '/Sessions/1')
kateproxy = bus.get_object(katebus, '/MainApplication')
fileline = None
app = QtWidgets.QApplication(sys.argv)
window = Debugger()
window.ui.nbutton.clicked.connect(window.printn)
window.ui.qbutton.clicked.connect(window.printq)
window.ui.sbutton.clicked.connect(window.prints)
window.ui.rbutton.clicked.connect(window.printr)
window.ui.untilbutton.clicked.connect(window.printuntil)
window.ui.backbutton.clicked.connect(window.backbutton)
window.ui.forwardbutton.clicked.connect(window.forwardbutton)
window.ui.tracecommand.returnPressed.connect(window.tracecommand)
sys.exit(app.exec_())