Add a test for weak alias
[deliverable/binutils-gdb.git] / gdb / gdbserver / server.c
CommitLineData
c906108c 1/* Main code for remote server for GDB.
0b302171
JB
2 Copyright (C) 1989, 1993-1995, 1997-2000, 2002-2012 Free Software
3 Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
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.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
19
20#include "server.h"
623b6bdf 21#include "gdbthread.h"
d1feda86 22#include "agent.h"
c906108c 23
68070c10 24#if HAVE_UNISTD_H
a9fa9f7d 25#include <unistd.h>
68070c10
PA
26#endif
27#if HAVE_SIGNAL_H
a9fa9f7d 28#include <signal.h>
68070c10 29#endif
b80864fb 30#if HAVE_SYS_WAIT_H
a9fa9f7d 31#include <sys/wait.h>
b80864fb 32#endif
a9fa9f7d 33
122f36ef
PA
34/* The thread set with an `Hc' packet. `Hc' is deprecated in favor of
35 `vCont'. Note the multi-process extensions made `vCont' a
36 requirement, so `Hc pPID.TID' is pretty much undefined. So
37 CONT_THREAD can be null_ptid for no `Hc' thread, minus_one_ptid for
38 resuming all threads of the process (again, `Hc' isn't used for
39 multi-process), or a specific thread ptid_t.
40
41 We also set this when handling a single-thread `vCont' resume, as
42 some places in the backends check it to know when (and for which
43 thread) single-thread scheduler-locking is in effect. */
95954743 44ptid_t cont_thread;
122f36ef
PA
45
46/* The thread set with an `Hg' packet. */
95954743 47ptid_t general_thread;
5b1c542e 48
0d62e5e8
DJ
49int server_waiting;
50
2d717e4f 51static int extended_protocol;
2d717e4f
DJ
52static int response_needed;
53static int exit_requested;
54
03f2bd59
JK
55/* --once: Exit after the first connection has closed. */
56int run_once;
57
95954743 58int multi_process;
bd99dc85
PA
59int non_stop;
60
03583c20
UW
61/* Whether we should attempt to disable the operating system's address
62 space randomization feature before starting an inferior. */
63int disable_randomization = 1;
64
ccd213ac 65static char **program_argv, **wrapper_argv;
2d717e4f 66
c74d0ad8
DJ
67/* Enable miscellaneous debugging output. The name is historical - it
68 was originally used to debug LinuxThreads support. */
69int debug_threads;
70
aa5ca48f
DE
71/* Enable debugging of h/w breakpoint/watchpoint support. */
72int debug_hw_points;
73
a493e3e2
PA
74int pass_signals[GDB_SIGNAL_LAST];
75int program_signals[GDB_SIGNAL_LAST];
9b224c5e 76int program_signals_p;
89be2091 77
c906108c 78jmp_buf toplevel;
c906108c 79
9b4b61c8
UW
80const char *gdbserver_xmltarget;
81
a9fa9f7d
DJ
82/* The PID of the originally created or attached inferior. Used to
83 send signals to the process when GDB sends us an asynchronous interrupt
84 (user hitting Control-C in the client), and to wait for the child to exit
85 when no longer debugging it. */
86
a1928bad 87unsigned long signal_pid;
a9fa9f7d 88
290fadea
RS
89#ifdef SIGTTOU
90/* A file descriptor for the controlling terminal. */
91int terminal_fd;
92
93/* TERMINAL_FD's original foreground group. */
94pid_t old_foreground_pgrp;
95
96/* Hand back terminal ownership to the original foreground group. */
97
98static void
99restore_old_foreground_pgrp (void)
100{
101 tcsetpgrp (terminal_fd, old_foreground_pgrp);
102}
103#endif
104
ec56be1b
PA
105/* Set if you want to disable optional thread related packets support
106 in gdbserver, for the sake of testing GDB against stubs that don't
107 support them. */
108int disable_packet_vCont;
109int disable_packet_Tthread;
110int disable_packet_qC;
111int disable_packet_qfThreadInfo;
112
5b1c542e
PA
113/* Last status reported to GDB. */
114static struct target_waitstatus last_status;
95954743 115static ptid_t last_ptid;
5b1c542e 116
bd99dc85
PA
117static char *own_buf;
118static unsigned char *mem_buf;
119
120/* Structure holding information relative to a single stop reply. We
121 keep a queue of these (really a singly-linked list) to push to GDB
122 in non-stop mode. */
123struct vstop_notif
124{
125 /* Pointer to next in list. */
126 struct vstop_notif *next;
127
128 /* Thread or process that got the event. */
95954743 129 ptid_t ptid;
bd99dc85
PA
130
131 /* Event info. */
132 struct target_waitstatus status;
133};
134
135/* The pending stop replies list head. */
136static struct vstop_notif *notif_queue = NULL;
137
138/* Put a stop reply to the stop reply queue. */
139
140static void
95954743 141queue_stop_reply (ptid_t ptid, struct target_waitstatus *status)
bd99dc85
PA
142{
143 struct vstop_notif *new_notif;
144
cfdee94a 145 new_notif = xmalloc (sizeof (*new_notif));
bd99dc85
PA
146 new_notif->next = NULL;
147 new_notif->ptid = ptid;
148 new_notif->status = *status;
149
150 if (notif_queue)
151 {
152 struct vstop_notif *tail;
153 for (tail = notif_queue;
154 tail && tail->next;
155 tail = tail->next)
156 ;
157 tail->next = new_notif;
158 }
159 else
160 notif_queue = new_notif;
161
162 if (remote_debug)
163 {
164 int i = 0;
165 struct vstop_notif *n;
166
167 for (n = notif_queue; n; n = n->next)
168 i++;
169
170 fprintf (stderr, "pending stop replies: %d\n", i);
171 }
172}
173
174/* Place an event in the stop reply queue, and push a notification if
175 we aren't sending one yet. */
176
177void
95954743 178push_event (ptid_t ptid, struct target_waitstatus *status)
bd99dc85 179{
d20a8ad9
PA
180 gdb_assert (status->kind != TARGET_WAITKIND_IGNORE);
181
bd99dc85
PA
182 queue_stop_reply (ptid, status);
183
184 /* If this is the first stop reply in the queue, then inform GDB
185 about it, by sending a Stop notification. */
186 if (notif_queue->next == NULL)
187 {
188 char *p = own_buf;
189 strcpy (p, "Stop:");
190 p += strlen (p);
191 prepare_resume_reply (p,
192 notif_queue->ptid, &notif_queue->status);
193 putpkt_notif (own_buf);
194 }
195}
196
95954743
PA
197/* Get rid of the currently pending stop replies for PID. If PID is
198 -1, then apply to all processes. */
bd99dc85
PA
199
200static void
95954743 201discard_queued_stop_replies (int pid)
bd99dc85 202{
95954743 203 struct vstop_notif *prev = NULL, *reply, *next;
bd99dc85 204
95954743 205 for (reply = notif_queue; reply; reply = next)
bd99dc85 206 {
95954743
PA
207 next = reply->next;
208
209 if (pid == -1
210 || ptid_get_pid (reply->ptid) == pid)
211 {
212 if (reply == notif_queue)
213 notif_queue = next;
214 else
215 prev->next = reply->next;
bd99dc85 216
95954743
PA
217 free (reply);
218 }
219 else
220 prev = reply;
bd99dc85
PA
221 }
222}
223
224/* If there are more stop replies to push, push one now. */
225
226static void
227send_next_stop_reply (char *own_buf)
228{
229 if (notif_queue)
230 prepare_resume_reply (own_buf,
231 notif_queue->ptid,
232 &notif_queue->status);
233 else
234 write_ok (own_buf);
235}
236
2d717e4f
DJ
237static int
238target_running (void)
239{
240 return all_threads.head != NULL;
241}
242
fc620387 243static int
5b1c542e 244start_inferior (char **argv)
c906108c 245{
ccd213ac 246 char **new_argv = argv;
2d717e4f 247
ccd213ac
DJ
248 if (wrapper_argv != NULL)
249 {
250 int i, count = 1;
251
252 for (i = 0; wrapper_argv[i] != NULL; i++)
253 count++;
254 for (i = 0; argv[i] != NULL; i++)
255 count++;
256 new_argv = alloca (sizeof (char *) * count);
257 count = 0;
258 for (i = 0; wrapper_argv[i] != NULL; i++)
259 new_argv[count++] = wrapper_argv[i];
260 for (i = 0; argv[i] != NULL; i++)
261 new_argv[count++] = argv[i];
262 new_argv[count] = NULL;
263 }
264
65730243
DE
265 if (debug_threads)
266 {
267 int i;
268 for (i = 0; new_argv[i]; ++i)
269 fprintf (stderr, "new_argv[%d] = \"%s\"\n", i, new_argv[i]);
270 fflush (stderr);
271 }
272
b80864fb 273#ifdef SIGTTOU
a9fa9f7d
DJ
274 signal (SIGTTOU, SIG_DFL);
275 signal (SIGTTIN, SIG_DFL);
b80864fb 276#endif
a9fa9f7d 277
122f36ef
PA
278 /* Clear this so the backend doesn't get confused, thinking
279 CONT_THREAD died, and it needs to resume all threads. */
280 cont_thread = null_ptid;
281
ccd213ac 282 signal_pid = create_inferior (new_argv[0], new_argv);
0d62e5e8 283
c588c53c
MS
284 /* FIXME: we don't actually know at this point that the create
285 actually succeeded. We won't know that until we wait. */
a1928bad 286 fprintf (stderr, "Process %s created; pid = %ld\n", argv[0],
a9fa9f7d 287 signal_pid);
b80864fb 288 fflush (stderr);
a9fa9f7d 289
b80864fb 290#ifdef SIGTTOU
a9fa9f7d
DJ
291 signal (SIGTTOU, SIG_IGN);
292 signal (SIGTTIN, SIG_IGN);
290fadea
RS
293 terminal_fd = fileno (stderr);
294 old_foreground_pgrp = tcgetpgrp (terminal_fd);
295 tcsetpgrp (terminal_fd, signal_pid);
296 atexit (restore_old_foreground_pgrp);
b80864fb 297#endif
c906108c 298
ccd213ac
DJ
299 if (wrapper_argv != NULL)
300 {
301 struct thread_resume resume_info;
ccd213ac 302
95954743 303 resume_info.thread = pid_to_ptid (signal_pid);
bd99dc85 304 resume_info.kind = resume_continue;
ccd213ac 305 resume_info.sig = 0;
ccd213ac 306
06db92f0 307 last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
bd99dc85 308
5b1c542e
PA
309 if (last_status.kind != TARGET_WAITKIND_STOPPED)
310 return signal_pid;
ccd213ac
DJ
311
312 do
313 {
2bd7c093 314 (*the_target->resume) (&resume_info, 1);
ccd213ac 315
06db92f0 316 last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
5b1c542e
PA
317 if (last_status.kind != TARGET_WAITKIND_STOPPED)
318 return signal_pid;
d20a8ad9
PA
319
320 current_inferior->last_resume_kind = resume_stop;
321 current_inferior->last_status = last_status;
ccd213ac 322 }
a493e3e2 323 while (last_status.value.sig != GDB_SIGNAL_TRAP);
ccd213ac 324
5b1c542e 325 return signal_pid;
ccd213ac
DJ
326 }
327
5b1c542e
PA
328 /* Wait till we are at 1st instruction in program, return new pid
329 (assuming success). */
95954743 330 last_ptid = mywait (pid_to_ptid (signal_pid), &last_status, 0, 0);
5b1c542e 331
d20a8ad9
PA
332 if (last_status.kind != TARGET_WAITKIND_EXITED
333 && last_status.kind != TARGET_WAITKIND_SIGNALLED)
334 {
335 current_inferior->last_resume_kind = resume_stop;
336 current_inferior->last_status = last_status;
337 }
338
5b1c542e 339 return signal_pid;
c906108c
SS
340}
341
45b7b345 342static int
5b1c542e 343attach_inferior (int pid)
45b7b345
DJ
344{
345 /* myattach should return -1 if attaching is unsupported,
346 0 if it succeeded, and call error() otherwise. */
a9fa9f7d 347
45b7b345
DJ
348 if (myattach (pid) != 0)
349 return -1;
350
6910d122 351 fprintf (stderr, "Attached; pid = %d\n", pid);
b80864fb 352 fflush (stderr);
6910d122 353
a9fa9f7d
DJ
354 /* FIXME - It may be that we should get the SIGNAL_PID from the
355 attach function, so that it can be the main thread instead of
356 whichever we were told to attach to. */
357 signal_pid = pid;
358
7d5d4e98
PA
359 /* Clear this so the backend doesn't get confused, thinking
360 CONT_THREAD died, and it needs to resume all threads. */
361 cont_thread = null_ptid;
362
bd99dc85
PA
363 if (!non_stop)
364 {
95954743 365 last_ptid = mywait (pid_to_ptid (pid), &last_status, 0, 0);
bd99dc85
PA
366
367 /* GDB knows to ignore the first SIGSTOP after attaching to a running
368 process using the "attach" command, but this is different; it's
369 just using "target remote". Pretend it's just starting up. */
370 if (last_status.kind == TARGET_WAITKIND_STOPPED
a493e3e2
PA
371 && last_status.value.sig == GDB_SIGNAL_STOP)
372 last_status.value.sig = GDB_SIGNAL_TRAP;
d20a8ad9
PA
373
374 current_inferior->last_resume_kind = resume_stop;
375 current_inferior->last_status = last_status;
bd99dc85 376 }
9db87ebd 377
45b7b345
DJ
378 return 0;
379}
380
c906108c 381extern int remote_debug;
ce3a066d 382
0876f84a
DJ
383/* Decode a qXfer read request. Return 0 if everything looks OK,
384 or -1 otherwise. */
385
386static int
d08aafef 387decode_xfer_read (char *buf, CORE_ADDR *ofs, unsigned int *len)
0876f84a 388{
d08aafef
PA
389 /* After the read marker and annex, qXfer looks like a
390 traditional 'm' packet. */
391 decode_m_packet (buf, ofs, len);
392
393 return 0;
394}
395
396static int
397decode_xfer (char *buf, char **object, char **rw, char **annex, char **offset)
398{
399 /* Extract and NUL-terminate the object. */
400 *object = buf;
401 while (*buf && *buf != ':')
402 buf++;
403 if (*buf == '\0')
404 return -1;
405 *buf++ = 0;
406
407 /* Extract and NUL-terminate the read/write action. */
408 *rw = buf;
409 while (*buf && *buf != ':')
410 buf++;
411 if (*buf == '\0')
412 return -1;
413 *buf++ = 0;
414
0876f84a
DJ
415 /* Extract and NUL-terminate the annex. */
416 *annex = buf;
417 while (*buf && *buf != ':')
418 buf++;
419 if (*buf == '\0')
420 return -1;
421 *buf++ = 0;
422
d08aafef 423 *offset = buf;
0876f84a
DJ
424 return 0;
425}
426
427/* Write the response to a successful qXfer read. Returns the
428 length of the (binary) data stored in BUF, corresponding
429 to as much of DATA/LEN as we could fit. IS_MORE controls
430 the first character of the response. */
431static int
23181151 432write_qxfer_response (char *buf, const void *data, int len, int is_more)
0876f84a
DJ
433{
434 int out_len;
435
436 if (is_more)
437 buf[0] = 'm';
438 else
439 buf[0] = 'l';
440
441 return remote_escape_output (data, len, (unsigned char *) buf + 1, &out_len,
442 PBUFSIZ - 2) + 1;
443}
444
89be2091 445/* Handle all of the extended 'Q' packets. */
ae1ada35
DE
446
447static void
89be2091
DJ
448handle_general_set (char *own_buf)
449{
450 if (strncmp ("QPassSignals:", own_buf, strlen ("QPassSignals:")) == 0)
451 {
a493e3e2 452 int numsigs = (int) GDB_SIGNAL_LAST, i;
89be2091
DJ
453 const char *p = own_buf + strlen ("QPassSignals:");
454 CORE_ADDR cursig;
455
456 p = decode_address_to_semicolon (&cursig, p);
457 for (i = 0; i < numsigs; i++)
458 {
459 if (i == cursig)
460 {
461 pass_signals[i] = 1;
462 if (*p == '\0')
463 /* Keep looping, to clear the remaining signals. */
464 cursig = -1;
465 else
466 p = decode_address_to_semicolon (&cursig, p);
467 }
468 else
469 pass_signals[i] = 0;
470 }
471 strcpy (own_buf, "OK");
472 return;
473 }
474
9b224c5e
PA
475 if (strncmp ("QProgramSignals:", own_buf, strlen ("QProgramSignals:")) == 0)
476 {
a493e3e2 477 int numsigs = (int) GDB_SIGNAL_LAST, i;
9b224c5e
PA
478 const char *p = own_buf + strlen ("QProgramSignals:");
479 CORE_ADDR cursig;
480
481 program_signals_p = 1;
482
483 p = decode_address_to_semicolon (&cursig, p);
484 for (i = 0; i < numsigs; i++)
485 {
486 if (i == cursig)
487 {
488 program_signals[i] = 1;
489 if (*p == '\0')
490 /* Keep looping, to clear the remaining signals. */
491 cursig = -1;
492 else
493 p = decode_address_to_semicolon (&cursig, p);
494 }
495 else
496 program_signals[i] = 0;
497 }
498 strcpy (own_buf, "OK");
499 return;
500 }
501
a6f3e723
SL
502 if (strcmp (own_buf, "QStartNoAckMode") == 0)
503 {
504 if (remote_debug)
505 {
506 fprintf (stderr, "[noack mode enabled]\n");
507 fflush (stderr);
508 }
509
510 noack_mode = 1;
511 write_ok (own_buf);
512 return;
513 }
514
bd99dc85
PA
515 if (strncmp (own_buf, "QNonStop:", 9) == 0)
516 {
517 char *mode = own_buf + 9;
518 int req = -1;
519 char *req_str;
520
521 if (strcmp (mode, "0") == 0)
522 req = 0;
523 else if (strcmp (mode, "1") == 0)
524 req = 1;
525 else
526 {
527 /* We don't know what this mode is, so complain to
528 GDB. */
529 fprintf (stderr, "Unknown non-stop mode requested: %s\n",
530 own_buf);
531 write_enn (own_buf);
532 return;
533 }
534
535 req_str = req ? "non-stop" : "all-stop";
536 if (start_non_stop (req) != 0)
537 {
538 fprintf (stderr, "Setting %s mode failed\n", req_str);
539 write_enn (own_buf);
540 return;
541 }
542
543 non_stop = req;
544
545 if (remote_debug)
546 fprintf (stderr, "[%s mode enabled]\n", req_str);
547
548 write_ok (own_buf);
549 return;
550 }
551
03583c20
UW
552 if (strncmp ("QDisableRandomization:", own_buf,
553 strlen ("QDisableRandomization:")) == 0)
554 {
555 char *packet = own_buf + strlen ("QDisableRandomization:");
556 ULONGEST setting;
557
558 unpack_varlen_hex (packet, &setting);
559 disable_randomization = setting;
560
561 if (remote_debug)
562 {
563 if (disable_randomization)
564 fprintf (stderr, "[address space randomization disabled]\n");
565 else
566 fprintf (stderr, "[address space randomization enabled]\n");
567 }
568
569 write_ok (own_buf);
570 return;
571 }
572
219f2f23
PA
573 if (target_supports_tracepoints ()
574 && handle_tracepoint_general_set (own_buf))
575 return;
576
d1feda86
YQ
577 if (strncmp ("QAgent:", own_buf, strlen ("QAgent:")) == 0)
578 {
579 char *mode = own_buf + strlen ("QAgent:");
580 int req = 0;
581
582 if (strcmp (mode, "0") == 0)
583 req = 0;
584 else if (strcmp (mode, "1") == 0)
585 req = 1;
586 else
587 {
588 /* We don't know what this value is, so complain to GDB. */
589 sprintf (own_buf, "E.Unknown QAgent value");
590 return;
591 }
592
593 /* Update the flag. */
594 use_agent = req;
595 if (remote_debug)
596 fprintf (stderr, "[%s agent]\n", req ? "Enable" : "Disable");
597 write_ok (own_buf);
598 return;
599 }
600
89be2091
DJ
601 /* Otherwise we didn't know what packet it was. Say we didn't
602 understand it. */
603 own_buf[0] = 0;
604}
605
23181151 606static const char *
fb1e4ffc 607get_features_xml (const char *annex)
23181151 608{
9b4b61c8
UW
609 /* gdbserver_xmltarget defines what to return when looking
610 for the "target.xml" file. Its contents can either be
611 verbatim XML code (prefixed with a '@') or else the name
612 of the actual XML file to be used in place of "target.xml".
fb1e4ffc 613
9b4b61c8
UW
614 This variable is set up from the auto-generated
615 init_registers_... routine for the current target. */
fb1e4ffc 616
9b4b61c8 617 if (gdbserver_xmltarget
221c031f 618 && strcmp (annex, "target.xml") == 0)
23181151 619 {
9b4b61c8
UW
620 if (*gdbserver_xmltarget == '@')
621 return gdbserver_xmltarget + 1;
23181151 622 else
9b4b61c8 623 annex = gdbserver_xmltarget;
23181151
DJ
624 }
625
9b4b61c8
UW
626#ifdef USE_XML
627 {
628 extern const char *const xml_builtin[][2];
629 int i;
630
631 /* Look for the annex. */
632 for (i = 0; xml_builtin[i][0] != NULL; i++)
633 if (strcmp (annex, xml_builtin[i][0]) == 0)
634 break;
635
636 if (xml_builtin[i][0] != NULL)
637 return xml_builtin[i][1];
638 }
639#endif
640
641 return NULL;
23181151
DJ
642}
643
c74d0ad8
DJ
644void
645monitor_show_help (void)
646{
647 monitor_output ("The following monitor commands are supported:\n");
648 monitor_output (" set debug <0|1>\n");
1b3f6016 649 monitor_output (" Enable general debugging messages\n");
aa5ca48f
DE
650 monitor_output (" set debug-hw-points <0|1>\n");
651 monitor_output (" Enable h/w breakpoint/watchpoint debugging messages\n");
c74d0ad8
DJ
652 monitor_output (" set remote-debug <0|1>\n");
653 monitor_output (" Enable remote protocol debugging messages\n");
ecd7ecbc
DJ
654 monitor_output (" exit\n");
655 monitor_output (" Quit GDBserver\n");
c74d0ad8
DJ
656}
657
764880b7
PA
658/* Read trace frame or inferior memory. Returns the number of bytes
659 actually read, zero when no further transfer is possible, and -1 on
660 error. Return of a positive value smaller than LEN does not
661 indicate there's no more to be read, only the end of the transfer.
662 E.g., when GDB reads memory from a traceframe, a first request may
663 be served from a memory block that does not cover the whole request
664 length. A following request gets the rest served from either
665 another block (of the same traceframe) or from the read-only
666 regions. */
219f2f23
PA
667
668static int
90d74c30 669gdb_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
219f2f23 670{
764880b7 671 int res;
90d74c30 672
219f2f23
PA
673 if (current_traceframe >= 0)
674 {
675 ULONGEST nbytes;
676 ULONGEST length = len;
677
678 if (traceframe_read_mem (current_traceframe,
679 memaddr, myaddr, len, &nbytes))
680 return EIO;
681 /* Data read from trace buffer, we're done. */
764880b7
PA
682 if (nbytes > 0)
683 return nbytes;
219f2f23 684 if (!in_readonly_region (memaddr, length))
764880b7 685 return -1;
219f2f23
PA
686 /* Otherwise we have a valid readonly case, fall through. */
687 /* (assume no half-trace half-real blocks for now) */
688 }
689
764880b7
PA
690 res = prepare_to_access_memory ();
691 if (res == 0)
90d74c30 692 {
764880b7 693 res = read_inferior_memory (memaddr, myaddr, len);
0146f85b 694 done_accessing_memory ();
90d74c30 695
764880b7
PA
696 return res == 0 ? len : -1;
697 }
698 else
699 return -1;
219f2f23
PA
700}
701
702/* Write trace frame or inferior memory. Actually, writing to trace
703 frames is forbidden. */
704
705static int
90d74c30 706gdb_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
219f2f23
PA
707{
708 if (current_traceframe >= 0)
709 return EIO;
710 else
90d74c30
PA
711 {
712 int ret;
713
714 ret = prepare_to_access_memory ();
715 if (ret == 0)
716 {
717 ret = write_inferior_memory (memaddr, myaddr, len);
0146f85b 718 done_accessing_memory ();
90d74c30
PA
719 }
720 return ret;
721 }
219f2f23
PA
722}
723
08388c79
DE
724/* Subroutine of handle_search_memory to simplify it. */
725
726static int
727handle_search_memory_1 (CORE_ADDR start_addr, CORE_ADDR search_space_len,
728 gdb_byte *pattern, unsigned pattern_len,
729 gdb_byte *search_buf,
730 unsigned chunk_size, unsigned search_buf_size,
731 CORE_ADDR *found_addrp)
732{
733 /* Prime the search buffer. */
734
764880b7
PA
735 if (gdb_read_memory (start_addr, search_buf, search_buf_size)
736 != search_buf_size)
08388c79 737 {
5e1471f5 738 warning ("Unable to access target memory at 0x%lx, halting search.",
08388c79
DE
739 (long) start_addr);
740 return -1;
741 }
742
743 /* Perform the search.
744
745 The loop is kept simple by allocating [N + pattern-length - 1] bytes.
746 When we've scanned N bytes we copy the trailing bytes to the start and
747 read in another N bytes. */
748
749 while (search_space_len >= pattern_len)
750 {
751 gdb_byte *found_ptr;
752 unsigned nr_search_bytes = (search_space_len < search_buf_size
753 ? search_space_len
754 : search_buf_size);
755
756 found_ptr = memmem (search_buf, nr_search_bytes, pattern, pattern_len);
757
758 if (found_ptr != NULL)
759 {
760 CORE_ADDR found_addr = start_addr + (found_ptr - search_buf);
761 *found_addrp = found_addr;
762 return 1;
763 }
764
765 /* Not found in this chunk, skip to next chunk. */
766
767 /* Don't let search_space_len wrap here, it's unsigned. */
768 if (search_space_len >= chunk_size)
769 search_space_len -= chunk_size;
770 else
771 search_space_len = 0;
772
773 if (search_space_len >= pattern_len)
774 {
775 unsigned keep_len = search_buf_size - chunk_size;
8a35fb51 776 CORE_ADDR read_addr = start_addr + chunk_size + keep_len;
08388c79
DE
777 int nr_to_read;
778
779 /* Copy the trailing part of the previous iteration to the front
780 of the buffer for the next iteration. */
781 memcpy (search_buf, search_buf + chunk_size, keep_len);
782
783 nr_to_read = (search_space_len - keep_len < chunk_size
784 ? search_space_len - keep_len
785 : chunk_size);
786
90d74c30 787 if (gdb_read_memory (read_addr, search_buf + keep_len,
764880b7 788 nr_to_read) != search_buf_size)
08388c79 789 {
493e2a69
MS
790 warning ("Unable to access target memory "
791 "at 0x%lx, halting search.",
08388c79
DE
792 (long) read_addr);
793 return -1;
794 }
795
796 start_addr += chunk_size;
797 }
798 }
799
800 /* Not found. */
801
802 return 0;
803}
804
805/* Handle qSearch:memory packets. */
806
807static void
808handle_search_memory (char *own_buf, int packet_len)
809{
810 CORE_ADDR start_addr;
811 CORE_ADDR search_space_len;
812 gdb_byte *pattern;
813 unsigned int pattern_len;
814 /* NOTE: also defined in find.c testcase. */
815#define SEARCH_CHUNK_SIZE 16000
816 const unsigned chunk_size = SEARCH_CHUNK_SIZE;
817 /* Buffer to hold memory contents for searching. */
818 gdb_byte *search_buf;
819 unsigned search_buf_size;
820 int found;
821 CORE_ADDR found_addr;
822 int cmd_name_len = sizeof ("qSearch:memory:") - 1;
823
aef93bd7 824 pattern = malloc (packet_len);
08388c79
DE
825 if (pattern == NULL)
826 {
5e1471f5 827 error ("Unable to allocate memory to perform the search");
08388c79
DE
828 strcpy (own_buf, "E00");
829 return;
830 }
831 if (decode_search_memory_packet (own_buf + cmd_name_len,
832 packet_len - cmd_name_len,
833 &start_addr, &search_space_len,
834 pattern, &pattern_len) < 0)
835 {
836 free (pattern);
5e1471f5 837 error ("Error in parsing qSearch:memory packet");
08388c79
DE
838 strcpy (own_buf, "E00");
839 return;
840 }
841
842 search_buf_size = chunk_size + pattern_len - 1;
843
844 /* No point in trying to allocate a buffer larger than the search space. */
845 if (search_space_len < search_buf_size)
846 search_buf_size = search_space_len;
847
aef93bd7 848 search_buf = malloc (search_buf_size);
08388c79
DE
849 if (search_buf == NULL)
850 {
851 free (pattern);
5e1471f5 852 error ("Unable to allocate memory to perform the search");
08388c79
DE
853 strcpy (own_buf, "E00");
854 return;
855 }
856
857 found = handle_search_memory_1 (start_addr, search_space_len,
858 pattern, pattern_len,
859 search_buf, chunk_size, search_buf_size,
860 &found_addr);
861
862 if (found > 0)
863 sprintf (own_buf, "1,%lx", (long) found_addr);
864 else if (found == 0)
865 strcpy (own_buf, "0");
866 else
867 strcpy (own_buf, "E00");
868
869 free (search_buf);
870 free (pattern);
871}
872
2d717e4f
DJ
873#define require_running(BUF) \
874 if (!target_running ()) \
875 { \
876 write_enn (BUF); \
877 return; \
878 }
879
cdbfd419
PP
880/* Handle monitor commands not handled by target-specific handlers. */
881
882static void
d73f2619 883handle_monitor_command (char *mon, char *own_buf)
cdbfd419
PP
884{
885 if (strcmp (mon, "set debug 1") == 0)
886 {
887 debug_threads = 1;
888 monitor_output ("Debug output enabled.\n");
889 }
890 else if (strcmp (mon, "set debug 0") == 0)
891 {
892 debug_threads = 0;
893 monitor_output ("Debug output disabled.\n");
894 }
895 else if (strcmp (mon, "set debug-hw-points 1") == 0)
896 {
897 debug_hw_points = 1;
898 monitor_output ("H/W point debugging output enabled.\n");
899 }
900 else if (strcmp (mon, "set debug-hw-points 0") == 0)
901 {
902 debug_hw_points = 0;
903 monitor_output ("H/W point debugging output disabled.\n");
904 }
905 else if (strcmp (mon, "set remote-debug 1") == 0)
906 {
907 remote_debug = 1;
908 monitor_output ("Protocol debug output enabled.\n");
909 }
910 else if (strcmp (mon, "set remote-debug 0") == 0)
911 {
912 remote_debug = 0;
913 monitor_output ("Protocol debug output disabled.\n");
914 }
915 else if (strcmp (mon, "help") == 0)
916 monitor_show_help ();
917 else if (strcmp (mon, "exit") == 0)
918 exit_requested = 1;
919 else
920 {
921 monitor_output ("Unknown monitor command.\n\n");
922 monitor_show_help ();
923 write_enn (own_buf);
924 }
925}
926
d08aafef
PA
927/* Associates a callback with each supported qXfer'able object. */
928
929struct qxfer
930{
931 /* The object this handler handles. */
932 const char *object;
933
934 /* Request that the target transfer up to LEN 8-bit bytes of the
935 target's OBJECT. The OFFSET, for a seekable object, specifies
936 the starting point. The ANNEX can be used to provide additional
937 data-specific information to the target.
938
939 Return the number of bytes actually transfered, zero when no
940 further transfer is possible, -1 on error, and -2 when the
941 transfer is not supported. Return of a positive value smaller
942 than LEN does not indicate the end of the object, only the end of
943 the transfer.
944
945 One, and only one, of readbuf or writebuf must be non-NULL. */
946 int (*xfer) (const char *annex,
947 gdb_byte *readbuf, const gdb_byte *writebuf,
948 ULONGEST offset, LONGEST len);
949};
950
951/* Handle qXfer:auxv:read. */
952
953static int
954handle_qxfer_auxv (const char *annex,
955 gdb_byte *readbuf, const gdb_byte *writebuf,
956 ULONGEST offset, LONGEST len)
957{
958 if (the_target->read_auxv == NULL || writebuf != NULL)
959 return -2;
960
961 if (annex[0] != '\0' || !target_running ())
962 return -1;
963
964 return (*the_target->read_auxv) (offset, readbuf, len);
965}
966
967/* Handle qXfer:features:read. */
968
969static int
970handle_qxfer_features (const char *annex,
971 gdb_byte *readbuf, const gdb_byte *writebuf,
972 ULONGEST offset, LONGEST len)
973{
974 const char *document;
975 size_t total_len;
976
977 if (writebuf != NULL)
978 return -2;
979
980 if (!target_running ())
981 return -1;
982
983 /* Grab the correct annex. */
984 document = get_features_xml (annex);
985 if (document == NULL)
986 return -1;
987
988 total_len = strlen (document);
989
990 if (offset > total_len)
991 return -1;
992
993 if (offset + len > total_len)
994 len = total_len - offset;
995
996 memcpy (readbuf, document + offset, len);
997 return len;
998}
999
1000/* Handle qXfer:libraries:read. */
1001
1002static int
1003handle_qxfer_libraries (const char *annex,
1004 gdb_byte *readbuf, const gdb_byte *writebuf,
1005 ULONGEST offset, LONGEST len)
1006{
1007 unsigned int total_len;
1008 char *document, *p;
1009 struct inferior_list_entry *dll_ptr;
1010
1011 if (writebuf != NULL)
1012 return -2;
1013
1014 if (annex[0] != '\0' || !target_running ())
1015 return -1;
1016
1017 /* Over-estimate the necessary memory. Assume that every character
1018 in the library name must be escaped. */
1019 total_len = 64;
1020 for (dll_ptr = all_dlls.head; dll_ptr != NULL; dll_ptr = dll_ptr->next)
1021 total_len += 128 + 6 * strlen (((struct dll_info *) dll_ptr)->name);
1022
1023 document = malloc (total_len);
1024 if (document == NULL)
1025 return -1;
1026
1027 strcpy (document, "<library-list>\n");
1028 p = document + strlen (document);
1029
1030 for (dll_ptr = all_dlls.head; dll_ptr != NULL; dll_ptr = dll_ptr->next)
1031 {
1032 struct dll_info *dll = (struct dll_info *) dll_ptr;
1033 char *name;
1034
1035 strcpy (p, " <library name=\"");
1036 p = p + strlen (p);
1037 name = xml_escape_text (dll->name);
1038 strcpy (p, name);
1039 free (name);
1040 p = p + strlen (p);
1041 strcpy (p, "\"><segment address=\"");
1042 p = p + strlen (p);
1043 sprintf (p, "0x%lx", (long) dll->base_addr);
1044 p = p + strlen (p);
1045 strcpy (p, "\"/></library>\n");
1046 p = p + strlen (p);
1047 }
1048
1049 strcpy (p, "</library-list>\n");
1050
1051 total_len = strlen (document);
1052
1053 if (offset > total_len)
1054 {
1055 free (document);
1056 return -1;
1057 }
1058
1059 if (offset + len > total_len)
1060 len = total_len - offset;
1061
1062 memcpy (readbuf, document + offset, len);
1063 free (document);
1064 return len;
1065}
1066
2268b414
JK
1067/* Handle qXfer:libraries-svr4:read. */
1068
1069static int
1070handle_qxfer_libraries_svr4 (const char *annex,
1071 gdb_byte *readbuf, const gdb_byte *writebuf,
1072 ULONGEST offset, LONGEST len)
1073{
1074 if (writebuf != NULL)
1075 return -2;
1076
1077 if (annex[0] != '\0' || !target_running ()
1078 || the_target->qxfer_libraries_svr4 == NULL)
1079 return -1;
1080
1081 return the_target->qxfer_libraries_svr4 (annex, readbuf, writebuf, offset, len);
1082}
1083
d08aafef
PA
1084/* Handle qXfer:osadata:read. */
1085
1086static int
1087handle_qxfer_osdata (const char *annex,
1088 gdb_byte *readbuf, const gdb_byte *writebuf,
1089 ULONGEST offset, LONGEST len)
1090{
1091 if (the_target->qxfer_osdata == NULL || writebuf != NULL)
1092 return -2;
1093
1094 return (*the_target->qxfer_osdata) (annex, readbuf, NULL, offset, len);
1095}
1096
1097/* Handle qXfer:siginfo:read and qXfer:siginfo:write. */
1098
1099static int
1100handle_qxfer_siginfo (const char *annex,
1101 gdb_byte *readbuf, const gdb_byte *writebuf,
1102 ULONGEST offset, LONGEST len)
1103{
1104 if (the_target->qxfer_siginfo == NULL)
1105 return -2;
1106
1107 if (annex[0] != '\0' || !target_running ())
1108 return -1;
1109
1110 return (*the_target->qxfer_siginfo) (annex, readbuf, writebuf, offset, len);
1111}
1112
1113/* Handle qXfer:spu:read and qXfer:spu:write. */
1114
1115static int
1116handle_qxfer_spu (const char *annex,
1117 gdb_byte *readbuf, const gdb_byte *writebuf,
1118 ULONGEST offset, LONGEST len)
1119{
1120 if (the_target->qxfer_spu == NULL)
1121 return -2;
1122
1123 if (!target_running ())
1124 return -1;
1125
1126 return (*the_target->qxfer_spu) (annex, readbuf, writebuf, offset, len);
1127}
1128
1129/* Handle qXfer:statictrace:read. */
1130
1131static int
1132handle_qxfer_statictrace (const char *annex,
1133 gdb_byte *readbuf, const gdb_byte *writebuf,
1134 ULONGEST offset, LONGEST len)
1135{
1136 ULONGEST nbytes;
1137
1138 if (writebuf != NULL)
1139 return -2;
1140
1141 if (annex[0] != '\0' || !target_running () || current_traceframe == -1)
1142 return -1;
1143
1144 if (traceframe_read_sdata (current_traceframe, offset,
1145 readbuf, len, &nbytes))
1146 return -1;
1147 return nbytes;
1148}
1149
1150/* Helper for handle_qxfer_threads. */
1151
dc146f7c 1152static void
d08aafef 1153handle_qxfer_threads_proper (struct buffer *buffer)
dc146f7c
VP
1154{
1155 struct inferior_list_entry *thread;
1156
1157 buffer_grow_str (buffer, "<threads>\n");
1158
1159 for (thread = all_threads.head; thread; thread = thread->next)
1160 {
1161 ptid_t ptid = thread_to_gdb_id ((struct thread_info *)thread);
1162 char ptid_s[100];
3e10640f 1163 int core = target_core_of_thread (ptid);
dc146f7c
VP
1164 char core_s[21];
1165
1166 write_ptid (ptid_s, ptid);
1167
dc146f7c
VP
1168 if (core != -1)
1169 {
1170 sprintf (core_s, "%d", core);
1171 buffer_xml_printf (buffer, "<thread id=\"%s\" core=\"%s\"/>\n",
1172 ptid_s, core_s);
1173 }
1174 else
1175 {
1176 buffer_xml_printf (buffer, "<thread id=\"%s\"/>\n",
1177 ptid_s);
1178 }
1179 }
1180
1181 buffer_grow_str0 (buffer, "</threads>\n");
1182}
1183
d08aafef
PA
1184/* Handle qXfer:threads:read. */
1185
dc146f7c 1186static int
d08aafef
PA
1187handle_qxfer_threads (const char *annex,
1188 gdb_byte *readbuf, const gdb_byte *writebuf,
1189 ULONGEST offset, LONGEST len)
dc146f7c
VP
1190{
1191 static char *result = 0;
1192 static unsigned int result_length = 0;
1193
d08aafef
PA
1194 if (writebuf != NULL)
1195 return -2;
1196
1197 if (!target_running () || annex[0] != '\0')
1198 return -1;
dc146f7c
VP
1199
1200 if (offset == 0)
1201 {
1202 struct buffer buffer;
1203 /* When asked for data at offset 0, generate everything and store into
1204 'result'. Successive reads will be served off 'result'. */
1205 if (result)
1206 free (result);
1207
1208 buffer_init (&buffer);
1209
d08aafef 1210 handle_qxfer_threads_proper (&buffer);
dc146f7c
VP
1211
1212 result = buffer_finish (&buffer);
1213 result_length = strlen (result);
1214 buffer_free (&buffer);
1215 }
1216
1217 if (offset >= result_length)
1218 {
1219 /* We're out of data. */
1220 free (result);
1221 result = NULL;
1222 result_length = 0;
1223 return 0;
1224 }
1225
d08aafef
PA
1226 if (len > result_length - offset)
1227 len = result_length - offset;
1228
1229 memcpy (readbuf, result + offset, len);
1230
1231 return len;
1232}
1233
b3b9301e
PA
1234/* Handle qXfer:traceframe-info:read. */
1235
1236static int
1237handle_qxfer_traceframe_info (const char *annex,
1238 gdb_byte *readbuf, const gdb_byte *writebuf,
1239 ULONGEST offset, LONGEST len)
1240{
1241 static char *result = 0;
1242 static unsigned int result_length = 0;
1243
1244 if (writebuf != NULL)
1245 return -2;
1246
1247 if (!target_running () || annex[0] != '\0' || current_traceframe == -1)
1248 return -1;
1249
1250 if (offset == 0)
1251 {
1252 struct buffer buffer;
1253
1254 /* When asked for data at offset 0, generate everything and
1255 store into 'result'. Successive reads will be served off
1256 'result'. */
1257 free (result);
1258
1259 buffer_init (&buffer);
1260
1261 traceframe_read_info (current_traceframe, &buffer);
1262
1263 result = buffer_finish (&buffer);
1264 result_length = strlen (result);
1265 buffer_free (&buffer);
1266 }
1267
1268 if (offset >= result_length)
1269 {
1270 /* We're out of data. */
1271 free (result);
1272 result = NULL;
1273 result_length = 0;
1274 return 0;
1275 }
1276
1277 if (len > result_length - offset)
1278 len = result_length - offset;
1279
1280 memcpy (readbuf, result + offset, len);
1281 return len;
1282}
1283
78d85199
YQ
1284/* Handle qXfer:fdpic:read. */
1285
1286static int
1287handle_qxfer_fdpic (const char *annex, gdb_byte *readbuf,
1288 const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
1289{
1290 if (the_target->read_loadmap == NULL)
1291 return -2;
1292
1293 if (!target_running ())
1294 return -1;
1295
1296 return (*the_target->read_loadmap) (annex, offset, readbuf, len);
1297}
1298
d08aafef
PA
1299static const struct qxfer qxfer_packets[] =
1300 {
1301 { "auxv", handle_qxfer_auxv },
78d85199 1302 { "fdpic", handle_qxfer_fdpic},
d08aafef
PA
1303 { "features", handle_qxfer_features },
1304 { "libraries", handle_qxfer_libraries },
2268b414 1305 { "libraries-svr4", handle_qxfer_libraries_svr4 },
d08aafef
PA
1306 { "osdata", handle_qxfer_osdata },
1307 { "siginfo", handle_qxfer_siginfo },
1308 { "spu", handle_qxfer_spu },
1309 { "statictrace", handle_qxfer_statictrace },
1310 { "threads", handle_qxfer_threads },
b3b9301e 1311 { "traceframe-info", handle_qxfer_traceframe_info },
d08aafef
PA
1312 };
1313
1314static int
1315handle_qxfer (char *own_buf, int packet_len, int *new_packet_len_p)
1316{
1317 int i;
1318 char *object;
1319 char *rw;
1320 char *annex;
1321 char *offset;
1322
1323 if (strncmp (own_buf, "qXfer:", 6) != 0)
1324 return 0;
1325
1326 /* Grab the object, r/w and annex. */
1327 if (decode_xfer (own_buf + 6, &object, &rw, &annex, &offset) < 0)
1328 {
1329 write_enn (own_buf);
1330 return 1;
1331 }
1332
1333 for (i = 0;
1334 i < sizeof (qxfer_packets) / sizeof (qxfer_packets[0]);
1335 i++)
1336 {
1337 const struct qxfer *q = &qxfer_packets[i];
1338
1339 if (strcmp (object, q->object) == 0)
1340 {
1341 if (strcmp (rw, "read") == 0)
1342 {
1343 unsigned char *data;
1344 int n;
1345 CORE_ADDR ofs;
1346 unsigned int len;
1347
1348 /* Grab the offset and length. */
1349 if (decode_xfer_read (offset, &ofs, &len) < 0)
1350 {
1351 write_enn (own_buf);
1352 return 1;
1353 }
1354
1355 /* Read one extra byte, as an indicator of whether there is
1356 more. */
1357 if (len > PBUFSIZ - 2)
1358 len = PBUFSIZ - 2;
1359 data = malloc (len + 1);
1360 if (data == NULL)
1361 {
1362 write_enn (own_buf);
1363 return 1;
1364 }
1365 n = (*q->xfer) (annex, data, NULL, ofs, len + 1);
1366 if (n == -2)
1367 {
1368 free (data);
1369 return 0;
1370 }
1371 else if (n < 0)
1372 write_enn (own_buf);
1373 else if (n > len)
1374 *new_packet_len_p = write_qxfer_response (own_buf, data, len, 1);
1375 else
1376 *new_packet_len_p = write_qxfer_response (own_buf, data, n, 0);
1377
1378 free (data);
1379 return 1;
1380 }
1381 else if (strcmp (rw, "write") == 0)
1382 {
1383 int n;
1384 unsigned int len;
1385 CORE_ADDR ofs;
1386 unsigned char *data;
1387
1388 strcpy (own_buf, "E00");
1389 data = malloc (packet_len - (offset - own_buf));
1390 if (data == NULL)
1391 {
1392 write_enn (own_buf);
1393 return 1;
1394 }
1395 if (decode_xfer_write (offset, packet_len - (offset - own_buf),
1396 &ofs, &len, data) < 0)
1397 {
1398 free (data);
1399 write_enn (own_buf);
1400 return 1;
1401 }
1402
1403 n = (*q->xfer) (annex, NULL, data, ofs, len);
1404 if (n == -2)
1405 {
1406 free (data);
1407 return 0;
1408 }
1409 else if (n < 0)
1410 write_enn (own_buf);
1411 else
1412 sprintf (own_buf, "%x", n);
dc146f7c 1413
d08aafef
PA
1414 free (data);
1415 return 1;
1416 }
dc146f7c 1417
d08aafef
PA
1418 return 0;
1419 }
1420 }
dc146f7c 1421
d08aafef 1422 return 0;
dc146f7c
VP
1423}
1424
30ba68cb
MS
1425/* Table used by the crc32 function to calcuate the checksum. */
1426
1427static unsigned int crc32_table[256] =
1428{0, 0};
1429
1430/* Compute 32 bit CRC from inferior memory.
1431
1432 On success, return 32 bit CRC.
1433 On failure, return (unsigned long long) -1. */
1434
1435static unsigned long long
1436crc32 (CORE_ADDR base, int len, unsigned int crc)
1437{
1438 if (!crc32_table[1])
1439 {
1440 /* Initialize the CRC table and the decoding table. */
1441 int i, j;
1442 unsigned int c;
1443
1444 for (i = 0; i < 256; i++)
1445 {
1446 for (c = i << 24, j = 8; j > 0; --j)
1447 c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1);
1448 crc32_table[i] = c;
1449 }
1450 }
1451
1452 while (len--)
1453 {
1454 unsigned char byte = 0;
1455
1456 /* Return failure if memory read fails. */
1457 if (read_inferior_memory (base, &byte, 1) != 0)
1458 return (unsigned long long) -1;
1459
1460 crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ byte) & 255];
1461 base++;
1462 }
1463 return (unsigned long long) crc;
1464}
1465
ce3a066d 1466/* Handle all of the extended 'q' packets. */
d08aafef 1467
ce3a066d 1468void
0e7f50da 1469handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
ce3a066d 1470{
0d62e5e8
DJ
1471 static struct inferior_list_entry *thread_ptr;
1472
bb63802a 1473 /* Reply the current thread id. */
db42f210 1474 if (strcmp ("qC", own_buf) == 0 && !disable_packet_qC)
bb63802a 1475 {
95954743 1476 ptid_t gdb_id;
2d717e4f 1477 require_running (own_buf);
bd99dc85 1478
95954743
PA
1479 if (!ptid_equal (general_thread, null_ptid)
1480 && !ptid_equal (general_thread, minus_one_ptid))
bd99dc85
PA
1481 gdb_id = general_thread;
1482 else
1483 {
1484 thread_ptr = all_threads.head;
1485 gdb_id = thread_to_gdb_id ((struct thread_info *)thread_ptr);
1486 }
1487
95954743
PA
1488 sprintf (own_buf, "QC");
1489 own_buf += 2;
4b812f4e 1490 write_ptid (own_buf, gdb_id);
bb63802a
UW
1491 return;
1492 }
1493
ce3a066d
DJ
1494 if (strcmp ("qSymbol::", own_buf) == 0)
1495 {
d3bbe7a0
PA
1496 /* GDB is suggesting new symbols have been loaded. This may
1497 mean a new shared library has been detected as loaded, so
1498 take the opportunity to check if breakpoints we think are
1499 inserted, still are. Note that it isn't guaranteed that
1500 we'll see this when a shared library is loaded, and nor will
1501 we see this for unloads (although breakpoints in unloaded
1502 libraries shouldn't trigger), as GDB may not find symbols for
1503 the library at all. We also re-validate breakpoints when we
1504 see a second GDB breakpoint for the same address, and or when
1505 we access breakpoint shadows. */
1506 validate_breakpoints ();
1507
fa593d66
PA
1508 if (target_supports_tracepoints ())
1509 tracepoint_look_up_symbols ();
1510
2d717e4f 1511 if (target_running () && the_target->look_up_symbols != NULL)
2f2893d9
DJ
1512 (*the_target->look_up_symbols) ();
1513
ce3a066d
DJ
1514 strcpy (own_buf, "OK");
1515 return;
1516 }
1517
db42f210 1518 if (!disable_packet_qfThreadInfo)
0d62e5e8 1519 {
db42f210 1520 if (strcmp ("qfThreadInfo", own_buf) == 0)
0d62e5e8 1521 {
95954743
PA
1522 ptid_t gdb_id;
1523
db42f210
PA
1524 require_running (own_buf);
1525 thread_ptr = all_threads.head;
95954743
PA
1526
1527 *own_buf++ = 'm';
1528 gdb_id = thread_to_gdb_id ((struct thread_info *)thread_ptr);
1529 write_ptid (own_buf, gdb_id);
0d62e5e8
DJ
1530 thread_ptr = thread_ptr->next;
1531 return;
1532 }
db42f210
PA
1533
1534 if (strcmp ("qsThreadInfo", own_buf) == 0)
0d62e5e8 1535 {
95954743
PA
1536 ptid_t gdb_id;
1537
db42f210
PA
1538 require_running (own_buf);
1539 if (thread_ptr != NULL)
1540 {
95954743
PA
1541 *own_buf++ = 'm';
1542 gdb_id = thread_to_gdb_id ((struct thread_info *)thread_ptr);
1543 write_ptid (own_buf, gdb_id);
db42f210
PA
1544 thread_ptr = thread_ptr->next;
1545 return;
1546 }
1547 else
1548 {
1549 sprintf (own_buf, "l");
1550 return;
1551 }
0d62e5e8
DJ
1552 }
1553 }
aa691b87 1554
52fb6437
NS
1555 if (the_target->read_offsets != NULL
1556 && strcmp ("qOffsets", own_buf) == 0)
1557 {
1558 CORE_ADDR text, data;
2d717e4f
DJ
1559
1560 require_running (own_buf);
52fb6437
NS
1561 if (the_target->read_offsets (&text, &data))
1562 sprintf (own_buf, "Text=%lX;Data=%lX;Bss=%lX",
1563 (long)text, (long)data, (long)data);
1564 else
1565 write_enn (own_buf);
1b3f6016 1566
52fb6437
NS
1567 return;
1568 }
1569
be2a5f71
DJ
1570 /* Protocol features query. */
1571 if (strncmp ("qSupported", own_buf, 10) == 0
1572 && (own_buf[10] == ':' || own_buf[10] == '\0'))
1573 {
95954743 1574 char *p = &own_buf[10];
fa593d66 1575 int gdb_supports_qRelocInsn = 0;
95954743 1576
1570b33e
L
1577 /* Start processing qSupported packet. */
1578 target_process_qsupported (NULL);
1579
95954743
PA
1580 /* Process each feature being provided by GDB. The first
1581 feature will follow a ':', and latter features will follow
1582 ';'. */
1583 if (*p == ':')
d149dd1d
PA
1584 {
1585 char **qsupported = NULL;
1586 int count = 0;
1587 int i;
1588
1589 /* Two passes, to avoid nested strtok calls in
1590 target_process_qsupported. */
1591 for (p = strtok (p + 1, ";");
1592 p != NULL;
1593 p = strtok (NULL, ";"))
1594 {
1595 count++;
1596 qsupported = xrealloc (qsupported, count * sizeof (char *));
1597 qsupported[count - 1] = xstrdup (p);
1598 }
1599
1600 for (i = 0; i < count; i++)
1601 {
1602 p = qsupported[i];
1603 if (strcmp (p, "multiprocess+") == 0)
1604 {
1605 /* GDB supports and wants multi-process support if
1606 possible. */
1607 if (target_supports_multi_process ())
1608 multi_process = 1;
1609 }
fa593d66
PA
1610 else if (strcmp (p, "qRelocInsn+") == 0)
1611 {
1612 /* GDB supports relocate instruction requests. */
1613 gdb_supports_qRelocInsn = 1;
1614 }
d149dd1d
PA
1615 else
1616 target_process_qsupported (p);
1617
1618 free (p);
1619 }
1620
1621 free (qsupported);
1622 }
95954743 1623
9b224c5e
PA
1624 sprintf (own_buf,
1625 "PacketSize=%x;QPassSignals+;QProgramSignals+",
1626 PBUFSIZ - 1);
0876f84a 1627
2268b414
JK
1628 if (the_target->qxfer_libraries_svr4 != NULL)
1629 strcat (own_buf, ";qXfer:libraries-svr4:read+");
1630 else
1631 {
1632 /* We do not have any hook to indicate whether the non-SVR4 target
1633 backend supports qXfer:libraries:read, so always report it. */
1634 strcat (own_buf, ";qXfer:libraries:read+");
1635 }
255e7678 1636
0876f84a 1637 if (the_target->read_auxv != NULL)
9f2e1e63 1638 strcat (own_buf, ";qXfer:auxv:read+");
2d717e4f 1639
0e7f50da
UW
1640 if (the_target->qxfer_spu != NULL)
1641 strcat (own_buf, ";qXfer:spu:read+;qXfer:spu:write+");
0876f84a 1642
4aa995e1
PA
1643 if (the_target->qxfer_siginfo != NULL)
1644 strcat (own_buf, ";qXfer:siginfo:read+;qXfer:siginfo:write+");
1645
78d85199
YQ
1646 if (the_target->read_loadmap != NULL)
1647 strcat (own_buf, ";qXfer:fdpic:read+");
1648
221c031f
UW
1649 /* We always report qXfer:features:read, as targets may
1650 install XML files on a subsequent call to arch_setup.
1651 If we reported to GDB on startup that we don't support
1652 qXfer:feature:read at all, we will never be re-queried. */
1653 strcat (own_buf, ";qXfer:features:read+");
23181151 1654
a6f3e723
SL
1655 if (transport_is_reliable)
1656 strcat (own_buf, ";QStartNoAckMode+");
07e059b5
VP
1657
1658 if (the_target->qxfer_osdata != NULL)
1b3f6016 1659 strcat (own_buf, ";qXfer:osdata:read+");
07e059b5 1660
cf8fd78b
PA
1661 if (target_supports_multi_process ())
1662 strcat (own_buf, ";multiprocess+");
95954743 1663
bd99dc85
PA
1664 if (target_supports_non_stop ())
1665 strcat (own_buf, ";QNonStop+");
1666
03583c20
UW
1667 if (target_supports_disable_randomization ())
1668 strcat (own_buf, ";QDisableRandomization+");
1669
dc146f7c
VP
1670 strcat (own_buf, ";qXfer:threads:read+");
1671
219f2f23
PA
1672 if (target_supports_tracepoints ())
1673 {
1674 strcat (own_buf, ";ConditionalTracepoints+");
1675 strcat (own_buf, ";TraceStateVariables+");
1676 strcat (own_buf, ";TracepointSource+");
8336d594 1677 strcat (own_buf, ";DisconnectedTracing+");
fa593d66
PA
1678 if (gdb_supports_qRelocInsn && target_supports_fast_tracepoints ())
1679 strcat (own_buf, ";FastTracepoints+");
0fb4aa4b 1680 strcat (own_buf, ";StaticTracepoints+");
1e4d1764 1681 strcat (own_buf, ";InstallInTrace+");
0fb4aa4b 1682 strcat (own_buf, ";qXfer:statictrace:read+");
b3b9301e 1683 strcat (own_buf, ";qXfer:traceframe-info:read+");
d248b706 1684 strcat (own_buf, ";EnableDisableTracepoints+");
3065dfb6 1685 strcat (own_buf, ";tracenz+");
219f2f23
PA
1686 }
1687
9f3a5c85
LM
1688 /* Support target-side breakpoint conditions. */
1689 strcat (own_buf, ";ConditionalBreakpoints+");
1690
d1feda86
YQ
1691 if (target_supports_agent ())
1692 strcat (own_buf, ";QAgent+");
1693
be2a5f71
DJ
1694 return;
1695 }
1696
dae5f5cf
DJ
1697 /* Thread-local storage support. */
1698 if (the_target->get_tls_address != NULL
1699 && strncmp ("qGetTLSAddr:", own_buf, 12) == 0)
1700 {
1701 char *p = own_buf + 12;
5b1c542e 1702 CORE_ADDR parts[2], address = 0;
dae5f5cf 1703 int i, err;
95954743 1704 ptid_t ptid = null_ptid;
dae5f5cf 1705
2d717e4f
DJ
1706 require_running (own_buf);
1707
dae5f5cf
DJ
1708 for (i = 0; i < 3; i++)
1709 {
1710 char *p2;
1711 int len;
1712
1713 if (p == NULL)
1714 break;
1715
1716 p2 = strchr (p, ',');
1717 if (p2)
1718 {
1719 len = p2 - p;
1720 p2++;
1721 }
1722 else
1723 {
1724 len = strlen (p);
1725 p2 = NULL;
1726 }
1727
5b1c542e 1728 if (i == 0)
95954743 1729 ptid = read_ptid (p, NULL);
5b1c542e
PA
1730 else
1731 decode_address (&parts[i - 1], p, len);
dae5f5cf
DJ
1732 p = p2;
1733 }
1734
1735 if (p != NULL || i < 3)
1736 err = 1;
1737 else
1738 {
e09875d4 1739 struct thread_info *thread = find_thread_ptid (ptid);
dae5f5cf
DJ
1740
1741 if (thread == NULL)
1742 err = 2;
1743 else
5b1c542e 1744 err = the_target->get_tls_address (thread, parts[0], parts[1],
dae5f5cf
DJ
1745 &address);
1746 }
1747
1748 if (err == 0)
1749 {
c6f46ca0 1750 strcpy (own_buf, paddress(address));
dae5f5cf
DJ
1751 return;
1752 }
1753 else if (err > 0)
1754 {
1755 write_enn (own_buf);
1756 return;
1757 }
1758
1759 /* Otherwise, pretend we do not understand this packet. */
1760 }
1761
711e434b
PM
1762 /* Windows OS Thread Information Block address support. */
1763 if (the_target->get_tib_address != NULL
1764 && strncmp ("qGetTIBAddr:", own_buf, 12) == 0)
1765 {
1766 char *annex;
1767 int n;
1768 CORE_ADDR tlb;
1769 ptid_t ptid = read_ptid (own_buf + 12, &annex);
1770
1771 n = (*the_target->get_tib_address) (ptid, &tlb);
1772 if (n == 1)
1773 {
c6f46ca0 1774 strcpy (own_buf, paddress(tlb));
711e434b
PM
1775 return;
1776 }
1777 else if (n == 0)
1778 {
1779 write_enn (own_buf);
1780 return;
1781 }
1782 return;
1783 }
1784
c74d0ad8
DJ
1785 /* Handle "monitor" commands. */
1786 if (strncmp ("qRcmd,", own_buf, 6) == 0)
1787 {
aef93bd7 1788 char *mon = malloc (PBUFSIZ);
c74d0ad8
DJ
1789 int len = strlen (own_buf + 6);
1790
aef93bd7
DE
1791 if (mon == NULL)
1792 {
1793 write_enn (own_buf);
1794 return;
1795 }
1796
d41b6bb4 1797 if ((len % 2) != 0 || unhexify (mon, own_buf + 6, len / 2) != len / 2)
c74d0ad8
DJ
1798 {
1799 write_enn (own_buf);
1800 free (mon);
1801 return;
1802 }
1803 mon[len / 2] = '\0';
1804
1805 write_ok (own_buf);
1806
cdbfd419
PP
1807 if (the_target->handle_monitor_command == NULL
1808 || (*the_target->handle_monitor_command) (mon) == 0)
1809 /* Default processing. */
d73f2619 1810 handle_monitor_command (mon, own_buf);
c74d0ad8
DJ
1811
1812 free (mon);
1813 return;
1814 }
1815
493e2a69
MS
1816 if (strncmp ("qSearch:memory:", own_buf,
1817 sizeof ("qSearch:memory:") - 1) == 0)
08388c79
DE
1818 {
1819 require_running (own_buf);
1820 handle_search_memory (own_buf, packet_len);
1821 return;
1822 }
1823
95954743
PA
1824 if (strcmp (own_buf, "qAttached") == 0
1825 || strncmp (own_buf, "qAttached:", sizeof ("qAttached:") - 1) == 0)
0b16c5cf 1826 {
95954743
PA
1827 struct process_info *process;
1828
1829 if (own_buf[sizeof ("qAttached") - 1])
1830 {
1831 int pid = strtoul (own_buf + sizeof ("qAttached:") - 1, NULL, 16);
1832 process = (struct process_info *)
1833 find_inferior_id (&all_processes, pid_to_ptid (pid));
1834 }
1835 else
1836 {
1837 require_running (own_buf);
1838 process = current_process ();
1839 }
1840
1841 if (process == NULL)
1842 {
1843 write_enn (own_buf);
1844 return;
1845 }
1846
1847 strcpy (own_buf, process->attached ? "1" : "0");
0b16c5cf
PA
1848 return;
1849 }
1850
30ba68cb
MS
1851 if (strncmp ("qCRC:", own_buf, 5) == 0)
1852 {
1853 /* CRC check (compare-section). */
1854 char *comma;
1855 CORE_ADDR base;
1856 int len;
1857 unsigned long long crc;
1858
1859 require_running (own_buf);
2280c721 1860 base = strtoul (own_buf + 5, &comma, 16);
30ba68cb
MS
1861 if (*comma++ != ',')
1862 {
1863 write_enn (own_buf);
1864 return;
1865 }
1866 len = strtoul (comma, NULL, 16);
1867 crc = crc32 (base, len, 0xffffffff);
1868 /* Check for memory failure. */
1869 if (crc == (unsigned long long) -1)
1870 {
1871 write_enn (own_buf);
1872 return;
1873 }
1874 sprintf (own_buf, "C%lx", (unsigned long) crc);
1875 return;
1876 }
1877
d08aafef
PA
1878 if (handle_qxfer (own_buf, packet_len, new_packet_len_p))
1879 return;
1880
219f2f23
PA
1881 if (target_supports_tracepoints () && handle_tracepoint_query (own_buf))
1882 return;
1883
ce3a066d
DJ
1884 /* Otherwise we didn't know what packet it was. Say we didn't
1885 understand it. */
1886 own_buf[0] = 0;
1887}
1888
ce1a5b52
PA
1889static void gdb_wants_all_threads_stopped (void);
1890
64386c31
DJ
1891/* Parse vCont packets. */
1892void
5b1c542e 1893handle_v_cont (char *own_buf)
64386c31
DJ
1894{
1895 char *p, *q;
1896 int n = 0, i = 0;
2bd7c093 1897 struct thread_resume *resume_info;
95954743 1898 struct thread_resume default_action = {{0}};
64386c31
DJ
1899
1900 /* Count the number of semicolons in the packet. There should be one
1901 for every action. */
1902 p = &own_buf[5];
1903 while (p)
1904 {
1905 n++;
1906 p++;
1907 p = strchr (p, ';');
1908 }
2bd7c093
PA
1909
1910 resume_info = malloc (n * sizeof (resume_info[0]));
aef93bd7
DE
1911 if (resume_info == NULL)
1912 goto err;
64386c31 1913
64386c31 1914 p = &own_buf[5];
64386c31
DJ
1915 while (*p)
1916 {
1917 p++;
1918
64386c31 1919 if (p[0] == 's' || p[0] == 'S')
bd99dc85 1920 resume_info[i].kind = resume_step;
64386c31 1921 else if (p[0] == 'c' || p[0] == 'C')
bd99dc85
PA
1922 resume_info[i].kind = resume_continue;
1923 else if (p[0] == 't')
1924 resume_info[i].kind = resume_stop;
64386c31
DJ
1925 else
1926 goto err;
1927
1928 if (p[0] == 'S' || p[0] == 'C')
1929 {
1930 int sig;
1931 sig = strtol (p + 1, &q, 16);
1932 if (p == q)
1933 goto err;
1934 p = q;
1935
2ea28649 1936 if (!gdb_signal_to_host_p (sig))
64386c31 1937 goto err;
2ea28649 1938 resume_info[i].sig = gdb_signal_to_host (sig);
64386c31
DJ
1939 }
1940 else
1941 {
1942 resume_info[i].sig = 0;
1943 p = p + 1;
1944 }
1945
1946 if (p[0] == 0)
1947 {
95954743 1948 resume_info[i].thread = minus_one_ptid;
64386c31
DJ
1949 default_action = resume_info[i];
1950
1951 /* Note: we don't increment i here, we'll overwrite this entry
1952 the next time through. */
1953 }
1954 else if (p[0] == ':')
1955 {
95954743 1956 ptid_t ptid = read_ptid (p + 1, &q);
a06660f7 1957
64386c31
DJ
1958 if (p == q)
1959 goto err;
1960 p = q;
1961 if (p[0] != ';' && p[0] != 0)
1962 goto err;
1963
95954743 1964 resume_info[i].thread = ptid;
a06660f7 1965
64386c31
DJ
1966 i++;
1967 }
1968 }
1969
2bd7c093
PA
1970 if (i < n)
1971 resume_info[i] = default_action;
64386c31 1972
122f36ef
PA
1973 /* `cont_thread' is still used in occasional places in the backend,
1974 to implement single-thread scheduler-locking. Doesn't make sense
0c9070b3
YQ
1975 to set it if we see a stop request, or a wildcard action (one
1976 with '-1' (all threads), or 'pPID.-1' (all threads of PID)). */
bd99dc85 1977 if (n == 1
122f36ef
PA
1978 && !(ptid_equal (resume_info[0].thread, minus_one_ptid)
1979 || ptid_get_lwp (resume_info[0].thread) == -1)
bd99dc85 1980 && resume_info[0].kind != resume_stop)
64386c31
DJ
1981 cont_thread = resume_info[0].thread;
1982 else
95954743 1983 cont_thread = minus_one_ptid;
dc3f8883 1984 set_desired_inferior (0);
64386c31 1985
bd99dc85
PA
1986 if (!non_stop)
1987 enable_async_io ();
1988
2bd7c093 1989 (*the_target->resume) (resume_info, n);
64386c31
DJ
1990
1991 free (resume_info);
1992
bd99dc85
PA
1993 if (non_stop)
1994 write_ok (own_buf);
1995 else
1996 {
95954743 1997 last_ptid = mywait (minus_one_ptid, &last_status, 0, 1);
ce1a5b52 1998
d20a8ad9
PA
1999 if (last_status.kind != TARGET_WAITKIND_EXITED
2000 && last_status.kind != TARGET_WAITKIND_SIGNALLED)
2001 current_inferior->last_status = last_status;
2002
ce1a5b52
PA
2003 /* From the client's perspective, all-stop mode always stops all
2004 threads implicitly (and the target backend has already done
2005 so by now). Tag all threads as "want-stopped", so we don't
2006 resume them implicitly without the client telling us to. */
2007 gdb_wants_all_threads_stopped ();
bd99dc85
PA
2008 prepare_resume_reply (own_buf, last_ptid, &last_status);
2009 disable_async_io ();
6bd31874
JB
2010
2011 if (last_status.kind == TARGET_WAITKIND_EXITED
2012 || last_status.kind == TARGET_WAITKIND_SIGNALLED)
2013 mourn_inferior (find_process_pid (ptid_get_pid (last_ptid)));
bd99dc85 2014 }
64386c31
DJ
2015 return;
2016
2017err:
255e7678 2018 write_enn (own_buf);
64386c31
DJ
2019 free (resume_info);
2020 return;
2021}
2022
2d717e4f
DJ
2023/* Attach to a new program. Return 1 if successful, 0 if failure. */
2024int
5b1c542e 2025handle_v_attach (char *own_buf)
2d717e4f
DJ
2026{
2027 int pid;
2028
2029 pid = strtol (own_buf + 8, NULL, 16);
5b1c542e 2030 if (pid != 0 && attach_inferior (pid) == 0)
2d717e4f 2031 {
aeba519e
PA
2032 /* Don't report shared library events after attaching, even if
2033 some libraries are preloaded. GDB will always poll the
2034 library list. Avoids the "stopped by shared library event"
2035 notice on the GDB side. */
2036 dlls_changed = 0;
bd99dc85
PA
2037
2038 if (non_stop)
2039 {
2040 /* In non-stop, we don't send a resume reply. Stop events
2041 will follow up using the normal notification
2042 mechanism. */
2043 write_ok (own_buf);
2044 }
2045 else
2046 prepare_resume_reply (own_buf, last_ptid, &last_status);
2047
2d717e4f
DJ
2048 return 1;
2049 }
2050 else
2051 {
2052 write_enn (own_buf);
2053 return 0;
2054 }
2055}
2056
2057/* Run a new program. Return 1 if successful, 0 if failure. */
2058static int
5b1c542e 2059handle_v_run (char *own_buf)
2d717e4f 2060{
aef93bd7 2061 char *p, *next_p, **new_argv;
2d717e4f
DJ
2062 int i, new_argc;
2063
2064 new_argc = 0;
2065 for (p = own_buf + strlen ("vRun;"); p && *p; p = strchr (p, ';'))
2066 {
2067 p++;
2068 new_argc++;
2069 }
2070
aef93bd7
DE
2071 new_argv = calloc (new_argc + 2, sizeof (char *));
2072 if (new_argv == NULL)
2073 {
2074 write_enn (own_buf);
2075 return 0;
2076 }
2077
2d717e4f
DJ
2078 i = 0;
2079 for (p = own_buf + strlen ("vRun;"); *p; p = next_p)
2080 {
2081 next_p = strchr (p, ';');
2082 if (next_p == NULL)
2083 next_p = p + strlen (p);
2084
2085 if (i == 0 && p == next_p)
2086 new_argv[i] = NULL;
2087 else
2088 {
aef93bd7 2089 /* FIXME: Fail request if out of memory instead of dying. */
bca929d3 2090 new_argv[i] = xmalloc (1 + (next_p - p) / 2);
2d717e4f
DJ
2091 unhexify (new_argv[i], p, (next_p - p) / 2);
2092 new_argv[i][(next_p - p) / 2] = '\0';
2093 }
2094
2095 if (*next_p)
2096 next_p++;
2097 i++;
2098 }
2099 new_argv[i] = NULL;
2100
2101 if (new_argv[0] == NULL)
2102 {
f142445f
DJ
2103 /* GDB didn't specify a program to run. Use the program from the
2104 last run with the new argument list. */
9b710a42 2105
2d717e4f
DJ
2106 if (program_argv == NULL)
2107 {
2108 write_enn (own_buf);
b2c04452 2109 freeargv (new_argv);
2d717e4f
DJ
2110 return 0;
2111 }
2112
aef93bd7
DE
2113 new_argv[0] = strdup (program_argv[0]);
2114 if (new_argv[0] == NULL)
2115 {
aef93bd7 2116 write_enn (own_buf);
b2c04452 2117 freeargv (new_argv);
aef93bd7 2118 return 0;
1b3f6016 2119 }
2d717e4f 2120 }
f142445f 2121
aef93bd7
DE
2122 /* Free the old argv and install the new one. */
2123 freeargv (program_argv);
f142445f 2124 program_argv = new_argv;
2d717e4f 2125
5b1c542e
PA
2126 start_inferior (program_argv);
2127 if (last_status.kind == TARGET_WAITKIND_STOPPED)
2d717e4f 2128 {
5b1c542e 2129 prepare_resume_reply (own_buf, last_ptid, &last_status);
bd99dc85
PA
2130
2131 /* In non-stop, sending a resume reply doesn't set the general
2132 thread, but GDB assumes a vRun sets it (this is so GDB can
2133 query which is the main thread of the new inferior. */
2134 if (non_stop)
2135 general_thread = last_ptid;
2136
2d717e4f
DJ
2137 return 1;
2138 }
2139 else
2140 {
2141 write_enn (own_buf);
2142 return 0;
2143 }
2144}
2145
95954743
PA
2146/* Kill process. Return 1 if successful, 0 if failure. */
2147int
2148handle_v_kill (char *own_buf)
2149{
2150 int pid;
2151 char *p = &own_buf[6];
0f54c268
PM
2152 if (multi_process)
2153 pid = strtol (p, NULL, 16);
2154 else
2155 pid = signal_pid;
95954743
PA
2156 if (pid != 0 && kill_inferior (pid) == 0)
2157 {
2158 last_status.kind = TARGET_WAITKIND_SIGNALLED;
a493e3e2 2159 last_status.value.sig = GDB_SIGNAL_KILL;
95954743
PA
2160 last_ptid = pid_to_ptid (pid);
2161 discard_queued_stop_replies (pid);
2162 write_ok (own_buf);
2163 return 1;
2164 }
2165 else
2166 {
2167 write_enn (own_buf);
2168 return 0;
2169 }
2170}
2171
bd99dc85
PA
2172/* Handle a 'vStopped' packet. */
2173static void
2174handle_v_stopped (char *own_buf)
2175{
2176 /* If we're waiting for GDB to acknowledge a pending stop reply,
2177 consider that done. */
2178 if (notif_queue)
2179 {
2180 struct vstop_notif *head;
2181
2182 if (remote_debug)
95954743
PA
2183 fprintf (stderr, "vStopped: acking %s\n",
2184 target_pid_to_str (notif_queue->ptid));
bd99dc85
PA
2185
2186 head = notif_queue;
2187 notif_queue = notif_queue->next;
2188 free (head);
2189 }
2190
2191 /* Push another stop reply, or if there are no more left, an OK. */
2192 send_next_stop_reply (own_buf);
2193}
2194
64386c31
DJ
2195/* Handle all of the extended 'v' packets. */
2196void
5b1c542e 2197handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
64386c31 2198{
db42f210 2199 if (!disable_packet_vCont)
64386c31 2200 {
db42f210
PA
2201 if (strncmp (own_buf, "vCont;", 6) == 0)
2202 {
2203 require_running (own_buf);
5b1c542e 2204 handle_v_cont (own_buf);
db42f210
PA
2205 return;
2206 }
64386c31 2207
db42f210
PA
2208 if (strncmp (own_buf, "vCont?", 6) == 0)
2209 {
bd99dc85 2210 strcpy (own_buf, "vCont;c;C;s;S;t");
db42f210
PA
2211 return;
2212 }
64386c31
DJ
2213 }
2214
a6b151f1
DJ
2215 if (strncmp (own_buf, "vFile:", 6) == 0
2216 && handle_vFile (own_buf, packet_len, new_packet_len))
2217 return;
2218
2d717e4f
DJ
2219 if (strncmp (own_buf, "vAttach;", 8) == 0)
2220 {
901f9912 2221 if ((!extended_protocol || !multi_process) && target_running ())
2d717e4f 2222 {
fd96d250
PA
2223 fprintf (stderr, "Already debugging a process\n");
2224 write_enn (own_buf);
2225 return;
2d717e4f 2226 }
5b1c542e 2227 handle_v_attach (own_buf);
2d717e4f
DJ
2228 return;
2229 }
2230
2231 if (strncmp (own_buf, "vRun;", 5) == 0)
2232 {
901f9912 2233 if ((!extended_protocol || !multi_process) && target_running ())
2d717e4f 2234 {
fd96d250
PA
2235 fprintf (stderr, "Already debugging a process\n");
2236 write_enn (own_buf);
2237 return;
2d717e4f 2238 }
5b1c542e 2239 handle_v_run (own_buf);
2d717e4f
DJ
2240 return;
2241 }
2242
95954743
PA
2243 if (strncmp (own_buf, "vKill;", 6) == 0)
2244 {
2245 if (!target_running ())
2246 {
2247 fprintf (stderr, "No process to kill\n");
2248 write_enn (own_buf);
2249 return;
2250 }
2251 handle_v_kill (own_buf);
2252 return;
2253 }
2254
bd99dc85
PA
2255 if (strncmp (own_buf, "vStopped", 8) == 0)
2256 {
2257 handle_v_stopped (own_buf);
2258 return;
2259 }
2260
64386c31
DJ
2261 /* Otherwise we didn't know what packet it was. Say we didn't
2262 understand it. */
2263 own_buf[0] = 0;
2264 return;
2265}
2266
bd99dc85
PA
2267/* Resume inferior and wait for another event. In non-stop mode,
2268 don't really wait here, but return immediatelly to the event
2269 loop. */
1fd7cdc2 2270static void
5b1c542e 2271myresume (char *own_buf, int step, int sig)
64386c31
DJ
2272{
2273 struct thread_resume resume_info[2];
2274 int n = 0;
2bd7c093 2275 int valid_cont_thread;
a20d5e98
DJ
2276
2277 set_desired_inferior (0);
64386c31 2278
95954743
PA
2279 valid_cont_thread = (!ptid_equal (cont_thread, null_ptid)
2280 && !ptid_equal (cont_thread, minus_one_ptid));
2bd7c093
PA
2281
2282 if (step || sig || valid_cont_thread)
64386c31
DJ
2283 {
2284 resume_info[0].thread
2285 = ((struct inferior_list_entry *) current_inferior)->id;
bd99dc85
PA
2286 if (step)
2287 resume_info[0].kind = resume_step;
2288 else
2289 resume_info[0].kind = resume_continue;
64386c31 2290 resume_info[0].sig = sig;
64386c31
DJ
2291 n++;
2292 }
2bd7c093
PA
2293
2294 if (!valid_cont_thread)
2295 {
95954743 2296 resume_info[n].thread = minus_one_ptid;
bd99dc85 2297 resume_info[n].kind = resume_continue;
2bd7c093
PA
2298 resume_info[n].sig = 0;
2299 n++;
2300 }
64386c31 2301
bd99dc85
PA
2302 if (!non_stop)
2303 enable_async_io ();
2304
2bd7c093 2305 (*the_target->resume) (resume_info, n);
bd99dc85
PA
2306
2307 if (non_stop)
2308 write_ok (own_buf);
2309 else
2310 {
95954743 2311 last_ptid = mywait (minus_one_ptid, &last_status, 0, 1);
d20a8ad9
PA
2312
2313 if (last_status.kind != TARGET_WAITKIND_EXITED
2314 && last_status.kind != TARGET_WAITKIND_SIGNALLED)
2315 {
2316 current_inferior->last_resume_kind = resume_stop;
2317 current_inferior->last_status = last_status;
2318 }
2319
bd99dc85
PA
2320 prepare_resume_reply (own_buf, last_ptid, &last_status);
2321 disable_async_io ();
6bd31874
JB
2322
2323 if (last_status.kind == TARGET_WAITKIND_EXITED
2324 || last_status.kind == TARGET_WAITKIND_SIGNALLED)
2325 mourn_inferior (find_process_pid (ptid_get_pid (last_ptid)));
bd99dc85
PA
2326 }
2327}
2328
2329/* Callback for for_each_inferior. Make a new stop reply for each
2330 stopped thread. */
2331
95954743
PA
2332static int
2333queue_stop_reply_callback (struct inferior_list_entry *entry, void *arg)
bd99dc85 2334{
8336d594 2335 struct thread_info *thread = (struct thread_info *) entry;
bd99dc85 2336
8336d594
PA
2337 /* For now, assume targets that don't have this callback also don't
2338 manage the thread's last_status field. */
2339 if (the_target->thread_stopped == NULL)
95954743 2340 {
8336d594
PA
2341 /* Pass the last stop reply back to GDB, but don't notify
2342 yet. */
2343 queue_stop_reply (entry->id, &thread->last_status);
2344 }
2345 else
2346 {
2347 if (thread_stopped (thread))
2348 {
2349 if (debug_threads)
493e2a69
MS
2350 fprintf (stderr,
2351 "Reporting thread %s as already stopped with %s\n",
8336d594
PA
2352 target_pid_to_str (entry->id),
2353 target_waitstatus_to_string (&thread->last_status));
2354
d20a8ad9
PA
2355 gdb_assert (thread->last_status.kind != TARGET_WAITKIND_IGNORE);
2356
8336d594
PA
2357 /* Pass the last stop reply back to GDB, but don't notify
2358 yet. */
2359 queue_stop_reply (entry->id, &thread->last_status);
2360 }
95954743
PA
2361 }
2362
2363 return 0;
64386c31
DJ
2364}
2365
ce1a5b52
PA
2366/* Set this inferior threads's state as "want-stopped". We won't
2367 resume this thread until the client gives us another action for
2368 it. */
8336d594
PA
2369
2370static void
2371gdb_wants_thread_stopped (struct inferior_list_entry *entry)
2372{
2373 struct thread_info *thread = (struct thread_info *) entry;
2374
2375 thread->last_resume_kind = resume_stop;
2376
2377 if (thread->last_status.kind == TARGET_WAITKIND_IGNORE)
2378 {
ce1a5b52
PA
2379 /* Most threads are stopped implicitly (all-stop); tag that with
2380 signal 0. */
8336d594 2381 thread->last_status.kind = TARGET_WAITKIND_STOPPED;
a493e3e2 2382 thread->last_status.value.sig = GDB_SIGNAL_0;
8336d594
PA
2383 }
2384}
2385
2386/* Set all threads' states as "want-stopped". */
2387
2388static void
2389gdb_wants_all_threads_stopped (void)
2390{
2391 for_each_inferior (&all_threads, gdb_wants_thread_stopped);
2392}
2393
2394/* Clear the gdb_detached flag of every process. */
2395
2396static void
2397gdb_reattached_process (struct inferior_list_entry *entry)
2398{
2399 struct process_info *process = (struct process_info *) entry;
2400
2401 process->gdb_detached = 0;
2402}
2403
5b1c542e
PA
2404/* Status handler for the '?' packet. */
2405
2406static void
2407handle_status (char *own_buf)
2408{
8336d594
PA
2409 /* GDB is connected, don't forward events to the target anymore. */
2410 for_each_inferior (&all_processes, gdb_reattached_process);
bd99dc85
PA
2411
2412 /* In non-stop mode, we must send a stop reply for each stopped
2413 thread. In all-stop mode, just send one for the first stopped
2414 thread we find. */
2415
2416 if (non_stop)
2417 {
8336d594
PA
2418 discard_queued_stop_replies (-1);
2419 find_inferior (&all_threads, queue_stop_reply_callback, NULL);
bd99dc85
PA
2420
2421 /* The first is sent immediatly. OK is sent if there is no
2422 stopped thread, which is the same handling of the vStopped
2423 packet (by design). */
2424 send_next_stop_reply (own_buf);
2425 }
5b1c542e 2426 else
bd99dc85 2427 {
7984d532 2428 pause_all (0);
fa593d66 2429 stabilize_threads ();
8336d594
PA
2430 gdb_wants_all_threads_stopped ();
2431
bd99dc85 2432 if (all_threads.head)
8336d594
PA
2433 {
2434 struct target_waitstatus status;
2435
2436 status.kind = TARGET_WAITKIND_STOPPED;
a493e3e2 2437 status.value.sig = GDB_SIGNAL_TRAP;
8336d594
PA
2438 prepare_resume_reply (own_buf,
2439 all_threads.head->id, &status);
2440 }
bd99dc85
PA
2441 else
2442 strcpy (own_buf, "W00");
2443 }
5b1c542e
PA
2444}
2445
dd24457d
DJ
2446static void
2447gdbserver_version (void)
2448{
c16158bc 2449 printf ("GNU gdbserver %s%s\n"
67827812 2450 "Copyright (C) 2012 Free Software Foundation, Inc.\n"
493e2a69
MS
2451 "gdbserver is free software, covered by the "
2452 "GNU General Public License.\n"
dd24457d 2453 "This gdbserver was configured as \"%s\"\n",
c16158bc 2454 PKGVERSION, version, host_name);
dd24457d
DJ
2455}
2456
0bc68c49 2457static void
c16158bc 2458gdbserver_usage (FILE *stream)
0bc68c49 2459{
c16158bc
JM
2460 fprintf (stream, "Usage:\tgdbserver [OPTIONS] COMM PROG [ARGS ...]\n"
2461 "\tgdbserver [OPTIONS] --attach COMM PID\n"
2462 "\tgdbserver [OPTIONS] --multi COMM\n"
2463 "\n"
2464 "COMM may either be a tty device (for serial debugging), or \n"
2465 "HOST:PORT to listen for a TCP connection.\n"
2466 "\n"
2467 "Options:\n"
62709adf
PA
2468 " --debug Enable general debugging output.\n"
2469 " --remote-debug Enable remote protocol debugging output.\n"
2470 " --version Display version information and exit.\n"
03f2bd59
JK
2471 " --wrapper WRAPPER -- Run WRAPPER to start new programs.\n"
2472 " --once Exit after the first connection has "
2473 "closed.\n");
c16158bc
JM
2474 if (REPORT_BUGS_TO[0] && stream == stdout)
2475 fprintf (stream, "Report bugs to \"%s\".\n", REPORT_BUGS_TO);
0bc68c49
DJ
2476}
2477
db42f210
PA
2478static void
2479gdbserver_show_disableable (FILE *stream)
2480{
2481 fprintf (stream, "Disableable packets:\n"
2482 " vCont \tAll vCont packets\n"
2483 " qC \tQuerying the current thread\n"
2484 " qfThreadInfo\tThread listing\n"
493e2a69
MS
2485 " Tthread \tPassing the thread specifier in the "
2486 "T stop reply packet\n"
db42f210
PA
2487 " threads \tAll of the above\n");
2488}
2489
2490
2d717e4f
DJ
2491#undef require_running
2492#define require_running(BUF) \
2493 if (!target_running ()) \
2494 { \
2495 write_enn (BUF); \
2496 break; \
2497 }
2498
95954743
PA
2499static int
2500first_thread_of (struct inferior_list_entry *entry, void *args)
2501{
2502 int pid = * (int *) args;
2503
2504 if (ptid_get_pid (entry->id) == pid)
2505 return 1;
2506
2507 return 0;
2508}
2509
2510static void
2511kill_inferior_callback (struct inferior_list_entry *entry)
2512{
2513 struct process_info *process = (struct process_info *) entry;
2514 int pid = ptid_get_pid (process->head.id);
2515
2516 kill_inferior (pid);
2517 discard_queued_stop_replies (pid);
2518}
2519
9f767825
DE
2520/* Callback for for_each_inferior to detach or kill the inferior,
2521 depending on whether we attached to it or not.
2522 We inform the user whether we're detaching or killing the process
2523 as this is only called when gdbserver is about to exit. */
2524
95954743
PA
2525static void
2526detach_or_kill_inferior_callback (struct inferior_list_entry *entry)
2527{
2528 struct process_info *process = (struct process_info *) entry;
2529 int pid = ptid_get_pid (process->head.id);
2530
2531 if (process->attached)
2532 detach_inferior (pid);
2533 else
2534 kill_inferior (pid);
2535
2536 discard_queued_stop_replies (pid);
2537}
2538
9f767825
DE
2539/* for_each_inferior callback for detach_or_kill_for_exit to print
2540 the pids of started inferiors. */
2541
2542static void
2543print_started_pid (struct inferior_list_entry *entry)
2544{
2545 struct process_info *process = (struct process_info *) entry;
2546
2547 if (! process->attached)
2548 {
2549 int pid = ptid_get_pid (process->head.id);
2550 fprintf (stderr, " %d", pid);
2551 }
2552}
2553
2554/* for_each_inferior callback for detach_or_kill_for_exit to print
2555 the pids of attached inferiors. */
2556
2557static void
2558print_attached_pid (struct inferior_list_entry *entry)
2559{
2560 struct process_info *process = (struct process_info *) entry;
2561
2562 if (process->attached)
2563 {
2564 int pid = ptid_get_pid (process->head.id);
2565 fprintf (stderr, " %d", pid);
2566 }
2567}
2568
2569/* Call this when exiting gdbserver with possible inferiors that need
2570 to be killed or detached from. */
2571
2572static void
2573detach_or_kill_for_exit (void)
2574{
2575 /* First print a list of the inferiors we will be killing/detaching.
2576 This is to assist the user, for example, in case the inferior unexpectedly
2577 dies after we exit: did we screw up or did the inferior exit on its own?
2578 Having this info will save some head-scratching. */
2579
2580 if (have_started_inferiors_p ())
2581 {
2582 fprintf (stderr, "Killing process(es):");
2583 for_each_inferior (&all_processes, print_started_pid);
2584 fprintf (stderr, "\n");
2585 }
2586 if (have_attached_inferiors_p ())
2587 {
2588 fprintf (stderr, "Detaching process(es):");
2589 for_each_inferior (&all_processes, print_attached_pid);
2590 fprintf (stderr, "\n");
2591 }
2592
2593 /* Now we can kill or detach the inferiors. */
2594
2595 for_each_inferior (&all_processes, detach_or_kill_inferior_callback);
2596}
2597
c906108c 2598int
da85418c 2599main (int argc, char *argv[])
c906108c 2600{
0729219d
DJ
2601 int bad_attach;
2602 int pid;
2d717e4f
DJ
2603 char *arg_end, *port;
2604 char **next_arg = &argv[1];
89dc0afd
JK
2605 volatile int multi_mode = 0;
2606 volatile int attach = 0;
2d717e4f 2607 int was_running;
c906108c 2608
2d717e4f 2609 while (*next_arg != NULL && **next_arg == '-')
dd24457d 2610 {
2d717e4f
DJ
2611 if (strcmp (*next_arg, "--version") == 0)
2612 {
2613 gdbserver_version ();
2614 exit (0);
2615 }
2616 else if (strcmp (*next_arg, "--help") == 0)
2617 {
c16158bc 2618 gdbserver_usage (stdout);
2d717e4f
DJ
2619 exit (0);
2620 }
2621 else if (strcmp (*next_arg, "--attach") == 0)
2622 attach = 1;
2623 else if (strcmp (*next_arg, "--multi") == 0)
2624 multi_mode = 1;
ccd213ac
DJ
2625 else if (strcmp (*next_arg, "--wrapper") == 0)
2626 {
2627 next_arg++;
2628
2629 wrapper_argv = next_arg;
2630 while (*next_arg != NULL && strcmp (*next_arg, "--") != 0)
2631 next_arg++;
2632
2633 if (next_arg == wrapper_argv || *next_arg == NULL)
2634 {
c16158bc 2635 gdbserver_usage (stderr);
ccd213ac
DJ
2636 exit (1);
2637 }
2638
2639 /* Consume the "--". */
2640 *next_arg = NULL;
2641 }
2d717e4f
DJ
2642 else if (strcmp (*next_arg, "--debug") == 0)
2643 debug_threads = 1;
62709adf
PA
2644 else if (strcmp (*next_arg, "--remote-debug") == 0)
2645 remote_debug = 1;
db42f210
PA
2646 else if (strcmp (*next_arg, "--disable-packet") == 0)
2647 {
2648 gdbserver_show_disableable (stdout);
2649 exit (0);
2650 }
2651 else if (strncmp (*next_arg,
2652 "--disable-packet=",
2653 sizeof ("--disable-packet=") - 1) == 0)
2654 {
2655 char *packets, *tok;
2656
2657 packets = *next_arg += sizeof ("--disable-packet=") - 1;
2658 for (tok = strtok (packets, ",");
2659 tok != NULL;
2660 tok = strtok (NULL, ","))
2661 {
2662 if (strcmp ("vCont", tok) == 0)
2663 disable_packet_vCont = 1;
2664 else if (strcmp ("Tthread", tok) == 0)
2665 disable_packet_Tthread = 1;
2666 else if (strcmp ("qC", tok) == 0)
2667 disable_packet_qC = 1;
2668 else if (strcmp ("qfThreadInfo", tok) == 0)
2669 disable_packet_qfThreadInfo = 1;
2670 else if (strcmp ("threads", tok) == 0)
2671 {
2672 disable_packet_vCont = 1;
2673 disable_packet_Tthread = 1;
2674 disable_packet_qC = 1;
2675 disable_packet_qfThreadInfo = 1;
2676 }
2677 else
2678 {
2679 fprintf (stderr, "Don't know how to disable \"%s\".\n\n",
2680 tok);
2681 gdbserver_show_disableable (stderr);
2682 exit (1);
2683 }
2684 }
2685 }
e0f9f062
DE
2686 else if (strcmp (*next_arg, "-") == 0)
2687 {
2688 /* "-" specifies a stdio connection and is a form of port
2689 specification. */
2690 *next_arg = STDIO_CONNECTION_NAME;
2691 break;
2692 }
03583c20
UW
2693 else if (strcmp (*next_arg, "--disable-randomization") == 0)
2694 disable_randomization = 1;
2695 else if (strcmp (*next_arg, "--no-disable-randomization") == 0)
2696 disable_randomization = 0;
03f2bd59
JK
2697 else if (strcmp (*next_arg, "--once") == 0)
2698 run_once = 1;
2d717e4f
DJ
2699 else
2700 {
2701 fprintf (stderr, "Unknown argument: %s\n", *next_arg);
2702 exit (1);
2703 }
dd24457d 2704
2d717e4f
DJ
2705 next_arg++;
2706 continue;
dd24457d
DJ
2707 }
2708
c5aa993b 2709 if (setjmp (toplevel))
c906108c 2710 {
c5aa993b
JM
2711 fprintf (stderr, "Exiting\n");
2712 exit (1);
c906108c
SS
2713 }
2714
2d717e4f
DJ
2715 port = *next_arg;
2716 next_arg++;
2717 if (port == NULL || (!attach && !multi_mode && *next_arg == NULL))
2718 {
c16158bc 2719 gdbserver_usage (stderr);
2d717e4f
DJ
2720 exit (1);
2721 }
2722
e0f9f062
DE
2723 /* We need to know whether the remote connection is stdio before
2724 starting the inferior. Inferiors created in this scenario have
2725 stdin,stdout redirected. So do this here before we call
2726 start_inferior. */
2727 remote_prepare (port);
2728
0729219d
DJ
2729 bad_attach = 0;
2730 pid = 0;
2d717e4f
DJ
2731
2732 /* --attach used to come after PORT, so allow it there for
2733 compatibility. */
2734 if (*next_arg != NULL && strcmp (*next_arg, "--attach") == 0)
45b7b345 2735 {
2d717e4f
DJ
2736 attach = 1;
2737 next_arg++;
45b7b345
DJ
2738 }
2739
2d717e4f
DJ
2740 if (attach
2741 && (*next_arg == NULL
2742 || (*next_arg)[0] == '\0'
2743 || (pid = strtoul (*next_arg, &arg_end, 0)) == 0
2744 || *arg_end != '\0'
2745 || next_arg[1] != NULL))
2746 bad_attach = 1;
2747
2748 if (bad_attach)
dd24457d 2749 {
c16158bc 2750 gdbserver_usage (stderr);
dd24457d
DJ
2751 exit (1);
2752 }
c906108c 2753
a20d5e98 2754 initialize_async_io ();
4ce44c66 2755 initialize_low ();
219f2f23
PA
2756 if (target_supports_tracepoints ())
2757 initialize_tracepoint ();
4ce44c66 2758
bca929d3
DE
2759 own_buf = xmalloc (PBUFSIZ + 1);
2760 mem_buf = xmalloc (PBUFSIZ);
0a30fbc4 2761
2d717e4f 2762 if (pid == 0 && *next_arg != NULL)
45b7b345 2763 {
2d717e4f
DJ
2764 int i, n;
2765
2766 n = argc - (next_arg - argv);
bca929d3 2767 program_argv = xmalloc (sizeof (char *) * (n + 1));
2d717e4f 2768 for (i = 0; i < n; i++)
bca929d3 2769 program_argv[i] = xstrdup (next_arg[i]);
2d717e4f
DJ
2770 program_argv[i] = NULL;
2771
45b7b345 2772 /* Wait till we are at first instruction in program. */
5b1c542e 2773 start_inferior (program_argv);
c906108c 2774
c588c53c
MS
2775 /* We are now (hopefully) stopped at the first instruction of
2776 the target process. This assumes that the target process was
2777 successfully created. */
45b7b345 2778 }
2d717e4f
DJ
2779 else if (pid != 0)
2780 {
5b1c542e 2781 if (attach_inferior (pid) == -1)
2d717e4f
DJ
2782 error ("Attaching not supported on this target");
2783
2784 /* Otherwise succeeded. */
2785 }
45b7b345
DJ
2786 else
2787 {
5b1c542e
PA
2788 last_status.kind = TARGET_WAITKIND_EXITED;
2789 last_status.value.integer = 0;
95954743 2790 last_ptid = minus_one_ptid;
45b7b345 2791 }
c906108c 2792
311de423
PA
2793 /* Don't report shared library events on the initial connection,
2794 even if some libraries are preloaded. Avoids the "stopped by
2795 shared library event" notice on gdb side. */
2796 dlls_changed = 0;
2797
8264bb58
DJ
2798 if (setjmp (toplevel))
2799 {
f128d5e9
PA
2800 /* If something fails and longjmps while detaching or killing
2801 inferiors, we'd end up here again, stuck in an infinite loop
2802 trap. Be sure that if that happens, we exit immediately
2803 instead. */
01b17894
PA
2804 if (setjmp (toplevel) == 0)
2805 detach_or_kill_for_exit ();
2806 else
2807 fprintf (stderr, "Detach or kill failed. Exiting\n");
8264bb58
DJ
2808 exit (1);
2809 }
2810
5b1c542e
PA
2811 if (last_status.kind == TARGET_WAITKIND_EXITED
2812 || last_status.kind == TARGET_WAITKIND_SIGNALLED)
2d717e4f
DJ
2813 was_running = 0;
2814 else
2815 was_running = 1;
2816
2817 if (!was_running && !multi_mode)
c588c53c 2818 {
2d717e4f 2819 fprintf (stderr, "No program to debug. GDBserver exiting.\n");
c588c53c
MS
2820 exit (1);
2821 }
2822
c906108c
SS
2823 while (1)
2824 {
a6f3e723 2825 noack_mode = 0;
95954743 2826 multi_process = 0;
8336d594
PA
2827 /* Be sure we're out of tfind mode. */
2828 current_traceframe = -1;
bd99dc85 2829
2d717e4f 2830 remote_open (port);
c906108c 2831
2d717e4f
DJ
2832 if (setjmp (toplevel) != 0)
2833 {
2834 /* An error occurred. */
2835 if (response_needed)
2836 {
2837 write_enn (own_buf);
2838 putpkt (own_buf);
2839 }
2840 }
2841
bd99dc85 2842 /* Wait for events. This will return when all event sources are
8336d594 2843 removed from the event loop. */
bd99dc85
PA
2844 start_event_loop ();
2845
2846 /* If an exit was requested (using the "monitor exit" command),
2847 terminate now. The only other way to get here is for
2848 getpkt to fail; close the connection and reopen it at the
2849 top of the loop. */
2850
03f2bd59 2851 if (exit_requested || run_once)
c906108c 2852 {
01b17894
PA
2853 /* If something fails and longjmps while detaching or
2854 killing inferiors, we'd end up here again, stuck in an
2855 infinite loop trap. Be sure that if that happens, we
2856 exit immediately instead. */
2857 if (setjmp (toplevel) == 0)
2858 {
2859 detach_or_kill_for_exit ();
2860 exit (0);
2861 }
2862 else
2863 {
2864 fprintf (stderr, "Detach or kill failed. Exiting\n");
2865 exit (1);
2866 }
bd99dc85 2867 }
8336d594
PA
2868
2869 fprintf (stderr,
2870 "Remote side has terminated connection. "
2871 "GDBserver will reopen the connection.\n");
2872
2873 if (tracing)
2874 {
2875 if (disconnected_tracing)
2876 {
2877 /* Try to enable non-stop/async mode, so we we can both
2878 wait for an async socket accept, and handle async
2879 target events simultaneously. There's also no point
2880 either in having the target always stop all threads,
2881 when we're going to pass signals down without
2882 informing GDB. */
2883 if (!non_stop)
2884 {
2885 if (start_non_stop (1))
2886 non_stop = 1;
2887
2888 /* Detaching implicitly resumes all threads; simply
2889 disconnecting does not. */
2890 }
2891 }
2892 else
2893 {
2894 fprintf (stderr,
2895 "Disconnected tracing disabled; stopping trace run.\n");
2896 stop_tracing ();
2897 }
2898 }
bd99dc85
PA
2899 }
2900}
01f9e8fa 2901
9f3a5c85
LM
2902/* Process options coming from Z packets for *point at address
2903 POINT_ADDR. PACKET is the packet buffer. *PACKET is updated
2904 to point to the first char after the last processed option. */
2905
2906static void
2907process_point_options (CORE_ADDR point_addr, char **packet)
2908{
2909 char *dataptr = *packet;
2910
2911 /* Check if data has the correct format. */
2912 if (*dataptr != ';')
2913 return;
2914
2915 dataptr++;
2916
2917 while (*dataptr)
2918 {
2919 switch (*dataptr)
2920 {
2921 case 'X':
2922 /* Conditional expression. */
c6030312
JB
2923 if (remote_debug)
2924 fprintf (stderr, "Found breakpoint condition.\n");
9f3a5c85
LM
2925 add_breakpoint_condition (point_addr, &dataptr);
2926 break;
2927 default:
2928 /* Unrecognized token, just skip it. */
2929 fprintf (stderr, "Unknown token %c, ignoring.\n",
2930 *dataptr);
2931 }
2932
2933 /* Skip tokens until we find one that we recognize. */
2934 while (*dataptr && *dataptr != 'X' && *dataptr != ';')
2935 dataptr++;
2936 }
2937 *packet = dataptr;
2938}
2939
bd99dc85
PA
2940/* Event loop callback that handles a serial event. The first byte in
2941 the serial buffer gets us here. We expect characters to arrive at
2942 a brisk pace, so we read the rest of the packet with a blocking
2943 getpkt call. */
01f9e8fa 2944
8336d594 2945static int
bd99dc85
PA
2946process_serial_event (void)
2947{
2948 char ch;
2949 int i = 0;
2950 int signal;
2951 unsigned int len;
764880b7 2952 int res;
bd99dc85 2953 CORE_ADDR mem_addr;
95954743 2954 int pid;
bd99dc85
PA
2955 unsigned char sig;
2956 int packet_len;
2957 int new_packet_len = -1;
2958
2959 /* Used to decide when gdbserver should exit in
2960 multi-mode/remote. */
2961 static int have_ran = 0;
2962
2963 if (!have_ran)
2964 have_ran = target_running ();
2965
2966 disable_async_io ();
2967
2968 response_needed = 0;
2969 packet_len = getpkt (own_buf);
2970 if (packet_len <= 0)
2971 {
bd99dc85 2972 remote_close ();
8336d594
PA
2973 /* Force an event loop break. */
2974 return -1;
bd99dc85
PA
2975 }
2976 response_needed = 1;
2977
2978 i = 0;
2979 ch = own_buf[i++];
2980 switch (ch)
2981 {
2982 case 'q':
2983 handle_query (own_buf, packet_len, &new_packet_len);
2984 break;
2985 case 'Q':
2986 handle_general_set (own_buf);
2987 break;
2988 case 'D':
2989 require_running (own_buf);
95954743
PA
2990
2991 if (multi_process)
2992 {
2993 i++; /* skip ';' */
2994 pid = strtol (&own_buf[i], NULL, 16);
2995 }
2996 else
2997 pid =
2998 ptid_get_pid (((struct inferior_list_entry *) current_inferior)->id);
2999
8336d594
PA
3000 if (tracing && disconnected_tracing)
3001 {
3002 struct thread_resume resume_info;
3003 struct process_info *process = find_process_pid (pid);
3004
3005 if (process == NULL)
3006 {
3007 write_enn (own_buf);
3008 break;
3009 }
3010
3011 fprintf (stderr,
3012 "Disconnected tracing in effect, "
3013 "leaving gdbserver attached to the process\n");
3014
3015 /* Make sure we're in non-stop/async mode, so we we can both
3016 wait for an async socket accept, and handle async target
3017 events simultaneously. There's also no point either in
3018 having the target stop all threads, when we're going to
3019 pass signals down without informing GDB. */
3020 if (!non_stop)
3021 {
3022 if (debug_threads)
3023 fprintf (stderr, "Forcing non-stop mode\n");
3024
3025 non_stop = 1;
3026 start_non_stop (1);
3027 }
3028
3029 process->gdb_detached = 1;
3030
3031 /* Detaching implicitly resumes all threads. */
3032 resume_info.thread = minus_one_ptid;
3033 resume_info.kind = resume_continue;
3034 resume_info.sig = 0;
3035 (*the_target->resume) (&resume_info, 1);
3036
3037 write_ok (own_buf);
3038 break; /* from switch/case */
3039 }
3040
95954743 3041 fprintf (stderr, "Detaching from process %d\n", pid);
8336d594 3042 stop_tracing ();
95954743 3043 if (detach_inferior (pid) != 0)
bd99dc85
PA
3044 write_enn (own_buf);
3045 else
3046 {
95954743 3047 discard_queued_stop_replies (pid);
bd99dc85
PA
3048 write_ok (own_buf);
3049
3050 if (extended_protocol)
c906108c 3051 {
bd99dc85
PA
3052 /* Treat this like a normal program exit. */
3053 last_status.kind = TARGET_WAITKIND_EXITED;
3054 last_status.value.integer = 0;
95954743 3055 last_ptid = pid_to_ptid (pid);
2d717e4f 3056
bd99dc85
PA
3057 current_inferior = NULL;
3058 }
3059 else
3060 {
3061 putpkt (own_buf);
3062 remote_close ();
3063
3064 /* If we are attached, then we can exit. Otherwise, we
3065 need to hang around doing nothing, until the child is
3066 gone. */
71f55dd8 3067 join_inferior (pid);
bd99dc85
PA
3068 exit (0);
3069 }
3070 }
3071 break;
3072 case '!':
3073 extended_protocol = 1;
3074 write_ok (own_buf);
3075 break;
3076 case '?':
3077 handle_status (own_buf);
3078 break;
3079 case 'H':
3080 if (own_buf[1] == 'c' || own_buf[1] == 'g' || own_buf[1] == 's')
3081 {
95954743
PA
3082 ptid_t gdb_id, thread_id;
3083 int pid;
bd99dc85
PA
3084
3085 require_running (own_buf);
95954743
PA
3086
3087 gdb_id = read_ptid (&own_buf[2], NULL);
3088
3089 pid = ptid_get_pid (gdb_id);
3090
3091 if (ptid_equal (gdb_id, null_ptid)
3092 || ptid_equal (gdb_id, minus_one_ptid))
3093 thread_id = null_ptid;
3094 else if (pid != 0
3095 && ptid_equal (pid_to_ptid (pid),
3096 gdb_id))
3097 {
3098 struct thread_info *thread =
3099 (struct thread_info *) find_inferior (&all_threads,
3100 first_thread_of,
3101 &pid);
3102 if (!thread)
3103 {
3104 write_enn (own_buf);
3105 break;
3106 }
3107
3108 thread_id = ((struct inferior_list_entry *)thread)->id;
3109 }
bd99dc85
PA
3110 else
3111 {
3112 thread_id = gdb_id_to_thread_id (gdb_id);
95954743 3113 if (ptid_equal (thread_id, null_ptid))
c906108c 3114 {
a06660f7 3115 write_enn (own_buf);
c906108c
SS
3116 break;
3117 }
c906108c
SS
3118 }
3119
bd99dc85 3120 if (own_buf[1] == 'g')
c906108c 3121 {
95954743 3122 if (ptid_equal (thread_id, null_ptid))
c906108c 3123 {
bd99dc85
PA
3124 /* GDB is telling us to choose any thread. Check if
3125 the currently selected thread is still valid. If
3126 it is not, select the first available. */
3127 struct thread_info *thread =
3128 (struct thread_info *) find_inferior_id (&all_threads,
3129 general_thread);
3130 if (thread == NULL)
3131 thread_id = all_threads.head->id;
c906108c 3132 }
bd99dc85
PA
3133
3134 general_thread = thread_id;
3135 set_desired_inferior (1);
c906108c 3136 }
bd99dc85
PA
3137 else if (own_buf[1] == 'c')
3138 cont_thread = thread_id;
c906108c 3139
bd99dc85
PA
3140 write_ok (own_buf);
3141 }
3142 else
3143 {
3144 /* Silently ignore it so that gdb can extend the protocol
3145 without compatibility headaches. */
3146 own_buf[0] = '\0';
2d717e4f 3147 }
bd99dc85
PA
3148 break;
3149 case 'g':
219f2f23
PA
3150 require_running (own_buf);
3151 if (current_traceframe >= 0)
3152 {
3153 struct regcache *regcache = new_register_cache ();
3154
3155 if (fetch_traceframe_registers (current_traceframe,
3156 regcache, -1) == 0)
3157 registers_to_string (regcache, own_buf);
3158 else
3159 write_enn (own_buf);
3160 free_register_cache (regcache);
3161 }
3162 else
3163 {
3164 struct regcache *regcache;
3165
3166 set_desired_inferior (1);
3167 regcache = get_thread_regcache (current_inferior, 1);
3168 registers_to_string (regcache, own_buf);
3169 }
bd99dc85
PA
3170 break;
3171 case 'G':
219f2f23
PA
3172 require_running (own_buf);
3173 if (current_traceframe >= 0)
3174 write_enn (own_buf);
3175 else
3176 {
442ea881
PA
3177 struct regcache *regcache;
3178
442ea881
PA
3179 set_desired_inferior (1);
3180 regcache = get_thread_regcache (current_inferior, 1);
3181 registers_from_string (regcache, &own_buf[1]);
3182 write_ok (own_buf);
3183 }
bd99dc85
PA
3184 break;
3185 case 'm':
3186 require_running (own_buf);
3187 decode_m_packet (&own_buf[1], &mem_addr, &len);
764880b7
PA
3188 res = gdb_read_memory (mem_addr, mem_buf, len);
3189 if (res < 0)
bd99dc85 3190 write_enn (own_buf);
764880b7
PA
3191 else
3192 convert_int_to_ascii (mem_buf, own_buf, res);
bd99dc85
PA
3193 break;
3194 case 'M':
3195 require_running (own_buf);
fa593d66 3196 decode_M_packet (&own_buf[1], &mem_addr, &len, &mem_buf);
90d74c30 3197 if (gdb_write_memory (mem_addr, mem_buf, len) == 0)
bd99dc85
PA
3198 write_ok (own_buf);
3199 else
3200 write_enn (own_buf);
3201 break;
3202 case 'X':
3203 require_running (own_buf);
3204 if (decode_X_packet (&own_buf[1], packet_len - 1,
fa593d66 3205 &mem_addr, &len, &mem_buf) < 0
90d74c30 3206 || gdb_write_memory (mem_addr, mem_buf, len) != 0)
bd99dc85
PA
3207 write_enn (own_buf);
3208 else
3209 write_ok (own_buf);
3210 break;
3211 case 'C':
3212 require_running (own_buf);
3213 convert_ascii_to_int (own_buf + 1, &sig, 1);
2ea28649
PA
3214 if (gdb_signal_to_host_p (sig))
3215 signal = gdb_signal_to_host (sig);
bd99dc85
PA
3216 else
3217 signal = 0;
3218 myresume (own_buf, 0, signal);
3219 break;
3220 case 'S':
3221 require_running (own_buf);
3222 convert_ascii_to_int (own_buf + 1, &sig, 1);
2ea28649
PA
3223 if (gdb_signal_to_host_p (sig))
3224 signal = gdb_signal_to_host (sig);
bd99dc85
PA
3225 else
3226 signal = 0;
3227 myresume (own_buf, 1, signal);
3228 break;
3229 case 'c':
3230 require_running (own_buf);
3231 signal = 0;
3232 myresume (own_buf, 0, signal);
3233 break;
3234 case 's':
3235 require_running (own_buf);
3236 signal = 0;
3237 myresume (own_buf, 1, signal);
3238 break;
c6314022
AR
3239 case 'Z': /* insert_ ... */
3240 /* Fallthrough. */
3241 case 'z': /* remove_ ... */
bd99dc85
PA
3242 {
3243 char *lenptr;
3244 char *dataptr;
3245 CORE_ADDR addr = strtoul (&own_buf[3], &lenptr, 16);
3246 int len = strtol (lenptr + 1, &dataptr, 16);
3247 char type = own_buf[1];
c6314022 3248 int res;
d993e290 3249 const int insert = ch == 'Z';
c6314022 3250
d993e290
PA
3251 /* Default to unrecognized/unsupported. */
3252 res = 1;
3253 switch (type)
3254 {
3255 case '0': /* software-breakpoint */
3256 case '1': /* hardware-breakpoint */
3257 case '2': /* write watchpoint */
3258 case '3': /* read watchpoint */
3259 case '4': /* access watchpoint */
3260 require_running (own_buf);
3261 if (insert && the_target->insert_point != NULL)
9f3a5c85
LM
3262 {
3263 /* Insert the breakpoint. If it is already inserted, nothing
3264 will take place. */
3265 res = (*the_target->insert_point) (type, addr, len);
3266
3267 /* GDB may have sent us a list of *point parameters to be
3268 evaluated on the target's side. Read such list here. If we
3269 already have a list of parameters, GDB is telling us to drop
3270 that list and use this one instead. */
3271 if (!res && (type == '0' || type == '1'))
3272 {
3273 /* Remove previous conditions. */
3274 clear_gdb_breakpoint_conditions (addr);
3275 process_point_options (addr, &dataptr);
3276 }
3277 }
d993e290
PA
3278 else if (!insert && the_target->remove_point != NULL)
3279 res = (*the_target->remove_point) (type, addr, len);
3280 break;
3281 default:
3282 break;
3283 }
bd99dc85 3284
c6314022
AR
3285 if (res == 0)
3286 write_ok (own_buf);
3287 else if (res == 1)
3288 /* Unsupported. */
3289 own_buf[0] = '\0';
bd99dc85 3290 else
c6314022 3291 write_enn (own_buf);
bd99dc85
PA
3292 break;
3293 }
3294 case 'k':
3295 response_needed = 0;
3296 if (!target_running ())
95954743
PA
3297 /* The packet we received doesn't make sense - but we can't
3298 reply to it, either. */
8336d594 3299 return 0;
c906108c 3300
95954743
PA
3301 fprintf (stderr, "Killing all inferiors\n");
3302 for_each_inferior (&all_processes, kill_inferior_callback);
c906108c 3303
bd99dc85
PA
3304 /* When using the extended protocol, we wait with no program
3305 running. The traditional protocol will exit instead. */
3306 if (extended_protocol)
3307 {
3308 last_status.kind = TARGET_WAITKIND_EXITED;
a493e3e2 3309 last_status.value.sig = GDB_SIGNAL_KILL;
8336d594 3310 return 0;
bd99dc85
PA
3311 }
3312 else
8336d594
PA
3313 exit (0);
3314
bd99dc85
PA
3315 case 'T':
3316 {
95954743 3317 ptid_t gdb_id, thread_id;
bd99dc85
PA
3318
3319 require_running (own_buf);
95954743
PA
3320
3321 gdb_id = read_ptid (&own_buf[1], NULL);
bd99dc85 3322 thread_id = gdb_id_to_thread_id (gdb_id);
95954743 3323 if (ptid_equal (thread_id, null_ptid))
bd99dc85
PA
3324 {
3325 write_enn (own_buf);
3326 break;
3327 }
3328
3329 if (mythread_alive (thread_id))
3330 write_ok (own_buf);
3331 else
3332 write_enn (own_buf);
3333 }
3334 break;
3335 case 'R':
3336 response_needed = 0;
3337
3338 /* Restarting the inferior is only supported in the extended
3339 protocol. */
3340 if (extended_protocol)
3341 {
3342 if (target_running ())
95954743
PA
3343 for_each_inferior (&all_processes,
3344 kill_inferior_callback);
bd99dc85
PA
3345 fprintf (stderr, "GDBserver restarting\n");
3346
3347 /* Wait till we are at 1st instruction in prog. */
3348 if (program_argv != NULL)
3349 start_inferior (program_argv);
3350 else
3351 {
3352 last_status.kind = TARGET_WAITKIND_EXITED;
a493e3e2 3353 last_status.value.sig = GDB_SIGNAL_KILL;
bd99dc85 3354 }
8336d594 3355 return 0;
c906108c
SS
3356 }
3357 else
3358 {
bd99dc85
PA
3359 /* It is a request we don't understand. Respond with an
3360 empty packet so that gdb knows that we don't support this
3361 request. */
3362 own_buf[0] = '\0';
3363 break;
3364 }
3365 case 'v':
3366 /* Extended (long) request. */
3367 handle_v_requests (own_buf, packet_len, &new_packet_len);
3368 break;
3369
3370 default:
3371 /* It is a request we don't understand. Respond with an empty
3372 packet so that gdb knows that we don't support this
3373 request. */
3374 own_buf[0] = '\0';
3375 break;
3376 }
3377
3378 if (new_packet_len != -1)
3379 putpkt_binary (own_buf, new_packet_len);
3380 else
3381 putpkt (own_buf);
3382
3383 response_needed = 0;
3384
3385 if (!extended_protocol && have_ran && !target_running ())
3386 {
3387 /* In non-stop, defer exiting until GDB had a chance to query
3388 the whole vStopped list (until it gets an OK). */
3389 if (!notif_queue)
3390 {
3391 fprintf (stderr, "GDBserver exiting\n");
c906108c 3392 remote_close ();
bd99dc85 3393 exit (0);
c906108c
SS
3394 }
3395 }
8336d594
PA
3396
3397 if (exit_requested)
3398 return -1;
3399
3400 return 0;
c906108c 3401}
bd99dc85
PA
3402
3403/* Event-loop callback for serial events. */
3404
8336d594 3405int
bd99dc85
PA
3406handle_serial_event (int err, gdb_client_data client_data)
3407{
3408 if (debug_threads)
3409 fprintf (stderr, "handling possible serial event\n");
3410
3411 /* Really handle it. */
8336d594
PA
3412 if (process_serial_event () < 0)
3413 return -1;
bd99dc85
PA
3414
3415 /* Be sure to not change the selected inferior behind GDB's back.
3416 Important in the non-stop mode asynchronous protocol. */
3417 set_desired_inferior (1);
8336d594
PA
3418
3419 return 0;
bd99dc85
PA
3420}
3421
3422/* Event-loop callback for target events. */
3423
8336d594 3424int
bd99dc85
PA
3425handle_target_event (int err, gdb_client_data client_data)
3426{
3427 if (debug_threads)
3428 fprintf (stderr, "handling possible target event\n");
3429
95954743
PA
3430 last_ptid = mywait (minus_one_ptid, &last_status,
3431 TARGET_WNOHANG, 1);
bd99dc85
PA
3432
3433 if (last_status.kind != TARGET_WAITKIND_IGNORE)
3434 {
8336d594
PA
3435 int pid = ptid_get_pid (last_ptid);
3436 struct process_info *process = find_process_pid (pid);
3437 int forward_event = !gdb_connected () || process->gdb_detached;
3438
3439 if (last_status.kind == TARGET_WAITKIND_EXITED
3440 || last_status.kind == TARGET_WAITKIND_SIGNALLED)
f9e39928
PA
3441 {
3442 mark_breakpoints_out (process);
3443 mourn_inferior (process);
3444 }
ce1a5b52 3445 else
d20a8ad9
PA
3446 {
3447 /* We're reporting this thread as stopped. Update its
3448 "want-stopped" state to what the client wants, until it
3449 gets a new resume action. */
3450 current_inferior->last_resume_kind = resume_stop;
3451 current_inferior->last_status = last_status;
3452 }
8336d594
PA
3453
3454 if (forward_event)
3455 {
3456 if (!target_running ())
3457 {
3458 /* The last process exited. We're done. */
3459 exit (0);
3460 }
3461
3462 if (last_status.kind == TARGET_WAITKIND_STOPPED)
3463 {
3464 /* A thread stopped with a signal, but gdb isn't
3465 connected to handle it. Pass it down to the
3466 inferior, as if it wasn't being traced. */
3467 struct thread_resume resume_info;
3468
3469 if (debug_threads)
3470 fprintf (stderr,
3471 "GDB not connected; forwarding event %d for [%s]\n",
3472 (int) last_status.kind,
3473 target_pid_to_str (last_ptid));
3474
3475 resume_info.thread = last_ptid;
3476 resume_info.kind = resume_continue;
2ea28649 3477 resume_info.sig = gdb_signal_to_host (last_status.value.sig);
8336d594
PA
3478 (*the_target->resume) (&resume_info, 1);
3479 }
3480 else if (debug_threads)
3481 fprintf (stderr, "GDB not connected; ignoring event %d for [%s]\n",
3482 (int) last_status.kind,
3483 target_pid_to_str (last_ptid));
3484 }
3485 else
3486 {
3487 /* Something interesting. Tell GDB about it. */
3488 push_event (last_ptid, &last_status);
3489 }
bd99dc85
PA
3490 }
3491
3492 /* Be sure to not change the selected inferior behind GDB's back.
3493 Important in the non-stop mode asynchronous protocol. */
3494 set_desired_inferior (1);
8336d594
PA
3495
3496 return 0;
bd99dc85 3497}
This page took 1.288281 seconds and 4 git commands to generate.