diff --git a/gdb-port/parser.py b/gdb-port/parser.py index 3d25e67dff28c97124e8589abcf1620517e4affb..6bfd8989ecae973542a6ad94443b541ca210976a 100644 --- a/gdb-port/parser.py +++ b/gdb-port/parser.py @@ -98,12 +98,10 @@ class ParserStack: self.bytes_since_prev_h_do_parse = [] self.stack_events = [] # Represents the index of a "waterline" on the stack_events for the purpose of counting allocations - # This is the index of the first event (stack push or pop) whose allocations have not been committed to memory stats yet. - # Allocations are computed by taking the difference of the total allocated bytes at a particular event and the total allocated bytes at the next event, stack_events[-1] will not be under the waterline under normal circumstances. - # (Possible exception: when stopping at a h_do_parse breakpoint to return control to the user.) - # Otherwise, self.committed <= len(stack_events)-2 + # This is the index of the last event (stack push or pop) where the relevant allocations have been committed to TopLevelParse's memory stats. + # Due to the semantics of stack events, this means that if self.committed points to a push event, nothing in that "frame" has been committed yet. if it points to a pop event, everything in that "frame" has been committed # A pop event will always commit, a push event will commit if the user requested a stop at that position (via hammer-parse-apply or hammer-parse-stop-pos) - self.committed = 0 + self.committed = -1 # New approach: # ParserStack tracks what "context" allocations happen in. A context is defined as a set of stack frames operating on the same parser @@ -334,15 +332,18 @@ class ParserStack: def commit_pop(self): current_event = self.stack_events[-1] - ev_list = self.stack_events[self.committed:] + ev_start = self.committed if self.committed > 0 else 0 + ev_list = self.stack_events[ev_start:] # NOTE: Assumes that ParserStack.pop() pops p_stack after this function runs current_parser = self.p_stack[-1] print("commit_pop: ev_list:", ev_list) # DEBUG - print("commit_pop: parser:", parser) # DEBUG + print("commit_pop: current_parser:", current_parser) # DEBUG for index, event in enumerate(ev_list[::-1]): pass + self.committed = len(self.stack_events)-1 + def commit_pushes_at_end(self): pass