|
61 | 61 | autoexit\n\ |
62 | 62 | "; |
63 | 63 |
|
| 64 | +NSMutableString * custom_commands = nil; |
| 65 | + |
64 | 66 | /* |
65 | 67 | * Some things do not seem to work when using the normal commands like process connect/launch, so we invoke them |
66 | 68 | * through the python interface. Also, Launch () doesn't seem to work when ran from init_module (), so we add |
|
106 | 108 | char *args = NULL; |
107 | 109 | char *envs = NULL; |
108 | 110 | char *list_root = NULL; |
| 111 | +const char * custom_script_path = NULL; |
109 | 112 | int _timeout = 0; |
110 | 113 | int _detectDeadlockTimeout = 0; |
111 | 114 | bool _json_output = false; |
@@ -961,13 +964,36 @@ void write_lldb_prep_cmds(AMDeviceRef device, CFURLRef disk_app_url) { |
961 | 964 | else |
962 | 965 | extra_cmds = lldb_prep_interactive_cmds; |
963 | 966 | 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 | + } |
964 | 972 | fclose(out); |
965 | 973 |
|
966 | 974 |
|
967 | 975 | out = fopen([python_file_path UTF8String], "w"); |
968 | 976 | CFDataRef pmodule_data = CFStringCreateExternalRepresentation(NULL, pmodule, kCFStringEncodingUTF8, 0); |
969 | 977 | fwrite(CFDataGetBytePtr(pmodule_data), CFDataGetLength(pmodule_data), 1, out); |
970 | 978 | 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 | + |
971 | 997 | fclose(out); |
972 | 998 |
|
973 | 999 | CFRelease(cmds); |
@@ -2240,7 +2266,9 @@ void usage(const char* app) { |
2240 | 2266 | @" --detect_deadlocks <sec> start printing backtraces for all threads periodically after specific amount of seconds\n" |
2241 | 2267 | @" -f, --file_system specify file system for mkdir / list / upload / download / rm\n" |
2242 | 2268 | @" -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", |
2244 | 2272 | [NSString stringWithUTF8String:app]); |
2245 | 2273 | } |
2246 | 2274 |
|
@@ -2296,6 +2324,8 @@ int main(int argc, char *argv[]) { |
2296 | 2324 | { "app_deltas", required_argument, NULL, 'A'}, |
2297 | 2325 | { "file_system", no_argument, NULL, 'f'}, |
2298 | 2326 | { "non-recursively", no_argument, NULL, 'F'}, |
| 2327 | + { "custom-script", required_argument, NULL, 1001}, |
| 2328 | + { "custom-command", required_argument, NULL, 1002}, |
2299 | 2329 | { NULL, 0, NULL, 0 }, |
2300 | 2330 | }; |
2301 | 2331 | int ch; |
@@ -2436,6 +2466,16 @@ int main(int argc, char *argv[]) { |
2436 | 2466 | case 'F': |
2437 | 2467 | non_recursively = true; |
2438 | 2468 | 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; |
2439 | 2479 | default: |
2440 | 2480 | usage(argv[0]); |
2441 | 2481 | return exitcode_error; |
|
0 commit comments