forked from iGio90/Dwarf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpanel_contexts.py
110 lines (94 loc) · 4.02 KB
/
panel_contexts.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
"""
Dwarf - Copyright (C) 2019 Giovanni Rocca (iGio90)
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 3 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>
"""
from PyQt5.QtCore import Qt
from ui.widget_context import ContextItem
from ui.widget_item_not_editable import NotEditableTableWidgetItem
from ui.widget_memory_address import MemoryAddressWidget
from ui.widget_table_base import TableBaseWidget
class ContextsPanel(TableBaseWidget):
def __init__(self, app, *__args):
super().__init__(app, 0, 0)
self.traced_tid = 0
def set_menu_actions(self, item, menu):
if item is not None:
ctx = self.item(item.row(), 0)
if isinstance(ctx, ContextItem):
if self.traced_tid > 0:
trace = menu.addAction("Stop trace")
else:
trace = menu.addAction("Trace")
trace.setData('trace')
menu.addSeparator()
resume = menu.addAction("Resume")
resume.setData('resume')
def on_menu_action(self, action_data, item):
ctx = self.item(item.row(), 0)
if isinstance(ctx, ContextItem):
if action_data == 'trace':
if self.traced_tid > 0:
self.app.dwarf_api('stopTracer')
self.app.get_trace_panel().stop()
else:
self.traced_tid = ctx.get_tid()
self.app.dwarf_api('startTracer', tid=self.traced_tid)
self.app.get_session_ui().add_dwarf_tab('trace', request_focus=False)
elif action_data == 'resume':
self.app.resume(ctx.get_tid())
return False
def resume_tid(self, tid):
items = self.findItems(str(tid), Qt.MatchExactly)
if len(items) > 0:
self.removeRow(items[0].row())
def add_context(self, data, library_onload=None):
if self.columnCount() == 0:
self.setColumnCount(3)
self.setHorizontalHeaderLabels(['tid', 'pc', 'symbol'])
row = self.rowCount()
self.insertRow(row)
q = ContextItem(data, str(data['tid']))
q.setForeground(Qt.darkCyan)
self.setItem(row, 0, q)
is_java = data['is_java']
if not is_java:
q = MemoryAddressWidget(data['ptr'])
else:
parts = data['ptr'].split('.')
q = NotEditableTableWidgetItem(parts[len(parts) - 1])
q.setForeground(Qt.red)
q.setFlags(Qt.NoItemFlags)
self.setItem(row, 1, q)
if library_onload is None:
if not is_java:
q = NotEditableTableWidgetItem('%s - %s' % (
data['symbol']['moduleName'], data['symbol']['name']))
else:
q = NotEditableTableWidgetItem('.'.join(parts[:len(parts) - 1]))
else:
q = NotEditableTableWidgetItem('loading %s' % library_onload)
q.setFlags(Qt.NoItemFlags)
q.setForeground(Qt.gray)
self.setItem(row, 2, q)
self.resizeRowsToContents()
self.horizontalHeader().setStretchLastSection(True)
def item_double_clicked(self, item):
if isinstance(item, ContextItem):
self.app.apply_context(item.get_context())
return False
return True
def clear(self):
self.setRowCount(0)
self.setColumnCount(0)
self.resizeColumnsToContents()
self.horizontalHeader().setStretchLastSection(True)
self.traced_tid = 0