OLD | NEW |
1 /* Main code for remote server for GDB. | 1 /* Main code for remote server for GDB. |
2 Copyright (C) 1989, 1993-1995, 1997-2000, 2002-2012 Free Software | 2 Copyright (C) 1989, 1993-1995, 1997-2000, 2002-2012 Free Software |
3 Foundation, Inc. | 3 Foundation, Inc. |
4 | 4 |
5 This file is part of GDB. | 5 This file is part of GDB. |
6 | 6 |
7 This program is free software; you can redistribute it and/or modify | 7 This program is free software; you can redistribute it and/or modify |
8 it under the terms of the GNU General Public License as published by | 8 it under the terms of the GNU General Public License as published by |
9 the Free Software Foundation; either version 3 of the License, or | 9 the Free Software Foundation; either version 3 of the License, or |
10 (at your option) any later version. | 10 (at your option) any later version. |
11 | 11 |
12 This program is distributed in the hope that it will be useful, | 12 This program is distributed in the hope that it will be useful, |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
16 | 16 |
17 You should have received a copy of the GNU General Public License | 17 You should have received a copy of the GNU General Public License |
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
19 | 19 |
20 #include "server.h" | 20 #include "server.h" |
| 21 #include "gdbthread.h" |
| 22 #include "agent.h" |
21 | 23 |
22 #if HAVE_UNISTD_H | 24 #if HAVE_UNISTD_H |
23 #include <unistd.h> | 25 #include <unistd.h> |
24 #endif | 26 #endif |
25 #if HAVE_SIGNAL_H | 27 #if HAVE_SIGNAL_H |
26 #include <signal.h> | 28 #include <signal.h> |
27 #endif | 29 #endif |
28 #if HAVE_SYS_WAIT_H | 30 #if HAVE_SYS_WAIT_H |
29 #include <sys/wait.h> | 31 #include <sys/wait.h> |
30 #endif | 32 #endif |
31 | 33 |
| 34 /* The thread set with an `Hc' packet. `Hc' is deprecated in favor of |
| 35 `vCont'. Note the multi-process extensions made `vCont' a |
| 36 requirement, so `Hc pPID.TID' is pretty much undefined. So |
| 37 CONT_THREAD can be null_ptid for no `Hc' thread, minus_one_ptid for |
| 38 resuming all threads of the process (again, `Hc' isn't used for |
| 39 multi-process), or a specific thread ptid_t. |
| 40 |
| 41 We also set this when handling a single-thread `vCont' resume, as |
| 42 some places in the backends check it to know when (and for which |
| 43 thread) single-thread scheduler-locking is in effect. */ |
32 ptid_t cont_thread; | 44 ptid_t cont_thread; |
| 45 |
| 46 /* The thread set with an `Hg' packet. */ |
33 ptid_t general_thread; | 47 ptid_t general_thread; |
34 | 48 |
35 int server_waiting; | 49 int server_waiting; |
36 | 50 |
37 static int extended_protocol; | 51 static int extended_protocol; |
38 static int response_needed; | 52 static int response_needed; |
39 static int exit_requested; | 53 static int exit_requested; |
40 | 54 |
41 /* --once: Exit after the first connection has closed. */ | 55 /* --once: Exit after the first connection has closed. */ |
42 int run_once; | 56 int run_once; |
43 | 57 |
44 int multi_process; | 58 int multi_process; |
45 int non_stop; | 59 int non_stop; |
46 | 60 |
47 /* Whether we should attempt to disable the operating system's address | 61 /* Whether we should attempt to disable the operating system's address |
48 space randomization feature before starting an inferior. */ | 62 space randomization feature before starting an inferior. */ |
49 int disable_randomization = 1; | 63 int disable_randomization = 1; |
50 | 64 |
51 static char **program_argv, **wrapper_argv; | 65 static char **program_argv, **wrapper_argv; |
52 | 66 |
53 /* Enable miscellaneous debugging output. The name is historical - it | 67 /* Enable miscellaneous debugging output. The name is historical - it |
54 was originally used to debug LinuxThreads support. */ | 68 was originally used to debug LinuxThreads support. */ |
55 int debug_threads; | 69 int debug_threads; |
56 | 70 |
57 /* Enable debugging of h/w breakpoint/watchpoint support. */ | 71 /* Enable debugging of h/w breakpoint/watchpoint support. */ |
58 int debug_hw_points; | 72 int debug_hw_points; |
59 | 73 |
60 int pass_signals[TARGET_SIGNAL_LAST]; | 74 int pass_signals[GDB_SIGNAL_LAST]; |
| 75 int program_signals[GDB_SIGNAL_LAST]; |
| 76 int program_signals_p; |
61 | 77 |
62 jmp_buf toplevel; | 78 jmp_buf toplevel; |
63 | 79 |
64 const char *gdbserver_xmltarget; | 80 const char *gdbserver_xmltarget; |
65 | 81 |
66 /* The PID of the originally created or attached inferior. Used to | 82 /* The PID of the originally created or attached inferior. Used to |
67 send signals to the process when GDB sends us an asynchronous interrupt | 83 send signals to the process when GDB sends us an asynchronous interrupt |
68 (user hitting Control-C in the client), and to wait for the child to exit | 84 (user hitting Control-C in the client), and to wait for the child to exit |
69 when no longer debugging it. */ | 85 when no longer debugging it. */ |
70 | 86 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 for (i = 0; new_argv[i]; ++i) | 268 for (i = 0; new_argv[i]; ++i) |
253 fprintf (stderr, "new_argv[%d] = \"%s\"\n", i, new_argv[i]); | 269 fprintf (stderr, "new_argv[%d] = \"%s\"\n", i, new_argv[i]); |
254 fflush (stderr); | 270 fflush (stderr); |
255 } | 271 } |
256 | 272 |
257 #ifdef SIGTTOU | 273 #ifdef SIGTTOU |
258 signal (SIGTTOU, SIG_DFL); | 274 signal (SIGTTOU, SIG_DFL); |
259 signal (SIGTTIN, SIG_DFL); | 275 signal (SIGTTIN, SIG_DFL); |
260 #endif | 276 #endif |
261 | 277 |
| 278 /* Clear this so the backend doesn't get confused, thinking |
| 279 CONT_THREAD died, and it needs to resume all threads. */ |
| 280 cont_thread = null_ptid; |
| 281 |
262 signal_pid = create_inferior (new_argv[0], new_argv); | 282 signal_pid = create_inferior (new_argv[0], new_argv); |
263 | 283 |
264 /* FIXME: we don't actually know at this point that the create | 284 /* FIXME: we don't actually know at this point that the create |
265 actually succeeded. We won't know that until we wait. */ | 285 actually succeeded. We won't know that until we wait. */ |
266 fprintf (stderr, "Process %s created; pid = %ld\n", argv[0], | 286 fprintf (stderr, "Process %s created; pid = %ld\n", argv[0], |
267 signal_pid); | 287 signal_pid); |
268 fflush (stderr); | 288 fflush (stderr); |
269 | 289 |
270 #ifdef SIGTTOU | 290 #ifdef SIGTTOU |
271 signal (SIGTTOU, SIG_IGN); | 291 signal (SIGTTOU, SIG_IGN); |
272 signal (SIGTTIN, SIG_IGN); | 292 signal (SIGTTIN, SIG_IGN); |
273 terminal_fd = fileno (stderr); | 293 terminal_fd = fileno (stderr); |
274 old_foreground_pgrp = tcgetpgrp (terminal_fd); | 294 old_foreground_pgrp = tcgetpgrp (terminal_fd); |
275 tcsetpgrp (terminal_fd, signal_pid); | 295 tcsetpgrp (terminal_fd, signal_pid); |
276 atexit (restore_old_foreground_pgrp); | 296 atexit (restore_old_foreground_pgrp); |
277 #endif | 297 #endif |
278 | 298 |
279 if (wrapper_argv != NULL) | 299 if (wrapper_argv != NULL) |
280 { | 300 { |
281 struct thread_resume resume_info; | 301 struct thread_resume resume_info; |
282 | 302 |
283 resume_info.thread = pid_to_ptid (signal_pid); | 303 resume_info.thread = pid_to_ptid (signal_pid); |
284 resume_info.kind = resume_continue; | 304 resume_info.kind = resume_continue; |
285 resume_info.sig = 0; | 305 resume_info.sig = 0; |
286 | 306 |
287 mywait (pid_to_ptid (signal_pid), &last_status, 0, 0); | 307 last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0); |
288 | 308 |
289 if (last_status.kind != TARGET_WAITKIND_STOPPED) | 309 if (last_status.kind != TARGET_WAITKIND_STOPPED) |
290 return signal_pid; | 310 return signal_pid; |
291 | 311 |
292 do | 312 do |
293 { | 313 { |
294 (*the_target->resume) (&resume_info, 1); | 314 (*the_target->resume) (&resume_info, 1); |
295 | 315 |
296 » mywait (pid_to_ptid (signal_pid), &last_status, 0, 0); | 316 » last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0); |
297 if (last_status.kind != TARGET_WAITKIND_STOPPED) | 317 if (last_status.kind != TARGET_WAITKIND_STOPPED) |
298 return signal_pid; | 318 return signal_pid; |
299 | 319 |
300 current_inferior->last_resume_kind = resume_stop; | 320 current_inferior->last_resume_kind = resume_stop; |
301 current_inferior->last_status = last_status; | 321 current_inferior->last_status = last_status; |
302 } | 322 } |
303 while (last_status.value.sig != TARGET_SIGNAL_TRAP); | 323 while (last_status.value.sig != GDB_SIGNAL_TRAP); |
304 | 324 |
305 current_inferior->last_resume_kind = resume_stop; | |
306 current_inferior->last_status = last_status; | |
307 return signal_pid; | 325 return signal_pid; |
308 } | 326 } |
309 | 327 |
310 /* Wait till we are at 1st instruction in program, return new pid | 328 /* Wait till we are at 1st instruction in program, return new pid |
311 (assuming success). */ | 329 (assuming success). */ |
312 last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0); | 330 last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0); |
313 | 331 |
314 if (last_status.kind != TARGET_WAITKIND_EXITED | 332 if (last_status.kind != TARGET_WAITKIND_EXITED |
315 && last_status.kind != TARGET_WAITKIND_SIGNALLED) | 333 && last_status.kind != TARGET_WAITKIND_SIGNALLED) |
316 { | 334 { |
(...skipping 14 matching lines...) Expand all Loading... |
331 return -1; | 349 return -1; |
332 | 350 |
333 fprintf (stderr, "Attached; pid = %d\n", pid); | 351 fprintf (stderr, "Attached; pid = %d\n", pid); |
334 fflush (stderr); | 352 fflush (stderr); |
335 | 353 |
336 /* FIXME - It may be that we should get the SIGNAL_PID from the | 354 /* FIXME - It may be that we should get the SIGNAL_PID from the |
337 attach function, so that it can be the main thread instead of | 355 attach function, so that it can be the main thread instead of |
338 whichever we were told to attach to. */ | 356 whichever we were told to attach to. */ |
339 signal_pid = pid; | 357 signal_pid = pid; |
340 | 358 |
| 359 /* Clear this so the backend doesn't get confused, thinking |
| 360 CONT_THREAD died, and it needs to resume all threads. */ |
| 361 cont_thread = null_ptid; |
| 362 |
341 if (!non_stop) | 363 if (!non_stop) |
342 { | 364 { |
343 last_ptid = mywait (pid_to_ptid (pid), &last_status, 0, 0); | 365 last_ptid = mywait (pid_to_ptid (pid), &last_status, 0, 0); |
344 | 366 |
345 /* GDB knows to ignore the first SIGSTOP after attaching to a running | 367 /* GDB knows to ignore the first SIGSTOP after attaching to a running |
346 process using the "attach" command, but this is different; it's | 368 process using the "attach" command, but this is different; it's |
347 just using "target remote". Pretend it's just starting up. */ | 369 just using "target remote". Pretend it's just starting up. */ |
348 if (last_status.kind == TARGET_WAITKIND_STOPPED | 370 if (last_status.kind == TARGET_WAITKIND_STOPPED |
349 » && last_status.value.sig == TARGET_SIGNAL_STOP) | 371 » && last_status.value.sig == GDB_SIGNAL_STOP) |
350 » last_status.value.sig = TARGET_SIGNAL_TRAP; | 372 » last_status.value.sig = GDB_SIGNAL_TRAP; |
351 | 373 |
352 current_inferior->last_resume_kind = resume_stop; | 374 current_inferior->last_resume_kind = resume_stop; |
353 current_inferior->last_status = last_status; | 375 current_inferior->last_status = last_status; |
354 } | 376 } |
355 | 377 |
356 return 0; | 378 return 0; |
357 } | 379 } |
358 | 380 |
359 extern int remote_debug; | 381 extern int remote_debug; |
360 | 382 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 PBUFSIZ - 2) + 1; | 442 PBUFSIZ - 2) + 1; |
421 } | 443 } |
422 | 444 |
423 /* Handle all of the extended 'Q' packets. */ | 445 /* Handle all of the extended 'Q' packets. */ |
424 | 446 |
425 static void | 447 static void |
426 handle_general_set (char *own_buf) | 448 handle_general_set (char *own_buf) |
427 { | 449 { |
428 if (strncmp ("QPassSignals:", own_buf, strlen ("QPassSignals:")) == 0) | 450 if (strncmp ("QPassSignals:", own_buf, strlen ("QPassSignals:")) == 0) |
429 { | 451 { |
430 int numsigs = (int) TARGET_SIGNAL_LAST, i; | 452 int numsigs = (int) GDB_SIGNAL_LAST, i; |
431 const char *p = own_buf + strlen ("QPassSignals:"); | 453 const char *p = own_buf + strlen ("QPassSignals:"); |
432 CORE_ADDR cursig; | 454 CORE_ADDR cursig; |
433 | 455 |
434 p = decode_address_to_semicolon (&cursig, p); | 456 p = decode_address_to_semicolon (&cursig, p); |
435 for (i = 0; i < numsigs; i++) | 457 for (i = 0; i < numsigs; i++) |
436 { | 458 { |
437 if (i == cursig) | 459 if (i == cursig) |
438 { | 460 { |
439 pass_signals[i] = 1; | 461 pass_signals[i] = 1; |
440 if (*p == '\0') | 462 if (*p == '\0') |
441 /* Keep looping, to clear the remaining signals. */ | 463 /* Keep looping, to clear the remaining signals. */ |
442 cursig = -1; | 464 cursig = -1; |
443 else | 465 else |
444 p = decode_address_to_semicolon (&cursig, p); | 466 p = decode_address_to_semicolon (&cursig, p); |
445 } | 467 } |
446 else | 468 else |
447 pass_signals[i] = 0; | 469 pass_signals[i] = 0; |
448 } | 470 } |
449 strcpy (own_buf, "OK"); | 471 strcpy (own_buf, "OK"); |
450 return; | 472 return; |
451 } | 473 } |
452 | 474 |
| 475 if (strncmp ("QProgramSignals:", own_buf, strlen ("QProgramSignals:")) == 0) |
| 476 { |
| 477 int numsigs = (int) GDB_SIGNAL_LAST, i; |
| 478 const char *p = own_buf + strlen ("QProgramSignals:"); |
| 479 CORE_ADDR cursig; |
| 480 |
| 481 program_signals_p = 1; |
| 482 |
| 483 p = decode_address_to_semicolon (&cursig, p); |
| 484 for (i = 0; i < numsigs; i++) |
| 485 { |
| 486 if (i == cursig) |
| 487 { |
| 488 program_signals[i] = 1; |
| 489 if (*p == '\0') |
| 490 /* Keep looping, to clear the remaining signals. */ |
| 491 cursig = -1; |
| 492 else |
| 493 p = decode_address_to_semicolon (&cursig, p); |
| 494 } |
| 495 else |
| 496 program_signals[i] = 0; |
| 497 } |
| 498 strcpy (own_buf, "OK"); |
| 499 return; |
| 500 } |
| 501 |
453 if (strcmp (own_buf, "QStartNoAckMode") == 0) | 502 if (strcmp (own_buf, "QStartNoAckMode") == 0) |
454 { | 503 { |
455 if (remote_debug) | 504 if (remote_debug) |
456 { | 505 { |
457 fprintf (stderr, "[noack mode enabled]\n"); | 506 fprintf (stderr, "[noack mode enabled]\n"); |
458 fflush (stderr); | 507 fflush (stderr); |
459 } | 508 } |
460 | 509 |
461 noack_mode = 1; | 510 noack_mode = 1; |
462 write_ok (own_buf); | 511 write_ok (own_buf); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 } | 567 } |
519 | 568 |
520 write_ok (own_buf); | 569 write_ok (own_buf); |
521 return; | 570 return; |
522 } | 571 } |
523 | 572 |
524 if (target_supports_tracepoints () | 573 if (target_supports_tracepoints () |
525 && handle_tracepoint_general_set (own_buf)) | 574 && handle_tracepoint_general_set (own_buf)) |
526 return; | 575 return; |
527 | 576 |
| 577 if (strncmp ("QAgent:", own_buf, strlen ("QAgent:")) == 0) |
| 578 { |
| 579 char *mode = own_buf + strlen ("QAgent:"); |
| 580 int req = 0; |
| 581 |
| 582 if (strcmp (mode, "0") == 0) |
| 583 req = 0; |
| 584 else if (strcmp (mode, "1") == 0) |
| 585 req = 1; |
| 586 else |
| 587 { |
| 588 /* We don't know what this value is, so complain to GDB. */ |
| 589 sprintf (own_buf, "E.Unknown QAgent value"); |
| 590 return; |
| 591 } |
| 592 |
| 593 /* Update the flag. */ |
| 594 use_agent = req; |
| 595 if (remote_debug) |
| 596 fprintf (stderr, "[%s agent]\n", req ? "Enable" : "Disable"); |
| 597 write_ok (own_buf); |
| 598 return; |
| 599 } |
| 600 |
528 /* Otherwise we didn't know what packet it was. Say we didn't | 601 /* Otherwise we didn't know what packet it was. Say we didn't |
529 understand it. */ | 602 understand it. */ |
530 own_buf[0] = 0; | 603 own_buf[0] = 0; |
531 } | 604 } |
532 | 605 |
533 static const char * | 606 static const char * |
534 get_features_xml (const char *annex) | 607 get_features_xml (const char *annex) |
535 { | 608 { |
536 /* gdbserver_xmltarget defines what to return when looking | 609 /* gdbserver_xmltarget defines what to return when looking |
537 for the "target.xml" file. Its contents can either be | 610 for the "target.xml" file. Its contents can either be |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 #define require_running(BUF) \ | 873 #define require_running(BUF) \ |
801 if (!target_running ()) \ | 874 if (!target_running ()) \ |
802 { \ | 875 { \ |
803 write_enn (BUF); \ | 876 write_enn (BUF); \ |
804 return; \ | 877 return; \ |
805 } | 878 } |
806 | 879 |
807 /* Handle monitor commands not handled by target-specific handlers. */ | 880 /* Handle monitor commands not handled by target-specific handlers. */ |
808 | 881 |
809 static void | 882 static void |
810 handle_monitor_command (char *mon) | 883 handle_monitor_command (char *mon, char *own_buf) |
811 { | 884 { |
812 if (strcmp (mon, "set debug 1") == 0) | 885 if (strcmp (mon, "set debug 1") == 0) |
813 { | 886 { |
814 debug_threads = 1; | 887 debug_threads = 1; |
815 monitor_output ("Debug output enabled.\n"); | 888 monitor_output ("Debug output enabled.\n"); |
816 } | 889 } |
817 else if (strcmp (mon, "set debug 0") == 0) | 890 else if (strcmp (mon, "set debug 0") == 0) |
818 { | 891 { |
819 debug_threads = 0; | 892 debug_threads = 0; |
820 monitor_output ("Debug output disabled.\n"); | 893 monitor_output ("Debug output disabled.\n"); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 unsigned int total_len; | 1007 unsigned int total_len; |
935 char *document, *p; | 1008 char *document, *p; |
936 struct inferior_list_entry *dll_ptr; | 1009 struct inferior_list_entry *dll_ptr; |
937 | 1010 |
938 if (writebuf != NULL) | 1011 if (writebuf != NULL) |
939 return -2; | 1012 return -2; |
940 | 1013 |
941 if (annex[0] != '\0' || !target_running ()) | 1014 if (annex[0] != '\0' || !target_running ()) |
942 return -1; | 1015 return -1; |
943 | 1016 |
944 /* Do not confuse this packet with qXfer:libraries-svr4:read. */ | |
945 if (the_target->qxfer_libraries_svr4 != NULL) | |
946 return 0; | |
947 | |
948 /* Over-estimate the necessary memory. Assume that every character | 1017 /* Over-estimate the necessary memory. Assume that every character |
949 in the library name must be escaped. */ | 1018 in the library name must be escaped. */ |
950 total_len = 64; | 1019 total_len = 64; |
951 for (dll_ptr = all_dlls.head; dll_ptr != NULL; dll_ptr = dll_ptr->next) | 1020 for (dll_ptr = all_dlls.head; dll_ptr != NULL; dll_ptr = dll_ptr->next) |
952 total_len += 128 + 6 * strlen (((struct dll_info *) dll_ptr)->name); | 1021 total_len += 128 + 6 * strlen (((struct dll_info *) dll_ptr)->name); |
953 | 1022 |
954 document = malloc (total_len); | 1023 document = malloc (total_len); |
955 if (document == NULL) | 1024 if (document == NULL) |
956 return -1; | 1025 return -1; |
957 | 1026 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 handle_qxfer_threads_proper (struct buffer *buffer) | 1153 handle_qxfer_threads_proper (struct buffer *buffer) |
1085 { | 1154 { |
1086 struct inferior_list_entry *thread; | 1155 struct inferior_list_entry *thread; |
1087 | 1156 |
1088 buffer_grow_str (buffer, "<threads>\n"); | 1157 buffer_grow_str (buffer, "<threads>\n"); |
1089 | 1158 |
1090 for (thread = all_threads.head; thread; thread = thread->next) | 1159 for (thread = all_threads.head; thread; thread = thread->next) |
1091 { | 1160 { |
1092 ptid_t ptid = thread_to_gdb_id ((struct thread_info *)thread); | 1161 ptid_t ptid = thread_to_gdb_id ((struct thread_info *)thread); |
1093 char ptid_s[100]; | 1162 char ptid_s[100]; |
1094 int core = -1; | 1163 int core = target_core_of_thread (ptid); |
1095 char core_s[21]; | 1164 char core_s[21]; |
1096 | 1165 |
1097 write_ptid (ptid_s, ptid); | 1166 write_ptid (ptid_s, ptid); |
1098 | 1167 |
1099 if (the_target->core_of_thread) | |
1100 core = (*the_target->core_of_thread) (ptid); | |
1101 | |
1102 if (core != -1) | 1168 if (core != -1) |
1103 { | 1169 { |
1104 sprintf (core_s, "%d", core); | 1170 sprintf (core_s, "%d", core); |
1105 buffer_xml_printf (buffer, "<thread id=\"%s\" core=\"%s\"/>\n", | 1171 buffer_xml_printf (buffer, "<thread id=\"%s\" core=\"%s\"/>\n", |
1106 ptid_s, core_s); | 1172 ptid_s, core_s); |
1107 } | 1173 } |
1108 else | 1174 else |
1109 { | 1175 { |
1110 buffer_xml_printf (buffer, "<thread id=\"%s\"/>\n", | 1176 buffer_xml_printf (buffer, "<thread id=\"%s\"/>\n", |
1111 ptid_s); | 1177 ptid_s); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1548 } | 1614 } |
1549 else | 1615 else |
1550 target_process_qsupported (p); | 1616 target_process_qsupported (p); |
1551 | 1617 |
1552 free (p); | 1618 free (p); |
1553 } | 1619 } |
1554 | 1620 |
1555 free (qsupported); | 1621 free (qsupported); |
1556 } | 1622 } |
1557 | 1623 |
1558 sprintf (own_buf, "PacketSize=%x;QPassSignals+", PBUFSIZ - 1); | 1624 sprintf (own_buf, |
| 1625 » "PacketSize=%x;QPassSignals+;QProgramSignals+", |
| 1626 » PBUFSIZ - 1); |
1559 | 1627 |
1560 if (the_target->qxfer_libraries_svr4 != NULL) | 1628 if (the_target->qxfer_libraries_svr4 != NULL) |
1561 strcat (own_buf, ";qXfer:libraries-svr4:read+"); | 1629 strcat (own_buf, ";qXfer:libraries-svr4:read+"); |
1562 else | 1630 else |
1563 { | 1631 { |
1564 /* We do not have any hook to indicate whether the non-SVR4 target | 1632 /* We do not have any hook to indicate whether the non-SVR4 target |
1565 backend supports qXfer:libraries:read, so always report it. */ | 1633 backend supports qXfer:libraries:read, so always report it. */ |
1566 strcat (own_buf, ";qXfer:libraries:read+"); | 1634 strcat (own_buf, ";qXfer:libraries:read+"); |
1567 } | 1635 } |
1568 | 1636 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1610 if (gdb_supports_qRelocInsn && target_supports_fast_tracepoints ()) | 1678 if (gdb_supports_qRelocInsn && target_supports_fast_tracepoints ()) |
1611 strcat (own_buf, ";FastTracepoints+"); | 1679 strcat (own_buf, ";FastTracepoints+"); |
1612 strcat (own_buf, ";StaticTracepoints+"); | 1680 strcat (own_buf, ";StaticTracepoints+"); |
1613 strcat (own_buf, ";InstallInTrace+"); | 1681 strcat (own_buf, ";InstallInTrace+"); |
1614 strcat (own_buf, ";qXfer:statictrace:read+"); | 1682 strcat (own_buf, ";qXfer:statictrace:read+"); |
1615 strcat (own_buf, ";qXfer:traceframe-info:read+"); | 1683 strcat (own_buf, ";qXfer:traceframe-info:read+"); |
1616 strcat (own_buf, ";EnableDisableTracepoints+"); | 1684 strcat (own_buf, ";EnableDisableTracepoints+"); |
1617 strcat (own_buf, ";tracenz+"); | 1685 strcat (own_buf, ";tracenz+"); |
1618 } | 1686 } |
1619 | 1687 |
| 1688 /* Support target-side breakpoint conditions and commands. */ |
| 1689 strcat (own_buf, ";ConditionalBreakpoints+"); |
| 1690 strcat (own_buf, ";BreakpointCommands+"); |
| 1691 |
| 1692 if (target_supports_agent ()) |
| 1693 strcat (own_buf, ";QAgent+"); |
| 1694 |
1620 return; | 1695 return; |
1621 } | 1696 } |
1622 | 1697 |
1623 /* Thread-local storage support. */ | 1698 /* Thread-local storage support. */ |
1624 if (the_target->get_tls_address != NULL | 1699 if (the_target->get_tls_address != NULL |
1625 && strncmp ("qGetTLSAddr:", own_buf, 12) == 0) | 1700 && strncmp ("qGetTLSAddr:", own_buf, 12) == 0) |
1626 { | 1701 { |
1627 char *p = own_buf + 12; | 1702 char *p = own_buf + 12; |
1628 CORE_ADDR parts[2], address = 0; | 1703 CORE_ADDR parts[2], address = 0; |
1629 int i, err; | 1704 int i, err; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1726 free (mon); | 1801 free (mon); |
1727 return; | 1802 return; |
1728 } | 1803 } |
1729 mon[len / 2] = '\0'; | 1804 mon[len / 2] = '\0'; |
1730 | 1805 |
1731 write_ok (own_buf); | 1806 write_ok (own_buf); |
1732 | 1807 |
1733 if (the_target->handle_monitor_command == NULL | 1808 if (the_target->handle_monitor_command == NULL |
1734 || (*the_target->handle_monitor_command) (mon) == 0) | 1809 || (*the_target->handle_monitor_command) (mon) == 0) |
1735 /* Default processing. */ | 1810 /* Default processing. */ |
1736 » handle_monitor_command (mon); | 1811 » handle_monitor_command (mon, own_buf); |
1737 | 1812 |
1738 free (mon); | 1813 free (mon); |
1739 return; | 1814 return; |
1740 } | 1815 } |
1741 | 1816 |
1742 if (strncmp ("qSearch:memory:", own_buf, | 1817 if (strncmp ("qSearch:memory:", own_buf, |
1743 sizeof ("qSearch:memory:") - 1) == 0) | 1818 sizeof ("qSearch:memory:") - 1) == 0) |
1744 { | 1819 { |
1745 require_running (own_buf); | 1820 require_running (own_buf); |
1746 handle_search_memory (own_buf, packet_len); | 1821 handle_search_memory (own_buf, packet_len); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1852 goto err; | 1927 goto err; |
1853 | 1928 |
1854 if (p[0] == 'S' || p[0] == 'C') | 1929 if (p[0] == 'S' || p[0] == 'C') |
1855 { | 1930 { |
1856 int sig; | 1931 int sig; |
1857 sig = strtol (p + 1, &q, 16); | 1932 sig = strtol (p + 1, &q, 16); |
1858 if (p == q) | 1933 if (p == q) |
1859 goto err; | 1934 goto err; |
1860 p = q; | 1935 p = q; |
1861 | 1936 |
1862 » if (!target_signal_to_host_p (sig)) | 1937 » if (!gdb_signal_to_host_p (sig)) |
1863 goto err; | 1938 goto err; |
1864 » resume_info[i].sig = target_signal_to_host (sig); | 1939 » resume_info[i].sig = gdb_signal_to_host (sig); |
1865 } | 1940 } |
1866 else | 1941 else |
1867 { | 1942 { |
1868 resume_info[i].sig = 0; | 1943 resume_info[i].sig = 0; |
1869 p = p + 1; | 1944 p = p + 1; |
1870 } | 1945 } |
1871 | 1946 |
1872 if (p[0] == 0) | 1947 if (p[0] == 0) |
1873 { | 1948 { |
1874 resume_info[i].thread = minus_one_ptid; | 1949 resume_info[i].thread = minus_one_ptid; |
(...skipping 14 matching lines...) Expand all Loading... |
1889 | 1964 |
1890 resume_info[i].thread = ptid; | 1965 resume_info[i].thread = ptid; |
1891 | 1966 |
1892 i++; | 1967 i++; |
1893 } | 1968 } |
1894 } | 1969 } |
1895 | 1970 |
1896 if (i < n) | 1971 if (i < n) |
1897 resume_info[i] = default_action; | 1972 resume_info[i] = default_action; |
1898 | 1973 |
1899 /* Still used in occasional places in the backend. */ | 1974 /* `cont_thread' is still used in occasional places in the backend, |
| 1975 to implement single-thread scheduler-locking. Doesn't make sense |
| 1976 to set it if we see a stop request, or a wildcard action (one |
| 1977 with '-1' (all threads), or 'pPID.-1' (all threads of PID)). */ |
1900 if (n == 1 | 1978 if (n == 1 |
1901 && !ptid_equal (resume_info[0].thread, minus_one_ptid) | 1979 && !(ptid_equal (resume_info[0].thread, minus_one_ptid) |
| 1980 » || ptid_get_lwp (resume_info[0].thread) == -1) |
1902 && resume_info[0].kind != resume_stop) | 1981 && resume_info[0].kind != resume_stop) |
1903 cont_thread = resume_info[0].thread; | 1982 cont_thread = resume_info[0].thread; |
1904 else | 1983 else |
1905 cont_thread = minus_one_ptid; | 1984 cont_thread = minus_one_ptid; |
1906 set_desired_inferior (0); | 1985 set_desired_inferior (0); |
1907 | 1986 |
1908 if (!non_stop) | 1987 if (!non_stop) |
1909 enable_async_io (); | 1988 enable_async_io (); |
1910 | 1989 |
1911 (*the_target->resume) (resume_info, n); | 1990 (*the_target->resume) (resume_info, n); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2071 { | 2150 { |
2072 int pid; | 2151 int pid; |
2073 char *p = &own_buf[6]; | 2152 char *p = &own_buf[6]; |
2074 if (multi_process) | 2153 if (multi_process) |
2075 pid = strtol (p, NULL, 16); | 2154 pid = strtol (p, NULL, 16); |
2076 else | 2155 else |
2077 pid = signal_pid; | 2156 pid = signal_pid; |
2078 if (pid != 0 && kill_inferior (pid) == 0) | 2157 if (pid != 0 && kill_inferior (pid) == 0) |
2079 { | 2158 { |
2080 last_status.kind = TARGET_WAITKIND_SIGNALLED; | 2159 last_status.kind = TARGET_WAITKIND_SIGNALLED; |
2081 last_status.value.sig = TARGET_SIGNAL_KILL; | 2160 last_status.value.sig = GDB_SIGNAL_KILL; |
2082 last_ptid = pid_to_ptid (pid); | 2161 last_ptid = pid_to_ptid (pid); |
2083 discard_queued_stop_replies (pid); | 2162 discard_queued_stop_replies (pid); |
2084 write_ok (own_buf); | 2163 write_ok (own_buf); |
2085 return 1; | 2164 return 1; |
2086 } | 2165 } |
2087 else | 2166 else |
2088 { | 2167 { |
2089 write_enn (own_buf); | 2168 write_enn (own_buf); |
2090 return 0; | 2169 return 0; |
2091 } | 2170 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2133 return; | 2212 return; |
2134 } | 2213 } |
2135 } | 2214 } |
2136 | 2215 |
2137 if (strncmp (own_buf, "vFile:", 6) == 0 | 2216 if (strncmp (own_buf, "vFile:", 6) == 0 |
2138 && handle_vFile (own_buf, packet_len, new_packet_len)) | 2217 && handle_vFile (own_buf, packet_len, new_packet_len)) |
2139 return; | 2218 return; |
2140 | 2219 |
2141 if (strncmp (own_buf, "vAttach;", 8) == 0) | 2220 if (strncmp (own_buf, "vAttach;", 8) == 0) |
2142 { | 2221 { |
2143 if (!multi_process && target_running ()) | 2222 if ((!extended_protocol || !multi_process) && target_running ()) |
2144 { | 2223 { |
2145 fprintf (stderr, "Already debugging a process\n"); | 2224 fprintf (stderr, "Already debugging a process\n"); |
2146 write_enn (own_buf); | 2225 write_enn (own_buf); |
2147 return; | 2226 return; |
2148 } | 2227 } |
2149 handle_v_attach (own_buf); | 2228 handle_v_attach (own_buf); |
2150 return; | 2229 return; |
2151 } | 2230 } |
2152 | 2231 |
2153 if (strncmp (own_buf, "vRun;", 5) == 0) | 2232 if (strncmp (own_buf, "vRun;", 5) == 0) |
2154 { | 2233 { |
2155 if (!multi_process && target_running ()) | 2234 if ((!extended_protocol || !multi_process) && target_running ()) |
2156 { | 2235 { |
2157 fprintf (stderr, "Already debugging a process\n"); | 2236 fprintf (stderr, "Already debugging a process\n"); |
2158 write_enn (own_buf); | 2237 write_enn (own_buf); |
2159 return; | 2238 return; |
2160 } | 2239 } |
2161 handle_v_run (own_buf); | 2240 handle_v_run (own_buf); |
2162 return; | 2241 return; |
2163 } | 2242 } |
2164 | 2243 |
2165 if (strncmp (own_buf, "vKill;", 6) == 0) | 2244 if (strncmp (own_buf, "vKill;", 6) == 0) |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2294 { | 2373 { |
2295 struct thread_info *thread = (struct thread_info *) entry; | 2374 struct thread_info *thread = (struct thread_info *) entry; |
2296 | 2375 |
2297 thread->last_resume_kind = resume_stop; | 2376 thread->last_resume_kind = resume_stop; |
2298 | 2377 |
2299 if (thread->last_status.kind == TARGET_WAITKIND_IGNORE) | 2378 if (thread->last_status.kind == TARGET_WAITKIND_IGNORE) |
2300 { | 2379 { |
2301 /* Most threads are stopped implicitly (all-stop); tag that with | 2380 /* Most threads are stopped implicitly (all-stop); tag that with |
2302 signal 0. */ | 2381 signal 0. */ |
2303 thread->last_status.kind = TARGET_WAITKIND_STOPPED; | 2382 thread->last_status.kind = TARGET_WAITKIND_STOPPED; |
2304 thread->last_status.value.sig = TARGET_SIGNAL_0; | 2383 thread->last_status.value.sig = GDB_SIGNAL_0; |
2305 } | 2384 } |
2306 } | 2385 } |
2307 | 2386 |
2308 /* Set all threads' states as "want-stopped". */ | 2387 /* Set all threads' states as "want-stopped". */ |
2309 | 2388 |
2310 static void | 2389 static void |
2311 gdb_wants_all_threads_stopped (void) | 2390 gdb_wants_all_threads_stopped (void) |
2312 { | 2391 { |
2313 for_each_inferior (&all_threads, gdb_wants_thread_stopped); | 2392 for_each_inferior (&all_threads, gdb_wants_thread_stopped); |
2314 } | 2393 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2349 { | 2428 { |
2350 pause_all (0); | 2429 pause_all (0); |
2351 stabilize_threads (); | 2430 stabilize_threads (); |
2352 gdb_wants_all_threads_stopped (); | 2431 gdb_wants_all_threads_stopped (); |
2353 | 2432 |
2354 if (all_threads.head) | 2433 if (all_threads.head) |
2355 { | 2434 { |
2356 struct target_waitstatus status; | 2435 struct target_waitstatus status; |
2357 | 2436 |
2358 status.kind = TARGET_WAITKIND_STOPPED; | 2437 status.kind = TARGET_WAITKIND_STOPPED; |
2359 » status.value.sig = TARGET_SIGNAL_TRAP; | 2438 » status.value.sig = GDB_SIGNAL_TRAP; |
2360 prepare_resume_reply (own_buf, | 2439 prepare_resume_reply (own_buf, |
2361 all_threads.head->id, &status); | 2440 all_threads.head->id, &status); |
2362 } | 2441 } |
2363 else | 2442 else |
2364 strcpy (own_buf, "W00"); | 2443 strcpy (own_buf, "W00"); |
2365 } | 2444 } |
2366 } | 2445 } |
2367 | 2446 |
2368 static void | 2447 static void |
2369 gdbserver_version (void) | 2448 gdbserver_version (void) |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2517 for_each_inferior (&all_processes, detach_or_kill_inferior_callback); | 2596 for_each_inferior (&all_processes, detach_or_kill_inferior_callback); |
2518 } | 2597 } |
2519 | 2598 |
2520 int | 2599 int |
2521 main (int argc, char *argv[]) | 2600 main (int argc, char *argv[]) |
2522 { | 2601 { |
2523 int bad_attach; | 2602 int bad_attach; |
2524 int pid; | 2603 int pid; |
2525 char *arg_end, *port; | 2604 char *arg_end, *port; |
2526 char **next_arg = &argv[1]; | 2605 char **next_arg = &argv[1]; |
2527 int multi_mode = 0; | 2606 volatile int multi_mode = 0; |
2528 int attach = 0; | 2607 volatile int attach = 0; |
2529 int was_running; | 2608 int was_running; |
2530 | 2609 |
2531 while (*next_arg != NULL && **next_arg == '-') | 2610 while (*next_arg != NULL && **next_arg == '-') |
2532 { | 2611 { |
2533 if (strcmp (*next_arg, "--version") == 0) | 2612 if (strcmp (*next_arg, "--version") == 0) |
2534 { | 2613 { |
2535 gdbserver_version (); | 2614 gdbserver_version (); |
2536 exit (0); | 2615 exit (0); |
2537 } | 2616 } |
2538 else if (strcmp (*next_arg, "--help") == 0) | 2617 else if (strcmp (*next_arg, "--help") == 0) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2598 } | 2677 } |
2599 else | 2678 else |
2600 { | 2679 { |
2601 fprintf (stderr, "Don't know how to disable \"%s\".\n\n", | 2680 fprintf (stderr, "Don't know how to disable \"%s\".\n\n", |
2602 tok); | 2681 tok); |
2603 gdbserver_show_disableable (stderr); | 2682 gdbserver_show_disableable (stderr); |
2604 exit (1); | 2683 exit (1); |
2605 } | 2684 } |
2606 } | 2685 } |
2607 } | 2686 } |
| 2687 else if (strcmp (*next_arg, "-") == 0) |
| 2688 { |
| 2689 /* "-" specifies a stdio connection and is a form of port |
| 2690 specification. */ |
| 2691 *next_arg = STDIO_CONNECTION_NAME; |
| 2692 break; |
| 2693 } |
2608 else if (strcmp (*next_arg, "--disable-randomization") == 0) | 2694 else if (strcmp (*next_arg, "--disable-randomization") == 0) |
2609 disable_randomization = 1; | 2695 disable_randomization = 1; |
2610 else if (strcmp (*next_arg, "--no-disable-randomization") == 0) | 2696 else if (strcmp (*next_arg, "--no-disable-randomization") == 0) |
2611 disable_randomization = 0; | 2697 disable_randomization = 0; |
2612 else if (strcmp (*next_arg, "--once") == 0) | 2698 else if (strcmp (*next_arg, "--once") == 0) |
2613 run_once = 1; | 2699 run_once = 1; |
2614 else | 2700 else |
2615 { | 2701 { |
2616 fprintf (stderr, "Unknown argument: %s\n", *next_arg); | 2702 fprintf (stderr, "Unknown argument: %s\n", *next_arg); |
2617 exit (1); | 2703 exit (1); |
(...skipping 10 matching lines...) Expand all Loading... |
2628 } | 2714 } |
2629 | 2715 |
2630 port = *next_arg; | 2716 port = *next_arg; |
2631 next_arg++; | 2717 next_arg++; |
2632 if (port == NULL || (!attach && !multi_mode && *next_arg == NULL)) | 2718 if (port == NULL || (!attach && !multi_mode && *next_arg == NULL)) |
2633 { | 2719 { |
2634 gdbserver_usage (stderr); | 2720 gdbserver_usage (stderr); |
2635 exit (1); | 2721 exit (1); |
2636 } | 2722 } |
2637 | 2723 |
| 2724 /* We need to know whether the remote connection is stdio before |
| 2725 starting the inferior. Inferiors created in this scenario have |
| 2726 stdin,stdout redirected. So do this here before we call |
| 2727 start_inferior. */ |
| 2728 remote_prepare (port); |
| 2729 |
2638 bad_attach = 0; | 2730 bad_attach = 0; |
2639 pid = 0; | 2731 pid = 0; |
2640 | 2732 |
2641 /* --attach used to come after PORT, so allow it there for | 2733 /* --attach used to come after PORT, so allow it there for |
2642 compatibility. */ | 2734 compatibility. */ |
2643 if (*next_arg != NULL && strcmp (*next_arg, "--attach") == 0) | 2735 if (*next_arg != NULL && strcmp (*next_arg, "--attach") == 0) |
2644 { | 2736 { |
2645 attach = 1; | 2737 attach = 1; |
2646 next_arg++; | 2738 next_arg++; |
2647 } | 2739 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2699 last_ptid = minus_one_ptid; | 2791 last_ptid = minus_one_ptid; |
2700 } | 2792 } |
2701 | 2793 |
2702 /* Don't report shared library events on the initial connection, | 2794 /* Don't report shared library events on the initial connection, |
2703 even if some libraries are preloaded. Avoids the "stopped by | 2795 even if some libraries are preloaded. Avoids the "stopped by |
2704 shared library event" notice on gdb side. */ | 2796 shared library event" notice on gdb side. */ |
2705 dlls_changed = 0; | 2797 dlls_changed = 0; |
2706 | 2798 |
2707 if (setjmp (toplevel)) | 2799 if (setjmp (toplevel)) |
2708 { | 2800 { |
2709 detach_or_kill_for_exit (); | 2801 /* If something fails and longjmps while detaching or killing |
| 2802 » inferiors, we'd end up here again, stuck in an infinite loop |
| 2803 » trap. Be sure that if that happens, we exit immediately |
| 2804 » instead. */ |
| 2805 if (setjmp (toplevel) == 0) |
| 2806 » detach_or_kill_for_exit (); |
| 2807 else |
| 2808 » fprintf (stderr, "Detach or kill failed. Exiting\n"); |
2710 exit (1); | 2809 exit (1); |
2711 } | 2810 } |
2712 | 2811 |
2713 if (last_status.kind == TARGET_WAITKIND_EXITED | 2812 if (last_status.kind == TARGET_WAITKIND_EXITED |
2714 || last_status.kind == TARGET_WAITKIND_SIGNALLED) | 2813 || last_status.kind == TARGET_WAITKIND_SIGNALLED) |
2715 was_running = 0; | 2814 was_running = 0; |
2716 else | 2815 else |
2717 was_running = 1; | 2816 was_running = 1; |
2718 | 2817 |
2719 if (!was_running && !multi_mode) | 2818 if (!was_running && !multi_mode) |
2720 { | 2819 { |
2721 fprintf (stderr, "No program to debug. GDBserver exiting.\n"); | 2820 fprintf (stderr, "No program to debug. GDBserver exiting.\n"); |
2722 exit (1); | 2821 exit (1); |
2723 } | 2822 } |
2724 | 2823 |
2725 remote_prepare (port); | |
2726 | |
2727 while (1) | 2824 while (1) |
2728 { | 2825 { |
2729 noack_mode = 0; | 2826 noack_mode = 0; |
2730 multi_process = 0; | 2827 multi_process = 0; |
2731 /* Be sure we're out of tfind mode. */ | 2828 /* Be sure we're out of tfind mode. */ |
2732 current_traceframe = -1; | 2829 current_traceframe = -1; |
2733 | 2830 |
2734 remote_open (port); | 2831 remote_open (port); |
2735 | 2832 |
2736 if (setjmp (toplevel) != 0) | 2833 if (setjmp (toplevel) != 0) |
(...skipping 10 matching lines...) Expand all Loading... |
2747 removed from the event loop. */ | 2844 removed from the event loop. */ |
2748 start_event_loop (); | 2845 start_event_loop (); |
2749 | 2846 |
2750 /* If an exit was requested (using the "monitor exit" command), | 2847 /* If an exit was requested (using the "monitor exit" command), |
2751 terminate now. The only other way to get here is for | 2848 terminate now. The only other way to get here is for |
2752 getpkt to fail; close the connection and reopen it at the | 2849 getpkt to fail; close the connection and reopen it at the |
2753 top of the loop. */ | 2850 top of the loop. */ |
2754 | 2851 |
2755 if (exit_requested || run_once) | 2852 if (exit_requested || run_once) |
2756 { | 2853 { |
2757 » detach_or_kill_for_exit (); | 2854 » /* If something fails and longjmps while detaching or |
2758 » exit (0); | 2855 » killing inferiors, we'd end up here again, stuck in an |
| 2856 » infinite loop trap. Be sure that if that happens, we |
| 2857 » exit immediately instead. */ |
| 2858 » if (setjmp (toplevel) == 0) |
| 2859 » { |
| 2860 » detach_or_kill_for_exit (); |
| 2861 » exit (0); |
| 2862 » } |
| 2863 » else |
| 2864 » { |
| 2865 » fprintf (stderr, "Detach or kill failed. Exiting\n"); |
| 2866 » exit (1); |
| 2867 » } |
2759 } | 2868 } |
2760 | 2869 |
2761 fprintf (stderr, | 2870 fprintf (stderr, |
2762 "Remote side has terminated connection. " | 2871 "Remote side has terminated connection. " |
2763 "GDBserver will reopen the connection.\n"); | 2872 "GDBserver will reopen the connection.\n"); |
2764 | 2873 |
2765 if (tracing) | 2874 if (tracing) |
2766 { | 2875 { |
2767 if (disconnected_tracing) | 2876 if (disconnected_tracing) |
2768 { | 2877 { |
(...skipping 15 matching lines...) Expand all Loading... |
2784 else | 2893 else |
2785 { | 2894 { |
2786 fprintf (stderr, | 2895 fprintf (stderr, |
2787 "Disconnected tracing disabled; stopping trace run.\n"); | 2896 "Disconnected tracing disabled; stopping trace run.\n"); |
2788 stop_tracing (); | 2897 stop_tracing (); |
2789 } | 2898 } |
2790 } | 2899 } |
2791 } | 2900 } |
2792 } | 2901 } |
2793 | 2902 |
| 2903 /* Process options coming from Z packets for *point at address |
| 2904 POINT_ADDR. PACKET is the packet buffer. *PACKET is updated |
| 2905 to point to the first char after the last processed option. */ |
| 2906 |
| 2907 static void |
| 2908 process_point_options (CORE_ADDR point_addr, char **packet) |
| 2909 { |
| 2910 char *dataptr = *packet; |
| 2911 int persist; |
| 2912 |
| 2913 /* Check if data has the correct format. */ |
| 2914 if (*dataptr != ';') |
| 2915 return; |
| 2916 |
| 2917 dataptr++; |
| 2918 |
| 2919 while (*dataptr) |
| 2920 { |
| 2921 if (*dataptr == ';') |
| 2922 ++dataptr; |
| 2923 |
| 2924 if (*dataptr == 'X') |
| 2925 { |
| 2926 /* Conditional expression. */ |
| 2927 fprintf (stderr, "Found breakpoint condition.\n"); |
| 2928 add_breakpoint_condition (point_addr, &dataptr); |
| 2929 } |
| 2930 else if (strncmp (dataptr, "cmds:", strlen ("cmds:")) == 0) |
| 2931 { |
| 2932 dataptr += strlen ("cmds:"); |
| 2933 if (debug_threads) |
| 2934 fprintf (stderr, "Found breakpoint commands %s.\n", dataptr); |
| 2935 persist = (*dataptr == '1'); |
| 2936 dataptr += 2; |
| 2937 add_breakpoint_commands (point_addr, &dataptr, persist); |
| 2938 } |
| 2939 else |
| 2940 { |
| 2941 /* Unrecognized token, just skip it. */ |
| 2942 fprintf (stderr, "Unknown token %c, ignoring.\n", |
| 2943 *dataptr); |
| 2944 } |
| 2945 |
| 2946 /* Skip tokens until we find one that we recognize. */ |
| 2947 while (*dataptr && *dataptr != 'X' && *dataptr != ';') |
| 2948 dataptr++; |
| 2949 } |
| 2950 *packet = dataptr; |
| 2951 } |
| 2952 |
2794 /* Event loop callback that handles a serial event. The first byte in | 2953 /* Event loop callback that handles a serial event. The first byte in |
2795 the serial buffer gets us here. We expect characters to arrive at | 2954 the serial buffer gets us here. We expect characters to arrive at |
2796 a brisk pace, so we read the rest of the packet with a blocking | 2955 a brisk pace, so we read the rest of the packet with a blocking |
2797 getpkt call. */ | 2956 getpkt call. */ |
2798 | 2957 |
2799 static int | 2958 static int |
2800 process_serial_event (void) | 2959 process_serial_event (void) |
2801 { | 2960 { |
2802 char ch; | 2961 char ch; |
2803 int i = 0; | 2962 int i = 0; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2844 | 3003 |
2845 if (multi_process) | 3004 if (multi_process) |
2846 { | 3005 { |
2847 i++; /* skip ';' */ | 3006 i++; /* skip ';' */ |
2848 pid = strtol (&own_buf[i], NULL, 16); | 3007 pid = strtol (&own_buf[i], NULL, 16); |
2849 } | 3008 } |
2850 else | 3009 else |
2851 pid = | 3010 pid = |
2852 ptid_get_pid (((struct inferior_list_entry *) current_inferior)->id); | 3011 ptid_get_pid (((struct inferior_list_entry *) current_inferior)->id); |
2853 | 3012 |
2854 if (tracing && disconnected_tracing) | 3013 if ((tracing && disconnected_tracing) || any_persistent_commands ()) |
2855 { | 3014 { |
2856 struct thread_resume resume_info; | 3015 struct thread_resume resume_info; |
2857 struct process_info *process = find_process_pid (pid); | 3016 struct process_info *process = find_process_pid (pid); |
2858 | 3017 |
2859 if (process == NULL) | 3018 if (process == NULL) |
2860 { | 3019 { |
2861 write_enn (own_buf); | 3020 write_enn (own_buf); |
2862 break; | 3021 break; |
2863 } | 3022 } |
2864 | 3023 |
2865 » fprintf (stderr, | 3024 » if (tracing && disconnected_tracing) |
2866 » » "Disconnected tracing in effect, " | 3025 » fprintf (stderr, |
2867 » » "leaving gdbserver attached to the process\n"); | 3026 » » "Disconnected tracing in effect, " |
| 3027 » » "leaving gdbserver attached to the process\n"); |
| 3028 |
| 3029 » if (any_persistent_commands ()) |
| 3030 » fprintf (stderr, |
| 3031 » » "Persistent commands are present, " |
| 3032 » » "leaving gdbserver attached to the process\n"); |
2868 | 3033 |
2869 /* Make sure we're in non-stop/async mode, so we we can both | 3034 /* Make sure we're in non-stop/async mode, so we we can both |
2870 wait for an async socket accept, and handle async target | 3035 wait for an async socket accept, and handle async target |
2871 events simultaneously. There's also no point either in | 3036 events simultaneously. There's also no point either in |
2872 having the target stop all threads, when we're going to | 3037 having the target stop all threads, when we're going to |
2873 pass signals down without informing GDB. */ | 3038 pass signals down without informing GDB. */ |
2874 if (!non_stop) | 3039 if (!non_stop) |
2875 { | 3040 { |
2876 if (debug_threads) | 3041 if (debug_threads) |
2877 fprintf (stderr, "Forcing non-stop mode\n"); | 3042 fprintf (stderr, "Forcing non-stop mode\n"); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3058 if (decode_X_packet (&own_buf[1], packet_len - 1, | 3223 if (decode_X_packet (&own_buf[1], packet_len - 1, |
3059 &mem_addr, &len, &mem_buf) < 0 | 3224 &mem_addr, &len, &mem_buf) < 0 |
3060 || gdb_write_memory (mem_addr, mem_buf, len) != 0) | 3225 || gdb_write_memory (mem_addr, mem_buf, len) != 0) |
3061 write_enn (own_buf); | 3226 write_enn (own_buf); |
3062 else | 3227 else |
3063 write_ok (own_buf); | 3228 write_ok (own_buf); |
3064 break; | 3229 break; |
3065 case 'C': | 3230 case 'C': |
3066 require_running (own_buf); | 3231 require_running (own_buf); |
3067 convert_ascii_to_int (own_buf + 1, &sig, 1); | 3232 convert_ascii_to_int (own_buf + 1, &sig, 1); |
3068 if (target_signal_to_host_p (sig)) | 3233 if (gdb_signal_to_host_p (sig)) |
3069 » signal = target_signal_to_host (sig); | 3234 » signal = gdb_signal_to_host (sig); |
3070 else | 3235 else |
3071 signal = 0; | 3236 signal = 0; |
3072 myresume (own_buf, 0, signal); | 3237 myresume (own_buf, 0, signal); |
3073 break; | 3238 break; |
3074 case 'S': | 3239 case 'S': |
3075 require_running (own_buf); | 3240 require_running (own_buf); |
3076 convert_ascii_to_int (own_buf + 1, &sig, 1); | 3241 convert_ascii_to_int (own_buf + 1, &sig, 1); |
3077 if (target_signal_to_host_p (sig)) | 3242 if (gdb_signal_to_host_p (sig)) |
3078 » signal = target_signal_to_host (sig); | 3243 » signal = gdb_signal_to_host (sig); |
3079 else | 3244 else |
3080 signal = 0; | 3245 signal = 0; |
3081 myresume (own_buf, 1, signal); | 3246 myresume (own_buf, 1, signal); |
3082 break; | 3247 break; |
3083 case 'c': | 3248 case 'c': |
3084 require_running (own_buf); | 3249 require_running (own_buf); |
3085 signal = 0; | 3250 signal = 0; |
3086 myresume (own_buf, 0, signal); | 3251 myresume (own_buf, 0, signal); |
3087 break; | 3252 break; |
3088 case 's': | 3253 case 's': |
(...skipping 17 matching lines...) Expand all Loading... |
3106 res = 1; | 3271 res = 1; |
3107 switch (type) | 3272 switch (type) |
3108 { | 3273 { |
3109 case '0': /* software-breakpoint */ | 3274 case '0': /* software-breakpoint */ |
3110 case '1': /* hardware-breakpoint */ | 3275 case '1': /* hardware-breakpoint */ |
3111 case '2': /* write watchpoint */ | 3276 case '2': /* write watchpoint */ |
3112 case '3': /* read watchpoint */ | 3277 case '3': /* read watchpoint */ |
3113 case '4': /* access watchpoint */ | 3278 case '4': /* access watchpoint */ |
3114 require_running (own_buf); | 3279 require_running (own_buf); |
3115 if (insert && the_target->insert_point != NULL) | 3280 if (insert && the_target->insert_point != NULL) |
3116 » res = (*the_target->insert_point) (type, addr, len); | 3281 » { |
| 3282 » » /* Insert the breakpoint. If it is already inserted, nothing |
| 3283 » » will take place. */ |
| 3284 » » res = (*the_target->insert_point) (type, addr, len); |
| 3285 |
| 3286 » » /* GDB may have sent us a list of *point parameters to be |
| 3287 » » evaluated on the target's side. Read such list here. If we |
| 3288 » » already have a list of parameters, GDB is telling us to drop |
| 3289 » » that list and use this one instead. */ |
| 3290 » » if (!res && (type == '0' || type == '1')) |
| 3291 » » { |
| 3292 » » /* Remove previous conditions. */ |
| 3293 » » clear_gdb_breakpoint_conditions (addr); |
| 3294 » » process_point_options (addr, &dataptr); |
| 3295 » » } |
| 3296 » } |
3117 else if (!insert && the_target->remove_point != NULL) | 3297 else if (!insert && the_target->remove_point != NULL) |
3118 res = (*the_target->remove_point) (type, addr, len); | 3298 res = (*the_target->remove_point) (type, addr, len); |
3119 break; | 3299 break; |
3120 default: | 3300 default: |
3121 break; | 3301 break; |
3122 } | 3302 } |
3123 | 3303 |
3124 if (res == 0) | 3304 if (res == 0) |
3125 write_ok (own_buf); | 3305 write_ok (own_buf); |
3126 else if (res == 1) | 3306 else if (res == 1) |
(...skipping 11 matching lines...) Expand all Loading... |
3138 return 0; | 3318 return 0; |
3139 | 3319 |
3140 fprintf (stderr, "Killing all inferiors\n"); | 3320 fprintf (stderr, "Killing all inferiors\n"); |
3141 for_each_inferior (&all_processes, kill_inferior_callback); | 3321 for_each_inferior (&all_processes, kill_inferior_callback); |
3142 | 3322 |
3143 /* When using the extended protocol, we wait with no program | 3323 /* When using the extended protocol, we wait with no program |
3144 running. The traditional protocol will exit instead. */ | 3324 running. The traditional protocol will exit instead. */ |
3145 if (extended_protocol) | 3325 if (extended_protocol) |
3146 { | 3326 { |
3147 last_status.kind = TARGET_WAITKIND_EXITED; | 3327 last_status.kind = TARGET_WAITKIND_EXITED; |
3148 » last_status.value.sig = TARGET_SIGNAL_KILL; | 3328 » last_status.value.sig = GDB_SIGNAL_KILL; |
3149 return 0; | 3329 return 0; |
3150 } | 3330 } |
3151 else | 3331 else |
3152 exit (0); | 3332 exit (0); |
3153 | 3333 |
3154 case 'T': | 3334 case 'T': |
3155 { | 3335 { |
3156 ptid_t gdb_id, thread_id; | 3336 ptid_t gdb_id, thread_id; |
3157 | 3337 |
3158 require_running (own_buf); | 3338 require_running (own_buf); |
(...skipping 23 matching lines...) Expand all Loading... |
3182 for_each_inferior (&all_processes, | 3362 for_each_inferior (&all_processes, |
3183 kill_inferior_callback); | 3363 kill_inferior_callback); |
3184 fprintf (stderr, "GDBserver restarting\n"); | 3364 fprintf (stderr, "GDBserver restarting\n"); |
3185 | 3365 |
3186 /* Wait till we are at 1st instruction in prog. */ | 3366 /* Wait till we are at 1st instruction in prog. */ |
3187 if (program_argv != NULL) | 3367 if (program_argv != NULL) |
3188 start_inferior (program_argv); | 3368 start_inferior (program_argv); |
3189 else | 3369 else |
3190 { | 3370 { |
3191 last_status.kind = TARGET_WAITKIND_EXITED; | 3371 last_status.kind = TARGET_WAITKIND_EXITED; |
3192 » last_status.value.sig = TARGET_SIGNAL_KILL; | 3372 » last_status.value.sig = GDB_SIGNAL_KILL; |
3193 } | 3373 } |
3194 return 0; | 3374 return 0; |
3195 } | 3375 } |
3196 else | 3376 else |
3197 { | 3377 { |
3198 /* It is a request we don't understand. Respond with an | 3378 /* It is a request we don't understand. Respond with an |
3199 empty packet so that gdb knows that we don't support this | 3379 empty packet so that gdb knows that we don't support this |
3200 request. */ | 3380 request. */ |
3201 own_buf[0] = '\0'; | 3381 own_buf[0] = '\0'; |
3202 break; | 3382 break; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3306 struct thread_resume resume_info; | 3486 struct thread_resume resume_info; |
3307 | 3487 |
3308 if (debug_threads) | 3488 if (debug_threads) |
3309 fprintf (stderr, | 3489 fprintf (stderr, |
3310 "GDB not connected; forwarding event %d for [%s]\n", | 3490 "GDB not connected; forwarding event %d for [%s]\n", |
3311 (int) last_status.kind, | 3491 (int) last_status.kind, |
3312 target_pid_to_str (last_ptid)); | 3492 target_pid_to_str (last_ptid)); |
3313 | 3493 |
3314 resume_info.thread = last_ptid; | 3494 resume_info.thread = last_ptid; |
3315 resume_info.kind = resume_continue; | 3495 resume_info.kind = resume_continue; |
3316 » resume_info.sig = target_signal_to_host (last_status.value.sig); | 3496 » resume_info.sig = gdb_signal_to_host (last_status.value.sig); |
3317 (*the_target->resume) (&resume_info, 1); | 3497 (*the_target->resume) (&resume_info, 1); |
3318 } | 3498 } |
3319 else if (debug_threads) | 3499 else if (debug_threads) |
3320 fprintf (stderr, "GDB not connected; ignoring event %d for [%s]\n", | 3500 fprintf (stderr, "GDB not connected; ignoring event %d for [%s]\n", |
3321 (int) last_status.kind, | 3501 (int) last_status.kind, |
3322 target_pid_to_str (last_ptid)); | 3502 target_pid_to_str (last_ptid)); |
3323 } | 3503 } |
3324 else | 3504 else |
3325 { | 3505 { |
3326 /* Something interesting. Tell GDB about it. */ | 3506 /* Something interesting. Tell GDB about it. */ |
3327 push_event (last_ptid, &last_status); | 3507 push_event (last_ptid, &last_status); |
3328 } | 3508 } |
3329 } | 3509 } |
3330 | 3510 |
3331 /* Be sure to not change the selected inferior behind GDB's back. | 3511 /* Be sure to not change the selected inferior behind GDB's back. |
3332 Important in the non-stop mode asynchronous protocol. */ | 3512 Important in the non-stop mode asynchronous protocol. */ |
3333 set_desired_inferior (1); | 3513 set_desired_inferior (1); |
3334 | 3514 |
3335 return 0; | 3515 return 0; |
3336 } | 3516 } |
OLD | NEW |