* server.c (handle_query): Correct error handling for read_auxv.
[deliverable/binutils-gdb.git] / gdb / gdbserver / server.c
1 /* Main code for remote server for GDB.
2 Copyright (C) 1989, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2002, 2003, 2004,
3 2005, 2006
4 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
22
23 #include "server.h"
24
25 #include <unistd.h>
26 #include <signal.h>
27 #if HAVE_SYS_WAIT_H
28 #include <sys/wait.h>
29 #endif
30
31 unsigned long cont_thread;
32 unsigned long general_thread;
33 unsigned long step_thread;
34 unsigned long thread_from_wait;
35 unsigned long old_thread_from_wait;
36 int extended_protocol;
37 int server_waiting;
38
39 jmp_buf toplevel;
40
41 /* The PID of the originally created or attached inferior. Used to
42 send signals to the process when GDB sends us an asynchronous interrupt
43 (user hitting Control-C in the client), and to wait for the child to exit
44 when no longer debugging it. */
45
46 unsigned long signal_pid;
47
48 #ifdef SIGTTOU
49 /* A file descriptor for the controlling terminal. */
50 int terminal_fd;
51
52 /* TERMINAL_FD's original foreground group. */
53 pid_t old_foreground_pgrp;
54
55 /* Hand back terminal ownership to the original foreground group. */
56
57 static void
58 restore_old_foreground_pgrp (void)
59 {
60 tcsetpgrp (terminal_fd, old_foreground_pgrp);
61 }
62 #endif
63
64 static int
65 start_inferior (char *argv[], char *statusptr)
66 {
67 #ifdef SIGTTOU
68 signal (SIGTTOU, SIG_DFL);
69 signal (SIGTTIN, SIG_DFL);
70 #endif
71
72 signal_pid = create_inferior (argv[0], argv);
73
74 fprintf (stderr, "Process %s created; pid = %ld\n", argv[0],
75 signal_pid);
76 fflush (stderr);
77
78 #ifdef SIGTTOU
79 signal (SIGTTOU, SIG_IGN);
80 signal (SIGTTIN, SIG_IGN);
81 terminal_fd = fileno (stderr);
82 old_foreground_pgrp = tcgetpgrp (terminal_fd);
83 tcsetpgrp (terminal_fd, signal_pid);
84 atexit (restore_old_foreground_pgrp);
85 #endif
86
87 /* Wait till we are at 1st instruction in program, return signal number. */
88 return mywait (statusptr, 0);
89 }
90
91 static int
92 attach_inferior (int pid, char *statusptr, int *sigptr)
93 {
94 /* myattach should return -1 if attaching is unsupported,
95 0 if it succeeded, and call error() otherwise. */
96
97 if (myattach (pid) != 0)
98 return -1;
99
100 fprintf (stderr, "Attached; pid = %d\n", pid);
101 fflush (stderr);
102
103 /* FIXME - It may be that we should get the SIGNAL_PID from the
104 attach function, so that it can be the main thread instead of
105 whichever we were told to attach to. */
106 signal_pid = pid;
107
108 *sigptr = mywait (statusptr, 0);
109
110 /* GDB knows to ignore the first SIGSTOP after attaching to a running
111 process using the "attach" command, but this is different; it's
112 just using "target remote". Pretend it's just starting up. */
113 if (*statusptr == 'T' && *sigptr == TARGET_SIGNAL_STOP)
114 *sigptr = TARGET_SIGNAL_TRAP;
115
116 return 0;
117 }
118
119 extern int remote_debug;
120
121 /* Decode a qXfer read request. Return 0 if everything looks OK,
122 or -1 otherwise. */
123
124 static int
125 decode_xfer_read (char *buf, char **annex, CORE_ADDR *ofs, unsigned int *len)
126 {
127 /* Extract and NUL-terminate the annex. */
128 *annex = buf;
129 while (*buf && *buf != ':')
130 buf++;
131 if (*buf == '\0')
132 return -1;
133 *buf++ = 0;
134
135 /* After the read/write marker and annex, qXfer looks like a
136 traditional 'm' packet. */
137 decode_m_packet (buf, ofs, len);
138
139 return 0;
140 }
141
142 /* Write the response to a successful qXfer read. Returns the
143 length of the (binary) data stored in BUF, corresponding
144 to as much of DATA/LEN as we could fit. IS_MORE controls
145 the first character of the response. */
146 static int
147 write_qxfer_response (char *buf, unsigned char *data, int len, int is_more)
148 {
149 int out_len;
150
151 if (is_more)
152 buf[0] = 'm';
153 else
154 buf[0] = 'l';
155
156 return remote_escape_output (data, len, (unsigned char *) buf + 1, &out_len,
157 PBUFSIZ - 2) + 1;
158 }
159
160 /* Handle all of the extended 'q' packets. */
161 void
162 handle_query (char *own_buf, int *new_packet_len_p)
163 {
164 static struct inferior_list_entry *thread_ptr;
165
166 if (strcmp ("qSymbol::", own_buf) == 0)
167 {
168 if (the_target->look_up_symbols != NULL)
169 (*the_target->look_up_symbols) ();
170
171 strcpy (own_buf, "OK");
172 return;
173 }
174
175 if (strcmp ("qfThreadInfo", own_buf) == 0)
176 {
177 thread_ptr = all_threads.head;
178 sprintf (own_buf, "m%x", thread_to_gdb_id ((struct thread_info *)thread_ptr));
179 thread_ptr = thread_ptr->next;
180 return;
181 }
182
183 if (strcmp ("qsThreadInfo", own_buf) == 0)
184 {
185 if (thread_ptr != NULL)
186 {
187 sprintf (own_buf, "m%x", thread_to_gdb_id ((struct thread_info *)thread_ptr));
188 thread_ptr = thread_ptr->next;
189 return;
190 }
191 else
192 {
193 sprintf (own_buf, "l");
194 return;
195 }
196 }
197
198 if (the_target->read_offsets != NULL
199 && strcmp ("qOffsets", own_buf) == 0)
200 {
201 CORE_ADDR text, data;
202
203 if (the_target->read_offsets (&text, &data))
204 sprintf (own_buf, "Text=%lX;Data=%lX;Bss=%lX",
205 (long)text, (long)data, (long)data);
206 else
207 write_enn (own_buf);
208
209 return;
210 }
211
212 if (the_target->read_auxv != NULL
213 && strncmp ("qXfer:auxv:read:", own_buf, 16) == 0)
214 {
215 unsigned char *data;
216 int n;
217 CORE_ADDR ofs;
218 unsigned int len;
219 char *annex;
220
221 /* Reject any annex; grab the offset and length. */
222 if (decode_xfer_read (own_buf + 16, &annex, &ofs, &len) < 0
223 || annex[0] != '\0')
224 {
225 strcpy (own_buf, "E00");
226 return;
227 }
228
229 /* Read one extra byte, as an indicator of whether there is
230 more. */
231 if (len > PBUFSIZ - 2)
232 len = PBUFSIZ - 2;
233 data = malloc (len + 1);
234 n = (*the_target->read_auxv) (ofs, data, len + 1);
235 if (n < 0)
236 write_enn (own_buf);
237 else if (n > len)
238 *new_packet_len_p = write_qxfer_response (own_buf, data, len, 1);
239 else
240 *new_packet_len_p = write_qxfer_response (own_buf, data, n, 0);
241
242 free (data);
243
244 return;
245 }
246
247 /* Protocol features query. */
248 if (strncmp ("qSupported", own_buf, 10) == 0
249 && (own_buf[10] == ':' || own_buf[10] == '\0'))
250 {
251 sprintf (own_buf, "PacketSize=%x", PBUFSIZ - 1);
252
253 if (the_target->read_auxv != NULL)
254 strcat (own_buf, ";qXfer:auxv:read+");
255
256 return;
257 }
258
259 /* Thread-local storage support. */
260 if (the_target->get_tls_address != NULL
261 && strncmp ("qGetTLSAddr:", own_buf, 12) == 0)
262 {
263 char *p = own_buf + 12;
264 CORE_ADDR parts[3], address = 0;
265 int i, err;
266
267 for (i = 0; i < 3; i++)
268 {
269 char *p2;
270 int len;
271
272 if (p == NULL)
273 break;
274
275 p2 = strchr (p, ',');
276 if (p2)
277 {
278 len = p2 - p;
279 p2++;
280 }
281 else
282 {
283 len = strlen (p);
284 p2 = NULL;
285 }
286
287 decode_address (&parts[i], p, len);
288 p = p2;
289 }
290
291 if (p != NULL || i < 3)
292 err = 1;
293 else
294 {
295 struct thread_info *thread = gdb_id_to_thread (parts[0]);
296
297 if (thread == NULL)
298 err = 2;
299 else
300 err = the_target->get_tls_address (thread, parts[1], parts[2],
301 &address);
302 }
303
304 if (err == 0)
305 {
306 sprintf (own_buf, "%llx", address);
307 return;
308 }
309 else if (err > 0)
310 {
311 write_enn (own_buf);
312 return;
313 }
314
315 /* Otherwise, pretend we do not understand this packet. */
316 }
317
318 /* Otherwise we didn't know what packet it was. Say we didn't
319 understand it. */
320 own_buf[0] = 0;
321 }
322
323 /* Parse vCont packets. */
324 void
325 handle_v_cont (char *own_buf, char *status, int *signal)
326 {
327 char *p, *q;
328 int n = 0, i = 0;
329 struct thread_resume *resume_info, default_action;
330
331 /* Count the number of semicolons in the packet. There should be one
332 for every action. */
333 p = &own_buf[5];
334 while (p)
335 {
336 n++;
337 p++;
338 p = strchr (p, ';');
339 }
340 /* Allocate room for one extra action, for the default remain-stopped
341 behavior; if no default action is in the list, we'll need the extra
342 slot. */
343 resume_info = malloc ((n + 1) * sizeof (resume_info[0]));
344
345 default_action.thread = -1;
346 default_action.leave_stopped = 1;
347 default_action.step = 0;
348 default_action.sig = 0;
349
350 p = &own_buf[5];
351 i = 0;
352 while (*p)
353 {
354 p++;
355
356 resume_info[i].leave_stopped = 0;
357
358 if (p[0] == 's' || p[0] == 'S')
359 resume_info[i].step = 1;
360 else if (p[0] == 'c' || p[0] == 'C')
361 resume_info[i].step = 0;
362 else
363 goto err;
364
365 if (p[0] == 'S' || p[0] == 'C')
366 {
367 int sig;
368 sig = strtol (p + 1, &q, 16);
369 if (p == q)
370 goto err;
371 p = q;
372
373 if (!target_signal_to_host_p (sig))
374 goto err;
375 resume_info[i].sig = target_signal_to_host (sig);
376 }
377 else
378 {
379 resume_info[i].sig = 0;
380 p = p + 1;
381 }
382
383 if (p[0] == 0)
384 {
385 resume_info[i].thread = -1;
386 default_action = resume_info[i];
387
388 /* Note: we don't increment i here, we'll overwrite this entry
389 the next time through. */
390 }
391 else if (p[0] == ':')
392 {
393 unsigned int gdb_id = strtoul (p + 1, &q, 16);
394 unsigned long thread_id;
395
396 if (p == q)
397 goto err;
398 p = q;
399 if (p[0] != ';' && p[0] != 0)
400 goto err;
401
402 thread_id = gdb_id_to_thread_id (gdb_id);
403 if (thread_id)
404 resume_info[i].thread = thread_id;
405 else
406 goto err;
407
408 i++;
409 }
410 }
411
412 resume_info[i] = default_action;
413
414 /* Still used in occasional places in the backend. */
415 if (n == 1 && resume_info[0].thread != -1)
416 cont_thread = resume_info[0].thread;
417 else
418 cont_thread = -1;
419 set_desired_inferior (0);
420
421 (*the_target->resume) (resume_info);
422
423 free (resume_info);
424
425 *signal = mywait (status, 1);
426 prepare_resume_reply (own_buf, *status, *signal);
427 return;
428
429 err:
430 /* No other way to report an error... */
431 strcpy (own_buf, "");
432 free (resume_info);
433 return;
434 }
435
436 /* Handle all of the extended 'v' packets. */
437 void
438 handle_v_requests (char *own_buf, char *status, int *signal)
439 {
440 if (strncmp (own_buf, "vCont;", 6) == 0)
441 {
442 handle_v_cont (own_buf, status, signal);
443 return;
444 }
445
446 if (strncmp (own_buf, "vCont?", 6) == 0)
447 {
448 strcpy (own_buf, "vCont;c;C;s;S");
449 return;
450 }
451
452 /* Otherwise we didn't know what packet it was. Say we didn't
453 understand it. */
454 own_buf[0] = 0;
455 return;
456 }
457
458 void
459 myresume (int step, int sig)
460 {
461 struct thread_resume resume_info[2];
462 int n = 0;
463
464 if (step || sig || (cont_thread != 0 && cont_thread != -1))
465 {
466 resume_info[0].thread
467 = ((struct inferior_list_entry *) current_inferior)->id;
468 resume_info[0].step = step;
469 resume_info[0].sig = sig;
470 resume_info[0].leave_stopped = 0;
471 n++;
472 }
473 resume_info[n].thread = -1;
474 resume_info[n].step = 0;
475 resume_info[n].sig = 0;
476 resume_info[n].leave_stopped = (cont_thread != 0 && cont_thread != -1);
477
478 (*the_target->resume) (resume_info);
479 }
480
481 static int attached;
482
483 static void
484 gdbserver_version (void)
485 {
486 printf ("GNU gdbserver %s\n"
487 "Copyright (C) 2006 Free Software Foundation, Inc.\n"
488 "gdbserver is free software, covered by the GNU General Public License.\n"
489 "This gdbserver was configured as \"%s\"\n",
490 version, host_name);
491 }
492
493 static void
494 gdbserver_usage (void)
495 {
496 printf ("Usage:\tgdbserver COMM PROG [ARGS ...]\n"
497 "\tgdbserver COMM --attach PID\n"
498 "\n"
499 "COMM may either be a tty device (for serial debugging), or \n"
500 "HOST:PORT to listen for a TCP connection.\n");
501 }
502
503 int
504 main (int argc, char *argv[])
505 {
506 char ch, status, *own_buf;
507 unsigned char *mem_buf;
508 int i = 0;
509 int signal;
510 unsigned int len;
511 CORE_ADDR mem_addr;
512 int bad_attach;
513 int pid;
514 char *arg_end;
515
516 if (argc >= 2 && strcmp (argv[1], "--version") == 0)
517 {
518 gdbserver_version ();
519 exit (0);
520 }
521
522 if (argc >= 2 && strcmp (argv[1], "--help") == 0)
523 {
524 gdbserver_usage ();
525 exit (0);
526 }
527
528 if (setjmp (toplevel))
529 {
530 fprintf (stderr, "Exiting\n");
531 exit (1);
532 }
533
534 bad_attach = 0;
535 pid = 0;
536 attached = 0;
537 if (argc >= 3 && strcmp (argv[2], "--attach") == 0)
538 {
539 if (argc == 4
540 && argv[3] != '\0'
541 && (pid = strtoul (argv[3], &arg_end, 10)) != 0
542 && *arg_end == '\0')
543 {
544 ;
545 }
546 else
547 bad_attach = 1;
548 }
549
550 if (argc < 3 || bad_attach)
551 {
552 gdbserver_usage ();
553 exit (1);
554 }
555
556 initialize_low ();
557
558 own_buf = malloc (PBUFSIZ);
559 mem_buf = malloc (PBUFSIZ);
560
561 if (pid == 0)
562 {
563 /* Wait till we are at first instruction in program. */
564 signal = start_inferior (&argv[2], &status);
565
566 /* We are now stopped at the first instruction of the target process */
567 }
568 else
569 {
570 switch (attach_inferior (pid, &status, &signal))
571 {
572 case -1:
573 error ("Attaching not supported on this target");
574 break;
575 default:
576 attached = 1;
577 break;
578 }
579 }
580
581 while (1)
582 {
583 remote_open (argv[1]);
584
585 restart:
586 setjmp (toplevel);
587 while (1)
588 {
589 unsigned char sig;
590 int packet_len;
591 int new_packet_len = -1;
592
593 packet_len = getpkt (own_buf);
594 if (packet_len <= 0)
595 break;
596
597 i = 0;
598 ch = own_buf[i++];
599 switch (ch)
600 {
601 case 'q':
602 handle_query (own_buf, &new_packet_len);
603 break;
604 case 'd':
605 remote_debug = !remote_debug;
606 break;
607 #ifndef USE_WIN32API
608 /* Skip "detach" support on mingw32, since we don't have
609 waitpid. */
610 case 'D':
611 fprintf (stderr, "Detaching from inferior\n");
612 detach_inferior ();
613 write_ok (own_buf);
614 putpkt (own_buf);
615 remote_close ();
616
617 /* If we are attached, then we can exit. Otherwise, we need to
618 hang around doing nothing, until the child is gone. */
619 if (!attached)
620 {
621 int status, ret;
622
623 do {
624 ret = waitpid (signal_pid, &status, 0);
625 if (WIFEXITED (status) || WIFSIGNALED (status))
626 break;
627 } while (ret != -1 || errno != ECHILD);
628 }
629
630 exit (0);
631 #endif
632
633 case '!':
634 if (attached == 0)
635 {
636 extended_protocol = 1;
637 prepare_resume_reply (own_buf, status, signal);
638 }
639 else
640 {
641 /* We can not use the extended protocol if we are
642 attached, because we can not restart the running
643 program. So return unrecognized. */
644 own_buf[0] = '\0';
645 }
646 break;
647 case '?':
648 prepare_resume_reply (own_buf, status, signal);
649 break;
650 case 'H':
651 if (own_buf[1] == 'c' || own_buf[1] == 'g' || own_buf[1] == 's')
652 {
653 unsigned long gdb_id, thread_id;
654
655 gdb_id = strtoul (&own_buf[2], NULL, 16);
656 thread_id = gdb_id_to_thread_id (gdb_id);
657 if (thread_id == 0)
658 {
659 write_enn (own_buf);
660 break;
661 }
662
663 if (own_buf[1] == 'g')
664 {
665 general_thread = thread_id;
666 set_desired_inferior (1);
667 }
668 else if (own_buf[1] == 'c')
669 cont_thread = thread_id;
670 else if (own_buf[1] == 's')
671 step_thread = thread_id;
672
673 write_ok (own_buf);
674 }
675 else
676 {
677 /* Silently ignore it so that gdb can extend the protocol
678 without compatibility headaches. */
679 own_buf[0] = '\0';
680 }
681 break;
682 case 'g':
683 set_desired_inferior (1);
684 registers_to_string (own_buf);
685 break;
686 case 'G':
687 set_desired_inferior (1);
688 registers_from_string (&own_buf[1]);
689 write_ok (own_buf);
690 break;
691 case 'm':
692 decode_m_packet (&own_buf[1], &mem_addr, &len);
693 if (read_inferior_memory (mem_addr, mem_buf, len) == 0)
694 convert_int_to_ascii (mem_buf, own_buf, len);
695 else
696 write_enn (own_buf);
697 break;
698 case 'M':
699 decode_M_packet (&own_buf[1], &mem_addr, &len, mem_buf);
700 if (write_inferior_memory (mem_addr, mem_buf, len) == 0)
701 write_ok (own_buf);
702 else
703 write_enn (own_buf);
704 break;
705 case 'X':
706 if (decode_X_packet (&own_buf[1], packet_len - 1,
707 &mem_addr, &len, mem_buf) < 0
708 || write_inferior_memory (mem_addr, mem_buf, len) != 0)
709 write_enn (own_buf);
710 else
711 write_ok (own_buf);
712 break;
713 case 'C':
714 convert_ascii_to_int (own_buf + 1, &sig, 1);
715 if (target_signal_to_host_p (sig))
716 signal = target_signal_to_host (sig);
717 else
718 signal = 0;
719 set_desired_inferior (0);
720 myresume (0, signal);
721 signal = mywait (&status, 1);
722 prepare_resume_reply (own_buf, status, signal);
723 break;
724 case 'S':
725 convert_ascii_to_int (own_buf + 1, &sig, 1);
726 if (target_signal_to_host_p (sig))
727 signal = target_signal_to_host (sig);
728 else
729 signal = 0;
730 set_desired_inferior (0);
731 myresume (1, signal);
732 signal = mywait (&status, 1);
733 prepare_resume_reply (own_buf, status, signal);
734 break;
735 case 'c':
736 set_desired_inferior (0);
737 myresume (0, 0);
738 signal = mywait (&status, 1);
739 prepare_resume_reply (own_buf, status, signal);
740 break;
741 case 's':
742 set_desired_inferior (0);
743 myresume (1, 0);
744 signal = mywait (&status, 1);
745 prepare_resume_reply (own_buf, status, signal);
746 break;
747 case 'Z':
748 {
749 char *lenptr;
750 char *dataptr;
751 CORE_ADDR addr = strtoul (&own_buf[3], &lenptr, 16);
752 int len = strtol (lenptr + 1, &dataptr, 16);
753 char type = own_buf[1];
754
755 if (the_target->insert_watchpoint == NULL
756 || (type < '2' || type > '4'))
757 {
758 /* No watchpoint support or not a watchpoint command;
759 unrecognized either way. */
760 own_buf[0] = '\0';
761 }
762 else
763 {
764 int res;
765
766 res = (*the_target->insert_watchpoint) (type, addr, len);
767 if (res == 0)
768 write_ok (own_buf);
769 else if (res == 1)
770 /* Unsupported. */
771 own_buf[0] = '\0';
772 else
773 write_enn (own_buf);
774 }
775 break;
776 }
777 case 'z':
778 {
779 char *lenptr;
780 char *dataptr;
781 CORE_ADDR addr = strtoul (&own_buf[3], &lenptr, 16);
782 int len = strtol (lenptr + 1, &dataptr, 16);
783 char type = own_buf[1];
784
785 if (the_target->remove_watchpoint == NULL
786 || (type < '2' || type > '4'))
787 {
788 /* No watchpoint support or not a watchpoint command;
789 unrecognized either way. */
790 own_buf[0] = '\0';
791 }
792 else
793 {
794 int res;
795
796 res = (*the_target->remove_watchpoint) (type, addr, len);
797 if (res == 0)
798 write_ok (own_buf);
799 else if (res == 1)
800 /* Unsupported. */
801 own_buf[0] = '\0';
802 else
803 write_enn (own_buf);
804 }
805 break;
806 }
807 case 'k':
808 fprintf (stderr, "Killing inferior\n");
809 kill_inferior ();
810 /* When using the extended protocol, we start up a new
811 debugging session. The traditional protocol will
812 exit instead. */
813 if (extended_protocol)
814 {
815 write_ok (own_buf);
816 fprintf (stderr, "GDBserver restarting\n");
817
818 /* Wait till we are at 1st instruction in prog. */
819 signal = start_inferior (&argv[2], &status);
820 goto restart;
821 break;
822 }
823 else
824 {
825 exit (0);
826 break;
827 }
828 case 'T':
829 {
830 unsigned long gdb_id, thread_id;
831
832 gdb_id = strtoul (&own_buf[1], NULL, 16);
833 thread_id = gdb_id_to_thread_id (gdb_id);
834 if (thread_id == 0)
835 {
836 write_enn (own_buf);
837 break;
838 }
839
840 if (mythread_alive (thread_id))
841 write_ok (own_buf);
842 else
843 write_enn (own_buf);
844 }
845 break;
846 case 'R':
847 /* Restarting the inferior is only supported in the
848 extended protocol. */
849 if (extended_protocol)
850 {
851 kill_inferior ();
852 write_ok (own_buf);
853 fprintf (stderr, "GDBserver restarting\n");
854
855 /* Wait till we are at 1st instruction in prog. */
856 signal = start_inferior (&argv[2], &status);
857 goto restart;
858 break;
859 }
860 else
861 {
862 /* It is a request we don't understand. Respond with an
863 empty packet so that gdb knows that we don't support this
864 request. */
865 own_buf[0] = '\0';
866 break;
867 }
868 case 'v':
869 /* Extended (long) request. */
870 handle_v_requests (own_buf, &status, &signal);
871 break;
872 default:
873 /* It is a request we don't understand. Respond with an
874 empty packet so that gdb knows that we don't support this
875 request. */
876 own_buf[0] = '\0';
877 break;
878 }
879
880 if (new_packet_len != -1)
881 putpkt_binary (own_buf, new_packet_len);
882 else
883 putpkt (own_buf);
884
885 if (status == 'W')
886 fprintf (stderr,
887 "\nChild exited with status %d\n", signal);
888 if (status == 'X')
889 fprintf (stderr, "\nChild terminated with signal = 0x%x (%s)\n",
890 target_signal_to_host (signal),
891 target_signal_to_name (signal));
892 if (status == 'W' || status == 'X')
893 {
894 if (extended_protocol)
895 {
896 fprintf (stderr, "Killing inferior\n");
897 kill_inferior ();
898 write_ok (own_buf);
899 fprintf (stderr, "GDBserver restarting\n");
900
901 /* Wait till we are at 1st instruction in prog. */
902 signal = start_inferior (&argv[2], &status);
903 goto restart;
904 break;
905 }
906 else
907 {
908 fprintf (stderr, "GDBserver exiting\n");
909 exit (0);
910 }
911 }
912 }
913
914 /* We come here when getpkt fails.
915
916 For the extended remote protocol we exit (and this is the only
917 way we gracefully exit!).
918
919 For the traditional remote protocol close the connection,
920 and re-open it at the top of the loop. */
921 if (extended_protocol)
922 {
923 remote_close ();
924 exit (0);
925 }
926 else
927 {
928 fprintf (stderr, "Remote side has terminated connection. "
929 "GDBserver will reopen the connection.\n");
930 remote_close ();
931 }
932 }
933 }
This page took 0.050579 seconds and 4 git commands to generate.