Skip to content

Commit

Permalink
Externalized LLDB_FRUITSTRAP_MODULE python commands into external fil…
Browse files Browse the repository at this point in the history
…e (source in src/scripts/lldb.py)
  • Loading branch information
shazron committed Jan 6, 2016
1 parent ca29173 commit 3fef0a5
Show file tree
Hide file tree
Showing 4 changed files with 461 additions and 88 deletions.
30 changes: 30 additions & 0 deletions ios-deploy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

/* Begin PBXFileReference section */
7E1C00CC1C3C93AF00D686B5 /* version.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = version.h; path = src/version.h; sourceTree = SOURCE_ROOT; };
7E1C00CF1C3C9ABB00D686B5 /* lldb.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; name = lldb.py; path = src/scripts/lldb.py; sourceTree = SOURCE_ROOT; };
7E1C00D11C3C9CB000D686B5 /* lldb.py.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = lldb.py.h; path = src/lldb.py.h; sourceTree = SOURCE_ROOT; };
7E70898E1B587BF3004D23AA /* ios-deploy */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "ios-deploy"; sourceTree = BUILT_PRODUCTS_DIR; };
7E7089991B587DE4004D23AA /* ios-deploy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "ios-deploy.c"; path = "src/ios-deploy.c"; sourceTree = SOURCE_ROOT; };
7E70899A1B587DE4004D23AA /* errors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = errors.h; path = src/errors.h; sourceTree = SOURCE_ROOT; };
Expand All @@ -47,6 +49,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
7E1C00CE1C3C9A7700D686B5 /* scripts */ = {
isa = PBXGroup;
children = (
7E1C00CF1C3C9ABB00D686B5 /* lldb.py */,
);
name = scripts;
sourceTree = "<group>";
};
7E7089851B587BF3004D23AA = {
isa = PBXGroup;
children = (
Expand All @@ -67,6 +77,8 @@
7E7089901B587BF3004D23AA /* ios-deploy */ = {
isa = PBXGroup;
children = (
7E1C00CE1C3C9A7700D686B5 /* scripts */,
7E1C00D11C3C9CB000D686B5 /* lldb.py.h */,
7E1C00CC1C3C93AF00D686B5 /* version.h */,
7E7089991B587DE4004D23AA /* ios-deploy.c */,
7E70899A1B587DE4004D23AA /* errors.h */,
Expand All @@ -91,6 +103,7 @@
isa = PBXNativeTarget;
buildConfigurationList = 7E7089951B587BF3004D23AA /* Build configuration list for PBXNativeTarget "ios-deploy" */;
buildPhases = (
7E1C00D01C3C9C0700D686B5 /* Run Script */,
7E70898A1B587BF3004D23AA /* Sources */,
7E70898B1B587BF3004D23AA /* Frameworks */,
7E70898C1B587BF3004D23AA /* CopyFiles */,
Expand Down Expand Up @@ -136,6 +149,23 @@
};
/* End PBXProject section */

/* Begin PBXShellScriptBuildPhase section */
7E1C00D01C3C9C0700D686B5 /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Run Script";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "echo \"\\\"# AUTO-GENERATED - DO NOT MODIFY\\n\\\"\" > src/lldb.h\nawk '{ print \"\\\"\"$0\"\\\\n\\\"\"}' src/scripts/lldb.py >> src/lldb.py.h\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
7E70898A1B587BF3004D23AA /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
93 changes: 5 additions & 88 deletions src/ios-deploy.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,93 +60,10 @@ const char* lldb_prep_noninteractive_cmds = "\
* through the python interface. Also, Launch () doesn't seem to work when ran from init_module (), so we add
* a command which can be used by the user to run it.
*/
#define LLDB_FRUITSTRAP_MODULE CFSTR("\
import lldb\n\
import os\n\
import sys\n\
import shlex\n\
\n\
def connect_command(debugger, command, result, internal_dict):\n\
# These two are passed in by the script which loads us\n\
connect_url = internal_dict['fruitstrap_connect_url']\n\
error = lldb.SBError()\n\
\n\
process = lldb.target.ConnectRemote(lldb.target.GetDebugger().GetListener(), connect_url, None, error)\n\
\n\
# Wait for connection to succeed\n\
listener = lldb.target.GetDebugger().GetListener()\n\
listener.StartListeningForEvents(process.GetBroadcaster(), lldb.SBProcess.eBroadcastBitStateChanged)\n\
events = []\n\
state = (process.GetState() or lldb.eStateInvalid)\n\
while state != lldb.eStateConnected:\n\
event = lldb.SBEvent()\n\
if listener.WaitForEvent(1, event):\n\
state = process.GetStateFromEvent(event)\n\
events.append(event)\n\
else:\n\
state = lldb.eStateInvalid\n\
\n\
# Add events back to queue, otherwise lldb freezes\n\
for event in events:\n\
listener.AddEvent(event)\n\
\n\
def run_command(debugger, command, result, internal_dict):\n\
device_app = internal_dict['fruitstrap_device_app']\n\
args = command.split('--',1)\n\
error = lldb.SBError()\n\
lldb.target.modules[0].SetPlatformFileSpec(lldb.SBFileSpec(device_app))\n\
lldb.target.Launch(lldb.SBLaunchInfo(shlex.split(args[1] and args[1] or '{args}')), error)\n\
lockedstr = ': Locked'\n\
if lockedstr in str(error):\n\
print('\\nDevice Locked\\n')\n\
os._exit(254)\n\
else:\n\
print(str(error))\n\
\n\
def safequit_command(debugger, command, result, internal_dict):\n\
process = lldb.target.process\n\
listener = debugger.GetListener()\n\
listener.StartListeningForEvents(process.GetBroadcaster(), lldb.SBProcess.eBroadcastBitStateChanged | lldb.SBProcess.eBroadcastBitSTDOUT | lldb.SBProcess.eBroadcastBitSTDERR)\n\
event = lldb.SBEvent()\n\
while True:\n\
if listener.WaitForEvent(1, event) and lldb.SBProcess.EventIsProcessEvent(event):\n\
state = lldb.SBProcess.GetStateFromEvent(event)\n\
else:\n\
state = process.GetState()\n\
\n\
if state == lldb.eStateRunning:\n\
process.Detach()\n\
os._exit(0)\n\
elif state > lldb.eStateRunning:\n\
os._exit(state)\n\
\n\
def autoexit_command(debugger, command, result, internal_dict):\n\
process = lldb.target.process\n\
listener = debugger.GetListener()\n\
listener.StartListeningForEvents(process.GetBroadcaster(), lldb.SBProcess.eBroadcastBitStateChanged | lldb.SBProcess.eBroadcastBitSTDOUT | lldb.SBProcess.eBroadcastBitSTDERR)\n\
event = lldb.SBEvent()\n\
while True:\n\
if listener.WaitForEvent(1, event) and lldb.SBProcess.EventIsProcessEvent(event):\n\
state = lldb.SBProcess.GetStateFromEvent(event)\n\
else:\n\
state = process.GetState()\n\
\n\
if state == lldb.eStateExited:\n\
os._exit(process.GetExitStatus())\n\
elif state == lldb.eStateStopped:\n\
debugger.HandleCommand('bt')\n\
os._exit({exitcode_app_crash})\n\
\n\
stdout = process.GetSTDOUT(1024)\n\
while stdout:\n\
sys.stdout.write(stdout)\n\
stdout = process.GetSTDOUT(1024)\n\
\n\
stderr = process.GetSTDERR(1024)\n\
while stderr:\n\
sys.stdout.write(stderr)\n\
stderr = process.GetSTDERR(1024)\n\
")
NSString* LLDB_FRUITSTRAP_MODULE = @
#include "lldb.py.h"
;


typedef struct am_device * AMDeviceRef;
mach_error_t AMDeviceSecureStartService(struct am_device *device, CFStringRef service_name, unsigned int *unknown, service_conn_t *handle);
Expand Down Expand Up @@ -753,7 +670,7 @@ void write_lldb_prep_cmds(AMDeviceRef device, CFURLRef disk_app_url) {
CFStringFindAndReplace(cmds, CFSTR("{ds_path}"), ds_path, range, 0);
range.length = CFStringGetLength(cmds);

CFMutableStringRef pmodule = CFStringCreateMutableCopy(NULL, 0, LLDB_FRUITSTRAP_MODULE);
CFMutableStringRef pmodule = CFStringCreateMutableCopy(NULL, 0, (CFStringRef)LLDB_FRUITSTRAP_MODULE);

CFRange rangeLLDB = { 0, CFStringGetLength(pmodule) };
CFStringRef exitcode_app_crash_str = CFStringCreateWithFormat(NULL, NULL, CFSTR("%d"), exitcode_app_crash);
Expand Down
Loading

0 comments on commit 3fef0a5

Please sign in to comment.