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 int pass_signals
[GDB_SIGNAL_LAST
];
73 int program_signals
[GDB_SIGNAL_LAST
];
74 int program_signals_p
;
76 /* The PID of the originally created or attached inferior. Used to
77 send signals to the process when GDB sends us an asynchronous interrupt
78 (user hitting Control-C in the client), and to wait for the child to exit
79 when no longer debugging it. */
81 unsigned long signal_pid
;
84 /* A file descriptor for the controlling terminal. */
87 /* TERMINAL_FD's original foreground group. */
88 pid_t old_foreground_pgrp
;
90 /* Hand back terminal ownership to the original foreground group. */
93 restore_old_foreground_pgrp (void)
95 tcsetpgrp (terminal_fd
, old_foreground_pgrp
);
99 /* Set if you want to disable optional thread related packets support
100 in gdbserver, for the sake of testing GDB against stubs that don't
102 int disable_packet_vCont
;
103 int disable_packet_Tthread
;
104 int disable_packet_qC
;
105 int disable_packet_qfThreadInfo
;
107 /* Last status reported to GDB. */
108 static struct target_waitstatus last_status
;
109 static ptid_t last_ptid
;
111 static char *own_buf
;
112 static unsigned char *mem_buf
;
114 /* A sub-class of 'struct notif_event' for stop, holding information
115 relative to a single stop reply. We keep a queue of these to
116 push to GDB in non-stop mode. */
120 struct notif_event base
;
122 /* Thread or process that got the event. */
126 struct target_waitstatus status
;
129 DEFINE_QUEUE_P (notif_event_p
);
131 /* Put a stop reply to the stop reply queue. */
134 queue_stop_reply (ptid_t ptid
, struct target_waitstatus
*status
)
136 struct vstop_notif
*new_notif
= xmalloc (sizeof (*new_notif
));
138 new_notif
->ptid
= ptid
;
139 new_notif
->status
= *status
;
141 notif_event_enque (¬if_stop
, (struct notif_event
*) new_notif
);
145 remove_all_on_match_pid (QUEUE (notif_event_p
) *q
,
146 QUEUE_ITER (notif_event_p
) *iter
,
147 struct notif_event
*event
,
153 || ptid_get_pid (((struct vstop_notif
*) event
)->ptid
) == *pid
)
155 if (q
->free_func
!= NULL
)
156 q
->free_func (event
);
158 QUEUE_remove_elem (notif_event_p
, q
, iter
);
164 /* Get rid of the currently pending stop replies for PID. If PID is
165 -1, then apply to all processes. */
168 discard_queued_stop_replies (int pid
)
170 QUEUE_iterate (notif_event_p
, notif_stop
.queue
,
171 remove_all_on_match_pid
, &pid
);
175 vstop_notif_reply (struct notif_event
*event
, char *own_buf
)
177 struct vstop_notif
*vstop
= (struct vstop_notif
*) event
;
179 prepare_resume_reply (own_buf
, vstop
->ptid
, &vstop
->status
);
182 struct notif_server notif_stop
=
184 "vStopped", "Stop", NULL
, vstop_notif_reply
,
188 target_running (void)
190 return get_first_thread () != NULL
;
194 start_inferior (char **argv
)
196 char **new_argv
= argv
;
198 if (wrapper_argv
!= NULL
)
202 for (i
= 0; wrapper_argv
[i
] != NULL
; i
++)
204 for (i
= 0; argv
[i
] != NULL
; i
++)
206 new_argv
= alloca (sizeof (char *) * count
);
208 for (i
= 0; wrapper_argv
[i
] != NULL
; i
++)
209 new_argv
[count
++] = wrapper_argv
[i
];
210 for (i
= 0; argv
[i
] != NULL
; i
++)
211 new_argv
[count
++] = argv
[i
];
212 new_argv
[count
] = NULL
;
218 for (i
= 0; new_argv
[i
]; ++i
)
219 debug_printf ("new_argv[%d] = \"%s\"\n", i
, new_argv
[i
]);
224 signal (SIGTTOU
, SIG_DFL
);
225 signal (SIGTTIN
, SIG_DFL
);
228 /* Clear this so the backend doesn't get confused, thinking
229 CONT_THREAD died, and it needs to resume all threads. */
230 cont_thread
= null_ptid
;
232 signal_pid
= create_inferior (new_argv
[0], new_argv
);
234 /* FIXME: we don't actually know at this point that the create
235 actually succeeded. We won't know that until we wait. */
236 fprintf (stderr
, "Process %s created; pid = %ld\n", argv
[0],
241 signal (SIGTTOU
, SIG_IGN
);
242 signal (SIGTTIN
, SIG_IGN
);
243 terminal_fd
= fileno (stderr
);
244 old_foreground_pgrp
= tcgetpgrp (terminal_fd
);
245 tcsetpgrp (terminal_fd
, signal_pid
);
246 atexit (restore_old_foreground_pgrp
);
249 if (wrapper_argv
!= NULL
)
251 struct thread_resume resume_info
;
253 memset (&resume_info
, 0, sizeof (resume_info
));
254 resume_info
.thread
= pid_to_ptid (signal_pid
);
255 resume_info
.kind
= resume_continue
;
258 last_ptid
= mywait (pid_to_ptid (signal_pid
), &last_status
, 0, 0);
260 if (last_status
.kind
!= TARGET_WAITKIND_STOPPED
)
265 (*the_target
->resume
) (&resume_info
, 1);
267 last_ptid
= mywait (pid_to_ptid (signal_pid
), &last_status
, 0, 0);
268 if (last_status
.kind
!= TARGET_WAITKIND_STOPPED
)
271 current_inferior
->last_resume_kind
= resume_stop
;
272 current_inferior
->last_status
= last_status
;
274 while (last_status
.value
.sig
!= GDB_SIGNAL_TRAP
);
279 /* Wait till we are at 1st instruction in program, return new pid
280 (assuming success). */
281 last_ptid
= mywait (pid_to_ptid (signal_pid
), &last_status
, 0, 0);
283 if (last_status
.kind
!= TARGET_WAITKIND_EXITED
284 && last_status
.kind
!= TARGET_WAITKIND_SIGNALLED
)
286 current_inferior
->last_resume_kind
= resume_stop
;
287 current_inferior
->last_status
= last_status
;
294 attach_inferior (int pid
)
296 /* myattach should return -1 if attaching is unsupported,
297 0 if it succeeded, and call error() otherwise. */
299 if (myattach (pid
) != 0)
302 fprintf (stderr
, "Attached; pid = %d\n", pid
);
305 /* FIXME - It may be that we should get the SIGNAL_PID from the
306 attach function, so that it can be the main thread instead of
307 whichever we were told to attach to. */
310 /* Clear this so the backend doesn't get confused, thinking
311 CONT_THREAD died, and it needs to resume all threads. */
312 cont_thread
= null_ptid
;
316 last_ptid
= mywait (pid_to_ptid (pid
), &last_status
, 0, 0);
318 /* GDB knows to ignore the first SIGSTOP after attaching to a running
319 process using the "attach" command, but this is different; it's
320 just using "target remote". Pretend it's just starting up. */
321 if (last_status
.kind
== TARGET_WAITKIND_STOPPED
322 && last_status
.value
.sig
== GDB_SIGNAL_STOP
)
323 last_status
.value
.sig
= GDB_SIGNAL_TRAP
;
325 current_inferior
->last_resume_kind
= resume_stop
;
326 current_inferior
->last_status
= last_status
;
332 extern int remote_debug
;
334 /* Decode a qXfer read request. Return 0 if everything looks OK,
338 decode_xfer_read (char *buf
, CORE_ADDR
*ofs
, unsigned int *len
)
340 /* After the read marker and annex, qXfer looks like a
341 traditional 'm' packet. */
342 decode_m_packet (buf
, ofs
, len
);
348 decode_xfer (char *buf
, char **object
, char **rw
, char **annex
, char **offset
)
350 /* Extract and NUL-terminate the object. */
352 while (*buf
&& *buf
!= ':')
358 /* Extract and NUL-terminate the read/write action. */
360 while (*buf
&& *buf
!= ':')
366 /* Extract and NUL-terminate the annex. */
368 while (*buf
&& *buf
!= ':')
378 /* Write the response to a successful qXfer read. Returns the
379 length of the (binary) data stored in BUF, corresponding
380 to as much of DATA/LEN as we could fit. IS_MORE controls
381 the first character of the response. */
383 write_qxfer_response (char *buf
, const void *data
, int len
, int is_more
)
392 return remote_escape_output (data
, len
, (unsigned char *) buf
+ 1, &out_len
,
396 /* Handle btrace enabling. */
399 handle_btrace_enable (struct thread_info
*thread
)
401 if (thread
->btrace
!= NULL
)
402 return "E.Btrace already enabled.";
404 thread
->btrace
= target_enable_btrace (thread
->entry
.id
);
405 if (thread
->btrace
== NULL
)
406 return "E.Could not enable btrace.";
411 /* Handle btrace disabling. */
414 handle_btrace_disable (struct thread_info
*thread
)
417 if (thread
->btrace
== NULL
)
418 return "E.Branch tracing not enabled.";
420 if (target_disable_btrace (thread
->btrace
) != 0)
421 return "E.Could not disable branch tracing.";
423 thread
->btrace
= NULL
;
427 /* Handle the "Qbtrace" packet. */
430 handle_btrace_general_set (char *own_buf
)
432 struct thread_info
*thread
;
436 if (strncmp ("Qbtrace:", own_buf
, strlen ("Qbtrace:")) != 0)
439 op
= own_buf
+ strlen ("Qbtrace:");
441 if (!target_supports_btrace ())
443 strcpy (own_buf
, "E.Target does not support branch tracing.");
447 if (ptid_equal (general_thread
, null_ptid
)
448 || ptid_equal (general_thread
, minus_one_ptid
))
450 strcpy (own_buf
, "E.Must select a single thread.");
454 thread
= find_thread_ptid (general_thread
);
457 strcpy (own_buf
, "E.No such thread.");
463 if (strcmp (op
, "bts") == 0)
464 err
= handle_btrace_enable (thread
);
465 else if (strcmp (op
, "off") == 0)
466 err
= handle_btrace_disable (thread
);
468 err
= "E.Bad Qbtrace operation. Use bts or off.";
471 strcpy (own_buf
, err
);
478 /* Handle all of the extended 'Q' packets. */
481 handle_general_set (char *own_buf
)
483 if (strncmp ("QPassSignals:", own_buf
, strlen ("QPassSignals:")) == 0)
485 int numsigs
= (int) GDB_SIGNAL_LAST
, i
;
486 const char *p
= own_buf
+ strlen ("QPassSignals:");
489 p
= decode_address_to_semicolon (&cursig
, p
);
490 for (i
= 0; i
< numsigs
; i
++)
496 /* Keep looping, to clear the remaining signals. */
499 p
= decode_address_to_semicolon (&cursig
, p
);
504 strcpy (own_buf
, "OK");
508 if (strncmp ("QProgramSignals:", own_buf
, strlen ("QProgramSignals:")) == 0)
510 int numsigs
= (int) GDB_SIGNAL_LAST
, i
;
511 const char *p
= own_buf
+ strlen ("QProgramSignals:");
514 program_signals_p
= 1;
516 p
= decode_address_to_semicolon (&cursig
, p
);
517 for (i
= 0; i
< numsigs
; i
++)
521 program_signals
[i
] = 1;
523 /* Keep looping, to clear the remaining signals. */
526 p
= decode_address_to_semicolon (&cursig
, p
);
529 program_signals
[i
] = 0;
531 strcpy (own_buf
, "OK");
535 if (strcmp (own_buf
, "QStartNoAckMode") == 0)
539 fprintf (stderr
, "[noack mode enabled]\n");
548 if (strncmp (own_buf
, "QNonStop:", 9) == 0)
550 char *mode
= own_buf
+ 9;
554 if (strcmp (mode
, "0") == 0)
556 else if (strcmp (mode
, "1") == 0)
560 /* We don't know what this mode is, so complain to
562 fprintf (stderr
, "Unknown non-stop mode requested: %s\n",
568 req_str
= req
? "non-stop" : "all-stop";
569 if (start_non_stop (req
) != 0)
571 fprintf (stderr
, "Setting %s mode failed\n", req_str
);
579 fprintf (stderr
, "[%s mode enabled]\n", req_str
);
585 if (strncmp ("QDisableRandomization:", own_buf
,
586 strlen ("QDisableRandomization:")) == 0)
588 char *packet
= own_buf
+ strlen ("QDisableRandomization:");
591 unpack_varlen_hex (packet
, &setting
);
592 disable_randomization
= setting
;
596 if (disable_randomization
)
597 fprintf (stderr
, "[address space randomization disabled]\n");
599 fprintf (stderr
, "[address space randomization enabled]\n");
606 if (target_supports_tracepoints ()
607 && handle_tracepoint_general_set (own_buf
))
610 if (strncmp ("QAgent:", own_buf
, strlen ("QAgent:")) == 0)
612 char *mode
= own_buf
+ strlen ("QAgent:");
615 if (strcmp (mode
, "0") == 0)
617 else if (strcmp (mode
, "1") == 0)
621 /* We don't know what this value is, so complain to GDB. */
622 sprintf (own_buf
, "E.Unknown QAgent value");
626 /* Update the flag. */
629 fprintf (stderr
, "[%s agent]\n", req
? "Enable" : "Disable");
634 if (handle_btrace_general_set (own_buf
))
637 /* Otherwise we didn't know what packet it was. Say we didn't
643 get_features_xml (const char *annex
)
645 const struct target_desc
*desc
= current_target_desc ();
647 /* `desc->xmltarget' defines what to return when looking for the
648 "target.xml" file. Its contents can either be verbatim XML code
649 (prefixed with a '@') or else the name of the actual XML file to
650 be used in place of "target.xml".
652 This variable is set up from the auto-generated
653 init_registers_... routine for the current target. */
655 if (desc
->xmltarget
!= NULL
&& strcmp (annex
, "target.xml") == 0)
657 if (*desc
->xmltarget
== '@')
658 return desc
->xmltarget
+ 1;
660 annex
= desc
->xmltarget
;
665 extern const char *const xml_builtin
[][2];
668 /* Look for the annex. */
669 for (i
= 0; xml_builtin
[i
][0] != NULL
; i
++)
670 if (strcmp (annex
, xml_builtin
[i
][0]) == 0)
673 if (xml_builtin
[i
][0] != NULL
)
674 return xml_builtin
[i
][1];
682 monitor_show_help (void)
684 monitor_output ("The following monitor commands are supported:\n");
685 monitor_output (" set debug <0|1>\n");
686 monitor_output (" Enable general debugging messages\n");
687 monitor_output (" set debug-hw-points <0|1>\n");
688 monitor_output (" Enable h/w breakpoint/watchpoint debugging messages\n");
689 monitor_output (" set remote-debug <0|1>\n");
690 monitor_output (" Enable remote protocol debugging messages\n");
691 monitor_output (" set debug-format option1[,option2,...]\n");
692 monitor_output (" Add additional information to debugging messages\n");
693 monitor_output (" Options: all, none");
694 monitor_output (", timestamp");
695 monitor_output ("\n");
696 monitor_output (" exit\n");
697 monitor_output (" Quit GDBserver\n");
700 /* Read trace frame or inferior memory. Returns the number of bytes
701 actually read, zero when no further transfer is possible, and -1 on
702 error. Return of a positive value smaller than LEN does not
703 indicate there's no more to be read, only the end of the transfer.
704 E.g., when GDB reads memory from a traceframe, a first request may
705 be served from a memory block that does not cover the whole request
706 length. A following request gets the rest served from either
707 another block (of the same traceframe) or from the read-only
711 gdb_read_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
715 if (current_traceframe
>= 0)
718 ULONGEST length
= len
;
720 if (traceframe_read_mem (current_traceframe
,
721 memaddr
, myaddr
, len
, &nbytes
))
723 /* Data read from trace buffer, we're done. */
726 if (!in_readonly_region (memaddr
, length
))
728 /* Otherwise we have a valid readonly case, fall through. */
729 /* (assume no half-trace half-real blocks for now) */
732 res
= prepare_to_access_memory ();
735 res
= read_inferior_memory (memaddr
, myaddr
, len
);
736 done_accessing_memory ();
738 return res
== 0 ? len
: -1;
744 /* Write trace frame or inferior memory. Actually, writing to trace
745 frames is forbidden. */
748 gdb_write_memory (CORE_ADDR memaddr
, const unsigned char *myaddr
, int len
)
750 if (current_traceframe
>= 0)
756 ret
= prepare_to_access_memory ();
759 ret
= write_inferior_memory (memaddr
, myaddr
, len
);
760 done_accessing_memory ();
766 /* Subroutine of handle_search_memory to simplify it. */
769 handle_search_memory_1 (CORE_ADDR start_addr
, CORE_ADDR search_space_len
,
770 gdb_byte
*pattern
, unsigned pattern_len
,
771 gdb_byte
*search_buf
,
772 unsigned chunk_size
, unsigned search_buf_size
,
773 CORE_ADDR
*found_addrp
)
775 /* Prime the search buffer. */
777 if (gdb_read_memory (start_addr
, search_buf
, search_buf_size
)
780 warning ("Unable to access %ld bytes of target "
781 "memory at 0x%lx, halting search.",
782 (long) search_buf_size
, (long) start_addr
);
786 /* Perform the search.
788 The loop is kept simple by allocating [N + pattern-length - 1] bytes.
789 When we've scanned N bytes we copy the trailing bytes to the start and
790 read in another N bytes. */
792 while (search_space_len
>= pattern_len
)
795 unsigned nr_search_bytes
= (search_space_len
< search_buf_size
799 found_ptr
= memmem (search_buf
, nr_search_bytes
, pattern
, pattern_len
);
801 if (found_ptr
!= NULL
)
803 CORE_ADDR found_addr
= start_addr
+ (found_ptr
- search_buf
);
804 *found_addrp
= found_addr
;
808 /* Not found in this chunk, skip to next chunk. */
810 /* Don't let search_space_len wrap here, it's unsigned. */
811 if (search_space_len
>= chunk_size
)
812 search_space_len
-= chunk_size
;
814 search_space_len
= 0;
816 if (search_space_len
>= pattern_len
)
818 unsigned keep_len
= search_buf_size
- chunk_size
;
819 CORE_ADDR read_addr
= start_addr
+ chunk_size
+ keep_len
;
822 /* Copy the trailing part of the previous iteration to the front
823 of the buffer for the next iteration. */
824 memcpy (search_buf
, search_buf
+ chunk_size
, keep_len
);
826 nr_to_read
= (search_space_len
- keep_len
< chunk_size
827 ? search_space_len
- keep_len
830 if (gdb_read_memory (read_addr
, search_buf
+ keep_len
,
831 nr_to_read
) != search_buf_size
)
833 warning ("Unable to access %ld bytes of target memory "
834 "at 0x%lx, halting search.",
835 (long) nr_to_read
, (long) read_addr
);
839 start_addr
+= chunk_size
;
848 /* Handle qSearch:memory packets. */
851 handle_search_memory (char *own_buf
, int packet_len
)
853 CORE_ADDR start_addr
;
854 CORE_ADDR search_space_len
;
856 unsigned int pattern_len
;
857 /* NOTE: also defined in find.c testcase. */
858 #define SEARCH_CHUNK_SIZE 16000
859 const unsigned chunk_size
= SEARCH_CHUNK_SIZE
;
860 /* Buffer to hold memory contents for searching. */
861 gdb_byte
*search_buf
;
862 unsigned search_buf_size
;
864 CORE_ADDR found_addr
;
865 int cmd_name_len
= sizeof ("qSearch:memory:") - 1;
867 pattern
= malloc (packet_len
);
870 error ("Unable to allocate memory to perform the search");
871 strcpy (own_buf
, "E00");
874 if (decode_search_memory_packet (own_buf
+ cmd_name_len
,
875 packet_len
- cmd_name_len
,
876 &start_addr
, &search_space_len
,
877 pattern
, &pattern_len
) < 0)
880 error ("Error in parsing qSearch:memory packet");
881 strcpy (own_buf
, "E00");
885 search_buf_size
= chunk_size
+ pattern_len
- 1;
887 /* No point in trying to allocate a buffer larger than the search space. */
888 if (search_space_len
< search_buf_size
)
889 search_buf_size
= search_space_len
;
891 search_buf
= malloc (search_buf_size
);
892 if (search_buf
== NULL
)
895 error ("Unable to allocate memory to perform the search");
896 strcpy (own_buf
, "E00");
900 found
= handle_search_memory_1 (start_addr
, search_space_len
,
901 pattern
, pattern_len
,
902 search_buf
, chunk_size
, search_buf_size
,
906 sprintf (own_buf
, "1,%lx", (long) found_addr
);
908 strcpy (own_buf
, "0");
910 strcpy (own_buf
, "E00");
916 #define require_running(BUF) \
917 if (!target_running ()) \
923 /* Parse options to --debug-format= and "monitor set debug-format".
924 ARG is the text after "--debug-format=" or "monitor set debug-format".
925 IS_MONITOR is non-zero if we're invoked via "monitor set debug-format".
926 This triggers calls to monitor_output.
927 The result is NULL if all options were parsed ok, otherwise an error
928 message which the caller must free.
930 N.B. These commands affect all debug format settings, they are not
931 cumulative. If a format is not specified, it is turned off.
932 However, we don't go to extra trouble with things like
933 "monitor set debug-format all,none,timestamp".
934 Instead we just parse them one at a time, in order.
936 The syntax for "monitor set debug" we support here is not identical
937 to gdb's "set debug foo on|off" because we also use this function to
938 parse "--debug-format=foo,bar". */
941 parse_debug_format_options (const char *arg
, int is_monitor
)
943 VEC (char_ptr
) *options
;
947 /* First turn all debug format options off. */
950 /* First remove leading spaces, for "monitor set debug-format". */
951 while (isspace (*arg
))
954 options
= delim_string_to_char_ptr_vec (arg
, ',');
956 for (ix
= 0; VEC_iterate (char_ptr
, options
, ix
, option
); ++ix
)
958 if (strcmp (option
, "all") == 0)
962 monitor_output ("All extra debug format options enabled.\n");
964 else if (strcmp (option
, "none") == 0)
968 monitor_output ("All extra debug format options disabled.\n");
970 else if (strcmp (option
, "timestamp") == 0)
974 monitor_output ("Timestamps will be added to debug output.\n");
976 else if (*option
== '\0')
978 /* An empty option, e.g., "--debug-format=foo,,bar", is ignored. */
983 char *msg
= xstrprintf ("Unknown debug-format argument: \"%s\"\n",
986 free_char_ptr_vec (options
);
991 free_char_ptr_vec (options
);
995 /* Handle monitor commands not handled by target-specific handlers. */
998 handle_monitor_command (char *mon
, char *own_buf
)
1000 if (strcmp (mon
, "set debug 1") == 0)
1003 monitor_output ("Debug output enabled.\n");
1005 else if (strcmp (mon
, "set debug 0") == 0)
1008 monitor_output ("Debug output disabled.\n");
1010 else if (strcmp (mon
, "set debug-hw-points 1") == 0)
1012 show_debug_regs
= 1;
1013 monitor_output ("H/W point debugging output enabled.\n");
1015 else if (strcmp (mon
, "set debug-hw-points 0") == 0)
1017 show_debug_regs
= 0;
1018 monitor_output ("H/W point debugging output disabled.\n");
1020 else if (strcmp (mon
, "set remote-debug 1") == 0)
1023 monitor_output ("Protocol debug output enabled.\n");
1025 else if (strcmp (mon
, "set remote-debug 0") == 0)
1028 monitor_output ("Protocol debug output disabled.\n");
1030 else if (strncmp (mon
, "set debug-format ",
1031 sizeof ("set debug-format ") - 1) == 0)
1034 = parse_debug_format_options (mon
+ sizeof ("set debug-format ") - 1,
1037 if (error_msg
!= NULL
)
1039 monitor_output (error_msg
);
1040 monitor_show_help ();
1041 write_enn (own_buf
);
1045 else if (strcmp (mon
, "help") == 0)
1046 monitor_show_help ();
1047 else if (strcmp (mon
, "exit") == 0)
1051 monitor_output ("Unknown monitor command.\n\n");
1052 monitor_show_help ();
1053 write_enn (own_buf
);
1057 /* Associates a callback with each supported qXfer'able object. */
1061 /* The object this handler handles. */
1064 /* Request that the target transfer up to LEN 8-bit bytes of the
1065 target's OBJECT. The OFFSET, for a seekable object, specifies
1066 the starting point. The ANNEX can be used to provide additional
1067 data-specific information to the target.
1069 Return the number of bytes actually transfered, zero when no
1070 further transfer is possible, -1 on error, -2 when the transfer
1071 is not supported, and -3 on a verbose error message that should
1072 be preserved. Return of a positive value smaller than LEN does
1073 not indicate the end of the object, only the end of the transfer.
1075 One, and only one, of readbuf or writebuf must be non-NULL. */
1076 int (*xfer
) (const char *annex
,
1077 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1078 ULONGEST offset
, LONGEST len
);
1081 /* Handle qXfer:auxv:read. */
1084 handle_qxfer_auxv (const char *annex
,
1085 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1086 ULONGEST offset
, LONGEST len
)
1088 if (the_target
->read_auxv
== NULL
|| writebuf
!= NULL
)
1091 if (annex
[0] != '\0' || !target_running ())
1094 return (*the_target
->read_auxv
) (offset
, readbuf
, len
);
1097 /* Handle qXfer:features:read. */
1100 handle_qxfer_features (const char *annex
,
1101 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1102 ULONGEST offset
, LONGEST len
)
1104 const char *document
;
1107 if (writebuf
!= NULL
)
1110 if (!target_running ())
1113 /* Grab the correct annex. */
1114 document
= get_features_xml (annex
);
1115 if (document
== NULL
)
1118 total_len
= strlen (document
);
1120 if (offset
> total_len
)
1123 if (offset
+ len
> total_len
)
1124 len
= total_len
- offset
;
1126 memcpy (readbuf
, document
+ offset
, len
);
1130 /* Worker routine for handle_qxfer_libraries.
1131 Add to the length pointed to by ARG a conservative estimate of the
1132 length needed to transmit the file name of INF. */
1135 accumulate_file_name_length (struct inferior_list_entry
*inf
, void *arg
)
1137 struct dll_info
*dll
= (struct dll_info
*) inf
;
1138 unsigned int *total_len
= arg
;
1140 /* Over-estimate the necessary memory. Assume that every character
1141 in the library name must be escaped. */
1142 *total_len
+= 128 + 6 * strlen (dll
->name
);
1145 /* Worker routine for handle_qxfer_libraries.
1146 Emit the XML to describe the library in INF. */
1149 emit_dll_description (struct inferior_list_entry
*inf
, void *arg
)
1151 struct dll_info
*dll
= (struct dll_info
*) inf
;
1156 strcpy (p
, " <library name=\"");
1158 name
= xml_escape_text (dll
->name
);
1162 strcpy (p
, "\"><segment address=\"");
1164 sprintf (p
, "0x%lx", (long) dll
->base_addr
);
1166 strcpy (p
, "\"/></library>\n");
1172 /* Handle qXfer:libraries:read. */
1175 handle_qxfer_libraries (const char *annex
,
1176 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1177 ULONGEST offset
, LONGEST len
)
1179 unsigned int total_len
;
1182 if (writebuf
!= NULL
)
1185 if (annex
[0] != '\0' || !target_running ())
1189 for_each_inferior_with_data (&all_dlls
, accumulate_file_name_length
,
1192 document
= malloc (total_len
);
1193 if (document
== NULL
)
1196 strcpy (document
, "<library-list>\n");
1197 p
= document
+ strlen (document
);
1199 for_each_inferior_with_data (&all_dlls
, emit_dll_description
, &p
);
1201 strcpy (p
, "</library-list>\n");
1203 total_len
= strlen (document
);
1205 if (offset
> total_len
)
1211 if (offset
+ len
> total_len
)
1212 len
= total_len
- offset
;
1214 memcpy (readbuf
, document
+ offset
, len
);
1219 /* Handle qXfer:libraries-svr4:read. */
1222 handle_qxfer_libraries_svr4 (const char *annex
,
1223 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1224 ULONGEST offset
, LONGEST len
)
1226 if (writebuf
!= NULL
)
1229 if (!target_running () || the_target
->qxfer_libraries_svr4
== NULL
)
1232 return the_target
->qxfer_libraries_svr4 (annex
, readbuf
, writebuf
, offset
, len
);
1235 /* Handle qXfer:osadata:read. */
1238 handle_qxfer_osdata (const char *annex
,
1239 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1240 ULONGEST offset
, LONGEST len
)
1242 if (the_target
->qxfer_osdata
== NULL
|| writebuf
!= NULL
)
1245 return (*the_target
->qxfer_osdata
) (annex
, readbuf
, NULL
, offset
, len
);
1248 /* Handle qXfer:siginfo:read and qXfer:siginfo:write. */
1251 handle_qxfer_siginfo (const char *annex
,
1252 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1253 ULONGEST offset
, LONGEST len
)
1255 if (the_target
->qxfer_siginfo
== NULL
)
1258 if (annex
[0] != '\0' || !target_running ())
1261 return (*the_target
->qxfer_siginfo
) (annex
, readbuf
, writebuf
, offset
, len
);
1264 /* Handle qXfer:spu:read and qXfer:spu:write. */
1267 handle_qxfer_spu (const char *annex
,
1268 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1269 ULONGEST offset
, LONGEST len
)
1271 if (the_target
->qxfer_spu
== NULL
)
1274 if (!target_running ())
1277 return (*the_target
->qxfer_spu
) (annex
, readbuf
, writebuf
, offset
, len
);
1280 /* Handle qXfer:statictrace:read. */
1283 handle_qxfer_statictrace (const char *annex
,
1284 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1285 ULONGEST offset
, LONGEST len
)
1289 if (writebuf
!= NULL
)
1292 if (annex
[0] != '\0' || !target_running () || current_traceframe
== -1)
1295 if (traceframe_read_sdata (current_traceframe
, offset
,
1296 readbuf
, len
, &nbytes
))
1301 /* Helper for handle_qxfer_threads_proper.
1302 Emit the XML to describe the thread of INF. */
1305 handle_qxfer_threads_worker (struct inferior_list_entry
*inf
, void *arg
)
1307 struct thread_info
*thread
= (struct thread_info
*) inf
;
1308 struct buffer
*buffer
= arg
;
1309 ptid_t ptid
= thread_to_gdb_id (thread
);
1311 int core
= target_core_of_thread (ptid
);
1314 write_ptid (ptid_s
, ptid
);
1318 sprintf (core_s
, "%d", core
);
1319 buffer_xml_printf (buffer
, "<thread id=\"%s\" core=\"%s\"/>\n",
1324 buffer_xml_printf (buffer
, "<thread id=\"%s\"/>\n",
1329 /* Helper for handle_qxfer_threads. */
1332 handle_qxfer_threads_proper (struct buffer
*buffer
)
1334 buffer_grow_str (buffer
, "<threads>\n");
1336 for_each_inferior_with_data (&all_threads
, handle_qxfer_threads_worker
,
1339 buffer_grow_str0 (buffer
, "</threads>\n");
1342 /* Handle qXfer:threads:read. */
1345 handle_qxfer_threads (const char *annex
,
1346 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1347 ULONGEST offset
, LONGEST len
)
1349 static char *result
= 0;
1350 static unsigned int result_length
= 0;
1352 if (writebuf
!= NULL
)
1355 if (!target_running () || annex
[0] != '\0')
1360 struct buffer buffer
;
1361 /* When asked for data at offset 0, generate everything and store into
1362 'result'. Successive reads will be served off 'result'. */
1366 buffer_init (&buffer
);
1368 handle_qxfer_threads_proper (&buffer
);
1370 result
= buffer_finish (&buffer
);
1371 result_length
= strlen (result
);
1372 buffer_free (&buffer
);
1375 if (offset
>= result_length
)
1377 /* We're out of data. */
1384 if (len
> result_length
- offset
)
1385 len
= result_length
- offset
;
1387 memcpy (readbuf
, result
+ offset
, len
);
1392 /* Handle qXfer:traceframe-info:read. */
1395 handle_qxfer_traceframe_info (const char *annex
,
1396 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1397 ULONGEST offset
, LONGEST len
)
1399 static char *result
= 0;
1400 static unsigned int result_length
= 0;
1402 if (writebuf
!= NULL
)
1405 if (!target_running () || annex
[0] != '\0' || current_traceframe
== -1)
1410 struct buffer buffer
;
1412 /* When asked for data at offset 0, generate everything and
1413 store into 'result'. Successive reads will be served off
1417 buffer_init (&buffer
);
1419 traceframe_read_info (current_traceframe
, &buffer
);
1421 result
= buffer_finish (&buffer
);
1422 result_length
= strlen (result
);
1423 buffer_free (&buffer
);
1426 if (offset
>= result_length
)
1428 /* We're out of data. */
1435 if (len
> result_length
- offset
)
1436 len
= result_length
- offset
;
1438 memcpy (readbuf
, result
+ offset
, len
);
1442 /* Handle qXfer:fdpic:read. */
1445 handle_qxfer_fdpic (const char *annex
, gdb_byte
*readbuf
,
1446 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1448 if (the_target
->read_loadmap
== NULL
)
1451 if (!target_running ())
1454 return (*the_target
->read_loadmap
) (annex
, offset
, readbuf
, len
);
1457 /* Handle qXfer:btrace:read. */
1460 handle_qxfer_btrace (const char *annex
,
1461 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1462 ULONGEST offset
, LONGEST len
)
1464 static struct buffer cache
;
1465 struct thread_info
*thread
;
1468 if (the_target
->read_btrace
== NULL
|| writebuf
!= NULL
)
1471 if (!target_running ())
1474 if (ptid_equal (general_thread
, null_ptid
)
1475 || ptid_equal (general_thread
, minus_one_ptid
))
1477 strcpy (own_buf
, "E.Must select a single thread.");
1481 thread
= find_thread_ptid (general_thread
);
1484 strcpy (own_buf
, "E.No such thread.");
1488 if (thread
->btrace
== NULL
)
1490 strcpy (own_buf
, "E.Btrace not enabled.");
1494 if (strcmp (annex
, "all") == 0)
1495 type
= BTRACE_READ_ALL
;
1496 else if (strcmp (annex
, "new") == 0)
1497 type
= BTRACE_READ_NEW
;
1498 else if (strcmp (annex
, "delta") == 0)
1499 type
= BTRACE_READ_DELTA
;
1502 strcpy (own_buf
, "E.Bad annex.");
1508 buffer_free (&cache
);
1510 result
= target_read_btrace (thread
->btrace
, &cache
, type
);
1513 memcpy (own_buf
, cache
.buffer
, cache
.used_size
);
1517 else if (offset
> cache
.used_size
)
1519 buffer_free (&cache
);
1523 if (len
> cache
.used_size
- offset
)
1524 len
= cache
.used_size
- offset
;
1526 memcpy (readbuf
, cache
.buffer
+ offset
, len
);
1531 static const struct qxfer qxfer_packets
[] =
1533 { "auxv", handle_qxfer_auxv
},
1534 { "btrace", handle_qxfer_btrace
},
1535 { "fdpic", handle_qxfer_fdpic
},
1536 { "features", handle_qxfer_features
},
1537 { "libraries", handle_qxfer_libraries
},
1538 { "libraries-svr4", handle_qxfer_libraries_svr4
},
1539 { "osdata", handle_qxfer_osdata
},
1540 { "siginfo", handle_qxfer_siginfo
},
1541 { "spu", handle_qxfer_spu
},
1542 { "statictrace", handle_qxfer_statictrace
},
1543 { "threads", handle_qxfer_threads
},
1544 { "traceframe-info", handle_qxfer_traceframe_info
},
1548 handle_qxfer (char *own_buf
, int packet_len
, int *new_packet_len_p
)
1556 if (strncmp (own_buf
, "qXfer:", 6) != 0)
1559 /* Grab the object, r/w and annex. */
1560 if (decode_xfer (own_buf
+ 6, &object
, &rw
, &annex
, &offset
) < 0)
1562 write_enn (own_buf
);
1567 i
< sizeof (qxfer_packets
) / sizeof (qxfer_packets
[0]);
1570 const struct qxfer
*q
= &qxfer_packets
[i
];
1572 if (strcmp (object
, q
->object
) == 0)
1574 if (strcmp (rw
, "read") == 0)
1576 unsigned char *data
;
1581 /* Grab the offset and length. */
1582 if (decode_xfer_read (offset
, &ofs
, &len
) < 0)
1584 write_enn (own_buf
);
1588 /* Read one extra byte, as an indicator of whether there is
1590 if (len
> PBUFSIZ
- 2)
1592 data
= malloc (len
+ 1);
1595 write_enn (own_buf
);
1598 n
= (*q
->xfer
) (annex
, data
, NULL
, ofs
, len
+ 1);
1606 /* Preserve error message. */
1609 write_enn (own_buf
);
1611 *new_packet_len_p
= write_qxfer_response (own_buf
, data
, len
, 1);
1613 *new_packet_len_p
= write_qxfer_response (own_buf
, data
, n
, 0);
1618 else if (strcmp (rw
, "write") == 0)
1623 unsigned char *data
;
1625 strcpy (own_buf
, "E00");
1626 data
= malloc (packet_len
- (offset
- own_buf
));
1629 write_enn (own_buf
);
1632 if (decode_xfer_write (offset
, packet_len
- (offset
- own_buf
),
1633 &ofs
, &len
, data
) < 0)
1636 write_enn (own_buf
);
1640 n
= (*q
->xfer
) (annex
, NULL
, data
, ofs
, len
);
1648 /* Preserve error message. */
1651 write_enn (own_buf
);
1653 sprintf (own_buf
, "%x", n
);
1666 /* Table used by the crc32 function to calcuate the checksum. */
1668 static unsigned int crc32_table
[256] =
1671 /* Compute 32 bit CRC from inferior memory.
1673 On success, return 32 bit CRC.
1674 On failure, return (unsigned long long) -1. */
1676 static unsigned long long
1677 crc32 (CORE_ADDR base
, int len
, unsigned int crc
)
1679 if (!crc32_table
[1])
1681 /* Initialize the CRC table and the decoding table. */
1685 for (i
= 0; i
< 256; i
++)
1687 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
1688 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
1695 unsigned char byte
= 0;
1697 /* Return failure if memory read fails. */
1698 if (read_inferior_memory (base
, &byte
, 1) != 0)
1699 return (unsigned long long) -1;
1701 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ byte
) & 255];
1704 return (unsigned long long) crc
;
1707 /* Handle all of the extended 'q' packets. */
1710 handle_query (char *own_buf
, int packet_len
, int *new_packet_len_p
)
1712 static struct inferior_list_entry
*thread_ptr
;
1714 /* Reply the current thread id. */
1715 if (strcmp ("qC", own_buf
) == 0 && !disable_packet_qC
)
1718 require_running (own_buf
);
1720 if (!ptid_equal (general_thread
, null_ptid
)
1721 && !ptid_equal (general_thread
, minus_one_ptid
))
1722 gdb_id
= general_thread
;
1725 thread_ptr
= get_first_inferior (&all_threads
);
1726 gdb_id
= thread_to_gdb_id ((struct thread_info
*)thread_ptr
);
1729 sprintf (own_buf
, "QC");
1731 write_ptid (own_buf
, gdb_id
);
1735 if (strcmp ("qSymbol::", own_buf
) == 0)
1737 /* GDB is suggesting new symbols have been loaded. This may
1738 mean a new shared library has been detected as loaded, so
1739 take the opportunity to check if breakpoints we think are
1740 inserted, still are. Note that it isn't guaranteed that
1741 we'll see this when a shared library is loaded, and nor will
1742 we see this for unloads (although breakpoints in unloaded
1743 libraries shouldn't trigger), as GDB may not find symbols for
1744 the library at all. We also re-validate breakpoints when we
1745 see a second GDB breakpoint for the same address, and or when
1746 we access breakpoint shadows. */
1747 validate_breakpoints ();
1749 if (target_supports_tracepoints ())
1750 tracepoint_look_up_symbols ();
1752 if (target_running () && the_target
->look_up_symbols
!= NULL
)
1753 (*the_target
->look_up_symbols
) ();
1755 strcpy (own_buf
, "OK");
1759 if (!disable_packet_qfThreadInfo
)
1761 if (strcmp ("qfThreadInfo", own_buf
) == 0)
1765 require_running (own_buf
);
1766 thread_ptr
= get_first_inferior (&all_threads
);
1769 gdb_id
= thread_to_gdb_id ((struct thread_info
*)thread_ptr
);
1770 write_ptid (own_buf
, gdb_id
);
1771 thread_ptr
= thread_ptr
->next
;
1775 if (strcmp ("qsThreadInfo", own_buf
) == 0)
1779 require_running (own_buf
);
1780 if (thread_ptr
!= NULL
)
1783 gdb_id
= thread_to_gdb_id ((struct thread_info
*)thread_ptr
);
1784 write_ptid (own_buf
, gdb_id
);
1785 thread_ptr
= thread_ptr
->next
;
1790 sprintf (own_buf
, "l");
1796 if (the_target
->read_offsets
!= NULL
1797 && strcmp ("qOffsets", own_buf
) == 0)
1799 CORE_ADDR text
, data
;
1801 require_running (own_buf
);
1802 if (the_target
->read_offsets (&text
, &data
))
1803 sprintf (own_buf
, "Text=%lX;Data=%lX;Bss=%lX",
1804 (long)text
, (long)data
, (long)data
);
1806 write_enn (own_buf
);
1811 /* Protocol features query. */
1812 if (strncmp ("qSupported", own_buf
, 10) == 0
1813 && (own_buf
[10] == ':' || own_buf
[10] == '\0'))
1815 char *p
= &own_buf
[10];
1816 int gdb_supports_qRelocInsn
= 0;
1818 /* Start processing qSupported packet. */
1819 target_process_qsupported (NULL
);
1821 /* Process each feature being provided by GDB. The first
1822 feature will follow a ':', and latter features will follow
1826 char **qsupported
= NULL
;
1830 /* Two passes, to avoid nested strtok calls in
1831 target_process_qsupported. */
1832 for (p
= strtok (p
+ 1, ";");
1834 p
= strtok (NULL
, ";"))
1837 qsupported
= xrealloc (qsupported
, count
* sizeof (char *));
1838 qsupported
[count
- 1] = xstrdup (p
);
1841 for (i
= 0; i
< count
; i
++)
1844 if (strcmp (p
, "multiprocess+") == 0)
1846 /* GDB supports and wants multi-process support if
1848 if (target_supports_multi_process ())
1851 else if (strcmp (p
, "qRelocInsn+") == 0)
1853 /* GDB supports relocate instruction requests. */
1854 gdb_supports_qRelocInsn
= 1;
1857 target_process_qsupported (p
);
1866 "PacketSize=%x;QPassSignals+;QProgramSignals+",
1869 if (the_target
->qxfer_libraries_svr4
!= NULL
)
1870 strcat (own_buf
, ";qXfer:libraries-svr4:read+"
1871 ";augmented-libraries-svr4-read+");
1874 /* We do not have any hook to indicate whether the non-SVR4 target
1875 backend supports qXfer:libraries:read, so always report it. */
1876 strcat (own_buf
, ";qXfer:libraries:read+");
1879 if (the_target
->read_auxv
!= NULL
)
1880 strcat (own_buf
, ";qXfer:auxv:read+");
1882 if (the_target
->qxfer_spu
!= NULL
)
1883 strcat (own_buf
, ";qXfer:spu:read+;qXfer:spu:write+");
1885 if (the_target
->qxfer_siginfo
!= NULL
)
1886 strcat (own_buf
, ";qXfer:siginfo:read+;qXfer:siginfo:write+");
1888 if (the_target
->read_loadmap
!= NULL
)
1889 strcat (own_buf
, ";qXfer:fdpic:read+");
1891 /* We always report qXfer:features:read, as targets may
1892 install XML files on a subsequent call to arch_setup.
1893 If we reported to GDB on startup that we don't support
1894 qXfer:feature:read at all, we will never be re-queried. */
1895 strcat (own_buf
, ";qXfer:features:read+");
1897 if (transport_is_reliable
)
1898 strcat (own_buf
, ";QStartNoAckMode+");
1900 if (the_target
->qxfer_osdata
!= NULL
)
1901 strcat (own_buf
, ";qXfer:osdata:read+");
1903 if (target_supports_multi_process ())
1904 strcat (own_buf
, ";multiprocess+");
1906 if (target_supports_non_stop ())
1907 strcat (own_buf
, ";QNonStop+");
1909 if (target_supports_disable_randomization ())
1910 strcat (own_buf
, ";QDisableRandomization+");
1912 strcat (own_buf
, ";qXfer:threads:read+");
1914 if (target_supports_tracepoints ())
1916 strcat (own_buf
, ";ConditionalTracepoints+");
1917 strcat (own_buf
, ";TraceStateVariables+");
1918 strcat (own_buf
, ";TracepointSource+");
1919 strcat (own_buf
, ";DisconnectedTracing+");
1920 if (gdb_supports_qRelocInsn
&& target_supports_fast_tracepoints ())
1921 strcat (own_buf
, ";FastTracepoints+");
1922 strcat (own_buf
, ";StaticTracepoints+");
1923 strcat (own_buf
, ";InstallInTrace+");
1924 strcat (own_buf
, ";qXfer:statictrace:read+");
1925 strcat (own_buf
, ";qXfer:traceframe-info:read+");
1926 strcat (own_buf
, ";EnableDisableTracepoints+");
1927 strcat (own_buf
, ";QTBuffer:size+");
1928 strcat (own_buf
, ";tracenz+");
1931 /* Support target-side breakpoint conditions and commands. */
1932 strcat (own_buf
, ";ConditionalBreakpoints+");
1933 strcat (own_buf
, ";BreakpointCommands+");
1935 if (target_supports_agent ())
1936 strcat (own_buf
, ";QAgent+");
1938 if (target_supports_btrace ())
1940 strcat (own_buf
, ";Qbtrace:bts+");
1941 strcat (own_buf
, ";Qbtrace:off+");
1942 strcat (own_buf
, ";qXfer:btrace:read+");
1948 /* Thread-local storage support. */
1949 if (the_target
->get_tls_address
!= NULL
1950 && strncmp ("qGetTLSAddr:", own_buf
, 12) == 0)
1952 char *p
= own_buf
+ 12;
1953 CORE_ADDR parts
[2], address
= 0;
1955 ptid_t ptid
= null_ptid
;
1957 require_running (own_buf
);
1959 for (i
= 0; i
< 3; i
++)
1967 p2
= strchr (p
, ',');
1980 ptid
= read_ptid (p
, NULL
);
1982 decode_address (&parts
[i
- 1], p
, len
);
1986 if (p
!= NULL
|| i
< 3)
1990 struct thread_info
*thread
= find_thread_ptid (ptid
);
1995 err
= the_target
->get_tls_address (thread
, parts
[0], parts
[1],
2001 strcpy (own_buf
, paddress(address
));
2006 write_enn (own_buf
);
2010 /* Otherwise, pretend we do not understand this packet. */
2013 /* Windows OS Thread Information Block address support. */
2014 if (the_target
->get_tib_address
!= NULL
2015 && strncmp ("qGetTIBAddr:", own_buf
, 12) == 0)
2020 ptid_t ptid
= read_ptid (own_buf
+ 12, &annex
);
2022 n
= (*the_target
->get_tib_address
) (ptid
, &tlb
);
2025 strcpy (own_buf
, paddress(tlb
));
2030 write_enn (own_buf
);
2036 /* Handle "monitor" commands. */
2037 if (strncmp ("qRcmd,", own_buf
, 6) == 0)
2039 char *mon
= malloc (PBUFSIZ
);
2040 int len
= strlen (own_buf
+ 6);
2044 write_enn (own_buf
);
2049 || hex2bin (own_buf
+ 6, (gdb_byte
*) mon
, len
/ 2) != len
/ 2)
2051 write_enn (own_buf
);
2055 mon
[len
/ 2] = '\0';
2059 if (the_target
->handle_monitor_command
== NULL
2060 || (*the_target
->handle_monitor_command
) (mon
) == 0)
2061 /* Default processing. */
2062 handle_monitor_command (mon
, own_buf
);
2068 if (strncmp ("qSearch:memory:", own_buf
,
2069 sizeof ("qSearch:memory:") - 1) == 0)
2071 require_running (own_buf
);
2072 handle_search_memory (own_buf
, packet_len
);
2076 if (strcmp (own_buf
, "qAttached") == 0
2077 || strncmp (own_buf
, "qAttached:", sizeof ("qAttached:") - 1) == 0)
2079 struct process_info
*process
;
2081 if (own_buf
[sizeof ("qAttached") - 1])
2083 int pid
= strtoul (own_buf
+ sizeof ("qAttached:") - 1, NULL
, 16);
2084 process
= (struct process_info
*)
2085 find_inferior_id (&all_processes
, pid_to_ptid (pid
));
2089 require_running (own_buf
);
2090 process
= current_process ();
2093 if (process
== NULL
)
2095 write_enn (own_buf
);
2099 strcpy (own_buf
, process
->attached
? "1" : "0");
2103 if (strncmp ("qCRC:", own_buf
, 5) == 0)
2105 /* CRC check (compare-section). */
2109 unsigned long long crc
;
2111 require_running (own_buf
);
2112 comma
= unpack_varlen_hex (own_buf
+ 5, &base
);
2113 if (*comma
++ != ',')
2115 write_enn (own_buf
);
2118 len
= strtoul (comma
, NULL
, 16);
2119 crc
= crc32 (base
, len
, 0xffffffff);
2120 /* Check for memory failure. */
2121 if (crc
== (unsigned long long) -1)
2123 write_enn (own_buf
);
2126 sprintf (own_buf
, "C%lx", (unsigned long) crc
);
2130 if (handle_qxfer (own_buf
, packet_len
, new_packet_len_p
))
2133 if (target_supports_tracepoints () && handle_tracepoint_query (own_buf
))
2136 /* Otherwise we didn't know what packet it was. Say we didn't
2141 static void gdb_wants_all_threads_stopped (void);
2142 static void resume (struct thread_resume
*actions
, size_t n
);
2144 /* The callback that is passed to visit_actioned_threads. */
2145 typedef int (visit_actioned_threads_callback_ftype
)
2146 (const struct thread_resume
*, struct thread_info
*);
2148 /* Struct to pass data to visit_actioned_threads. */
2150 struct visit_actioned_threads_data
2152 const struct thread_resume
*actions
;
2154 visit_actioned_threads_callback_ftype
*callback
;
2157 /* Call CALLBACK for any thread to which ACTIONS applies to. Returns
2158 true if CALLBACK returns true. Returns false if no matching thread
2159 is found or CALLBACK results false.
2160 Note: This function is itself a callback for find_inferior. */
2163 visit_actioned_threads (struct inferior_list_entry
*entry
, void *datap
)
2165 struct visit_actioned_threads_data
*data
= datap
;
2166 const struct thread_resume
*actions
= data
->actions
;
2167 size_t num_actions
= data
->num_actions
;
2168 visit_actioned_threads_callback_ftype
*callback
= data
->callback
;
2171 for (i
= 0; i
< num_actions
; i
++)
2173 const struct thread_resume
*action
= &actions
[i
];
2175 if (ptid_equal (action
->thread
, minus_one_ptid
)
2176 || ptid_equal (action
->thread
, entry
->id
)
2177 || ((ptid_get_pid (action
->thread
)
2178 == ptid_get_pid (entry
->id
))
2179 && ptid_get_lwp (action
->thread
) == -1))
2181 struct thread_info
*thread
= (struct thread_info
*) entry
;
2183 if ((*callback
) (action
, thread
))
2191 /* Callback for visit_actioned_threads. If the thread has a pending
2192 status to report, report it now. */
2195 handle_pending_status (const struct thread_resume
*resumption
,
2196 struct thread_info
*thread
)
2198 if (thread
->status_pending_p
)
2200 thread
->status_pending_p
= 0;
2202 last_status
= thread
->last_status
;
2203 last_ptid
= thread
->entry
.id
;
2204 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
2210 /* Parse vCont packets. */
2212 handle_v_cont (char *own_buf
)
2216 struct thread_resume
*resume_info
;
2217 struct thread_resume default_action
= {{0}};
2219 /* Count the number of semicolons in the packet. There should be one
2220 for every action. */
2226 p
= strchr (p
, ';');
2229 resume_info
= malloc (n
* sizeof (resume_info
[0]));
2230 if (resume_info
== NULL
)
2238 memset (&resume_info
[i
], 0, sizeof resume_info
[i
]);
2240 if (p
[0] == 's' || p
[0] == 'S')
2241 resume_info
[i
].kind
= resume_step
;
2242 else if (p
[0] == 'r')
2243 resume_info
[i
].kind
= resume_step
;
2244 else if (p
[0] == 'c' || p
[0] == 'C')
2245 resume_info
[i
].kind
= resume_continue
;
2246 else if (p
[0] == 't')
2247 resume_info
[i
].kind
= resume_stop
;
2251 if (p
[0] == 'S' || p
[0] == 'C')
2254 sig
= strtol (p
+ 1, &q
, 16);
2259 if (!gdb_signal_to_host_p (sig
))
2261 resume_info
[i
].sig
= gdb_signal_to_host (sig
);
2263 else if (p
[0] == 'r')
2267 p
= unpack_varlen_hex (p
+ 1, &addr
);
2268 resume_info
[i
].step_range_start
= addr
;
2273 p
= unpack_varlen_hex (p
+ 1, &addr
);
2274 resume_info
[i
].step_range_end
= addr
;
2283 resume_info
[i
].thread
= minus_one_ptid
;
2284 default_action
= resume_info
[i
];
2286 /* Note: we don't increment i here, we'll overwrite this entry
2287 the next time through. */
2289 else if (p
[0] == ':')
2291 ptid_t ptid
= read_ptid (p
+ 1, &q
);
2296 if (p
[0] != ';' && p
[0] != 0)
2299 resume_info
[i
].thread
= ptid
;
2306 resume_info
[i
] = default_action
;
2308 /* `cont_thread' is still used in occasional places in the backend,
2309 to implement single-thread scheduler-locking. Doesn't make sense
2310 to set it if we see a stop request, or a wildcard action (one
2311 with '-1' (all threads), or 'pPID.-1' (all threads of PID)). */
2313 && !(ptid_equal (resume_info
[0].thread
, minus_one_ptid
)
2314 || ptid_get_lwp (resume_info
[0].thread
) == -1)
2315 && resume_info
[0].kind
!= resume_stop
)
2316 cont_thread
= resume_info
[0].thread
;
2318 cont_thread
= minus_one_ptid
;
2319 set_desired_inferior (0);
2321 resume (resume_info
, n
);
2326 write_enn (own_buf
);
2331 /* Resume target with ACTIONS, an array of NUM_ACTIONS elements. */
2334 resume (struct thread_resume
*actions
, size_t num_actions
)
2338 /* Check if among the threads that GDB wants actioned, there's
2339 one with a pending status to report. If so, skip actually
2340 resuming/stopping and report the pending event
2342 struct visit_actioned_threads_data data
;
2344 data
.actions
= actions
;
2345 data
.num_actions
= num_actions
;
2346 data
.callback
= handle_pending_status
;
2347 if (find_inferior (&all_threads
, visit_actioned_threads
, &data
) != NULL
)
2353 (*the_target
->resume
) (actions
, num_actions
);
2359 last_ptid
= mywait (minus_one_ptid
, &last_status
, 0, 1);
2361 if (last_status
.kind
== TARGET_WAITKIND_NO_RESUMED
)
2363 /* No proper RSP support for this yet. At least return
2365 sprintf (own_buf
, "E.No unwaited-for children left.");
2366 disable_async_io ();
2370 if (last_status
.kind
!= TARGET_WAITKIND_EXITED
2371 && last_status
.kind
!= TARGET_WAITKIND_SIGNALLED
2372 && last_status
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
2373 current_inferior
->last_status
= last_status
;
2375 /* From the client's perspective, all-stop mode always stops all
2376 threads implicitly (and the target backend has already done
2377 so by now). Tag all threads as "want-stopped", so we don't
2378 resume them implicitly without the client telling us to. */
2379 gdb_wants_all_threads_stopped ();
2380 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
2381 disable_async_io ();
2383 if (last_status
.kind
== TARGET_WAITKIND_EXITED
2384 || last_status
.kind
== TARGET_WAITKIND_SIGNALLED
)
2385 mourn_inferior (find_process_pid (ptid_get_pid (last_ptid
)));
2389 /* Attach to a new program. Return 1 if successful, 0 if failure. */
2391 handle_v_attach (char *own_buf
)
2395 pid
= strtol (own_buf
+ 8, NULL
, 16);
2396 if (pid
!= 0 && attach_inferior (pid
) == 0)
2398 /* Don't report shared library events after attaching, even if
2399 some libraries are preloaded. GDB will always poll the
2400 library list. Avoids the "stopped by shared library event"
2401 notice on the GDB side. */
2406 /* In non-stop, we don't send a resume reply. Stop events
2407 will follow up using the normal notification
2412 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
2418 write_enn (own_buf
);
2423 /* Run a new program. Return 1 if successful, 0 if failure. */
2425 handle_v_run (char *own_buf
)
2427 char *p
, *next_p
, **new_argv
;
2431 for (p
= own_buf
+ strlen ("vRun;"); p
&& *p
; p
= strchr (p
, ';'))
2437 new_argv
= calloc (new_argc
+ 2, sizeof (char *));
2438 if (new_argv
== NULL
)
2440 write_enn (own_buf
);
2445 for (p
= own_buf
+ strlen ("vRun;"); *p
; p
= next_p
)
2447 next_p
= strchr (p
, ';');
2449 next_p
= p
+ strlen (p
);
2451 if (i
== 0 && p
== next_p
)
2455 /* FIXME: Fail request if out of memory instead of dying. */
2456 new_argv
[i
] = xmalloc (1 + (next_p
- p
) / 2);
2457 hex2bin (p
, (gdb_byte
*) new_argv
[i
], (next_p
- p
) / 2);
2458 new_argv
[i
][(next_p
- p
) / 2] = '\0';
2467 if (new_argv
[0] == NULL
)
2469 /* GDB didn't specify a program to run. Use the program from the
2470 last run with the new argument list. */
2472 if (program_argv
== NULL
)
2474 write_enn (own_buf
);
2475 freeargv (new_argv
);
2479 new_argv
[0] = strdup (program_argv
[0]);
2480 if (new_argv
[0] == NULL
)
2482 write_enn (own_buf
);
2483 freeargv (new_argv
);
2488 /* Free the old argv and install the new one. */
2489 freeargv (program_argv
);
2490 program_argv
= new_argv
;
2492 start_inferior (program_argv
);
2493 if (last_status
.kind
== TARGET_WAITKIND_STOPPED
)
2495 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
2497 /* In non-stop, sending a resume reply doesn't set the general
2498 thread, but GDB assumes a vRun sets it (this is so GDB can
2499 query which is the main thread of the new inferior. */
2501 general_thread
= last_ptid
;
2507 write_enn (own_buf
);
2512 /* Kill process. Return 1 if successful, 0 if failure. */
2514 handle_v_kill (char *own_buf
)
2517 char *p
= &own_buf
[6];
2519 pid
= strtol (p
, NULL
, 16);
2522 if (pid
!= 0 && kill_inferior (pid
) == 0)
2524 last_status
.kind
= TARGET_WAITKIND_SIGNALLED
;
2525 last_status
.value
.sig
= GDB_SIGNAL_KILL
;
2526 last_ptid
= pid_to_ptid (pid
);
2527 discard_queued_stop_replies (pid
);
2533 write_enn (own_buf
);
2538 /* Handle all of the extended 'v' packets. */
2540 handle_v_requests (char *own_buf
, int packet_len
, int *new_packet_len
)
2542 if (!disable_packet_vCont
)
2544 if (strncmp (own_buf
, "vCont;", 6) == 0)
2546 require_running (own_buf
);
2547 handle_v_cont (own_buf
);
2551 if (strncmp (own_buf
, "vCont?", 6) == 0)
2553 strcpy (own_buf
, "vCont;c;C;s;S;t");
2554 if (target_supports_range_stepping ())
2556 own_buf
= own_buf
+ strlen (own_buf
);
2557 strcpy (own_buf
, ";r");
2563 if (strncmp (own_buf
, "vFile:", 6) == 0
2564 && handle_vFile (own_buf
, packet_len
, new_packet_len
))
2567 if (strncmp (own_buf
, "vAttach;", 8) == 0)
2569 if ((!extended_protocol
|| !multi_process
) && target_running ())
2571 fprintf (stderr
, "Already debugging a process\n");
2572 write_enn (own_buf
);
2575 handle_v_attach (own_buf
);
2579 if (strncmp (own_buf
, "vRun;", 5) == 0)
2581 if ((!extended_protocol
|| !multi_process
) && target_running ())
2583 fprintf (stderr
, "Already debugging a process\n");
2584 write_enn (own_buf
);
2587 handle_v_run (own_buf
);
2591 if (strncmp (own_buf
, "vKill;", 6) == 0)
2593 if (!target_running ())
2595 fprintf (stderr
, "No process to kill\n");
2596 write_enn (own_buf
);
2599 handle_v_kill (own_buf
);
2603 if (handle_notif_ack (own_buf
, packet_len
))
2606 /* Otherwise we didn't know what packet it was. Say we didn't
2612 /* Resume inferior and wait for another event. In non-stop mode,
2613 don't really wait here, but return immediatelly to the event
2616 myresume (char *own_buf
, int step
, int sig
)
2618 struct thread_resume resume_info
[2];
2620 int valid_cont_thread
;
2622 set_desired_inferior (0);
2624 valid_cont_thread
= (!ptid_equal (cont_thread
, null_ptid
)
2625 && !ptid_equal (cont_thread
, minus_one_ptid
));
2627 if (step
|| sig
|| valid_cont_thread
)
2629 resume_info
[0].thread
= current_ptid
;
2631 resume_info
[0].kind
= resume_step
;
2633 resume_info
[0].kind
= resume_continue
;
2634 resume_info
[0].sig
= sig
;
2638 if (!valid_cont_thread
)
2640 resume_info
[n
].thread
= minus_one_ptid
;
2641 resume_info
[n
].kind
= resume_continue
;
2642 resume_info
[n
].sig
= 0;
2646 resume (resume_info
, n
);
2649 /* Callback for for_each_inferior. Make a new stop reply for each
2653 queue_stop_reply_callback (struct inferior_list_entry
*entry
, void *arg
)
2655 struct thread_info
*thread
= (struct thread_info
*) entry
;
2657 /* For now, assume targets that don't have this callback also don't
2658 manage the thread's last_status field. */
2659 if (the_target
->thread_stopped
== NULL
)
2661 struct vstop_notif
*new_notif
= xmalloc (sizeof (*new_notif
));
2663 new_notif
->ptid
= entry
->id
;
2664 new_notif
->status
= thread
->last_status
;
2665 /* Pass the last stop reply back to GDB, but don't notify
2667 notif_event_enque (¬if_stop
,
2668 (struct notif_event
*) new_notif
);
2672 if (thread_stopped (thread
))
2677 = target_waitstatus_to_string (&thread
->last_status
);
2679 debug_printf ("Reporting thread %s as already stopped with %s\n",
2680 target_pid_to_str (entry
->id
),
2683 xfree (status_string
);
2686 gdb_assert (thread
->last_status
.kind
!= TARGET_WAITKIND_IGNORE
);
2688 /* Pass the last stop reply back to GDB, but don't notify
2690 queue_stop_reply (entry
->id
, &thread
->last_status
);
2697 /* Set this inferior threads's state as "want-stopped". We won't
2698 resume this thread until the client gives us another action for
2702 gdb_wants_thread_stopped (struct inferior_list_entry
*entry
)
2704 struct thread_info
*thread
= (struct thread_info
*) entry
;
2706 thread
->last_resume_kind
= resume_stop
;
2708 if (thread
->last_status
.kind
== TARGET_WAITKIND_IGNORE
)
2710 /* Most threads are stopped implicitly (all-stop); tag that with
2712 thread
->last_status
.kind
= TARGET_WAITKIND_STOPPED
;
2713 thread
->last_status
.value
.sig
= GDB_SIGNAL_0
;
2717 /* Set all threads' states as "want-stopped". */
2720 gdb_wants_all_threads_stopped (void)
2722 for_each_inferior (&all_threads
, gdb_wants_thread_stopped
);
2725 /* Clear the gdb_detached flag of every process. */
2728 gdb_reattached_process (struct inferior_list_entry
*entry
)
2730 struct process_info
*process
= (struct process_info
*) entry
;
2732 process
->gdb_detached
= 0;
2735 /* Callback for for_each_inferior. Clear the thread's pending status
2739 clear_pending_status_callback (struct inferior_list_entry
*entry
)
2741 struct thread_info
*thread
= (struct thread_info
*) entry
;
2743 thread
->status_pending_p
= 0;
2746 /* Callback for for_each_inferior. If the thread is stopped with an
2747 interesting event, mark it as having a pending event. */
2750 set_pending_status_callback (struct inferior_list_entry
*entry
)
2752 struct thread_info
*thread
= (struct thread_info
*) entry
;
2754 if (thread
->last_status
.kind
!= TARGET_WAITKIND_STOPPED
2755 || (thread
->last_status
.value
.sig
!= GDB_SIGNAL_0
2756 /* A breakpoint, watchpoint or finished step from a previous
2757 GDB run isn't considered interesting for a new GDB run.
2758 If we left those pending, the new GDB could consider them
2759 random SIGTRAPs. This leaves out real async traps. We'd
2760 have to peek into the (target-specific) siginfo to
2761 distinguish those. */
2762 && thread
->last_status
.value
.sig
!= GDB_SIGNAL_TRAP
))
2763 thread
->status_pending_p
= 1;
2766 /* Callback for find_inferior. Return true if ENTRY (a thread) has a
2767 pending status to report to GDB. */
2770 find_status_pending_thread_callback (struct inferior_list_entry
*entry
, void *data
)
2772 struct thread_info
*thread
= (struct thread_info
*) entry
;
2774 return thread
->status_pending_p
;
2777 /* Status handler for the '?' packet. */
2780 handle_status (char *own_buf
)
2782 /* GDB is connected, don't forward events to the target anymore. */
2783 for_each_inferior (&all_processes
, gdb_reattached_process
);
2785 /* In non-stop mode, we must send a stop reply for each stopped
2786 thread. In all-stop mode, just send one for the first stopped
2791 find_inferior (&all_threads
, queue_stop_reply_callback
, NULL
);
2793 /* The first is sent immediatly. OK is sent if there is no
2794 stopped thread, which is the same handling of the vStopped
2795 packet (by design). */
2796 notif_write_event (¬if_stop
, own_buf
);
2800 struct inferior_list_entry
*thread
= NULL
;
2803 stabilize_threads ();
2804 gdb_wants_all_threads_stopped ();
2806 /* We can only report one status, but we might be coming out of
2807 non-stop -- if more than one thread is stopped with
2808 interesting events, leave events for the threads we're not
2809 reporting now pending. They'll be reported the next time the
2810 threads are resumed. Start by marking all interesting events
2812 for_each_inferior (&all_threads
, set_pending_status_callback
);
2814 /* Prefer the last thread that reported an event to GDB (even if
2815 that was a GDB_SIGNAL_TRAP). */
2816 if (last_status
.kind
!= TARGET_WAITKIND_IGNORE
2817 && last_status
.kind
!= TARGET_WAITKIND_EXITED
2818 && last_status
.kind
!= TARGET_WAITKIND_SIGNALLED
)
2819 thread
= find_inferior_id (&all_threads
, last_ptid
);
2821 /* If the last event thread is not found for some reason, look
2822 for some other thread that might have an event to report. */
2824 thread
= find_inferior (&all_threads
,
2825 find_status_pending_thread_callback
, NULL
);
2827 /* If we're still out of luck, simply pick the first thread in
2830 thread
= get_first_inferior (&all_threads
);
2834 struct thread_info
*tp
= (struct thread_info
*) thread
;
2836 /* We're reporting this event, so it's no longer
2838 tp
->status_pending_p
= 0;
2840 /* GDB assumes the current thread is the thread we're
2841 reporting the status for. */
2842 general_thread
= thread
->id
;
2843 set_desired_inferior (1);
2845 gdb_assert (tp
->last_status
.kind
!= TARGET_WAITKIND_IGNORE
);
2846 prepare_resume_reply (own_buf
, tp
->entry
.id
, &tp
->last_status
);
2849 strcpy (own_buf
, "W00");
2854 gdbserver_version (void)
2856 printf ("GNU gdbserver %s%s\n"
2857 "Copyright (C) 2014 Free Software Foundation, Inc.\n"
2858 "gdbserver is free software, covered by the "
2859 "GNU General Public License.\n"
2860 "This gdbserver was configured as \"%s\"\n",
2861 PKGVERSION
, version
, host_name
);
2865 gdbserver_usage (FILE *stream
)
2867 fprintf (stream
, "Usage:\tgdbserver [OPTIONS] COMM PROG [ARGS ...]\n"
2868 "\tgdbserver [OPTIONS] --attach COMM PID\n"
2869 "\tgdbserver [OPTIONS] --multi COMM\n"
2871 "COMM may either be a tty device (for serial debugging), or \n"
2872 "HOST:PORT to listen for a TCP connection.\n"
2875 " --debug Enable general debugging output.\n"
2876 " --debug-format=opt1[,opt2,...]\n"
2877 " Specify extra content in debugging output.\n"
2882 " --remote-debug Enable remote protocol debugging output.\n"
2883 " --version Display version information and exit.\n"
2884 " --wrapper WRAPPER -- Run WRAPPER to start new programs.\n"
2885 " --once Exit after the first connection has "
2887 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
2888 fprintf (stream
, "Report bugs to \"%s\".\n", REPORT_BUGS_TO
);
2892 gdbserver_show_disableable (FILE *stream
)
2894 fprintf (stream
, "Disableable packets:\n"
2895 " vCont \tAll vCont packets\n"
2896 " qC \tQuerying the current thread\n"
2897 " qfThreadInfo\tThread listing\n"
2898 " Tthread \tPassing the thread specifier in the "
2899 "T stop reply packet\n"
2900 " threads \tAll of the above\n");
2904 #undef require_running
2905 #define require_running(BUF) \
2906 if (!target_running ()) \
2913 first_thread_of (struct inferior_list_entry
*entry
, void *args
)
2915 int pid
= * (int *) args
;
2917 if (ptid_get_pid (entry
->id
) == pid
)
2924 kill_inferior_callback (struct inferior_list_entry
*entry
)
2926 struct process_info
*process
= (struct process_info
*) entry
;
2927 int pid
= ptid_get_pid (process
->entry
.id
);
2929 kill_inferior (pid
);
2930 discard_queued_stop_replies (pid
);
2933 /* Callback for for_each_inferior to detach or kill the inferior,
2934 depending on whether we attached to it or not.
2935 We inform the user whether we're detaching or killing the process
2936 as this is only called when gdbserver is about to exit. */
2939 detach_or_kill_inferior_callback (struct inferior_list_entry
*entry
)
2941 struct process_info
*process
= (struct process_info
*) entry
;
2942 int pid
= ptid_get_pid (process
->entry
.id
);
2944 if (process
->attached
)
2945 detach_inferior (pid
);
2947 kill_inferior (pid
);
2949 discard_queued_stop_replies (pid
);
2952 /* for_each_inferior callback for detach_or_kill_for_exit to print
2953 the pids of started inferiors. */
2956 print_started_pid (struct inferior_list_entry
*entry
)
2958 struct process_info
*process
= (struct process_info
*) entry
;
2960 if (! process
->attached
)
2962 int pid
= ptid_get_pid (process
->entry
.id
);
2963 fprintf (stderr
, " %d", pid
);
2967 /* for_each_inferior callback for detach_or_kill_for_exit to print
2968 the pids of attached inferiors. */
2971 print_attached_pid (struct inferior_list_entry
*entry
)
2973 struct process_info
*process
= (struct process_info
*) entry
;
2975 if (process
->attached
)
2977 int pid
= ptid_get_pid (process
->entry
.id
);
2978 fprintf (stderr
, " %d", pid
);
2982 /* Call this when exiting gdbserver with possible inferiors that need
2983 to be killed or detached from. */
2986 detach_or_kill_for_exit (void)
2988 /* First print a list of the inferiors we will be killing/detaching.
2989 This is to assist the user, for example, in case the inferior unexpectedly
2990 dies after we exit: did we screw up or did the inferior exit on its own?
2991 Having this info will save some head-scratching. */
2993 if (have_started_inferiors_p ())
2995 fprintf (stderr
, "Killing process(es):");
2996 for_each_inferior (&all_processes
, print_started_pid
);
2997 fprintf (stderr
, "\n");
2999 if (have_attached_inferiors_p ())
3001 fprintf (stderr
, "Detaching process(es):");
3002 for_each_inferior (&all_processes
, print_attached_pid
);
3003 fprintf (stderr
, "\n");
3006 /* Now we can kill or detach the inferiors. */
3008 for_each_inferior (&all_processes
, detach_or_kill_inferior_callback
);
3011 /* Value that will be passed to exit(3) when gdbserver exits. */
3012 static int exit_code
;
3014 /* Cleanup version of detach_or_kill_for_exit. */
3017 detach_or_kill_for_exit_cleanup (void *ignore
)
3019 volatile struct gdb_exception exception
;
3021 TRY_CATCH (exception
, RETURN_MASK_ALL
)
3023 detach_or_kill_for_exit ();
3026 if (exception
.reason
< 0)
3029 fprintf (stderr
, "Detach or kill failed: %s\n", exception
.message
);
3034 /* Main function. This is called by the real "main" function,
3035 wrapped in a TRY_CATCH that handles any uncaught exceptions. */
3037 static void ATTRIBUTE_NORETURN
3038 captured_main (int argc
, char *argv
[])
3042 char *arg_end
, *port
;
3043 char **next_arg
= &argv
[1];
3044 volatile int multi_mode
= 0;
3045 volatile int attach
= 0;
3048 while (*next_arg
!= NULL
&& **next_arg
== '-')
3050 if (strcmp (*next_arg
, "--version") == 0)
3052 gdbserver_version ();
3055 else if (strcmp (*next_arg
, "--help") == 0)
3057 gdbserver_usage (stdout
);
3060 else if (strcmp (*next_arg
, "--attach") == 0)
3062 else if (strcmp (*next_arg
, "--multi") == 0)
3064 else if (strcmp (*next_arg
, "--wrapper") == 0)
3068 wrapper_argv
= next_arg
;
3069 while (*next_arg
!= NULL
&& strcmp (*next_arg
, "--") != 0)
3072 if (next_arg
== wrapper_argv
|| *next_arg
== NULL
)
3074 gdbserver_usage (stderr
);
3078 /* Consume the "--". */
3081 else if (strcmp (*next_arg
, "--debug") == 0)
3083 else if (strncmp (*next_arg
,
3085 sizeof ("--debug-format=") - 1) == 0)
3088 = parse_debug_format_options ((*next_arg
)
3089 + sizeof ("--debug-format=") - 1, 0);
3091 if (error_msg
!= NULL
)
3093 fprintf (stderr
, "%s", error_msg
);
3097 else if (strcmp (*next_arg
, "--remote-debug") == 0)
3099 else if (strcmp (*next_arg
, "--disable-packet") == 0)
3101 gdbserver_show_disableable (stdout
);
3104 else if (strncmp (*next_arg
,
3105 "--disable-packet=",
3106 sizeof ("--disable-packet=") - 1) == 0)
3108 char *packets
, *tok
;
3110 packets
= *next_arg
+= sizeof ("--disable-packet=") - 1;
3111 for (tok
= strtok (packets
, ",");
3113 tok
= strtok (NULL
, ","))
3115 if (strcmp ("vCont", tok
) == 0)
3116 disable_packet_vCont
= 1;
3117 else if (strcmp ("Tthread", tok
) == 0)
3118 disable_packet_Tthread
= 1;
3119 else if (strcmp ("qC", tok
) == 0)
3120 disable_packet_qC
= 1;
3121 else if (strcmp ("qfThreadInfo", tok
) == 0)
3122 disable_packet_qfThreadInfo
= 1;
3123 else if (strcmp ("threads", tok
) == 0)
3125 disable_packet_vCont
= 1;
3126 disable_packet_Tthread
= 1;
3127 disable_packet_qC
= 1;
3128 disable_packet_qfThreadInfo
= 1;
3132 fprintf (stderr
, "Don't know how to disable \"%s\".\n\n",
3134 gdbserver_show_disableable (stderr
);
3139 else if (strcmp (*next_arg
, "-") == 0)
3141 /* "-" specifies a stdio connection and is a form of port
3143 *next_arg
= STDIO_CONNECTION_NAME
;
3146 else if (strcmp (*next_arg
, "--disable-randomization") == 0)
3147 disable_randomization
= 1;
3148 else if (strcmp (*next_arg
, "--no-disable-randomization") == 0)
3149 disable_randomization
= 0;
3150 else if (strcmp (*next_arg
, "--once") == 0)
3154 fprintf (stderr
, "Unknown argument: %s\n", *next_arg
);
3164 if (port
== NULL
|| (!attach
&& !multi_mode
&& *next_arg
== NULL
))
3166 gdbserver_usage (stderr
);
3170 /* Remember stdio descriptors. LISTEN_DESC must not be listed, it will be
3171 opened by remote_prepare. */
3174 /* We need to know whether the remote connection is stdio before
3175 starting the inferior. Inferiors created in this scenario have
3176 stdin,stdout redirected. So do this here before we call
3178 remote_prepare (port
);
3183 /* --attach used to come after PORT, so allow it there for
3185 if (*next_arg
!= NULL
&& strcmp (*next_arg
, "--attach") == 0)
3192 && (*next_arg
== NULL
3193 || (*next_arg
)[0] == '\0'
3194 || (pid
= strtoul (*next_arg
, &arg_end
, 0)) == 0
3196 || next_arg
[1] != NULL
))
3201 gdbserver_usage (stderr
);
3205 initialize_async_io ();
3207 initialize_event_loop ();
3208 if (target_supports_tracepoints ())
3209 initialize_tracepoint ();
3211 own_buf
= xmalloc (PBUFSIZ
+ 1);
3212 mem_buf
= xmalloc (PBUFSIZ
);
3214 if (pid
== 0 && *next_arg
!= NULL
)
3218 n
= argc
- (next_arg
- argv
);
3219 program_argv
= xmalloc (sizeof (char *) * (n
+ 1));
3220 for (i
= 0; i
< n
; i
++)
3221 program_argv
[i
] = xstrdup (next_arg
[i
]);
3222 program_argv
[i
] = NULL
;
3224 /* Wait till we are at first instruction in program. */
3225 start_inferior (program_argv
);
3227 /* We are now (hopefully) stopped at the first instruction of
3228 the target process. This assumes that the target process was
3229 successfully created. */
3233 if (attach_inferior (pid
) == -1)
3234 error ("Attaching not supported on this target");
3236 /* Otherwise succeeded. */
3240 last_status
.kind
= TARGET_WAITKIND_EXITED
;
3241 last_status
.value
.integer
= 0;
3242 last_ptid
= minus_one_ptid
;
3244 make_cleanup (detach_or_kill_for_exit_cleanup
, NULL
);
3246 initialize_notif ();
3248 /* Don't report shared library events on the initial connection,
3249 even if some libraries are preloaded. Avoids the "stopped by
3250 shared library event" notice on gdb side. */
3253 if (last_status
.kind
== TARGET_WAITKIND_EXITED
3254 || last_status
.kind
== TARGET_WAITKIND_SIGNALLED
)
3259 if (!was_running
&& !multi_mode
)
3260 error ("No program to debug");
3264 volatile struct gdb_exception exception
;
3268 /* Be sure we're out of tfind mode. */
3269 current_traceframe
= -1;
3273 TRY_CATCH (exception
, RETURN_MASK_ERROR
)
3275 /* Wait for events. This will return when all event sources
3276 are removed from the event loop. */
3277 start_event_loop ();
3279 /* If an exit was requested (using the "monitor exit"
3280 command), terminate now. The only other way to get
3281 here is for getpkt to fail; close the connection
3282 and reopen it at the top of the loop. */
3284 if (exit_requested
|| run_once
)
3285 throw_quit ("Quit");
3288 "Remote side has terminated connection. "
3289 "GDBserver will reopen the connection.\n");
3291 /* Get rid of any pending statuses. An eventual reconnection
3292 (by the same GDB instance or another) will refresh all its
3293 state from scratch. */
3294 discard_queued_stop_replies (-1);
3295 for_each_inferior (&all_threads
,
3296 clear_pending_status_callback
);
3300 if (disconnected_tracing
)
3302 /* Try to enable non-stop/async mode, so we we can
3303 both wait for an async socket accept, and handle
3304 async target events simultaneously. There's also
3305 no point either in having the target always stop
3306 all threads, when we're going to pass signals
3307 down without informing GDB. */
3310 if (start_non_stop (1))
3313 /* Detaching implicitly resumes all threads;
3314 simply disconnecting does not. */
3320 "Disconnected tracing disabled; "
3321 "stopping trace run.\n");
3327 if (exception
.reason
== RETURN_ERROR
)
3329 if (response_needed
)
3331 write_enn (own_buf
);
3338 /* Main function. */
3341 main (int argc
, char *argv
[])
3343 volatile struct gdb_exception exception
;
3345 TRY_CATCH (exception
, RETURN_MASK_ALL
)
3347 captured_main (argc
, argv
);
3350 /* captured_main should never return. */
3351 gdb_assert (exception
.reason
< 0);
3353 if (exception
.reason
== RETURN_ERROR
)
3356 fprintf (stderr
, "%s\n", exception
.message
);
3357 fprintf (stderr
, "Exiting\n");
3364 /* Skip PACKET until the next semi-colon (or end of string). */
3367 skip_to_semicolon (char **packet
)
3369 while (**packet
!= '\0' && **packet
!= ';')
3373 /* Process options coming from Z packets for a breakpoint. PACKET is
3374 the packet buffer. *PACKET is updated to point to the first char
3375 after the last processed option. */
3378 process_point_options (struct breakpoint
*bp
, char **packet
)
3380 char *dataptr
= *packet
;
3383 /* Check if data has the correct format. */
3384 if (*dataptr
!= ';')
3391 if (*dataptr
== ';')
3394 if (*dataptr
== 'X')
3396 /* Conditional expression. */
3398 debug_printf ("Found breakpoint condition.\n");
3399 if (!add_breakpoint_condition (bp
, &dataptr
))
3400 skip_to_semicolon (&dataptr
);
3402 else if (strncmp (dataptr
, "cmds:", strlen ("cmds:")) == 0)
3404 dataptr
+= strlen ("cmds:");
3406 debug_printf ("Found breakpoint commands %s.\n", dataptr
);
3407 persist
= (*dataptr
== '1');
3409 if (add_breakpoint_commands (bp
, &dataptr
, persist
))
3410 skip_to_semicolon (&dataptr
);
3414 fprintf (stderr
, "Unknown token %c, ignoring.\n",
3416 /* Skip tokens until we find one that we recognize. */
3417 skip_to_semicolon (&dataptr
);
3423 /* Event loop callback that handles a serial event. The first byte in
3424 the serial buffer gets us here. We expect characters to arrive at
3425 a brisk pace, so we read the rest of the packet with a blocking
3429 process_serial_event (void)
3440 int new_packet_len
= -1;
3442 /* Used to decide when gdbserver should exit in
3443 multi-mode/remote. */
3444 static int have_ran
= 0;
3447 have_ran
= target_running ();
3449 disable_async_io ();
3451 response_needed
= 0;
3452 packet_len
= getpkt (own_buf
);
3453 if (packet_len
<= 0)
3456 /* Force an event loop break. */
3459 response_needed
= 1;
3466 handle_query (own_buf
, packet_len
, &new_packet_len
);
3469 handle_general_set (own_buf
);
3472 require_running (own_buf
);
3477 pid
= strtol (&own_buf
[i
], NULL
, 16);
3480 pid
= ptid_get_pid (current_ptid
);
3482 if ((tracing
&& disconnected_tracing
) || any_persistent_commands ())
3484 struct thread_resume resume_info
;
3485 struct process_info
*process
= find_process_pid (pid
);
3487 if (process
== NULL
)
3489 write_enn (own_buf
);
3493 if (tracing
&& disconnected_tracing
)
3495 "Disconnected tracing in effect, "
3496 "leaving gdbserver attached to the process\n");
3498 if (any_persistent_commands ())
3500 "Persistent commands are present, "
3501 "leaving gdbserver attached to the process\n");
3503 /* Make sure we're in non-stop/async mode, so we we can both
3504 wait for an async socket accept, and handle async target
3505 events simultaneously. There's also no point either in
3506 having the target stop all threads, when we're going to
3507 pass signals down without informing GDB. */
3511 debug_printf ("Forcing non-stop mode\n");
3517 process
->gdb_detached
= 1;
3519 /* Detaching implicitly resumes all threads. */
3520 resume_info
.thread
= minus_one_ptid
;
3521 resume_info
.kind
= resume_continue
;
3522 resume_info
.sig
= 0;
3523 (*the_target
->resume
) (&resume_info
, 1);
3526 break; /* from switch/case */
3529 fprintf (stderr
, "Detaching from process %d\n", pid
);
3531 if (detach_inferior (pid
) != 0)
3532 write_enn (own_buf
);
3535 discard_queued_stop_replies (pid
);
3538 if (extended_protocol
)
3540 /* Treat this like a normal program exit. */
3541 last_status
.kind
= TARGET_WAITKIND_EXITED
;
3542 last_status
.value
.integer
= 0;
3543 last_ptid
= pid_to_ptid (pid
);
3545 current_inferior
= NULL
;
3552 /* If we are attached, then we can exit. Otherwise, we
3553 need to hang around doing nothing, until the child is
3555 join_inferior (pid
);
3561 extended_protocol
= 1;
3565 handle_status (own_buf
);
3568 if (own_buf
[1] == 'c' || own_buf
[1] == 'g' || own_buf
[1] == 's')
3570 ptid_t gdb_id
, thread_id
;
3573 require_running (own_buf
);
3575 gdb_id
= read_ptid (&own_buf
[2], NULL
);
3577 pid
= ptid_get_pid (gdb_id
);
3579 if (ptid_equal (gdb_id
, null_ptid
)
3580 || ptid_equal (gdb_id
, minus_one_ptid
))
3581 thread_id
= null_ptid
;
3583 && ptid_equal (pid_to_ptid (pid
),
3586 struct thread_info
*thread
=
3587 (struct thread_info
*) find_inferior (&all_threads
,
3592 write_enn (own_buf
);
3596 thread_id
= thread
->entry
.id
;
3600 thread_id
= gdb_id_to_thread_id (gdb_id
);
3601 if (ptid_equal (thread_id
, null_ptid
))
3603 write_enn (own_buf
);
3608 if (own_buf
[1] == 'g')
3610 if (ptid_equal (thread_id
, null_ptid
))
3612 /* GDB is telling us to choose any thread. Check if
3613 the currently selected thread is still valid. If
3614 it is not, select the first available. */
3615 struct thread_info
*thread
=
3616 (struct thread_info
*) find_inferior_id (&all_threads
,
3620 thread
= get_first_thread ();
3621 thread_id
= thread
->entry
.id
;
3625 general_thread
= thread_id
;
3626 set_desired_inferior (1);
3628 else if (own_buf
[1] == 'c')
3629 cont_thread
= thread_id
;
3635 /* Silently ignore it so that gdb can extend the protocol
3636 without compatibility headaches. */
3641 require_running (own_buf
);
3642 if (current_traceframe
>= 0)
3644 struct regcache
*regcache
3645 = new_register_cache (current_target_desc ());
3647 if (fetch_traceframe_registers (current_traceframe
,
3649 registers_to_string (regcache
, own_buf
);
3651 write_enn (own_buf
);
3652 free_register_cache (regcache
);
3656 struct regcache
*regcache
;
3658 set_desired_inferior (1);
3659 regcache
= get_thread_regcache (current_inferior
, 1);
3660 registers_to_string (regcache
, own_buf
);
3664 require_running (own_buf
);
3665 if (current_traceframe
>= 0)
3666 write_enn (own_buf
);
3669 struct regcache
*regcache
;
3671 set_desired_inferior (1);
3672 regcache
= get_thread_regcache (current_inferior
, 1);
3673 registers_from_string (regcache
, &own_buf
[1]);
3678 require_running (own_buf
);
3679 decode_m_packet (&own_buf
[1], &mem_addr
, &len
);
3680 res
= gdb_read_memory (mem_addr
, mem_buf
, len
);
3682 write_enn (own_buf
);
3684 bin2hex (mem_buf
, own_buf
, res
);
3687 require_running (own_buf
);
3688 decode_M_packet (&own_buf
[1], &mem_addr
, &len
, &mem_buf
);
3689 if (gdb_write_memory (mem_addr
, mem_buf
, len
) == 0)
3692 write_enn (own_buf
);
3695 require_running (own_buf
);
3696 if (decode_X_packet (&own_buf
[1], packet_len
- 1,
3697 &mem_addr
, &len
, &mem_buf
) < 0
3698 || gdb_write_memory (mem_addr
, mem_buf
, len
) != 0)
3699 write_enn (own_buf
);
3704 require_running (own_buf
);
3705 hex2bin (own_buf
+ 1, &sig
, 1);
3706 if (gdb_signal_to_host_p (sig
))
3707 signal
= gdb_signal_to_host (sig
);
3710 myresume (own_buf
, 0, signal
);
3713 require_running (own_buf
);
3714 hex2bin (own_buf
+ 1, &sig
, 1);
3715 if (gdb_signal_to_host_p (sig
))
3716 signal
= gdb_signal_to_host (sig
);
3719 myresume (own_buf
, 1, signal
);
3722 require_running (own_buf
);
3724 myresume (own_buf
, 0, signal
);
3727 require_running (own_buf
);
3729 myresume (own_buf
, 1, signal
);
3731 case 'Z': /* insert_ ... */
3733 case 'z': /* remove_ ... */
3738 char type
= own_buf
[1];
3740 const int insert
= ch
== 'Z';
3741 char *p
= &own_buf
[3];
3743 p
= unpack_varlen_hex (p
, &addr
);
3744 len
= strtol (p
+ 1, &dataptr
, 16);
3748 struct breakpoint
*bp
;
3750 bp
= set_gdb_breakpoint (type
, addr
, len
, &res
);
3755 /* GDB may have sent us a list of *point parameters to
3756 be evaluated on the target's side. Read such list
3757 here. If we already have a list of parameters, GDB
3758 is telling us to drop that list and use this one
3760 clear_breakpoint_conditions_and_commands (bp
);
3761 process_point_options (bp
, &dataptr
);
3765 res
= delete_gdb_breakpoint (type
, addr
, len
);
3773 write_enn (own_buf
);
3777 response_needed
= 0;
3778 if (!target_running ())
3779 /* The packet we received doesn't make sense - but we can't
3780 reply to it, either. */
3783 fprintf (stderr
, "Killing all inferiors\n");
3784 for_each_inferior (&all_processes
, kill_inferior_callback
);
3786 /* When using the extended protocol, we wait with no program
3787 running. The traditional protocol will exit instead. */
3788 if (extended_protocol
)
3790 last_status
.kind
= TARGET_WAITKIND_EXITED
;
3791 last_status
.value
.sig
= GDB_SIGNAL_KILL
;
3799 ptid_t gdb_id
, thread_id
;
3801 require_running (own_buf
);
3803 gdb_id
= read_ptid (&own_buf
[1], NULL
);
3804 thread_id
= gdb_id_to_thread_id (gdb_id
);
3805 if (ptid_equal (thread_id
, null_ptid
))
3807 write_enn (own_buf
);
3811 if (mythread_alive (thread_id
))
3814 write_enn (own_buf
);
3818 response_needed
= 0;
3820 /* Restarting the inferior is only supported in the extended
3822 if (extended_protocol
)
3824 if (target_running ())
3825 for_each_inferior (&all_processes
,
3826 kill_inferior_callback
);
3827 fprintf (stderr
, "GDBserver restarting\n");
3829 /* Wait till we are at 1st instruction in prog. */
3830 if (program_argv
!= NULL
)
3831 start_inferior (program_argv
);
3834 last_status
.kind
= TARGET_WAITKIND_EXITED
;
3835 last_status
.value
.sig
= GDB_SIGNAL_KILL
;
3841 /* It is a request we don't understand. Respond with an
3842 empty packet so that gdb knows that we don't support this
3848 /* Extended (long) request. */
3849 handle_v_requests (own_buf
, packet_len
, &new_packet_len
);
3853 /* It is a request we don't understand. Respond with an empty
3854 packet so that gdb knows that we don't support this
3860 if (new_packet_len
!= -1)
3861 putpkt_binary (own_buf
, new_packet_len
);
3865 response_needed
= 0;
3867 if (!extended_protocol
&& have_ran
&& !target_running ())
3869 /* In non-stop, defer exiting until GDB had a chance to query
3870 the whole vStopped list (until it gets an OK). */
3871 if (QUEUE_is_empty (notif_event_p
, notif_stop
.queue
))
3873 /* Be transparent when GDB is connected through stdio -- no
3874 need to spam GDB's console. */
3875 if (!remote_connection_is_stdio ())
3876 fprintf (stderr
, "GDBserver exiting\n");
3888 /* Event-loop callback for serial events. */
3891 handle_serial_event (int err
, gdb_client_data client_data
)
3894 debug_printf ("handling possible serial event\n");
3896 /* Really handle it. */
3897 if (process_serial_event () < 0)
3900 /* Be sure to not change the selected inferior behind GDB's back.
3901 Important in the non-stop mode asynchronous protocol. */
3902 set_desired_inferior (1);
3907 /* Event-loop callback for target events. */
3910 handle_target_event (int err
, gdb_client_data client_data
)
3913 debug_printf ("handling possible target event\n");
3915 last_ptid
= mywait (minus_one_ptid
, &last_status
,
3918 if (last_status
.kind
== TARGET_WAITKIND_NO_RESUMED
)
3920 /* No RSP support for this yet. */
3922 else if (last_status
.kind
!= TARGET_WAITKIND_IGNORE
)
3924 int pid
= ptid_get_pid (last_ptid
);
3925 struct process_info
*process
= find_process_pid (pid
);
3926 int forward_event
= !gdb_connected () || process
->gdb_detached
;
3928 if (last_status
.kind
== TARGET_WAITKIND_EXITED
3929 || last_status
.kind
== TARGET_WAITKIND_SIGNALLED
)
3931 mark_breakpoints_out (process
);
3932 mourn_inferior (process
);
3936 /* We're reporting this thread as stopped. Update its
3937 "want-stopped" state to what the client wants, until it
3938 gets a new resume action. */
3939 current_inferior
->last_resume_kind
= resume_stop
;
3940 current_inferior
->last_status
= last_status
;
3945 if (!target_running ())
3947 /* The last process exited. We're done. */
3951 if (last_status
.kind
== TARGET_WAITKIND_STOPPED
)
3953 /* A thread stopped with a signal, but gdb isn't
3954 connected to handle it. Pass it down to the
3955 inferior, as if it wasn't being traced. */
3956 struct thread_resume resume_info
;
3959 debug_printf ("GDB not connected; forwarding event %d for"
3961 (int) last_status
.kind
,
3962 target_pid_to_str (last_ptid
));
3964 resume_info
.thread
= last_ptid
;
3965 resume_info
.kind
= resume_continue
;
3966 resume_info
.sig
= gdb_signal_to_host (last_status
.value
.sig
);
3967 (*the_target
->resume
) (&resume_info
, 1);
3969 else if (debug_threads
)
3970 debug_printf ("GDB not connected; ignoring event %d for [%s]\n",
3971 (int) last_status
.kind
,
3972 target_pid_to_str (last_ptid
));
3976 struct vstop_notif
*vstop_notif
3977 = xmalloc (sizeof (struct vstop_notif
));
3979 vstop_notif
->status
= last_status
;
3980 vstop_notif
->ptid
= last_ptid
;
3981 /* Push Stop notification. */
3982 notif_push (¬if_stop
,
3983 (struct notif_event
*) vstop_notif
);
3987 /* Be sure to not change the selected inferior behind GDB's back.
3988 Important in the non-stop mode asynchronous protocol. */
3989 set_desired_inferior (1);