summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/libimobiledevice/debugserver.h11
-rw-r--r--src/debugserver.c13
-rw-r--r--tools/idevicedebug.c50
3 files changed, 43 insertions, 31 deletions
diff --git a/include/libimobiledevice/debugserver.h b/include/libimobiledevice/debugserver.h
index 03f97a4..90ba514 100644
--- a/include/libimobiledevice/debugserver.h
+++ b/include/libimobiledevice/debugserver.h
@@ -181,11 +181,16 @@ debugserver_error_t debugserver_client_set_ack_mode(debugserver_client_t client,
/**
* Sets behavior when awaiting a response from the server.
*
- * @see debugserver_client_send_command, debugserver_client_receive_response, debugserver_client_receive
+ * @see debugserver_client_send_command, debugserver_client_receive_response,
+ * debugserver_client_receive
*
* @param client The debugserver client
- * @param cancel_receive A function pointer that will be called approximately every receive_loop_timeout milliseconds; the function should return a boolean flag specifying whether to stop waiting for a response. If NULL, behaves as if it always returns true.
- * @param receive_loop_timeout Time in milliseconds between calls to cancel_receive.
+ * @param cancel_receive A function pointer that will be called approximately
+ * every receive_loop_timeout milliseconds; the function should return a
+ * boolean flag specifying whether to stop waiting for a response. If NULL,
+ * behaves as if it always returns true.
+ * @param receive_loop_timeout Time in milliseconds between calls to
+ * cancel_receive.
*
* @return DEBUGSERVER_E_SUCCESS on success, or an DEBUGSERVER_E_* error
* code otherwise.
diff --git a/src/debugserver.c b/src/debugserver.c
index 4d653cf..1c20c25 100644
--- a/src/debugserver.c
+++ b/src/debugserver.c
@@ -89,8 +89,8 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_new(idevice_t device
debugserver_client_t client_loc = (debugserver_client_t) malloc(sizeof(struct debugserver_client_private));
client_loc->parent = parent;
client_loc->noack_mode = 0;
- client_loc->cancel_receive = NULL;
- client_loc->receive_loop_timeout = 1000;
+ client_loc->cancel_receive = NULL;
+ client_loc->receive_loop_timeout = 1000;
*client = client_loc;
@@ -165,10 +165,11 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive_with_timeout
LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive(debugserver_client_t client, char* data, uint32_t size, uint32_t *received)
{
debugserver_error_t res = DEBUGSERVER_E_UNKNOWN_ERROR;
- do {
- res = debugserver_client_receive_with_timeout(client, data, size, received, client->receive_loop_timeout);
- } while (res == DEBUGSERVER_E_TIMEOUT && client->cancel_receive != NULL && !client->cancel_receive());
- return res;
+ do {
+ /* Is this allowed to return DEBUGSERVER_E_TIMEOUT and also set data and received? */
+ res = debugserver_client_receive_with_timeout(client, data, size, received, client->receive_loop_timeout);
+ } while (res == DEBUGSERVER_E_TIMEOUT && client->cancel_receive != NULL && !client->cancel_receive());
+ return res;
}
LIBIMOBILEDEVICE_API debugserver_error_t debugserver_command_new(const char* name, int argc, char* argv[], debugserver_command_t* command)
diff --git a/tools/idevicedebug.c b/tools/idevicedebug.c
index ae6dd02..67ef938 100644
--- a/tools/idevicedebug.c
+++ b/tools/idevicedebug.c
@@ -119,8 +119,9 @@ static debugserver_error_t debugserver_client_handle_response(debugserver_client
char* o = NULL;
char* r = *response;
- /* Documentation of response codes can be found here:
- https://github.com/llvm/llvm-project/blob/4fe839ef3a51e0ea2e72ea2f8e209790489407a2/lldb/docs/lldb-gdb-remote.txt#L1269 */
+ /* Documentation of response codes can be found here:
+ https://github.com/llvm/llvm-project/blob/4fe839ef3a51e0ea2e72ea2f8e209790489407a2/lldb/docs/lldb-gdb-remote.txt#L1269
+ */
if (r[0] == 'O') {
/* stdout/stderr */
@@ -130,8 +131,11 @@ static debugserver_error_t debugserver_client_handle_response(debugserver_client
} else if (r[0] == 'T') {
/* thread stopped information */
log_debug("Thread stopped. Details:\n%s", r + 1);
- if (exit_status != NULL) {
- /* "Thread stopped" seems to happen when assert() fails. Use bash convention where signals cause an exit status of 128 + signal */
+ if (exit_status != NULL) {
+ /* "Thread stopped" seems to happen when assert() fails.
+ Use bash convention where signals cause an exit
+ status of 128 + signal
+ */
*exit_status = 128 + SIGABRT;
}
/* Break out of the loop. */
@@ -143,13 +147,15 @@ static debugserver_error_t debugserver_client_handle_response(debugserver_client
debugserver_decode_string(r + 1, strlen(r) - 1, &o);
if (o != NULL) {
printf("Exit %s: %u\n", (r[0] == 'W' ? "status" : "due to signal"), o[0]);
- if (exit_status != NULL) {
- /* Use bash convention where signals cause an exit status of 128 + signal */
- *exit_status = o[0] + (r[0] == 'W' ? 0 : 128);
- }
+ if (exit_status != NULL) {
+ /* Use bash convention where signals cause an
+ exit status of 128 + signal
+ */
+ *exit_status = o[0] + (r[0] == 'W' ? 0 : 128);
+ }
} else {
- debug_info("Unable to decode exit status from %s", r);
- dres = DEBUGSERVER_E_UNKNOWN_ERROR;
+ debug_info("Unable to decode exit status from %s", r);
+ dres = DEBUGSERVER_E_UNKNOWN_ERROR;
}
} else if (r && strlen(r) == 0) {
log_debug("empty response");
@@ -157,13 +163,13 @@ static debugserver_error_t debugserver_client_handle_response(debugserver_client
log_debug("ERROR: unhandled response '%s'", r);
}
- if (o != NULL) {
- free(o);
- o = NULL;
- }
+ if (o != NULL) {
+ free(o);
+ o = NULL;
+ }
- free(*response);
- *response = NULL;
+ free(*response);
+ *response = NULL;
return dres;
}
@@ -351,8 +357,8 @@ int main(int argc, char *argv[])
goto cleanup;
}
- /* set receive params */
- if (debugserver_client_set_receive_params(debugserver_client, cancel_receive, 250) != DEBUGSERVER_E_SUCCESS) {
+ /* set receive params */
+ if (debugserver_client_set_receive_params(debugserver_client, cancel_receive, 250) != DEBUGSERVER_E_SUCCESS) {
fprintf(stderr, "Error in debugserver_client_set_receive_params\n");
goto cleanup;
}
@@ -494,7 +500,7 @@ int main(int argc, char *argv[])
if (strncmp(response, "OK", 2)) {
dres = debugserver_client_handle_response(debugserver_client, &response, &res);
if (dres != DEBUGSERVER_E_SUCCESS) {
- debug_info("failed to process response; error %d; %s", dres, response);
+ log_debug("failed to process response; error %d; %s", dres, response);
break;
}
}
@@ -521,9 +527,9 @@ int main(int argc, char *argv[])
response = NULL;
}
- if (res < 0) {
- res = (dres == DEBUGSERVER_E_SUCCESS) ? 0: -1;
- }
+ if (res < 0) {
+ res = (dres == DEBUGSERVER_E_SUCCESS) ? 0: -1;
+ }
break;
}