From fc1d9c4fbf4eab6f5aa74065635c1ae40851b069 Mon Sep 17 00:00:00 2001 From: pompolic <pompolic@special-circumstanc.es> Date: Mon, 8 May 2023 20:45:59 +0200 Subject: [PATCH] Disable profiling on AST commands --- gdb-port/commands.py | 56 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/gdb-port/commands.py b/gdb-port/commands.py index 1c7702a..b35000d 100644 --- a/gdb-port/commands.py +++ b/gdb-port/commands.py @@ -255,24 +255,60 @@ 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 # HDoParseRetBreakpoint sets hammer_step_counter to 1 after capturing the AST subtree, so this will stop at the first h_do_parse invocation afterwards if gdb.selected_inferior().pid > 0: gdb.execute("continue") + top_level_parse.show_input_map_after_apply = showmap_old 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() + +class HammerParseApplyAndShowAST(FlowControlWithPrint): + def __init__(self): + super(HammerParseApplyAndShowAST, self).__init__("hammer-parse-apply-and-show-ast", gdb.COMMAND_OBSCURE) + 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 + 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 + + # HDoParseRetBreakpoint sets hammer_step_counter to 1 after capturing the AST subtree, so this will stop at the first h_do_parse invocation afterwards + if gdb.selected_inferior().pid > 0: + gdb.execute("continue") + + top_level_parse.show_input_map_after_apply = showmap_old + 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 + +HammerParseApplyAndShowAST() -- GitLab