Skip to content

Commit

Permalink
Merge pull request #232 from facebook/auto-import
Browse files Browse the repository at this point in the history
Import UIKit to retry expression evaluation
  • Loading branch information
kastiglione committed Mar 6, 2018
2 parents 9438fa2 + 3c19024 commit 6a3e4fb
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions fblldbbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ def lex(self, commandLine):
def run(self, arguments, option):
pass

def isSuccess(error):
# When evaluating a `void` expression, the returned value will indicate an
# error. This error is named: kNoResult. This error value does *not* mean
# there was a problem. This logic follows what the builtin `expression`
# command does. See: https://git.io/vwpjl (UserExpression.h)
kNoResult = 0x1001
return error.success or error.value == kNoResult

def importModule(frame, module):
options = lldb.SBExpressionOptions()
options.SetLanguage(lldb.eLanguageTypeObjC)
value = frame.EvaluateExpression('@import ' + module, options)
return isSuccess(value.error)

# evaluates expression in Objective-C++ context, so it will work even for
# Swift projects
def evaluateExpressionValue(expression, printErrors=True, language=lldb.eLanguageTypeObjC_plus_plus):
Expand All @@ -62,13 +76,15 @@ def evaluateExpressionValue(expression, printErrors=True, language=lldb.eLanguag
value = frame.EvaluateExpression(expression, options)
error = value.GetError()

if printErrors and error.Fail():
# When evaluating a `void` expression, the returned value has an error code named kNoResult.
# This is not an error that should be printed. This follows what the built in `expression` command does.
# See: https://git.io/vwpjl (UserExpression.h)
kNoResult = 0x1001
if error.GetError() != kNoResult:
print error
# Retry if the error could be resolved by first importing UIKit.
if (error.type == lldb.eErrorTypeExpression and
error.value == lldb.eExpressionParseError and
importModule(frame, 'UIKit')):
value = frame.EvaluateExpression(expression, options)
error = value.GetError()

if printErrors and not isSuccess(error):
print error

return value

Expand Down

0 comments on commit 6a3e4fb

Please sign in to comment.