Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enable&disable breakpoints by rg-expression. #230

Merged
merged 7 commits into from
Mar 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions commands/FBDebugCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def lldbcommands():
FBMethodBreakpointCommand(),
FBMemoryWarningCommand(),
FBFindInstancesCommand(),
FBMethodBreakpointEnableCommand(),
FBMethodBreakpointDisableCommand(),
]

class FBWatchInstanceVariableCommand(fb.FBCommand):
Expand Down Expand Up @@ -189,6 +191,83 @@ def run(self, arguments, options):
fb.evaluateEffect('[[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)]')


def switchBreakpointState(expression,on):

expression_pattern = re.compile(r'{}'.format(expression),re.I)

target = lldb.debugger.GetSelectedTarget()
for breakpoint in target.breakpoint_iter():
if breakpoint.IsEnabled() != on and (expression_pattern.search(str(breakpoint))):
print str(breakpoint)
breakpoint.SetEnabled(on)
Copy link
Contributor

@kastiglione kastiglione Mar 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you find this was necessary in your experience? I'm curious what are some example cases where these commands need to apply to the breakpoint itself instead of working only on the locations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use br disable 41 to off 41,and benable 41 only enable locations's state.
The 41 41.1 will be ignore.

for location in breakpoint:
if location.IsEnabled() != on and (expression_pattern.search(str(location)) or expression == hex(location.GetAddress()) ):
print str(location)
location.SetEnabled(on)

class FBMethodBreakpointEnableCommand(fb.FBCommand):
def name(self):
return 'benable'

def description(self):
return """
Enable a set of breakpoints for a regular expression

Examples:

* benable ***address***
benable 0x0000000104514dfc
benable 0x183e23564

#use `benable *filename*` to switch all breakpoints in this file to `enable`
benable SUNNetService.m

#use `benable ***module(AppName)***` to switch all breakpoints in this module to `enable`
benable UIKit
benable Foundation

"""

def args(self):
return [
fb.FBCommandArgument(arg='expression', type='string', help='Expression to enable breakpoint'),
]

def run(self, arguments, options):
expression = arguments[0]
switchBreakpointState(expression,True)

class FBMethodBreakpointDisableCommand(fb.FBCommand):
def name(self):
return 'bdisable'

def description(self):
return """
Disable a set of breakpoints for a regular expression

Examples:

* bdisable ***address***
bdisable 0x0000000104514dfc
bdisable 0x183e23564

#use `bdisable *filename*` to switch all breakpoints in this file to `disable`
bdisable SUNNetService.m

#use `bdisable ***module(AppName)***` to switch all breakpoints in this module to `disable`
bdisable UIKit
bdisable Foundation

"""
def args(self):
return [
fb.FBCommandArgument(arg='expression', type='string', help='Expression to disable breakpoint'),
]

def run(self, arguments, options):
expression = arguments[0]
switchBreakpointState(expression,False)

class FBFindInstancesCommand(fb.FBCommand):
def name(self):
return 'findinstances'
Expand Down