diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/idevicedebug.c | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/tools/idevicedebug.c b/tools/idevicedebug.c index 6c2f5cf..71da0bf 100644 --- a/tools/idevicedebug.c +++ b/tools/idevicedebug.c | |||
| @@ -42,6 +42,10 @@ | |||
| 42 | #include <plist/plist.h> | 42 | #include <plist/plist.h> |
| 43 | #include "common/debug.h" | 43 | #include "common/debug.h" |
| 44 | 44 | ||
| 45 | static int debug_level = 0; | ||
| 46 | |||
| 47 | #define log_debug(...) if (debug_level > 0) { printf(__VA_ARGS__); fputc('\n', stdout); } | ||
| 48 | |||
| 45 | enum cmd_mode { | 49 | enum cmd_mode { |
| 46 | CMD_NONE = 0, | 50 | CMD_NONE = 0, |
| 47 | CMD_RUN | 51 | CMD_RUN |
| @@ -93,7 +97,7 @@ static instproxy_error_t instproxy_client_get_object_by_key_from_info_directiona | |||
| 93 | if (object) { | 97 | if (object) { |
| 94 | *node = plist_copy(object); | 98 | *node = plist_copy(object); |
| 95 | } else { | 99 | } else { |
| 96 | debug_info("key %s not found", key); | 100 | log_debug("key %s not found", key); |
| 97 | return INSTPROXY_E_OP_FAILED; | 101 | return INSTPROXY_E_OP_FAILED; |
| 98 | } | 102 | } |
| 99 | 103 | ||
| @@ -128,12 +132,12 @@ static debugserver_error_t debugserver_client_handle_response(debugserver_client | |||
| 128 | /* send reply */ | 132 | /* send reply */ |
| 129 | debugserver_command_new("OK", 0, NULL, &command); | 133 | debugserver_command_new("OK", 0, NULL, &command); |
| 130 | dres = debugserver_client_send_command(client, command, response, NULL); | 134 | dres = debugserver_client_send_command(client, command, response, NULL); |
| 131 | debug_info("result: %d", dres); | 135 | log_debug("result: %d", dres); |
| 132 | debugserver_command_free(command); | 136 | debugserver_command_free(command); |
| 133 | command = NULL; | 137 | command = NULL; |
| 134 | } else if (r[0] == 'T') { | 138 | } else if (r[0] == 'T') { |
| 135 | /* thread stopped information */ | 139 | /* thread stopped information */ |
| 136 | debug_info("Thread stopped. Details:\n%s", r + 1); | 140 | log_debug("Thread stopped. Details:\n%s", r + 1); |
| 137 | 141 | ||
| 138 | free(*response); | 142 | free(*response); |
| 139 | *response = NULL; | 143 | *response = NULL; |
| @@ -154,7 +158,7 @@ static debugserver_error_t debugserver_client_handle_response(debugserver_client | |||
| 154 | /* send reply */ | 158 | /* send reply */ |
| 155 | debugserver_command_new("OK", 0, NULL, &command); | 159 | debugserver_command_new("OK", 0, NULL, &command); |
| 156 | dres = debugserver_client_send_command(client, command, response, NULL); | 160 | dres = debugserver_client_send_command(client, command, response, NULL); |
| 157 | debug_info("result: %d", dres); | 161 | log_debug("result: %d", dres); |
| 158 | debugserver_command_free(command); | 162 | debugserver_command_free(command); |
| 159 | command = NULL; | 163 | command = NULL; |
| 160 | } else if (r && strlen(r) == 0) { | 164 | } else if (r && strlen(r) == 0) { |
| @@ -167,11 +171,11 @@ static debugserver_error_t debugserver_client_handle_response(debugserver_client | |||
| 167 | /* no command */ | 171 | /* no command */ |
| 168 | debugserver_command_new("OK", 0, NULL, &command); | 172 | debugserver_command_new("OK", 0, NULL, &command); |
| 169 | dres = debugserver_client_send_command(client, command, response, NULL); | 173 | dres = debugserver_client_send_command(client, command, response, NULL); |
| 170 | debug_info("result: %d", dres); | 174 | log_debug("result: %d", dres); |
| 171 | debugserver_command_free(command); | 175 | debugserver_command_free(command); |
| 172 | command = NULL; | 176 | command = NULL; |
| 173 | } else { | 177 | } else { |
| 174 | debug_info("ERROR: unhandled response", r); | 178 | log_debug("ERROR: unhandled response '%s'", r); |
| 175 | } | 179 | } |
| 176 | 180 | ||
| 177 | return dres; | 181 | return dres; |
| @@ -203,7 +207,6 @@ int main(int argc, char *argv[]) | |||
| 203 | instproxy_client_t instproxy_client = NULL; | 207 | instproxy_client_t instproxy_client = NULL; |
| 204 | debugserver_client_t debugserver_client = NULL; | 208 | debugserver_client_t debugserver_client = NULL; |
| 205 | int i; | 209 | int i; |
| 206 | int debug_level = 0; | ||
| 207 | int cmd = CMD_NONE; | 210 | int cmd = CMD_NONE; |
| 208 | const char* udid = NULL; | 211 | const char* udid = NULL; |
| 209 | const char* bundle_identifier = NULL; | 212 | const char* bundle_identifier = NULL; |
| @@ -319,7 +322,7 @@ int main(int argc, char *argv[]) | |||
| 319 | 322 | ||
| 320 | if (container && (plist_get_node_type(container) == PLIST_STRING)) { | 323 | if (container && (plist_get_node_type(container) == PLIST_STRING)) { |
| 321 | plist_get_string_val(container, &working_directory); | 324 | plist_get_string_val(container, &working_directory); |
| 322 | debug_info("working_directory: %s\n", working_directory); | 325 | log_debug("working_directory: %s\n", working_directory); |
| 323 | plist_free(container); | 326 | plist_free(container); |
| 324 | } else { | 327 | } else { |
| 325 | plist_free(container); | 328 | plist_free(container); |
| @@ -340,7 +343,7 @@ int main(int argc, char *argv[]) | |||
| 340 | 343 | ||
| 341 | /* enable logging for the session in debug mode */ | 344 | /* enable logging for the session in debug mode */ |
| 342 | if (debug_level) { | 345 | if (debug_level) { |
| 343 | debug_info("Setting logging bitmask..."); | 346 | log_debug("Setting logging bitmask..."); |
| 344 | debugserver_command_new("QSetLogging:bitmask=LOG_ALL|LOG_RNB_REMOTE|LOG_RNB_PACKETS", 0, NULL, &command); | 347 | debugserver_command_new("QSetLogging:bitmask=LOG_ALL|LOG_RNB_REMOTE|LOG_RNB_PACKETS", 0, NULL, &command); |
| 345 | dres = debugserver_client_send_command(debugserver_client, command, &response, NULL); | 348 | dres = debugserver_client_send_command(debugserver_client, command, &response, NULL); |
| 346 | debugserver_command_free(command); | 349 | debugserver_command_free(command); |
| @@ -356,7 +359,7 @@ int main(int argc, char *argv[]) | |||
| 356 | } | 359 | } |
| 357 | 360 | ||
| 358 | /* set maximum packet size */ | 361 | /* set maximum packet size */ |
| 359 | debug_info("Setting maximum packet size..."); | 362 | log_debug("Setting maximum packet size..."); |
| 360 | char* packet_size[2] = {strdup("1024"), NULL}; | 363 | char* packet_size[2] = {strdup("1024"), NULL}; |
| 361 | debugserver_command_new("QSetMaxPacketSize:", 1, packet_size, &command); | 364 | debugserver_command_new("QSetMaxPacketSize:", 1, packet_size, &command); |
| 362 | free(packet_size[0]); | 365 | free(packet_size[0]); |
| @@ -373,7 +376,7 @@ int main(int argc, char *argv[]) | |||
| 373 | } | 376 | } |
| 374 | 377 | ||
| 375 | /* set working directory */ | 378 | /* set working directory */ |
| 376 | debug_info("Setting working directory..."); | 379 | log_debug("Setting working directory..."); |
| 377 | char* working_dir[2] = {working_directory, NULL}; | 380 | char* working_dir[2] = {working_directory, NULL}; |
| 378 | debugserver_command_new("QSetWorkingDir:", 1, working_dir, &command); | 381 | debugserver_command_new("QSetWorkingDir:", 1, working_dir, &command); |
| 379 | dres = debugserver_client_send_command(debugserver_client, command, &response, NULL); | 382 | dres = debugserver_client_send_command(debugserver_client, command, &response, NULL); |
| @@ -390,23 +393,23 @@ int main(int argc, char *argv[]) | |||
| 390 | 393 | ||
| 391 | /* set environment */ | 394 | /* set environment */ |
| 392 | if (environment) { | 395 | if (environment) { |
| 393 | debug_info("Setting environment..."); | 396 | log_debug("Setting environment..."); |
| 394 | for (environment_index = 0; environment_index < environment_count; environment_index++) { | 397 | for (environment_index = 0; environment_index < environment_count; environment_index++) { |
| 395 | debug_info("setting environment variable: %s", environment[environment_index]); | 398 | log_debug("setting environment variable: %s", environment[environment_index]); |
| 396 | debugserver_client_set_environment_hex_encoded(debugserver_client, environment[environment_index], NULL); | 399 | debugserver_client_set_environment_hex_encoded(debugserver_client, environment[environment_index], NULL); |
| 397 | } | 400 | } |
| 398 | } | 401 | } |
| 399 | 402 | ||
| 400 | /* set arguments and run app */ | 403 | /* set arguments and run app */ |
| 401 | debug_info("Setting argv..."); | 404 | log_debug("Setting argv..."); |
| 402 | i++; /* i is the offset of the bundle identifier, thus skip it */ | 405 | i++; /* i is the offset of the bundle identifier, thus skip it */ |
| 403 | int app_argc = (argc - i + 2); | 406 | int app_argc = (argc - i + 2); |
| 404 | char **app_argv = (char**)malloc(sizeof(char*) * app_argc); | 407 | char **app_argv = (char**)malloc(sizeof(char*) * app_argc); |
| 405 | app_argv[0] = path; | 408 | app_argv[0] = path; |
| 406 | debug_info("app_argv[%d] = %s", 0, app_argv[0]); | 409 | log_debug("app_argv[%d] = %s", 0, app_argv[0]); |
| 407 | app_argc = 1; | 410 | app_argc = 1; |
| 408 | while (i < argc && argv && argv[i]) { | 411 | while (i < argc && argv && argv[i]) { |
| 409 | debug_info("app_argv[%d] = %s", app_argc, argv[i]); | 412 | log_debug("app_argv[%d] = %s", app_argc, argv[i]); |
| 410 | app_argv[app_argc++] = argv[i]; | 413 | app_argv[app_argc++] = argv[i]; |
| 411 | i++; | 414 | i++; |
| 412 | } | 415 | } |
| @@ -415,7 +418,7 @@ int main(int argc, char *argv[]) | |||
| 415 | free(app_argv); | 418 | free(app_argv); |
| 416 | 419 | ||
| 417 | /* check if launch succeeded */ | 420 | /* check if launch succeeded */ |
| 418 | debug_info("Checking if launch succeeded..."); | 421 | log_debug("Checking if launch succeeded..."); |
| 419 | debugserver_command_new("qLaunchSuccess", 0, NULL, &command); | 422 | debugserver_command_new("qLaunchSuccess", 0, NULL, &command); |
| 420 | dres = debugserver_client_send_command(debugserver_client, command, &response, NULL); | 423 | dres = debugserver_client_send_command(debugserver_client, command, &response, NULL); |
| 421 | debugserver_command_free(command); | 424 | debugserver_command_free(command); |
| @@ -430,7 +433,7 @@ int main(int argc, char *argv[]) | |||
| 430 | } | 433 | } |
| 431 | 434 | ||
| 432 | /* set thread */ | 435 | /* set thread */ |
| 433 | debug_info("Setting thread..."); | 436 | log_debug("Setting thread..."); |
| 434 | debugserver_command_new("Hc0", 0, NULL, &command); | 437 | debugserver_command_new("Hc0", 0, NULL, &command); |
| 435 | dres = debugserver_client_send_command(debugserver_client, command, &response, NULL); | 438 | dres = debugserver_client_send_command(debugserver_client, command, &response, NULL); |
| 436 | debugserver_command_free(command); | 439 | debugserver_command_free(command); |
| @@ -445,22 +448,22 @@ int main(int argc, char *argv[]) | |||
| 445 | } | 448 | } |
| 446 | 449 | ||
| 447 | /* continue running process */ | 450 | /* continue running process */ |
| 448 | debug_info("Continue running process..."); | 451 | log_debug("Continue running process..."); |
| 449 | debugserver_command_new("c", 0, NULL, &command); | 452 | debugserver_command_new("c", 0, NULL, &command); |
| 450 | dres = debugserver_client_send_command(debugserver_client, command, &response, NULL); | 453 | dres = debugserver_client_send_command(debugserver_client, command, &response, NULL); |
| 451 | debugserver_command_free(command); | 454 | debugserver_command_free(command); |
| 452 | command = NULL; | 455 | command = NULL; |
| 453 | 456 | ||
| 454 | /* main loop which is parsing/handling packets during the run */ | 457 | /* main loop which is parsing/handling packets during the run */ |
| 455 | debug_info("Entering run loop..."); | 458 | log_debug("Entering run loop..."); |
| 456 | while (!quit_flag) { | 459 | while (!quit_flag) { |
| 457 | if (dres != DEBUGSERVER_E_SUCCESS) { | 460 | if (dres != DEBUGSERVER_E_SUCCESS) { |
| 458 | debug_info("failed to receive response"); | 461 | log_debug("failed to receive response"); |
| 459 | break; | 462 | break; |
| 460 | } | 463 | } |
| 461 | 464 | ||
| 462 | if (response) { | 465 | if (response) { |
| 463 | debug_info("response: %s", response); | 466 | log_debug("response: %s", response); |
| 464 | dres = debugserver_client_handle_response(debugserver_client, &response, 1); | 467 | dres = debugserver_client_handle_response(debugserver_client, &response, 1); |
| 465 | } | 468 | } |
| 466 | 469 | ||
| @@ -468,7 +471,7 @@ int main(int argc, char *argv[]) | |||
| 468 | } | 471 | } |
| 469 | 472 | ||
| 470 | /* kill process after we finished */ | 473 | /* kill process after we finished */ |
| 471 | debug_info("Killing process..."); | 474 | log_debug("Killing process..."); |
| 472 | debugserver_command_new("k", 0, NULL, &command); | 475 | debugserver_command_new("k", 0, NULL, &command); |
| 473 | dres = debugserver_client_send_command(debugserver_client, command, &response, NULL); | 476 | dres = debugserver_client_send_command(debugserver_client, command, &response, NULL); |
| 474 | debugserver_command_free(command); | 477 | debugserver_command_free(command); |
