1 /* Main code for remote server for GDB.
2 Copyright (C) 1989, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
34 ptid_t general_thread;
38 static int extended_protocol;
39 static int response_needed;
40 static int exit_requested;
42 /* --once: Exit after the first connection has closed. */
48 /* Whether we should attempt to disable the operating system's address
49 space randomization feature before starting an inferior. */
50 int disable_randomization = 1;
52 static char **program_argv, **wrapper_argv;
54 /* Enable miscellaneous debugging output. The name is historical - it
55 was originally used to debug LinuxThreads support. */
58 /* Enable debugging of h/w breakpoint/watchpoint support. */
61 int pass_signals[TARGET_SIGNAL_LAST];
65 const char *gdbserver_xmltarget;
67 /* The PID of the originally created or attached inferior. Used to
68 send signals to the process when GDB sends us an asynchronous interrupt
69 (user hitting Control-C in the client), and to wait for the child to exit
70 when no longer debugging it. */
72 unsigned long signal_pid;
75 /* A file descriptor for the controlling terminal. */
78 /* TERMINAL_FD's original foreground group. */
79 pid_t old_foreground_pgrp;
81 /* Hand back terminal ownership to the original foreground group. */
84 restore_old_foreground_pgrp (void)
86 tcsetpgrp (terminal_fd, old_foreground_pgrp);
90 /* Set if you want to disable optional thread related packets support
91 in gdbserver, for the sake of testing GDB against stubs that don't
93 int disable_packet_vCont;
94 int disable_packet_Tthread;
95 int disable_packet_qC;
96 int disable_packet_qfThreadInfo;
98 /* Last status reported to GDB. */
99 static struct target_waitstatus last_status;
100 static ptid_t last_ptid;
102 static char *own_buf;
103 static unsigned char *mem_buf;
105 /* Structure holding information relative to a single stop reply. We
106 keep a queue of these (really a singly-linked list) to push to GDB
110 /* Pointer to next in list. */
111 struct vstop_notif *next;
113 /* Thread or process that got the event. */
117 struct target_waitstatus status;
120 /* The pending stop replies list head. */
121 static struct vstop_notif *notif_queue = NULL;
123 /* Put a stop reply to the stop reply queue. */
126 queue_stop_reply (ptid_t ptid, struct target_waitstatus *status)
128 struct vstop_notif *new_notif;
130 new_notif = xmalloc (sizeof (*new_notif));
131 new_notif->next = NULL;
132 new_notif->ptid = ptid;
133 new_notif->status = *status;
137 struct vstop_notif *tail;
138 for (tail = notif_queue;
142 tail->next = new_notif;
145 notif_queue = new_notif;
150 struct vstop_notif *n;
152 for (n = notif_queue; n; n = n->next)
155 fprintf (stderr, "pending stop replies: %d\n", i);
159 /* Place an event in the stop reply queue, and push a notification if
160 we aren't sending one yet. */
163 push_event (ptid_t ptid, struct target_waitstatus *status)
165 gdb_assert (status->kind != TARGET_WAITKIND_IGNORE);
167 queue_stop_reply (ptid, status);
169 /* If this is the first stop reply in the queue, then inform GDB
170 about it, by sending a Stop notification. */
171 if (notif_queue->next == NULL)
176 prepare_resume_reply (p,
177 notif_queue->ptid, ¬if_queue->status);
178 putpkt_notif (own_buf);
182 /* Get rid of the currently pending stop replies for PID. If PID is
183 -1, then apply to all processes. */
186 discard_queued_stop_replies (int pid)
188 struct vstop_notif *prev = NULL, *reply, *next;
190 for (reply = notif_queue; reply; reply = next)
195 || ptid_get_pid (reply->ptid) == pid)
197 if (reply == notif_queue)
200 prev->next = reply->next;
209 /* If there are more stop replies to push, push one now. */
212 send_next_stop_reply (char *own_buf)
215 prepare_resume_reply (own_buf,
217 ¬if_queue->status);
223 target_running (void)
225 return all_threads.head != NULL;
229 start_inferior (char **argv)
231 char **new_argv = argv;
233 if (wrapper_argv != NULL)
237 for (i = 0; wrapper_argv[i] != NULL; i++)
239 for (i = 0; argv[i] != NULL; i++)
241 new_argv = alloca (sizeof (char *) * count);
243 for (i = 0; wrapper_argv[i] != NULL; i++)
244 new_argv[count++] = wrapper_argv[i];
245 for (i = 0; argv[i] != NULL; i++)
246 new_argv[count++] = argv[i];
247 new_argv[count] = NULL;
253 for (i = 0; new_argv[i]; ++i)
254 fprintf (stderr, "new_argv[%d] = \"%s\"\n", i, new_argv[i]);
259 signal (SIGTTOU, SIG_DFL);
260 signal (SIGTTIN, SIG_DFL);
263 signal_pid = create_inferior (new_argv[0], new_argv);
265 /* FIXME: we don't actually know at this point that the create
266 actually succeeded. We won't know that until we wait. */
267 fprintf (stderr, "Process %s created; pid = %ld\n", argv[0],
272 signal (SIGTTOU, SIG_IGN);
273 signal (SIGTTIN, SIG_IGN);
274 terminal_fd = fileno (stderr);
275 old_foreground_pgrp = tcgetpgrp (terminal_fd);
276 tcsetpgrp (terminal_fd, signal_pid);
277 atexit (restore_old_foreground_pgrp);
280 if (wrapper_argv != NULL)
282 struct thread_resume resume_info;
284 resume_info.thread = pid_to_ptid (signal_pid);
285 resume_info.kind = resume_continue;
288 mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
290 if (last_status.kind != TARGET_WAITKIND_STOPPED)
295 (*the_target->resume) (&resume_info, 1);
297 mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
298 if (last_status.kind != TARGET_WAITKIND_STOPPED)
301 current_inferior->last_resume_kind = resume_stop;
302 current_inferior->last_status = last_status;
304 while (last_status.value.sig != TARGET_SIGNAL_TRAP);
306 current_inferior->last_resume_kind = resume_stop;
307 current_inferior->last_status = last_status;
311 /* Wait till we are at 1st instruction in program, return new pid
312 (assuming success). */
313 last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
315 if (last_status.kind != TARGET_WAITKIND_EXITED
316 && last_status.kind != TARGET_WAITKIND_SIGNALLED)
318 current_inferior->last_resume_kind = resume_stop;
319 current_inferior->last_status = last_status;
326 attach_inferior (int pid)
328 /* myattach should return -1 if attaching is unsupported,
329 0 if it succeeded, and call error() otherwise. */
331 if (myattach (pid) != 0)
334 fprintf (stderr, "Attached; pid = %d\n", pid);
337 /* FIXME - It may be that we should get the SIGNAL_PID from the
338 attach function, so that it can be the main thread instead of
339 whichever we were told to attach to. */
344 last_ptid = mywait (pid_to_ptid (pid), &last_status, 0, 0);
346 /* GDB knows to ignore the first SIGSTOP after attaching to a running
347 process using the "attach" command, but this is different; it's
348 just using "target remote". Pretend it's just starting up. */
349 if (last_status.kind == TARGET_WAITKIND_STOPPED
350 && last_status.value.sig == TARGET_SIGNAL_STOP)
351 last_status.value.sig = TARGET_SIGNAL_TRAP;
353 current_inferior->last_resume_kind = resume_stop;
354 current_inferior->last_status = last_status;
360 extern int remote_debug;
362 /* Decode a qXfer read request. Return 0 if everything looks OK,
366 decode_xfer_read (char *buf, CORE_ADDR *ofs, unsigned int *len)
368 /* After the read marker and annex, qXfer looks like a
369 traditional 'm' packet. */
370 decode_m_packet (buf, ofs, len);
376 decode_xfer (char *buf, char **object, char **rw, char **annex, char **offset)
378 /* Extract and NUL-terminate the object. */
380 while (*buf && *buf != ':')
386 /* Extract and NUL-terminate the read/write action. */
388 while (*buf && *buf != ':')
394 /* Extract and NUL-terminate the annex. */
396 while (*buf && *buf != ':')
406 /* Write the response to a successful qXfer read. Returns the
407 length of the (binary) data stored in BUF, corresponding
408 to as much of DATA/LEN as we could fit. IS_MORE controls
409 the first character of the response. */
411 write_qxfer_response (char *buf, const void *data, int len, int is_more)
420 return remote_escape_output (data, len, (unsigned char *) buf + 1, &out_len,
424 /* Handle all of the extended 'Q' packets. */
427 handle_general_set (char *own_buf)
429 if (strncmp ("QPassSignals:", own_buf, strlen ("QPassSignals:")) == 0)
431 int numsigs = (int) TARGET_SIGNAL_LAST, i;
432 const char *p = own_buf + strlen ("QPassSignals:");
435 p = decode_address_to_semicolon (&cursig, p);
436 for (i = 0; i < numsigs; i++)
442 /* Keep looping, to clear the remaining signals. */
445 p = decode_address_to_semicolon (&cursig, p);
450 strcpy (own_buf, "OK");
454 if (strcmp (own_buf, "QStartNoAckMode") == 0)
458 fprintf (stderr, "[noack mode enabled]\n");
467 if (strncmp (own_buf, "QNonStop:", 9) == 0)
469 char *mode = own_buf + 9;
473 if (strcmp (mode, "0") == 0)
475 else if (strcmp (mode, "1") == 0)
479 /* We don't know what this mode is, so complain to
481 fprintf (stderr, "Unknown non-stop mode requested: %s\n",
487 req_str = req ? "non-stop" : "all-stop";
488 if (start_non_stop (req) != 0)
490 fprintf (stderr, "Setting %s mode failed\n", req_str);
498 fprintf (stderr, "[%s mode enabled]\n", req_str);
504 if (strncmp ("QDisableRandomization:", own_buf,
505 strlen ("QDisableRandomization:")) == 0)
507 char *packet = own_buf + strlen ("QDisableRandomization:");
510 unpack_varlen_hex (packet, &setting);
511 disable_randomization = setting;
515 if (disable_randomization)
516 fprintf (stderr, "[address space randomization disabled]\n");
518 fprintf (stderr, "[address space randomization enabled]\n");
525 if (target_supports_tracepoints ()
526 && handle_tracepoint_general_set (own_buf))
529 /* Otherwise we didn't know what packet it was. Say we didn't
535 get_features_xml (const char *annex)
537 /* gdbserver_xmltarget defines what to return when looking
538 for the "target.xml" file. Its contents can either be
539 verbatim XML code (prefixed with a '@') or else the name
540 of the actual XML file to be used in place of "target.xml".
542 This variable is set up from the auto-generated
543 init_registers_... routine for the current target. */
545 if (gdbserver_xmltarget
546 && strcmp (annex, "target.xml") == 0)
548 if (*gdbserver_xmltarget == '@')
549 return gdbserver_xmltarget + 1;
551 annex = gdbserver_xmltarget;
556 extern const char *const xml_builtin[][2];
559 /* Look for the annex. */
560 for (i = 0; xml_builtin[i][0] != NULL; i++)
561 if (strcmp (annex, xml_builtin[i][0]) == 0)
564 if (xml_builtin[i][0] != NULL)
565 return xml_builtin[i][1];
573 monitor_show_help (void)
575 monitor_output ("The following monitor commands are supported:\n");
576 monitor_output (" set debug <0|1>\n");
577 monitor_output (" Enable general debugging messages\n");
578 monitor_output (" set debug-hw-points <0|1>\n");
579 monitor_output (" Enable h/w breakpoint/watchpoint debugging messages\n");
580 monitor_output (" set remote-debug <0|1>\n");
581 monitor_output (" Enable remote protocol debugging messages\n");
582 monitor_output (" exit\n");
583 monitor_output (" Quit GDBserver\n");
586 /* Read trace frame or inferior memory. Returns the number of bytes
587 actually read, zero when no further transfer is possible, and -1 on
588 error. Return of a positive value smaller than LEN does not
589 indicate there's no more to be read, only the end of the transfer.
590 E.g., when GDB reads memory from a traceframe, a first request may
591 be served from a memory block that does not cover the whole request
592 length. A following request gets the rest served from either
593 another block (of the same traceframe) or from the read-only
597 gdb_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
601 if (current_traceframe >= 0)
604 ULONGEST length = len;
606 if (traceframe_read_mem (current_traceframe,
607 memaddr, myaddr, len, &nbytes))
609 /* Data read from trace buffer, we're done. */
612 if (!in_readonly_region (memaddr, length))
614 /* Otherwise we have a valid readonly case, fall through. */
615 /* (assume no half-trace half-real blocks for now) */
618 res = prepare_to_access_memory ();
621 res = read_inferior_memory (memaddr, myaddr, len);
622 done_accessing_memory ();
624 return res == 0 ? len : -1;
630 /* Write trace frame or inferior memory. Actually, writing to trace
631 frames is forbidden. */
634 gdb_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
636 if (current_traceframe >= 0)
642 ret = prepare_to_access_memory ();
645 ret = write_inferior_memory (memaddr, myaddr, len);
646 done_accessing_memory ();
652 /* Subroutine of handle_search_memory to simplify it. */
655 handle_search_memory_1 (CORE_ADDR start_addr, CORE_ADDR search_space_len,
656 gdb_byte *pattern, unsigned pattern_len,
657 gdb_byte *search_buf,
658 unsigned chunk_size, unsigned search_buf_size,
659 CORE_ADDR *found_addrp)
661 /* Prime the search buffer. */
663 if (gdb_read_memory (start_addr, search_buf, search_buf_size)
666 warning ("Unable to access target memory at 0x%lx, halting search.",
671 /* Perform the search.
673 The loop is kept simple by allocating [N + pattern-length - 1] bytes.
674 When we've scanned N bytes we copy the trailing bytes to the start and
675 read in another N bytes. */
677 while (search_space_len >= pattern_len)
680 unsigned nr_search_bytes = (search_space_len < search_buf_size
684 found_ptr = memmem (search_buf, nr_search_bytes, pattern, pattern_len);
686 if (found_ptr != NULL)
688 CORE_ADDR found_addr = start_addr + (found_ptr - search_buf);
689 *found_addrp = found_addr;
693 /* Not found in this chunk, skip to next chunk. */
695 /* Don't let search_space_len wrap here, it's unsigned. */
696 if (search_space_len >= chunk_size)
697 search_space_len -= chunk_size;
699 search_space_len = 0;
701 if (search_space_len >= pattern_len)
703 unsigned keep_len = search_buf_size - chunk_size;
704 CORE_ADDR read_addr = start_addr + chunk_size + keep_len;
707 /* Copy the trailing part of the previous iteration to the front
708 of the buffer for the next iteration. */
709 memcpy (search_buf, search_buf + chunk_size, keep_len);
711 nr_to_read = (search_space_len - keep_len < chunk_size
712 ? search_space_len - keep_len
715 if (gdb_read_memory (read_addr, search_buf + keep_len,
716 nr_to_read) != search_buf_size)
718 warning ("Unable to access target memory "
719 "at 0x%lx, halting search.",
724 start_addr += chunk_size;
733 /* Handle qSearch:memory packets. */
736 handle_search_memory (char *own_buf, int packet_len)
738 CORE_ADDR start_addr;
739 CORE_ADDR search_space_len;
741 unsigned int pattern_len;
742 /* NOTE: also defined in find.c testcase. */
743 #define SEARCH_CHUNK_SIZE 16000
744 const unsigned chunk_size = SEARCH_CHUNK_SIZE;
745 /* Buffer to hold memory contents for searching. */
746 gdb_byte *search_buf;
747 unsigned search_buf_size;
749 CORE_ADDR found_addr;
750 int cmd_name_len = sizeof ("qSearch:memory:") - 1;
752 pattern = malloc (packet_len);
755 error ("Unable to allocate memory to perform the search");
756 strcpy (own_buf, "E00");
759 if (decode_search_memory_packet (own_buf + cmd_name_len,
760 packet_len - cmd_name_len,
761 &start_addr, &search_space_len,
762 pattern, &pattern_len) < 0)
765 error ("Error in parsing qSearch:memory packet");
766 strcpy (own_buf, "E00");
770 search_buf_size = chunk_size + pattern_len - 1;
772 /* No point in trying to allocate a buffer larger than the search space. */
773 if (search_space_len < search_buf_size)
774 search_buf_size = search_space_len;
776 search_buf = malloc (search_buf_size);
777 if (search_buf == NULL)
780 error ("Unable to allocate memory to perform the search");
781 strcpy (own_buf, "E00");
785 found = handle_search_memory_1 (start_addr, search_space_len,
786 pattern, pattern_len,
787 search_buf, chunk_size, search_buf_size,
791 sprintf (own_buf, "1,%lx", (long) found_addr);
793 strcpy (own_buf, "0");
795 strcpy (own_buf, "E00");
801 #define require_running(BUF) \
802 if (!target_running ()) \
808 /* Handle monitor commands not handled by target-specific handlers. */
811 handle_monitor_command (char *mon)
813 if (strcmp (mon, "set debug 1") == 0)
816 monitor_output ("Debug output enabled.\n");
818 else if (strcmp (mon, "set debug 0") == 0)
821 monitor_output ("Debug output disabled.\n");
823 else if (strcmp (mon, "set debug-hw-points 1") == 0)
826 monitor_output ("H/W point debugging output enabled.\n");
828 else if (strcmp (mon, "set debug-hw-points 0") == 0)
831 monitor_output ("H/W point debugging output disabled.\n");
833 else if (strcmp (mon, "set remote-debug 1") == 0)
836 monitor_output ("Protocol debug output enabled.\n");
838 else if (strcmp (mon, "set remote-debug 0") == 0)
841 monitor_output ("Protocol debug output disabled.\n");
843 else if (strcmp (mon, "help") == 0)
844 monitor_show_help ();
845 else if (strcmp (mon, "exit") == 0)
849 monitor_output ("Unknown monitor command.\n\n");
850 monitor_show_help ();
855 /* Associates a callback with each supported qXfer'able object. */
859 /* The object this handler handles. */
862 /* Request that the target transfer up to LEN 8-bit bytes of the
863 target's OBJECT. The OFFSET, for a seekable object, specifies
864 the starting point. The ANNEX can be used to provide additional
865 data-specific information to the target.
867 Return the number of bytes actually transfered, zero when no
868 further transfer is possible, -1 on error, and -2 when the
869 transfer is not supported. Return of a positive value smaller
870 than LEN does not indicate the end of the object, only the end of
873 One, and only one, of readbuf or writebuf must be non-NULL. */
874 int (*xfer) (const char *annex,
875 gdb_byte *readbuf, const gdb_byte *writebuf,
876 ULONGEST offset, LONGEST len);
879 /* Handle qXfer:auxv:read. */
882 handle_qxfer_auxv (const char *annex,
883 gdb_byte *readbuf, const gdb_byte *writebuf,
884 ULONGEST offset, LONGEST len)
886 if (the_target->read_auxv == NULL || writebuf != NULL)
889 if (annex[0] != '\0' || !target_running ())
892 return (*the_target->read_auxv) (offset, readbuf, len);
895 /* Handle qXfer:features:read. */
898 handle_qxfer_features (const char *annex,
899 gdb_byte *readbuf, const gdb_byte *writebuf,
900 ULONGEST offset, LONGEST len)
902 const char *document;
905 if (writebuf != NULL)
908 if (!target_running ())
911 /* Grab the correct annex. */
912 document = get_features_xml (annex);
913 if (document == NULL)
916 total_len = strlen (document);
918 if (offset > total_len)
921 if (offset + len > total_len)
922 len = total_len - offset;
924 memcpy (readbuf, document + offset, len);
928 /* Handle qXfer:libraries:read. */
931 handle_qxfer_libraries (const char *annex,
932 gdb_byte *readbuf, const gdb_byte *writebuf,
933 ULONGEST offset, LONGEST len)
935 unsigned int total_len;
937 struct inferior_list_entry *dll_ptr;
939 if (writebuf != NULL)
942 if (annex[0] != '\0' || !target_running ())
945 /* Over-estimate the necessary memory. Assume that every character
946 in the library name must be escaped. */
948 for (dll_ptr = all_dlls.head; dll_ptr != NULL; dll_ptr = dll_ptr->next)
949 total_len += 128 + 6 * strlen (((struct dll_info *) dll_ptr)->name);
951 document = malloc (total_len);
952 if (document == NULL)
955 strcpy (document, "<library-list>\n");
956 p = document + strlen (document);
958 for (dll_ptr = all_dlls.head; dll_ptr != NULL; dll_ptr = dll_ptr->next)
960 struct dll_info *dll = (struct dll_info *) dll_ptr;
963 strcpy (p, " <library name=\"");
965 name = xml_escape_text (dll->name);
969 strcpy (p, "\"><segment address=\"");
971 sprintf (p, "0x%lx", (long) dll->base_addr);
973 strcpy (p, "\"/></library>\n");
977 strcpy (p, "</library-list>\n");
979 total_len = strlen (document);
981 if (offset > total_len)
987 if (offset + len > total_len)
988 len = total_len - offset;
990 memcpy (readbuf, document + offset, len);
995 /* Handle qXfer:osadata:read. */
998 handle_qxfer_osdata (const char *annex,
999 gdb_byte *readbuf, const gdb_byte *writebuf,
1000 ULONGEST offset, LONGEST len)
1002 if (the_target->qxfer_osdata == NULL || writebuf != NULL)
1005 return (*the_target->qxfer_osdata) (annex, readbuf, NULL, offset, len);
1008 /* Handle qXfer:siginfo:read and qXfer:siginfo:write. */
1011 handle_qxfer_siginfo (const char *annex,
1012 gdb_byte *readbuf, const gdb_byte *writebuf,
1013 ULONGEST offset, LONGEST len)
1015 if (the_target->qxfer_siginfo == NULL)
1018 if (annex[0] != '\0' || !target_running ())
1021 return (*the_target->qxfer_siginfo) (annex, readbuf, writebuf, offset, len);
1024 /* Handle qXfer:spu:read and qXfer:spu:write. */
1027 handle_qxfer_spu (const char *annex,
1028 gdb_byte *readbuf, const gdb_byte *writebuf,
1029 ULONGEST offset, LONGEST len)
1031 if (the_target->qxfer_spu == NULL)
1034 if (!target_running ())
1037 return (*the_target->qxfer_spu) (annex, readbuf, writebuf, offset, len);
1040 /* Handle qXfer:statictrace:read. */
1043 handle_qxfer_statictrace (const char *annex,
1044 gdb_byte *readbuf, const gdb_byte *writebuf,
1045 ULONGEST offset, LONGEST len)
1049 if (writebuf != NULL)
1052 if (annex[0] != '\0' || !target_running () || current_traceframe == -1)
1055 if (traceframe_read_sdata (current_traceframe, offset,
1056 readbuf, len, &nbytes))
1061 /* Helper for handle_qxfer_threads. */
1064 handle_qxfer_threads_proper (struct buffer *buffer)
1066 struct inferior_list_entry *thread;
1068 buffer_grow_str (buffer, "<threads>\n");
1070 for (thread = all_threads.head; thread; thread = thread->next)
1072 ptid_t ptid = thread_to_gdb_id ((struct thread_info *)thread);
1077 write_ptid (ptid_s, ptid);
1079 if (the_target->core_of_thread)
1080 core = (*the_target->core_of_thread) (ptid);
1084 sprintf (core_s, "%d", core);
1085 buffer_xml_printf (buffer, "<thread id=\"%s\" core=\"%s\"/>\n",
1090 buffer_xml_printf (buffer, "<thread id=\"%s\"/>\n",
1095 buffer_grow_str0 (buffer, "</threads>\n");
1098 /* Handle qXfer:threads:read. */
1101 handle_qxfer_threads (const char *annex,
1102 gdb_byte *readbuf, const gdb_byte *writebuf,
1103 ULONGEST offset, LONGEST len)
1105 static char *result = 0;
1106 static unsigned int result_length = 0;
1108 if (writebuf != NULL)
1111 if (!target_running () || annex[0] != '\0')
1116 struct buffer buffer;
1117 /* When asked for data at offset 0, generate everything and store into
1118 'result'. Successive reads will be served off 'result'. */
1122 buffer_init (&buffer);
1124 handle_qxfer_threads_proper (&buffer);
1126 result = buffer_finish (&buffer);
1127 result_length = strlen (result);
1128 buffer_free (&buffer);
1131 if (offset >= result_length)
1133 /* We're out of data. */
1140 if (len > result_length - offset)
1141 len = result_length - offset;
1143 memcpy (readbuf, result + offset, len);
1148 /* Handle qXfer:traceframe-info:read. */
1151 handle_qxfer_traceframe_info (const char *annex,
1152 gdb_byte *readbuf, const gdb_byte *writebuf,
1153 ULONGEST offset, LONGEST len)
1155 static char *result = 0;
1156 static unsigned int result_length = 0;
1158 if (writebuf != NULL)
1161 if (!target_running () || annex[0] != '\0' || current_traceframe == -1)
1166 struct buffer buffer;
1168 /* When asked for data at offset 0, generate everything and
1169 store into 'result'. Successive reads will be served off
1173 buffer_init (&buffer);
1175 traceframe_read_info (current_traceframe, &buffer);
1177 result = buffer_finish (&buffer);
1178 result_length = strlen (result);
1179 buffer_free (&buffer);
1182 if (offset >= result_length)
1184 /* We're out of data. */
1191 if (len > result_length - offset)
1192 len = result_length - offset;
1194 memcpy (readbuf, result + offset, len);
1198 /* Handle qXfer:fdpic:read. */
1201 handle_qxfer_fdpic (const char *annex, gdb_byte *readbuf,
1202 const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
1204 if (the_target->read_loadmap == NULL)
1207 if (!target_running ())
1210 return (*the_target->read_loadmap) (annex, offset, readbuf, len);
1213 static const struct qxfer qxfer_packets[] =
1215 { "auxv", handle_qxfer_auxv },
1216 { "fdpic", handle_qxfer_fdpic},
1217 { "features", handle_qxfer_features },
1218 { "libraries", handle_qxfer_libraries },
1219 { "osdata", handle_qxfer_osdata },
1220 { "siginfo", handle_qxfer_siginfo },
1221 { "spu", handle_qxfer_spu },
1222 { "statictrace", handle_qxfer_statictrace },
1223 { "threads", handle_qxfer_threads },
1224 { "traceframe-info", handle_qxfer_traceframe_info },
1228 handle_qxfer (char *own_buf, int packet_len, int *new_packet_len_p)
1236 if (strncmp (own_buf, "qXfer:", 6) != 0)
1239 /* Grab the object, r/w and annex. */
1240 if (decode_xfer (own_buf + 6, &object, &rw, &annex, &offset) < 0)
1242 write_enn (own_buf);
1247 i < sizeof (qxfer_packets) / sizeof (qxfer_packets[0]);
1250 const struct qxfer *q = &qxfer_packets[i];
1252 if (strcmp (object, q->object) == 0)
1254 if (strcmp (rw, "read") == 0)
1256 unsigned char *data;
1261 /* Grab the offset and length. */
1262 if (decode_xfer_read (offset, &ofs, &len) < 0)
1264 write_enn (own_buf);
1268 /* Read one extra byte, as an indicator of whether there is
1270 if (len > PBUFSIZ - 2)
1272 data = malloc (len + 1);
1275 write_enn (own_buf);
1278 n = (*q->xfer) (annex, data, NULL, ofs, len + 1);
1285 write_enn (own_buf);
1287 *new_packet_len_p = write_qxfer_response (own_buf, data, len, 1);
1289 *new_packet_len_p = write_qxfer_response (own_buf, data, n, 0);
1294 else if (strcmp (rw, "write") == 0)
1299 unsigned char *data;
1301 strcpy (own_buf, "E00");
1302 data = malloc (packet_len - (offset - own_buf));
1305 write_enn (own_buf);
1308 if (decode_xfer_write (offset, packet_len - (offset - own_buf),
1309 &ofs, &len, data) < 0)
1312 write_enn (own_buf);
1316 n = (*q->xfer) (annex, NULL, data, ofs, len);
1323 write_enn (own_buf);
1325 sprintf (own_buf, "%x", n);
1338 /* Table used by the crc32 function to calcuate the checksum. */
1340 static unsigned int crc32_table[256] =
1343 /* Compute 32 bit CRC from inferior memory.
1345 On success, return 32 bit CRC.
1346 On failure, return (unsigned long long) -1. */
1348 static unsigned long long
1349 crc32 (CORE_ADDR base, int len, unsigned int crc)
1351 if (!crc32_table[1])
1353 /* Initialize the CRC table and the decoding table. */
1357 for (i = 0; i < 256; i++)
1359 for (c = i << 24, j = 8; j > 0; --j)
1360 c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1);
1367 unsigned char byte = 0;
1369 /* Return failure if memory read fails. */
1370 if (read_inferior_memory (base, &byte, 1) != 0)
1371 return (unsigned long long) -1;
1373 crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ byte) & 255];
1376 return (unsigned long long) crc;
1379 /* Handle all of the extended 'q' packets. */
1382 handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
1384 static struct inferior_list_entry *thread_ptr;
1386 /* Reply the current thread id. */
1387 if (strcmp ("qC", own_buf) == 0 && !disable_packet_qC)
1390 require_running (own_buf);
1392 if (!ptid_equal (general_thread, null_ptid)
1393 && !ptid_equal (general_thread, minus_one_ptid))
1394 gdb_id = general_thread;
1397 thread_ptr = all_threads.head;
1398 gdb_id = thread_to_gdb_id ((struct thread_info *)thread_ptr);
1401 sprintf (own_buf, "QC");
1403 write_ptid (own_buf, gdb_id);
1407 if (strcmp ("qSymbol::", own_buf) == 0)
1409 /* GDB is suggesting new symbols have been loaded. This may
1410 mean a new shared library has been detected as loaded, so
1411 take the opportunity to check if breakpoints we think are
1412 inserted, still are. Note that it isn't guaranteed that
1413 we'll see this when a shared library is loaded, and nor will
1414 we see this for unloads (although breakpoints in unloaded
1415 libraries shouldn't trigger), as GDB may not find symbols for
1416 the library at all. We also re-validate breakpoints when we
1417 see a second GDB breakpoint for the same address, and or when
1418 we access breakpoint shadows. */
1419 validate_breakpoints ();
1421 if (target_supports_tracepoints ())
1422 tracepoint_look_up_symbols ();
1424 if (target_running () && the_target->look_up_symbols != NULL)
1425 (*the_target->look_up_symbols) ();
1427 strcpy (own_buf, "OK");
1431 if (!disable_packet_qfThreadInfo)
1433 if (strcmp ("qfThreadInfo", own_buf) == 0)
1437 require_running (own_buf);
1438 thread_ptr = all_threads.head;
1441 gdb_id = thread_to_gdb_id ((struct thread_info *)thread_ptr);
1442 write_ptid (own_buf, gdb_id);
1443 thread_ptr = thread_ptr->next;
1447 if (strcmp ("qsThreadInfo", own_buf) == 0)
1451 require_running (own_buf);
1452 if (thread_ptr != NULL)
1455 gdb_id = thread_to_gdb_id ((struct thread_info *)thread_ptr);
1456 write_ptid (own_buf, gdb_id);
1457 thread_ptr = thread_ptr->next;
1462 sprintf (own_buf, "l");
1468 if (the_target->read_offsets != NULL
1469 && strcmp ("qOffsets", own_buf) == 0)
1471 CORE_ADDR text, data;
1473 require_running (own_buf);
1474 if (the_target->read_offsets (&text, &data))
1475 sprintf (own_buf, "Text=%lX;Data=%lX;Bss=%lX",
1476 (long)text, (long)data, (long)data);
1478 write_enn (own_buf);
1483 /* Protocol features query. */
1484 if (strncmp ("qSupported", own_buf, 10) == 0
1485 && (own_buf[10] == ':' || own_buf[10] == '\0'))
1487 char *p = &own_buf[10];
1488 int gdb_supports_qRelocInsn = 0;
1490 /* Start processing qSupported packet. */
1491 target_process_qsupported (NULL);
1493 /* Process each feature being provided by GDB. The first
1494 feature will follow a ':', and latter features will follow
1498 char **qsupported = NULL;
1502 /* Two passes, to avoid nested strtok calls in
1503 target_process_qsupported. */
1504 for (p = strtok (p + 1, ";");
1506 p = strtok (NULL, ";"))
1509 qsupported = xrealloc (qsupported, count * sizeof (char *));
1510 qsupported[count - 1] = xstrdup (p);
1513 for (i = 0; i < count; i++)
1516 if (strcmp (p, "multiprocess+") == 0)
1518 /* GDB supports and wants multi-process support if
1520 if (target_supports_multi_process ())
1523 else if (strcmp (p, "qRelocInsn+") == 0)
1525 /* GDB supports relocate instruction requests. */
1526 gdb_supports_qRelocInsn = 1;
1529 target_process_qsupported (p);
1537 sprintf (own_buf, "PacketSize=%x;QPassSignals+", PBUFSIZ - 1);
1539 /* We do not have any hook to indicate whether the target backend
1540 supports qXfer:libraries:read, so always report it. */
1541 strcat (own_buf, ";qXfer:libraries:read+");
1543 if (the_target->read_auxv != NULL)
1544 strcat (own_buf, ";qXfer:auxv:read+");
1546 if (the_target->qxfer_spu != NULL)
1547 strcat (own_buf, ";qXfer:spu:read+;qXfer:spu:write+");
1549 if (the_target->qxfer_siginfo != NULL)
1550 strcat (own_buf, ";qXfer:siginfo:read+;qXfer:siginfo:write+");
1552 if (the_target->read_loadmap != NULL)
1553 strcat (own_buf, ";qXfer:fdpic:read+");
1555 /* We always report qXfer:features:read, as targets may
1556 install XML files on a subsequent call to arch_setup.
1557 If we reported to GDB on startup that we don't support
1558 qXfer:feature:read at all, we will never be re-queried. */
1559 strcat (own_buf, ";qXfer:features:read+");
1561 if (transport_is_reliable)
1562 strcat (own_buf, ";QStartNoAckMode+");
1564 if (the_target->qxfer_osdata != NULL)
1565 strcat (own_buf, ";qXfer:osdata:read+");
1567 if (target_supports_multi_process ())
1568 strcat (own_buf, ";multiprocess+");
1570 if (target_supports_non_stop ())
1571 strcat (own_buf, ";QNonStop+");
1573 if (target_supports_disable_randomization ())
1574 strcat (own_buf, ";QDisableRandomization+");
1576 strcat (own_buf, ";qXfer:threads:read+");
1578 if (target_supports_tracepoints ())
1580 strcat (own_buf, ";ConditionalTracepoints+");
1581 strcat (own_buf, ";TraceStateVariables+");
1582 strcat (own_buf, ";TracepointSource+");
1583 strcat (own_buf, ";DisconnectedTracing+");
1584 if (gdb_supports_qRelocInsn && target_supports_fast_tracepoints ())
1585 strcat (own_buf, ";FastTracepoints+");
1586 strcat (own_buf, ";StaticTracepoints+");
1587 strcat (own_buf, ";qXfer:statictrace:read+");
1588 strcat (own_buf, ";qXfer:traceframe-info:read+");
1589 strcat (own_buf, ";EnableDisableTracepoints+");
1590 strcat (own_buf, ";tracenz+");
1596 /* Thread-local storage support. */
1597 if (the_target->get_tls_address != NULL
1598 && strncmp ("qGetTLSAddr:", own_buf, 12) == 0)
1600 char *p = own_buf + 12;
1601 CORE_ADDR parts[2], address = 0;
1603 ptid_t ptid = null_ptid;
1605 require_running (own_buf);
1607 for (i = 0; i < 3; i++)
1615 p2 = strchr (p, ',');
1628 ptid = read_ptid (p, NULL);
1630 decode_address (&parts[i - 1], p, len);
1634 if (p != NULL || i < 3)
1638 struct thread_info *thread = find_thread_ptid (ptid);
1643 err = the_target->get_tls_address (thread, parts[0], parts[1],
1649 strcpy (own_buf, paddress(address));
1654 write_enn (own_buf);
1658 /* Otherwise, pretend we do not understand this packet. */
1661 /* Windows OS Thread Information Block address support. */
1662 if (the_target->get_tib_address != NULL
1663 && strncmp ("qGetTIBAddr:", own_buf, 12) == 0)
1668 ptid_t ptid = read_ptid (own_buf + 12, &annex);
1670 n = (*the_target->get_tib_address) (ptid, &tlb);
1673 strcpy (own_buf, paddress(tlb));
1678 write_enn (own_buf);
1684 /* Handle "monitor" commands. */
1685 if (strncmp ("qRcmd,", own_buf, 6) == 0)
1687 char *mon = malloc (PBUFSIZ);
1688 int len = strlen (own_buf + 6);
1692 write_enn (own_buf);
1696 if ((len % 2) != 0 || unhexify (mon, own_buf + 6, len / 2) != len / 2)
1698 write_enn (own_buf);
1702 mon[len / 2] = '\0';
1706 if (the_target->handle_monitor_command == NULL
1707 || (*the_target->handle_monitor_command) (mon) == 0)
1708 /* Default processing. */
1709 handle_monitor_command (mon);
1715 if (strncmp ("qSearch:memory:", own_buf,
1716 sizeof ("qSearch:memory:") - 1) == 0)
1718 require_running (own_buf);
1719 handle_search_memory (own_buf, packet_len);
1723 if (strcmp (own_buf, "qAttached") == 0
1724 || strncmp (own_buf, "qAttached:", sizeof ("qAttached:") - 1) == 0)
1726 struct process_info *process;
1728 if (own_buf[sizeof ("qAttached") - 1])
1730 int pid = strtoul (own_buf + sizeof ("qAttached:") - 1, NULL, 16);
1731 process = (struct process_info *)
1732 find_inferior_id (&all_processes, pid_to_ptid (pid));
1736 require_running (own_buf);
1737 process = current_process ();
1740 if (process == NULL)
1742 write_enn (own_buf);
1746 strcpy (own_buf, process->attached ? "1" : "0");
1750 if (strncmp ("qCRC:", own_buf, 5) == 0)
1752 /* CRC check (compare-section). */
1756 unsigned long long crc;
1758 require_running (own_buf);
1759 base = strtoul (own_buf + 5, &comma, 16);
1760 if (*comma++ != ',')
1762 write_enn (own_buf);
1765 len = strtoul (comma, NULL, 16);
1766 crc = crc32 (base, len, 0xffffffff);
1767 /* Check for memory failure. */
1768 if (crc == (unsigned long long) -1)
1770 write_enn (own_buf);
1773 sprintf (own_buf, "C%lx", (unsigned long) crc);
1777 if (handle_qxfer (own_buf, packet_len, new_packet_len_p))
1780 if (target_supports_tracepoints () && handle_tracepoint_query (own_buf))
1783 /* Otherwise we didn't know what packet it was. Say we didn't
1788 static void gdb_wants_all_threads_stopped (void);
1790 /* Parse vCont packets. */
1792 handle_v_cont (char *own_buf)
1796 struct thread_resume *resume_info;
1797 struct thread_resume default_action = {{0}};
1799 /* Count the number of semicolons in the packet. There should be one
1800 for every action. */
1806 p = strchr (p, ';');
1809 resume_info = malloc (n * sizeof (resume_info[0]));
1810 if (resume_info == NULL)
1818 if (p[0] == 's' || p[0] == 'S')
1819 resume_info[i].kind = resume_step;
1820 else if (p[0] == 'c' || p[0] == 'C')
1821 resume_info[i].kind = resume_continue;
1822 else if (p[0] == 't')
1823 resume_info[i].kind = resume_stop;
1827 if (p[0] == 'S' || p[0] == 'C')
1830 sig = strtol (p + 1, &q, 16);
1835 if (!target_signal_to_host_p (sig))
1837 resume_info[i].sig = target_signal_to_host (sig);
1841 resume_info[i].sig = 0;
1847 resume_info[i].thread = minus_one_ptid;
1848 default_action = resume_info[i];
1850 /* Note: we don't increment i here, we'll overwrite this entry
1851 the next time through. */
1853 else if (p[0] == ':')
1855 ptid_t ptid = read_ptid (p + 1, &q);
1860 if (p[0] != ';' && p[0] != 0)
1863 resume_info[i].thread = ptid;
1870 resume_info[i] = default_action;
1872 /* Still used in occasional places in the backend. */
1874 && !ptid_equal (resume_info[0].thread, minus_one_ptid)
1875 && resume_info[0].kind != resume_stop)
1876 cont_thread = resume_info[0].thread;
1878 cont_thread = minus_one_ptid;
1879 set_desired_inferior (0);
1884 (*the_target->resume) (resume_info, n);
1892 last_ptid = mywait (minus_one_ptid, &last_status, 0, 1);
1894 if (last_status.kind != TARGET_WAITKIND_EXITED
1895 && last_status.kind != TARGET_WAITKIND_SIGNALLED)
1896 current_inferior->last_status = last_status;
1898 /* From the client's perspective, all-stop mode always stops all
1899 threads implicitly (and the target backend has already done
1900 so by now). Tag all threads as "want-stopped", so we don't
1901 resume them implicitly without the client telling us to. */
1902 gdb_wants_all_threads_stopped ();
1903 prepare_resume_reply (own_buf, last_ptid, &last_status);
1904 disable_async_io ();
1906 if (last_status.kind == TARGET_WAITKIND_EXITED
1907 || last_status.kind == TARGET_WAITKIND_SIGNALLED)
1908 mourn_inferior (find_process_pid (ptid_get_pid (last_ptid)));
1913 write_enn (own_buf);
1918 /* Attach to a new program. Return 1 if successful, 0 if failure. */
1920 handle_v_attach (char *own_buf)
1924 pid = strtol (own_buf + 8, NULL, 16);
1925 if (pid != 0 && attach_inferior (pid) == 0)
1927 /* Don't report shared library events after attaching, even if
1928 some libraries are preloaded. GDB will always poll the
1929 library list. Avoids the "stopped by shared library event"
1930 notice on the GDB side. */
1935 /* In non-stop, we don't send a resume reply. Stop events
1936 will follow up using the normal notification
1941 prepare_resume_reply (own_buf, last_ptid, &last_status);
1947 write_enn (own_buf);
1952 /* Run a new program. Return 1 if successful, 0 if failure. */
1954 handle_v_run (char *own_buf)
1956 char *p, *next_p, **new_argv;
1960 for (p = own_buf + strlen ("vRun;"); p && *p; p = strchr (p, ';'))
1966 new_argv = calloc (new_argc + 2, sizeof (char *));
1967 if (new_argv == NULL)
1969 write_enn (own_buf);
1974 for (p = own_buf + strlen ("vRun;"); *p; p = next_p)
1976 next_p = strchr (p, ';');
1978 next_p = p + strlen (p);
1980 if (i == 0 && p == next_p)
1984 /* FIXME: Fail request if out of memory instead of dying. */
1985 new_argv[i] = xmalloc (1 + (next_p - p) / 2);
1986 unhexify (new_argv[i], p, (next_p - p) / 2);
1987 new_argv[i][(next_p - p) / 2] = '\0';
1996 if (new_argv[0] == NULL)
1998 /* GDB didn't specify a program to run. Use the program from the
1999 last run with the new argument list. */
2001 if (program_argv == NULL)
2003 write_enn (own_buf);
2004 freeargv (new_argv);
2008 new_argv[0] = strdup (program_argv[0]);
2009 if (new_argv[0] == NULL)
2011 write_enn (own_buf);
2012 freeargv (new_argv);
2017 /* Free the old argv and install the new one. */
2018 freeargv (program_argv);
2019 program_argv = new_argv;
2021 start_inferior (program_argv);
2022 if (last_status.kind == TARGET_WAITKIND_STOPPED)
2024 prepare_resume_reply (own_buf, last_ptid, &last_status);
2026 /* In non-stop, sending a resume reply doesn't set the general
2027 thread, but GDB assumes a vRun sets it (this is so GDB can
2028 query which is the main thread of the new inferior. */
2030 general_thread = last_ptid;
2036 write_enn (own_buf);
2041 /* Kill process. Return 1 if successful, 0 if failure. */
2043 handle_v_kill (char *own_buf)
2046 char *p = &own_buf[6];
2048 pid = strtol (p, NULL, 16);
2051 if (pid != 0 && kill_inferior (pid) == 0)
2053 last_status.kind = TARGET_WAITKIND_SIGNALLED;
2054 last_status.value.sig = TARGET_SIGNAL_KILL;
2055 last_ptid = pid_to_ptid (pid);
2056 discard_queued_stop_replies (pid);
2062 write_enn (own_buf);
2067 /* Handle a 'vStopped' packet. */
2069 handle_v_stopped (char *own_buf)
2071 /* If we're waiting for GDB to acknowledge a pending stop reply,
2072 consider that done. */
2075 struct vstop_notif *head;
2078 fprintf (stderr, "vStopped: acking %s\n",
2079 target_pid_to_str (notif_queue->ptid));
2082 notif_queue = notif_queue->next;
2086 /* Push another stop reply, or if there are no more left, an OK. */
2087 send_next_stop_reply (own_buf);
2090 /* Handle all of the extended 'v' packets. */
2092 handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
2094 if (!disable_packet_vCont)
2096 if (strncmp (own_buf, "vCont;", 6) == 0)
2098 require_running (own_buf);
2099 handle_v_cont (own_buf);
2103 if (strncmp (own_buf, "vCont?", 6) == 0)
2105 strcpy (own_buf, "vCont;c;C;s;S;t");
2110 if (strncmp (own_buf, "vFile:", 6) == 0
2111 && handle_vFile (own_buf, packet_len, new_packet_len))
2114 if (strncmp (own_buf, "vAttach;", 8) == 0)
2116 if (!multi_process && target_running ())
2118 fprintf (stderr, "Already debugging a process\n");
2119 write_enn (own_buf);
2122 handle_v_attach (own_buf);
2126 if (strncmp (own_buf, "vRun;", 5) == 0)
2128 if (!multi_process && target_running ())
2130 fprintf (stderr, "Already debugging a process\n");
2131 write_enn (own_buf);
2134 handle_v_run (own_buf);
2138 if (strncmp (own_buf, "vKill;", 6) == 0)
2140 if (!target_running ())
2142 fprintf (stderr, "No process to kill\n");
2143 write_enn (own_buf);
2146 handle_v_kill (own_buf);
2150 if (strncmp (own_buf, "vStopped", 8) == 0)
2152 handle_v_stopped (own_buf);
2156 /* Otherwise we didn't know what packet it was. Say we didn't
2162 /* Resume inferior and wait for another event. In non-stop mode,
2163 don't really wait here, but return immediatelly to the event
2166 myresume (char *own_buf, int step, int sig)
2168 struct thread_resume resume_info[2];
2170 int valid_cont_thread;
2172 set_desired_inferior (0);
2174 valid_cont_thread = (!ptid_equal (cont_thread, null_ptid)
2175 && !ptid_equal (cont_thread, minus_one_ptid));
2177 if (step || sig || valid_cont_thread)
2179 resume_info[0].thread
2180 = ((struct inferior_list_entry *) current_inferior)->id;
2182 resume_info[0].kind = resume_step;
2184 resume_info[0].kind = resume_continue;
2185 resume_info[0].sig = sig;
2189 if (!valid_cont_thread)
2191 resume_info[n].thread = minus_one_ptid;
2192 resume_info[n].kind = resume_continue;
2193 resume_info[n].sig = 0;
2200 (*the_target->resume) (resume_info, n);
2206 last_ptid = mywait (minus_one_ptid, &last_status, 0, 1);
2208 if (last_status.kind != TARGET_WAITKIND_EXITED
2209 && last_status.kind != TARGET_WAITKIND_SIGNALLED)
2211 current_inferior->last_resume_kind = resume_stop;
2212 current_inferior->last_status = last_status;
2215 prepare_resume_reply (own_buf, last_ptid, &last_status);
2216 disable_async_io ();
2218 if (last_status.kind == TARGET_WAITKIND_EXITED
2219 || last_status.kind == TARGET_WAITKIND_SIGNALLED)
2220 mourn_inferior (find_process_pid (ptid_get_pid (last_ptid)));
2224 /* Callback for for_each_inferior. Make a new stop reply for each
2228 queue_stop_reply_callback (struct inferior_list_entry *entry, void *arg)
2230 struct thread_info *thread = (struct thread_info *) entry;
2232 /* For now, assume targets that don't have this callback also don't
2233 manage the thread's last_status field. */
2234 if (the_target->thread_stopped == NULL)
2236 /* Pass the last stop reply back to GDB, but don't notify
2238 queue_stop_reply (entry->id, &thread->last_status);
2242 if (thread_stopped (thread))
2246 "Reporting thread %s as already stopped with %s\n",
2247 target_pid_to_str (entry->id),
2248 target_waitstatus_to_string (&thread->last_status));
2250 gdb_assert (thread->last_status.kind != TARGET_WAITKIND_IGNORE);
2252 /* Pass the last stop reply back to GDB, but don't notify
2254 queue_stop_reply (entry->id, &thread->last_status);
2261 /* Set this inferior threads's state as "want-stopped". We won't
2262 resume this thread until the client gives us another action for
2266 gdb_wants_thread_stopped (struct inferior_list_entry *entry)
2268 struct thread_info *thread = (struct thread_info *) entry;
2270 thread->last_resume_kind = resume_stop;
2272 if (thread->last_status.kind == TARGET_WAITKIND_IGNORE)
2274 /* Most threads are stopped implicitly (all-stop); tag that with
2276 thread->last_status.kind = TARGET_WAITKIND_STOPPED;
2277 thread->last_status.value.sig = TARGET_SIGNAL_0;
2281 /* Set all threads' states as "want-stopped". */
2284 gdb_wants_all_threads_stopped (void)
2286 for_each_inferior (&all_threads, gdb_wants_thread_stopped);
2289 /* Clear the gdb_detached flag of every process. */
2292 gdb_reattached_process (struct inferior_list_entry *entry)
2294 struct process_info *process = (struct process_info *) entry;
2296 process->gdb_detached = 0;
2299 /* Status handler for the '?' packet. */
2302 handle_status (char *own_buf)
2304 /* GDB is connected, don't forward events to the target anymore. */
2305 for_each_inferior (&all_processes, gdb_reattached_process);
2307 /* In non-stop mode, we must send a stop reply for each stopped
2308 thread. In all-stop mode, just send one for the first stopped
2313 discard_queued_stop_replies (-1);
2314 find_inferior (&all_threads, queue_stop_reply_callback, NULL);
2316 /* The first is sent immediatly. OK is sent if there is no
2317 stopped thread, which is the same handling of the vStopped
2318 packet (by design). */
2319 send_next_stop_reply (own_buf);
2324 stabilize_threads ();
2325 gdb_wants_all_threads_stopped ();
2327 if (all_threads.head)
2329 struct target_waitstatus status;
2331 status.kind = TARGET_WAITKIND_STOPPED;
2332 status.value.sig = TARGET_SIGNAL_TRAP;
2333 prepare_resume_reply (own_buf,
2334 all_threads.head->id, &status);
2337 strcpy (own_buf, "W00");
2342 gdbserver_version (void)
2344 printf ("GNU gdbserver %s%s\n"
2345 "Copyright (C) 2011 Free Software Foundation, Inc.\n"
2346 "gdbserver is free software, covered by the "
2347 "GNU General Public License.\n"
2348 "This gdbserver was configured as \"%s\"\n",
2349 PKGVERSION, version, host_name);
2353 gdbserver_usage (FILE *stream)
2355 fprintf (stream, "Usage:\tgdbserver [OPTIONS] COMM PROG [ARGS ...]\n"
2356 "\tgdbserver [OPTIONS] --attach COMM PID\n"
2357 "\tgdbserver [OPTIONS] --multi COMM\n"
2359 "COMM may either be a tty device (for serial debugging), or \n"
2360 "HOST:PORT to listen for a TCP connection.\n"
2363 " --debug Enable general debugging output.\n"
2364 " --remote-debug Enable remote protocol debugging output.\n"
2365 " --version Display version information and exit.\n"
2366 " --wrapper WRAPPER -- Run WRAPPER to start new programs.\n"
2367 " --once Exit after the first connection has "
2369 if (REPORT_BUGS_TO[0] && stream == stdout)
2370 fprintf (stream, "Report bugs to \"%s\".\n", REPORT_BUGS_TO);
2374 gdbserver_show_disableable (FILE *stream)
2376 fprintf (stream, "Disableable packets:\n"
2377 " vCont \tAll vCont packets\n"
2378 " qC \tQuerying the current thread\n"
2379 " qfThreadInfo\tThread listing\n"
2380 " Tthread \tPassing the thread specifier in the "
2381 "T stop reply packet\n"
2382 " threads \tAll of the above\n");
2386 #undef require_running
2387 #define require_running(BUF) \
2388 if (!target_running ()) \
2395 first_thread_of (struct inferior_list_entry *entry, void *args)
2397 int pid = * (int *) args;
2399 if (ptid_get_pid (entry->id) == pid)
2406 kill_inferior_callback (struct inferior_list_entry *entry)
2408 struct process_info *process = (struct process_info *) entry;
2409 int pid = ptid_get_pid (process->head.id);
2411 kill_inferior (pid);
2412 discard_queued_stop_replies (pid);
2415 /* Callback for for_each_inferior to detach or kill the inferior,
2416 depending on whether we attached to it or not.
2417 We inform the user whether we're detaching or killing the process
2418 as this is only called when gdbserver is about to exit. */
2421 detach_or_kill_inferior_callback (struct inferior_list_entry *entry)
2423 struct process_info *process = (struct process_info *) entry;
2424 int pid = ptid_get_pid (process->head.id);
2426 if (process->attached)
2427 detach_inferior (pid);
2429 kill_inferior (pid);
2431 discard_queued_stop_replies (pid);
2434 /* for_each_inferior callback for detach_or_kill_for_exit to print
2435 the pids of started inferiors. */
2438 print_started_pid (struct inferior_list_entry *entry)
2440 struct process_info *process = (struct process_info *) entry;
2442 if (! process->attached)
2444 int pid = ptid_get_pid (process->head.id);
2445 fprintf (stderr, " %d", pid);
2449 /* for_each_inferior callback for detach_or_kill_for_exit to print
2450 the pids of attached inferiors. */
2453 print_attached_pid (struct inferior_list_entry *entry)
2455 struct process_info *process = (struct process_info *) entry;
2457 if (process->attached)
2459 int pid = ptid_get_pid (process->head.id);
2460 fprintf (stderr, " %d", pid);
2464 /* Call this when exiting gdbserver with possible inferiors that need
2465 to be killed or detached from. */
2468 detach_or_kill_for_exit (void)
2470 /* First print a list of the inferiors we will be killing/detaching.
2471 This is to assist the user, for example, in case the inferior unexpectedly
2472 dies after we exit: did we screw up or did the inferior exit on its own?
2473 Having this info will save some head-scratching. */
2475 if (have_started_inferiors_p ())
2477 fprintf (stderr, "Killing process(es):");
2478 for_each_inferior (&all_processes, print_started_pid);
2479 fprintf (stderr, "\n");
2481 if (have_attached_inferiors_p ())
2483 fprintf (stderr, "Detaching process(es):");
2484 for_each_inferior (&all_processes, print_attached_pid);
2485 fprintf (stderr, "\n");
2488 /* Now we can kill or detach the inferiors. */
2490 for_each_inferior (&all_processes, detach_or_kill_inferior_callback);
2494 main (int argc, char *argv[])
2498 char *arg_end, *port;
2499 char **next_arg = &argv[1];
2504 while (*next_arg != NULL && **next_arg == '-')
2506 if (strcmp (*next_arg, "--version") == 0)
2508 gdbserver_version ();
2511 else if (strcmp (*next_arg, "--help") == 0)
2513 gdbserver_usage (stdout);
2516 else if (strcmp (*next_arg, "--attach") == 0)
2518 else if (strcmp (*next_arg, "--multi") == 0)
2520 else if (strcmp (*next_arg, "--wrapper") == 0)
2524 wrapper_argv = next_arg;
2525 while (*next_arg != NULL && strcmp (*next_arg, "--") != 0)
2528 if (next_arg == wrapper_argv || *next_arg == NULL)
2530 gdbserver_usage (stderr);
2534 /* Consume the "--". */
2537 else if (strcmp (*next_arg, "--debug") == 0)
2539 else if (strcmp (*next_arg, "--remote-debug") == 0)
2541 else if (strcmp (*next_arg, "--disable-packet") == 0)
2543 gdbserver_show_disableable (stdout);
2546 else if (strncmp (*next_arg,
2547 "--disable-packet=",
2548 sizeof ("--disable-packet=") - 1) == 0)
2550 char *packets, *tok;
2552 packets = *next_arg += sizeof ("--disable-packet=") - 1;
2553 for (tok = strtok (packets, ",");
2555 tok = strtok (NULL, ","))
2557 if (strcmp ("vCont", tok) == 0)
2558 disable_packet_vCont = 1;
2559 else if (strcmp ("Tthread", tok) == 0)
2560 disable_packet_Tthread = 1;
2561 else if (strcmp ("qC", tok) == 0)
2562 disable_packet_qC = 1;
2563 else if (strcmp ("qfThreadInfo", tok) == 0)
2564 disable_packet_qfThreadInfo = 1;
2565 else if (strcmp ("threads", tok) == 0)
2567 disable_packet_vCont = 1;
2568 disable_packet_Tthread = 1;
2569 disable_packet_qC = 1;
2570 disable_packet_qfThreadInfo = 1;
2574 fprintf (stderr, "Don't know how to disable \"%s\".\n\n",
2576 gdbserver_show_disableable (stderr);
2581 else if (strcmp (*next_arg, "--disable-randomization") == 0)
2582 disable_randomization = 1;
2583 else if (strcmp (*next_arg, "--no-disable-randomization") == 0)
2584 disable_randomization = 0;
2585 else if (strcmp (*next_arg, "--once") == 0)
2589 fprintf (stderr, "Unknown argument: %s\n", *next_arg);
2597 if (setjmp (toplevel))
2599 fprintf (stderr, "Exiting\n");
2605 if (port == NULL || (!attach && !multi_mode && *next_arg == NULL))
2607 gdbserver_usage (stderr);
2614 /* --attach used to come after PORT, so allow it there for
2616 if (*next_arg != NULL && strcmp (*next_arg, "--attach") == 0)
2623 && (*next_arg == NULL
2624 || (*next_arg)[0] == '\0'
2625 || (pid = strtoul (*next_arg, &arg_end, 0)) == 0
2627 || next_arg[1] != NULL))
2632 gdbserver_usage (stderr);
2636 initialize_async_io ();
2638 if (target_supports_tracepoints ())
2639 initialize_tracepoint ();
2641 own_buf = xmalloc (PBUFSIZ + 1);
2642 mem_buf = xmalloc (PBUFSIZ);
2644 if (pid == 0 && *next_arg != NULL)
2648 n = argc - (next_arg - argv);
2649 program_argv = xmalloc (sizeof (char *) * (n + 1));
2650 for (i = 0; i < n; i++)
2651 program_argv[i] = xstrdup (next_arg[i]);
2652 program_argv[i] = NULL;
2654 /* Wait till we are at first instruction in program. */
2655 start_inferior (program_argv);
2657 /* We are now (hopefully) stopped at the first instruction of
2658 the target process. This assumes that the target process was
2659 successfully created. */
2663 if (attach_inferior (pid) == -1)
2664 error ("Attaching not supported on this target");
2666 /* Otherwise succeeded. */
2670 last_status.kind = TARGET_WAITKIND_EXITED;
2671 last_status.value.integer = 0;
2672 last_ptid = minus_one_ptid;
2675 /* Don't report shared library events on the initial connection,
2676 even if some libraries are preloaded. Avoids the "stopped by
2677 shared library event" notice on gdb side. */
2680 if (setjmp (toplevel))
2682 detach_or_kill_for_exit ();
2686 if (last_status.kind == TARGET_WAITKIND_EXITED
2687 || last_status.kind == TARGET_WAITKIND_SIGNALLED)
2692 if (!was_running && !multi_mode)
2694 fprintf (stderr, "No program to debug. GDBserver exiting.\n");
2698 remote_prepare (port);
2704 /* Be sure we're out of tfind mode. */
2705 current_traceframe = -1;
2709 if (setjmp (toplevel) != 0)
2711 /* An error occurred. */
2712 if (response_needed)
2714 write_enn (own_buf);
2719 /* Wait for events. This will return when all event sources are
2720 removed from the event loop. */
2721 start_event_loop ();
2723 /* If an exit was requested (using the "monitor exit" command),
2724 terminate now. The only other way to get here is for
2725 getpkt to fail; close the connection and reopen it at the
2728 if (exit_requested || run_once)
2730 detach_or_kill_for_exit ();
2735 "Remote side has terminated connection. "
2736 "GDBserver will reopen the connection.\n");
2740 if (disconnected_tracing)
2742 /* Try to enable non-stop/async mode, so we we can both
2743 wait for an async socket accept, and handle async
2744 target events simultaneously. There's also no point
2745 either in having the target always stop all threads,
2746 when we're going to pass signals down without
2750 if (start_non_stop (1))
2753 /* Detaching implicitly resumes all threads; simply
2754 disconnecting does not. */
2760 "Disconnected tracing disabled; stopping trace run.\n");
2767 /* Event loop callback that handles a serial event. The first byte in
2768 the serial buffer gets us here. We expect characters to arrive at
2769 a brisk pace, so we read the rest of the packet with a blocking
2773 process_serial_event (void)
2784 int new_packet_len = -1;
2786 /* Used to decide when gdbserver should exit in
2787 multi-mode/remote. */
2788 static int have_ran = 0;
2791 have_ran = target_running ();
2793 disable_async_io ();
2795 response_needed = 0;
2796 packet_len = getpkt (own_buf);
2797 if (packet_len <= 0)
2800 /* Force an event loop break. */
2803 response_needed = 1;
2810 handle_query (own_buf, packet_len, &new_packet_len);
2813 handle_general_set (own_buf);
2816 require_running (own_buf);
2821 pid = strtol (&own_buf[i], NULL, 16);
2825 ptid_get_pid (((struct inferior_list_entry *) current_inferior)->id);
2827 if (tracing && disconnected_tracing)
2829 struct thread_resume resume_info;
2830 struct process_info *process = find_process_pid (pid);
2832 if (process == NULL)
2834 write_enn (own_buf);
2839 "Disconnected tracing in effect, "
2840 "leaving gdbserver attached to the process\n");
2842 /* Make sure we're in non-stop/async mode, so we we can both
2843 wait for an async socket accept, and handle async target
2844 events simultaneously. There's also no point either in
2845 having the target stop all threads, when we're going to
2846 pass signals down without informing GDB. */
2850 fprintf (stderr, "Forcing non-stop mode\n");
2856 process->gdb_detached = 1;
2858 /* Detaching implicitly resumes all threads. */
2859 resume_info.thread = minus_one_ptid;
2860 resume_info.kind = resume_continue;
2861 resume_info.sig = 0;
2862 (*the_target->resume) (&resume_info, 1);
2865 break; /* from switch/case */
2868 fprintf (stderr, "Detaching from process %d\n", pid);
2870 if (detach_inferior (pid) != 0)
2871 write_enn (own_buf);
2874 discard_queued_stop_replies (pid);
2877 if (extended_protocol)
2879 /* Treat this like a normal program exit. */
2880 last_status.kind = TARGET_WAITKIND_EXITED;
2881 last_status.value.integer = 0;
2882 last_ptid = pid_to_ptid (pid);
2884 current_inferior = NULL;
2891 /* If we are attached, then we can exit. Otherwise, we
2892 need to hang around doing nothing, until the child is
2894 join_inferior (pid);
2900 extended_protocol = 1;
2904 handle_status (own_buf);
2907 if (own_buf[1] == 'c' || own_buf[1] == 'g' || own_buf[1] == 's')
2909 ptid_t gdb_id, thread_id;
2912 require_running (own_buf);
2914 gdb_id = read_ptid (&own_buf[2], NULL);
2916 pid = ptid_get_pid (gdb_id);
2918 if (ptid_equal (gdb_id, null_ptid)
2919 || ptid_equal (gdb_id, minus_one_ptid))
2920 thread_id = null_ptid;
2922 && ptid_equal (pid_to_ptid (pid),
2925 struct thread_info *thread =
2926 (struct thread_info *) find_inferior (&all_threads,
2931 write_enn (own_buf);
2935 thread_id = ((struct inferior_list_entry *)thread)->id;
2939 thread_id = gdb_id_to_thread_id (gdb_id);
2940 if (ptid_equal (thread_id, null_ptid))
2942 write_enn (own_buf);
2947 if (own_buf[1] == 'g')
2949 if (ptid_equal (thread_id, null_ptid))
2951 /* GDB is telling us to choose any thread. Check if
2952 the currently selected thread is still valid. If
2953 it is not, select the first available. */
2954 struct thread_info *thread =
2955 (struct thread_info *) find_inferior_id (&all_threads,
2958 thread_id = all_threads.head->id;
2961 general_thread = thread_id;
2962 set_desired_inferior (1);
2964 else if (own_buf[1] == 'c')
2965 cont_thread = thread_id;
2971 /* Silently ignore it so that gdb can extend the protocol
2972 without compatibility headaches. */
2977 require_running (own_buf);
2978 if (current_traceframe >= 0)
2980 struct regcache *regcache = new_register_cache ();
2982 if (fetch_traceframe_registers (current_traceframe,
2984 registers_to_string (regcache, own_buf);
2986 write_enn (own_buf);
2987 free_register_cache (regcache);
2991 struct regcache *regcache;
2993 set_desired_inferior (1);
2994 regcache = get_thread_regcache (current_inferior, 1);
2995 registers_to_string (regcache, own_buf);
2999 require_running (own_buf);
3000 if (current_traceframe >= 0)
3001 write_enn (own_buf);
3004 struct regcache *regcache;
3006 set_desired_inferior (1);
3007 regcache = get_thread_regcache (current_inferior, 1);
3008 registers_from_string (regcache, &own_buf[1]);
3013 require_running (own_buf);
3014 decode_m_packet (&own_buf[1], &mem_addr, &len);
3015 res = gdb_read_memory (mem_addr, mem_buf, len);
3017 write_enn (own_buf);
3019 convert_int_to_ascii (mem_buf, own_buf, res);
3022 require_running (own_buf);
3023 decode_M_packet (&own_buf[1], &mem_addr, &len, &mem_buf);
3024 if (gdb_write_memory (mem_addr, mem_buf, len) == 0)
3027 write_enn (own_buf);
3030 require_running (own_buf);
3031 if (decode_X_packet (&own_buf[1], packet_len - 1,
3032 &mem_addr, &len, &mem_buf) < 0
3033 || gdb_write_memory (mem_addr, mem_buf, len) != 0)
3034 write_enn (own_buf);
3039 require_running (own_buf);
3040 convert_ascii_to_int (own_buf + 1, &sig, 1);
3041 if (target_signal_to_host_p (sig))
3042 signal = target_signal_to_host (sig);
3045 myresume (own_buf, 0, signal);
3048 require_running (own_buf);
3049 convert_ascii_to_int (own_buf + 1, &sig, 1);
3050 if (target_signal_to_host_p (sig))
3051 signal = target_signal_to_host (sig);
3054 myresume (own_buf, 1, signal);
3057 require_running (own_buf);
3059 myresume (own_buf, 0, signal);
3062 require_running (own_buf);
3064 myresume (own_buf, 1, signal);
3066 case 'Z': /* insert_ ... */
3068 case 'z': /* remove_ ... */
3072 CORE_ADDR addr = strtoul (&own_buf[3], &lenptr, 16);
3073 int len = strtol (lenptr + 1, &dataptr, 16);
3074 char type = own_buf[1];
3076 const int insert = ch == 'Z';
3078 /* Default to unrecognized/unsupported. */
3082 case '0': /* software-breakpoint */
3083 case '1': /* hardware-breakpoint */
3084 case '2': /* write watchpoint */
3085 case '3': /* read watchpoint */
3086 case '4': /* access watchpoint */
3087 require_running (own_buf);
3088 if (insert && the_target->insert_point != NULL)
3089 res = (*the_target->insert_point) (type, addr, len);
3090 else if (!insert && the_target->remove_point != NULL)
3091 res = (*the_target->remove_point) (type, addr, len);
3103 write_enn (own_buf);
3107 response_needed = 0;
3108 if (!target_running ())
3109 /* The packet we received doesn't make sense - but we can't
3110 reply to it, either. */
3113 fprintf (stderr, "Killing all inferiors\n");
3114 for_each_inferior (&all_processes, kill_inferior_callback);
3116 /* When using the extended protocol, we wait with no program
3117 running. The traditional protocol will exit instead. */
3118 if (extended_protocol)
3120 last_status.kind = TARGET_WAITKIND_EXITED;
3121 last_status.value.sig = TARGET_SIGNAL_KILL;
3129 ptid_t gdb_id, thread_id;
3131 require_running (own_buf);
3133 gdb_id = read_ptid (&own_buf[1], NULL);
3134 thread_id = gdb_id_to_thread_id (gdb_id);
3135 if (ptid_equal (thread_id, null_ptid))
3137 write_enn (own_buf);
3141 if (mythread_alive (thread_id))
3144 write_enn (own_buf);
3148 response_needed = 0;
3150 /* Restarting the inferior is only supported in the extended
3152 if (extended_protocol)
3154 if (target_running ())
3155 for_each_inferior (&all_processes,
3156 kill_inferior_callback);
3157 fprintf (stderr, "GDBserver restarting\n");
3159 /* Wait till we are at 1st instruction in prog. */
3160 if (program_argv != NULL)
3161 start_inferior (program_argv);
3164 last_status.kind = TARGET_WAITKIND_EXITED;
3165 last_status.value.sig = TARGET_SIGNAL_KILL;
3171 /* It is a request we don't understand. Respond with an
3172 empty packet so that gdb knows that we don't support this
3178 /* Extended (long) request. */
3179 handle_v_requests (own_buf, packet_len, &new_packet_len);
3183 /* It is a request we don't understand. Respond with an empty
3184 packet so that gdb knows that we don't support this
3190 if (new_packet_len != -1)
3191 putpkt_binary (own_buf, new_packet_len);
3195 response_needed = 0;
3197 if (!extended_protocol && have_ran && !target_running ())
3199 /* In non-stop, defer exiting until GDB had a chance to query
3200 the whole vStopped list (until it gets an OK). */
3203 fprintf (stderr, "GDBserver exiting\n");
3215 /* Event-loop callback for serial events. */
3218 handle_serial_event (int err, gdb_client_data client_data)
3221 fprintf (stderr, "handling possible serial event\n");
3223 /* Really handle it. */
3224 if (process_serial_event () < 0)
3227 /* Be sure to not change the selected inferior behind GDB's back.
3228 Important in the non-stop mode asynchronous protocol. */
3229 set_desired_inferior (1);
3234 /* Event-loop callback for target events. */
3237 handle_target_event (int err, gdb_client_data client_data)
3240 fprintf (stderr, "handling possible target event\n");
3242 last_ptid = mywait (minus_one_ptid, &last_status,
3245 if (last_status.kind != TARGET_WAITKIND_IGNORE)
3247 int pid = ptid_get_pid (last_ptid);
3248 struct process_info *process = find_process_pid (pid);
3249 int forward_event = !gdb_connected () || process->gdb_detached;
3251 if (last_status.kind == TARGET_WAITKIND_EXITED
3252 || last_status.kind == TARGET_WAITKIND_SIGNALLED)
3254 mark_breakpoints_out (process);
3255 mourn_inferior (process);
3259 /* We're reporting this thread as stopped. Update its
3260 "want-stopped" state to what the client wants, until it
3261 gets a new resume action. */
3262 current_inferior->last_resume_kind = resume_stop;
3263 current_inferior->last_status = last_status;
3268 if (!target_running ())
3270 /* The last process exited. We're done. */
3274 if (last_status.kind == TARGET_WAITKIND_STOPPED)
3276 /* A thread stopped with a signal, but gdb isn't
3277 connected to handle it. Pass it down to the
3278 inferior, as if it wasn't being traced. */
3279 struct thread_resume resume_info;
3283 "GDB not connected; forwarding event %d for [%s]\n",
3284 (int) last_status.kind,
3285 target_pid_to_str (last_ptid));
3287 resume_info.thread = last_ptid;
3288 resume_info.kind = resume_continue;
3289 resume_info.sig = target_signal_to_host (last_status.value.sig);
3290 (*the_target->resume) (&resume_info, 1);
3292 else if (debug_threads)
3293 fprintf (stderr, "GDB not connected; ignoring event %d for [%s]\n",
3294 (int) last_status.kind,
3295 target_pid_to_str (last_ptid));
3299 /* Something interesting. Tell GDB about it. */
3300 push_event (last_ptid, &last_status);
3304 /* Be sure to not change the selected inferior behind GDB's back.
3305 Important in the non-stop mode asynchronous protocol. */
3306 set_desired_inferior (1);