diff --git a/gdb-port/parser.py b/gdb-port/parser.py index 7bd7607ab8f1bd8f832bc794ba07cc3b381efaff..71544570e9713a8f5808f8d4d97f2306a1a33e03 100644 --- a/gdb-port/parser.py +++ b/gdb-port/parser.py @@ -127,10 +127,13 @@ class ParserStack: # On a pop() operation, to compute the difference, the code needs to find the corresponding push(), subtract amb_2-amb_1, then from the result, recursively subtract the (amb_2-amb_1) differences of the push()/pop() pairs inbetween # The push/pop operations are implicitly guaranteed to be balanced so long as execution proceeds normally - def push(self, parser, should_commit=False): + def push(self, parser, arena, should_commit=False): self.p_stack.append(parser) if self.top_level_parse.memory_stat_method == HammerMemoryStatisticsMethod.DETAILED_ARENA_STATS: - #TODO: check that self.arena is same as gdb.selected_frame()'s arena + #TODO: self.arena would only be none on the first push(), and should have a value by the time commit_at_*() functions run + # it might be worth merging TopLevelParse.first_h_do_parse_after_h_packrat_parse() into TopLevelParse.enter_h_do_parse() + assert (self.arena is None) or self.arena == arena + #assert self.arena == arena # DEBUG self.stack_events.append((StackEvent.PUSH, int(self.arena_gdbval['arena_malloc_bytes']), parser)) prev = 0 #print("Bytes allocated since last h_do_parse:", thusfar, ", parser:", str(parser)) # DEBUG @@ -271,6 +274,8 @@ class ParserStack: #print("commit_at_pop: current_frame_alloc", current_frame_alloc) # DEBUG pop_allocs = {} + assert self.arena # DEBUG + # TODO: clean up if len(ev_list) == 1: # Compare bytes allocated in arena to last known value, which will be the additional bytes allocated since reentering the stack frame @@ -307,6 +312,8 @@ class ParserStack: #print("commit_at_push: ev_list:", ev_list) # DEBUG #print("commit_at_push: current_parser:", current_parser) # DEBUG #print("commit_at_push: current_event:", current_event) # DEBUG + + assert self.arena # DEBUG # Degenerate cases: there is a single push event on ev_list. In that case, we do nothing but increment self.committed # A pop followed by a push will also be effectively a no-op, with the difference in bytes allocated being zero (but potentially not always: does longjmp() mess with this?) diff --git a/gdb-port/top-level-parse.py b/gdb-port/top-level-parse.py index 060a7c8d0920272633bd37923d2cb1752f2360f2..80e0fa556e5000cd94b0337318d9ececc6432ef6 100644 --- a/gdb-port/top-level-parse.py +++ b/gdb-port/top-level-parse.py @@ -64,7 +64,7 @@ class TopLevelParse: parser_obj = Parser(None, parser) self.parser_objs[parser] = parser_obj parser_stack = self.peek_parserstack() - parser_stack.push(parser_obj, stopping_at_bp) + parser_stack.push(parser_obj, arena, stopping_at_bp) parser_obj.increment_apply_count(int(arena)) if parser_stack.parse_state is None and parser_stack.parse_state != parse_state_int: self.first_h_do_parse_after_packrat_parse(parse_state_int, arena_int)