Skip to content

Commit 5322de7

Browse files
authored
add ability to execute custom scripts and commands (#472)
1 parent ee3aec1 commit 5322de7

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/ios-deploy/ios-deploy.m

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
autoexit\n\
6262
";
6363

64+
NSMutableString * custom_commands = nil;
65+
6466
/*
6567
* Some things do not seem to work when using the normal commands like process connect/launch, so we invoke them
6668
* through the python interface. Also, Launch () doesn't seem to work when ran from init_module (), so we add
@@ -106,6 +108,7 @@
106108
char *args = NULL;
107109
char *envs = NULL;
108110
char *list_root = NULL;
111+
const char * custom_script_path = NULL;
109112
int _timeout = 0;
110113
int _detectDeadlockTimeout = 0;
111114
bool _json_output = false;
@@ -961,13 +964,36 @@ void write_lldb_prep_cmds(AMDeviceRef device, CFURLRef disk_app_url) {
961964
else
962965
extra_cmds = lldb_prep_interactive_cmds;
963966
fwrite(extra_cmds, strlen(extra_cmds), 1, out);
967+
if (custom_commands != nil)
968+
{
969+
const char * cmds = [custom_commands UTF8String];
970+
fwrite(cmds, 1, strlen(cmds), out);
971+
}
964972
fclose(out);
965973

966974

967975
out = fopen([python_file_path UTF8String], "w");
968976
CFDataRef pmodule_data = CFStringCreateExternalRepresentation(NULL, pmodule, kCFStringEncodingUTF8, 0);
969977
fwrite(CFDataGetBytePtr(pmodule_data), CFDataGetLength(pmodule_data), 1, out);
970978
CFRelease(pmodule_data);
979+
980+
if (custom_script_path)
981+
{
982+
FILE * fh = fopen(custom_script_path, "r");
983+
if (fh == NULL)
984+
{
985+
on_error(@"Failed to open %s", custom_script_path);
986+
}
987+
fwrite("\n", 1, 1, out);
988+
char buffer[0x1000];
989+
size_t bytesRead;
990+
while ((bytesRead = fread(buffer, 1, sizeof(buffer), fh)) > 0)
991+
{
992+
fwrite(buffer, 1, bytesRead, out);
993+
}
994+
fclose(fh);
995+
}
996+
971997
fclose(out);
972998

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

@@ -2296,6 +2324,8 @@ int main(int argc, char *argv[]) {
22962324
{ "app_deltas", required_argument, NULL, 'A'},
22972325
{ "file_system", no_argument, NULL, 'f'},
22982326
{ "non-recursively", no_argument, NULL, 'F'},
2327+
{ "custom-script", required_argument, NULL, 1001},
2328+
{ "custom-command", required_argument, NULL, 1002},
22992329
{ NULL, 0, NULL, 0 },
23002330
};
23012331
int ch;
@@ -2436,6 +2466,16 @@ int main(int argc, char *argv[]) {
24362466
case 'F':
24372467
non_recursively = true;
24382468
break;
2469+
case 1001:
2470+
custom_script_path = optarg;
2471+
break;
2472+
case 1002:
2473+
if (custom_commands == nil)
2474+
{
2475+
custom_commands = [[NSMutableString alloc] init];
2476+
}
2477+
[custom_commands appendFormat:@"%s\n", optarg];
2478+
break;
24392479
default:
24402480
usage(argv[0]);
24412481
return exitcode_error;

0 commit comments

Comments
 (0)