1 /* Main code for remote server for GDB.
2 Copyright (C) 1989-2014 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "gdbthread.h"
33 #include "btrace-common.h"
34 #include "filestuff.h"
35 #include "tracepoint.h"
39 /* The thread set with an `Hc' packet. `Hc' is deprecated in favor of
40 `vCont'. Note the multi-process extensions made `vCont' a
41 requirement, so `Hc pPID.TID' is pretty much undefined. So
42 CONT_THREAD can be null_ptid for no `Hc' thread, minus_one_ptid for
43 resuming all threads of the process (again, `Hc' isn't used for
44 multi-process), or a specific thread ptid_t.
46 We also set this when handling a single-thread `vCont' resume, as
47 some places in the backends check it to know when (and for which
48 thread) single-thread scheduler-locking is in effect. */
51 /* The thread set with an `Hg' packet. */
52 ptid_t general_thread
;
56 static int extended_protocol
;
57 static int response_needed
;
58 static int exit_requested
;
60 /* --once: Exit after the first connection has closed. */
66 /* Whether we should attempt to disable the operating system's address
67 space randomization feature before starting an inferior. */
68 int disable_randomization
= 1;
70 static char **program_argv
, **wrapper_argv
;
72 /* Enable debugging of h/w breakpoint/watchpoint support. */
75 int pass_signals
[GDB_SIGNAL_LAST
];
76 int program_signals
[GDB_SIGNAL_LAST
];
77 int program_signals_p
;
81 /* The PID of the originally created or attached inferior. Used to
82 send signals to the process when GDB sends us an asynchronous interrupt
83 (user hitting Control-C in the client), and to wait for the child to exit
84 when no longer debugging it. */
86 unsigned long signal_pid
;
89 /* A file descriptor for the controlling terminal. */
92 /* TERMINAL_FD's original foreground group. */
93 pid_t old_foreground_pgrp
;
95 /* Hand back terminal ownership to the original foreground group. */
98 restore_old_foreground_pgrp (void)
100 tcsetpgrp (terminal_fd
, old_foreground_pgrp
);
104 /* Set if you want to disable optional thread related packets support
105 in gdbserver, for the sake of testing GDB against stubs that don't
107 int disable_packet_vCont
;
108 int disable_packet_Tthread
;
109 int disable_packet_qC
;
110 int disable_packet_qfThreadInfo
;
112 /* Last status reported to GDB. */
113 static struct target_waitstatus last_status
;
114 static ptid_t last_ptid
;
116 static char *own_buf
;
117 static unsigned char *mem_buf
;
119 /* A sub-class of 'struct notif_event' for stop, holding information
120 relative to a single stop reply. We keep a queue of these to
121 push to GDB in non-stop mode. */
125 struct notif_event base
;
127 /* Thread or process that got the event. */
131 struct target_waitstatus status
;
134 DEFINE_QUEUE_P (notif_event_p
);
136 /* Put a stop reply to the stop reply queue. */
139 queue_stop_reply (ptid_t ptid
, struct target_waitstatus
*status
)
141 struct vstop_notif
*new_notif
= xmalloc (sizeof (*new_notif
));
143 new_notif
->ptid
= ptid
;
144 new_notif
->status
= *status
;
146 notif_event_enque (¬if_stop
, (struct notif_event
*) new_notif
);
150 remove_all_on_match_pid (QUEUE (notif_event_p
) *q
,
151 QUEUE_ITER (notif_event_p
) *iter
,
152 struct notif_event
*event
,
158 || ptid_get_pid (((struct vstop_notif
*) event
)->ptid
) == *pid
)
160 if (q
->free_func
!= NULL
)
161 q
->free_func (event
);
163 QUEUE_remove_elem (notif_event_p
, q
, iter
);
169 /* Get rid of the currently pending stop replies for PID. If PID is
170 -1, then apply to all processes. */
173 discard_queued_stop_replies (int pid
)
175 QUEUE_iterate (notif_event_p
, notif_stop
.queue
,
176 remove_all_on_match_pid
, &pid
);
180 vstop_notif_reply (struct notif_event
*event
, char *own_buf
)
182 struct vstop_notif
*vstop
= (struct vstop_notif
*) event
;
184 prepare_resume_reply (own_buf
, vstop
->ptid
, &vstop
->status
);
187 struct notif_server notif_stop
=
189 "vStopped", "Stop", NULL
, vstop_notif_reply
,
193 target_running (void)
195 return get_first_thread () != NULL
;
199 start_inferior (char **argv
)
201 char **new_argv
= argv
;
203 if (wrapper_argv
!= NULL
)
207 for (i
= 0; wrapper_argv
[i
] != NULL
; i
++)
209 for (i
= 0; argv
[i
] != NULL
; i
++)
211 new_argv
= alloca (sizeof (char *) * count
);
213 for (i
= 0; wrapper_argv
[i
] != NULL
; i
++)
214 new_argv
[count
++] = wrapper_argv
[i
];
215 for (i
= 0; argv
[i
] != NULL
; i
++)
216 new_argv
[count
++] = argv
[i
];
217 new_argv
[count
] = NULL
;
223 for (i
= 0; new_argv
[i
]; ++i
)
224 debug_printf ("new_argv[%d] = \"%s\"\n", i
, new_argv
[i
]);
229 signal (SIGTTOU
, SIG_DFL
);
230 signal (SIGTTIN
, SIG_DFL
);
233 /* Clear this so the backend doesn't get confused, thinking
234 CONT_THREAD died, and it needs to resume all threads. */
235 cont_thread
= null_ptid
;
237 signal_pid
= create_inferior (new_argv
[0], new_argv
);
239 /* FIXME: we don't actually know at this point that the create
240 actually succeeded. We won't know that until we wait. */
241 fprintf (stderr
, "Process %s created; pid = %ld\n", argv
[0],
246 signal (SIGTTOU
, SIG_IGN
);
247 signal (SIGTTIN
, SIG_IGN
);
248 terminal_fd
= fileno (stderr
);
249 old_foreground_pgrp
= tcgetpgrp (terminal_fd
);
250 tcsetpgrp (terminal_fd
, signal_pid
);
251 atexit (restore_old_foreground_pgrp
);
254 if (wrapper_argv
!= NULL
)
256 struct thread_resume resume_info
;
258 memset (&resume_info
, 0, sizeof (resume_info
));
259 resume_info
.thread
= pid_to_ptid (signal_pid
);
260 resume_info
.kind
= resume_continue
;
263 last_ptid
= mywait (pid_to_ptid (signal_pid
), &last_status
, 0, 0);
265 if (last_status
.kind
!= TARGET_WAITKIND_STOPPED
)
270 (*the_target
->resume
) (&resume_info
, 1);
272 last_ptid
= mywait (pid_to_ptid (signal_pid
), &last_status
, 0, 0);
273 if (last_status
.kind
!= TARGET_WAITKIND_STOPPED
)
276 current_inferior
->last_resume_kind
= resume_stop
;
277 current_inferior
->last_status
= last_status
;
279 while (last_status
.value
.sig
!= GDB_SIGNAL_TRAP
);
284 /* Wait till we are at 1st instruction in program, return new pid
285 (assuming success). */
286 last_ptid
= mywait (pid_to_ptid (signal_pid
), &last_status
, 0, 0);
288 if (last_status
.kind
!= TARGET_WAITKIND_EXITED
289 && last_status
.kind
!= TARGET_WAITKIND_SIGNALLED
)
291 current_inferior
->last_resume_kind
= resume_stop
;
292 current_inferior
->last_status
= last_status
;
299 attach_inferior (int pid
)
301 /* myattach should return -1 if attaching is unsupported,
302 0 if it succeeded, and call error() otherwise. */
304 if (myattach (pid
) != 0)
307 fprintf (stderr
, "Attached; pid = %d\n", pid
);
310 /* FIXME - It may be that we should get the SIGNAL_PID from the
311 attach function, so that it can be the main thread instead of
312 whichever we were told to attach to. */
315 /* Clear this so the backend doesn't get confused, thinking
316 CONT_THREAD died, and it needs to resume all threads. */
317 cont_thread
= null_ptid
;
321 last_ptid
= mywait (pid_to_ptid (pid
), &last_status
, 0, 0);
323 /* GDB knows to ignore the first SIGSTOP after attaching to a running
324 process using the "attach" command, but this is different; it's
325 just using "target remote". Pretend it's just starting up. */
326 if (last_status
.kind
== TARGET_WAITKIND_STOPPED
327 && last_status
.value
.sig
== GDB_SIGNAL_STOP
)
328 last_status
.value
.sig
= GDB_SIGNAL_TRAP
;
330 current_inferior
->last_resume_kind
= resume_stop
;
331 current_inferior
->last_status
= last_status
;
337 extern int remote_debug
;
339 /* Decode a qXfer read request. Return 0 if everything looks OK,
343 decode_xfer_read (char *buf
, CORE_ADDR
*ofs
, unsigned int *len
)
345 /* After the read marker and annex, qXfer looks like a
346 traditional 'm' packet. */
347 decode_m_packet (buf
, ofs
, len
);
353 decode_xfer (char *buf
, char **object
, char **rw
, char **annex
, char **offset
)
355 /* Extract and NUL-terminate the object. */
357 while (*buf
&& *buf
!= ':')
363 /* Extract and NUL-terminate the read/write action. */
365 while (*buf
&& *buf
!= ':')
371 /* Extract and NUL-terminate the annex. */
373 while (*buf
&& *buf
!= ':')
383 /* Write the response to a successful qXfer read. Returns the
384 length of the (binary) data stored in BUF, corresponding
385 to as much of DATA/LEN as we could fit. IS_MORE controls
386 the first character of the response. */
388 write_qxfer_response (char *buf
, const void *data
, int len
, int is_more
)
397 return remote_escape_output (data
, len
, (unsigned char *) buf
+ 1, &out_len
,
401 /* Handle btrace enabling. */
404 handle_btrace_enable (struct thread_info
*thread
)
406 if (thread
->btrace
!= NULL
)
407 return "E.Btrace already enabled.";
409 thread
->btrace
= target_enable_btrace (thread
->entry
.id
);
410 if (thread
->btrace
== NULL
)
411 return "E.Could not enable btrace.";
416 /* Handle btrace disabling. */
419 handle_btrace_disable (struct thread_info
*thread
)
422 if (thread
->btrace
== NULL
)
423 return "E.Branch tracing not enabled.";
425 if (target_disable_btrace (thread
->btrace
) != 0)
426 return "E.Could not disable branch tracing.";
428 thread
->btrace
= NULL
;
432 /* Handle the "Qbtrace" packet. */
435 handle_btrace_general_set (char *own_buf
)
437 struct thread_info
*thread
;
441 if (strncmp ("Qbtrace:", own_buf
, strlen ("Qbtrace:")) != 0)
444 op
= own_buf
+ strlen ("Qbtrace:");
446 if (!target_supports_btrace ())
448 strcpy (own_buf
, "E.Target does not support branch tracing.");
452 if (ptid_equal (general_thread
, null_ptid
)
453 || ptid_equal (general_thread
, minus_one_ptid
))
455 strcpy (own_buf
, "E.Must select a single thread.");
459 thread
= find_thread_ptid (general_thread
);
462 strcpy (own_buf
, "E.No such thread.");
468 if (strcmp (op
, "bts") == 0)
469 err
= handle_btrace_enable (thread
);
470 else if (strcmp (op
, "off") == 0)
471 err
= handle_btrace_disable (thread
);
473 err
= "E.Bad Qbtrace operation. Use bts or off.";
476 strcpy (own_buf
, err
);
483 /* Handle all of the extended 'Q' packets. */
486 handle_general_set (char *own_buf
)
488 if (strncmp ("QPassSignals:", own_buf
, strlen ("QPassSignals:")) == 0)
490 int numsigs
= (int) GDB_SIGNAL_LAST
, i
;
491 const char *p
= own_buf
+ strlen ("QPassSignals:");
494 p
= decode_address_to_semicolon (&cursig
, p
);
495 for (i
= 0; i
< numsigs
; i
++)
501 /* Keep looping, to clear the remaining signals. */
504 p
= decode_address_to_semicolon (&cursig
, p
);
509 strcpy (own_buf
, "OK");
513 if (strncmp ("QProgramSignals:", own_buf
, strlen ("QProgramSignals:")) == 0)
515 int numsigs
= (int) GDB_SIGNAL_LAST
, i
;
516 const char *p
= own_buf
+ strlen ("QProgramSignals:");
519 program_signals_p
= 1;
521 p
= decode_address_to_semicolon (&cursig
, p
);
522 for (i
= 0; i
< numsigs
; i
++)
526 program_signals
[i
] = 1;
528 /* Keep looping, to clear the remaining signals. */
531 p
= decode_address_to_semicolon (&cursig
, p
);
534 program_signals
[i
] = 0;
536 strcpy (own_buf
, "OK");
540 if (strcmp (own_buf
, "QStartNoAckMode") == 0)
544 fprintf (stderr
, "[noack mode enabled]\n");
553 if (strncmp (own_buf
, "QNonStop:", 9) == 0)
555 char *mode
= own_buf
+ 9;
559 if (strcmp (mode
, "0") == 0)
561 else if (strcmp (mode
, "1") == 0)
565 /* We don't know what this mode is, so complain to
567 fprintf (stderr
, "Unknown non-stop mode requested: %s\n",
573 req_str
= req
? "non-stop" : "all-stop";
574 if (start_non_stop (req
) != 0)
576 fprintf (stderr
, "Setting %s mode failed\n", req_str
);
584 fprintf (stderr
, "[%s mode enabled]\n", req_str
);
590 if (strncmp ("QDisableRandomization:", own_buf
,
591 strlen ("QDisableRandomization:")) == 0)
593 char *packet
= own_buf
+ strlen ("QDisableRandomization:");
596 unpack_varlen_hex (packet
, &setting
);
597 disable_randomization
= setting
;
601 if (disable_randomization
)
602 fprintf (stderr
, "[address space randomization disabled]\n");
604 fprintf (stderr
, "[address space randomization enabled]\n");
611 if (target_supports_tracepoints ()
612 && handle_tracepoint_general_set (own_buf
))
615 if (strncmp ("QAgent:", own_buf
, strlen ("QAgent:")) == 0)
617 char *mode
= own_buf
+ strlen ("QAgent:");
620 if (strcmp (mode
, "0") == 0)
622 else if (strcmp (mode
, "1") == 0)
626 /* We don't know what this value is, so complain to GDB. */
627 sprintf (own_buf
, "E.Unknown QAgent value");
631 /* Update the flag. */
634 fprintf (stderr
, "[%s agent]\n", req
? "Enable" : "Disable");
639 if (handle_btrace_general_set (own_buf
))
642 /* Otherwise we didn't know what packet it was. Say we didn't
648 get_features_xml (const char *annex
)
650 const struct target_desc
*desc
= current_target_desc ();
652 /* `desc->xmltarget' defines what to return when looking for the
653 "target.xml" file. Its contents can either be verbatim XML code
654 (prefixed with a '@') or else the name of the actual XML file to
655 be used in place of "target.xml".
657 This variable is set up from the auto-generated
658 init_registers_... routine for the current target. */
660 if (desc
->xmltarget
!= NULL
&& strcmp (annex
, "target.xml") == 0)
662 if (*desc
->xmltarget
== '@')
663 return desc
->xmltarget
+ 1;
665 annex
= desc
->xmltarget
;
670 extern const char *const xml_builtin
[][2];
673 /* Look for the annex. */
674 for (i
= 0; xml_builtin
[i
][0] != NULL
; i
++)
675 if (strcmp (annex
, xml_builtin
[i
][0]) == 0)
678 if (xml_builtin
[i
][0] != NULL
)
679 return xml_builtin
[i
][1];
687 monitor_show_help (void)
689 monitor_output ("The following monitor commands are supported:\n");
690 monitor_output (" set debug <0|1>\n");
691 monitor_output (" Enable general debugging messages\n");
692 monitor_output (" set debug-hw-points <0|1>\n");
693 monitor_output (" Enable h/w breakpoint/watchpoint debugging messages\n");
694 monitor_output (" set remote-debug <0|1>\n");
695 monitor_output (" Enable remote protocol debugging messages\n");
696 monitor_output (" set debug-format option1[,option2,...]\n");
697 monitor_output (" Add additional information to debugging messages\n");
698 monitor_output (" Options: all, none");
699 #ifdef HAVE_GETTIMEOFDAY
700 monitor_output (", timestamp");
702 monitor_output ("\n");
703 monitor_output (" exit\n");
704 monitor_output (" Quit GDBserver\n");
707 /* Read trace frame or inferior memory. Returns the number of bytes
708 actually read, zero when no further transfer is possible, and -1 on
709 error. Return of a positive value smaller than LEN does not
710 indicate there's no more to be read, only the end of the transfer.
711 E.g., when GDB reads memory from a traceframe, a first request may
712 be served from a memory block that does not cover the whole request
713 length. A following request gets the rest served from either
714 another block (of the same traceframe) or from the read-only
718 gdb_read_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
722 if (current_traceframe
>= 0)
725 ULONGEST length
= len
;
727 if (traceframe_read_mem (current_traceframe
,
728 memaddr
, myaddr
, len
, &nbytes
))
730 /* Data read from trace buffer, we're done. */
733 if (!in_readonly_region (memaddr
, length
))
735 /* Otherwise we have a valid readonly case, fall through. */
736 /* (assume no half-trace half-real blocks for now) */
739 res
= prepare_to_access_memory ();
742 res
= read_inferior_memory (memaddr
, myaddr
, len
);
743 done_accessing_memory ();
745 return res
== 0 ? len
: -1;
751 /* Write trace frame or inferior memory. Actually, writing to trace
752 frames is forbidden. */
755 gdb_write_memory (CORE_ADDR memaddr
, const unsigned char *myaddr
, int len
)
757 if (current_traceframe
>= 0)
763 ret
= prepare_to_access_memory ();
766 ret
= write_inferior_memory (memaddr
, myaddr
, len
);
767 done_accessing_memory ();
773 /* Subroutine of handle_search_memory to simplify it. */
776 handle_search_memory_1 (CORE_ADDR start_addr
, CORE_ADDR search_space_len
,
777 gdb_byte
*pattern
, unsigned pattern_len
,
778 gdb_byte
*search_buf
,
779 unsigned chunk_size
, unsigned search_buf_size
,
780 CORE_ADDR
*found_addrp
)
782 /* Prime the search buffer. */
784 if (gdb_read_memory (start_addr
, search_buf
, search_buf_size
)
787 warning ("Unable to access %ld bytes of target "
788 "memory at 0x%lx, halting search.",
789 (long) search_buf_size
, (long) start_addr
);
793 /* Perform the search.
795 The loop is kept simple by allocating [N + pattern-length - 1] bytes.
796 When we've scanned N bytes we copy the trailing bytes to the start and
797 read in another N bytes. */
799 while (search_space_len
>= pattern_len
)
802 unsigned nr_search_bytes
= (search_space_len
< search_buf_size
806 found_ptr
= memmem (search_buf
, nr_search_bytes
, pattern
, pattern_len
);
808 if (found_ptr
!= NULL
)
810 CORE_ADDR found_addr
= start_addr
+ (found_ptr
- search_buf
);
811 *found_addrp
= found_addr
;
815 /* Not found in this chunk, skip to next chunk. */
817 /* Don't let search_space_len wrap here, it's unsigned. */
818 if (search_space_len
>= chunk_size
)
819 search_space_len
-= chunk_size
;
821 search_space_len
= 0;
823 if (search_space_len
>= pattern_len
)
825 unsigned keep_len
= search_buf_size
- chunk_size
;
826 CORE_ADDR read_addr
= start_addr
+ chunk_size
+ keep_len
;
829 /* Copy the trailing part of the previous iteration to the front
830 of the buffer for the next iteration. */
831 memcpy (search_buf
, search_buf
+ chunk_size
, keep_len
);
833 nr_to_read
= (search_space_len
- keep_len
< chunk_size
834 ? search_space_len
- keep_len
837 if (gdb_read_memory (read_addr
, search_buf
+ keep_len
,
838 nr_to_read
) != search_buf_size
)
840 warning ("Unable to access %ld bytes of target memory "
841 "at 0x%lx, halting search.",
842 (long) nr_to_read
, (long) read_addr
);
846 start_addr
+= chunk_size
;
855 /* Handle qSearch:memory packets. */
858 handle_search_memory (char *own_buf
, int packet_len
)
860 CORE_ADDR start_addr
;
861 CORE_ADDR search_space_len
;
863 unsigned int pattern_len
;
864 /* NOTE: also defined in find.c testcase. */
865 #define SEARCH_CHUNK_SIZE 16000
866 const unsigned chunk_size
= SEARCH_CHUNK_SIZE
;
867 /* Buffer to hold memory contents for searching. */
868 gdb_byte
*search_buf
;
869 unsigned search_buf_size
;
871 CORE_ADDR found_addr
;
872 int cmd_name_len
= sizeof ("qSearch:memory:") - 1;
874 pattern
= malloc (packet_len
);
877 error ("Unable to allocate memory to perform the search");
878 strcpy (own_buf
, "E00");
881 if (decode_search_memory_packet (own_buf
+ cmd_name_len
,
882 packet_len
- cmd_name_len
,
883 &start_addr
, &search_space_len
,
884 pattern
, &pattern_len
) < 0)
887 error ("Error in parsing qSearch:memory packet");
888 strcpy (own_buf
, "E00");
892 search_buf_size
= chunk_size
+ pattern_len
- 1;
894 /* No point in trying to allocate a buffer larger than the search space. */
895 if (search_space_len
< search_buf_size
)
896 search_buf_size
= search_space_len
;
898 search_buf
= malloc (search_buf_size
);
899 if (search_buf
== NULL
)
902 error ("Unable to allocate memory to perform the search");
903 strcpy (own_buf
, "E00");
907 found
= handle_search_memory_1 (start_addr
, search_space_len
,
908 pattern
, pattern_len
,
909 search_buf
, chunk_size
, search_buf_size
,
913 sprintf (own_buf
, "1,%lx", (long) found_addr
);
915 strcpy (own_buf
, "0");
917 strcpy (own_buf
, "E00");
923 #define require_running(BUF) \
924 if (!target_running ()) \
930 /* Parse options to --debug-format= and "monitor set debug-format".
931 ARG is the text after "--debug-format=" or "monitor set debug-format".
932 IS_MONITOR is non-zero if we're invoked via "monitor set debug-format".
933 This triggers calls to monitor_output.
934 The result is NULL if all options were parsed ok, otherwise an error
935 message which the caller must free.
937 N.B. These commands affect all debug format settings, they are not
938 cumulative. If a format is not specified, it is turned off.
939 However, we don't go to extra trouble with things like
940 "monitor set debug-format all,none,timestamp".
941 Instead we just parse them one at a time, in order.
943 The syntax for "monitor set debug" we support here is not identical
944 to gdb's "set debug foo on|off" because we also use this function to
945 parse "--debug-format=foo,bar". */
948 parse_debug_format_options (const char *arg
, int is_monitor
)
950 VEC (char_ptr
) *options
;
954 /* First turn all debug format options off. */
957 /* First remove leading spaces, for "monitor set debug-format". */
958 while (isspace (*arg
))
961 options
= delim_string_to_char_ptr_vec (arg
, ',');
963 for (ix
= 0; VEC_iterate (char_ptr
, options
, ix
, option
); ++ix
)
965 if (strcmp (option
, "all") == 0)
969 monitor_output ("All extra debug format options enabled.\n");
971 else if (strcmp (option
, "none") == 0)
975 monitor_output ("All extra debug format options disabled.\n");
977 #ifdef HAVE_GETTIMEOFDAY
978 else if (strcmp (option
, "timestamp") == 0)
982 monitor_output ("Timestamps will be added to debug output.\n");
985 else if (*option
== '\0')
987 /* An empty option, e.g., "--debug-format=foo,,bar", is ignored. */
992 char *msg
= xstrprintf ("Unknown debug-format argument: \"%s\"\n",
995 free_char_ptr_vec (options
);
1000 free_char_ptr_vec (options
);
1004 /* Handle monitor commands not handled by target-specific handlers. */
1007 handle_monitor_command (char *mon
, char *own_buf
)
1009 if (strcmp (mon
, "set debug 1") == 0)
1012 monitor_output ("Debug output enabled.\n");
1014 else if (strcmp (mon
, "set debug 0") == 0)
1017 monitor_output ("Debug output disabled.\n");
1019 else if (strcmp (mon
, "set debug-hw-points 1") == 0)
1021 debug_hw_points
= 1;
1022 monitor_output ("H/W point debugging output enabled.\n");
1024 else if (strcmp (mon
, "set debug-hw-points 0") == 0)
1026 debug_hw_points
= 0;
1027 monitor_output ("H/W point debugging output disabled.\n");
1029 else if (strcmp (mon
, "set remote-debug 1") == 0)
1032 monitor_output ("Protocol debug output enabled.\n");
1034 else if (strcmp (mon
, "set remote-debug 0") == 0)
1037 monitor_output ("Protocol debug output disabled.\n");
1039 else if (strncmp (mon
, "set debug-format ",
1040 sizeof ("set debug-format ") - 1) == 0)
1043 = parse_debug_format_options (mon
+ sizeof ("set debug-format ") - 1,
1046 if (error_msg
!= NULL
)
1048 monitor_output (error_msg
);
1049 monitor_show_help ();
1050 write_enn (own_buf
);
1054 else if (strcmp (mon
, "help") == 0)
1055 monitor_show_help ();
1056 else if (strcmp (mon
, "exit") == 0)
1060 monitor_output ("Unknown monitor command.\n\n");
1061 monitor_show_help ();
1062 write_enn (own_buf
);
1066 /* Associates a callback with each supported qXfer'able object. */
1070 /* The object this handler handles. */
1073 /* Request that the target transfer up to LEN 8-bit bytes of the
1074 target's OBJECT. The OFFSET, for a seekable object, specifies
1075 the starting point. The ANNEX can be used to provide additional
1076 data-specific information to the target.
1078 Return the number of bytes actually transfered, zero when no
1079 further transfer is possible, -1 on error, -2 when the transfer
1080 is not supported, and -3 on a verbose error message that should
1081 be preserved. Return of a positive value smaller than LEN does
1082 not indicate the end of the object, only the end of the transfer.
1084 One, and only one, of readbuf or writebuf must be non-NULL. */
1085 int (*xfer
) (const char *annex
,
1086 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1087 ULONGEST offset
, LONGEST len
);
1090 /* Handle qXfer:auxv:read. */
1093 handle_qxfer_auxv (const char *annex
,
1094 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1095 ULONGEST offset
, LONGEST len
)
1097 if (the_target
->read_auxv
== NULL
|| writebuf
!= NULL
)
1100 if (annex
[0] != '\0' || !target_running ())
1103 return (*the_target
->read_auxv
) (offset
, readbuf
, len
);
1106 /* Handle qXfer:features:read. */
1109 handle_qxfer_features (const char *annex
,
1110 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1111 ULONGEST offset
, LONGEST len
)
1113 const char *document
;
1116 if (writebuf
!= NULL
)
1119 if (!target_running ())
1122 /* Grab the correct annex. */
1123 document
= get_features_xml (annex
);
1124 if (document
== NULL
)
1127 total_len
= strlen (document
);
1129 if (offset
> total_len
)
1132 if (offset
+ len
> total_len
)
1133 len
= total_len
- offset
;
1135 memcpy (readbuf
, document
+ offset
, len
);
1139 /* Worker routine for handle_qxfer_libraries.
1140 Add to the length pointed to by ARG a conservative estimate of the
1141 length needed to transmit the file name of INF. */
1144 accumulate_file_name_length (struct inferior_list_entry
*inf
, void *arg
)
1146 struct dll_info
*dll
= (struct dll_info
*) inf
;
1147 unsigned int *total_len
= arg
;
1149 /* Over-estimate the necessary memory. Assume that every character
1150 in the library name must be escaped. */
1151 *total_len
+= 128 + 6 * strlen (dll
->name
);
1154 /* Worker routine for handle_qxfer_libraries.
1155 Emit the XML to describe the library in INF. */
1158 emit_dll_description (struct inferior_list_entry
*inf
, void *arg
)
1160 struct dll_info
*dll
= (struct dll_info
*) inf
;
1165 strcpy (p
, " <library name=\"");
1167 name
= xml_escape_text (dll
->name
);
1171 strcpy (p
, "\"><segment address=\"");
1173 sprintf (p
, "0x%lx", (long) dll
->base_addr
);
1175 strcpy (p
, "\"/></library>\n");
1181 /* Handle qXfer:libraries:read. */
1184 handle_qxfer_libraries (const char *annex
,
1185 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1186 ULONGEST offset
, LONGEST len
)
1188 unsigned int total_len
;
1191 if (writebuf
!= NULL
)
1194 if (annex
[0] != '\0' || !target_running ())
1198 for_each_inferior_with_data (&all_dlls
, accumulate_file_name_length
,
1201 document
= malloc (total_len
);
1202 if (document
== NULL
)
1205 strcpy (document
, "<library-list>\n");
1206 p
= document
+ strlen (document
);
1208 for_each_inferior_with_data (&all_dlls
, emit_dll_description
, &p
);
1210 strcpy (p
, "</library-list>\n");
1212 total_len
= strlen (document
);
1214 if (offset
> total_len
)
1220 if (offset
+ len
> total_len
)
1221 len
= total_len
- offset
;
1223 memcpy (readbuf
, document
+ offset
, len
);
1228 /* Handle qXfer:libraries-svr4:read. */
1231 handle_qxfer_libraries_svr4 (const char *annex
,
1232 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1233 ULONGEST offset
, LONGEST len
)
1235 if (writebuf
!= NULL
)
1238 if (!target_running () || the_target
->qxfer_libraries_svr4
== NULL
)
1241 return the_target
->qxfer_libraries_svr4 (annex
, readbuf
, writebuf
, offset
, len
);
1244 /* Handle qXfer:osadata:read. */
1247 handle_qxfer_osdata (const char *annex
,
1248 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1249 ULONGEST offset
, LONGEST len
)
1251 if (the_target
->qxfer_osdata
== NULL
|| writebuf
!= NULL
)
1254 return (*the_target
->qxfer_osdata
) (annex
, readbuf
, NULL
, offset
, len
);
1257 /* Handle qXfer:siginfo:read and qXfer:siginfo:write. */
1260 handle_qxfer_siginfo (const char *annex
,
1261 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1262 ULONGEST offset
, LONGEST len
)
1264 if (the_target
->qxfer_siginfo
== NULL
)
1267 if (annex
[0] != '\0' || !target_running ())
1270 return (*the_target
->qxfer_siginfo
) (annex
, readbuf
, writebuf
, offset
, len
);
1273 /* Handle qXfer:spu:read and qXfer:spu:write. */
1276 handle_qxfer_spu (const char *annex
,
1277 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1278 ULONGEST offset
, LONGEST len
)
1280 if (the_target
->qxfer_spu
== NULL
)
1283 if (!target_running ())
1286 return (*the_target
->qxfer_spu
) (annex
, readbuf
, writebuf
, offset
, len
);
1289 /* Handle qXfer:statictrace:read. */
1292 handle_qxfer_statictrace (const char *annex
,
1293 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1294 ULONGEST offset
, LONGEST len
)
1298 if (writebuf
!= NULL
)
1301 if (annex
[0] != '\0' || !target_running () || current_traceframe
== -1)
1304 if (traceframe_read_sdata (current_traceframe
, offset
,
1305 readbuf
, len
, &nbytes
))
1310 /* Helper for handle_qxfer_threads_proper.
1311 Emit the XML to describe the thread of INF. */
1314 handle_qxfer_threads_worker (struct inferior_list_entry
*inf
, void *arg
)
1316 struct thread_info
*thread
= (struct thread_info
*) inf
;
1317 struct buffer
*buffer
= arg
;
1318 ptid_t ptid
= thread_to_gdb_id (thread
);
1320 int core
= target_core_of_thread (ptid
);
1323 write_ptid (ptid_s
, ptid
);
1327 sprintf (core_s
, "%d", core
);
1328 buffer_xml_printf (buffer
, "<thread id=\"%s\" core=\"%s\"/>\n",
1333 buffer_xml_printf (buffer
, "<thread id=\"%s\"/>\n",
1338 /* Helper for handle_qxfer_threads. */
1341 handle_qxfer_threads_proper (struct buffer
*buffer
)
1343 buffer_grow_str (buffer
, "<threads>\n");
1345 for_each_inferior_with_data (&all_threads
, handle_qxfer_threads_worker
,
1348 buffer_grow_str0 (buffer
, "</threads>\n");
1351 /* Handle qXfer:threads:read. */
1354 handle_qxfer_threads (const char *annex
,
1355 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1356 ULONGEST offset
, LONGEST len
)
1358 static char *result
= 0;
1359 static unsigned int result_length
= 0;
1361 if (writebuf
!= NULL
)
1364 if (!target_running () || annex
[0] != '\0')
1369 struct buffer buffer
;
1370 /* When asked for data at offset 0, generate everything and store into
1371 'result'. Successive reads will be served off 'result'. */
1375 buffer_init (&buffer
);
1377 handle_qxfer_threads_proper (&buffer
);
1379 result
= buffer_finish (&buffer
);
1380 result_length
= strlen (result
);
1381 buffer_free (&buffer
);
1384 if (offset
>= result_length
)
1386 /* We're out of data. */
1393 if (len
> result_length
- offset
)
1394 len
= result_length
- offset
;
1396 memcpy (readbuf
, result
+ offset
, len
);
1401 /* Handle qXfer:traceframe-info:read. */
1404 handle_qxfer_traceframe_info (const char *annex
,
1405 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1406 ULONGEST offset
, LONGEST len
)
1408 static char *result
= 0;
1409 static unsigned int result_length
= 0;
1411 if (writebuf
!= NULL
)
1414 if (!target_running () || annex
[0] != '\0' || current_traceframe
== -1)
1419 struct buffer buffer
;
1421 /* When asked for data at offset 0, generate everything and
1422 store into 'result'. Successive reads will be served off
1426 buffer_init (&buffer
);
1428 traceframe_read_info (current_traceframe
, &buffer
);
1430 result
= buffer_finish (&buffer
);
1431 result_length
= strlen (result
);
1432 buffer_free (&buffer
);
1435 if (offset
>= result_length
)
1437 /* We're out of data. */
1444 if (len
> result_length
- offset
)
1445 len
= result_length
- offset
;
1447 memcpy (readbuf
, result
+ offset
, len
);
1451 /* Handle qXfer:fdpic:read. */
1454 handle_qxfer_fdpic (const char *annex
, gdb_byte
*readbuf
,
1455 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1457 if (the_target
->read_loadmap
== NULL
)
1460 if (!target_running ())
1463 return (*the_target
->read_loadmap
) (annex
, offset
, readbuf
, len
);
1466 /* Handle qXfer:btrace:read. */
1469 handle_qxfer_btrace (const char *annex
,
1470 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1471 ULONGEST offset
, LONGEST len
)
1473 static struct buffer cache
;
1474 struct thread_info
*thread
;
1477 if (the_target
->read_btrace
== NULL
|| writebuf
!= NULL
)
1480 if (!target_running ())
1483 if (ptid_equal (general_thread
, null_ptid
)
1484 || ptid_equal (general_thread
, minus_one_ptid
))
1486 strcpy (own_buf
, "E.Must select a single thread.");
1490 thread
= find_thread_ptid (general_thread
);
1493 strcpy (own_buf
, "E.No such thread.");
1497 if (thread
->btrace
== NULL
)
1499 strcpy (own_buf
, "E.Btrace not enabled.");
1503 if (strcmp (annex
, "all") == 0)
1504 type
= BTRACE_READ_ALL
;
1505 else if (strcmp (annex
, "new") == 0)
1506 type
= BTRACE_READ_NEW
;
1507 else if (strcmp (annex
, "delta") == 0)
1508 type
= BTRACE_READ_DELTA
;
1511 strcpy (own_buf
, "E.Bad annex.");
1517 buffer_free (&cache
);
1519 result
= target_read_btrace (thread
->btrace
, &cache
, type
);
1522 memcpy (own_buf
, cache
.buffer
, cache
.used_size
);
1526 else if (offset
> cache
.used_size
)
1528 buffer_free (&cache
);
1532 if (len
> cache
.used_size
- offset
)
1533 len
= cache
.used_size
- offset
;
1535 memcpy (readbuf
, cache
.buffer
+ offset
, len
);
1540 static const struct qxfer qxfer_packets
[] =
1542 { "auxv", handle_qxfer_auxv
},
1543 { "btrace", handle_qxfer_btrace
},
1544 { "fdpic", handle_qxfer_fdpic
},
1545 { "features", handle_qxfer_features
},
1546 { "libraries", handle_qxfer_libraries
},
1547 { "libraries-svr4", handle_qxfer_libraries_svr4
},
1548 { "osdata", handle_qxfer_osdata
},
1549 { "siginfo", handle_qxfer_siginfo
},
1550 { "spu", handle_qxfer_spu
},
1551 { "statictrace", handle_qxfer_statictrace
},
1552 { "threads", handle_qxfer_threads
},
1553 { "traceframe-info", handle_qxfer_traceframe_info
},
1557 handle_qxfer (char *own_buf
, int packet_len
, int *new_packet_len_p
)
1565 if (strncmp (own_buf
, "qXfer:", 6) != 0)
1568 /* Grab the object, r/w and annex. */
1569 if (decode_xfer (own_buf
+ 6, &object
, &rw
, &annex
, &offset
) < 0)
1571 write_enn (own_buf
);
1576 i
< sizeof (qxfer_packets
) / sizeof (qxfer_packets
[0]);
1579 const struct qxfer
*q
= &qxfer_packets
[i
];
1581 if (strcmp (object
, q
->object
) == 0)
1583 if (strcmp (rw
, "read") == 0)
1585 unsigned char *data
;
1590 /* Grab the offset and length. */
1591 if (decode_xfer_read (offset
, &ofs
, &len
) < 0)
1593 write_enn (own_buf
);
1597 /* Read one extra byte, as an indicator of whether there is
1599 if (len
> PBUFSIZ
- 2)
1601 data
= malloc (len
+ 1);
1604 write_enn (own_buf
);
1607 n
= (*q
->xfer
) (annex
, data
, NULL
, ofs
, len
+ 1);
1615 /* Preserve error message. */
1618 write_enn (own_buf
);
1620 *new_packet_len_p
= write_qxfer_response (own_buf
, data
, len
, 1);
1622 *new_packet_len_p
= write_qxfer_response (own_buf
, data
, n
, 0);
1627 else if (strcmp (rw
, "write") == 0)
1632 unsigned char *data
;
1634 strcpy (own_buf
, "E00");
1635 data
= malloc (packet_len
- (offset
- own_buf
));
1638 write_enn (own_buf
);
1641 if (decode_xfer_write (offset
, packet_len
- (offset
- own_buf
),
1642 &ofs
, &len
, data
) < 0)
1645 write_enn (own_buf
);
1649 n
= (*q
->xfer
) (annex
, NULL
, data
, ofs
, len
);
1657 /* Preserve error message. */
1660 write_enn (own_buf
);
1662 sprintf (own_buf
, "%x", n
);
1675 /* Table used by the crc32 function to calcuate the checksum. */
1677 static unsigned int crc32_table
[256] =
1680 /* Compute 32 bit CRC from inferior memory.
1682 On success, return 32 bit CRC.
1683 On failure, return (unsigned long long) -1. */
1685 static unsigned long long
1686 crc32 (CORE_ADDR base
, int len
, unsigned int crc
)
1688 if (!crc32_table
[1])
1690 /* Initialize the CRC table and the decoding table. */
1694 for (i
= 0; i
< 256; i
++)
1696 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
1697 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
1704 unsigned char byte
= 0;
1706 /* Return failure if memory read fails. */
1707 if (read_inferior_memory (base
, &byte
, 1) != 0)
1708 return (unsigned long long) -1;
1710 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ byte
) & 255];
1713 return (unsigned long long) crc
;
1716 /* Handle all of the extended 'q' packets. */
1719 handle_query (char *own_buf
, int packet_len
, int *new_packet_len_p
)
1721 static struct inferior_list_entry
*thread_ptr
;
1723 /* Reply the current thread id. */
1724 if (strcmp ("qC", own_buf
) == 0 && !disable_packet_qC
)
1727 require_running (own_buf
);
1729 if (!ptid_equal (general_thread
, null_ptid
)
1730 && !ptid_equal (general_thread
, minus_one_ptid
))
1731 gdb_id
= general_thread
;
1734 thread_ptr
= get_first_inferior (&all_threads
);
1735 gdb_id
= thread_to_gdb_id ((struct thread_info
*)thread_ptr
);
1738 sprintf (own_buf
, "QC");
1740 write_ptid (own_buf
, gdb_id
);
1744 if (strcmp ("qSymbol::", own_buf
) == 0)
1746 /* GDB is suggesting new symbols have been loaded. This may
1747 mean a new shared library has been detected as loaded, so
1748 take the opportunity to check if breakpoints we think are
1749 inserted, still are. Note that it isn't guaranteed that
1750 we'll see this when a shared library is loaded, and nor will
1751 we see this for unloads (although breakpoints in unloaded
1752 libraries shouldn't trigger), as GDB may not find symbols for
1753 the library at all. We also re-validate breakpoints when we
1754 see a second GDB breakpoint for the same address, and or when
1755 we access breakpoint shadows. */
1756 validate_breakpoints ();
1758 if (target_supports_tracepoints ())
1759 tracepoint_look_up_symbols ();
1761 if (target_running () && the_target
->look_up_symbols
!= NULL
)
1762 (*the_target
->look_up_symbols
) ();
1764 strcpy (own_buf
, "OK");
1768 if (!disable_packet_qfThreadInfo
)
1770 if (strcmp ("qfThreadInfo", own_buf
) == 0)
1774 require_running (own_buf
);
1775 thread_ptr
= get_first_inferior (&all_threads
);
1778 gdb_id
= thread_to_gdb_id ((struct thread_info
*)thread_ptr
);
1779 write_ptid (own_buf
, gdb_id
);
1780 thread_ptr
= thread_ptr
->next
;
1784 if (strcmp ("qsThreadInfo", own_buf
) == 0)
1788 require_running (own_buf
);
1789 if (thread_ptr
!= NULL
)
1792 gdb_id
= thread_to_gdb_id ((struct thread_info
*)thread_ptr
);
1793 write_ptid (own_buf
, gdb_id
);
1794 thread_ptr
= thread_ptr
->next
;
1799 sprintf (own_buf
, "l");
1805 if (the_target
->read_offsets
!= NULL
1806 && strcmp ("qOffsets", own_buf
) == 0)
1808 CORE_ADDR text
, data
;
1810 require_running (own_buf
);
1811 if (the_target
->read_offsets (&text
, &data
))
1812 sprintf (own_buf
, "Text=%lX;Data=%lX;Bss=%lX",
1813 (long)text
, (long)data
, (long)data
);
1815 write_enn (own_buf
);
1820 /* Protocol features query. */
1821 if (strncmp ("qSupported", own_buf
, 10) == 0
1822 && (own_buf
[10] == ':' || own_buf
[10] == '\0'))
1824 char *p
= &own_buf
[10];
1825 int gdb_supports_qRelocInsn
= 0;
1827 /* Start processing qSupported packet. */
1828 target_process_qsupported (NULL
);
1830 /* Process each feature being provided by GDB. The first
1831 feature will follow a ':', and latter features will follow
1835 char **qsupported
= NULL
;
1839 /* Two passes, to avoid nested strtok calls in
1840 target_process_qsupported. */
1841 for (p
= strtok (p
+ 1, ";");
1843 p
= strtok (NULL
, ";"))
1846 qsupported
= xrealloc (qsupported
, count
* sizeof (char *));
1847 qsupported
[count
- 1] = xstrdup (p
);
1850 for (i
= 0; i
< count
; i
++)
1853 if (strcmp (p
, "multiprocess+") == 0)
1855 /* GDB supports and wants multi-process support if
1857 if (target_supports_multi_process ())
1860 else if (strcmp (p
, "qRelocInsn+") == 0)
1862 /* GDB supports relocate instruction requests. */
1863 gdb_supports_qRelocInsn
= 1;
1866 target_process_qsupported (p
);
1875 "PacketSize=%x;QPassSignals+;QProgramSignals+",
1878 if (the_target
->qxfer_libraries_svr4
!= NULL
)
1879 strcat (own_buf
, ";qXfer:libraries-svr4:read+"
1880 ";augmented-libraries-svr4-read+");
1883 /* We do not have any hook to indicate whether the non-SVR4 target
1884 backend supports qXfer:libraries:read, so always report it. */
1885 strcat (own_buf
, ";qXfer:libraries:read+");
1888 if (the_target
->read_auxv
!= NULL
)
1889 strcat (own_buf
, ";qXfer:auxv:read+");
1891 if (the_target
->qxfer_spu
!= NULL
)
1892 strcat (own_buf
, ";qXfer:spu:read+;qXfer:spu:write+");
1894 if (the_target
->qxfer_siginfo
!= NULL
)
1895 strcat (own_buf
, ";qXfer:siginfo:read+;qXfer:siginfo:write+");
1897 if (the_target
->read_loadmap
!= NULL
)
1898 strcat (own_buf
, ";qXfer:fdpic:read+");
1900 /* We always report qXfer:features:read, as targets may
1901 install XML files on a subsequent call to arch_setup.
1902 If we reported to GDB on startup that we don't support
1903 qXfer:feature:read at all, we will never be re-queried. */
1904 strcat (own_buf
, ";qXfer:features:read+");
1906 if (transport_is_reliable
)
1907 strcat (own_buf
, ";QStartNoAckMode+");
1909 if (the_target
->qxfer_osdata
!= NULL
)
1910 strcat (own_buf
, ";qXfer:osdata:read+");
1912 if (target_supports_multi_process ())
1913 strcat (own_buf
, ";multiprocess+");
1915 if (target_supports_non_stop ())
1916 strcat (own_buf
, ";QNonStop+");
1918 if (target_supports_disable_randomization ())
1919 strcat (own_buf
, ";QDisableRandomization+");
1921 strcat (own_buf
, ";qXfer:threads:read+");
1923 if (target_supports_tracepoints ())
1925 strcat (own_buf
, ";ConditionalTracepoints+");
1926 strcat (own_buf
, ";TraceStateVariables+");
1927 strcat (own_buf
, ";TracepointSource+");
1928 strcat (own_buf
, ";DisconnectedTracing+");
1929 if (gdb_supports_qRelocInsn
&& target_supports_fast_tracepoints ())
1930 strcat (own_buf
, ";FastTracepoints+");
1931 strcat (own_buf
, ";StaticTracepoints+");
1932 strcat (own_buf
, ";InstallInTrace+");
1933 strcat (own_buf
, ";qXfer:statictrace:read+");
1934 strcat (own_buf
, ";qXfer:traceframe-info:read+");
1935 strcat (own_buf
, ";EnableDisableTracepoints+");
1936 strcat (own_buf
, ";QTBuffer:size+");
1937 strcat (own_buf
, ";tracenz+");
1940 /* Support target-side breakpoint conditions and commands. */
1941 strcat (own_buf
, ";ConditionalBreakpoints+");
1942 strcat (own_buf
, ";BreakpointCommands+");
1944 if (target_supports_agent ())
1945 strcat (own_buf
, ";QAgent+");
1947 if (target_supports_btrace ())
1949 strcat (own_buf
, ";Qbtrace:bts+");
1950 strcat (own_buf
, ";Qbtrace:off+");
1951 strcat (own_buf
, ";qXfer:btrace:read+");
1957 /* Thread-local storage support. */
1958 if (the_target
->get_tls_address
!= NULL
1959 && strncmp ("qGetTLSAddr:", own_buf
, 12) == 0)
1961 char *p
= own_buf
+ 12;
1962 CORE_ADDR parts
[2], address
= 0;
1964 ptid_t ptid
= null_ptid
;
1966 require_running (own_buf
);
1968 for (i
= 0; i
< 3; i
++)
1976 p2
= strchr (p
, ',');
1989 ptid
= read_ptid (p
, NULL
);
1991 decode_address (&parts
[i
- 1], p
, len
);
1995 if (p
!= NULL
|| i
< 3)
1999 struct thread_info
*thread
= find_thread_ptid (ptid
);
2004 err
= the_target
->get_tls_address (thread
, parts
[0], parts
[1],
2010 strcpy (own_buf
, paddress(address
));
2015 write_enn (own_buf
);
2019 /* Otherwise, pretend we do not understand this packet. */
2022 /* Windows OS Thread Information Block address support. */
2023 if (the_target
->get_tib_address
!= NULL
2024 && strncmp ("qGetTIBAddr:", own_buf
, 12) == 0)
2029 ptid_t ptid
= read_ptid (own_buf
+ 12, &annex
);
2031 n
= (*the_target
->get_tib_address
) (ptid
, &tlb
);
2034 strcpy (own_buf
, paddress(tlb
));
2039 write_enn (own_buf
);
2045 /* Handle "monitor" commands. */
2046 if (strncmp ("qRcmd,", own_buf
, 6) == 0)
2048 char *mon
= malloc (PBUFSIZ
);
2049 int len
= strlen (own_buf
+ 6);
2053 write_enn (own_buf
);
2058 || hex2bin (own_buf
+ 6, (gdb_byte
*) mon
, len
/ 2) != len
/ 2)
2060 write_enn (own_buf
);
2064 mon
[len
/ 2] = '\0';
2068 if (the_target
->handle_monitor_command
== NULL
2069 || (*the_target
->handle_monitor_command
) (mon
) == 0)
2070 /* Default processing. */
2071 handle_monitor_command (mon
, own_buf
);
2077 if (strncmp ("qSearch:memory:", own_buf
,
2078 sizeof ("qSearch:memory:") - 1) == 0)
2080 require_running (own_buf
);
2081 handle_search_memory (own_buf
, packet_len
);
2085 if (strcmp (own_buf
, "qAttached") == 0
2086 || strncmp (own_buf
, "qAttached:", sizeof ("qAttached:") - 1) == 0)
2088 struct process_info
*process
;
2090 if (own_buf
[sizeof ("qAttached") - 1])
2092 int pid
= strtoul (own_buf
+ sizeof ("qAttached:") - 1, NULL
, 16);
2093 process
= (struct process_info
*)
2094 find_inferior_id (&all_processes
, pid_to_ptid (pid
));
2098 require_running (own_buf
);
2099 process
= current_process ();
2102 if (process
== NULL
)
2104 write_enn (own_buf
);
2108 strcpy (own_buf
, process
->attached
? "1" : "0");
2112 if (strncmp ("qCRC:", own_buf
, 5) == 0)
2114 /* CRC check (compare-section). */
2118 unsigned long long crc
;
2120 require_running (own_buf
);
2121 comma
= unpack_varlen_hex (own_buf
+ 5, &base
);
2122 if (*comma
++ != ',')
2124 write_enn (own_buf
);
2127 len
= strtoul (comma
, NULL
, 16);
2128 crc
= crc32 (base
, len
, 0xffffffff);
2129 /* Check for memory failure. */
2130 if (crc
== (unsigned long long) -1)
2132 write_enn (own_buf
);
2135 sprintf (own_buf
, "C%lx", (unsigned long) crc
);
2139 if (handle_qxfer (own_buf
, packet_len
, new_packet_len_p
))
2142 if (target_supports_tracepoints () && handle_tracepoint_query (own_buf
))
2145 /* Otherwise we didn't know what packet it was. Say we didn't
2150 static void gdb_wants_all_threads_stopped (void);
2151 static void resume (struct thread_resume
*actions
, size_t n
);
2153 /* The callback that is passed to visit_actioned_threads. */
2154 typedef int (visit_actioned_threads_callback_ftype
)
2155 (const struct thread_resume
*, struct thread_info
*);
2157 /* Struct to pass data to visit_actioned_threads. */
2159 struct visit_actioned_threads_data
2161 const struct thread_resume
*actions
;
2163 visit_actioned_threads_callback_ftype
*callback
;
2166 /* Call CALLBACK for any thread to which ACTIONS applies to. Returns
2167 true if CALLBACK returns true. Returns false if no matching thread
2168 is found or CALLBACK results false.
2169 Note: This function is itself a callback for find_inferior. */
2172 visit_actioned_threads (struct inferior_list_entry
*entry
, void *datap
)
2174 struct visit_actioned_threads_data
*data
= datap
;
2175 const struct thread_resume
*actions
= data
->actions
;
2176 size_t num_actions
= data
->num_actions
;
2177 visit_actioned_threads_callback_ftype
*callback
= data
->callback
;
2180 for (i
= 0; i
< num_actions
; i
++)
2182 const struct thread_resume
*action
= &actions
[i
];
2184 if (ptid_equal (action
->thread
, minus_one_ptid
)
2185 || ptid_equal (action
->thread
, entry
->id
)
2186 || ((ptid_get_pid (action
->thread
)
2187 == ptid_get_pid (entry
->id
))
2188 && ptid_get_lwp (action
->thread
) == -1))
2190 struct thread_info
*thread
= (struct thread_info
*) entry
;
2192 if ((*callback
) (action
, thread
))
2200 /* Callback for visit_actioned_threads. If the thread has a pending
2201 status to report, report it now. */
2204 handle_pending_status (const struct thread_resume
*resumption
,
2205 struct thread_info
*thread
)
2207 if (thread
->status_pending_p
)
2209 thread
->status_pending_p
= 0;
2211 last_status
= thread
->last_status
;
2212 last_ptid
= thread
->entry
.id
;
2213 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
2219 /* Parse vCont packets. */
2221 handle_v_cont (char *own_buf
)
2225 struct thread_resume
*resume_info
;
2226 struct thread_resume default_action
= {{0}};
2228 /* Count the number of semicolons in the packet. There should be one
2229 for every action. */
2235 p
= strchr (p
, ';');
2238 resume_info
= malloc (n
* sizeof (resume_info
[0]));
2239 if (resume_info
== NULL
)
2247 memset (&resume_info
[i
], 0, sizeof resume_info
[i
]);
2249 if (p
[0] == 's' || p
[0] == 'S')
2250 resume_info
[i
].kind
= resume_step
;
2251 else if (p
[0] == 'r')
2252 resume_info
[i
].kind
= resume_step
;
2253 else if (p
[0] == 'c' || p
[0] == 'C')
2254 resume_info
[i
].kind
= resume_continue
;
2255 else if (p
[0] == 't')
2256 resume_info
[i
].kind
= resume_stop
;
2260 if (p
[0] == 'S' || p
[0] == 'C')
2263 sig
= strtol (p
+ 1, &q
, 16);
2268 if (!gdb_signal_to_host_p (sig
))
2270 resume_info
[i
].sig
= gdb_signal_to_host (sig
);
2272 else if (p
[0] == 'r')
2276 p
= unpack_varlen_hex (p
+ 1, &addr
);
2277 resume_info
[i
].step_range_start
= addr
;
2282 p
= unpack_varlen_hex (p
+ 1, &addr
);
2283 resume_info
[i
].step_range_end
= addr
;
2292 resume_info
[i
].thread
= minus_one_ptid
;
2293 default_action
= resume_info
[i
];
2295 /* Note: we don't increment i here, we'll overwrite this entry
2296 the next time through. */
2298 else if (p
[0] == ':')
2300 ptid_t ptid
= read_ptid (p
+ 1, &q
);
2305 if (p
[0] != ';' && p
[0] != 0)
2308 resume_info
[i
].thread
= ptid
;
2315 resume_info
[i
] = default_action
;
2317 /* `cont_thread' is still used in occasional places in the backend,
2318 to implement single-thread scheduler-locking. Doesn't make sense
2319 to set it if we see a stop request, or a wildcard action (one
2320 with '-1' (all threads), or 'pPID.-1' (all threads of PID)). */
2322 && !(ptid_equal (resume_info
[0].thread
, minus_one_ptid
)
2323 || ptid_get_lwp (resume_info
[0].thread
) == -1)
2324 && resume_info
[0].kind
!= resume_stop
)
2325 cont_thread
= resume_info
[0].thread
;
2327 cont_thread
= minus_one_ptid
;
2328 set_desired_inferior (0);
2330 resume (resume_info
, n
);
2335 write_enn (own_buf
);
2340 /* Resume target with ACTIONS, an array of NUM_ACTIONS elements. */
2343 resume (struct thread_resume
*actions
, size_t num_actions
)
2347 /* Check if among the threads that GDB wants actioned, there's
2348 one with a pending status to report. If so, skip actually
2349 resuming/stopping and report the pending event
2351 struct visit_actioned_threads_data data
;
2353 data
.actions
= actions
;
2354 data
.num_actions
= num_actions
;
2355 data
.callback
= handle_pending_status
;
2356 if (find_inferior (&all_threads
, visit_actioned_threads
, &data
) != NULL
)
2362 (*the_target
->resume
) (actions
, num_actions
);
2368 last_ptid
= mywait (minus_one_ptid
, &last_status
, 0, 1);
2370 if (last_status
.kind
== TARGET_WAITKIND_NO_RESUMED
)
2372 /* No proper RSP support for this yet. At least return
2374 sprintf (own_buf
, "E.No unwaited-for children left.");
2375 disable_async_io ();
2379 if (last_status
.kind
!= TARGET_WAITKIND_EXITED
2380 && last_status
.kind
!= TARGET_WAITKIND_SIGNALLED
2381 && last_status
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
2382 current_inferior
->last_status
= last_status
;
2384 /* From the client's perspective, all-stop mode always stops all
2385 threads implicitly (and the target backend has already done
2386 so by now). Tag all threads as "want-stopped", so we don't
2387 resume them implicitly without the client telling us to. */
2388 gdb_wants_all_threads_stopped ();
2389 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
2390 disable_async_io ();
2392 if (last_status
.kind
== TARGET_WAITKIND_EXITED
2393 || last_status
.kind
== TARGET_WAITKIND_SIGNALLED
)
2394 mourn_inferior (find_process_pid (ptid_get_pid (last_ptid
)));
2398 /* Attach to a new program. Return 1 if successful, 0 if failure. */
2400 handle_v_attach (char *own_buf
)
2404 pid
= strtol (own_buf
+ 8, NULL
, 16);
2405 if (pid
!= 0 && attach_inferior (pid
) == 0)
2407 /* Don't report shared library events after attaching, even if
2408 some libraries are preloaded. GDB will always poll the
2409 library list. Avoids the "stopped by shared library event"
2410 notice on the GDB side. */
2415 /* In non-stop, we don't send a resume reply. Stop events
2416 will follow up using the normal notification
2421 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
2427 write_enn (own_buf
);
2432 /* Run a new program. Return 1 if successful, 0 if failure. */
2434 handle_v_run (char *own_buf
)
2436 char *p
, *next_p
, **new_argv
;
2440 for (p
= own_buf
+ strlen ("vRun;"); p
&& *p
; p
= strchr (p
, ';'))
2446 new_argv
= calloc (new_argc
+ 2, sizeof (char *));
2447 if (new_argv
== NULL
)
2449 write_enn (own_buf
);
2454 for (p
= own_buf
+ strlen ("vRun;"); *p
; p
= next_p
)
2456 next_p
= strchr (p
, ';');
2458 next_p
= p
+ strlen (p
);
2460 if (i
== 0 && p
== next_p
)
2464 /* FIXME: Fail request if out of memory instead of dying. */
2465 new_argv
[i
] = xmalloc (1 + (next_p
- p
) / 2);
2466 hex2bin (p
, (gdb_byte
*) new_argv
[i
], (next_p
- p
) / 2);
2467 new_argv
[i
][(next_p
- p
) / 2] = '\0';
2476 if (new_argv
[0] == NULL
)
2478 /* GDB didn't specify a program to run. Use the program from the
2479 last run with the new argument list. */
2481 if (program_argv
== NULL
)
2483 write_enn (own_buf
);
2484 freeargv (new_argv
);
2488 new_argv
[0] = strdup (program_argv
[0]);
2489 if (new_argv
[0] == NULL
)
2491 write_enn (own_buf
);
2492 freeargv (new_argv
);
2497 /* Free the old argv and install the new one. */
2498 freeargv (program_argv
);
2499 program_argv
= new_argv
;
2501 start_inferior (program_argv
);
2502 if (last_status
.kind
== TARGET_WAITKIND_STOPPED
)
2504 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
2506 /* In non-stop, sending a resume reply doesn't set the general
2507 thread, but GDB assumes a vRun sets it (this is so GDB can
2508 query which is the main thread of the new inferior. */
2510 general_thread
= last_ptid
;
2516 write_enn (own_buf
);
2521 /* Kill process. Return 1 if successful, 0 if failure. */
2523 handle_v_kill (char *own_buf
)
2526 char *p
= &own_buf
[6];
2528 pid
= strtol (p
, NULL
, 16);
2531 if (pid
!= 0 && kill_inferior (pid
) == 0)
2533 last_status
.kind
= TARGET_WAITKIND_SIGNALLED
;
2534 last_status
.value
.sig
= GDB_SIGNAL_KILL
;
2535 last_ptid
= pid_to_ptid (pid
);
2536 discard_queued_stop_replies (pid
);
2542 write_enn (own_buf
);
2547 /* Handle all of the extended 'v' packets. */
2549 handle_v_requests (char *own_buf
, int packet_len
, int *new_packet_len
)
2551 if (!disable_packet_vCont
)
2553 if (strncmp (own_buf
, "vCont;", 6) == 0)
2555 require_running (own_buf
);
2556 handle_v_cont (own_buf
);
2560 if (strncmp (own_buf
, "vCont?", 6) == 0)
2562 strcpy (own_buf
, "vCont;c;C;s;S;t");
2563 if (target_supports_range_stepping ())
2565 own_buf
= own_buf
+ strlen (own_buf
);
2566 strcpy (own_buf
, ";r");
2572 if (strncmp (own_buf
, "vFile:", 6) == 0
2573 && handle_vFile (own_buf
, packet_len
, new_packet_len
))
2576 if (strncmp (own_buf
, "vAttach;", 8) == 0)
2578 if ((!extended_protocol
|| !multi_process
) && target_running ())
2580 fprintf (stderr
, "Already debugging a process\n");
2581 write_enn (own_buf
);
2584 handle_v_attach (own_buf
);
2588 if (strncmp (own_buf
, "vRun;", 5) == 0)
2590 if ((!extended_protocol
|| !multi_process
) && target_running ())
2592 fprintf (stderr
, "Already debugging a process\n");
2593 write_enn (own_buf
);
2596 handle_v_run (own_buf
);
2600 if (strncmp (own_buf
, "vKill;", 6) == 0)
2602 if (!target_running ())
2604 fprintf (stderr
, "No process to kill\n");
2605 write_enn (own_buf
);
2608 handle_v_kill (own_buf
);
2612 if (handle_notif_ack (own_buf
, packet_len
))
2615 /* Otherwise we didn't know what packet it was. Say we didn't
2621 /* Resume inferior and wait for another event. In non-stop mode,
2622 don't really wait here, but return immediatelly to the event
2625 myresume (char *own_buf
, int step
, int sig
)
2627 struct thread_resume resume_info
[2];
2629 int valid_cont_thread
;
2631 set_desired_inferior (0);
2633 valid_cont_thread
= (!ptid_equal (cont_thread
, null_ptid
)
2634 && !ptid_equal (cont_thread
, minus_one_ptid
));
2636 if (step
|| sig
|| valid_cont_thread
)
2638 resume_info
[0].thread
= current_ptid
;
2640 resume_info
[0].kind
= resume_step
;
2642 resume_info
[0].kind
= resume_continue
;
2643 resume_info
[0].sig
= sig
;
2647 if (!valid_cont_thread
)
2649 resume_info
[n
].thread
= minus_one_ptid
;
2650 resume_info
[n
].kind
= resume_continue
;
2651 resume_info
[n
].sig
= 0;
2655 resume (resume_info
, n
);
2658 /* Callback for for_each_inferior. Make a new stop reply for each
2662 queue_stop_reply_callback (struct inferior_list_entry
*entry
, void *arg
)
2664 struct thread_info
*thread
= (struct thread_info
*) entry
;
2666 /* For now, assume targets that don't have this callback also don't
2667 manage the thread's last_status field. */
2668 if (the_target
->thread_stopped
== NULL
)
2670 struct vstop_notif
*new_notif
= xmalloc (sizeof (*new_notif
));
2672 new_notif
->ptid
= entry
->id
;
2673 new_notif
->status
= thread
->last_status
;
2674 /* Pass the last stop reply back to GDB, but don't notify
2676 notif_event_enque (¬if_stop
,
2677 (struct notif_event
*) new_notif
);
2681 if (thread_stopped (thread
))
2686 = target_waitstatus_to_string (&thread
->last_status
);
2688 debug_printf ("Reporting thread %s as already stopped with %s\n",
2689 target_pid_to_str (entry
->id
),
2692 xfree (status_string
);
2695 gdb_assert (thread
->last_status
.kind
!= TARGET_WAITKIND_IGNORE
);
2697 /* Pass the last stop reply back to GDB, but don't notify
2699 queue_stop_reply (entry
->id
, &thread
->last_status
);
2706 /* Set this inferior threads's state as "want-stopped". We won't
2707 resume this thread until the client gives us another action for
2711 gdb_wants_thread_stopped (struct inferior_list_entry
*entry
)
2713 struct thread_info
*thread
= (struct thread_info
*) entry
;
2715 thread
->last_resume_kind
= resume_stop
;
2717 if (thread
->last_status
.kind
== TARGET_WAITKIND_IGNORE
)
2719 /* Most threads are stopped implicitly (all-stop); tag that with
2721 thread
->last_status
.kind
= TARGET_WAITKIND_STOPPED
;
2722 thread
->last_status
.value
.sig
= GDB_SIGNAL_0
;
2726 /* Set all threads' states as "want-stopped". */
2729 gdb_wants_all_threads_stopped (void)
2731 for_each_inferior (&all_threads
, gdb_wants_thread_stopped
);
2734 /* Clear the gdb_detached flag of every process. */
2737 gdb_reattached_process (struct inferior_list_entry
*entry
)
2739 struct process_info
*process
= (struct process_info
*) entry
;
2741 process
->gdb_detached
= 0;
2744 /* Callback for for_each_inferior. Clear the thread's pending status
2748 clear_pending_status_callback (struct inferior_list_entry
*entry
)
2750 struct thread_info
*thread
= (struct thread_info
*) entry
;
2752 thread
->status_pending_p
= 0;
2755 /* Callback for for_each_inferior. If the thread is stopped with an
2756 interesting event, mark it as having a pending event. */
2759 set_pending_status_callback (struct inferior_list_entry
*entry
)
2761 struct thread_info
*thread
= (struct thread_info
*) entry
;
2763 if (thread
->last_status
.kind
!= TARGET_WAITKIND_STOPPED
2764 || (thread
->last_status
.value
.sig
!= GDB_SIGNAL_0
2765 /* A breakpoint, watchpoint or finished step from a previous
2766 GDB run isn't considered interesting for a new GDB run.
2767 If we left those pending, the new GDB could consider them
2768 random SIGTRAPs. This leaves out real async traps. We'd
2769 have to peek into the (target-specific) siginfo to
2770 distinguish those. */
2771 && thread
->last_status
.value
.sig
!= GDB_SIGNAL_TRAP
))
2772 thread
->status_pending_p
= 1;
2775 /* Callback for find_inferior. Return true if ENTRY (a thread) has a
2776 pending status to report to GDB. */
2779 find_status_pending_thread_callback (struct inferior_list_entry
*entry
, void *data
)
2781 struct thread_info
*thread
= (struct thread_info
*) entry
;
2783 return thread
->status_pending_p
;
2786 /* Status handler for the '?' packet. */
2789 handle_status (char *own_buf
)
2791 /* GDB is connected, don't forward events to the target anymore. */
2792 for_each_inferior (&all_processes
, gdb_reattached_process
);
2794 /* In non-stop mode, we must send a stop reply for each stopped
2795 thread. In all-stop mode, just send one for the first stopped
2800 find_inferior (&all_threads
, queue_stop_reply_callback
, NULL
);
2802 /* The first is sent immediatly. OK is sent if there is no
2803 stopped thread, which is the same handling of the vStopped
2804 packet (by design). */
2805 notif_write_event (¬if_stop
, own_buf
);
2809 struct inferior_list_entry
*thread
= NULL
;
2812 stabilize_threads ();
2813 gdb_wants_all_threads_stopped ();
2815 /* We can only report one status, but we might be coming out of
2816 non-stop -- if more than one thread is stopped with
2817 interesting events, leave events for the threads we're not
2818 reporting now pending. They'll be reported the next time the
2819 threads are resumed. Start by marking all interesting events
2821 for_each_inferior (&all_threads
, set_pending_status_callback
);
2823 /* Prefer the last thread that reported an event to GDB (even if
2824 that was a GDB_SIGNAL_TRAP). */
2825 if (last_status
.kind
!= TARGET_WAITKIND_IGNORE
2826 && last_status
.kind
!= TARGET_WAITKIND_EXITED
2827 && last_status
.kind
!= TARGET_WAITKIND_SIGNALLED
)
2828 thread
= find_inferior_id (&all_threads
, last_ptid
);
2830 /* If the last event thread is not found for some reason, look
2831 for some other thread that might have an event to report. */
2833 thread
= find_inferior (&all_threads
,
2834 find_status_pending_thread_callback
, NULL
);
2836 /* If we're still out of luck, simply pick the first thread in
2839 thread
= get_first_inferior (&all_threads
);
2843 struct thread_info
*tp
= (struct thread_info
*) thread
;
2845 /* We're reporting this event, so it's no longer
2847 tp
->status_pending_p
= 0;
2849 /* GDB assumes the current thread is the thread we're
2850 reporting the status for. */
2851 general_thread
= thread
->id
;
2852 set_desired_inferior (1);
2854 gdb_assert (tp
->last_status
.kind
!= TARGET_WAITKIND_IGNORE
);
2855 prepare_resume_reply (own_buf
, tp
->entry
.id
, &tp
->last_status
);
2858 strcpy (own_buf
, "W00");
2863 gdbserver_version (void)
2865 printf ("GNU gdbserver %s%s\n"
2866 "Copyright (C) 2014 Free Software Foundation, Inc.\n"
2867 "gdbserver is free software, covered by the "
2868 "GNU General Public License.\n"
2869 "This gdbserver was configured as \"%s\"\n",
2870 PKGVERSION
, version
, host_name
);
2874 gdbserver_usage (FILE *stream
)
2876 fprintf (stream
, "Usage:\tgdbserver [OPTIONS] COMM PROG [ARGS ...]\n"
2877 "\tgdbserver [OPTIONS] --attach COMM PID\n"
2878 "\tgdbserver [OPTIONS] --multi COMM\n"
2880 "COMM may either be a tty device (for serial debugging), or \n"
2881 "HOST:PORT to listen for a TCP connection.\n"
2884 " --debug Enable general debugging output.\n"
2885 " --debug-format=opt1[,opt2,...]\n"
2886 " Specify extra content in debugging output.\n"
2890 #ifdef HAVE_GETTIMEOFDAY
2893 " --remote-debug Enable remote protocol debugging output.\n"
2894 " --version Display version information and exit.\n"
2895 " --wrapper WRAPPER -- Run WRAPPER to start new programs.\n"
2896 " --once Exit after the first connection has "
2898 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
2899 fprintf (stream
, "Report bugs to \"%s\".\n", REPORT_BUGS_TO
);
2903 gdbserver_show_disableable (FILE *stream
)
2905 fprintf (stream
, "Disableable packets:\n"
2906 " vCont \tAll vCont packets\n"
2907 " qC \tQuerying the current thread\n"
2908 " qfThreadInfo\tThread listing\n"
2909 " Tthread \tPassing the thread specifier in the "
2910 "T stop reply packet\n"
2911 " threads \tAll of the above\n");
2915 #undef require_running
2916 #define require_running(BUF) \
2917 if (!target_running ()) \
2924 first_thread_of (struct inferior_list_entry
*entry
, void *args
)
2926 int pid
= * (int *) args
;
2928 if (ptid_get_pid (entry
->id
) == pid
)
2935 kill_inferior_callback (struct inferior_list_entry
*entry
)
2937 struct process_info
*process
= (struct process_info
*) entry
;
2938 int pid
= ptid_get_pid (process
->entry
.id
);
2940 kill_inferior (pid
);
2941 discard_queued_stop_replies (pid
);
2944 /* Callback for for_each_inferior to detach or kill the inferior,
2945 depending on whether we attached to it or not.
2946 We inform the user whether we're detaching or killing the process
2947 as this is only called when gdbserver is about to exit. */
2950 detach_or_kill_inferior_callback (struct inferior_list_entry
*entry
)
2952 struct process_info
*process
= (struct process_info
*) entry
;
2953 int pid
= ptid_get_pid (process
->entry
.id
);
2955 if (process
->attached
)
2956 detach_inferior (pid
);
2958 kill_inferior (pid
);
2960 discard_queued_stop_replies (pid
);
2963 /* for_each_inferior callback for detach_or_kill_for_exit to print
2964 the pids of started inferiors. */
2967 print_started_pid (struct inferior_list_entry
*entry
)
2969 struct process_info
*process
= (struct process_info
*) entry
;
2971 if (! process
->attached
)
2973 int pid
= ptid_get_pid (process
->entry
.id
);
2974 fprintf (stderr
, " %d", pid
);
2978 /* for_each_inferior callback for detach_or_kill_for_exit to print
2979 the pids of attached inferiors. */
2982 print_attached_pid (struct inferior_list_entry
*entry
)
2984 struct process_info
*process
= (struct process_info
*) entry
;
2986 if (process
->attached
)
2988 int pid
= ptid_get_pid (process
->entry
.id
);
2989 fprintf (stderr
, " %d", pid
);
2993 /* Call this when exiting gdbserver with possible inferiors that need
2994 to be killed or detached from. */
2997 detach_or_kill_for_exit (void)
2999 /* First print a list of the inferiors we will be killing/detaching.
3000 This is to assist the user, for example, in case the inferior unexpectedly
3001 dies after we exit: did we screw up or did the inferior exit on its own?
3002 Having this info will save some head-scratching. */
3004 if (have_started_inferiors_p ())
3006 fprintf (stderr
, "Killing process(es):");
3007 for_each_inferior (&all_processes
, print_started_pid
);
3008 fprintf (stderr
, "\n");
3010 if (have_attached_inferiors_p ())
3012 fprintf (stderr
, "Detaching process(es):");
3013 for_each_inferior (&all_processes
, print_attached_pid
);
3014 fprintf (stderr
, "\n");
3017 /* Now we can kill or detach the inferiors. */
3019 for_each_inferior (&all_processes
, detach_or_kill_inferior_callback
);
3023 main (int argc
, char *argv
[])
3027 char *arg_end
, *port
;
3028 char **next_arg
= &argv
[1];
3029 volatile int multi_mode
= 0;
3030 volatile int attach
= 0;
3033 while (*next_arg
!= NULL
&& **next_arg
== '-')
3035 if (strcmp (*next_arg
, "--version") == 0)
3037 gdbserver_version ();
3040 else if (strcmp (*next_arg
, "--help") == 0)
3042 gdbserver_usage (stdout
);
3045 else if (strcmp (*next_arg
, "--attach") == 0)
3047 else if (strcmp (*next_arg
, "--multi") == 0)
3049 else if (strcmp (*next_arg
, "--wrapper") == 0)
3053 wrapper_argv
= next_arg
;
3054 while (*next_arg
!= NULL
&& strcmp (*next_arg
, "--") != 0)
3057 if (next_arg
== wrapper_argv
|| *next_arg
== NULL
)
3059 gdbserver_usage (stderr
);
3063 /* Consume the "--". */
3066 else if (strcmp (*next_arg
, "--debug") == 0)
3068 else if (strncmp (*next_arg
,
3070 sizeof ("--debug-format=") - 1) == 0)
3073 = parse_debug_format_options ((*next_arg
)
3074 + sizeof ("--debug-format=") - 1, 0);
3076 if (error_msg
!= NULL
)
3078 fprintf (stderr
, "%s", error_msg
);
3082 else if (strcmp (*next_arg
, "--remote-debug") == 0)
3084 else if (strcmp (*next_arg
, "--disable-packet") == 0)
3086 gdbserver_show_disableable (stdout
);
3089 else if (strncmp (*next_arg
,
3090 "--disable-packet=",
3091 sizeof ("--disable-packet=") - 1) == 0)
3093 char *packets
, *tok
;
3095 packets
= *next_arg
+= sizeof ("--disable-packet=") - 1;
3096 for (tok
= strtok (packets
, ",");
3098 tok
= strtok (NULL
, ","))
3100 if (strcmp ("vCont", tok
) == 0)
3101 disable_packet_vCont
= 1;
3102 else if (strcmp ("Tthread", tok
) == 0)
3103 disable_packet_Tthread
= 1;
3104 else if (strcmp ("qC", tok
) == 0)
3105 disable_packet_qC
= 1;
3106 else if (strcmp ("qfThreadInfo", tok
) == 0)
3107 disable_packet_qfThreadInfo
= 1;
3108 else if (strcmp ("threads", tok
) == 0)
3110 disable_packet_vCont
= 1;
3111 disable_packet_Tthread
= 1;
3112 disable_packet_qC
= 1;
3113 disable_packet_qfThreadInfo
= 1;
3117 fprintf (stderr
, "Don't know how to disable \"%s\".\n\n",
3119 gdbserver_show_disableable (stderr
);
3124 else if (strcmp (*next_arg
, "-") == 0)
3126 /* "-" specifies a stdio connection and is a form of port
3128 *next_arg
= STDIO_CONNECTION_NAME
;
3131 else if (strcmp (*next_arg
, "--disable-randomization") == 0)
3132 disable_randomization
= 1;
3133 else if (strcmp (*next_arg
, "--no-disable-randomization") == 0)
3134 disable_randomization
= 0;
3135 else if (strcmp (*next_arg
, "--once") == 0)
3139 fprintf (stderr
, "Unknown argument: %s\n", *next_arg
);
3147 if (setjmp (toplevel
))
3149 fprintf (stderr
, "Exiting\n");
3155 if (port
== NULL
|| (!attach
&& !multi_mode
&& *next_arg
== NULL
))
3157 gdbserver_usage (stderr
);
3161 /* Remember stdio descriptors. LISTEN_DESC must not be listed, it will be
3162 opened by remote_prepare. */
3165 /* We need to know whether the remote connection is stdio before
3166 starting the inferior. Inferiors created in this scenario have
3167 stdin,stdout redirected. So do this here before we call
3169 remote_prepare (port
);
3174 /* --attach used to come after PORT, so allow it there for
3176 if (*next_arg
!= NULL
&& strcmp (*next_arg
, "--attach") == 0)
3183 && (*next_arg
== NULL
3184 || (*next_arg
)[0] == '\0'
3185 || (pid
= strtoul (*next_arg
, &arg_end
, 0)) == 0
3187 || next_arg
[1] != NULL
))
3192 gdbserver_usage (stderr
);
3196 initialize_async_io ();
3198 initialize_event_loop ();
3199 if (target_supports_tracepoints ())
3200 initialize_tracepoint ();
3202 own_buf
= xmalloc (PBUFSIZ
+ 1);
3203 mem_buf
= xmalloc (PBUFSIZ
);
3205 if (pid
== 0 && *next_arg
!= NULL
)
3209 n
= argc
- (next_arg
- argv
);
3210 program_argv
= xmalloc (sizeof (char *) * (n
+ 1));
3211 for (i
= 0; i
< n
; i
++)
3212 program_argv
[i
] = xstrdup (next_arg
[i
]);
3213 program_argv
[i
] = NULL
;
3215 /* Wait till we are at first instruction in program. */
3216 start_inferior (program_argv
);
3218 /* We are now (hopefully) stopped at the first instruction of
3219 the target process. This assumes that the target process was
3220 successfully created. */
3224 if (attach_inferior (pid
) == -1)
3225 error ("Attaching not supported on this target");
3227 /* Otherwise succeeded. */
3231 last_status
.kind
= TARGET_WAITKIND_EXITED
;
3232 last_status
.value
.integer
= 0;
3233 last_ptid
= minus_one_ptid
;
3236 initialize_notif ();
3238 /* Don't report shared library events on the initial connection,
3239 even if some libraries are preloaded. Avoids the "stopped by
3240 shared library event" notice on gdb side. */
3243 if (setjmp (toplevel
))
3245 /* If something fails and longjmps while detaching or killing
3246 inferiors, we'd end up here again, stuck in an infinite loop
3247 trap. Be sure that if that happens, we exit immediately
3249 if (setjmp (toplevel
) == 0)
3250 detach_or_kill_for_exit ();
3252 fprintf (stderr
, "Detach or kill failed. Exiting\n");
3256 if (last_status
.kind
== TARGET_WAITKIND_EXITED
3257 || last_status
.kind
== TARGET_WAITKIND_SIGNALLED
)
3262 if (!was_running
&& !multi_mode
)
3264 fprintf (stderr
, "No program to debug. GDBserver exiting.\n");
3272 /* Be sure we're out of tfind mode. */
3273 current_traceframe
= -1;
3277 if (setjmp (toplevel
) != 0)
3279 /* An error occurred. */
3280 if (response_needed
)
3282 write_enn (own_buf
);
3287 /* Wait for events. This will return when all event sources are
3288 removed from the event loop. */
3289 start_event_loop ();
3291 /* If an exit was requested (using the "monitor exit" command),
3292 terminate now. The only other way to get here is for
3293 getpkt to fail; close the connection and reopen it at the
3296 if (exit_requested
|| run_once
)
3298 /* If something fails and longjmps while detaching or
3299 killing inferiors, we'd end up here again, stuck in an
3300 infinite loop trap. Be sure that if that happens, we
3301 exit immediately instead. */
3302 if (setjmp (toplevel
) == 0)
3304 detach_or_kill_for_exit ();
3309 fprintf (stderr
, "Detach or kill failed. Exiting\n");
3315 "Remote side has terminated connection. "
3316 "GDBserver will reopen the connection.\n");
3318 /* Get rid of any pending statuses. An eventual reconnection
3319 (by the same GDB instance or another) will refresh all its
3320 state from scratch. */
3321 discard_queued_stop_replies (-1);
3322 for_each_inferior (&all_threads
, clear_pending_status_callback
);
3326 if (disconnected_tracing
)
3328 /* Try to enable non-stop/async mode, so we we can both
3329 wait for an async socket accept, and handle async
3330 target events simultaneously. There's also no point
3331 either in having the target always stop all threads,
3332 when we're going to pass signals down without
3336 if (start_non_stop (1))
3339 /* Detaching implicitly resumes all threads; simply
3340 disconnecting does not. */
3346 "Disconnected tracing disabled; stopping trace run.\n");
3353 /* Skip PACKET until the next semi-colon (or end of string). */
3356 skip_to_semicolon (char **packet
)
3358 while (**packet
!= '\0' && **packet
!= ';')
3362 /* Process options coming from Z packets for a breakpoint. PACKET is
3363 the packet buffer. *PACKET is updated to point to the first char
3364 after the last processed option. */
3367 process_point_options (struct breakpoint
*bp
, char **packet
)
3369 char *dataptr
= *packet
;
3372 /* Check if data has the correct format. */
3373 if (*dataptr
!= ';')
3380 if (*dataptr
== ';')
3383 if (*dataptr
== 'X')
3385 /* Conditional expression. */
3387 debug_printf ("Found breakpoint condition.\n");
3388 if (!add_breakpoint_condition (bp
, &dataptr
))
3389 skip_to_semicolon (&dataptr
);
3391 else if (strncmp (dataptr
, "cmds:", strlen ("cmds:")) == 0)
3393 dataptr
+= strlen ("cmds:");
3395 debug_printf ("Found breakpoint commands %s.\n", dataptr
);
3396 persist
= (*dataptr
== '1');
3398 if (add_breakpoint_commands (bp
, &dataptr
, persist
))
3399 skip_to_semicolon (&dataptr
);
3403 fprintf (stderr
, "Unknown token %c, ignoring.\n",
3405 /* Skip tokens until we find one that we recognize. */
3406 skip_to_semicolon (&dataptr
);
3412 /* Event loop callback that handles a serial event. The first byte in
3413 the serial buffer gets us here. We expect characters to arrive at
3414 a brisk pace, so we read the rest of the packet with a blocking
3418 process_serial_event (void)
3429 int new_packet_len
= -1;
3431 /* Used to decide when gdbserver should exit in
3432 multi-mode/remote. */
3433 static int have_ran
= 0;
3436 have_ran
= target_running ();
3438 disable_async_io ();
3440 response_needed
= 0;
3441 packet_len
= getpkt (own_buf
);
3442 if (packet_len
<= 0)
3445 /* Force an event loop break. */
3448 response_needed
= 1;
3455 handle_query (own_buf
, packet_len
, &new_packet_len
);
3458 handle_general_set (own_buf
);
3461 require_running (own_buf
);
3466 pid
= strtol (&own_buf
[i
], NULL
, 16);
3469 pid
= ptid_get_pid (current_ptid
);
3471 if ((tracing
&& disconnected_tracing
) || any_persistent_commands ())
3473 struct thread_resume resume_info
;
3474 struct process_info
*process
= find_process_pid (pid
);
3476 if (process
== NULL
)
3478 write_enn (own_buf
);
3482 if (tracing
&& disconnected_tracing
)
3484 "Disconnected tracing in effect, "
3485 "leaving gdbserver attached to the process\n");
3487 if (any_persistent_commands ())
3489 "Persistent commands are present, "
3490 "leaving gdbserver attached to the process\n");
3492 /* Make sure we're in non-stop/async mode, so we we can both
3493 wait for an async socket accept, and handle async target
3494 events simultaneously. There's also no point either in
3495 having the target stop all threads, when we're going to
3496 pass signals down without informing GDB. */
3500 debug_printf ("Forcing non-stop mode\n");
3506 process
->gdb_detached
= 1;
3508 /* Detaching implicitly resumes all threads. */
3509 resume_info
.thread
= minus_one_ptid
;
3510 resume_info
.kind
= resume_continue
;
3511 resume_info
.sig
= 0;
3512 (*the_target
->resume
) (&resume_info
, 1);
3515 break; /* from switch/case */
3518 fprintf (stderr
, "Detaching from process %d\n", pid
);
3520 if (detach_inferior (pid
) != 0)
3521 write_enn (own_buf
);
3524 discard_queued_stop_replies (pid
);
3527 if (extended_protocol
)
3529 /* Treat this like a normal program exit. */
3530 last_status
.kind
= TARGET_WAITKIND_EXITED
;
3531 last_status
.value
.integer
= 0;
3532 last_ptid
= pid_to_ptid (pid
);
3534 current_inferior
= NULL
;
3541 /* If we are attached, then we can exit. Otherwise, we
3542 need to hang around doing nothing, until the child is
3544 join_inferior (pid
);
3550 extended_protocol
= 1;
3554 handle_status (own_buf
);
3557 if (own_buf
[1] == 'c' || own_buf
[1] == 'g' || own_buf
[1] == 's')
3559 ptid_t gdb_id
, thread_id
;
3562 require_running (own_buf
);
3564 gdb_id
= read_ptid (&own_buf
[2], NULL
);
3566 pid
= ptid_get_pid (gdb_id
);
3568 if (ptid_equal (gdb_id
, null_ptid
)
3569 || ptid_equal (gdb_id
, minus_one_ptid
))
3570 thread_id
= null_ptid
;
3572 && ptid_equal (pid_to_ptid (pid
),
3575 struct thread_info
*thread
=
3576 (struct thread_info
*) find_inferior (&all_threads
,
3581 write_enn (own_buf
);
3585 thread_id
= thread
->entry
.id
;
3589 thread_id
= gdb_id_to_thread_id (gdb_id
);
3590 if (ptid_equal (thread_id
, null_ptid
))
3592 write_enn (own_buf
);
3597 if (own_buf
[1] == 'g')
3599 if (ptid_equal (thread_id
, null_ptid
))
3601 /* GDB is telling us to choose any thread. Check if
3602 the currently selected thread is still valid. If
3603 it is not, select the first available. */
3604 struct thread_info
*thread
=
3605 (struct thread_info
*) find_inferior_id (&all_threads
,
3609 thread
= get_first_thread ();
3610 thread_id
= thread
->entry
.id
;
3614 general_thread
= thread_id
;
3615 set_desired_inferior (1);
3617 else if (own_buf
[1] == 'c')
3618 cont_thread
= thread_id
;
3624 /* Silently ignore it so that gdb can extend the protocol
3625 without compatibility headaches. */
3630 require_running (own_buf
);
3631 if (current_traceframe
>= 0)
3633 struct regcache
*regcache
3634 = new_register_cache (current_target_desc ());
3636 if (fetch_traceframe_registers (current_traceframe
,
3638 registers_to_string (regcache
, own_buf
);
3640 write_enn (own_buf
);
3641 free_register_cache (regcache
);
3645 struct regcache
*regcache
;
3647 set_desired_inferior (1);
3648 regcache
= get_thread_regcache (current_inferior
, 1);
3649 registers_to_string (regcache
, own_buf
);
3653 require_running (own_buf
);
3654 if (current_traceframe
>= 0)
3655 write_enn (own_buf
);
3658 struct regcache
*regcache
;
3660 set_desired_inferior (1);
3661 regcache
= get_thread_regcache (current_inferior
, 1);
3662 registers_from_string (regcache
, &own_buf
[1]);
3667 require_running (own_buf
);
3668 decode_m_packet (&own_buf
[1], &mem_addr
, &len
);
3669 res
= gdb_read_memory (mem_addr
, mem_buf
, len
);
3671 write_enn (own_buf
);
3673 bin2hex (mem_buf
, own_buf
, res
);
3676 require_running (own_buf
);
3677 decode_M_packet (&own_buf
[1], &mem_addr
, &len
, &mem_buf
);
3678 if (gdb_write_memory (mem_addr
, mem_buf
, len
) == 0)
3681 write_enn (own_buf
);
3684 require_running (own_buf
);
3685 if (decode_X_packet (&own_buf
[1], packet_len
- 1,
3686 &mem_addr
, &len
, &mem_buf
) < 0
3687 || gdb_write_memory (mem_addr
, mem_buf
, len
) != 0)
3688 write_enn (own_buf
);
3693 require_running (own_buf
);
3694 hex2bin (own_buf
+ 1, &sig
, 1);
3695 if (gdb_signal_to_host_p (sig
))
3696 signal
= gdb_signal_to_host (sig
);
3699 myresume (own_buf
, 0, signal
);
3702 require_running (own_buf
);
3703 hex2bin (own_buf
+ 1, &sig
, 1);
3704 if (gdb_signal_to_host_p (sig
))
3705 signal
= gdb_signal_to_host (sig
);
3708 myresume (own_buf
, 1, signal
);
3711 require_running (own_buf
);
3713 myresume (own_buf
, 0, signal
);
3716 require_running (own_buf
);
3718 myresume (own_buf
, 1, signal
);
3720 case 'Z': /* insert_ ... */
3722 case 'z': /* remove_ ... */
3727 char type
= own_buf
[1];
3729 const int insert
= ch
== 'Z';
3730 char *p
= &own_buf
[3];
3732 p
= unpack_varlen_hex (p
, &addr
);
3733 len
= strtol (p
+ 1, &dataptr
, 16);
3737 struct breakpoint
*bp
;
3739 bp
= set_gdb_breakpoint (type
, addr
, len
, &res
);
3744 /* GDB may have sent us a list of *point parameters to
3745 be evaluated on the target's side. Read such list
3746 here. If we already have a list of parameters, GDB
3747 is telling us to drop that list and use this one
3749 clear_breakpoint_conditions_and_commands (bp
);
3750 process_point_options (bp
, &dataptr
);
3754 res
= delete_gdb_breakpoint (type
, addr
, len
);
3762 write_enn (own_buf
);
3766 response_needed
= 0;
3767 if (!target_running ())
3768 /* The packet we received doesn't make sense - but we can't
3769 reply to it, either. */
3772 fprintf (stderr
, "Killing all inferiors\n");
3773 for_each_inferior (&all_processes
, kill_inferior_callback
);
3775 /* When using the extended protocol, we wait with no program
3776 running. The traditional protocol will exit instead. */
3777 if (extended_protocol
)
3779 last_status
.kind
= TARGET_WAITKIND_EXITED
;
3780 last_status
.value
.sig
= GDB_SIGNAL_KILL
;
3788 ptid_t gdb_id
, thread_id
;
3790 require_running (own_buf
);
3792 gdb_id
= read_ptid (&own_buf
[1], NULL
);
3793 thread_id
= gdb_id_to_thread_id (gdb_id
);
3794 if (ptid_equal (thread_id
, null_ptid
))
3796 write_enn (own_buf
);
3800 if (mythread_alive (thread_id
))
3803 write_enn (own_buf
);
3807 response_needed
= 0;
3809 /* Restarting the inferior is only supported in the extended
3811 if (extended_protocol
)
3813 if (target_running ())
3814 for_each_inferior (&all_processes
,
3815 kill_inferior_callback
);
3816 fprintf (stderr
, "GDBserver restarting\n");
3818 /* Wait till we are at 1st instruction in prog. */
3819 if (program_argv
!= NULL
)
3820 start_inferior (program_argv
);
3823 last_status
.kind
= TARGET_WAITKIND_EXITED
;
3824 last_status
.value
.sig
= GDB_SIGNAL_KILL
;
3830 /* It is a request we don't understand. Respond with an
3831 empty packet so that gdb knows that we don't support this
3837 /* Extended (long) request. */
3838 handle_v_requests (own_buf
, packet_len
, &new_packet_len
);
3842 /* It is a request we don't understand. Respond with an empty
3843 packet so that gdb knows that we don't support this
3849 if (new_packet_len
!= -1)
3850 putpkt_binary (own_buf
, new_packet_len
);
3854 response_needed
= 0;
3856 if (!extended_protocol
&& have_ran
&& !target_running ())
3858 /* In non-stop, defer exiting until GDB had a chance to query
3859 the whole vStopped list (until it gets an OK). */
3860 if (QUEUE_is_empty (notif_event_p
, notif_stop
.queue
))
3862 /* Be transparent when GDB is connected through stdio -- no
3863 need to spam GDB's console. */
3864 if (!remote_connection_is_stdio ())
3865 fprintf (stderr
, "GDBserver exiting\n");
3877 /* Event-loop callback for serial events. */
3880 handle_serial_event (int err
, gdb_client_data client_data
)
3883 debug_printf ("handling possible serial event\n");
3885 /* Really handle it. */
3886 if (process_serial_event () < 0)
3889 /* Be sure to not change the selected inferior behind GDB's back.
3890 Important in the non-stop mode asynchronous protocol. */
3891 set_desired_inferior (1);
3896 /* Event-loop callback for target events. */
3899 handle_target_event (int err
, gdb_client_data client_data
)
3902 debug_printf ("handling possible target event\n");
3904 last_ptid
= mywait (minus_one_ptid
, &last_status
,
3907 if (last_status
.kind
== TARGET_WAITKIND_NO_RESUMED
)
3909 /* No RSP support for this yet. */
3911 else if (last_status
.kind
!= TARGET_WAITKIND_IGNORE
)
3913 int pid
= ptid_get_pid (last_ptid
);
3914 struct process_info
*process
= find_process_pid (pid
);
3915 int forward_event
= !gdb_connected () || process
->gdb_detached
;
3917 if (last_status
.kind
== TARGET_WAITKIND_EXITED
3918 || last_status
.kind
== TARGET_WAITKIND_SIGNALLED
)
3920 mark_breakpoints_out (process
);
3921 mourn_inferior (process
);
3925 /* We're reporting this thread as stopped. Update its
3926 "want-stopped" state to what the client wants, until it
3927 gets a new resume action. */
3928 current_inferior
->last_resume_kind
= resume_stop
;
3929 current_inferior
->last_status
= last_status
;
3934 if (!target_running ())
3936 /* The last process exited. We're done. */
3940 if (last_status
.kind
== TARGET_WAITKIND_STOPPED
)
3942 /* A thread stopped with a signal, but gdb isn't
3943 connected to handle it. Pass it down to the
3944 inferior, as if it wasn't being traced. */
3945 struct thread_resume resume_info
;
3948 debug_printf ("GDB not connected; forwarding event %d for"
3950 (int) last_status
.kind
,
3951 target_pid_to_str (last_ptid
));
3953 resume_info
.thread
= last_ptid
;
3954 resume_info
.kind
= resume_continue
;
3955 resume_info
.sig
= gdb_signal_to_host (last_status
.value
.sig
);
3956 (*the_target
->resume
) (&resume_info
, 1);
3958 else if (debug_threads
)
3959 debug_printf ("GDB not connected; ignoring event %d for [%s]\n",
3960 (int) last_status
.kind
,
3961 target_pid_to_str (last_ptid
));
3965 struct vstop_notif
*vstop_notif
3966 = xmalloc (sizeof (struct vstop_notif
));
3968 vstop_notif
->status
= last_status
;
3969 vstop_notif
->ptid
= last_ptid
;
3970 /* Push Stop notification. */
3971 notif_push (¬if_stop
,
3972 (struct notif_event
*) vstop_notif
);
3976 /* Be sure to not change the selected inferior behind GDB's back.
3977 Important in the non-stop mode asynchronous protocol. */
3978 set_desired_inferior (1);