1 /* Main code for remote server for GDB.
2 Copyright (C) 1989, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
35 unsigned long cont_thread
;
36 unsigned long general_thread
;
37 unsigned long step_thread
;
41 static int extended_protocol
;
43 static int response_needed
;
44 static int exit_requested
;
48 static char **program_argv
, **wrapper_argv
;
50 /* Enable miscellaneous debugging output. The name is historical - it
51 was originally used to debug LinuxThreads support. */
54 int pass_signals
[TARGET_SIGNAL_LAST
];
58 const char *gdbserver_xmltarget
;
60 /* The PID of the originally created or attached inferior. Used to
61 send signals to the process when GDB sends us an asynchronous interrupt
62 (user hitting Control-C in the client), and to wait for the child to exit
63 when no longer debugging it. */
65 unsigned long signal_pid
;
68 /* A file descriptor for the controlling terminal. */
71 /* TERMINAL_FD's original foreground group. */
72 pid_t old_foreground_pgrp
;
74 /* Hand back terminal ownership to the original foreground group. */
77 restore_old_foreground_pgrp (void)
79 tcsetpgrp (terminal_fd
, old_foreground_pgrp
);
83 /* Set if you want to disable optional thread related packets support
84 in gdbserver, for the sake of testing GDB against stubs that don't
86 int disable_packet_vCont
;
87 int disable_packet_Tthread
;
88 int disable_packet_qC
;
89 int disable_packet_qfThreadInfo
;
91 /* Last status reported to GDB. */
92 static struct target_waitstatus last_status
;
93 static unsigned long last_ptid
;
96 static unsigned char *mem_buf
;
98 /* Structure holding information relative to a single stop reply. We
99 keep a queue of these (really a singly-linked list) to push to GDB
103 /* Pointer to next in list. */
104 struct vstop_notif
*next
;
106 /* Thread or process that got the event. */
110 struct target_waitstatus status
;
113 /* The pending stop replies list head. */
114 static struct vstop_notif
*notif_queue
= NULL
;
116 /* Put a stop reply to the stop reply queue. */
119 queue_stop_reply (unsigned long ptid
, struct target_waitstatus
*status
)
121 struct vstop_notif
*new_notif
;
123 new_notif
= malloc (sizeof (*new_notif
));
124 new_notif
->next
= NULL
;
125 new_notif
->ptid
= ptid
;
126 new_notif
->status
= *status
;
130 struct vstop_notif
*tail
;
131 for (tail
= notif_queue
;
135 tail
->next
= new_notif
;
138 notif_queue
= new_notif
;
143 struct vstop_notif
*n
;
145 for (n
= notif_queue
; n
; n
= n
->next
)
148 fprintf (stderr
, "pending stop replies: %d\n", i
);
152 /* Place an event in the stop reply queue, and push a notification if
153 we aren't sending one yet. */
156 push_event (unsigned long ptid
, struct target_waitstatus
*status
)
158 queue_stop_reply (ptid
, status
);
160 /* If this is the first stop reply in the queue, then inform GDB
161 about it, by sending a Stop notification. */
162 if (notif_queue
->next
== NULL
)
167 prepare_resume_reply (p
,
168 notif_queue
->ptid
, ¬if_queue
->status
);
169 putpkt_notif (own_buf
);
173 /* Get rid of the currently pending stop replies. */
176 discard_queued_stop_replies (void)
178 struct vstop_notif
*next
;
182 next
= notif_queue
->next
;
189 /* If there are more stop replies to push, push one now. */
192 send_next_stop_reply (char *own_buf
)
195 prepare_resume_reply (own_buf
,
197 ¬if_queue
->status
);
203 target_running (void)
205 return all_threads
.head
!= NULL
;
209 start_inferior (char **argv
)
211 char **new_argv
= argv
;
214 if (wrapper_argv
!= NULL
)
218 for (i
= 0; wrapper_argv
[i
] != NULL
; i
++)
220 for (i
= 0; argv
[i
] != NULL
; i
++)
222 new_argv
= alloca (sizeof (char *) * count
);
224 for (i
= 0; wrapper_argv
[i
] != NULL
; i
++)
225 new_argv
[count
++] = wrapper_argv
[i
];
226 for (i
= 0; argv
[i
] != NULL
; i
++)
227 new_argv
[count
++] = argv
[i
];
228 new_argv
[count
] = NULL
;
232 signal (SIGTTOU
, SIG_DFL
);
233 signal (SIGTTIN
, SIG_DFL
);
236 signal_pid
= create_inferior (new_argv
[0], new_argv
);
238 /* FIXME: we don't actually know at this point that the create
239 actually succeeded. We won't know that until we wait. */
240 fprintf (stderr
, "Process %s created; pid = %ld\n", argv
[0],
245 signal (SIGTTOU
, SIG_IGN
);
246 signal (SIGTTIN
, SIG_IGN
);
247 terminal_fd
= fileno (stderr
);
248 old_foreground_pgrp
= tcgetpgrp (terminal_fd
);
249 tcsetpgrp (terminal_fd
, signal_pid
);
250 atexit (restore_old_foreground_pgrp
);
253 if (wrapper_argv
!= NULL
)
255 struct thread_resume resume_info
;
258 resume_info
.thread
= -1;
259 resume_info
.kind
= resume_continue
;
262 ptid
= mywait (&last_status
, 0, 0);
264 if (last_status
.kind
!= TARGET_WAITKIND_STOPPED
)
269 (*the_target
->resume
) (&resume_info
, 1);
271 mywait (&last_status
, 0, 0);
272 if (last_status
.kind
!= TARGET_WAITKIND_STOPPED
)
275 while (last_status
.value
.sig
!= TARGET_SIGNAL_TRAP
);
280 /* Wait till we are at 1st instruction in program, return new pid
281 (assuming success). */
282 last_ptid
= mywait (&last_status
, 0, 0);
288 attach_inferior (int pid
)
290 /* myattach should return -1 if attaching is unsupported,
291 0 if it succeeded, and call error() otherwise. */
293 if (myattach (pid
) != 0)
298 fprintf (stderr
, "Attached; pid = %d\n", pid
);
301 /* FIXME - It may be that we should get the SIGNAL_PID from the
302 attach function, so that it can be the main thread instead of
303 whichever we were told to attach to. */
308 last_ptid
= mywait (&last_status
, 0, 0);
310 /* GDB knows to ignore the first SIGSTOP after attaching to a running
311 process using the "attach" command, but this is different; it's
312 just using "target remote". Pretend it's just starting up. */
313 if (last_status
.kind
== TARGET_WAITKIND_STOPPED
314 && last_status
.value
.sig
== TARGET_SIGNAL_STOP
)
315 last_status
.value
.sig
= TARGET_SIGNAL_TRAP
;
321 extern int remote_debug
;
323 /* Decode a qXfer read request. Return 0 if everything looks OK,
327 decode_xfer_read (char *buf
, char **annex
, CORE_ADDR
*ofs
, unsigned int *len
)
329 /* Extract and NUL-terminate the annex. */
331 while (*buf
&& *buf
!= ':')
337 /* After the read marker and annex, qXfer looks like a
338 traditional 'm' packet. */
339 decode_m_packet (buf
, ofs
, len
);
344 /* Write the response to a successful qXfer read. Returns the
345 length of the (binary) data stored in BUF, corresponding
346 to as much of DATA/LEN as we could fit. IS_MORE controls
347 the first character of the response. */
349 write_qxfer_response (char *buf
, const void *data
, int len
, int is_more
)
358 return remote_escape_output (data
, len
, (unsigned char *) buf
+ 1, &out_len
,
362 /* Handle all of the extended 'Q' packets. */
364 handle_general_set (char *own_buf
)
366 if (strncmp ("QPassSignals:", own_buf
, strlen ("QPassSignals:")) == 0)
368 int numsigs
= (int) TARGET_SIGNAL_LAST
, i
;
369 const char *p
= own_buf
+ strlen ("QPassSignals:");
372 p
= decode_address_to_semicolon (&cursig
, p
);
373 for (i
= 0; i
< numsigs
; i
++)
379 /* Keep looping, to clear the remaining signals. */
382 p
= decode_address_to_semicolon (&cursig
, p
);
387 strcpy (own_buf
, "OK");
391 if (strcmp (own_buf
, "QStartNoAckMode") == 0)
395 fprintf (stderr
, "[noack mode enabled]\n");
404 if (strncmp (own_buf
, "QNonStop:", 9) == 0)
406 char *mode
= own_buf
+ 9;
410 if (strcmp (mode
, "0") == 0)
412 else if (strcmp (mode
, "1") == 0)
416 /* We don't know what this mode is, so complain to
418 fprintf (stderr
, "Unknown non-stop mode requested: %s\n",
424 req_str
= req
? "non-stop" : "all-stop";
425 if (start_non_stop (req
) != 0)
427 fprintf (stderr
, "Setting %s mode failed\n", req_str
);
435 fprintf (stderr
, "[%s mode enabled]\n", req_str
);
441 /* Otherwise we didn't know what packet it was. Say we didn't
447 get_features_xml (const char *annex
)
449 /* gdbserver_xmltarget defines what to return when looking
450 for the "target.xml" file. Its contents can either be
451 verbatim XML code (prefixed with a '@') or else the name
452 of the actual XML file to be used in place of "target.xml".
454 This variable is set up from the auto-generated
455 init_registers_... routine for the current target. */
457 if (gdbserver_xmltarget
458 && strcmp (annex
, "target.xml") == 0)
460 if (*gdbserver_xmltarget
== '@')
461 return gdbserver_xmltarget
+ 1;
463 annex
= gdbserver_xmltarget
;
468 extern const char *const xml_builtin
[][2];
471 /* Look for the annex. */
472 for (i
= 0; xml_builtin
[i
][0] != NULL
; i
++)
473 if (strcmp (annex
, xml_builtin
[i
][0]) == 0)
476 if (xml_builtin
[i
][0] != NULL
)
477 return xml_builtin
[i
][1];
485 monitor_show_help (void)
487 monitor_output ("The following monitor commands are supported:\n");
488 monitor_output (" set debug <0|1>\n");
489 monitor_output (" Enable general debugging messages\n");
490 monitor_output (" set remote-debug <0|1>\n");
491 monitor_output (" Enable remote protocol debugging messages\n");
492 monitor_output (" exit\n");
493 monitor_output (" Quit GDBserver\n");
496 /* Subroutine of handle_search_memory to simplify it. */
499 handle_search_memory_1 (CORE_ADDR start_addr
, CORE_ADDR search_space_len
,
500 gdb_byte
*pattern
, unsigned pattern_len
,
501 gdb_byte
*search_buf
,
502 unsigned chunk_size
, unsigned search_buf_size
,
503 CORE_ADDR
*found_addrp
)
505 /* Prime the search buffer. */
507 if (read_inferior_memory (start_addr
, search_buf
, search_buf_size
) != 0)
509 warning ("Unable to access target memory at 0x%lx, halting search.",
514 /* Perform the search.
516 The loop is kept simple by allocating [N + pattern-length - 1] bytes.
517 When we've scanned N bytes we copy the trailing bytes to the start and
518 read in another N bytes. */
520 while (search_space_len
>= pattern_len
)
523 unsigned nr_search_bytes
= (search_space_len
< search_buf_size
527 found_ptr
= memmem (search_buf
, nr_search_bytes
, pattern
, pattern_len
);
529 if (found_ptr
!= NULL
)
531 CORE_ADDR found_addr
= start_addr
+ (found_ptr
- search_buf
);
532 *found_addrp
= found_addr
;
536 /* Not found in this chunk, skip to next chunk. */
538 /* Don't let search_space_len wrap here, it's unsigned. */
539 if (search_space_len
>= chunk_size
)
540 search_space_len
-= chunk_size
;
542 search_space_len
= 0;
544 if (search_space_len
>= pattern_len
)
546 unsigned keep_len
= search_buf_size
- chunk_size
;
547 CORE_ADDR read_addr
= start_addr
+ keep_len
;
550 /* Copy the trailing part of the previous iteration to the front
551 of the buffer for the next iteration. */
552 memcpy (search_buf
, search_buf
+ chunk_size
, keep_len
);
554 nr_to_read
= (search_space_len
- keep_len
< chunk_size
555 ? search_space_len
- keep_len
558 if (read_inferior_memory (read_addr
, search_buf
+ keep_len
,
561 warning ("Unable to access target memory at 0x%lx, halting search.",
566 start_addr
+= chunk_size
;
575 /* Handle qSearch:memory packets. */
578 handle_search_memory (char *own_buf
, int packet_len
)
580 CORE_ADDR start_addr
;
581 CORE_ADDR search_space_len
;
583 unsigned int pattern_len
;
584 /* NOTE: also defined in find.c testcase. */
585 #define SEARCH_CHUNK_SIZE 16000
586 const unsigned chunk_size
= SEARCH_CHUNK_SIZE
;
587 /* Buffer to hold memory contents for searching. */
588 gdb_byte
*search_buf
;
589 unsigned search_buf_size
;
591 CORE_ADDR found_addr
;
592 int cmd_name_len
= sizeof ("qSearch:memory:") - 1;
594 pattern
= malloc (packet_len
);
597 error ("Unable to allocate memory to perform the search");
598 strcpy (own_buf
, "E00");
601 if (decode_search_memory_packet (own_buf
+ cmd_name_len
,
602 packet_len
- cmd_name_len
,
603 &start_addr
, &search_space_len
,
604 pattern
, &pattern_len
) < 0)
607 error ("Error in parsing qSearch:memory packet");
608 strcpy (own_buf
, "E00");
612 search_buf_size
= chunk_size
+ pattern_len
- 1;
614 /* No point in trying to allocate a buffer larger than the search space. */
615 if (search_space_len
< search_buf_size
)
616 search_buf_size
= search_space_len
;
618 search_buf
= malloc (search_buf_size
);
619 if (search_buf
== NULL
)
622 error ("Unable to allocate memory to perform the search");
623 strcpy (own_buf
, "E00");
627 found
= handle_search_memory_1 (start_addr
, search_space_len
,
628 pattern
, pattern_len
,
629 search_buf
, chunk_size
, search_buf_size
,
633 sprintf (own_buf
, "1,%lx", (long) found_addr
);
635 strcpy (own_buf
, "0");
637 strcpy (own_buf
, "E00");
643 #define require_running(BUF) \
644 if (!target_running ()) \
650 /* Handle all of the extended 'q' packets. */
652 handle_query (char *own_buf
, int packet_len
, int *new_packet_len_p
)
654 static struct inferior_list_entry
*thread_ptr
;
656 /* Reply the current thread id. */
657 if (strcmp ("qC", own_buf
) == 0 && !disable_packet_qC
)
659 unsigned long gdb_id
;
660 require_running (own_buf
);
662 if (general_thread
!= 0 && general_thread
!= -1)
663 gdb_id
= general_thread
;
666 thread_ptr
= all_threads
.head
;
667 gdb_id
= thread_to_gdb_id ((struct thread_info
*)thread_ptr
);
670 sprintf (own_buf
, "QC%lx", gdb_id
);
674 if (strcmp ("qSymbol::", own_buf
) == 0)
676 if (target_running () && the_target
->look_up_symbols
!= NULL
)
677 (*the_target
->look_up_symbols
) ();
679 strcpy (own_buf
, "OK");
683 if (!disable_packet_qfThreadInfo
)
685 if (strcmp ("qfThreadInfo", own_buf
) == 0)
687 require_running (own_buf
);
688 thread_ptr
= all_threads
.head
;
689 sprintf (own_buf
, "m%x",
690 thread_to_gdb_id ((struct thread_info
*)thread_ptr
));
691 thread_ptr
= thread_ptr
->next
;
695 if (strcmp ("qsThreadInfo", own_buf
) == 0)
697 require_running (own_buf
);
698 if (thread_ptr
!= NULL
)
700 sprintf (own_buf
, "m%x",
701 thread_to_gdb_id ((struct thread_info
*)thread_ptr
));
702 thread_ptr
= thread_ptr
->next
;
707 sprintf (own_buf
, "l");
713 if (the_target
->read_offsets
!= NULL
714 && strcmp ("qOffsets", own_buf
) == 0)
716 CORE_ADDR text
, data
;
718 require_running (own_buf
);
719 if (the_target
->read_offsets (&text
, &data
))
720 sprintf (own_buf
, "Text=%lX;Data=%lX;Bss=%lX",
721 (long)text
, (long)data
, (long)data
);
728 if (the_target
->qxfer_spu
!= NULL
729 && strncmp ("qXfer:spu:read:", own_buf
, 15) == 0)
735 unsigned char *spu_buf
;
737 require_running (own_buf
);
738 strcpy (own_buf
, "E00");
739 if (decode_xfer_read (own_buf
+ 15, &annex
, &ofs
, &len
) < 0)
741 if (len
> PBUFSIZ
- 2)
743 spu_buf
= malloc (len
+ 1);
747 n
= (*the_target
->qxfer_spu
) (annex
, spu_buf
, NULL
, ofs
, len
+ 1);
751 *new_packet_len_p
= write_qxfer_response (own_buf
, spu_buf
, len
, 1);
753 *new_packet_len_p
= write_qxfer_response (own_buf
, spu_buf
, n
, 0);
759 if (the_target
->qxfer_spu
!= NULL
760 && strncmp ("qXfer:spu:write:", own_buf
, 16) == 0)
766 unsigned char *spu_buf
;
768 require_running (own_buf
);
769 strcpy (own_buf
, "E00");
770 spu_buf
= malloc (packet_len
- 15);
773 if (decode_xfer_write (own_buf
+ 16, packet_len
- 16, &annex
,
774 &ofs
, &len
, spu_buf
) < 0)
780 n
= (*the_target
->qxfer_spu
)
781 (annex
, NULL
, (unsigned const char *)spu_buf
, ofs
, len
);
785 sprintf (own_buf
, "%x", n
);
791 if (the_target
->read_auxv
!= NULL
792 && strncmp ("qXfer:auxv:read:", own_buf
, 16) == 0)
800 require_running (own_buf
);
802 /* Reject any annex; grab the offset and length. */
803 if (decode_xfer_read (own_buf
+ 16, &annex
, &ofs
, &len
) < 0
806 strcpy (own_buf
, "E00");
810 /* Read one extra byte, as an indicator of whether there is
812 if (len
> PBUFSIZ
- 2)
814 data
= malloc (len
+ 1);
820 n
= (*the_target
->read_auxv
) (ofs
, data
, len
+ 1);
824 *new_packet_len_p
= write_qxfer_response (own_buf
, data
, len
, 1);
826 *new_packet_len_p
= write_qxfer_response (own_buf
, data
, n
, 0);
833 if (strncmp ("qXfer:features:read:", own_buf
, 20) == 0)
836 unsigned int len
, total_len
;
837 const char *document
;
840 require_running (own_buf
);
842 /* Grab the annex, offset, and length. */
843 if (decode_xfer_read (own_buf
+ 20, &annex
, &ofs
, &len
) < 0)
845 strcpy (own_buf
, "E00");
849 /* Now grab the correct annex. */
850 document
= get_features_xml (annex
);
851 if (document
== NULL
)
853 strcpy (own_buf
, "E00");
857 total_len
= strlen (document
);
858 if (len
> PBUFSIZ
- 2)
863 else if (len
< total_len
- ofs
)
864 *new_packet_len_p
= write_qxfer_response (own_buf
, document
+ ofs
,
867 *new_packet_len_p
= write_qxfer_response (own_buf
, document
+ ofs
,
873 if (strncmp ("qXfer:libraries:read:", own_buf
, 21) == 0)
876 unsigned int len
, total_len
;
878 struct inferior_list_entry
*dll_ptr
;
881 require_running (own_buf
);
883 /* Reject any annex; grab the offset and length. */
884 if (decode_xfer_read (own_buf
+ 21, &annex
, &ofs
, &len
) < 0
887 strcpy (own_buf
, "E00");
891 /* Over-estimate the necessary memory. Assume that every character
892 in the library name must be escaped. */
894 for (dll_ptr
= all_dlls
.head
; dll_ptr
!= NULL
; dll_ptr
= dll_ptr
->next
)
895 total_len
+= 128 + 6 * strlen (((struct dll_info
*) dll_ptr
)->name
);
897 document
= malloc (total_len
);
898 if (document
== NULL
)
903 strcpy (document
, "<library-list>\n");
904 p
= document
+ strlen (document
);
906 for (dll_ptr
= all_dlls
.head
; dll_ptr
!= NULL
; dll_ptr
= dll_ptr
->next
)
908 struct dll_info
*dll
= (struct dll_info
*) dll_ptr
;
911 strcpy (p
, " <library name=\"");
913 name
= xml_escape_text (dll
->name
);
917 strcpy (p
, "\"><segment address=\"");
919 sprintf (p
, "0x%lx", (long) dll
->base_addr
);
921 strcpy (p
, "\"/></library>\n");
925 strcpy (p
, "</library-list>\n");
927 total_len
= strlen (document
);
928 if (len
> PBUFSIZ
- 2)
933 else if (len
< total_len
- ofs
)
934 *new_packet_len_p
= write_qxfer_response (own_buf
, document
+ ofs
,
937 *new_packet_len_p
= write_qxfer_response (own_buf
, document
+ ofs
,
944 if (the_target
->qxfer_osdata
!= NULL
945 && strncmp ("qXfer:osdata:read:", own_buf
, 18) == 0)
951 unsigned char *workbuf
;
953 strcpy (own_buf
, "E00");
954 if (decode_xfer_read (own_buf
+ 18, &annex
, &ofs
, &len
) < 0)
956 if (len
> PBUFSIZ
- 2)
958 workbuf
= malloc (len
+ 1);
962 n
= (*the_target
->qxfer_osdata
) (annex
, workbuf
, NULL
, ofs
, len
+ 1);
966 *new_packet_len_p
= write_qxfer_response (own_buf
, workbuf
, len
, 1);
968 *new_packet_len_p
= write_qxfer_response (own_buf
, workbuf
, n
, 0);
974 if (the_target
->qxfer_siginfo
!= NULL
975 && strncmp ("qXfer:siginfo:read:", own_buf
, 19) == 0)
983 require_running (own_buf
);
985 /* Reject any annex; grab the offset and length. */
986 if (decode_xfer_read (own_buf
+ 19, &annex
, &ofs
, &len
) < 0
989 strcpy (own_buf
, "E00");
993 /* Read one extra byte, as an indicator of whether there is
995 if (len
> PBUFSIZ
- 2)
997 data
= malloc (len
+ 1);
1000 n
= (*the_target
->qxfer_siginfo
) (annex
, data
, NULL
, ofs
, len
+ 1);
1002 write_enn (own_buf
);
1004 *new_packet_len_p
= write_qxfer_response (own_buf
, data
, len
, 1);
1006 *new_packet_len_p
= write_qxfer_response (own_buf
, data
, n
, 0);
1012 if (the_target
->qxfer_siginfo
!= NULL
1013 && strncmp ("qXfer:siginfo:write:", own_buf
, 20) == 0)
1019 unsigned char *data
;
1021 require_running (own_buf
);
1023 strcpy (own_buf
, "E00");
1024 data
= malloc (packet_len
- 19);
1027 if (decode_xfer_write (own_buf
+ 20, packet_len
- 20, &annex
,
1028 &ofs
, &len
, data
) < 0)
1034 n
= (*the_target
->qxfer_siginfo
)
1035 (annex
, NULL
, (unsigned const char *)data
, ofs
, len
);
1037 write_enn (own_buf
);
1039 sprintf (own_buf
, "%x", n
);
1045 /* Protocol features query. */
1046 if (strncmp ("qSupported", own_buf
, 10) == 0
1047 && (own_buf
[10] == ':' || own_buf
[10] == '\0'))
1049 sprintf (own_buf
, "PacketSize=%x;QPassSignals+", PBUFSIZ
- 1);
1051 /* We do not have any hook to indicate whether the target backend
1052 supports qXfer:libraries:read, so always report it. */
1053 strcat (own_buf
, ";qXfer:libraries:read+");
1055 if (the_target
->read_auxv
!= NULL
)
1056 strcat (own_buf
, ";qXfer:auxv:read+");
1058 if (the_target
->qxfer_spu
!= NULL
)
1059 strcat (own_buf
, ";qXfer:spu:read+;qXfer:spu:write+");
1061 if (the_target
->qxfer_siginfo
!= NULL
)
1062 strcat (own_buf
, ";qXfer:siginfo:read+;qXfer:siginfo:write+");
1064 /* We always report qXfer:features:read, as targets may
1065 install XML files on a subsequent call to arch_setup.
1066 If we reported to GDB on startup that we don't support
1067 qXfer:feature:read at all, we will never be re-queried. */
1068 strcat (own_buf
, ";qXfer:features:read+");
1070 if (transport_is_reliable
)
1071 strcat (own_buf
, ";QStartNoAckMode+");
1073 if (the_target
->qxfer_osdata
!= NULL
)
1074 strcat (own_buf
, ";qXfer:osdata:read+");
1076 if (target_supports_non_stop ())
1077 strcat (own_buf
, ";QNonStop+");
1082 /* Thread-local storage support. */
1083 if (the_target
->get_tls_address
!= NULL
1084 && strncmp ("qGetTLSAddr:", own_buf
, 12) == 0)
1086 char *p
= own_buf
+ 12;
1087 CORE_ADDR parts
[2], address
= 0;
1089 unsigned long ptid
= 0;
1091 require_running (own_buf
);
1093 for (i
= 0; i
< 3; i
++)
1101 p2
= strchr (p
, ',');
1114 ptid
= strtoul (p
, NULL
, 16);
1116 decode_address (&parts
[i
- 1], p
, len
);
1120 if (p
!= NULL
|| i
< 3)
1124 struct thread_info
*thread
= gdb_id_to_thread (ptid
);
1129 err
= the_target
->get_tls_address (thread
, parts
[0], parts
[1],
1135 sprintf (own_buf
, "%llx", address
);
1140 write_enn (own_buf
);
1144 /* Otherwise, pretend we do not understand this packet. */
1147 /* Handle "monitor" commands. */
1148 if (strncmp ("qRcmd,", own_buf
, 6) == 0)
1150 char *mon
= malloc (PBUFSIZ
);
1151 int len
= strlen (own_buf
+ 6);
1155 write_enn (own_buf
);
1159 if ((len
% 2) != 0 || unhexify (mon
, own_buf
+ 6, len
/ 2) != len
/ 2)
1161 write_enn (own_buf
);
1165 mon
[len
/ 2] = '\0';
1169 if (strcmp (mon
, "set debug 1") == 0)
1172 monitor_output ("Debug output enabled.\n");
1174 else if (strcmp (mon
, "set debug 0") == 0)
1177 monitor_output ("Debug output disabled.\n");
1179 else if (strcmp (mon
, "set remote-debug 1") == 0)
1182 monitor_output ("Protocol debug output enabled.\n");
1184 else if (strcmp (mon
, "set remote-debug 0") == 0)
1187 monitor_output ("Protocol debug output disabled.\n");
1189 else if (strcmp (mon
, "help") == 0)
1190 monitor_show_help ();
1191 else if (strcmp (mon
, "exit") == 0)
1195 monitor_output ("Unknown monitor command.\n\n");
1196 monitor_show_help ();
1197 write_enn (own_buf
);
1204 if (strncmp ("qSearch:memory:", own_buf
, sizeof ("qSearch:memory:") - 1) == 0)
1206 require_running (own_buf
);
1207 handle_search_memory (own_buf
, packet_len
);
1211 if (strcmp (own_buf
, "qAttached") == 0)
1213 require_running (own_buf
);
1214 strcpy (own_buf
, attached
? "1" : "0");
1218 /* Otherwise we didn't know what packet it was. Say we didn't
1223 /* Parse vCont packets. */
1225 handle_v_cont (char *own_buf
)
1229 struct thread_resume
*resume_info
;
1230 struct thread_resume default_action
= {0};
1232 /* Count the number of semicolons in the packet. There should be one
1233 for every action. */
1239 p
= strchr (p
, ';');
1242 resume_info
= malloc (n
* sizeof (resume_info
[0]));
1243 if (resume_info
== NULL
)
1251 if (p
[0] == 's' || p
[0] == 'S')
1252 resume_info
[i
].kind
= resume_step
;
1253 else if (p
[0] == 'c' || p
[0] == 'C')
1254 resume_info
[i
].kind
= resume_continue
;
1255 else if (p
[0] == 't')
1256 resume_info
[i
].kind
= resume_stop
;
1260 if (p
[0] == 'S' || p
[0] == 'C')
1263 sig
= strtol (p
+ 1, &q
, 16);
1268 if (!target_signal_to_host_p (sig
))
1270 resume_info
[i
].sig
= target_signal_to_host (sig
);
1274 resume_info
[i
].sig
= 0;
1280 resume_info
[i
].thread
= -1;
1281 default_action
= resume_info
[i
];
1283 /* Note: we don't increment i here, we'll overwrite this entry
1284 the next time through. */
1286 else if (p
[0] == ':')
1288 unsigned int gdb_id
= strtoul (p
+ 1, &q
, 16);
1289 unsigned long thread_id
;
1294 if (p
[0] != ';' && p
[0] != 0)
1297 thread_id
= gdb_id_to_thread_id (gdb_id
);
1299 resume_info
[i
].thread
= thread_id
;
1308 resume_info
[i
] = default_action
;
1310 /* Still used in occasional places in the backend. */
1312 && resume_info
[0].thread
!= -1
1313 && resume_info
[0].kind
!= resume_stop
)
1314 cont_thread
= resume_info
[0].thread
;
1317 set_desired_inferior (0);
1322 (*the_target
->resume
) (resume_info
, n
);
1330 last_ptid
= mywait (&last_status
, 0, 1);
1331 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
1332 disable_async_io ();
1337 write_enn (own_buf
);
1342 /* Attach to a new program. Return 1 if successful, 0 if failure. */
1344 handle_v_attach (char *own_buf
)
1348 pid
= strtol (own_buf
+ 8, NULL
, 16);
1349 if (pid
!= 0 && attach_inferior (pid
) == 0)
1351 /* Don't report shared library events after attaching, even if
1352 some libraries are preloaded. GDB will always poll the
1353 library list. Avoids the "stopped by shared library event"
1354 notice on the GDB side. */
1359 /* In non-stop, we don't send a resume reply. Stop events
1360 will follow up using the normal notification
1365 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
1371 write_enn (own_buf
);
1376 /* Run a new program. Return 1 if successful, 0 if failure. */
1378 handle_v_run (char *own_buf
)
1380 char *p
, *next_p
, **new_argv
;
1384 for (p
= own_buf
+ strlen ("vRun;"); p
&& *p
; p
= strchr (p
, ';'))
1390 new_argv
= calloc (new_argc
+ 2, sizeof (char *));
1391 if (new_argv
== NULL
)
1393 write_enn (own_buf
);
1398 for (p
= own_buf
+ strlen ("vRun;"); *p
; p
= next_p
)
1400 next_p
= strchr (p
, ';');
1402 next_p
= p
+ strlen (p
);
1404 if (i
== 0 && p
== next_p
)
1408 /* FIXME: Fail request if out of memory instead of dying. */
1409 new_argv
[i
] = xmalloc (1 + (next_p
- p
) / 2);
1410 unhexify (new_argv
[i
], p
, (next_p
- p
) / 2);
1411 new_argv
[i
][(next_p
- p
) / 2] = '\0';
1420 if (new_argv
[0] == NULL
)
1422 /* GDB didn't specify a program to run. Use the program from the
1423 last run with the new argument list. */
1425 if (program_argv
== NULL
)
1427 /* FIXME: new_argv memory leak */
1428 write_enn (own_buf
);
1432 new_argv
[0] = strdup (program_argv
[0]);
1433 if (new_argv
[0] == NULL
)
1435 /* FIXME: new_argv memory leak */
1436 write_enn (own_buf
);
1441 /* Free the old argv and install the new one. */
1442 freeargv (program_argv
);
1443 program_argv
= new_argv
;
1445 start_inferior (program_argv
);
1446 if (last_status
.kind
== TARGET_WAITKIND_STOPPED
)
1448 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
1450 /* In non-stop, sending a resume reply doesn't set the general
1451 thread, but GDB assumes a vRun sets it (this is so GDB can
1452 query which is the main thread of the new inferior. */
1454 general_thread
= last_ptid
;
1460 write_enn (own_buf
);
1465 /* Handle a 'vStopped' packet. */
1467 handle_v_stopped (char *own_buf
)
1469 /* If we're waiting for GDB to acknowledge a pending stop reply,
1470 consider that done. */
1473 struct vstop_notif
*head
;
1476 fprintf (stderr
, "vStopped: acking %ld\n", notif_queue
->ptid
);
1479 notif_queue
= notif_queue
->next
;
1483 /* Push another stop reply, or if there are no more left, an OK. */
1484 send_next_stop_reply (own_buf
);
1487 /* Handle all of the extended 'v' packets. */
1489 handle_v_requests (char *own_buf
, int packet_len
, int *new_packet_len
)
1491 if (!disable_packet_vCont
)
1493 if (strncmp (own_buf
, "vCont;", 6) == 0)
1495 require_running (own_buf
);
1496 handle_v_cont (own_buf
);
1500 if (strncmp (own_buf
, "vCont?", 6) == 0)
1502 strcpy (own_buf
, "vCont;c;C;s;S;t");
1507 if (strncmp (own_buf
, "vFile:", 6) == 0
1508 && handle_vFile (own_buf
, packet_len
, new_packet_len
))
1511 if (strncmp (own_buf
, "vAttach;", 8) == 0)
1513 if (target_running ())
1515 fprintf (stderr
, "Already debugging a process\n");
1516 write_enn (own_buf
);
1519 handle_v_attach (own_buf
);
1523 if (strncmp (own_buf
, "vRun;", 5) == 0)
1525 if (target_running ())
1527 fprintf (stderr
, "Already debugging a process\n");
1528 write_enn (own_buf
);
1531 handle_v_run (own_buf
);
1535 if (strncmp (own_buf
, "vStopped", 8) == 0)
1537 handle_v_stopped (own_buf
);
1541 /* Otherwise we didn't know what packet it was. Say we didn't
1547 /* Resume inferior and wait for another event. In non-stop mode,
1548 don't really wait here, but return immediatelly to the event
1551 myresume (char *own_buf
, int step
, int sig
)
1553 struct thread_resume resume_info
[2];
1555 int valid_cont_thread
;
1557 set_desired_inferior (0);
1559 valid_cont_thread
= (cont_thread
!= 0 && cont_thread
!= -1);
1561 if (step
|| sig
|| valid_cont_thread
)
1563 resume_info
[0].thread
1564 = ((struct inferior_list_entry
*) current_inferior
)->id
;
1566 resume_info
[0].kind
= resume_step
;
1568 resume_info
[0].kind
= resume_continue
;
1569 resume_info
[0].sig
= sig
;
1573 if (!valid_cont_thread
)
1575 resume_info
[n
].thread
= -1;
1576 resume_info
[n
].kind
= resume_continue
;
1577 resume_info
[n
].sig
= 0;
1584 (*the_target
->resume
) (resume_info
, n
);
1590 last_ptid
= mywait (&last_status
, 0, 1);
1591 prepare_resume_reply (own_buf
, last_ptid
, &last_status
);
1592 disable_async_io ();
1596 /* Callback for for_each_inferior. Make a new stop reply for each
1600 queue_stop_reply_callback (struct inferior_list_entry
*entry
)
1602 struct target_waitstatus status
;
1604 status
.kind
= TARGET_WAITKIND_STOPPED
;
1605 status
.value
.sig
= TARGET_SIGNAL_TRAP
;
1607 /* Pass the last stop reply back to GDB, but don't notify. */
1608 queue_stop_reply (entry
->id
, &status
);
1611 /* Status handler for the '?' packet. */
1614 handle_status (char *own_buf
)
1616 struct target_waitstatus status
;
1617 status
.kind
= TARGET_WAITKIND_STOPPED
;
1618 status
.value
.sig
= TARGET_SIGNAL_TRAP
;
1620 /* In non-stop mode, we must send a stop reply for each stopped
1621 thread. In all-stop mode, just send one for the first stopped
1626 discard_queued_stop_replies ();
1627 for_each_inferior (&all_threads
, queue_stop_reply_callback
);
1629 /* The first is sent immediatly. OK is sent if there is no
1630 stopped thread, which is the same handling of the vStopped
1631 packet (by design). */
1632 send_next_stop_reply (own_buf
);
1636 if (all_threads
.head
)
1637 prepare_resume_reply (own_buf
,
1638 all_threads
.head
->id
, &status
);
1640 strcpy (own_buf
, "W00");
1645 gdbserver_version (void)
1647 printf ("GNU gdbserver %s%s\n"
1648 "Copyright (C) 2009 Free Software Foundation, Inc.\n"
1649 "gdbserver is free software, covered by the GNU General Public License.\n"
1650 "This gdbserver was configured as \"%s\"\n",
1651 PKGVERSION
, version
, host_name
);
1655 gdbserver_usage (FILE *stream
)
1657 fprintf (stream
, "Usage:\tgdbserver [OPTIONS] COMM PROG [ARGS ...]\n"
1658 "\tgdbserver [OPTIONS] --attach COMM PID\n"
1659 "\tgdbserver [OPTIONS] --multi COMM\n"
1661 "COMM may either be a tty device (for serial debugging), or \n"
1662 "HOST:PORT to listen for a TCP connection.\n"
1665 " --debug Enable general debugging output.\n"
1666 " --remote-debug Enable remote protocol debugging output.\n"
1667 " --version Display version information and exit.\n"
1668 " --wrapper WRAPPER -- Run WRAPPER to start new programs.\n");
1669 if (REPORT_BUGS_TO
[0] && stream
== stdout
)
1670 fprintf (stream
, "Report bugs to \"%s\".\n", REPORT_BUGS_TO
);
1674 gdbserver_show_disableable (FILE *stream
)
1676 fprintf (stream
, "Disableable packets:\n"
1677 " vCont \tAll vCont packets\n"
1678 " qC \tQuerying the current thread\n"
1679 " qfThreadInfo\tThread listing\n"
1680 " Tthread \tPassing the thread specifier in the T stop reply packet\n"
1681 " threads \tAll of the above\n");
1685 #undef require_running
1686 #define require_running(BUF) \
1687 if (!target_running ()) \
1694 main (int argc
, char *argv
[])
1698 char *arg_end
, *port
;
1699 char **next_arg
= &argv
[1];
1704 while (*next_arg
!= NULL
&& **next_arg
== '-')
1706 if (strcmp (*next_arg
, "--version") == 0)
1708 gdbserver_version ();
1711 else if (strcmp (*next_arg
, "--help") == 0)
1713 gdbserver_usage (stdout
);
1716 else if (strcmp (*next_arg
, "--attach") == 0)
1718 else if (strcmp (*next_arg
, "--multi") == 0)
1720 else if (strcmp (*next_arg
, "--wrapper") == 0)
1724 wrapper_argv
= next_arg
;
1725 while (*next_arg
!= NULL
&& strcmp (*next_arg
, "--") != 0)
1728 if (next_arg
== wrapper_argv
|| *next_arg
== NULL
)
1730 gdbserver_usage (stderr
);
1734 /* Consume the "--". */
1737 else if (strcmp (*next_arg
, "--debug") == 0)
1739 else if (strcmp (*next_arg
, "--remote-debug") == 0)
1741 else if (strcmp (*next_arg
, "--disable-packet") == 0)
1743 gdbserver_show_disableable (stdout
);
1746 else if (strncmp (*next_arg
,
1747 "--disable-packet=",
1748 sizeof ("--disable-packet=") - 1) == 0)
1750 char *packets
, *tok
;
1752 packets
= *next_arg
+= sizeof ("--disable-packet=") - 1;
1753 for (tok
= strtok (packets
, ",");
1755 tok
= strtok (NULL
, ","))
1757 if (strcmp ("vCont", tok
) == 0)
1758 disable_packet_vCont
= 1;
1759 else if (strcmp ("Tthread", tok
) == 0)
1760 disable_packet_Tthread
= 1;
1761 else if (strcmp ("qC", tok
) == 0)
1762 disable_packet_qC
= 1;
1763 else if (strcmp ("qfThreadInfo", tok
) == 0)
1764 disable_packet_qfThreadInfo
= 1;
1765 else if (strcmp ("threads", tok
) == 0)
1767 disable_packet_vCont
= 1;
1768 disable_packet_Tthread
= 1;
1769 disable_packet_qC
= 1;
1770 disable_packet_qfThreadInfo
= 1;
1774 fprintf (stderr
, "Don't know how to disable \"%s\".\n\n",
1776 gdbserver_show_disableable (stderr
);
1783 fprintf (stderr
, "Unknown argument: %s\n", *next_arg
);
1791 if (setjmp (toplevel
))
1793 fprintf (stderr
, "Exiting\n");
1799 if (port
== NULL
|| (!attach
&& !multi_mode
&& *next_arg
== NULL
))
1801 gdbserver_usage (stderr
);
1808 /* --attach used to come after PORT, so allow it there for
1810 if (*next_arg
!= NULL
&& strcmp (*next_arg
, "--attach") == 0)
1817 && (*next_arg
== NULL
1818 || (*next_arg
)[0] == '\0'
1819 || (pid
= strtoul (*next_arg
, &arg_end
, 0)) == 0
1821 || next_arg
[1] != NULL
))
1826 gdbserver_usage (stderr
);
1830 initialize_async_io ();
1833 own_buf
= xmalloc (PBUFSIZ
+ 1);
1834 mem_buf
= xmalloc (PBUFSIZ
);
1836 if (pid
== 0 && *next_arg
!= NULL
)
1840 n
= argc
- (next_arg
- argv
);
1841 program_argv
= xmalloc (sizeof (char *) * (n
+ 1));
1842 for (i
= 0; i
< n
; i
++)
1843 program_argv
[i
] = xstrdup (next_arg
[i
]);
1844 program_argv
[i
] = NULL
;
1846 /* Wait till we are at first instruction in program. */
1847 start_inferior (program_argv
);
1849 /* We are now (hopefully) stopped at the first instruction of
1850 the target process. This assumes that the target process was
1851 successfully created. */
1855 if (attach_inferior (pid
) == -1)
1856 error ("Attaching not supported on this target");
1858 /* Otherwise succeeded. */
1862 last_status
.kind
= TARGET_WAITKIND_EXITED
;
1863 last_status
.value
.integer
= 0;
1867 /* Don't report shared library events on the initial connection,
1868 even if some libraries are preloaded. Avoids the "stopped by
1869 shared library event" notice on gdb side. */
1872 if (setjmp (toplevel
))
1874 fprintf (stderr
, "Killing inferior\n");
1879 if (last_status
.kind
== TARGET_WAITKIND_EXITED
1880 || last_status
.kind
== TARGET_WAITKIND_SIGNALLED
)
1885 if (!was_running
&& !multi_mode
)
1887 fprintf (stderr
, "No program to debug. GDBserver exiting.\n");
1898 if (setjmp (toplevel
) != 0)
1900 /* An error occurred. */
1901 if (response_needed
)
1903 write_enn (own_buf
);
1908 /* Wait for events. This will return when all event sources are
1909 removed from the event loop. */
1910 start_event_loop ();
1912 /* If an exit was requested (using the "monitor exit" command),
1913 terminate now. The only other way to get here is for
1914 getpkt to fail; close the connection and reopen it at the
1926 fprintf (stderr
, "Remote side has terminated connection. "
1927 "GDBserver will reopen the connection.\n");
1931 /* Event loop callback that handles a serial event. The first byte in
1932 the serial buffer gets us here. We expect characters to arrive at
1933 a brisk pace, so we read the rest of the packet with a blocking
1937 process_serial_event (void)
1946 int new_packet_len
= -1;
1948 /* Used to decide when gdbserver should exit in
1949 multi-mode/remote. */
1950 static int have_ran
= 0;
1953 have_ran
= target_running ();
1955 disable_async_io ();
1957 response_needed
= 0;
1958 packet_len
= getpkt (own_buf
);
1959 if (packet_len
<= 0)
1965 response_needed
= 1;
1972 handle_query (own_buf
, packet_len
, &new_packet_len
);
1975 handle_general_set (own_buf
);
1978 require_running (own_buf
);
1979 fprintf (stderr
, "Detaching from inferior\n");
1980 if (detach_inferior () != 0)
1981 write_enn (own_buf
);
1984 discard_queued_stop_replies ();
1987 if (extended_protocol
)
1989 /* Treat this like a normal program exit. */
1990 last_status
.kind
= TARGET_WAITKIND_EXITED
;
1991 last_status
.value
.integer
= 0;
1992 last_ptid
= signal_pid
;
1994 current_inferior
= NULL
;
2001 /* If we are attached, then we can exit. Otherwise, we
2002 need to hang around doing nothing, until the child is
2012 extended_protocol
= 1;
2016 handle_status (own_buf
);
2019 if (own_buf
[1] == 'c' || own_buf
[1] == 'g' || own_buf
[1] == 's')
2021 unsigned long gdb_id
, thread_id
;
2023 require_running (own_buf
);
2024 gdb_id
= strtoul (&own_buf
[2], NULL
, 16);
2025 if (gdb_id
== 0 || gdb_id
== -1)
2029 thread_id
= gdb_id_to_thread_id (gdb_id
);
2032 write_enn (own_buf
);
2037 if (own_buf
[1] == 'g')
2041 /* GDB is telling us to choose any thread. Check if
2042 the currently selected thread is still valid. If
2043 it is not, select the first available. */
2044 struct thread_info
*thread
=
2045 (struct thread_info
*) find_inferior_id (&all_threads
,
2048 thread_id
= all_threads
.head
->id
;
2051 general_thread
= thread_id
;
2052 set_desired_inferior (1);
2054 else if (own_buf
[1] == 'c')
2055 cont_thread
= thread_id
;
2056 else if (own_buf
[1] == 's')
2057 step_thread
= thread_id
;
2063 /* Silently ignore it so that gdb can extend the protocol
2064 without compatibility headaches. */
2069 require_running (own_buf
);
2070 set_desired_inferior (1);
2071 registers_to_string (own_buf
);
2074 require_running (own_buf
);
2075 set_desired_inferior (1);
2076 registers_from_string (&own_buf
[1]);
2080 require_running (own_buf
);
2081 decode_m_packet (&own_buf
[1], &mem_addr
, &len
);
2082 if (read_inferior_memory (mem_addr
, mem_buf
, len
) == 0)
2083 convert_int_to_ascii (mem_buf
, own_buf
, len
);
2085 write_enn (own_buf
);
2088 require_running (own_buf
);
2089 decode_M_packet (&own_buf
[1], &mem_addr
, &len
, mem_buf
);
2090 if (write_inferior_memory (mem_addr
, mem_buf
, len
) == 0)
2093 write_enn (own_buf
);
2096 require_running (own_buf
);
2097 if (decode_X_packet (&own_buf
[1], packet_len
- 1,
2098 &mem_addr
, &len
, mem_buf
) < 0
2099 || write_inferior_memory (mem_addr
, mem_buf
, len
) != 0)
2100 write_enn (own_buf
);
2105 require_running (own_buf
);
2106 convert_ascii_to_int (own_buf
+ 1, &sig
, 1);
2107 if (target_signal_to_host_p (sig
))
2108 signal
= target_signal_to_host (sig
);
2111 myresume (own_buf
, 0, signal
);
2114 require_running (own_buf
);
2115 convert_ascii_to_int (own_buf
+ 1, &sig
, 1);
2116 if (target_signal_to_host_p (sig
))
2117 signal
= target_signal_to_host (sig
);
2120 myresume (own_buf
, 1, signal
);
2123 require_running (own_buf
);
2125 myresume (own_buf
, 0, signal
);
2128 require_running (own_buf
);
2130 myresume (own_buf
, 1, signal
);
2136 CORE_ADDR addr
= strtoul (&own_buf
[3], &lenptr
, 16);
2137 int len
= strtol (lenptr
+ 1, &dataptr
, 16);
2138 char type
= own_buf
[1];
2140 if (the_target
->insert_watchpoint
== NULL
2141 || (type
< '2' || type
> '4'))
2143 /* No watchpoint support or not a watchpoint command;
2144 unrecognized either way. */
2151 require_running (own_buf
);
2152 res
= (*the_target
->insert_watchpoint
) (type
, addr
, len
);
2159 write_enn (own_buf
);
2167 CORE_ADDR addr
= strtoul (&own_buf
[3], &lenptr
, 16);
2168 int len
= strtol (lenptr
+ 1, &dataptr
, 16);
2169 char type
= own_buf
[1];
2171 if (the_target
->remove_watchpoint
== NULL
2172 || (type
< '2' || type
> '4'))
2174 /* No watchpoint support or not a watchpoint command;
2175 unrecognized either way. */
2182 require_running (own_buf
);
2183 res
= (*the_target
->remove_watchpoint
) (type
, addr
, len
);
2190 write_enn (own_buf
);
2195 response_needed
= 0;
2196 if (!target_running ())
2197 /* The packet we received doesn't make sense - but we
2198 can't reply to it, either. */
2201 fprintf (stderr
, "Killing inferior\n");
2203 discard_queued_stop_replies ();
2205 /* When using the extended protocol, we wait with no program
2206 running. The traditional protocol will exit instead. */
2207 if (extended_protocol
)
2209 last_status
.kind
= TARGET_WAITKIND_EXITED
;
2210 last_status
.value
.sig
= TARGET_SIGNAL_KILL
;
2220 unsigned long gdb_id
, thread_id
;
2222 require_running (own_buf
);
2223 gdb_id
= strtoul (&own_buf
[1], NULL
, 16);
2224 thread_id
= gdb_id_to_thread_id (gdb_id
);
2227 write_enn (own_buf
);
2231 if (mythread_alive (thread_id
))
2234 write_enn (own_buf
);
2238 response_needed
= 0;
2240 /* Restarting the inferior is only supported in the extended
2242 if (extended_protocol
)
2244 if (target_running ())
2247 discard_queued_stop_replies ();
2249 fprintf (stderr
, "GDBserver restarting\n");
2251 /* Wait till we are at 1st instruction in prog. */
2252 if (program_argv
!= NULL
)
2253 start_inferior (program_argv
);
2256 last_status
.kind
= TARGET_WAITKIND_EXITED
;
2257 last_status
.value
.sig
= TARGET_SIGNAL_KILL
;
2263 /* It is a request we don't understand. Respond with an
2264 empty packet so that gdb knows that we don't support this
2270 /* Extended (long) request. */
2271 handle_v_requests (own_buf
, packet_len
, &new_packet_len
);
2275 /* It is a request we don't understand. Respond with an empty
2276 packet so that gdb knows that we don't support this
2282 if (new_packet_len
!= -1)
2283 putpkt_binary (own_buf
, new_packet_len
);
2287 response_needed
= 0;
2289 if (!extended_protocol
&& have_ran
&& !target_running ())
2291 /* In non-stop, defer exiting until GDB had a chance to query
2292 the whole vStopped list (until it gets an OK). */
2295 fprintf (stderr
, "GDBserver exiting\n");
2302 /* Event-loop callback for serial events. */
2305 handle_serial_event (int err
, gdb_client_data client_data
)
2308 fprintf (stderr
, "handling possible serial event\n");
2310 /* Really handle it. */
2311 process_serial_event ();
2313 /* Be sure to not change the selected inferior behind GDB's back.
2314 Important in the non-stop mode asynchronous protocol. */
2315 set_desired_inferior (1);
2318 /* Event-loop callback for target events. */
2321 handle_target_event (int err
, gdb_client_data client_data
)
2324 fprintf (stderr
, "handling possible target event\n");
2326 last_ptid
= mywait (&last_status
, TARGET_WNOHANG
, 1);
2328 if (last_status
.kind
!= TARGET_WAITKIND_IGNORE
)
2330 /* Something interesting. Tell GDB about it. */
2331 push_event (last_ptid
, &last_status
);
2334 /* Be sure to not change the selected inferior behind GDB's back.
2335 Important in the non-stop mode asynchronous protocol. */
2336 set_desired_inferior (1);