Skip to content

Commit

Permalink
add ability to execute custom scripts and commands (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukalnins authored Sep 1, 2020
1 parent ee3aec1 commit 5322de7
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion src/ios-deploy/ios-deploy.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
autoexit\n\
";

NSMutableString * custom_commands = nil;

/*
* Some things do not seem to work when using the normal commands like process connect/launch, so we invoke them
* through the python interface. Also, Launch () doesn't seem to work when ran from init_module (), so we add
Expand Down Expand Up @@ -106,6 +108,7 @@
char *args = NULL;
char *envs = NULL;
char *list_root = NULL;
const char * custom_script_path = NULL;
int _timeout = 0;
int _detectDeadlockTimeout = 0;
bool _json_output = false;
Expand Down Expand Up @@ -961,13 +964,36 @@ void write_lldb_prep_cmds(AMDeviceRef device, CFURLRef disk_app_url) {
else
extra_cmds = lldb_prep_interactive_cmds;
fwrite(extra_cmds, strlen(extra_cmds), 1, out);
if (custom_commands != nil)
{
const char * cmds = [custom_commands UTF8String];
fwrite(cmds, 1, strlen(cmds), out);
}
fclose(out);


out = fopen([python_file_path UTF8String], "w");
CFDataRef pmodule_data = CFStringCreateExternalRepresentation(NULL, pmodule, kCFStringEncodingUTF8, 0);
fwrite(CFDataGetBytePtr(pmodule_data), CFDataGetLength(pmodule_data), 1, out);
CFRelease(pmodule_data);

if (custom_script_path)
{
FILE * fh = fopen(custom_script_path, "r");
if (fh == NULL)
{
on_error(@"Failed to open %s", custom_script_path);
}
fwrite("\n", 1, 1, out);
char buffer[0x1000];
size_t bytesRead;
while ((bytesRead = fread(buffer, 1, sizeof(buffer), fh)) > 0)
{
fwrite(buffer, 1, bytesRead, out);
}
fclose(fh);
}

fclose(out);

CFRelease(cmds);
Expand Down Expand Up @@ -2240,7 +2266,9 @@ void usage(const char* app) {
@" --detect_deadlocks <sec> start printing backtraces for all threads periodically after specific amount of seconds\n"
@" -f, --file_system specify file system for mkdir / list / upload / download / rm\n"
@" -F, --non-recursively specify non-recursively walk directory\n"
@" -j, --json format output as JSON\n",
@" -j, --json format output as JSON\n"
@" --custom-script <script> path to custom python script to execute in lldb\n"
@" --custom-command <command> specify additional lldb commands to execute\n",
[NSString stringWithUTF8String:app]);
}

Expand Down Expand Up @@ -2296,6 +2324,8 @@ int main(int argc, char *argv[]) {
{ "app_deltas", required_argument, NULL, 'A'},
{ "file_system", no_argument, NULL, 'f'},
{ "non-recursively", no_argument, NULL, 'F'},
{ "custom-script", required_argument, NULL, 1001},
{ "custom-command", required_argument, NULL, 1002},
{ NULL, 0, NULL, 0 },
};
int ch;
Expand Down Expand Up @@ -2436,6 +2466,16 @@ int main(int argc, char *argv[]) {
case 'F':
non_recursively = true;
break;
case 1001:
custom_script_path = optarg;
break;
case 1002:
if (custom_commands == nil)
{
custom_commands = [[NSMutableString alloc] init];
}
[custom_commands appendFormat:@"%s\n", optarg];
break;
default:
usage(argv[0]);
return exitcode_error;
Expand Down

0 comments on commit 5322de7

Please sign in to comment.