From 5ab789782635d1e1a4d2ad1245f2d4b1b4978e29 Mon Sep 17 00:00:00 2001
From: pompolic <pompolic@special-circumstanc.es>
Date: Fri, 14 Apr 2023 19:28:25 +0200
Subject: [PATCH] Hook up new functions with ParserStack.pop()

---
 gdb-port/parser.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gdb-port/parser.py b/gdb-port/parser.py
index 00ff0b6..58cd12e 100644
--- a/gdb-port/parser.py
+++ b/gdb-port/parser.py
@@ -154,6 +154,7 @@ class ParserStack:
 			# and presenting it a unified manner at the UI layer
 			# Additionally, it would probably make more sense to store it at the ParserStack, storing (frame, bytes) pairs
 			self.bytes_since_prev_h_do_parse.append(thusfar)
+			# TODO: where should commit_on_push() be called? HDoParseBreakpoint determines whether to stop, which ParserStack doesn't know about. could be a bool parameter to push()
 
 	def pop(self):
 		self.partial_alloc_counts.pop()
@@ -169,10 +170,10 @@ class ParserStack:
 			allocated_bytes = self.cumulative_byte_differences[-len(self.cumulative_byte_differences)] - self.cumulative_byte_differences[-(len(self.cumulative_byte_differences)-1)]  # NB: len(self.cumulative_byte_differences) changed since the last line
 			self.total_byte_differences.insert(-len(self.cumulative_byte_differences), allocated_bytes)
 
-			allocs = self.compute_parserstack_frame_allocs()
+			allocs = self.commit_on_pop()
 			#print("adding mem use: parser:", str(parser_obj), "arena:", hex(int(self.arena)), "bytes:", allocated_bytes) # DEBUG
 			print("adding mem use (alternate): parser:", str(parser_obj), "arena:", hex(int(self.arena)), "bytes:", allocs) # DEBUG
-			parser_obj.add_mem_use(int(self.arena), allocs)
+			#parser_obj.add_mem_use(int(self.arena), allocs)
 			# TODO: allocations can be attributed to individual h_do_parse(parser) calls, thus the same per-parser per-arena stats tracking can be done
 
 		return self.p_stack.pop()
@@ -336,6 +337,7 @@ class ParserStack:
 		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_at_pop: self.committed:", self.committed) # DEBUG
 		print("commit_at_pop: ev_list:", ev_list) # DEBUG
 		print("commit_at_pop: current_parser:", current_parser) # DEBUG
 		print("commit_at_pop: current_event:", current_event) # DEBUG
@@ -377,6 +379,7 @@ class ParserStack:
 		ev_list = self.stack_events[ev_start:]
 		# NOTE: assumes that ParserStack.push() has already pushed the parser in question on the stack
 		current_parser = self.p_stack[-1]
+		print("commit_at_push: self.committed:", self.committed) # DEBUG
 		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
@@ -394,6 +397,7 @@ class ParserStack:
 
 		# Most recent event is a push event, and we have no information on its allocations yet. So we only increment self.committed up to the index of the previous event
 		self.committed = len(self.stack_events)-2
+		# TODO: do we want to increment mem use in commit_at_*, or do we want to return the dict and have it taken care of by push()/pop()?
 		return push_allocs
 
 	# checking self.committed will show if all the relevant allocations before revisiting the current stack frame have been committed.
-- 
GitLab