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
;
79 /* The PID of the originally created or attached inferior. Used to
80 send signals to the process when GDB sends us an asynchronous interrupt
81 (user hitting Control-C in the client), and to wait for the child to exit
82 when no longer debugging it. */
84 unsigned long signal_pid
;
87 /* A file descriptor for the controlling terminal. */
90 /* TERMINAL_FD's original foreground group. */
91 pid_t old_foreground_pgrp
;
93 /* Hand back terminal ownership to the original foreground group. */
96 restore_old_foreground_pgrp (void)
98 tcsetpgrp (terminal_fd
, old_foreground_pgrp
);
102 /* Set if you want to disable optional thread related packets support
103 in gdbserver, for the sake of testing GDB against stubs that don't
105 int disable_packet_vCont
;
106 int disable_packet_Tthread
;
107 int disable_packet_qC
;
108 int disable_packet_qfThreadInfo
;
110 /* Last status reported to GDB. */
111 static struct target_waitstatus last_status
;
112 static ptid_t last_ptid
;
114 static char *own_buf
;
115 static unsigned char *mem_buf
;
117 /* A sub-class of 'struct notif_event' for stop, holding information
118 relative to a single stop reply. We keep a queue of these to
119 push to GDB in non-stop mode. */
123 struct notif_event base
;
125 /* Thread or process that got the event. */
129 struct target_waitstatus status
;
132 DEFINE_QUEUE_P (notif_event_p
);
134 /* Put a stop reply to the stop reply queue. */
137 queue_stop_reply (ptid_t ptid
, struct target_waitstatus
*status
)
139 struct vstop_notif
*new_notif
= xmalloc (sizeof (*new_notif
));
141 new_notif
->ptid
= ptid
;
142 new_notif
->status
= *status
;
144 notif_event_enque (¬if_stop
, (struct notif_event
*) new_notif
);
148 remove_all_on_match_pid (QUEUE (notif_event_p
) *q
,
149 QUEUE_ITER (notif_event_p
) *iter
,
150 struct notif_event
*event
,
156 || ptid_get_pid (((struct vstop_notif
*) event
)->ptid
) == *pid
)
158 if (q
->free_func
!= NULL
)
159 q
->free_func (event
);
161 QUEUE_remove_elem (notif_event_p
, q
, iter
);
167 /* Get rid of the currently pending stop replies for PID. If PID is
168 -1, then apply to all processes. */
171 discard_queued_stop_replies (int pid
)
173 QUEUE_iterate (notif_event_p
, notif_stop
.queue
,
174 remove_all_on_match_pid
, &pid
);
178 vstop_notif_reply (struct notif_event
*event
, char *own_buf
)
180 struct vstop_notif
*vstop
= (struct vstop_notif
*) event
;
182 prepare_resume_reply (own_buf
, vstop
->ptid
, &vstop
->status
);
185 struct notif_server notif_stop
=
187 "vStopped", "Stop", NULL
, vstop_notif_reply
,
191 target_running (void)
193 return get_first_thread () != NULL
;
197 start_inferior (char **argv
)
199 char **new_argv
= argv
;
201 if (wrapper_argv
!= NULL
)
205 for (i
= 0; wrapper_argv
[i
] != NULL
; i
++)
207 for (i
= 0; argv
[i
] != NULL
; i
++)
209 new_argv
= alloca (sizeof (char *) * count
);
211 for (i
= 0; wrapper_argv
[i
] != NULL
; i
++)
212 new_argv
[count
++] = wrapper_argv
[i
];
213 for (i
= 0; argv
[i
] != NULL
; i
++)
214 new_argv
[count
++] = argv
[i
];
215 new_argv
[count
] = NULL
;
221 for (i
= 0; new_argv
[i
]; ++i
)
222 debug_printf ("new_argv[%d] = \"%s\"\n", i
, new_argv
[i
]);
227 signal (SIGTTOU
, SIG_DFL
);
228 signal (SIGTTIN
, SIG_DFL
);
231 /* Clear this so the backend doesn't get confused, thinking
232 CONT_THREAD died, and it needs to resume all threads. */
233 cont_thread
= null_ptid
;
235 signal_pid
= create_inferior (new_argv
[0], new_argv
);
237 /* FIXME: we don't actually know at this point that the create
238 actually succeeded. We won't know that until we wait. */
239 fprintf (stderr
, "Process %s created; pid = %ld\n", argv
[0],
244 signal (SIGTTOU
, SIG_IGN
);
245 signal (SIGTTIN
, SIG_IGN
);
246 terminal_fd
= fileno (stderr
);
247 old_foreground_pgrp
= tcgetpgrp (terminal_fd
);
248 tcsetpgrp (terminal_fd
, signal_pid
);
249 atexit (restore_old_foreground_pgrp
);
252 if (wrapper_argv
!= NULL
)
254 struct thread_resume resume_info
;
256 memset (&resume_info
, 0, sizeof (resume_info
));
257 resume_info
.thread
= pid_to_ptid (signal_pid
);
258 resume_info
.kind
= resume_continue
;
261 last_ptid
= mywait (pid_to_ptid (signal_pid
), &last_status
, 0, 0);
263 if (last_status
.kind
!= TARGET_WAITKIND_STOPPED
)
268 (*the_target
->resume
) (&resume_info
, 1);
270 last_ptid
= mywait (pid_to_ptid (signal_pid
), &last_status
, 0, 0);
271 if (last_status
.kind
!= TARGET_WAITKIND_STOPPED
)
274 current_inferior
->last_resume_kind
= resume_stop
;
275 current_inferior
->last_status
= last_status
;
277 while (last_status
.value
.sig
!= GDB_SIGNAL_TRAP
);
282 /* Wait till we are at 1st instruction in program, return new pid
283 (assuming success). */
284 last_ptid
= mywait (pid_to_ptid (signal_pid
), &last_status
, 0, 0);
286 if (last_status
.kind
!= TARGET_WAITKIND_EXITED
287 && last_status
.kind
!= TARGET_WAITKIND_SIGNALLED
)
289 current_inferior
->last_resume_kind
= resume_stop
;
290 current_inferior
->last_status
= last_status
;
297 attach_inferior (int pid
)
299 /* myattach should return -1 if attaching is unsupported,
300 0 if it succeeded, and call error() otherwise. */
302 if (myattach (pid
) != 0)
305 fprintf (stderr
, "Attached; pid = %d\n", pid
);
308 /* FIXME - It may be that we should get the SIGNAL_PID from the
309 attach function, so that it can be the main thread instead of
310 whichever we were told to attach to. */
313 /* Clear this so the backend doesn't get confused, thinking
314 CONT_THREAD died, and it needs to resume all threads. */
315 cont_thread
= null_ptid
;
319 last_ptid
= mywait (pid_to_ptid (pid
), &last_status
, 0, 0);
321 /* GDB knows to ignore the first SIGSTOP after attaching to a running
322 process using the "attach" command, but this is different; it's
323 just using "target remote". Pretend it's just starting up. */
324 if (last_status
.kind
== TARGET_WAITKIND_STOPPED
325 && last_status
.value
.sig
== GDB_SIGNAL_STOP
)
326 last_status
.value
.sig
= GDB_SIGNAL_TRAP
;
328 current_inferior
->last_resume_kind
= resume_stop
;
329 current_inferior
->last_status
= last_status
;
335 extern int remote_debug
;
337 /* Decode a qXfer read request. Return 0 if everything looks OK,
341 decode_xfer_read (char *buf
, CORE_ADDR
*ofs
, unsigned int *len
)
343 /* After the read marker and annex, qXfer looks like a
344 traditional 'm' packet. */
345 decode_m_packet (buf
, ofs
, len
);
351 decode_xfer (char *buf
, char **object
, char **rw
, char **annex
, char **offset
)
353 /* Extract and NUL-terminate the object. */
355 while (*buf
&& *buf
!= ':')
361 /* Extract and NUL-terminate the read/write action. */
363 while (*buf
&& *buf
!= ':')
369 /* Extract and NUL-terminate the annex. */
371 while (*buf
&& *buf
!= ':')
381 /* Write the response to a successful qXfer read. Returns the
382 length of the (binary) data stored in BUF, corresponding
383 to as much of DATA/LEN as we could fit. IS_MORE controls
384 the first character of the response. */
386 write_qxfer_response (char *buf
, const void *data
, int len
, int is_more
)
395 return remote_escape_output (data
, len
, (unsigned char *) buf
+ 1, &out_len
,
399 /* Handle btrace enabling. */
402 handle_btrace_enable (struct thread_info
*thread
)
404 if (thread
->btrace
!= NULL
)
405 return "E.Btrace already enabled.";
407 thread
->btrace
= target_enable_btrace (thread
->entry
.id
);
408 if (thread
->btrace
== NULL
)
409 return "E.Could not enable btrace.";
414 /* Handle btrace disabling. */
417 handle_btrace_disable (struct thread_info
*thread
)
420 if (thread
->btrace
== NULL
)
421 return "E.Branch tracing not enabled.";
423 if (target_disable_btrace (thread
->btrace
) != 0)
424 return "E.Could not disable branch tracing.";
426 thread
->btrace
= NULL
;
430 /* Handle the "Qbtrace" packet. */
433 handle_btrace_general_set (char *own_buf
)
435 struct thread_info
*thread
;
439 if (strncmp ("Qbtrace:", own_buf
, strlen ("Qbtrace:")) != 0)
442 op
= own_buf
+ strlen ("Qbtrace:");
444 if (!target_supports_btrace ())
446 strcpy (own_buf
, "E.Target does not support branch tracing.");
450 if (ptid_equal (general_thread
, null_ptid
)
451 || ptid_equal (general_thread
, minus_one_ptid
))
453 strcpy (own_buf
, "E.Must select a single thread.");
457 thread
= find_thread_ptid (general_thread
);
460 strcpy (own_buf
, "E.No such thread.");
466 if (strcmp (op
, "bts") == 0)
467 err
= handle_btrace_enable (thread
);
468 else if (strcmp (op
, "off") == 0)
469 err
= handle_btrace_disable (thread
);
471 err
= "E.Bad Qbtrace operation. Use bts or off.";
474 strcpy (own_buf
, err
);
481 /* Handle all of the extended 'Q' packets. */
484 handle_general_set (char *own_buf
)
486 if (strncmp ("QPassSignals:", own_buf
, strlen ("QPassSignals:")) == 0)
488 int numsigs
= (int) GDB_SIGNAL_LAST
, i
;
489 const char *p
= own_buf
+ strlen ("QPassSignals:");
492 p
= decode_address_to_semicolon (&cursig
, p
);
493 for (i
= 0; i
< numsigs
; i
++)
499 /* Keep looping, to clear the remaining signals. */
502 p
= decode_address_to_semicolon (&cursig
, p
);
507 strcpy (own_buf
, "OK");
511 if (strncmp ("QProgramSignals:", own_buf
, strlen ("QProgramSignals:")) == 0)
513 int numsigs
= (int) GDB_SIGNAL_LAST
, i
;
514 const char *p
= own_buf
+ strlen ("QProgramSignals:");
517 program_signals_p
= 1;
519 p
= decode_address_to_semicolon (&cursig
, p
);
520 for (i
= 0; i
< numsigs
; i
++)
524 program_signals
[i
] = 1;
526 /* Keep looping, to clear the remaining signals. */
529 p
= decode_address_to_semicolon (&cursig
, p
);
532 program_signals
[i
] = 0;
534 strcpy (own_buf
, "OK");
538 if (strcmp (own_buf
, "QStartNoAckMode") == 0)
542 fprintf (stderr
, "[noack mode enabled]\n");
551 if (strncmp (own_buf
, "QNonStop:", 9) == 0)
553 char *mode
= own_buf
+ 9;
557 if (strcmp (mode
, "0") == 0)
559 else if (strcmp (mode
, "1") == 0)
563 /* We don't know what this mode is, so complain to
565 fprintf (stderr
, "Unknown non-stop mode requested: %s\n",
571 req_str
= req
? "non-stop" : "all-stop";
572 if (start_non_stop (req
) != 0)
574 fprintf (stderr
, "Setting %s mode failed\n", req_str
);
582 fprintf (stderr
, "[%s mode enabled]\n", req_str
);
588 if (strncmp ("QDisableRandomization:", own_buf
,
589 strlen ("QDisableRandomization:")) == 0)
591 char *packet
= own_buf
+ strlen ("QDisableRandomization:");
594 unpack_varlen_hex (packet
, &setting
);
595 disable_randomization
= setting
;
599 if (disable_randomization
)
600 fprintf (stderr
, "[address space randomization disabled]\n");
602 fprintf (stderr
, "[address space randomization enabled]\n");
609 if (target_supports_tracepoints ()
610 && handle_tracepoint_general_set (own_buf
))
613 if (strncmp ("QAgent:", own_buf
, strlen ("QAgent:")) == 0)
615 char *mode
= own_buf
+ strlen ("QAgent:");
618 if (strcmp (mode
, "0") == 0)
620 else if (strcmp (mode
, "1") == 0)
624 /* We don't know what this value is, so complain to GDB. */
625 sprintf (own_buf
, "E.Unknown QAgent value");
629 /* Update the flag. */
632 fprintf (stderr
, "[%s agent]\n", req
? "Enable" : "Disable");
637 if (handle_btrace_general_set (own_buf
))
640 /* Otherwise we didn't know what packet it was. Say we didn't
646 get_features_xml (const char *annex
)
648 const struct target_desc
*desc
= current_target_desc ();
650 /* `desc->xmltarget' defines what to return when looking for the
651 "target.xml" file. Its contents can either be verbatim XML code
652 (prefixed with a '@') or else the name of the actual XML file to
653 be used in place of "target.xml".
655 This variable is set up from the auto-generated
656 init_registers_... routine for the current target. */
658 if (desc
->xmltarget
!= NULL
&& strcmp (annex
, "target.xml") == 0)
660 if (*desc
->xmltarget
== '@')
661 return desc
->xmltarget
+ 1;
663 annex
= desc
->xmltarget
;
668 extern const char *const xml_builtin
[][2];
671 /* Look for the annex. */
672 for (i
= 0; xml_builtin
[i
][0] != NULL
; i
++)
673 if (strcmp (annex
, xml_builtin
[i
][0]) == 0)
676 if (xml_builtin
[i
][0] != NULL
)
677 return xml_builtin
[i
][1];
685 monitor_show_help (void)
687 monitor_output ("The following monitor commands are supported:\n");
688 monitor_output (" set debug <0|1>\n");
689 monitor_output (" Enable general debugging messages\n");
690 monitor_output (" set debug-hw-points <0|1>\n");
691 monitor_output (" Enable h/w breakpoint/watchpoint debugging messages\n");
692 monitor_output (" set remote-debug <0|1>\n");
693 monitor_output (" Enable remote protocol debugging messages\n");
694 monitor_output (" set debug-format option1[,option2,...]\n");
695 monitor_output (" Add additional information to debugging messages\n");
696 monitor_output (" Options: all, none");
697 monitor_output (", timestamp");
698 monitor_output ("\n");
699 monitor_output (" exit\n");
700 monitor_output (" Quit GDBserver\n");
703 /* Read trace frame or inferior memory. Returns the number of bytes
704 actually read, zero when no further transfer is possible, and -1 on
705 error. Return of a positive value smaller than LEN does not
706 indicate there's no more to be read, only the end of the transfer.
707 E.g., when GDB reads memory from a traceframe, a first request may
708 be served from a memory block that does not cover the whole request
709 length. A following request gets the rest served from either
710 another block (of the same traceframe) or from the read-only
714 gdb_read_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
718 if (current_traceframe
>= 0)
721 ULONGEST length
= len
;
723 if (traceframe_read_mem (current_traceframe
,
724 memaddr
, myaddr
, len
, &nbytes
))
726 /* Data read from trace buffer, we're done. */
729 if (!in_readonly_region (memaddr
, length
))
731 /* Otherwise we have a valid readonly case, fall through. */
732 /* (assume no half-trace half-real blocks for now) */
735 res
= prepare_to_access_memory ();
738 res
= read_inferior_memory (memaddr
, myaddr
, len
);
739 done_accessing_memory ();
741 return res
== 0 ? len
: -1;
747 /* Write trace frame or inferior memory. Actually, writing to trace
748 frames is forbidden. */
751 gdb_write_memory (CORE_ADDR memaddr
, const unsigned char *myaddr
, int len
)
753 if (current_traceframe
>= 0)
759 ret
= prepare_to_access_memory ();
762 ret
= write_inferior_memory (memaddr
, myaddr
, len
);
763 done_accessing_memory ();
769 /* Subroutine of handle_search_memory to simplify it. */
772 handle_search_memory_1 (CORE_ADDR start_addr
, CORE_ADDR search_space_len
,
773 gdb_byte
*pattern
, unsigned pattern_len
,
774 gdb_byte
*search_buf
,
775 unsigned chunk_size
, unsigned search_buf_size
,
776 CORE_ADDR
*found_addrp
)
778 /* Prime the search buffer. */
780 if (gdb_read_memory (start_addr
, search_buf
, search_buf_size
)
783 warning ("Unable to access %ld bytes of target "
784 "memory at 0x%lx, halting search.",
785 (long) search_buf_size
, (long) start_addr
);
789 /* Perform the search.
791 The loop is kept simple by allocating [N + pattern-length - 1] bytes.
792 When we've scanned N bytes we copy the trailing bytes to the start and
793 read in another N bytes. */
795 while (search_space_len
>= pattern_len
)
798 unsigned nr_search_bytes
= (search_space_len
< search_buf_size
802 found_ptr
= memmem (search_buf
, nr_search_bytes
, pattern
, pattern_len
);
804 if (found_ptr
!= NULL
)
806 CORE_ADDR found_addr
= start_addr
+ (found_ptr
- search_buf
);
807 *found_addrp
= found_addr
;
811 /* Not found in this chunk, skip to next chunk. */
813 /* Don't let search_space_len wrap here, it's unsigned. */
814 if (search_space_len
>= chunk_size
)
815 search_space_len
-= chunk_size
;
817 search_space_len
= 0;
819 if (search_space_len
>= pattern_len
)
821 unsigned keep_len
= search_buf_size
- chunk_size
;
822 CORE_ADDR read_addr
= start_addr
+ chunk_size
+ keep_len
;
825 /* Copy the trailing part of the previous iteration to the front
826 of the buffer for the next iteration. */
827 memcpy (search_buf
, search_buf
+ chunk_size
, keep_len
);
829 nr_to_read
= (search_space_len
- keep_len
< chunk_size
830 ? search_space_len
- keep_len
833 if (gdb_read_memory (read_addr
, search_buf
+ keep_len
,
834 nr_to_read
) != search_buf_size
)
836 warning ("Unable to access %ld bytes of target memory "
837 "at 0x%lx, halting search.",
838 (long) nr_to_read
, (long) read_addr
);
842 start_addr
+= chunk_size
;
851 /* Handle qSearch:memory packets. */
854 handle_search_memory (char *own_buf
, int packet_len
)
856 CORE_ADDR start_addr
;
857 CORE_ADDR search_space_len
;
859 unsigned int pattern_len
;
860 /* NOTE: also defined in find.c testcase. */
861 #define SEARCH_CHUNK_SIZE 16000
862 const unsigned chunk_size
= SEARCH_CHUNK_SIZE
;
863 /* Buffer to hold memory contents for searching. */
864 gdb_byte
*search_buf
;
865 unsigned search_buf_size
;
867 CORE_ADDR found_addr
;
868 int cmd_name_len
= sizeof ("qSearch:memory:") - 1;
870 pattern
= malloc (packet_len
);
873 error ("Unable to allocate memory to perform the search");
874 strcpy (own_buf
, "E00");
877 if (decode_search_memory_packet (own_buf
+ cmd_name_len
,
878 packet_len
- cmd_name_len
,
879 &start_addr
, &search_space_len
,
880 pattern
, &pattern_len
) < 0)
883 error ("Error in parsing qSearch:memory packet");
884 strcpy (own_buf
, "E00");
888 search_buf_size
= chunk_size
+ pattern_len
- 1;
890 /* No point in trying to allocate a buffer larger than the search space. */
891 if (search_space_len
< search_buf_size
)
892 search_buf_size
= search_space_len
;
894 search_buf
= malloc (search_buf_size
);
895 if (search_buf
== NULL
)
898 error ("Unable to allocate memory to perform the search");
899 strcpy (own_buf
, "E00");
903 found
= handle_search_memory_1 (start_addr
, search_space_len
,
904 pattern
, pattern_len
,
905 search_buf
, chunk_size
, search_buf_size
,
909 sprintf (own_buf
, "1,%lx", (long) found_addr
);
911 strcpy (own_buf
, "0");
913 strcpy (own_buf
, "E00");
919 #define require_running(BUF) \
920 if (!target_running ()) \
926 /* Parse options to --debug-format= and "monitor set debug-format".
927 ARG is the text after "--debug-format=" or "monitor set debug-format".
928 IS_MONITOR is non-zero if we're invoked via "monitor set debug-format".
929 This triggers calls to monitor_output.
930 The result is NULL if all options were parsed ok, otherwise an error
931 message which the caller must free.
933 N.B. These commands affect all debug format settings, they are not
934 cumulative. If a format is not specified, it is turned off.
935 However, we don't go to extra trouble with things like
936 "monitor set debug-format all,none,timestamp".
937 Instead we just parse them one at a time, in order.
939 The syntax for "monitor set debug" we support here is not identical
940 to gdb's "set debug foo on|off" because we also use this function to
941 parse "--debug-format=foo,bar". */
944 parse_debug_format_options (const char *arg
, int is_monitor
)
946 VEC (char_ptr
) *options
;
950 /* First turn all debug format options off. */
953 /* First remove leading spaces, for "monitor set debug-format". */
954 while (isspace (*arg
))
957 options
= delim_string_to_char_ptr_vec (arg
, ',');
959 for (ix
= 0; VEC_iterate (char_ptr
, options
, ix
, option
); ++ix
)
961 if (strcmp (option
, "all") == 0)
965 monitor_output ("All extra debug format options enabled.\n");
967 else if (strcmp (option
, "none") == 0)
971 monitor_output ("All extra debug format options disabled.\n");
973 else if (strcmp (option
, "timestamp") == 0)
977 monitor_output ("Timestamps will be added to debug output.\n");
979 else if (*option
== '\0')
981 /* An empty option, e.g., "--debug-format=foo,,bar", is ignored. */
986 char *msg
= xstrprintf ("Unknown debug-format argument: \"%s\"\n",
989 free_char_ptr_vec (options
);
994 free_char_ptr_vec (options
);
998 /* Handle monitor commands not handled by target-specific handlers. */
1001 handle_monitor_command (char *mon
, char *own_buf
)
1003 if (strcmp (mon
, "set debug 1") == 0)
1006 monitor_output ("Debug output enabled.\n");
1008 else if (strcmp (mon
, "set debug 0") == 0)
1011 monitor_output ("Debug output disabled.\n");
1013 else if (strcmp (mon
, "set debug-hw-points 1") == 0)
1015 debug_hw_points
= 1;
1016 monitor_output ("H/W point debugging output enabled.\n");
1018 else if (strcmp (mon
, "set debug-hw-points 0") == 0)
1020 debug_hw_points
= 0;
1021 monitor_output ("H/W point debugging output disabled.\n");
1023 else if (strcmp (mon
, "set remote-debug 1") == 0)
1026 monitor_output ("Protocol debug output enabled.\n");
1028 else if (strcmp (mon
, "set remote-debug 0") == 0)
1031 monitor_output ("Protocol debug output disabled.\n");
1033 else if (strncmp (mon
, "set debug-format ",
1034 sizeof ("set debug-format ") - 1) == 0)
1037 = parse_debug_format_options (mon
+ sizeof ("set debug-format ") - 1,
1040 if (error_msg
!= NULL
)
1042 monitor_output (error_msg
);
1043 monitor_show_help ();
1044 write_enn (own_buf
);
1048 else if (strcmp (mon
, "help") == 0)
1049 monitor_show_help ();
1050 else if (strcmp (mon
, "exit") == 0)
1054 monitor_output ("Unknown monitor command.\n\n");
1055 monitor_show_help ();
1056 write_enn (own_buf
);
1060 /* Associates a callback with each supported qXfer'able object. */
1064 /* The object this handler handles. */
1067 /* Request that the target transfer up to LEN 8-bit bytes of the
1068 target's OBJECT. The OFFSET, for a seekable object, specifies
1069 the starting point. The ANNEX can be used to provide additional
1070 data-specific information to the target.
1072 Return the number of bytes actually transfered, zero when no
1073 further transfer is possible, -1 on error, -2 when the transfer
1074 is not supported, and -3 on a verbose error message that should
1075 be preserved. Return of a positive value smaller than LEN does
1076 not indicate the end of the object, only the end of the transfer.
1078 One, and only one, of readbuf or writebuf must be non-NULL. */
1079 int (*xfer
) (const char *annex
,
1080 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1081 ULONGEST offset
, LONGEST len
);
1084 /* Handle qXfer:auxv:read. */
1087 handle_qxfer_auxv (const char *annex
,
1088 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1089 ULONGEST offset
, LONGEST len
)
1091 if (the_target
->read_auxv
== NULL
|| writebuf
!= NULL
)
1094 if (annex
[0] != '\0' || !target_running ())
1097 return (*the_target
->read_auxv
) (offset
, readbuf
, len
);
1100 /* Handle qXfer:features:read. */
1103 handle_qxfer_features (const char *annex
,
1104 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1105 ULONGEST offset
, LONGEST len
)
1107 const char *document
;
1110 if (writebuf
!= NULL
)
1113 if (!target_running ())
1116 /* Grab the correct annex. */
1117 document
= get_features_xml (annex
);
1118 if (document
== NULL
)
1121 total_len
= strlen (document
);
1123 if (offset
> total_len
)
1126 if (offset
+ len
> total_len
)
1127 len
= total_len
- offset
;
1129 memcpy (readbuf
, document
+ offset
, len
);
1133 /* Worker routine for handle_qxfer_libraries.
1134 Add to the length pointed to by ARG a conservative estimate of the
1135 length needed to transmit the file name of INF. */
1138 accumulate_file_name_length (struct inferior_list_entry
*inf
, void *arg
)
1140 struct dll_info
*dll
= (struct dll_info
*) inf
;
1141 unsigned int *total_len
= arg
;
1143 /* Over-estimate the necessary memory. Assume that every character
1144 in the library name must be escaped. */
1145 *total_len
+= 128 + 6 * strlen (dll
->name
);
1148 /* Worker routine for handle_qxfer_libraries.
1149 Emit the XML to describe the library in INF. */
1152 emit_dll_description (struct inferior_list_entry
*inf
, void *arg
)
1154 struct dll_info
*dll
= (struct dll_info
*) inf
;
1159 strcpy (p
, " <library name=\"");
1161 name
= xml_escape_text (dll
->name
);
1165 strcpy (p
, "\"><segment address=\"");
1167 sprintf (p
, "0x%lx", (long) dll
->base_addr
);
1169 strcpy (p
, "\"/></library>\n");
1175 /* Handle qXfer:libraries:read. */
1178 handle_qxfer_libraries (const char *annex
,
1179 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1180 ULONGEST offset
, LONGEST len
)
1182 unsigned int total_len
;
1185 if (writebuf
!= NULL
)
1188 if (annex
[0] != '\0' || !target_running ())
1192 for_each_inferior_with_data (&all_dlls
, accumulate_file_name_length
,
1195 document
= malloc (total_len
);
1196 if (document
== NULL
)
1199 strcpy (document
, "<library-list>\n");
1200 p
= document
+ strlen (document
);
1202 for_each_inferior_with_data (&all_dlls
, emit_dll_description
, &p
);
1204 strcpy (p
, "</library-list>\n");
1206 total_len
= strlen (document
);
1208 if (offset
> total_len
)
1214 if (offset
+ len
> total_len
)
1215 len
= total_len
- offset
;
1217 memcpy (readbuf
, document
+ offset
, len
);
1222 /* Handle qXfer:libraries-svr4:read. */
1225 handle_qxfer_libraries_svr4 (const char *annex
,
1226 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1227 ULONGEST offset
, LONGEST len
)
1229 if (writebuf
!= NULL
)
1232 if (!target_running () || the_target
->qxfer_libraries_svr4
== NULL
)
1235 return the_target
->qxfer_libraries_svr4 (annex
, readbuf
, writebuf
, offset
, len
);
1238 /* Handle qXfer:osadata:read. */
1241 handle_qxfer_osdata (const char *annex
,
1242 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1243 ULONGEST offset
, LONGEST len
)
1245 if (the_target
->qxfer_osdata
== NULL
|| writebuf
!= NULL
)
1248 return (*the_target
->qxfer_osdata
) (annex
, readbuf
, NULL
, offset
, len
);
1251 /* Handle qXfer:siginfo:read and qXfer:siginfo:write. */
1254 handle_qxfer_siginfo (const char *annex
,
1255 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1256 ULONGEST offset
, LONGEST len
)
1258 if (the_target
->qxfer_siginfo
== NULL
)
1261 if (annex
[0] != '\0' || !target_running ())
1264 return (*the_target
->qxfer_siginfo
) (annex
, readbuf
, writebuf
, offset
, len
);
1267 /* Handle qXfer:spu:read and qXfer:spu:write. */
1270 handle_qxfer_spu (const char *annex
,
1271 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1272 ULONGEST offset
, LONGEST len
)
1274 if (the_target
->qxfer_spu
== NULL
)
1277 if (!target_running ())
1280 return (*the_target
->qxfer_spu
) (annex
, readbuf
, writebuf
, offset
, len
);
1283 /* Handle qXfer:statictrace:read. */
1286 handle_qxfer_statictrace (const char *annex
,
1287 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1288 ULONGEST offset
, LONGEST len
)
1292 if (writebuf
!= NULL
)
1295 if (annex
[0] != '\0' || !target_running () || current_traceframe
== -1)
1298 if (traceframe_read_sdata (current_traceframe
, offset
,
1299 readbuf
, len
, &nbytes
))
1304 /* Helper for handle_qxfer_threads_proper.
1305 Emit the XML to describe the thread of INF. */
1308 handle_qxfer_threads_worker (struct inferior_list_entry
*inf
, void *arg
)
1310 struct thread_info
*thread
= (struct thread_info
*) inf
;
1311 struct buffer
*buffer
= arg
;
1312 ptid_t ptid
= thread_to_gdb_id (thread
);
1314 int core
= target_core_of_thread (ptid
);
1317 write_ptid (ptid_s
, ptid
);
1321 sprintf (core_s
, "%d", core
);
1322 buffer_xml_printf (buffer
, "<thread id=\"%s\" core=\"%s\"/>\n",
1327 buffer_xml_printf (buffer
, "<thread id=\"%s\"/>\n",
1332 /* Helper for handle_qxfer_threads. */
1335 handle_qxfer_threads_proper (struct buffer
*buffer
)
1337 buffer_grow_str (buffer
, "<threads>\n");
1339 for_each_inferior_with_data (&all_threads
, handle_qxfer_threads_worker
,
1342 buffer_grow_str0 (buffer
, "</threads>\n");
1345 /* Handle qXfer:threads:read. */
1348 handle_qxfer_threads (const char *annex
,
1349 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1350 ULONGEST offset
, LONGEST len
)
1352 static char *result
= 0;
1353 static unsigned int result_length
= 0;
1355 if (writebuf
!= NULL
)
1358 if (!target_running () || annex
[0] != '\0')
1363 struct buffer buffer
;
1364 /* When asked for data at offset 0, generate everything and store into
1365 'result'. Successive reads will be served off 'result'. */
1369 buffer_init (&buffer
);
1371 handle_qxfer_threads_proper (&buffer
);
1373 result
= buffer_finish (&buffer
);
1374 result_length
= strlen (result
);
1375 buffer_free (&buffer
);
1378 if (offset
>= result_length
)
1380 /* We're out of data. */
1387 if (len
> result_length
- offset
)
1388 len
= result_length
- offset
;
1390 memcpy (readbuf
, result
+ offset
, len
);
1395 /* Handle qXfer:traceframe-info:read. */
1398 handle_qxfer_traceframe_info (const char *annex
,
1399 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1400 ULONGEST offset
, LONGEST len
)
1402 static char *result
= 0;
1403 static unsigned int result_length
= 0;
1405 if (writebuf
!= NULL
)
1408 if (!target_running () || annex
[0] != '\0' || current_traceframe
== -1)
1413 struct buffer buffer
;
1415 /* When asked for data at offset 0, generate everything and
1416 store into 'result'. Successive reads will be served off
1420 buffer_init (&buffer
);
1422 traceframe_read_info (current_traceframe
, &buffer
);
1424 result
= buffer_finish (&buffer
);
1425 result_length
= strlen (result
);
1426 buffer_free (&buffer
);
1429 if (offset
>= result_length
)
1431 /* We're out of data. */
1438 if (len
> result_length
- offset
)
1439 len
= result_length
- offset
;
1441 memcpy (readbuf
, result
+ offset
, len
);
1445 /* Handle qXfer:fdpic:read. */
1448 handle_qxfer_fdpic (const char *annex
, gdb_byte
*readbuf
,
1449 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1451 if (the_target
->read_loadmap
== NULL
)
1454 if (!target_running ())
1457 return (*the_target
->read_loadmap
) (annex
, offset
, readbuf
, len
);
1460 /* Handle qXfer:btrace:read. */
1463 handle_qxfer_btrace (const char *annex
,
1464 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1465 ULONGEST offset
, LONGEST len
)
1467 static struct buffer cache
;
1468 struct thread_info
*thread
;
1471 if (the_target
->read_btrace
== NULL
|| writebuf
!= NULL
)
1474 if (!target_running ())
1477 if (ptid_equal (general_thread
, null_ptid
)
1478 || ptid_equal (general_thread
, minus_one_ptid
))
1480 strcpy (own_buf
, "E.Must select a single thread.");
1484 thread
= find_thread_ptid (general_thread
);
1487 strcpy (own_buf
, "E.No such thread.");
1491 if (thread
->btrace
== NULL
)
1493 strcpy (own_buf
, "E.Btrace not enabled.");
1497 if (strcmp (annex
, "all") == 0)
1498 type
= BTRACE_READ_ALL
;
1499 else if (strcmp (annex
, "new") == 0)
1500 type
= BTRACE_READ_NEW
;
1501 else if (strcmp (annex
, "delta") == 0)
1502 type
= BTRACE_READ_DELTA
;
1505 strcpy (own_buf
, "E.Bad annex.");
1511 buffer_free (&cache
);
1513 result
= target_read_btrace (thread
->btrace
, &cache
, type
);
1516 memcpy (own_buf
, cache
.buffer
, cache
.used_size
);
1520 else if (offset
> cache
.used_size
)
1522 buffer_free (&cache
);
1526 if (len
> cache
.used_size
- offset
)
1527 len
= cache
.used_size
- offset
;
1529 memcpy (readbuf
, cache
.buffer
+ offset
, len
);
1534 static const struct qxfer qxfer_packets
[] =
1536 { "auxv", handle_qxfer_auxv
},
1537 { "btrace", handle_qxfer_btrace
},
1538 { "fdpic", handle_qxfer_fdpic
},
1539 { "features", handle_qxfer_features
},
1540 { "libraries", handle_qxfer_libraries
},
1541 { "libraries-svr4", handle_qxfer_libraries_svr4
},
1542 { "osdata", handle_qxfer_osdata
},
1543 { "siginfo", handle_qxfer_siginfo
},
1544 { "spu", handle_qxfer_spu
},
1545 { "statictrace", handle_qxfer_statictrace
},
1546 { "threads", handle_qxfer_threads
},
1547 { "traceframe-info", handle_qxfer_traceframe_info
},
1551 handle_qxfer (char *own_buf
, int packet_len
, int *new_packet_len_p
)
1559 if (strncmp (own_buf
, "qXfer:", 6) != 0)
1562 /* Grab the object, r/w and annex. */
1563 if (decode_xfer (own_buf
+ 6, &object
, &rw
, &annex
, &offset
) < 0)
1565 write_enn (own_buf
);
1570 i
< sizeof (qxfer_packets
) / sizeof (qxfer_packets
[0]);
1573 const struct qxfer
*q
= &qxfer_packets
[i
];
1575 if (strcmp (object
, q
->object
) == 0)
1577 if (strcmp (rw
, "read") == 0)
1579 unsigned char *data
;
1584 /* Grab the offset and length. */
1585 if (decode_xfer_read (offset
, &ofs
, &len
) < 0)
1587 write_enn (own_buf
);
1591 /* Read one extra byte, as an indicator of whether there is
1593 if (len
> PBUFSIZ
- 2)
1595 data
= malloc (len
+ 1);
1598 write_enn (own_buf
);
1601 n
= (*q
->xfer
) (annex
, data
, NULL
, ofs
, len
+ 1);
1609 /* Preserve error message. */
1612 write_enn (own_buf
);
1614 *new_packet_len_p
= write_qxfer_response (own_buf
, data
, len
, 1);
1616 *new_packet_len_p
= write_qxfer_response (own_buf
, data
, n
, 0);
1621 else if (strcmp (rw
, "write") == 0)
1626 unsigned char *data
;
1628 strcpy (own_buf
, "E00");
1629 data
= malloc (packet_len
- (offset
- own_buf
));
1632 write_enn (own_buf
);
1635 if (decode_xfer_write (offset
, packet_len
- (offset
- own_buf
),
1636 &ofs
, &len
, data
) < 0)
1639 write_enn (own_buf
);
1643 n
= (*q
->xfer
) (annex
, NULL
, data
, ofs
, len
);
1651 /* Preserve error message. */
1654 write_enn (own_buf
);
1656 sprintf (own_buf
, "%x", n
);
1669 /* Table used by the crc32 function to calcuate the checksum. */
1671 static unsigned int crc32_table
[256] =
1674 /* Compute 32 bit CRC from inferior memory.
1676 On success, return 32 bit CRC.
1677 On failure, return (unsigned long long) -1. */
1679 static unsigned long long
1680 crc32 (CORE_ADDR base
, int len
, unsigned int crc
)
1682 if (!crc32_table
[1])
1684 /* Initialize the CRC table and the decoding table. */
1688 for (i
= 0; i
< 256; i
++)
1690 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
1691 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
1698 unsigned char byte
= 0;
1700 /* Return failure if memory read fails. */
1701 if (read_inferior_memory (base
, &byte
, 1) != 0)
1702 return (unsigned long long) -1;
1704 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ byte
) & 255];
1707 return (unsigned long long) crc
;
1710 /* Handle all of the extended 'q' packets. */
1713 handle_query (char *own_buf
, int packet_len
, int *new_packet_len_p
)
1715 static struct inferior_list_entry
*thread_ptr
;
1717 /* Reply the current thread id. */
1718 if (strcmp ("qC", own_buf
) == 0 && !disable_packet_qC
)
1721 require_running (own_buf
);
1723 if (!ptid_equal (general_thread
, null_ptid
)
1724 && !ptid_equal (general_thread
, minus_one_ptid
))
1725 gdb_id
= general_thread
;
1728 thread_ptr
= get_first_inferior (&all_threads
);
1729 gdb_id
= thread_to_gdb_id ((struct thread_info
*)thread_ptr
);
1732 sprintf (own_buf
, "QC");
1734 write_ptid (own_buf
, gdb_id
);
1738 if (strcmp ("qSymbol::", own_buf
) == 0)
1740 /* GDB is suggesting new symbols have been loaded. This may
1741 mean a new shared library has been detected as loaded, so
1742 take the opportunity to check if breakpoints we think are
1743 inserted, still are. Note that it isn't guaranteed that
1744 we'll see this when a shared library is loaded, and nor will
1745 we see this for unloads (although breakpoints in unloaded
1746 libraries shouldn't trigger), as GDB may not find symbols for
1747 the library at all. We also re-validate breakpoints when we
1748 see a second GDB breakpoint for the same address, and or when
1749 we access breakpoint shadows. */
1750 validate_breakpoints ();
1752 if (target_supports_tracepoints ())
1753 tracepoint_look_up_symbols ();
1755 if (target_running () && the_target
->look_up_symbols
!= NULL
)
1756 (*the_target
->look_up_symbols
) ();
1758 strcpy (own_buf
, "OK");
1762 if (!disable_packet_qfThreadInfo
)
1764 if (strcmp ("qfThreadInfo", own_buf
) == 0)
1768 require_running (own_buf
);
1769 thread_ptr
= get_first_inferior (&all_threads
);
1772 gdb_id
= thread_to_gdb_id ((struct thread_info
*)thread_ptr
);
1773 write_ptid (own_buf
, gdb_id
);
1774 thread_ptr
= thread_ptr
->next
;
1778 if (strcmp ("qsThreadInfo", own_buf
) == 0)
1782 require_running (own_buf
);
1783 if (thread_ptr
!= NULL
)
1786 gdb_id
= thread_to_gdb_id ((struct thread_info
*)thread_ptr
);
1787 write_ptid (own_buf
, gdb_id
);
1788 thread_ptr
= thread_ptr
->next
;
1793 sprintf (own_buf
, "l");
1799 if (the_target
->read_offsets
!= NULL
1800 && strcmp ("qOffsets", own_buf
) == 0)
1802 CORE_ADDR text
, data
;
1804 require_running (own_buf
);
1805 if (the_target
->read_offsets (&text
, &data
))
1806 sprintf (own_buf
, "Text=%lX;Data=%lX;Bss=%lX",
1807 (long)text
, (long)data
, (long)data
);
1809 write_enn (own_buf
);
1814 /* Protocol features query. */
1815 if (strncmp ("qSupported", own_buf
, 10) == 0
1816 && (own_buf
[10] == ':' || own_buf
[10] == '\0'))
1818 char *p
= &own_buf
[10];
1819 int gdb_supports_qRelocInsn
= 0;
1821 /* Start processing qSupported packet. */
1822 target_process_qsupported (NULL
);
1824 /* Process each feature being provided by GDB. The first
1825 feature will follow a ':', and latter features will follow
1829 char **qsupported
= NULL
;
1833 /* Two passes, to avoid nested strtok calls in
1834 target_process_qsupported. */
1835 for (p
= strtok (p
+ 1, ";");
1837 p
= strtok (NULL
, ";"))
1840 qsupported
= xrealloc (qsupported
, count
* sizeof (char *));
1841 qsupported
[count
- 1] = xstrdup (p
);
1844 for (i
= 0; i
< count
; i
++)
1847 if (strcmp (p
, "multiprocess+") == 0)
1849 /* GDB supports and wants multi-process support if
1851 if (target_supports_multi_process ())
1854 else if (strcmp (p
, "qRelocInsn+") == 0)
1856 /* GDB supports relocate instruction requests. */
1857 gdb_supports_qRelocInsn
= 1;
1860 target_process_qsupported (p
);
1869 "PacketSize=%x;QPassSignals+;QProgramSignals+",
1872 if (the_target
->qxfer_libraries_svr4
!= NULL
)
1873 strcat (own_buf
, ";qXfer:libraries-svr4:read+"
1874 ";augmented-libraries-svr4-read+");
1877 /* We do not have any hook to indicate whether the non-SVR4 target
1878 backend supports qXfer:libraries:read, so always report it. */
1879 strcat (own_buf
, ";qXfer:libraries:read+");
1882 if (the_target
->read_auxv
!= NULL
)
1883 strcat (own_buf
, ";qXfer:auxv:read+");
1885 if (the_target
->qxfer_spu
!= NULL
)
1886 strcat (own_buf
, ";qXfer:spu:read+;qXfer:spu:write+");
1888 if (the_target
->qxfer_siginfo
!= NULL
)
1889 strcat (own_buf
, ";qXfer:siginfo:read+;qXfer:siginfo:write+");
1891 if (the_target
->read_loadmap
!= NULL
)
1892 strcat (own_buf
, ";qXfer:fdpic:read+");
1894 /* We always report qXfer:features:read, as targets may
1895 install XML files on a subsequent call to arch_setup.
1896 If we reported to GDB on startup that we don't support
1897 qXfer:feature:read at all, we will never be re-queried. */
1898 strcat (own_buf
, ";qXfer:features:read+");
1900 if (transport_is_reliable
)
1901 strcat (own_buf
, ";QStartNoAckMode+");
1903 if (the_target
->qxfer_osdata
!= NULL
)
1904 strcat (own_buf
, ";qXfer:osdata:read+");
1906 if (target_supports_multi_process ())
1907 strcat (own_buf
, ";multiprocess+");
1909 if (target_supports_non_stop ())
1910 strcat (own_buf
, ";QNonStop+");
1912 if (target_supports_disable_randomization ())
1913 strcat (own_buf
, ";QDisableRandomization+");
1915 strcat (own_buf
, ";qXfer:threads:read+");
1917 if (target_supports_tracepoints ())
1919 strcat (own_buf
, ";ConditionalTracepoints+");
1920 strcat (own_buf
, ";TraceStateVariables+");
1921 strcat (own_buf
, ";TracepointSource+");
1922 strcat (own_buf
, ";DisconnectedTracing+");
1923 if (gdb_supports_qRelocInsn
&& target_supports_fast_tracepoints ())
1924 strcat (own_buf
, ";FastTracepoints+");
1925 strcat (own_buf
, ";StaticTracepoints+");
1926 strcat (own_buf
, ";InstallInTrace+");
1927 strcat (own_buf
, ";qXfer:statictrace:read+");
1928 strcat (own_buf
, ";qXfer:traceframe-info:read+");
1929 strcat (own_buf
, ";EnableDisableTracepoints+");
1930 strcat (own_buf
, ";QTBuffer:size+");
1931 strcat (own_buf
, ";tracenz+");
1934 /* Support target-side breakpoint conditions and commands. */
1935 strcat (own_buf
, ";ConditionalBreakpoints+");
1936 strcat (own_buf
, ";BreakpointCommands+");
1938 if (target_supports_agent ())
1939 strcat (own_buf
, ";QAgent+");
1941 if (target_supports_btrace ())
1943 strcat (own_buf
, ";Qbtrace:bts+");
1944 strcat (own_buf
, ";Qbtrace:off+");
1945 strcat (own_buf
, ";qXfer:btrace:read+");
1951 /* Thread-local storage support. */
1952 if (the_target
->get_tls_address
!= NULL
1953 && strncmp ("qGetTLSAddr:", own_buf
, 12) == 0)
1955 char *p
= own_buf
+ 12;
1956 CORE_ADDR parts
[2], address
= 0;
1958 ptid_t ptid
= null_ptid
;
1960 require_running (own_buf
);
1962 for (i
= 0; i
< 3; i
++)
1970 p2
= strchr (p
, ',');
1983 ptid
= read_ptid (p
, NULL
);
1985 decode_address (&parts
[i
- 1], p
, len
);
1989 if (p
!= NULL
|| i
< 3)
1993 struct thread_info
*thread
= find_thread_ptid (ptid
);
1998 err
= the_target
->get_tls_address (thread
, parts
[0], parts
[1],
2004 strcpy (own_buf
, paddress(address
));
2009 write_enn (own_buf
);
2013 /* Otherwise, pretend we do not understand this packet. */
2016 /* Windows OS Thread Information Block address support. */
2017 if (the_target
->get_tib_address
!= NULL
2018 && strncmp ("qGetTIBAddr:", own_buf
, 12) == 0)
2023 ptid_t ptid
= read_ptid (own_buf
+ 12, &annex
);
2025 n
= (*the_target
->get_tib_address
) (ptid
, &tlb
);
2028 strcpy (own_buf
, paddress(tlb
));
2033 write_enn (own_buf
);
2039 /* Handle "monitor" commands. */
2040 if (strncmp ("qRcmd,", own_buf
, 6) == 0)
2042 char *mon
= malloc (PBUFSIZ
);
2043 int len
= strlen (own_buf
+ 6);
2047 write_enn (own_buf
);
2052 || hex2bin (own_buf
+ 6, (gdb_byte
*) mon
, len
/ 2) != len
/ 2)
2054 write_enn (own_buf
);
2058 mon
[len
/ 2] = '\0';
2062 if (the_target
->handle_monitor_command
== NULL
2063 || (*the_target
->handle_monitor_command
) (mon
) == 0)
2064 /* Default processing. */
2065 handle_monitor_command (mon
, own_buf
);
2071 if (strncmp ("qSearch:memory:", own_buf
,
2072 sizeof ("qSearch:memory:") - 1) == 0)
2074 require_running (own_buf
);
2075 handle_search_memory (own_buf
, packet_len
);
2079 if (strcmp (own_buf
, "qAttached") == 0
2080 || strncmp (own_buf
, "qAttached:", sizeof ("qAttached:") - 1) == 0)
2082 struct process_info
*process
;
2084 if (own_buf
[sizeof ("qAttached") - 1])
2086 int pid
= strtoul (own_buf
+ sizeof ("qAttached:") - 1, NULL
, 16);
2087 process
= (struct process_info
*)
2088 find_inferior_id (&all_processes
, pid_to_ptid (pid
));
2092 require_running (own_buf
);
2093 process
= current_process ();
2096 if (process
== NULL
)
2098 write_enn (own_buf
);
2102 strcpy (own_buf
, process
->attached
? "1" : "0");
2106 if (strncmp ("qCRC:", own_buf
, 5) == 0)
2108 /* CRC check (compare-section). */
2112 unsigned long long crc
;
2114 require_running (own_buf
);
2115 comma
= unpack_varlen_hex (own_buf
+ 5, &base
);
2116 if (*comma
++ != ',')
2118 write_enn (own_buf
);
2121 len
= strtoul (comma
, NULL
, 16);
2122 crc
= crc32 (base
, len
, 0xffffffff);
2123 /* Check for memory failure. */
2124 if (crc
== (unsigned long long) -1)
2126 write_enn (own_buf
);
2129 sprintf (own_buf
, "C%lx", (unsigned long) crc
);
2133 if (handle_qxfer (own_buf
, packet_len
, new_packet_len_p
))
2136 if (target_supports_tracepoints () && handle_tracepoint_query (own_buf
))
2139 /* Otherwise we didn't know what packet it was. Say we didn't
2144 static void gdb_wants_all_threads_stopped (void);
2145 static void resume (struct thread_resume
*actions
, size_t n
);
2147 /* The callback that is passed to visit_actioned_threads. */
2148 typedef int (visit_actioned_threads_callback_ftype
)
2149 (const struct thread_resume
*, struct thread_info
*);
2151 /* Struct to pass data to visit_actioned_threads. */
2153 struct visit_actioned_threads_data
2155 const struct thread_resume
*actions
;
2157 visit_actioned_threads_callback_ftype
*callback
;
2160 /* Call CALLBACK for any thread to which ACTIONS applies to. Returns
2161 true if CALLBACK returns true. Returns false if no matching thread
2162 is found or CALLBACK results false.
2163 Note: This function is itself a callback for find_inferior. */
2166 visit_actioned_threads (struct inferior_list_entry
*entry
, void *datap
)
2168 struct visit_actioned_threads_data
*data
= datap
;
2169 const struct thread_resume
*actions
= data
->actions
;
2170 size_t num_actions
= data
->num_actions
;
2171 visit_actioned_threads_callback_ftype
*callback
= data
->callback
;
2174 for (i
= 0; i
< num_actions
; i
++)
2176 const struct thread_resume
*action
= &actions
[i
];
2178 if (ptid_equal (action
->thread
, minus_one_ptid
)
2179 || ptid_equal (action
->thread
, entry
->id
)
2180 || ((ptid_get_pid (action
->thread
)
2181 == ptid_get_pid (entry
->id
))
2182 && ptid_get_lwp (action
->thread
) == -1))
2184 struct thread_info
*thread
= (struct thread_info
*) entry
;
2186 if ((*callback
) (action
, thread
))
2194 /* Callback for visit_actioned_threads. If the thread has a pending
2195 status to report, report it now. */
2198 handle_pending_status (const struct thread_resume
*resumption
,
2199 struct thread_info
*thread
)
2201 if (thread
->status_pending_p
)
2203 thread
->status_pending_p
= 0;
2205 last_status
= thread
->last_status
;
2206 last_ptid
= thread
->entry
.id
;
2207 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
2213 /* Parse vCont packets. */
2215 handle_v_cont (char *own_buf
)
2219 struct thread_resume
*resume_info
;
2220 struct thread_resume default_action
= {{0}};
2222 /* Count the number of semicolons in the packet. There should be one
2223 for every action. */
2229 p
= strchr (p
, ';');
2232 resume_info
= malloc (n
* sizeof (resume_info
[0]));
2233 if (resume_info
== NULL
)
2241 memset (&resume_info
[i
], 0, sizeof resume_info
[i
]);
2243 if (p
[0] == 's' || p
[0] == 'S')
2244 resume_info
[i
].kind
= resume_step
;
2245 else if (p
[0] == 'r')
2246 resume_info
[i
].kind
= resume_step
;
2247 else if (p
[0] == 'c' || p
[0] == 'C')
2248 resume_info
[i
].kind
= resume_continue
;
2249 else if (p
[0] == 't')
2250 resume_info
[i
].kind
= resume_stop
;
2254 if (p
[0] == 'S' || p
[0] == 'C')
2257 sig
= strtol (p
+ 1, &q
, 16);
2262 if (!gdb_signal_to_host_p (sig
))
2264 resume_info
[i
].sig
= gdb_signal_to_host (sig
);
2266 else if (p
[0] == 'r')
2270 p
= unpack_varlen_hex (p
+ 1, &addr
);
2271 resume_info
[i
].step_range_start
= addr
;
2276 p
= unpack_varlen_hex (p
+ 1, &addr
);
2277 resume_info
[i
].step_range_end
= addr
;
2286 resume_info
[i
].thread
= minus_one_ptid
;
2287 default_action
= resume_info
[i
];
2289 /* Note: we don't increment i here, we'll overwrite this entry
2290 the next time through. */
2292 else if (p
[0] == ':')
2294 ptid_t ptid
= read_ptid (p
+ 1, &q
);
2299 if (p
[0] != ';' && p
[0] != 0)
2302 resume_info
[i
].thread
= ptid
;
2309 resume_info
[i
] = default_action
;
2311 /* `cont_thread' is still used in occasional places in the backend,
2312 to implement single-thread scheduler-locking. Doesn't make sense
2313 to set it if we see a stop request, or a wildcard action (one
2314 with '-1' (all threads), or 'pPID.-1' (all threads of PID)). */
2316 && !(ptid_equal (resume_info
[0].thread
, minus_one_ptid
)
2317 || ptid_get_lwp (resume_info
[0].thread
) == -1)
2318 && resume_info
[0].kind
!= resume_stop
)
2319 cont_thread
= resume_info
[0].thread
;
2321 cont_thread
= minus_one_ptid
;
2322 set_desired_inferior (0);
2324 resume (resume_info
, n
);
2329 write_enn (own_buf
);
2334 /* Resume target with ACTIONS, an array of NUM_ACTIONS elements. */
2337 resume (struct thread_resume
*actions
, size_t num_actions
)
2341 /* Check if among the threads that GDB wants actioned, there's
2342 one with a pending status to report. If so, skip actually
2343 resuming/stopping and report the pending event
2345 struct visit_actioned_threads_data data
;
2347 data
.actions
= actions
;
2348 data
.num_actions
= num_actions
;
2349 data
.callback
= handle_pending_status
;
2350 if (find_inferior (&all_threads
, visit_actioned_threads
, &data
) != NULL
)
2356 (*the_target
->resume
) (actions
, num_actions
);
2362 last_ptid
= mywait (minus_one_ptid
, &last_status
, 0, 1);
2364 if (last_status
.kind
== TARGET_WAITKIND_NO_RESUMED
)
2366 /* No proper RSP support for this yet. At least return
2368 sprintf (own_buf
, "E.No unwaited-for children left.");
2369 disable_async_io ();
2373 if (last_status
.kind
!= TARGET_WAITKIND_EXITED
2374 && last_status
.kind
!= TARGET_WAITKIND_SIGNALLED
2375 && last_status
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
2376 current_inferior
->last_status
= last_status
;
2378 /* From the client's perspective, all-stop mode always stops all
2379 threads implicitly (and the target backend has already done
2380 so by now). Tag all threads as "want-stopped", so we don't
2381 resume them implicitly without the client telling us to. */
2382 gdb_wants_all_threads_stopped ();
2383 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
2384 disable_async_io ();
2386 if (last_status
.kind
== TARGET_WAITKIND_EXITED
2387 || last_status
.kind
== TARGET_WAITKIND_SIGNALLED
)
2388 mourn_inferior (find_process_pid (ptid_get_pid (last_ptid
)));
2392 /* Attach to a new program. Return 1 if successful, 0 if failure. */
2394 handle_v_attach (char *own_buf
)
2398 pid
= strtol (own_buf
+ 8, NULL
, 16);
2399 if (pid
!= 0 && attach_inferior (pid
) == 0)
2401 /* Don't report shared library events after attaching, even if
2402 some libraries are preloaded. GDB will always poll the
2403 library list. Avoids the "stopped by shared library event"
2404 notice on the GDB side. */
2409 /* In non-stop, we don't send a resume reply. Stop events
2410 will follow up using the normal notification
2415 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
2421 write_enn (own_buf
);
2426 /* Run a new program. Return 1 if successful, 0 if failure. */
2428 handle_v_run (char *own_buf
)
2430 char *p
, *next_p
, **new_argv
;
2434 for (p
= own_buf
+ strlen ("vRun;"); p
&& *p
; p
= strchr (p
, ';'))
2440 new_argv
= calloc (new_argc
+ 2, sizeof (char *));
2441 if (new_argv
== NULL
)
2443 write_enn (own_buf
);
2448 for (p
= own_buf
+ strlen ("vRun;"); *p
; p
= next_p
)
2450 next_p
= strchr (p
, ';');
2452 next_p
= p
+ strlen (p
);
2454 if (i
== 0 && p
== next_p
)
2458 /* FIXME: Fail request if out of memory instead of dying. */
2459 new_argv
[i
] = xmalloc (1 + (next_p
- p
) / 2);
2460 hex2bin (p
, (gdb_byte
*) new_argv
[i
], (next_p
- p
) / 2);
2461 new_argv
[i
][(next_p
- p
) / 2] = '\0';
2470 if (new_argv
[0] == NULL
)
2472 /* GDB didn't specify a program to run. Use the program from the
2473 last run with the new argument list. */
2475 if (program_argv
== NULL
)
2477 write_enn (own_buf
);
2478 freeargv (new_argv
);
2482 new_argv
[0] = strdup (program_argv
[0]);
2483 if (new_argv
[0] == NULL
)
2485 write_enn (own_buf
);
2486 freeargv (new_argv
);
2491 /* Free the old argv and install the new one. */
2492 freeargv (program_argv
);
2493 program_argv
= new_argv
;
2495 start_inferior (program_argv
);
2496 if (last_status
.kind
== TARGET_WAITKIND_STOPPED
)
2498 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
2500 /* In non-stop, sending a resume reply doesn't set the general
2501 thread, but GDB assumes a vRun sets it (this is so GDB can
2502 query which is the main thread of the new inferior. */
2504 general_thread
= last_ptid
;
2510 write_enn (own_buf
);
2515 /* Kill process. Return 1 if successful, 0 if failure. */
2517 handle_v_kill (char *own_buf
)
2520 char *p
= &own_buf
[6];
2522 pid
= strtol (p
, NULL
, 16);
2525 if (pid
!= 0 && kill_inferior (pid
) == 0)
2527 last_status
.kind
= TARGET_WAITKIND_SIGNALLED
;
2528 last_status
.value
.sig
= GDB_SIGNAL_KILL
;
2529 last_ptid
= pid_to_ptid (pid
);
2530 discard_queued_stop_replies (pid
);
2536 write_enn (own_buf
);
2541 /* Handle all of the extended 'v' packets. */
2543 handle_v_requests (char *own_buf
, int packet_len
, int *new_packet_len
)
2545 if (!disable_packet_vCont
)
2547 if (strncmp (own_buf
, "vCont;", 6) == 0)
2549 require_running (own_buf
);
2550 handle_v_cont (own_buf
);
2554 if (strncmp (own_buf
, "vCont?", 6) == 0)
2556 strcpy (own_buf
, "vCont;c;C;s;S;t");
2557 if (target_supports_range_stepping ())
2559 own_buf
= own_buf
+ strlen (own_buf
);
2560 strcpy (own_buf
, ";r");
2566 if (strncmp (own_buf
, "vFile:", 6) == 0
2567 && handle_vFile (own_buf
, packet_len
, new_packet_len
))
2570 if (strncmp (own_buf
, "vAttach;", 8) == 0)
2572 if ((!extended_protocol
|| !multi_process
) && target_running ())
2574 fprintf (stderr
, "Already debugging a process\n");
2575 write_enn (own_buf
);
2578 handle_v_attach (own_buf
);
2582 if (strncmp (own_buf
, "vRun;", 5) == 0)
2584 if ((!extended_protocol
|| !multi_process
) && target_running ())
2586 fprintf (stderr
, "Already debugging a process\n");
2587 write_enn (own_buf
);
2590 handle_v_run (own_buf
);
2594 if (strncmp (own_buf
, "vKill;", 6) == 0)
2596 if (!target_running ())
2598 fprintf (stderr
, "No process to kill\n");
2599 write_enn (own_buf
);
2602 handle_v_kill (own_buf
);
2606 if (handle_notif_ack (own_buf
, packet_len
))
2609 /* Otherwise we didn't know what packet it was. Say we didn't
2615 /* Resume inferior and wait for another event. In non-stop mode,
2616 don't really wait here, but return immediatelly to the event
2619 myresume (char *own_buf
, int step
, int sig
)
2621 struct thread_resume resume_info
[2];
2623 int valid_cont_thread
;
2625 set_desired_inferior (0);
2627 valid_cont_thread
= (!ptid_equal (cont_thread
, null_ptid
)
2628 && !ptid_equal (cont_thread
, minus_one_ptid
));
2630 if (step
|| sig
|| valid_cont_thread
)
2632 resume_info
[0].thread
= current_ptid
;
2634 resume_info
[0].kind
= resume_step
;
2636 resume_info
[0].kind
= resume_continue
;
2637 resume_info
[0].sig
= sig
;
2641 if (!valid_cont_thread
)
2643 resume_info
[n
].thread
= minus_one_ptid
;
2644 resume_info
[n
].kind
= resume_continue
;
2645 resume_info
[n
].sig
= 0;
2649 resume (resume_info
, n
);
2652 /* Callback for for_each_inferior. Make a new stop reply for each
2656 queue_stop_reply_callback (struct inferior_list_entry
*entry
, void *arg
)
2658 struct thread_info
*thread
= (struct thread_info
*) entry
;
2660 /* For now, assume targets that don't have this callback also don't
2661 manage the thread's last_status field. */
2662 if (the_target
->thread_stopped
== NULL
)
2664 struct vstop_notif
*new_notif
= xmalloc (sizeof (*new_notif
));
2666 new_notif
->ptid
= entry
->id
;
2667 new_notif
->status
= thread
->last_status
;
2668 /* Pass the last stop reply back to GDB, but don't notify
2670 notif_event_enque (¬if_stop
,
2671 (struct notif_event
*) new_notif
);
2675 if (thread_stopped (thread
))
2680 = target_waitstatus_to_string (&thread
->last_status
);
2682 debug_printf ("Reporting thread %s as already stopped with %s\n",
2683 target_pid_to_str (entry
->id
),
2686 xfree (status_string
);
2689 gdb_assert (thread
->last_status
.kind
!= TARGET_WAITKIND_IGNORE
);
2691 /* Pass the last stop reply back to GDB, but don't notify
2693 queue_stop_reply (entry
->id
, &thread
->last_status
);
2700 /* Set this inferior threads's state as "want-stopped". We won't
2701 resume this thread until the client gives us another action for
2705 gdb_wants_thread_stopped (struct inferior_list_entry
*entry
)
2707 struct thread_info
*thread
= (struct thread_info
*) entry
;
2709 thread
->last_resume_kind
= resume_stop
;
2711 if (thread
->last_status
.kind
== TARGET_WAITKIND_IGNORE
)
2713 /* Most threads are stopped implicitly (all-stop); tag that with
2715 thread
->last_status
.kind
= TARGET_WAITKIND_STOPPED
;
2716 thread
->last_status
.value
.sig
= GDB_SIGNAL_0
;
2720 /* Set all threads' states as "want-stopped". */
2723 gdb_wants_all_threads_stopped (void)
2725 for_each_inferior (&all_threads
, gdb_wants_thread_stopped
);
2728 /* Clear the gdb_detached flag of every process. */
2731 gdb_reattached_process (struct inferior_list_entry
*entry
)
2733 struct process_info
*process
= (struct process_info
*) entry
;
2735 process
->gdb_detached
= 0;
2738 /* Callback for for_each_inferior. Clear the thread's pending status
2742 clear_pending_status_callback (struct inferior_list_entry
*entry
)
2744 struct thread_info
*thread
= (struct thread_info
*) entry
;
2746 thread
->status_pending_p
= 0;
2749 /* Callback for for_each_inferior. If the thread is stopped with an
2750 interesting event, mark it as having a pending event. */
2753 set_pending_status_callback (struct inferior_list_entry
*entry
)
2755 struct thread_info
*thread
= (struct thread_info
*) entry
;
2757 if (thread
->last_status
.kind
!= TARGET_WAITKIND_STOPPED
2758 || (thread
->last_status
.value
.sig
!= GDB_SIGNAL_0
2759 /* A breakpoint, watchpoint or finished step from a previous
2760 GDB run isn't considered interesting for a new GDB run.
2761 If we left those pending, the new GDB could consider them
2762 random SIGTRAPs. This leaves out real async traps. We'd
2763 have to peek into the (target-specific) siginfo to
2764 distinguish those. */
2765 && thread
->last_status
.value
.sig
!= GDB_SIGNAL_TRAP
))
2766 thread
->status_pending_p
= 1;
2769 /* Callback for find_inferior. Return true if ENTRY (a thread) has a
2770 pending status to report to GDB. */
2773 find_status_pending_thread_callback (struct inferior_list_entry
*entry
, void *data
)
2775 struct thread_info
*thread
= (struct thread_info
*) entry
;
2777 return thread
->status_pending_p
;
2780 /* Status handler for the '?' packet. */
2783 handle_status (char *own_buf
)
2785 /* GDB is connected, don't forward events to the target anymore. */
2786 for_each_inferior (&all_processes
, gdb_reattached_process
);
2788 /* In non-stop mode, we must send a stop reply for each stopped
2789 thread. In all-stop mode, just send one for the first stopped
2794 find_inferior (&all_threads
, queue_stop_reply_callback
, NULL
);
2796 /* The first is sent immediatly. OK is sent if there is no
2797 stopped thread, which is the same handling of the vStopped
2798 packet (by design). */
2799 notif_write_event (¬if_stop
, own_buf
);
2803 struct inferior_list_entry
*thread
= NULL
;
2806 stabilize_threads ();
2807 gdb_wants_all_threads_stopped ();
2809 /* We can only report one status, but we might be coming out of
2810 non-stop -- if more than one thread is stopped with
2811 interesting events, leave events for the threads we're not
2812 reporting now pending. They'll be reported the next time the
2813 threads are resumed. Start by marking all interesting events
2815 for_each_inferior (&all_threads
, set_pending_status_callback
);
2817 /* Prefer the last thread that reported an event to GDB (even if
2818 that was a GDB_SIGNAL_TRAP). */
2819 if (last_status
.kind
!= TARGET_WAITKIND_IGNORE
2820 && last_status
.kind
!= TARGET_WAITKIND_EXITED
2821 && last_status
.kind
!= TARGET_WAITKIND_SIGNALLED
)
2822 thread
= find_inferior_id (&all_threads
, last_ptid
);
2824 /* If the last event thread is not found for some reason, look
2825 for some other thread that might have an event to report. */
2827 thread
= find_inferior (&all_threads
,
2828 find_status_pending_thread_callback
, NULL
);
2830 /* If we're still out of luck, simply pick the first thread in
2833 thread
= get_first_inferior (&all_threads
);
2837 struct thread_info
*tp
= (struct thread_info
*) thread
;
2839 /* We're reporting this event, so it's no longer
2841 tp
->status_pending_p
= 0;
2843 /* GDB assumes the current thread is the thread we're
2844 reporting the status for. */
2845 general_thread
= thread
->id
;
2846 set_desired_inferior (1);
2848 gdb_assert (tp
->last_status
.kind
!= TARGET_WAITKIND_IGNORE
);
2849 prepare_resume_reply (own_buf
, tp
->entry
.id
, &tp
->last_status
);
2852 strcpy (own_buf
, "W00");
2857 gdbserver_version (void)
2859 printf ("GNU gdbserver %s%s\n"
2860 "Copyright (C) 2014 Free Software Foundation, Inc.\n"
2861 "gdbserver is free software, covered by the "
2862 "GNU General Public License.\n"
2863 "This gdbserver was configured as \"%s\"\n",
2864 PKGVERSION
, version
, host_name
);
2868 gdbserver_usage (FILE *stream
)
2870 fprintf (stream
, "Usage:\tgdbserver [OPTIONS] COMM PROG [ARGS ...]\n"
2871 "\tgdbserver [OPTIONS] --attach COMM PID\n"
2872 "\tgdbserver [OPTIONS] --multi COMM\n"
2874 "COMM may either be a tty device (for serial debugging), or \n"
2875 "HOST:PORT to listen for a TCP connection.\n"
2878 " --debug Enable general debugging output.\n"
2879 " --debug-format=opt1[,opt2,...]\n"
2880 " Specify extra content in debugging output.\n"
2885 " --remote-debug Enable remote protocol debugging output.\n"
2886 " --version Display version information and exit.\n"
2887 " --wrapper WRAPPER -- Run WRAPPER to start new programs.\n"
2888 " --once Exit after the first connection has "
2890 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
2891 fprintf (stream
, "Report bugs to \"%s\".\n", REPORT_BUGS_TO
);
2895 gdbserver_show_disableable (FILE *stream
)
2897 fprintf (stream
, "Disableable packets:\n"
2898 " vCont \tAll vCont packets\n"
2899 " qC \tQuerying the current thread\n"
2900 " qfThreadInfo\tThread listing\n"
2901 " Tthread \tPassing the thread specifier in the "
2902 "T stop reply packet\n"
2903 " threads \tAll of the above\n");
2907 #undef require_running
2908 #define require_running(BUF) \
2909 if (!target_running ()) \
2916 first_thread_of (struct inferior_list_entry
*entry
, void *args
)
2918 int pid
= * (int *) args
;
2920 if (ptid_get_pid (entry
->id
) == pid
)
2927 kill_inferior_callback (struct inferior_list_entry
*entry
)
2929 struct process_info
*process
= (struct process_info
*) entry
;
2930 int pid
= ptid_get_pid (process
->entry
.id
);
2932 kill_inferior (pid
);
2933 discard_queued_stop_replies (pid
);
2936 /* Callback for for_each_inferior to detach or kill the inferior,
2937 depending on whether we attached to it or not.
2938 We inform the user whether we're detaching or killing the process
2939 as this is only called when gdbserver is about to exit. */
2942 detach_or_kill_inferior_callback (struct inferior_list_entry
*entry
)
2944 struct process_info
*process
= (struct process_info
*) entry
;
2945 int pid
= ptid_get_pid (process
->entry
.id
);
2947 if (process
->attached
)
2948 detach_inferior (pid
);
2950 kill_inferior (pid
);
2952 discard_queued_stop_replies (pid
);
2955 /* for_each_inferior callback for detach_or_kill_for_exit to print
2956 the pids of started inferiors. */
2959 print_started_pid (struct inferior_list_entry
*entry
)
2961 struct process_info
*process
= (struct process_info
*) entry
;
2963 if (! process
->attached
)
2965 int pid
= ptid_get_pid (process
->entry
.id
);
2966 fprintf (stderr
, " %d", pid
);
2970 /* for_each_inferior callback for detach_or_kill_for_exit to print
2971 the pids of attached inferiors. */
2974 print_attached_pid (struct inferior_list_entry
*entry
)
2976 struct process_info
*process
= (struct process_info
*) entry
;
2978 if (process
->attached
)
2980 int pid
= ptid_get_pid (process
->entry
.id
);
2981 fprintf (stderr
, " %d", pid
);
2985 /* Call this when exiting gdbserver with possible inferiors that need
2986 to be killed or detached from. */
2989 detach_or_kill_for_exit (void)
2991 /* First print a list of the inferiors we will be killing/detaching.
2992 This is to assist the user, for example, in case the inferior unexpectedly
2993 dies after we exit: did we screw up or did the inferior exit on its own?
2994 Having this info will save some head-scratching. */
2996 if (have_started_inferiors_p ())
2998 fprintf (stderr
, "Killing process(es):");
2999 for_each_inferior (&all_processes
, print_started_pid
);
3000 fprintf (stderr
, "\n");
3002 if (have_attached_inferiors_p ())
3004 fprintf (stderr
, "Detaching process(es):");
3005 for_each_inferior (&all_processes
, print_attached_pid
);
3006 fprintf (stderr
, "\n");
3009 /* Now we can kill or detach the inferiors. */
3011 for_each_inferior (&all_processes
, detach_or_kill_inferior_callback
);
3014 /* Value that will be passed to exit(3) when gdbserver exits. */
3015 static int exit_code
;
3017 /* Cleanup version of detach_or_kill_for_exit. */
3020 detach_or_kill_for_exit_cleanup (void *ignore
)
3022 volatile struct gdb_exception exception
;
3024 TRY_CATCH (exception
, RETURN_MASK_ALL
)
3026 detach_or_kill_for_exit ();
3029 if (exception
.reason
< 0)
3032 fprintf (stderr
, "Detach or kill failed: %s\n", exception
.message
);
3037 /* Main function. This is called by the real "main" function,
3038 wrapped in a TRY_CATCH that handles any uncaught exceptions. */
3040 static void ATTRIBUTE_NORETURN
3041 captured_main (int argc
, char *argv
[])
3045 char *arg_end
, *port
;
3046 char **next_arg
= &argv
[1];
3047 volatile int multi_mode
= 0;
3048 volatile int attach
= 0;
3051 while (*next_arg
!= NULL
&& **next_arg
== '-')
3053 if (strcmp (*next_arg
, "--version") == 0)
3055 gdbserver_version ();
3058 else if (strcmp (*next_arg
, "--help") == 0)
3060 gdbserver_usage (stdout
);
3063 else if (strcmp (*next_arg
, "--attach") == 0)
3065 else if (strcmp (*next_arg
, "--multi") == 0)
3067 else if (strcmp (*next_arg
, "--wrapper") == 0)
3071 wrapper_argv
= next_arg
;
3072 while (*next_arg
!= NULL
&& strcmp (*next_arg
, "--") != 0)
3075 if (next_arg
== wrapper_argv
|| *next_arg
== NULL
)
3077 gdbserver_usage (stderr
);
3081 /* Consume the "--". */
3084 else if (strcmp (*next_arg
, "--debug") == 0)
3086 else if (strncmp (*next_arg
,
3088 sizeof ("--debug-format=") - 1) == 0)
3091 = parse_debug_format_options ((*next_arg
)
3092 + sizeof ("--debug-format=") - 1, 0);
3094 if (error_msg
!= NULL
)
3096 fprintf (stderr
, "%s", error_msg
);
3100 else if (strcmp (*next_arg
, "--remote-debug") == 0)
3102 else if (strcmp (*next_arg
, "--disable-packet") == 0)
3104 gdbserver_show_disableable (stdout
);
3107 else if (strncmp (*next_arg
,
3108 "--disable-packet=",
3109 sizeof ("--disable-packet=") - 1) == 0)
3111 char *packets
, *tok
;
3113 packets
= *next_arg
+= sizeof ("--disable-packet=") - 1;
3114 for (tok
= strtok (packets
, ",");
3116 tok
= strtok (NULL
, ","))
3118 if (strcmp ("vCont", tok
) == 0)
3119 disable_packet_vCont
= 1;
3120 else if (strcmp ("Tthread", tok
) == 0)
3121 disable_packet_Tthread
= 1;
3122 else if (strcmp ("qC", tok
) == 0)
3123 disable_packet_qC
= 1;
3124 else if (strcmp ("qfThreadInfo", tok
) == 0)
3125 disable_packet_qfThreadInfo
= 1;
3126 else if (strcmp ("threads", tok
) == 0)
3128 disable_packet_vCont
= 1;
3129 disable_packet_Tthread
= 1;
3130 disable_packet_qC
= 1;
3131 disable_packet_qfThreadInfo
= 1;
3135 fprintf (stderr
, "Don't know how to disable \"%s\".\n\n",
3137 gdbserver_show_disableable (stderr
);
3142 else if (strcmp (*next_arg
, "-") == 0)
3144 /* "-" specifies a stdio connection and is a form of port
3146 *next_arg
= STDIO_CONNECTION_NAME
;
3149 else if (strcmp (*next_arg
, "--disable-randomization") == 0)
3150 disable_randomization
= 1;
3151 else if (strcmp (*next_arg
, "--no-disable-randomization") == 0)
3152 disable_randomization
= 0;
3153 else if (strcmp (*next_arg
, "--once") == 0)
3157 fprintf (stderr
, "Unknown argument: %s\n", *next_arg
);
3167 if (port
== NULL
|| (!attach
&& !multi_mode
&& *next_arg
== NULL
))
3169 gdbserver_usage (stderr
);
3173 /* Remember stdio descriptors. LISTEN_DESC must not be listed, it will be
3174 opened by remote_prepare. */
3177 /* We need to know whether the remote connection is stdio before
3178 starting the inferior. Inferiors created in this scenario have
3179 stdin,stdout redirected. So do this here before we call
3181 remote_prepare (port
);
3186 /* --attach used to come after PORT, so allow it there for
3188 if (*next_arg
!= NULL
&& strcmp (*next_arg
, "--attach") == 0)
3195 && (*next_arg
== NULL
3196 || (*next_arg
)[0] == '\0'
3197 || (pid
= strtoul (*next_arg
, &arg_end
, 0)) == 0
3199 || next_arg
[1] != NULL
))
3204 gdbserver_usage (stderr
);
3208 initialize_async_io ();
3210 initialize_event_loop ();
3211 if (target_supports_tracepoints ())
3212 initialize_tracepoint ();
3214 own_buf
= xmalloc (PBUFSIZ
+ 1);
3215 mem_buf
= xmalloc (PBUFSIZ
);
3217 if (pid
== 0 && *next_arg
!= NULL
)
3221 n
= argc
- (next_arg
- argv
);
3222 program_argv
= xmalloc (sizeof (char *) * (n
+ 1));
3223 for (i
= 0; i
< n
; i
++)
3224 program_argv
[i
] = xstrdup (next_arg
[i
]);
3225 program_argv
[i
] = NULL
;
3227 /* Wait till we are at first instruction in program. */
3228 start_inferior (program_argv
);
3230 /* We are now (hopefully) stopped at the first instruction of
3231 the target process. This assumes that the target process was
3232 successfully created. */
3236 if (attach_inferior (pid
) == -1)
3237 error ("Attaching not supported on this target");
3239 /* Otherwise succeeded. */
3243 last_status
.kind
= TARGET_WAITKIND_EXITED
;
3244 last_status
.value
.integer
= 0;
3245 last_ptid
= minus_one_ptid
;
3247 make_cleanup (detach_or_kill_for_exit_cleanup
, NULL
);
3249 initialize_notif ();
3251 /* Don't report shared library events on the initial connection,
3252 even if some libraries are preloaded. Avoids the "stopped by
3253 shared library event" notice on gdb side. */
3256 if (last_status
.kind
== TARGET_WAITKIND_EXITED
3257 || last_status
.kind
== TARGET_WAITKIND_SIGNALLED
)
3262 if (!was_running
&& !multi_mode
)
3263 error ("No program to debug");
3267 volatile struct gdb_exception exception
;
3271 /* Be sure we're out of tfind mode. */
3272 current_traceframe
= -1;
3276 TRY_CATCH (exception
, RETURN_MASK_ERROR
)
3278 /* Wait for events. This will return when all event sources
3279 are removed from the event loop. */
3280 start_event_loop ();
3282 /* If an exit was requested (using the "monitor exit"
3283 command), terminate now. The only other way to get
3284 here is for getpkt to fail; close the connection
3285 and reopen it at the top of the loop. */
3287 if (exit_requested
|| run_once
)
3288 throw_quit ("Quit");
3291 "Remote side has terminated connection. "
3292 "GDBserver will reopen the connection.\n");
3294 /* Get rid of any pending statuses. An eventual reconnection
3295 (by the same GDB instance or another) will refresh all its
3296 state from scratch. */
3297 discard_queued_stop_replies (-1);
3298 for_each_inferior (&all_threads
,
3299 clear_pending_status_callback
);
3303 if (disconnected_tracing
)
3305 /* Try to enable non-stop/async mode, so we we can
3306 both wait for an async socket accept, and handle
3307 async target events simultaneously. There's also
3308 no point either in having the target always stop
3309 all threads, when we're going to pass signals
3310 down without informing GDB. */
3313 if (start_non_stop (1))
3316 /* Detaching implicitly resumes all threads;
3317 simply disconnecting does not. */
3323 "Disconnected tracing disabled; "
3324 "stopping trace run.\n");
3330 if (exception
.reason
== RETURN_ERROR
)
3332 if (response_needed
)
3334 write_enn (own_buf
);
3341 /* Main function. */
3344 main (int argc
, char *argv
[])
3346 volatile struct gdb_exception exception
;
3348 TRY_CATCH (exception
, RETURN_MASK_ALL
)
3350 captured_main (argc
, argv
);
3353 /* captured_main should never return. */
3354 gdb_assert (exception
.reason
< 0);
3356 if (exception
.reason
== RETURN_ERROR
)
3359 fprintf (stderr
, "%s\n", exception
.message
);
3360 fprintf (stderr
, "Exiting\n");
3367 /* Skip PACKET until the next semi-colon (or end of string). */
3370 skip_to_semicolon (char **packet
)
3372 while (**packet
!= '\0' && **packet
!= ';')
3376 /* Process options coming from Z packets for a breakpoint. PACKET is
3377 the packet buffer. *PACKET is updated to point to the first char
3378 after the last processed option. */
3381 process_point_options (struct breakpoint
*bp
, char **packet
)
3383 char *dataptr
= *packet
;
3386 /* Check if data has the correct format. */
3387 if (*dataptr
!= ';')
3394 if (*dataptr
== ';')
3397 if (*dataptr
== 'X')
3399 /* Conditional expression. */
3401 debug_printf ("Found breakpoint condition.\n");
3402 if (!add_breakpoint_condition (bp
, &dataptr
))
3403 skip_to_semicolon (&dataptr
);
3405 else if (strncmp (dataptr
, "cmds:", strlen ("cmds:")) == 0)
3407 dataptr
+= strlen ("cmds:");
3409 debug_printf ("Found breakpoint commands %s.\n", dataptr
);
3410 persist
= (*dataptr
== '1');
3412 if (add_breakpoint_commands (bp
, &dataptr
, persist
))
3413 skip_to_semicolon (&dataptr
);
3417 fprintf (stderr
, "Unknown token %c, ignoring.\n",
3419 /* Skip tokens until we find one that we recognize. */
3420 skip_to_semicolon (&dataptr
);
3426 /* Event loop callback that handles a serial event. The first byte in
3427 the serial buffer gets us here. We expect characters to arrive at
3428 a brisk pace, so we read the rest of the packet with a blocking
3432 process_serial_event (void)
3443 int new_packet_len
= -1;
3445 /* Used to decide when gdbserver should exit in
3446 multi-mode/remote. */
3447 static int have_ran
= 0;
3450 have_ran
= target_running ();
3452 disable_async_io ();
3454 response_needed
= 0;
3455 packet_len
= getpkt (own_buf
);
3456 if (packet_len
<= 0)
3459 /* Force an event loop break. */
3462 response_needed
= 1;
3469 handle_query (own_buf
, packet_len
, &new_packet_len
);
3472 handle_general_set (own_buf
);
3475 require_running (own_buf
);
3480 pid
= strtol (&own_buf
[i
], NULL
, 16);
3483 pid
= ptid_get_pid (current_ptid
);
3485 if ((tracing
&& disconnected_tracing
) || any_persistent_commands ())
3487 struct thread_resume resume_info
;
3488 struct process_info
*process
= find_process_pid (pid
);
3490 if (process
== NULL
)
3492 write_enn (own_buf
);
3496 if (tracing
&& disconnected_tracing
)
3498 "Disconnected tracing in effect, "
3499 "leaving gdbserver attached to the process\n");
3501 if (any_persistent_commands ())
3503 "Persistent commands are present, "
3504 "leaving gdbserver attached to the process\n");
3506 /* Make sure we're in non-stop/async mode, so we we can both
3507 wait for an async socket accept, and handle async target
3508 events simultaneously. There's also no point either in
3509 having the target stop all threads, when we're going to
3510 pass signals down without informing GDB. */
3514 debug_printf ("Forcing non-stop mode\n");
3520 process
->gdb_detached
= 1;
3522 /* Detaching implicitly resumes all threads. */
3523 resume_info
.thread
= minus_one_ptid
;
3524 resume_info
.kind
= resume_continue
;
3525 resume_info
.sig
= 0;
3526 (*the_target
->resume
) (&resume_info
, 1);
3529 break; /* from switch/case */
3532 fprintf (stderr
, "Detaching from process %d\n", pid
);
3534 if (detach_inferior (pid
) != 0)
3535 write_enn (own_buf
);
3538 discard_queued_stop_replies (pid
);
3541 if (extended_protocol
)
3543 /* Treat this like a normal program exit. */
3544 last_status
.kind
= TARGET_WAITKIND_EXITED
;
3545 last_status
.value
.integer
= 0;
3546 last_ptid
= pid_to_ptid (pid
);
3548 current_inferior
= NULL
;
3555 /* If we are attached, then we can exit. Otherwise, we
3556 need to hang around doing nothing, until the child is
3558 join_inferior (pid
);
3564 extended_protocol
= 1;
3568 handle_status (own_buf
);
3571 if (own_buf
[1] == 'c' || own_buf
[1] == 'g' || own_buf
[1] == 's')
3573 ptid_t gdb_id
, thread_id
;
3576 require_running (own_buf
);
3578 gdb_id
= read_ptid (&own_buf
[2], NULL
);
3580 pid
= ptid_get_pid (gdb_id
);
3582 if (ptid_equal (gdb_id
, null_ptid
)
3583 || ptid_equal (gdb_id
, minus_one_ptid
))
3584 thread_id
= null_ptid
;
3586 && ptid_equal (pid_to_ptid (pid
),
3589 struct thread_info
*thread
=
3590 (struct thread_info
*) find_inferior (&all_threads
,
3595 write_enn (own_buf
);
3599 thread_id
= thread
->entry
.id
;
3603 thread_id
= gdb_id_to_thread_id (gdb_id
);
3604 if (ptid_equal (thread_id
, null_ptid
))
3606 write_enn (own_buf
);
3611 if (own_buf
[1] == 'g')
3613 if (ptid_equal (thread_id
, null_ptid
))
3615 /* GDB is telling us to choose any thread. Check if
3616 the currently selected thread is still valid. If
3617 it is not, select the first available. */
3618 struct thread_info
*thread
=
3619 (struct thread_info
*) find_inferior_id (&all_threads
,
3623 thread
= get_first_thread ();
3624 thread_id
= thread
->entry
.id
;
3628 general_thread
= thread_id
;
3629 set_desired_inferior (1);
3631 else if (own_buf
[1] == 'c')
3632 cont_thread
= thread_id
;
3638 /* Silently ignore it so that gdb can extend the protocol
3639 without compatibility headaches. */
3644 require_running (own_buf
);
3645 if (current_traceframe
>= 0)
3647 struct regcache
*regcache
3648 = new_register_cache (current_target_desc ());
3650 if (fetch_traceframe_registers (current_traceframe
,
3652 registers_to_string (regcache
, own_buf
);
3654 write_enn (own_buf
);
3655 free_register_cache (regcache
);
3659 struct regcache
*regcache
;
3661 set_desired_inferior (1);
3662 regcache
= get_thread_regcache (current_inferior
, 1);
3663 registers_to_string (regcache
, own_buf
);
3667 require_running (own_buf
);
3668 if (current_traceframe
>= 0)
3669 write_enn (own_buf
);
3672 struct regcache
*regcache
;
3674 set_desired_inferior (1);
3675 regcache
= get_thread_regcache (current_inferior
, 1);
3676 registers_from_string (regcache
, &own_buf
[1]);
3681 require_running (own_buf
);
3682 decode_m_packet (&own_buf
[1], &mem_addr
, &len
);
3683 res
= gdb_read_memory (mem_addr
, mem_buf
, len
);
3685 write_enn (own_buf
);
3687 bin2hex (mem_buf
, own_buf
, res
);
3690 require_running (own_buf
);
3691 decode_M_packet (&own_buf
[1], &mem_addr
, &len
, &mem_buf
);
3692 if (gdb_write_memory (mem_addr
, mem_buf
, len
) == 0)
3695 write_enn (own_buf
);
3698 require_running (own_buf
);
3699 if (decode_X_packet (&own_buf
[1], packet_len
- 1,
3700 &mem_addr
, &len
, &mem_buf
) < 0
3701 || gdb_write_memory (mem_addr
, mem_buf
, len
) != 0)
3702 write_enn (own_buf
);
3707 require_running (own_buf
);
3708 hex2bin (own_buf
+ 1, &sig
, 1);
3709 if (gdb_signal_to_host_p (sig
))
3710 signal
= gdb_signal_to_host (sig
);
3713 myresume (own_buf
, 0, signal
);
3716 require_running (own_buf
);
3717 hex2bin (own_buf
+ 1, &sig
, 1);
3718 if (gdb_signal_to_host_p (sig
))
3719 signal
= gdb_signal_to_host (sig
);
3722 myresume (own_buf
, 1, signal
);
3725 require_running (own_buf
);
3727 myresume (own_buf
, 0, signal
);
3730 require_running (own_buf
);
3732 myresume (own_buf
, 1, signal
);
3734 case 'Z': /* insert_ ... */
3736 case 'z': /* remove_ ... */
3741 char type
= own_buf
[1];
3743 const int insert
= ch
== 'Z';
3744 char *p
= &own_buf
[3];
3746 p
= unpack_varlen_hex (p
, &addr
);
3747 len
= strtol (p
+ 1, &dataptr
, 16);
3751 struct breakpoint
*bp
;
3753 bp
= set_gdb_breakpoint (type
, addr
, len
, &res
);
3758 /* GDB may have sent us a list of *point parameters to
3759 be evaluated on the target's side. Read such list
3760 here. If we already have a list of parameters, GDB
3761 is telling us to drop that list and use this one
3763 clear_breakpoint_conditions_and_commands (bp
);
3764 process_point_options (bp
, &dataptr
);
3768 res
= delete_gdb_breakpoint (type
, addr
, len
);
3776 write_enn (own_buf
);
3780 response_needed
= 0;
3781 if (!target_running ())
3782 /* The packet we received doesn't make sense - but we can't
3783 reply to it, either. */
3786 fprintf (stderr
, "Killing all inferiors\n");
3787 for_each_inferior (&all_processes
, kill_inferior_callback
);
3789 /* When using the extended protocol, we wait with no program
3790 running. The traditional protocol will exit instead. */
3791 if (extended_protocol
)
3793 last_status
.kind
= TARGET_WAITKIND_EXITED
;
3794 last_status
.value
.sig
= GDB_SIGNAL_KILL
;
3802 ptid_t gdb_id
, thread_id
;
3804 require_running (own_buf
);
3806 gdb_id
= read_ptid (&own_buf
[1], NULL
);
3807 thread_id
= gdb_id_to_thread_id (gdb_id
);
3808 if (ptid_equal (thread_id
, null_ptid
))
3810 write_enn (own_buf
);
3814 if (mythread_alive (thread_id
))
3817 write_enn (own_buf
);
3821 response_needed
= 0;
3823 /* Restarting the inferior is only supported in the extended
3825 if (extended_protocol
)
3827 if (target_running ())
3828 for_each_inferior (&all_processes
,
3829 kill_inferior_callback
);
3830 fprintf (stderr
, "GDBserver restarting\n");
3832 /* Wait till we are at 1st instruction in prog. */
3833 if (program_argv
!= NULL
)
3834 start_inferior (program_argv
);
3837 last_status
.kind
= TARGET_WAITKIND_EXITED
;
3838 last_status
.value
.sig
= GDB_SIGNAL_KILL
;
3844 /* It is a request we don't understand. Respond with an
3845 empty packet so that gdb knows that we don't support this
3851 /* Extended (long) request. */
3852 handle_v_requests (own_buf
, packet_len
, &new_packet_len
);
3856 /* It is a request we don't understand. Respond with an empty
3857 packet so that gdb knows that we don't support this
3863 if (new_packet_len
!= -1)
3864 putpkt_binary (own_buf
, new_packet_len
);
3868 response_needed
= 0;
3870 if (!extended_protocol
&& have_ran
&& !target_running ())
3872 /* In non-stop, defer exiting until GDB had a chance to query
3873 the whole vStopped list (until it gets an OK). */
3874 if (QUEUE_is_empty (notif_event_p
, notif_stop
.queue
))
3876 /* Be transparent when GDB is connected through stdio -- no
3877 need to spam GDB's console. */
3878 if (!remote_connection_is_stdio ())
3879 fprintf (stderr
, "GDBserver exiting\n");
3891 /* Event-loop callback for serial events. */
3894 handle_serial_event (int err
, gdb_client_data client_data
)
3897 debug_printf ("handling possible serial event\n");
3899 /* Really handle it. */
3900 if (process_serial_event () < 0)
3903 /* Be sure to not change the selected inferior behind GDB's back.
3904 Important in the non-stop mode asynchronous protocol. */
3905 set_desired_inferior (1);
3910 /* Event-loop callback for target events. */
3913 handle_target_event (int err
, gdb_client_data client_data
)
3916 debug_printf ("handling possible target event\n");
3918 last_ptid
= mywait (minus_one_ptid
, &last_status
,
3921 if (last_status
.kind
== TARGET_WAITKIND_NO_RESUMED
)
3923 /* No RSP support for this yet. */
3925 else if (last_status
.kind
!= TARGET_WAITKIND_IGNORE
)
3927 int pid
= ptid_get_pid (last_ptid
);
3928 struct process_info
*process
= find_process_pid (pid
);
3929 int forward_event
= !gdb_connected () || process
->gdb_detached
;
3931 if (last_status
.kind
== TARGET_WAITKIND_EXITED
3932 || last_status
.kind
== TARGET_WAITKIND_SIGNALLED
)
3934 mark_breakpoints_out (process
);
3935 mourn_inferior (process
);
3939 /* We're reporting this thread as stopped. Update its
3940 "want-stopped" state to what the client wants, until it
3941 gets a new resume action. */
3942 current_inferior
->last_resume_kind
= resume_stop
;
3943 current_inferior
->last_status
= last_status
;
3948 if (!target_running ())
3950 /* The last process exited. We're done. */
3954 if (last_status
.kind
== TARGET_WAITKIND_STOPPED
)
3956 /* A thread stopped with a signal, but gdb isn't
3957 connected to handle it. Pass it down to the
3958 inferior, as if it wasn't being traced. */
3959 struct thread_resume resume_info
;
3962 debug_printf ("GDB not connected; forwarding event %d for"
3964 (int) last_status
.kind
,
3965 target_pid_to_str (last_ptid
));
3967 resume_info
.thread
= last_ptid
;
3968 resume_info
.kind
= resume_continue
;
3969 resume_info
.sig
= gdb_signal_to_host (last_status
.value
.sig
);
3970 (*the_target
->resume
) (&resume_info
, 1);
3972 else if (debug_threads
)
3973 debug_printf ("GDB not connected; ignoring event %d for [%s]\n",
3974 (int) last_status
.kind
,
3975 target_pid_to_str (last_ptid
));
3979 struct vstop_notif
*vstop_notif
3980 = xmalloc (sizeof (struct vstop_notif
));
3982 vstop_notif
->status
= last_status
;
3983 vstop_notif
->ptid
= last_ptid
;
3984 /* Push Stop notification. */
3985 notif_push (¬if_stop
,
3986 (struct notif_event
*) vstop_notif
);
3990 /* Be sure to not change the selected inferior behind GDB's back.
3991 Important in the non-stop mode asynchronous protocol. */
3992 set_desired_inferior (1);