I'm using ios-deploy
to launch ios app automatically, it works fine but only a probem: it won't restart the app if it's already running.
I have studied its source code and learned it's using the lldb
command to launch the app. the lldb script is (part):
def run_command(debugger, command, result, internal_dict):
device_app = internal_dict['fruitstrap_device_app']
args = command.split('--',1)
error = lldb.SBError()
lldb.target.modules[0].SetPlatformFileSpec(lldb.SBFileSpec(device_app))
args_arr = []
if len(args) > 1:
args_arr = shlex.split(args[1])
args_arr = args_arr + shlex.split('{args}')
launchInfo = lldb.SBLaunchInfo(args_arr)
global listener
launchInfo.SetListener(listener)
#This env variable makes NSLog, CFLog and os_log messages get mirrored to stderr
#https://stackoverflow.com/a/39581193
launchInfo.SetEnvironmentEntries(['OS_ACTIVITY_DT_MODE=enable'], True)
lldb.target.Launch(launchInfo, error)
lockedstr = ': Locked'
if lockedstr in str(error):
print('\\nDevice Locked\\n')
os._exit(254)
else:
print(str(error))
the start command:
(lldb) command source -s 0 '/tmp/BB1ED2A3-3A3E-413A-935D-323D7A7533D1/fruitstrap-lldb-prep-cmds-6a050aabefc708cb7fc6024c4dd1743080d6e20b' Executing commands in '/tmp/BB1ED2A3-3A3E-413A-935D-323D7A7533D1/fruitstrap-lldb-prep-cmds-6a050aabefc708cb7fc6024c4dd1743080d6e20b'. (lldb) platform select remote-ios --sysroot '/Users/wellbye/Library/Developer/Xcode/iOS DeviceSupport/12.0 (16A366)/Symbols' Platform: remote-ios Connected: no SDK Path: "/Users/wellbye/Library/Developer/Xcode/iOS DeviceSupport/12.0 (16A366)/Symbols" (lldb) target create "/Users/wellbye/git-repo/j/mj3d/Product/build/ios/Build/Products/Release-iphoneos/mj.app" Current executable set to '/Users/wellbye/git-repo/j/mj3d/Product/build/ios/Build/Products/Release-iphoneos/mj.app' (arm64). (lldb) script fruitstrap_device_app="/private/var/containers/Bundle/Application/1FB0E7E3-6616-4789-8E6F-598C4F5AAC35/mj.app" (lldb) script fruitstrap_connect_url="connect://127.0.0.1:62276"
(lldb) target modules search-paths add /usr "/Users/wellbye/Library/Developer/Xcode/iOS DeviceSupport/12.0 (16A366)/Symbols/usr" /System "/Users/wellbye/Library/Developer/Xcode/iOS DeviceSupport/12.0 (16A366)/Symbols/System" "/private/var/containers/Bundle/Application/1FB0E7E3-6616-4789-8E6F-598C4F5AAC35" "/Users/wellbye/git-repo/j/mj3d/Product/build/ios/Build/Products/Release-iphoneos" "/var/containers/Bundle/Application/1FB0E7E3-6616-4789-8E6F-598C4F5AAC35" "/Users/wellbye/git-repo/j/mj3d/Product/build/ios/Build/Products/Release-iphoneos" /Developer "/Users/wellbye/Library/Developer/Xcode/iOS DeviceSupport/12.0 (16A366)/Symbols/Developer" (lldb) command script import "/tmp/BB1ED2A3-3A3E-413A-935D-323D7A7533D1/fruitstrap_6a050aabefc708cb7fc6024c4dd1743080d6e20b.py" (lldb) command script add -f fruitstrap_6a050aabefc708cb7fc6024c4dd1743080d6e20b.connect_command connect (lldb) command script add -s asynchronous -f fruitstrap_6a050aabefc708cb7fc6024c4dd1743080d6e20b.run_command run
(lldb) command script add -s asynchronous -f fruitstrap_6a050aabefc708cb7fc6024c4dd1743080d6e20b.autoexit_command autoexit (lldb) command script add -s asynchronous -f fruitstrap_6a050aabefc708cb7fc6024c4dd1743080d6e20b.safequit_command safequit (lldb) connect (lldb) run
I have searched the lldb's python api reference, but haven't seen anything (args or flags) I could use for my purpose.
so how could we let the lldb server know it should kill the exist process and start a new one?