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 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/>. */
32 unsigned long cont_thread
;
33 unsigned long general_thread
;
34 unsigned long step_thread
;
35 unsigned long thread_from_wait
;
36 unsigned long old_thread_from_wait
;
37 int extended_protocol
;
40 /* Enable miscellaneous debugging output. The name is historical - it
41 was originally used to debug LinuxThreads support. */
44 int pass_signals
[TARGET_SIGNAL_LAST
];
48 /* The PID of the originally created or attached inferior. Used to
49 send signals to the process when GDB sends us an asynchronous interrupt
50 (user hitting Control-C in the client), and to wait for the child to exit
51 when no longer debugging it. */
53 unsigned long signal_pid
;
56 /* A file descriptor for the controlling terminal. */
59 /* TERMINAL_FD's original foreground group. */
60 pid_t old_foreground_pgrp
;
62 /* Hand back terminal ownership to the original foreground group. */
65 restore_old_foreground_pgrp (void)
67 tcsetpgrp (terminal_fd
, old_foreground_pgrp
);
72 start_inferior (char *argv
[], char *statusptr
)
75 signal (SIGTTOU
, SIG_DFL
);
76 signal (SIGTTIN
, SIG_DFL
);
79 signal_pid
= create_inferior (argv
[0], argv
);
81 /* FIXME: we don't actually know at this point that the create
82 actually succeeded. We won't know that until we wait. */
83 fprintf (stderr
, "Process %s created; pid = %ld\n", argv
[0],
88 signal (SIGTTOU
, SIG_IGN
);
89 signal (SIGTTIN
, SIG_IGN
);
90 terminal_fd
= fileno (stderr
);
91 old_foreground_pgrp
= tcgetpgrp (terminal_fd
);
92 tcsetpgrp (terminal_fd
, signal_pid
);
93 atexit (restore_old_foreground_pgrp
);
96 /* Wait till we are at 1st instruction in program, return signal
97 number (assuming success). */
98 return mywait (statusptr
, 0);
102 attach_inferior (int pid
, char *statusptr
, int *sigptr
)
104 /* myattach should return -1 if attaching is unsupported,
105 0 if it succeeded, and call error() otherwise. */
107 if (myattach (pid
) != 0)
110 fprintf (stderr
, "Attached; pid = %d\n", pid
);
113 /* FIXME - It may be that we should get the SIGNAL_PID from the
114 attach function, so that it can be the main thread instead of
115 whichever we were told to attach to. */
118 *sigptr
= mywait (statusptr
, 0);
120 /* GDB knows to ignore the first SIGSTOP after attaching to a running
121 process using the "attach" command, but this is different; it's
122 just using "target remote". Pretend it's just starting up. */
123 if (*statusptr
== 'T' && *sigptr
== TARGET_SIGNAL_STOP
)
124 *sigptr
= TARGET_SIGNAL_TRAP
;
129 extern int remote_debug
;
131 /* Decode a qXfer read request. Return 0 if everything looks OK,
135 decode_xfer_read (char *buf
, char **annex
, CORE_ADDR
*ofs
, unsigned int *len
)
137 /* Extract and NUL-terminate the annex. */
139 while (*buf
&& *buf
!= ':')
145 /* After the read marker and annex, qXfer looks like a
146 traditional 'm' packet. */
147 decode_m_packet (buf
, ofs
, len
);
152 /* Write the response to a successful qXfer read. Returns the
153 length of the (binary) data stored in BUF, corresponding
154 to as much of DATA/LEN as we could fit. IS_MORE controls
155 the first character of the response. */
157 write_qxfer_response (char *buf
, const void *data
, int len
, int is_more
)
166 return remote_escape_output (data
, len
, (unsigned char *) buf
+ 1, &out_len
,
170 /* Handle all of the extended 'Q' packets. */
172 handle_general_set (char *own_buf
)
174 if (strncmp ("QPassSignals:", own_buf
, strlen ("QPassSignals:")) == 0)
176 int numsigs
= (int) TARGET_SIGNAL_LAST
, i
;
177 const char *p
= own_buf
+ strlen ("QPassSignals:");
180 p
= decode_address_to_semicolon (&cursig
, p
);
181 for (i
= 0; i
< numsigs
; i
++)
187 /* Keep looping, to clear the remaining signals. */
190 p
= decode_address_to_semicolon (&cursig
, p
);
195 strcpy (own_buf
, "OK");
199 /* Otherwise we didn't know what packet it was. Say we didn't
205 get_features_xml (const char *annex
)
207 static int features_supported
= -1;
208 static char *document
;
211 extern const char *const xml_builtin
[][2];
214 /* Look for the annex. */
215 for (i
= 0; xml_builtin
[i
][0] != NULL
; i
++)
216 if (strcmp (annex
, xml_builtin
[i
][0]) == 0)
219 if (xml_builtin
[i
][0] != NULL
)
220 return xml_builtin
[i
][1];
223 if (strcmp (annex
, "target.xml") != 0)
226 if (features_supported
== -1)
228 const char *arch
= NULL
;
229 if (the_target
->arch_string
!= NULL
)
230 arch
= (*the_target
->arch_string
) ();
233 features_supported
= 0;
236 features_supported
= 1;
237 document
= malloc (64 + strlen (arch
));
238 snprintf (document
, 64 + strlen (arch
),
239 "<target><architecture>%s</architecture></target>",
248 monitor_show_help (void)
250 monitor_output ("The following monitor commands are supported:\n");
251 monitor_output (" set debug <0|1>\n");
252 monitor_output (" Enable general debugging messages\n");
253 monitor_output (" set remote-debug <0|1>\n");
254 monitor_output (" Enable remote protocol debugging messages\n");
257 /* Handle all of the extended 'q' packets. */
259 handle_query (char *own_buf
, int packet_len
, int *new_packet_len_p
)
261 static struct inferior_list_entry
*thread_ptr
;
263 /* Reply the current thread id. */
264 if (strcmp ("qC", own_buf
) == 0)
266 thread_ptr
= all_threads
.head
;
267 sprintf (own_buf
, "QC%x",
268 thread_to_gdb_id ((struct thread_info
*)thread_ptr
));
272 if (strcmp ("qSymbol::", own_buf
) == 0)
274 if (the_target
->look_up_symbols
!= NULL
)
275 (*the_target
->look_up_symbols
) ();
277 strcpy (own_buf
, "OK");
281 if (strcmp ("qfThreadInfo", own_buf
) == 0)
283 thread_ptr
= all_threads
.head
;
284 sprintf (own_buf
, "m%x", thread_to_gdb_id ((struct thread_info
*)thread_ptr
));
285 thread_ptr
= thread_ptr
->next
;
289 if (strcmp ("qsThreadInfo", own_buf
) == 0)
291 if (thread_ptr
!= NULL
)
293 sprintf (own_buf
, "m%x", thread_to_gdb_id ((struct thread_info
*)thread_ptr
));
294 thread_ptr
= thread_ptr
->next
;
299 sprintf (own_buf
, "l");
304 if (the_target
->read_offsets
!= NULL
305 && strcmp ("qOffsets", own_buf
) == 0)
307 CORE_ADDR text
, data
;
309 if (the_target
->read_offsets (&text
, &data
))
310 sprintf (own_buf
, "Text=%lX;Data=%lX;Bss=%lX",
311 (long)text
, (long)data
, (long)data
);
318 if (the_target
->qxfer_spu
!= NULL
319 && strncmp ("qXfer:spu:read:", own_buf
, 15) == 0)
325 unsigned char *spu_buf
;
327 strcpy (own_buf
, "E00");
328 if (decode_xfer_read (own_buf
+ 15, &annex
, &ofs
, &len
) < 0)
330 if (len
> PBUFSIZ
- 2)
332 spu_buf
= malloc (len
+ 1);
336 n
= (*the_target
->qxfer_spu
) (annex
, spu_buf
, NULL
, ofs
, len
+ 1);
340 *new_packet_len_p
= write_qxfer_response
341 (own_buf
, spu_buf
, len
, 1);
343 *new_packet_len_p
= write_qxfer_response
344 (own_buf
, spu_buf
, n
, 0);
350 if (the_target
->qxfer_spu
!= NULL
351 && strncmp ("qXfer:spu:write:", own_buf
, 16) == 0)
357 unsigned char *spu_buf
;
359 strcpy (own_buf
, "E00");
360 spu_buf
= malloc (packet_len
- 15);
363 if (decode_xfer_write (own_buf
+ 16, packet_len
- 16, &annex
,
364 &ofs
, &len
, spu_buf
) < 0)
370 n
= (*the_target
->qxfer_spu
)
371 (annex
, NULL
, (unsigned const char *)spu_buf
, ofs
, len
);
375 sprintf (own_buf
, "%x", n
);
381 if (the_target
->read_auxv
!= NULL
382 && strncmp ("qXfer:auxv:read:", own_buf
, 16) == 0)
390 /* Reject any annex; grab the offset and length. */
391 if (decode_xfer_read (own_buf
+ 16, &annex
, &ofs
, &len
) < 0
394 strcpy (own_buf
, "E00");
398 /* Read one extra byte, as an indicator of whether there is
400 if (len
> PBUFSIZ
- 2)
402 data
= malloc (len
+ 1);
403 n
= (*the_target
->read_auxv
) (ofs
, data
, len
+ 1);
407 *new_packet_len_p
= write_qxfer_response (own_buf
, data
, len
, 1);
409 *new_packet_len_p
= write_qxfer_response (own_buf
, data
, n
, 0);
416 if (strncmp ("qXfer:features:read:", own_buf
, 20) == 0)
419 unsigned int len
, total_len
;
420 const char *document
;
423 /* Check for support. */
424 document
= get_features_xml ("target.xml");
425 if (document
== NULL
)
431 /* Grab the annex, offset, and length. */
432 if (decode_xfer_read (own_buf
+ 20, &annex
, &ofs
, &len
) < 0)
434 strcpy (own_buf
, "E00");
438 /* Now grab the correct annex. */
439 document
= get_features_xml (annex
);
440 if (document
== NULL
)
442 strcpy (own_buf
, "E00");
446 total_len
= strlen (document
);
447 if (len
> PBUFSIZ
- 2)
452 else if (len
< total_len
- ofs
)
453 *new_packet_len_p
= write_qxfer_response (own_buf
, document
+ ofs
,
456 *new_packet_len_p
= write_qxfer_response (own_buf
, document
+ ofs
,
462 if (strncmp ("qXfer:libraries:read:", own_buf
, 21) == 0)
465 unsigned int len
, total_len
;
467 struct inferior_list_entry
*dll_ptr
;
470 /* Reject any annex; grab the offset and length. */
471 if (decode_xfer_read (own_buf
+ 21, &annex
, &ofs
, &len
) < 0
474 strcpy (own_buf
, "E00");
478 /* Over-estimate the necessary memory. Assume that every character
479 in the library name must be escaped. */
481 for (dll_ptr
= all_dlls
.head
; dll_ptr
!= NULL
; dll_ptr
= dll_ptr
->next
)
482 total_len
+= 128 + 6 * strlen (((struct dll_info
*) dll_ptr
)->name
);
484 document
= malloc (total_len
);
485 strcpy (document
, "<library-list>\n");
486 p
= document
+ strlen (document
);
488 for (dll_ptr
= all_dlls
.head
; dll_ptr
!= NULL
; dll_ptr
= dll_ptr
->next
)
490 struct dll_info
*dll
= (struct dll_info
*) dll_ptr
;
493 strcpy (p
, " <library name=\"");
495 name
= xml_escape_text (dll
->name
);
499 strcpy (p
, "\"><segment address=\"");
501 sprintf (p
, "0x%lx", (long) dll
->base_addr
);
503 strcpy (p
, "\"/></library>\n");
507 strcpy (p
, "</library-list>\n");
509 total_len
= strlen (document
);
510 if (len
> PBUFSIZ
- 2)
515 else if (len
< total_len
- ofs
)
516 *new_packet_len_p
= write_qxfer_response (own_buf
, document
+ ofs
,
519 *new_packet_len_p
= write_qxfer_response (own_buf
, document
+ ofs
,
526 /* Protocol features query. */
527 if (strncmp ("qSupported", own_buf
, 10) == 0
528 && (own_buf
[10] == ':' || own_buf
[10] == '\0'))
530 sprintf (own_buf
, "PacketSize=%x;QPassSignals+", PBUFSIZ
- 1);
532 /* We do not have any hook to indicate whether the target backend
533 supports qXfer:libraries:read, so always report it. */
534 strcat (own_buf
, ";qXfer:libraries:read+");
536 if (the_target
->read_auxv
!= NULL
)
537 strcat (own_buf
, ";qXfer:auxv:read+");
539 if (the_target
->qxfer_spu
!= NULL
)
540 strcat (own_buf
, ";qXfer:spu:read+;qXfer:spu:write+");
542 if (get_features_xml ("target.xml") != NULL
)
543 strcat (own_buf
, ";qXfer:features:read+");
548 /* Thread-local storage support. */
549 if (the_target
->get_tls_address
!= NULL
550 && strncmp ("qGetTLSAddr:", own_buf
, 12) == 0)
552 char *p
= own_buf
+ 12;
553 CORE_ADDR parts
[3], address
= 0;
556 for (i
= 0; i
< 3; i
++)
564 p2
= strchr (p
, ',');
576 decode_address (&parts
[i
], p
, len
);
580 if (p
!= NULL
|| i
< 3)
584 struct thread_info
*thread
= gdb_id_to_thread (parts
[0]);
589 err
= the_target
->get_tls_address (thread
, parts
[1], parts
[2],
595 sprintf (own_buf
, "%llx", address
);
604 /* Otherwise, pretend we do not understand this packet. */
607 /* Handle "monitor" commands. */
608 if (strncmp ("qRcmd,", own_buf
, 6) == 0)
610 char *mon
= malloc (PBUFSIZ
);
611 int len
= strlen (own_buf
+ 6);
613 if ((len
% 1) != 0 || unhexify (mon
, own_buf
+ 6, len
/ 2) != len
/ 2)
623 if (strcmp (mon
, "set debug 1") == 0)
626 monitor_output ("Debug output enabled.\n");
628 else if (strcmp (mon
, "set debug 0") == 0)
631 monitor_output ("Debug output disabled.\n");
633 else if (strcmp (mon
, "set remote-debug 1") == 0)
636 monitor_output ("Protocol debug output enabled.\n");
638 else if (strcmp (mon
, "set remote-debug 0") == 0)
641 monitor_output ("Protocol debug output disabled.\n");
643 else if (strcmp (mon
, "help") == 0)
644 monitor_show_help ();
647 monitor_output ("Unknown monitor command.\n\n");
648 monitor_show_help ();
656 /* Otherwise we didn't know what packet it was. Say we didn't
661 /* Parse vCont packets. */
663 handle_v_cont (char *own_buf
, char *status
, int *signal
)
667 struct thread_resume
*resume_info
, default_action
;
669 /* Count the number of semicolons in the packet. There should be one
678 /* Allocate room for one extra action, for the default remain-stopped
679 behavior; if no default action is in the list, we'll need the extra
681 resume_info
= malloc ((n
+ 1) * sizeof (resume_info
[0]));
683 default_action
.thread
= -1;
684 default_action
.leave_stopped
= 1;
685 default_action
.step
= 0;
686 default_action
.sig
= 0;
694 resume_info
[i
].leave_stopped
= 0;
696 if (p
[0] == 's' || p
[0] == 'S')
697 resume_info
[i
].step
= 1;
698 else if (p
[0] == 'c' || p
[0] == 'C')
699 resume_info
[i
].step
= 0;
703 if (p
[0] == 'S' || p
[0] == 'C')
706 sig
= strtol (p
+ 1, &q
, 16);
711 if (!target_signal_to_host_p (sig
))
713 resume_info
[i
].sig
= target_signal_to_host (sig
);
717 resume_info
[i
].sig
= 0;
723 resume_info
[i
].thread
= -1;
724 default_action
= resume_info
[i
];
726 /* Note: we don't increment i here, we'll overwrite this entry
727 the next time through. */
729 else if (p
[0] == ':')
731 unsigned int gdb_id
= strtoul (p
+ 1, &q
, 16);
732 unsigned long thread_id
;
737 if (p
[0] != ';' && p
[0] != 0)
740 thread_id
= gdb_id_to_thread_id (gdb_id
);
742 resume_info
[i
].thread
= thread_id
;
750 resume_info
[i
] = default_action
;
752 /* Still used in occasional places in the backend. */
753 if (n
== 1 && resume_info
[0].thread
!= -1)
754 cont_thread
= resume_info
[0].thread
;
757 set_desired_inferior (0);
759 (*the_target
->resume
) (resume_info
);
763 *signal
= mywait (status
, 1);
764 prepare_resume_reply (own_buf
, *status
, *signal
);
773 /* Handle all of the extended 'v' packets. */
775 handle_v_requests (char *own_buf
, char *status
, int *signal
)
777 if (strncmp (own_buf
, "vCont;", 6) == 0)
779 handle_v_cont (own_buf
, status
, signal
);
783 if (strncmp (own_buf
, "vCont?", 6) == 0)
785 strcpy (own_buf
, "vCont;c;C;s;S");
789 /* Otherwise we didn't know what packet it was. Say we didn't
796 myresume (int step
, int sig
)
798 struct thread_resume resume_info
[2];
801 if (step
|| sig
|| (cont_thread
!= 0 && cont_thread
!= -1))
803 resume_info
[0].thread
804 = ((struct inferior_list_entry
*) current_inferior
)->id
;
805 resume_info
[0].step
= step
;
806 resume_info
[0].sig
= sig
;
807 resume_info
[0].leave_stopped
= 0;
810 resume_info
[n
].thread
= -1;
811 resume_info
[n
].step
= 0;
812 resume_info
[n
].sig
= 0;
813 resume_info
[n
].leave_stopped
= (cont_thread
!= 0 && cont_thread
!= -1);
815 (*the_target
->resume
) (resume_info
);
821 gdbserver_version (void)
823 printf ("GNU gdbserver %s\n"
824 "Copyright (C) 2007 Free Software Foundation, Inc.\n"
825 "gdbserver is free software, covered by the GNU General Public License.\n"
826 "This gdbserver was configured as \"%s\"\n",
831 gdbserver_usage (void)
833 printf ("Usage:\tgdbserver COMM PROG [ARGS ...]\n"
834 "\tgdbserver COMM --attach PID\n"
836 "COMM may either be a tty device (for serial debugging), or \n"
837 "HOST:PORT to listen for a TCP connection.\n");
841 main (int argc
, char *argv
[])
843 char ch
, status
, *own_buf
;
844 unsigned char *mem_buf
;
853 if (argc
>= 2 && strcmp (argv
[1], "--version") == 0)
855 gdbserver_version ();
859 if (argc
>= 2 && strcmp (argv
[1], "--help") == 0)
865 if (setjmp (toplevel
))
867 fprintf (stderr
, "Exiting\n");
874 if (argc
>= 3 && strcmp (argv
[2], "--attach") == 0)
877 && argv
[3][0] != '\0'
878 && (pid
= strtoul (argv
[3], &arg_end
, 10)) != 0
887 if (argc
< 3 || bad_attach
)
895 own_buf
= malloc (PBUFSIZ
+ 1);
896 mem_buf
= malloc (PBUFSIZ
);
900 /* Wait till we are at first instruction in program. */
901 signal
= start_inferior (&argv
[2], &status
);
903 /* We are now (hopefully) stopped at the first instruction of
904 the target process. This assumes that the target process was
905 successfully created. */
907 /* Don't report shared library events on the initial connection,
908 even if some libraries are preloaded. */
913 switch (attach_inferior (pid
, &status
, &signal
))
916 error ("Attaching not supported on this target");
924 if (setjmp (toplevel
))
926 fprintf (stderr
, "Killing inferior\n");
931 if (status
== 'W' || status
== 'X')
933 fprintf (stderr
, "No inferior, GDBserver exiting.\n");
939 remote_open (argv
[1]);
947 int new_packet_len
= -1;
949 packet_len
= getpkt (own_buf
);
958 handle_query (own_buf
, packet_len
, &new_packet_len
);
961 handle_general_set (own_buf
);
964 fprintf (stderr
, "Detaching from inferior\n");
965 if (detach_inferior () != 0)
976 /* If we are attached, then we can exit. Otherwise, we
977 need to hang around doing nothing, until the child
987 extended_protocol
= 1;
988 prepare_resume_reply (own_buf
, status
, signal
);
992 /* We can not use the extended protocol if we are
993 attached, because we can not restart the running
994 program. So return unrecognized. */
999 prepare_resume_reply (own_buf
, status
, signal
);
1002 if (own_buf
[1] == 'c' || own_buf
[1] == 'g' || own_buf
[1] == 's')
1004 unsigned long gdb_id
, thread_id
;
1006 gdb_id
= strtoul (&own_buf
[2], NULL
, 16);
1007 thread_id
= gdb_id_to_thread_id (gdb_id
);
1010 write_enn (own_buf
);
1014 if (own_buf
[1] == 'g')
1016 general_thread
= thread_id
;
1017 set_desired_inferior (1);
1019 else if (own_buf
[1] == 'c')
1020 cont_thread
= thread_id
;
1021 else if (own_buf
[1] == 's')
1022 step_thread
= thread_id
;
1028 /* Silently ignore it so that gdb can extend the protocol
1029 without compatibility headaches. */
1034 set_desired_inferior (1);
1035 registers_to_string (own_buf
);
1038 set_desired_inferior (1);
1039 registers_from_string (&own_buf
[1]);
1043 decode_m_packet (&own_buf
[1], &mem_addr
, &len
);
1044 if (read_inferior_memory (mem_addr
, mem_buf
, len
) == 0)
1045 convert_int_to_ascii (mem_buf
, own_buf
, len
);
1047 write_enn (own_buf
);
1050 decode_M_packet (&own_buf
[1], &mem_addr
, &len
, mem_buf
);
1051 if (write_inferior_memory (mem_addr
, mem_buf
, len
) == 0)
1054 write_enn (own_buf
);
1057 if (decode_X_packet (&own_buf
[1], packet_len
- 1,
1058 &mem_addr
, &len
, mem_buf
) < 0
1059 || write_inferior_memory (mem_addr
, mem_buf
, len
) != 0)
1060 write_enn (own_buf
);
1065 convert_ascii_to_int (own_buf
+ 1, &sig
, 1);
1066 if (target_signal_to_host_p (sig
))
1067 signal
= target_signal_to_host (sig
);
1070 set_desired_inferior (0);
1071 myresume (0, signal
);
1072 signal
= mywait (&status
, 1);
1073 prepare_resume_reply (own_buf
, status
, signal
);
1076 convert_ascii_to_int (own_buf
+ 1, &sig
, 1);
1077 if (target_signal_to_host_p (sig
))
1078 signal
= target_signal_to_host (sig
);
1081 set_desired_inferior (0);
1082 myresume (1, signal
);
1083 signal
= mywait (&status
, 1);
1084 prepare_resume_reply (own_buf
, status
, signal
);
1087 set_desired_inferior (0);
1089 signal
= mywait (&status
, 1);
1090 prepare_resume_reply (own_buf
, status
, signal
);
1093 set_desired_inferior (0);
1095 signal
= mywait (&status
, 1);
1096 prepare_resume_reply (own_buf
, status
, signal
);
1102 CORE_ADDR addr
= strtoul (&own_buf
[3], &lenptr
, 16);
1103 int len
= strtol (lenptr
+ 1, &dataptr
, 16);
1104 char type
= own_buf
[1];
1106 if (the_target
->insert_watchpoint
== NULL
1107 || (type
< '2' || type
> '4'))
1109 /* No watchpoint support or not a watchpoint command;
1110 unrecognized either way. */
1117 res
= (*the_target
->insert_watchpoint
) (type
, addr
, len
);
1124 write_enn (own_buf
);
1132 CORE_ADDR addr
= strtoul (&own_buf
[3], &lenptr
, 16);
1133 int len
= strtol (lenptr
+ 1, &dataptr
, 16);
1134 char type
= own_buf
[1];
1136 if (the_target
->remove_watchpoint
== NULL
1137 || (type
< '2' || type
> '4'))
1139 /* No watchpoint support or not a watchpoint command;
1140 unrecognized either way. */
1147 res
= (*the_target
->remove_watchpoint
) (type
, addr
, len
);
1154 write_enn (own_buf
);
1159 fprintf (stderr
, "Killing inferior\n");
1161 /* When using the extended protocol, we start up a new
1162 debugging session. The traditional protocol will
1164 if (extended_protocol
)
1167 fprintf (stderr
, "GDBserver restarting\n");
1169 /* Wait till we are at 1st instruction in prog. */
1170 signal
= start_inferior (&argv
[2], &status
);
1181 unsigned long gdb_id
, thread_id
;
1183 gdb_id
= strtoul (&own_buf
[1], NULL
, 16);
1184 thread_id
= gdb_id_to_thread_id (gdb_id
);
1187 write_enn (own_buf
);
1191 if (mythread_alive (thread_id
))
1194 write_enn (own_buf
);
1198 /* Restarting the inferior is only supported in the
1199 extended protocol. */
1200 if (extended_protocol
)
1204 fprintf (stderr
, "GDBserver restarting\n");
1206 /* Wait till we are at 1st instruction in prog. */
1207 signal
= start_inferior (&argv
[2], &status
);
1213 /* It is a request we don't understand. Respond with an
1214 empty packet so that gdb knows that we don't support this
1220 /* Extended (long) request. */
1221 handle_v_requests (own_buf
, &status
, &signal
);
1224 /* It is a request we don't understand. Respond with an
1225 empty packet so that gdb knows that we don't support this
1231 if (new_packet_len
!= -1)
1232 putpkt_binary (own_buf
, new_packet_len
);
1238 "\nChild exited with status %d\n", signal
);
1240 fprintf (stderr
, "\nChild terminated with signal = 0x%x (%s)\n",
1241 target_signal_to_host (signal
),
1242 target_signal_to_name (signal
));
1243 if (status
== 'W' || status
== 'X')
1245 if (extended_protocol
)
1247 fprintf (stderr
, "Killing inferior\n");
1250 fprintf (stderr
, "GDBserver restarting\n");
1252 /* Wait till we are at 1st instruction in prog. */
1253 signal
= start_inferior (&argv
[2], &status
);
1259 fprintf (stderr
, "GDBserver exiting\n");
1265 /* We come here when getpkt fails.
1267 For the extended remote protocol we exit (and this is the only
1268 way we gracefully exit!).
1270 For the traditional remote protocol close the connection,
1271 and re-open it at the top of the loop. */
1272 if (extended_protocol
)
1279 fprintf (stderr
, "Remote side has terminated connection. "
1280 "GDBserver will reopen the connection.\n");