From 2605146b9db6623dc4c34b0b049c5a16a3a9bff7 Mon Sep 17 00:00:00 2001 From: pompolic <pompolic@special-circumstanc.es> Date: Fri, 31 Mar 2023 20:38:41 +0200 Subject: [PATCH] (WIP commit) Add destructive version of previous function, rename compute -> calculate --- gdb-port/parser.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/gdb-port/parser.py b/gdb-port/parser.py index e429e70..ba34bc1 100644 --- a/gdb-port/parser.py +++ b/gdb-port/parser.py @@ -245,6 +245,7 @@ class ParserStack: return self.compute_outer_frame(stack_events) + #TODO: compute -> calculate def compute_outer_frame(self, stack_slice): if len(stack_slice) == 2: return stack_slice[1][1] - stack_slice[0][1] @@ -256,16 +257,32 @@ class ParserStack: # alternatively: return (stack_slice[-1][1] - stack_slice[-2][1]) + (stack_slice[1][1] - stack_slice[0][1]) - def compute_pushes_at_end(self): + def calculate_pushes_at_end(self): # Throws StopIteration if no more items in the iterator match the condition - last_pop = next(index for index,ev in enumerate(self.stack_events[::-1]) if ev[0] == StackEvent.POP, None) + last_pop = next((index for index,ev in enumerate(self.stack_events[::-1]) if ev[0] == StackEvent.POP), None) + # TODO: recursion, attribute each difference to the correct parser if last_pop is None: # No "pop" events in the list, stack_events is all pushes # Subtract the bytes allocated before the first push happened, from the bytes allocated by the most recent h_do_parse() - return self.stack_events[0][1] - self.stack_events[-1][1] + #return self.stack_events[0][1] - self.stack_events[-1][1] + pass - return self.stack_events[0][1] - self.stack_events[-index][1] + #return self.stack_events[0][1] - self.stack_events[-index][1] #for index, ev in enumerate(self.stack_events[::-1]): # if ev[0] == StackEvent.POP: # last_pop = index + + def calculate_and_clear_pushes_at_end(self): + # Throws StopIteration if no more items in the iterator match the condition + last_pop = next((index for index,ev in enumerate(self.stack_events[::-1]) if ev[0] == StackEvent.POP), None) + # TODO: recursion + if last_pop is None: + # No "pop" events in the list, stack_events is all pushes + # Subtract the bytes allocated before the first push happened, from the bytes allocated by the most recent h_do_parse() + #allocs = self.stack_events[0][1] - self.stack_events[-1][1] + pass + + #allocs = self.stack_events[0][1] - self.stack_events[-index][1] + # Clear elements related to allocations we just counted + self.stack_events = self.stack_events[:-index] -- GitLab