diff options
-rw-r--r-- | docs/idevicedebugserverproxy.1 | 3 | ||||
-rw-r--r-- | tools/idevicedebugserverproxy.c | 33 |
2 files changed, 34 insertions, 2 deletions
diff --git a/docs/idevicedebugserverproxy.1 b/docs/idevicedebugserverproxy.1 index 248c694..69200ee 100644 --- a/docs/idevicedebugserverproxy.1 +++ b/docs/idevicedebugserverproxy.1 | |||
@@ -22,6 +22,9 @@ target specific device by UDID. | |||
22 | .B \-n, \-\-network | 22 | .B \-n, \-\-network |
23 | connect to network device. | 23 | connect to network device. |
24 | .TP | 24 | .TP |
25 | .B \-l, \-\-lldb | ||
26 | Enable lldb support. | ||
27 | .TP | ||
25 | .B \-d, \-\-debug | 28 | .B \-d, \-\-debug |
26 | enable communication debugging. | 29 | enable communication debugging. |
27 | .TP | 30 | .TP |
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 @@ | |||
52 | #define info(...) fprintf(stdout, __VA_ARGS__); fflush(stdout) | 52 | #define info(...) fprintf(stdout, __VA_ARGS__); fflush(stdout) |
53 | #define debug(...) if(debug_mode) fprintf(stdout, __VA_ARGS__) | 53 | #define debug(...) if(debug_mode) fprintf(stdout, __VA_ARGS__) |
54 | 54 | ||
55 | static int support_lldb = 0; | ||
55 | static int debug_mode = 0; | 56 | static int debug_mode = 0; |
56 | static int quit_flag = 0; | 57 | static int quit_flag = 0; |
58 | static uint16_t local_port = 0; | ||
57 | 59 | ||
58 | typedef struct { | 60 | typedef struct { |
59 | int client_fd; | 61 | int client_fd; |
@@ -90,6 +92,7 @@ static void print_usage(int argc, char **argv, int is_error) | |||
90 | " -u, --udid UDID target specific device by UDID\n" | 92 | " -u, --udid UDID target specific device by UDID\n" |
91 | " -n, --network connect to network device\n" | 93 | " -n, --network connect to network device\n" |
92 | " -d, --debug enable communication debugging\n" | 94 | " -d, --debug enable communication debugging\n" |
95 | " -l, --lldb enable lldb support\n" | ||
93 | " -h, --help prints usage information\n" | 96 | " -h, --help prints usage information\n" |
94 | " -v, --version prints version information\n" | 97 | " -v, --version prints version information\n" |
95 | "\n" | 98 | "\n" |
@@ -98,6 +101,26 @@ static void print_usage(int argc, char **argv, int is_error) | |||
98 | ); | 101 | ); |
99 | } | 102 | } |
100 | 103 | ||
104 | static int intercept_packet(char *packet, ssize_t *packet_len) { | ||
105 | static const char kReqLaunchServer[] = "$qLaunchGDBServer;#4b"; | ||
106 | |||
107 | char buffer[64] = {0}; | ||
108 | if (*packet_len == (ssize_t)(sizeof(kReqLaunchServer) - 1) | ||
109 | && memcmp(packet, kReqLaunchServer, sizeof(kReqLaunchServer) - 1) == 0) { | ||
110 | sprintf(buffer, "port:%d;", local_port); | ||
111 | } else { | ||
112 | return 0; | ||
113 | } | ||
114 | int sum = 0; | ||
115 | for (size_t i = 0; i < strlen(buffer); i++) { | ||
116 | sum += buffer[i]; | ||
117 | } | ||
118 | sum = sum & 255; | ||
119 | sprintf(packet, "$%s#%02x", buffer, sum); | ||
120 | *packet_len = strlen(packet); | ||
121 | return 1; | ||
122 | } | ||
123 | |||
101 | static void* connection_handler(void* data) | 124 | static void* connection_handler(void* data) |
102 | { | 125 | { |
103 | debugserver_error_t derr = DEBUGSERVER_E_SUCCESS; | 126 | debugserver_error_t derr = DEBUGSERVER_E_SUCCESS; |
@@ -137,7 +160,10 @@ static void* connection_handler(void* data) | |||
137 | fprintf(stderr, "connection closed\n"); | 160 | fprintf(stderr, "connection closed\n"); |
138 | break; | 161 | break; |
139 | } | 162 | } |
140 | 163 | if (support_lldb && intercept_packet(buf, &n)) { | |
164 | socket_send(client_fd, buf, n); | ||
165 | continue; | ||
166 | } | ||
141 | uint32_t sent = 0; | 167 | uint32_t sent = 0; |
142 | debugserver_client_send(socket_info->debugserver_client, buf, n, &sent); | 168 | debugserver_client_send(socket_info->debugserver_client, buf, n, &sent); |
143 | } | 169 | } |
@@ -180,7 +206,6 @@ int main(int argc, char *argv[]) | |||
180 | thread_info_t *thread_list = NULL; | 206 | thread_info_t *thread_list = NULL; |
181 | const char* udid = NULL; | 207 | const char* udid = NULL; |
182 | int use_network = 0; | 208 | int use_network = 0; |
183 | uint16_t local_port = 0; | ||
184 | int server_fd; | 209 | int server_fd; |
185 | int result = EXIT_SUCCESS; | 210 | int result = EXIT_SUCCESS; |
186 | int c = 0; | 211 | int c = 0; |
@@ -189,6 +214,7 @@ int main(int argc, char *argv[]) | |||
189 | { "help", no_argument, NULL, 'h' }, | 214 | { "help", no_argument, NULL, 'h' }, |
190 | { "udid", required_argument, NULL, 'u' }, | 215 | { "udid", required_argument, NULL, 'u' }, |
191 | { "network", no_argument, NULL, 'n' }, | 216 | { "network", no_argument, NULL, 'n' }, |
217 | { "lldb", no_argument, NULL, 'l' }, | ||
192 | { "version", no_argument, NULL, 'v' }, | 218 | { "version", no_argument, NULL, 'v' }, |
193 | { NULL, 0, NULL, 0} | 219 | { NULL, 0, NULL, 0} |
194 | }; | 220 | }; |
@@ -234,6 +260,9 @@ int main(int argc, char *argv[]) | |||
234 | case 'n': | 260 | case 'n': |
235 | use_network = 1; | 261 | use_network = 1; |
236 | break; | 262 | break; |
263 | case 'l': | ||
264 | support_lldb = 1; | ||
265 | break; | ||
237 | case 'h': | 266 | case 'h': |
238 | print_usage(argc, argv, 0); | 267 | print_usage(argc, argv, 0); |
239 | return 0; | 268 | return 0; |