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 1 commit
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
54 changes: 54 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,58 @@ def run(self, arguments, options):
fb.evaluateEffect('[[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)]')


def switchBreakpointState(expression,on):
ci = lldb.debugger.GetCommandInterpreter()
res = lldb.SBCommandReturnObject()
Copy link
Contributor

Choose a reason for hiding this comment

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

These two lines are no longer used.


ci.HandleCommand('br list',res)
listStr = res.GetOutput()

br_list = listStr.splitlines()
expression_pattern = re.compile(r'{}'.format(expression),re.I)
id_pattern = re.compile(r'^\s*([1-9]\d*)(\.\d+)?',re.I)
Copy link
Contributor

@kastiglione kastiglione Feb 26, 2018

Choose a reason for hiding this comment

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

What do you think about using the Python API, instead of parsing the output of breakpoint list?

For example, it would roughly look like:

for breakpoint in target.breakpoint_iter():
  for location in breakpoint:
    if pattern.search(location.GetAddress().symbol.name):
      location.SetEnabled(False)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  target = lldb.debugger.GetSelectedTarget()
  for breakpoint in target.breakpoint_iter():
    for location in breakpoint:
      if expression_pattern.search('{}'.format(location)):
        location.SetEnabled(on)

What do you think about using location?
They have some different.

location	2.1: where = SunLigth`__66+[SUNNetService httpAsyncPostWithDictionary:completionBlock:]_block_invoke + 1984 at SUNNetService.m:37, address = 0x0000000104514dfc, unresolved, hit count = 0  Options: disabled 
address		SunLigth`__66+[SUNNetService httpAsyncPostWithDictionary:completionBlock:]_block_invoke + 1984 at SUNNetService.m:37
symbol		id = {0x00006db1}, range = [0x00000001001e063c-0x00000001001e0ec8), mangled="__66+[SUNNetService httpAsyncPostWithDictionary:completionBlock:]_block_invoke"
name 		__66+[SUNNetService httpAsyncPostWithDictionary:completionBlock:]_block_invoke

So that,we can use benable disabled to switch all breakpoints to enable,and also as follow


#use `benable disabled` to switch all breakpoints to `enable`
benable disabled

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

* benable ***filename***
benable SUNNetService.m 

* benable ***module***
benable UIKit
benable SunLigth 

Copy link
Contributor

Choose a reason for hiding this comment

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

Enabling/disabling via filename and module definitely seem useful!

for br in br_list:
if expression_pattern.search(br) and id_pattern.search(br):
id = id_pattern.search(br).group()
if id:
print br
if on:
lldb.debugger.HandleCommand('br enable {}'.format(id))
else:
lldb.debugger.HandleCommand('br disable {}'.format(id))

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

Choose a reason for hiding this comment

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

lldb has an alias command named rb for regex breakpoint. I think it makes sense to call this rbenable and rbdisable, what do you think?


def description(self):
return "Enable a set of breakpoints for a relative expression"
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: should be "regular", not "relative"


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 relative expression"

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