From c7fda1ae30d42097f2f5132859bf00dc21d0af60 Mon Sep 17 00:00:00 2001
From: pompolic <pompolic@special-circumstanc.es>
Date: Wed, 15 Feb 2023 15:13:38 +0100
Subject: [PATCH] Printing cleanup

---
 gdb-port/commands.py           | 42 ++++++++++++++++++----------------
 gdb-port/hammer-breakpoints.py |  2 +-
 2 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/gdb-port/commands.py b/gdb-port/commands.py
index bcfa0c7..1c030ca 100644
--- a/gdb-port/commands.py
+++ b/gdb-port/commands.py
@@ -222,9 +222,10 @@ class HammerParseApply(FlowControlWithPrint):
 		print(":: hammer-parse-apply")
 
 	def invoke(self, arg, from_tty):
-		#profiler = cProfile.Profile() # DEBUG
-		#profiler.enable() # DEBUG
-		with cProfile.Profile() as profiler: # DEBUG
+		##profiler = cProfile.Profile() # DEBUG
+		##profiler.enable() # DEBUG
+		#with cProfile.Profile() as profiler: # DEBUG
+		if True:
 			top_level_parse.setup_ast_stack_index(0) #TODO: is it a problem if this command overwrites it? would it better to use a convenience variable, as with parse-step?
 			showmap_old = top_level_parse.show_input_map_after_apply
 			top_level_parse.show_input_map_after_apply = False
@@ -237,13 +238,13 @@ class HammerParseApply(FlowControlWithPrint):
 			top_level_parse.clear_ast_stack_index()
 
 			self.conditionally_print_backtrace()
-		profiler.print_stats(sort='tottime') # DEBUG
-		#profiler.disable() # DEBUG
-		#s = io.StringIO() # DEBUG
-		#sortby = SortKey.CUMULATIVE # DEBUG
-		#ps = pstats.Stats(pr, stream=s).sort_stats(sortby) # DEBUG
-		#ps.print_stats() # DEBUG
-		#print(s.getvalue()) # DEBUG
+		#profiler.print_stats(sort='tottime') # DEBUG
+		##profiler.disable() # DEBUG
+		##s = io.StringIO() # DEBUG
+		##sortby = SortKey.CUMULATIVE # DEBUG
+		##ps = pstats.Stats(pr, stream=s).sort_stats(sortby) # DEBUG
+		##ps.print_stats() # DEBUG
+		##print(s.getvalue()) # DEBUG
 
 HammerParseApply()
 
@@ -253,9 +254,10 @@ class HammerParseApplyAndShowAST(FlowControlWithPrint):
 		print(":: hammer-parse-apply-and-show-ast")
 
 	def invoke(self, arg, from_tty):
-		#profiler = cProfile.Profile() # DEBUG
-		#profiler.enable() # DEBUG
-		with cProfile.Profile() as profiler: # DEBUG
+		##profiler = cProfile.Profile() # DEBUG
+		##profiler.enable() # DEBUG
+		#with cProfile.Profile() as profiler: # DEBUG
+		if True:
 			top_level_parse.setup_ast_stack_index(0) #TODO: is it a problem if this command overwrites it? would it better to use a convenience variable, as with parse-step?
 			showmap_old = top_level_parse.show_input_map_after_apply
 			top_level_parse.show_input_map_after_apply = True
@@ -268,12 +270,12 @@ class HammerParseApplyAndShowAST(FlowControlWithPrint):
 			top_level_parse.clear_ast_stack_index()
 
 			self.conditionally_print_backtrace()
-		profiler.print_stats(sort='tottime') # DEBUG
-		#profiler.disable() # DEBUG
-		#s = io.StringIO() # DEBUG
-		#sortby = SortKey.CUMULATIVE # DEBUG
-		#ps = pstats.Stats(pr, stream=s).sort_stats(sortby) # DEBUG
-		#ps.print_stats() # DEBUG
-		#print(s.getvalue()) # DEBUG
+		#profiler.print_stats(sort='tottime') # DEBUG
+		##profiler.disable() # DEBUG
+		##s = io.StringIO() # DEBUG
+		##sortby = SortKey.CUMULATIVE # DEBUG
+		##ps = pstats.Stats(pr, stream=s).sort_stats(sortby) # DEBUG
+		##ps.print_stats() # DEBUG
+		##print(s.getvalue()) # DEBUG
 
 HammerParseApplyAndShowAST()
diff --git a/gdb-port/hammer-breakpoints.py b/gdb-port/hammer-breakpoints.py
index 2e26ae6..ba5d5d6 100644
--- a/gdb-port/hammer-breakpoints.py
+++ b/gdb-port/hammer-breakpoints.py
@@ -96,7 +96,7 @@ class HDoParseRetBreakpoint(gdb.Breakpoint):
 			ast_manager.print_ast()
 			#print(top_level_parse.peek_parserstack().p_stack) #TODO:sometimes the hammer-parser-backtrace gets messed up
 			top_level_parse.input_ptr = parse_state['input_stream']['input']
-			if top_level_parse.show_input_map_after_apply:
+			if top_level_parse.show_input_map_after_apply and ast_manager.top_node:
 				top_level_parse.print_input_map(ast_manager.top_node.ast)
 			#print(top_level_parse.peek_parserstack().p_stack)
 			# Do not stop at this breakpoint, but stop at the next HDoParseBreakpoint
-- 
GitLab