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 delay command #179

Merged
merged 1 commit into from
Dec 17, 2016
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
37 changes: 37 additions & 0 deletions commands/FBDelay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/python
from threading import Timer
import fblldbbase as fb
import fblldbobjcruntimehelpers as runtimeHelpers
import lldb
import string


def lldbcommands():
return [
FBDelay()
]

class FBDelay(fb.FBCommand):
def name(self):
return 'zzz'

def description(self):
return 'Executes specified lldb command after delay.'

def args(self):
return [
fb.FBCommandArgument(arg='delay in seconds', type='float', help='time to wait before executing specified command'),
fb.FBCommandArgument(arg='lldb command', type='string', help='another lldb command to execute after specified delay', default='process interrupt')
]

def run(self, arguments, options):
lldb.debugger.SetAsync(True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this code save the current value of async and set it back after?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems like I didn't understand the meaning of SetAsync().
From documentation I thought that it detaches execution of the following command (continue in this case) allowing function to be evaluated even after we continue the execution.
Did I misunderstand it? Or maybe I'm just missing the point of your comment

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's right, but I didn't think its affect was for only one command, I'm thinking it stays in async mode until something calls SetAsync(False). If that is the case this command should change it back to the original value after it's done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually don't see it being used like that in other cases we either enable reset async conditionally or don't do it at all in FBFindCommands.py

I don't mind resetting if you are certain we should do it.
Sadly, no documentation, and I don't feel like lldb spelunking right now 😳

Copy link
Contributor

Choose a reason for hiding this comment

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

I spelunked last night, and the main thing is that the async setting decides whether Resume() or ResumeSynchronous() is called. I didn't write any code though which would really answer the question. I don't know if those other cases really confirm it either way.

Since it must work as is, we can leave this for another day 👍

lldb.debugger.HandleCommand('process continue')
delay = float(arguments[0])
command = str(arguments[1])
t = Timer(delay, lambda: self.runDelayed(command))
t.start()

def runDelayed(self, command):
lldb.debugger.HandleCommand('process interrupt')
lldb.debugger.HandleCommand(command)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does lldb silently accept an empty command? I ask because the description says zzz 3 "process interrupt" is equivalent to just zzz 3, so I'm presuming this means lldb doesn't error on empty commands.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually set a default value on the command option, it probably got lost because I didn't break it at certain line length (is there a style guide you'd like to follow here?)
The default parameter is , default='process interrupt'
Should I add a check for an empty command and replace it with default value?

Copy link
Contributor

Choose a reason for hiding this comment

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

😎 I did overlook the default.

Given the declared default, don't feel strongly either way about handling an empty command.