From 0c880dd5ad420a4c15bfe2f30cb2cdf3425e3f1c Mon Sep 17 00:00:00 2001 From: Jim Carciofini Date: Mon, 19 Feb 2024 13:37:37 -0600 Subject: [PATCH] Fix bug wrt which end of edge is clicked in CFAR flow graph. --- pate_binja/pate.py | 4 ++-- pate_binja/view.py | 29 +++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/pate_binja/pate.py b/pate_binja/pate.py index a3c6fc04..e7fa2d1f 100644 --- a/pate_binja/pate.py +++ b/pate_binja/pate.py @@ -513,10 +513,10 @@ def pprint_node_event_trace(self, trace, label: str, pre: str = '', out: IO = sy def pprint_node_event_trace_domain(self, trace, label: str, pre: str = '', out: IO = sys.stdout): if trace.get('precondition'): - out.write(f'{pre}Trace Precondition:\n') + out.write(f'{pre}Precondition:\n') pprint_eq_domain(trace['precondition'], pre + ' ', out) if trace.get('postcondition'): - out.write(f'{pre}Trace Postcondition:\n') + out.write(f'{pre}Postcondition:\n') pprint_eq_domain(trace['postcondition'], pre + ' ', out) def pprint_node_event_trace_original(self, trace, label: str, pre: str = '', out: IO = sys.stdout): diff --git a/pate_binja/view.py b/pate_binja/view.py index 09d1f8d5..cb0f66b7 100644 --- a/pate_binja/view.py +++ b/pate_binja/view.py @@ -238,8 +238,6 @@ def build_pate_flow_graph(self, show_ce_trace: bool = False): flow_graph = FlowGraph() - show_ce_trace = False # disable for now - # First create all nodes cfarToFlowNode = {} cfar_node: pate.CFARNode @@ -253,7 +251,7 @@ def build_pate_flow_graph(self, out.write(cfar_node.id.replace(' <- ', '\n <- ')) out.write('\n') - cfar_node.pprint_node_contents('', out, show_ce_trace) + cfar_node.pprint_node_contents('', out, False) # show_ce_trace) Disable trace in node flow_node.lines = out.getvalue().split('\n') # flow_node.lines = [lines[0]] @@ -284,17 +282,25 @@ def build_pate_flow_graph(self, def mousePressEvent(self, event: QMouseEvent): node = self.getNodeForMouseEvent(event) edgeTuple = self.getEdgeForMouseEvent(event) - print("Node: ", node) - print("Edge: ", edgeTuple) + # if node: + # print("Node: ", self.flowToCfarNode[node].id) + # if edgeTuple: + # print("Edge source: ", self.flowToCfarNode[edgeTuple[0].source].id) + # print("Edge target: ", self.flowToCfarNode[edgeTuple[0].target].id) + # print("Edge incoming: ", edgeTuple[1]) if edgeTuple: self.showExitInfo(edgeTuple) def showExitInfo(self, edgeTuple: tuple[FlowGraphEdge, bool]) -> None: edge = edgeTuple[0] - incoming = edgeTuple[1] - sourceCfarNode = self.flowToCfarNode[edge.source] - exitCfarNode = self.flowToCfarNode[edge.target] + incoming = edgeTuple[1] # Direction of edge depends on which half was clicked + if incoming: + sourceCfarNode = self.flowToCfarNode[edge.target] + exitCfarNode = self.flowToCfarNode[edge.source] + else: + sourceCfarNode = self.flowToCfarNode[edge.source] + exitCfarNode = self.flowToCfarNode[edge.target] exitMetaData = sourceCfarNode.exit_meta_data.get(exitCfarNode, {}) @@ -308,6 +314,13 @@ def showExitInfo(self, edgeTuple: tuple[FlowGraphEdge, bool]) -> None: # TODO: dialog? print("No exit info") + exitMetaData = sourceCfarNode.exit_meta_data.get(exitCfarNode, {}) + ceTrace = exitMetaData.get('ce_event_trace') + trace = exitMetaData.get('event_trace') + print('exitMetaData:', exitMetaData) + print('ceTrace', ceTrace) + print('trace', trace) + def showExitTraceInfo(self, sourceCfarNode: pate.CFARNode, trace: dict, label: str): d = PateCfarExitDialog(parent=self) with io.StringIO() as out: