Skip to content

Commit

Permalink
More resilient locking, so QT UI update does not clash with in-progre…
Browse files Browse the repository at this point in the history
…ss actions like converting a block to code. Also inverted colouring for uncertain data references.
  • Loading branch information
rmtew committed Feb 14, 2017
1 parent 4668cc5 commit 011964c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
7 changes: 5 additions & 2 deletions .gitignore
@@ -1,4 +1,7 @@
samples
local_binaries
*.pyc
*.pikl
/.vs/Solution/v14/.suo
/.pyproj.user
/.vs/Solution/v*/.suo
/*.pyproj.user
/*.psproj
10 changes: 5 additions & 5 deletions python/disassembly.py
Expand Up @@ -985,9 +985,9 @@ def get_block_line_number(program_data, block_idx):
def clear_block_line_count(program_data, block, block_idx=None):
""" line_count_rlock """
# type: (disassembly_data.ProgramData, disassembly_data.SegmentBlock, int) -> None
if block_idx is None:
discard, block_idx = lookup_block_by_address(program_data, block.address)
with line_count_rlock:
if block_idx is None:
discard, block_idx = lookup_block_by_address(program_data, block.address)
block.line_count = 0
if program_data.block_line0s_dirtyidx is None or block_idx < program_data.block_line0s_dirtyidx:
program_data.block_line0s_dirtyidx = block_idx
Expand Down Expand Up @@ -1025,10 +1025,10 @@ def api_get_next_block_line_number(program_data, data_type, line_idx, direction_
def insert_block(program_data, insert_idx, block):
""" line_count_rlock """
# type: (disassembly_data.ProgramData, int, disassembly_data.SegmentBlock) -> None
program_data.block_addresses.insert(insert_idx, block.address)
program_data.blocks.insert(insert_idx, block)

with line_count_rlock:
program_data.block_addresses.insert(insert_idx, block.address)
program_data.blocks.insert(insert_idx, block)

program_data.block_line0s.insert(insert_idx, None)
# Update how much of the sorted line number index needs to be recalculated.
if program_data.block_line0s_dirtyidx is None or insert_idx < program_data.block_line0s_dirtyidx:
Expand Down
3 changes: 3 additions & 0 deletions python/editor_state.py
Expand Up @@ -256,6 +256,9 @@ def get_address(self, acting_client):
# worth reconsidering dealing with things in terms of line numbers. TODO.
return disassembly.api_get_address_for_line_number(self.disassembly_data, self.line_number)

def get_address_for_line_number(self, acting_client, line_number):
return disassembly.api_get_address_for_line_number(self.disassembly_data, line_number)

def get_line_number_for_address(self, acting_client, address):
return disassembly.api_get_line_number_for_address(self.disassembly_data, address)

Expand Down
15 changes: 11 additions & 4 deletions python/qtui.py
Expand Up @@ -260,7 +260,8 @@ class DisassemblyItemDelegate(QtGui.QStyledItemDelegate):
}
"""

def __init__(self, parent=None):
def __init__(self, parent, window):
self._window = window
super(DisassemblyItemDelegate, self).__init__(parent)

def paint(self, painter, option, index):
Expand All @@ -273,8 +274,10 @@ def paint(self, painter, option, index):
doc.setDefaultFont(self.parent().font())
doc.setDefaultStyleSheet(self.default_style_sheet)
text = options.text
bits = text.split(", ")
if options.state & QtGui.QStyle.State_Selected:
if self._window._is_uncertain_data_reference(index.row()):
text = "<span style='color: white; background-color: black'>"+ text +"</span>";
elif options.state & QtGui.QStyle.State_Selected:
bits = text.split(", ")
if len(bits) > 1:
bits[0] += ", "
text = "<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor=red>"+ ("</td><td bgcolor=green>".join(bits)) +"</td></tr></table>"
Expand Down Expand Up @@ -530,7 +533,7 @@ def __init__(self, parent=None):
self.list_model._column_alignments[0] = QtCore.Qt.AlignRight
self.list_table = create_table_widget(self, self.list_model)
self.list_table.setColumnWidth(4, 200)
self.list_table.setItemDelegate(DisassemblyItemDelegate(self.list_table))
self.list_table.setItemDelegate(DisassemblyItemDelegate(self.list_table, self))
self.list_table.setSelectionBehavior(QtGui.QAbstractItemView.SelectItems)
self.list_table.selection_change_signal.connect(self.list_table_selection_change_event)
self.setCentralWidget(self.list_table)
Expand Down Expand Up @@ -1254,6 +1257,10 @@ def close_progress_dialog(self):
self._progress_dialog = None
self._progress_dialog_steps = 0

def _is_uncertain_data_reference(self, line_number):
address = self.editor_state.get_address_for_line_number(self.editor_client, line_number)
return self.uncertain_data_references_model._index_cell_value(0, address) > -1

def _get_rows_from_indices(self, indices):
# Whether the selection model is per-row (rather than per-cell) or not, we get all
# selected cells. So use a set generator expression to get a unique set of rows.
Expand Down

0 comments on commit 011964c

Please sign in to comment.