1*5c2921b0SApple OSS Distributions# Feed user stacks to ios/speedtracer 2*5c2921b0SApple OSS Distributions 3*5c2921b0SApple OSS Distributionsdef plugin_init(kernel_target, config, lldb_obj, isConnected): 4*5c2921b0SApple OSS Distributions """ initialize the common data as required by plugin """ 5*5c2921b0SApple OSS Distributions return None 6*5c2921b0SApple OSS Distributions 7*5c2921b0SApple OSS Distributionsdef plugin_execute(command_name, result_output): 8*5c2921b0SApple OSS Distributions """ The xnu framework will call this function with output of a command. 9*5c2921b0SApple OSS Distributions The options for returning are as follows 10*5c2921b0SApple OSS Distributions returns: (status, outstr, further_cmds) 11*5c2921b0SApple OSS Distributions status: Boolean - specifying whether plugin execution succeeded(True) or failed. If failed then xnu will stop doing any further work with this command. 12*5c2921b0SApple OSS Distributions outstr: str - string output for user to be printed at the prompt 13*5c2921b0SApple OSS Distributions further_cmds: [] of str - this holds set of commands to execute at the lldb prompt. Empty array if nothing is required. 14*5c2921b0SApple OSS Distributions """ 15*5c2921b0SApple OSS Distributions import subprocess,os 16*5c2921b0SApple OSS Distributions status = True 17*5c2921b0SApple OSS Distributions outstr = '' 18*5c2921b0SApple OSS Distributions further_cmds = [] 19*5c2921b0SApple OSS Distributions 20*5c2921b0SApple OSS Distributions if command_name != 'showtaskuserstacks' : 21*5c2921b0SApple OSS Distributions status = False 22*5c2921b0SApple OSS Distributions else: 23*5c2921b0SApple OSS Distributions ios_process = subprocess.Popen([os.path.join(os.path.dirname(os.path.abspath(__file__)), "iosspeedtracer.sh")], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 24*5c2921b0SApple OSS Distributions 25*5c2921b0SApple OSS Distributions outstr += ios_process.communicate(input=result_output)[0] 26*5c2921b0SApple OSS Distributions 27*5c2921b0SApple OSS Distributions return (status, outstr, further_cmds) 28*5c2921b0SApple OSS Distributions 29*5c2921b0SApple OSS Distributionsdef plugin_cleanup(): 30*5c2921b0SApple OSS Distributions """ A cleanup call from xnu which is a signal to wrap up any open file descriptors etc. """ 31*5c2921b0SApple OSS Distributions return None 32*5c2921b0SApple OSS Distributions 33*5c2921b0SApple OSS Distributions 34