diff --git a/gdb-port/parser.py b/gdb-port/parser.py index e429e7027b2f63cbd5dca582be336e8c396fc3dd..ba34bc1ee2065645d91ae78cfde1624c848736a8 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]