Created
February 21, 2016 23:27
-
-
Save parallaxe/5ae1583125e751ec7f5b to your computer and use it in GitHub Desktop.
Struggling with debugging a recursive function? You've set a breakpoint that should only break on a certain recursion-depth? This command is meant to rescue. Set it as action to a breakpoint with the depth you want the breakpoint to stop as argument, like continue_when_recursion_depth_not_equal_to 2 to stop on a recursion-depth of 2.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lldb | |
import commands | |
import optparse | |
import shlex | |
def create_continue_when_recursion_depth_not_equal_to_options(): | |
usage = "usage: %prog <depth as stop-condition>" | |
description='''Struggling with debugging a recursive function? You've set a breakpoint that should only | |
break on a certain recursion-depth? This command is meant to rescue. Set it as action to a breakpoint | |
with the depth you want the breakpoint to stop as argument, like | |
continue_when_recursion_depth_not_equal_to 2 | |
to stop on a recursion-depth of 2. | |
''' | |
parser = optparse.OptionParser(description=description, prog='create_continue_when_recursion_depth_not_equal_to_options',usage=usage) | |
return parser | |
def continue_when_recursion_depth_not_equal_to(debugger, command, result, internal_dict): | |
command_args = shlex.split(command) | |
thread = debugger.GetSelectedTarget().GetProcess().GetSelectedThread() | |
start_num_frames = thread.GetNumFrames() | |
if start_num_frames == 0: | |
return | |
current_frame = thread.GetSelectedFrame() | |
current_function = current_frame.GetFunction() | |
if not current_function: | |
print >>result, "only works in a function-context" | |
return | |
# get the recursion-depth of the current function | |
depth = 0 | |
for i in range(0, start_num_frames): | |
frame = thread.GetFrameAtIndex(i) | |
function = frame.GetFunction() | |
if function == current_function: | |
depth += 1 | |
if depth != int(command_args[0]): | |
debugger.SetAsync(True) # needed for whatever reason for Xcode - else it will crash | |
debugger.HandleCommand('continue') | |
def __lldb_init_module (debugger, dict): | |
debugger.HandleCommand('command script add -f continue_when_recursion_depth_not_equal_to.continue_when_recursion_depth_not_equal_to continue_when_recursion_depth_not_equal_to') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment