<s> import lldb <EOL> import json <EOL> class FBCommandArgument : <EOL> def __init__ ( self , short = '<STR_LIT>' , long = '<STR_LIT>' , arg = '<STR_LIT>' , type = '<STR_LIT>' , help = '<STR_LIT>' , default = '<STR_LIT>' , boolean = False ) : <EOL> self . shortName = short <EOL> self . longName = long <EOL> self . argName = arg <EOL> self . argType = type <EOL> self . help = help <EOL> self . default = default <EOL> self . boolean = boolean <EOL> class FBCommand : <EOL> def name ( self ) : <EOL> return None <EOL> def options ( self ) : <EOL> return [ ] <EOL> def args ( self ) : <EOL> return [ ] <EOL> def description ( self ) : <EOL> return '<STR_LIT>' <EOL> def run ( self , arguments , option ) : <EOL> pass <EOL> def evaluateExpressionValueWithLanguage ( expression , language , printErrors ) : <EOL> frame = lldb . debugger . GetSelectedTarget ( ) . GetProcess ( ) . GetSelectedThread ( ) . GetSelectedFrame ( ) <EOL> expr_options = lldb . SBExpressionOptions ( ) <EOL> expr_options . SetLanguage ( language ) <EOL> value = frame . EvaluateExpression ( expression , expr_options ) <EOL> if printErrors and value . GetError ( ) is not None and str ( value . GetError ( ) ) != '<STR_LIT:success>' : <EOL> print value . GetError ( ) <EOL> return value <EOL> def evaluateExpressionValueInFrameLanguage ( expression , printErrors = True ) : <EOL> frame = lldb . debugger . GetSelectedTarget ( ) . GetProcess ( ) . GetSelectedThread ( ) . GetSelectedFrame ( ) <EOL> language = frame . GetCompileUnit ( ) . GetLanguage ( ) <EOL> return evaluateExpressionValueWithLanguage ( expression , language , printErrors ) <EOL> def evaluateExpressionValue ( expression , printErrors = True ) : <EOL> return evaluateExpressionValueWithLanguage ( expression , lldb . eLanguageTypeObjC_plus_plus , printErrors ) <EOL> def evaluateIntegerExpression ( expression , printErrors = True ) : <EOL> output = evaluateExpression ( '<STR_LIT>' + expression + '<STR_LIT:)>' , printErrors ) . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if output . startswith ( '<STR_LIT>' ) : <EOL> output = output [ <NUM_LIT:2> : ] <EOL> elif output . startswith ( '<STR_LIT:\\>' ) : <EOL> output = output [ <NUM_LIT:1> : ] <EOL> return int ( output , <NUM_LIT:16> ) <EOL> def evaluateBooleanExpression ( expression , printErrors = True ) : <EOL> return ( int ( evaluateIntegerExpression ( '<STR_LIT>' + expression + '<STR_LIT:)>' , printErrors ) ) != <NUM_LIT:0> ) <EOL> def evaluateExpression ( expression , printErrors = True ) : <EOL> return evaluateExpressionValue ( expression , printErrors ) . GetValue ( ) <EOL> def evaluateObjectExpression ( expression , printErrors = True ) : <EOL> return evaluateExpression ( '<STR_LIT>' + expression + '<STR_LIT:)>' , printErrors ) <EOL> def evaluateCStringExpression ( expression , printErrors = True ) : <EOL> ret = evaluateExpression ( expression , printErrors ) <EOL> process = lldb . debugger . GetSelectedTarget ( ) . GetProcess ( ) <EOL> error = lldb . SBError ( ) <EOL> ret = process . ReadCStringFromMemory ( int ( ret , <NUM_LIT:16> ) , <NUM_LIT> , error ) <EOL> if error . Success ( ) : <EOL> return ret <EOL> else : <EOL> if printErrors : <EOL> print error <EOL> return None <EOL> RETURN_MACRO = """<STR_LIT>""" <EOL> def check_expr ( expr ) : <EOL> return expr . strip ( ) . split ( '<STR_LIT:;>' ) [ - <NUM_LIT:2> ] . find ( '<STR_LIT>' ) != - <NUM_LIT:1> <EOL> def evaluate ( expr ) : <EOL> if not check_expr ( expr ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> command = "<STR_LIT>" + RETURN_MACRO + '<STR_LIT:\n>' + expr + "<STR_LIT>" <EOL> ret = evaluateExpressionValue ( command , True ) <EOL> if not ret . GetError ( ) . Success ( ) : <EOL> print ret . GetError ( ) <EOL> return None <EOL> else : <EOL> process = lldb . debugger . GetSelectedTarget ( ) . GetProcess ( ) <EOL> error = lldb . SBError ( ) <EOL> ret = process . ReadCStringFromMemory ( int ( ret . GetValue ( ) , <NUM_LIT:16> ) , <NUM_LIT:2> ** <NUM_LIT:20> , error ) <EOL> if not error . Success ( ) : <EOL> print error <EOL> return None <EOL> else : <EOL> ret = json . loads ( ret ) <EOL> return ret [ '<STR_LIT>' ] </s>
