diff --git a/gdb-port/parser-name-instrumentation-gdb.py b/gdb-port/parser-name-instrumentation-gdb.py index 9fb59610077acdc530e788bbe3045a8e2abb7500..782b4da5ccd414377c36b43fa8b0a5c01fa3373b 100644 --- a/gdb-port/parser-name-instrumentation-gdb.py +++ b/gdb-port/parser-name-instrumentation-gdb.py @@ -249,10 +249,13 @@ class HDoParseBreakpoint(gdb.Breakpoint): # Check if we need to stop after a number of steps step_counter = gdb.convenience_variable("hammer_step_counter") - # TODO: check first or decrement first? step_counter needs to be checked for NULL anyway if step_counter is not None and step_counter > 0: step_counter -= 1 - retval = True + if step_counter == 0: + gdb.set_convenience_variable("hammer_step_counter", None) # unset step counter + retval = True + else: + gdb.set_convenience_variable("hammer_step_counter", step_counter) #else: # retval remains False @@ -326,13 +329,28 @@ class HammerParserBacktrace(gdb.Command): def invoke(self, arg, from_tty): parserstack = top_level_parse.peek_parserstack().p_stack - depth = min(len(parserstack), 10) # TODO: configurable max stack depth + args = gdb.string_to_argv(arg) + # TODO: remove default 10, len(parserstack) should be default + if len(args) < 1: + maxsize = len(parserstack) + else: + try: + maxsize = int(args[0]) + if maxsize < 1: + raise ValueError + except ValueError: + maxsize = len(parserstacK) + print("Argument must be a positive integer") + + depth = min(len(parserstack), maxsize) if depth > 0: # if stack not empty # unsure what the idiomatic python is for handling negative indices starting with -1, # but this addition is to avoid off-by-one errors index = -(depth+1) for p in parserstack[-1:index:-1]: print("[" + str(hex(p.address)) + "] " + p.name) + if depth < len(parserstack): + print("[...]") HammerParserBacktrace() diff --git a/gdb-port/utility-commands.py b/gdb-port/utility-commands.py index df25c1077c5bb5c89fbbaf69500c8534c608f6d6..b94e3798cad31149170d1e370ea4523faeef5f69 100644 --- a/gdb-port/utility-commands.py +++ b/gdb-port/utility-commands.py @@ -28,6 +28,7 @@ class HammerParseStep(gdb.Command): else: steps = 1 + print("Steps: " + str(int(steps))) gdb.set_convenience_variable("hammer_step_counter", int(steps)) # Counting the stops is the responsibility of HDoParseBreakpoint # On each breakpoint hit, something like this is executed in HDoParseBreakpoint.stop():