Skip to content

Commit

Permalink
Fix bug wrt which end of edge is clicked in CFAR flow graph.
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-carciofini committed Feb 19, 2024
1 parent 9d68d3c commit 0c880dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pate_binja/pate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
29 changes: 21 additions & 8 deletions pate_binja/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]]
Expand Down Expand Up @@ -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, {})

Expand All @@ -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:
Expand Down

0 comments on commit 0c880dd

Please sign in to comment.