summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGravatar Ruipu Ma2021-09-14 17:08:09 +0800
committerGravatar Nikias Bassen2022-07-03 01:48:07 +0200
commit2eec1b9a172354c8521123a767d998b17bd2ac18 (patch)
tree95c84fca46dc15e71c012f11e41b01e1255fa135 /tools
parent32d531a955b9a099e3418e84ef31f4b041974a4d (diff)
downloadlibimobiledevice-master.tar.gz
libimobiledevice-master.tar.bz2
idevicedebugserverproxy: Add support for 'qLaunchGDBServer' command of lldbHEADmaster
Diffstat (limited to 'tools')
-rw-r--r--tools/idevicedebugserverproxy.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/tools/idevicedebugserverproxy.c b/tools/idevicedebugserverproxy.c
index 8a3b4ff..9fe7051 100644
--- a/tools/idevicedebugserverproxy.c
+++ b/tools/idevicedebugserverproxy.c
@@ -52,8 +52,10 @@
#define info(...) fprintf(stdout, __VA_ARGS__); fflush(stdout)
#define debug(...) if(debug_mode) fprintf(stdout, __VA_ARGS__)
+static int support_lldb = 0;
static int debug_mode = 0;
static int quit_flag = 0;
+static uint16_t local_port = 0;
typedef struct {
int client_fd;
@@ -90,6 +92,7 @@ static void print_usage(int argc, char **argv, int is_error)
" -u, --udid UDID target specific device by UDID\n"
" -n, --network connect to network device\n"
" -d, --debug enable communication debugging\n"
+ " -l, --lldb enable lldb support\n"
" -h, --help prints usage information\n"
" -v, --version prints version information\n"
"\n"
@@ -98,6 +101,26 @@ static void print_usage(int argc, char **argv, int is_error)
);
}
+static int intercept_packet(char *packet, ssize_t *packet_len) {
+ static const char kReqLaunchServer[] = "$qLaunchGDBServer;#4b";
+
+ char buffer[64] = {0};
+ if (*packet_len == (ssize_t)(sizeof(kReqLaunchServer) - 1)
+ && memcmp(packet, kReqLaunchServer, sizeof(kReqLaunchServer) - 1) == 0) {
+ sprintf(buffer, "port:%d;", local_port);
+ } else {
+ return 0;
+ }
+ int sum = 0;
+ for (size_t i = 0; i < strlen(buffer); i++) {
+ sum += buffer[i];
+ }
+ sum = sum & 255;
+ sprintf(packet, "$%s#%02x", buffer, sum);
+ *packet_len = strlen(packet);
+ return 1;
+}
+
static void* connection_handler(void* data)
{
debugserver_error_t derr = DEBUGSERVER_E_SUCCESS;
@@ -137,7 +160,10 @@ static void* connection_handler(void* data)
fprintf(stderr, "connection closed\n");
break;
}
-
+ if (support_lldb && intercept_packet(buf, &n)) {
+ socket_send(client_fd, buf, n);
+ continue;
+ }
uint32_t sent = 0;
debugserver_client_send(socket_info->debugserver_client, buf, n, &sent);
}
@@ -180,7 +206,6 @@ int main(int argc, char *argv[])
thread_info_t *thread_list = NULL;
const char* udid = NULL;
int use_network = 0;
- uint16_t local_port = 0;
int server_fd;
int result = EXIT_SUCCESS;
int c = 0;
@@ -189,6 +214,7 @@ int main(int argc, char *argv[])
{ "help", no_argument, NULL, 'h' },
{ "udid", required_argument, NULL, 'u' },
{ "network", no_argument, NULL, 'n' },
+ { "lldb", no_argument, NULL, 'l' },
{ "version", no_argument, NULL, 'v' },
{ NULL, 0, NULL, 0}
};
@@ -234,6 +260,9 @@ int main(int argc, char *argv[])
case 'n':
use_network = 1;
break;
+ case 'l':
+ support_lldb = 1;
+ break;
case 'h':
print_usage(argc, argv, 0);
return 0;