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