1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* See the GDB User Guide for details of the GDB remote protocol. */
30 /*#include "terminal.h" */
33 #include "gdb-stabs.h"
34 #include "gdbthread.h"
36 #include "remote-notif.h"
41 #include "cli/cli-decode.h"
42 #include "cli/cli-setshow.h"
43 #include "target-descriptions.h"
45 #include "filestuff.h"
50 #include "gdb_sys_time.h"
52 #include "event-loop.h"
53 #include "event-top.h"
59 #include "gdbcore.h" /* for exec_bfd */
61 #include "remote-fileio.h"
62 #include "gdb/fileio.h"
64 #include "xml-support.h"
66 #include "memory-map.h"
68 #include "tracepoint.h"
73 #include "record-btrace.h"
75 #include "common/scoped_restore.h"
77 #include "common/byte-vector.h"
79 /* Per-program-space data key. */
80 static const struct program_space_data
*remote_pspace_data
;
82 /* The variable registered as the control variable used by the
83 remote exec-file commands. While the remote exec-file setting is
84 per-program-space, the set/show machinery uses this as the
85 location of the remote exec-file value. */
86 static char *remote_exec_file_var
;
88 /* The size to align memory write packets, when practical. The protocol
89 does not guarantee any alignment, and gdb will generate short
90 writes and unaligned writes, but even as a best-effort attempt this
91 can improve bulk transfers. For instance, if a write is misaligned
92 relative to the target's data bus, the stub may need to make an extra
93 round trip fetching data from the target. This doesn't make a
94 huge difference, but it's easy to do, so we try to be helpful.
96 The alignment chosen is arbitrary; usually data bus width is
97 important here, not the possibly larger cache line size. */
98 enum { REMOTE_ALIGN_WRITES
= 16 };
100 /* Prototypes for local functions. */
101 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
102 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
103 int forever
, int *is_notif
);
105 static void remote_files_info (struct target_ops
*ignore
);
107 static void remote_prepare_to_store (struct target_ops
*self
,
108 struct regcache
*regcache
);
110 static void remote_open_1 (const char *, int, struct target_ops
*,
113 static void remote_close (struct target_ops
*self
);
117 static int remote_vkill (int pid
, struct remote_state
*rs
);
119 static void remote_kill_k (void);
121 static void remote_mourn (struct target_ops
*ops
);
123 static void extended_remote_restart (void);
125 static void remote_send (char **buf
, long *sizeof_buf_p
);
127 static int readchar (int timeout
);
129 static void remote_serial_write (const char *str
, int len
);
131 static void remote_kill (struct target_ops
*ops
);
133 static int remote_can_async_p (struct target_ops
*);
135 static int remote_is_async_p (struct target_ops
*);
137 static void remote_async (struct target_ops
*ops
, int enable
);
139 static void remote_thread_events (struct target_ops
*ops
, int enable
);
141 static void interrupt_query (void);
143 static void set_general_thread (ptid_t ptid
);
144 static void set_continue_thread (ptid_t ptid
);
146 static void get_offsets (void);
148 static void skip_frame (void);
150 static long read_frame (char **buf_p
, long *sizeof_buf
);
152 static int hexnumlen (ULONGEST num
);
154 static void init_remote_ops (void);
156 static void init_extended_remote_ops (void);
158 static void remote_stop (struct target_ops
*self
, ptid_t
);
160 static int stubhex (int ch
);
162 static int hexnumstr (char *, ULONGEST
);
164 static int hexnumnstr (char *, ULONGEST
, int);
166 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
168 static void print_packet (const char *);
170 static int stub_unpack_int (char *buff
, int fieldlength
);
172 static ptid_t
remote_current_thread (ptid_t oldptid
);
174 static int putpkt_binary (const char *buf
, int cnt
);
176 static void check_binary_download (CORE_ADDR addr
);
178 struct packet_config
;
180 static void show_packet_config_cmd (struct packet_config
*config
);
182 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
184 struct cmd_list_element
*c
,
187 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
188 static ptid_t
read_ptid (const char *buf
, const char **obuf
);
190 static void remote_set_permissions (struct target_ops
*self
);
192 static int remote_get_trace_status (struct target_ops
*self
,
193 struct trace_status
*ts
);
195 static int remote_upload_tracepoints (struct target_ops
*self
,
196 struct uploaded_tp
**utpp
);
198 static int remote_upload_trace_state_variables (struct target_ops
*self
,
199 struct uploaded_tsv
**utsvp
);
201 static void remote_query_supported (void);
203 static void remote_check_symbols (void);
206 static void stop_reply_xfree (struct stop_reply
*);
207 static void remote_parse_stop_reply (char *, struct stop_reply
*);
208 static void push_stop_reply (struct stop_reply
*);
209 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
210 static int peek_stop_reply (ptid_t ptid
);
212 struct threads_listing_context
;
213 static void remove_new_fork_children (struct threads_listing_context
*);
215 static void remote_async_inferior_event_handler (gdb_client_data
);
217 static void remote_terminal_ours (struct target_ops
*self
);
219 static int remote_read_description_p (struct target_ops
*target
);
221 static void remote_console_output (char *msg
);
223 static int remote_supports_cond_breakpoints (struct target_ops
*self
);
225 static int remote_can_run_breakpoint_commands (struct target_ops
*self
);
227 static void remote_btrace_reset (void);
229 static void remote_btrace_maybe_reopen (void);
231 static int stop_reply_queue_length (void);
233 static void readahead_cache_invalidate (void);
235 static void remote_unpush_and_throw (void);
237 static struct remote_state
*get_remote_state (void);
241 static struct cmd_list_element
*remote_cmdlist
;
243 /* For "set remote" and "show remote". */
245 static struct cmd_list_element
*remote_set_cmdlist
;
246 static struct cmd_list_element
*remote_show_cmdlist
;
248 /* Stub vCont actions support.
250 Each field is a boolean flag indicating whether the stub reports
251 support for the corresponding action. */
253 struct vCont_action_support
268 /* Controls whether GDB is willing to use range stepping. */
270 static int use_range_stepping
= 1;
272 #define OPAQUETHREADBYTES 8
274 /* a 64 bit opaque identifier */
275 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
277 /* About this many threadisds fit in a packet. */
279 #define MAXTHREADLISTRESULTS 32
281 /* The max number of chars in debug output. The rest of chars are
284 #define REMOTE_DEBUG_MAX_CHAR 512
286 /* Data for the vFile:pread readahead cache. */
288 struct readahead_cache
290 /* The file descriptor for the file that is being cached. -1 if the
294 /* The offset into the file that the cache buffer corresponds
298 /* The buffer holding the cache contents. */
300 /* The buffer's size. We try to read as much as fits into a packet
304 /* Cache hit and miss counters. */
309 /* Description of the remote protocol state for the currently
310 connected target. This is per-target state, and independent of the
311 selected architecture. */
315 /* A buffer to use for incoming packets, and its current size. The
316 buffer is grown dynamically for larger incoming packets.
317 Outgoing packets may also be constructed in this buffer.
318 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
319 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
324 /* True if we're going through initial connection setup (finding out
325 about the remote side's threads, relocating symbols, etc.). */
328 /* If we negotiated packet size explicitly (and thus can bypass
329 heuristics for the largest packet size that will not overflow
330 a buffer in the stub), this will be set to that packet size.
331 Otherwise zero, meaning to use the guessed size. */
332 long explicit_packet_size
;
334 /* remote_wait is normally called when the target is running and
335 waits for a stop reply packet. But sometimes we need to call it
336 when the target is already stopped. We can send a "?" packet
337 and have remote_wait read the response. Or, if we already have
338 the response, we can stash it in BUF and tell remote_wait to
339 skip calling getpkt. This flag is set when BUF contains a
340 stop reply packet and the target is not waiting. */
341 int cached_wait_status
;
343 /* True, if in no ack mode. That is, neither GDB nor the stub will
344 expect acks from each other. The connection is assumed to be
348 /* True if we're connected in extended remote mode. */
351 /* True if we resumed the target and we're waiting for the target to
352 stop. In the mean time, we can't start another command/query.
353 The remote server wouldn't be ready to process it, so we'd
354 timeout waiting for a reply that would never come and eventually
355 we'd close the connection. This can happen in asynchronous mode
356 because we allow GDB commands while the target is running. */
357 int waiting_for_stop_reply
;
359 /* The status of the stub support for the various vCont actions. */
360 struct vCont_action_support supports_vCont
;
362 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
363 responded to that. */
366 /* True if we saw a Ctrl-C while reading or writing from/to the
367 remote descriptor. At that point it is not safe to send a remote
368 interrupt packet, so we instead remember we saw the Ctrl-C and
369 process it once we're done with sending/receiving the current
370 packet, which should be shortly. If however that takes too long,
371 and the user presses Ctrl-C again, we offer to disconnect. */
372 int got_ctrlc_during_io
;
374 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
375 remote_open knows that we don't have a file open when the program
377 struct serial
*remote_desc
;
379 /* These are the threads which we last sent to the remote system. The
380 TID member will be -1 for all or -2 for not sent yet. */
381 ptid_t general_thread
;
382 ptid_t continue_thread
;
384 /* This is the traceframe which we last selected on the remote system.
385 It will be -1 if no traceframe is selected. */
386 int remote_traceframe_number
;
388 char *last_pass_packet
;
390 /* The last QProgramSignals packet sent to the target. We bypass
391 sending a new program signals list down to the target if the new
392 packet is exactly the same as the last we sent. IOW, we only let
393 the target know about program signals list changes. */
394 char *last_program_signals_packet
;
396 enum gdb_signal last_sent_signal
;
400 /* The execution direction of the last resume we got. */
401 enum exec_direction_kind last_resume_exec_dir
;
403 char *finished_object
;
404 char *finished_annex
;
405 ULONGEST finished_offset
;
407 /* Should we try the 'ThreadInfo' query packet?
409 This variable (NOT available to the user: auto-detect only!)
410 determines whether GDB will use the new, simpler "ThreadInfo"
411 query or the older, more complex syntax for thread queries.
412 This is an auto-detect variable (set to true at each connect,
413 and set to false when the target fails to recognize it). */
414 int use_threadinfo_query
;
415 int use_threadextra_query
;
417 threadref echo_nextthread
;
418 threadref nextthread
;
419 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
421 /* The state of remote notification. */
422 struct remote_notif_state
*notif_state
;
424 /* The branch trace configuration. */
425 struct btrace_config btrace_config
;
427 /* The argument to the last "vFile:setfs:" packet we sent, used
428 to avoid sending repeated unnecessary "vFile:setfs:" packets.
429 Initialized to -1 to indicate that no "vFile:setfs:" packet
430 has yet been sent. */
433 /* A readahead cache for vFile:pread. Often, reading a binary
434 involves a sequence of small reads. E.g., when parsing an ELF
435 file. A readahead cache helps mostly the case of remote
436 debugging on a connection with higher latency, due to the
437 request/reply nature of the RSP. We only cache data for a single
438 file descriptor at a time. */
439 struct readahead_cache readahead_cache
;
442 /* Private data that we'll store in (struct thread_info)->private. */
443 struct private_thread_info
449 /* Thread handle, perhaps a pthread_t or thread_t value, stored as a
450 sequence of bytes. */
451 gdb::byte_vector
*thread_handle
;
453 /* Whether the target stopped for a breakpoint/watchpoint. */
454 enum target_stop_reason stop_reason
;
456 /* This is set to the data address of the access causing the target
457 to stop for a watchpoint. */
458 CORE_ADDR watch_data_address
;
460 /* Fields used by the vCont action coalescing implemented in
461 remote_resume / remote_commit_resume. remote_resume stores each
462 thread's last resume request in these fields, so that a later
463 remote_commit_resume knows which is the proper action for this
464 thread to include in the vCont packet. */
466 /* True if the last target_resume call for this thread was a step
467 request, false if a continue request. */
468 int last_resume_step
;
470 /* The signal specified in the last target_resume call for this
472 enum gdb_signal last_resume_sig
;
474 /* Whether this thread was already vCont-resumed on the remote
480 free_private_thread_info (struct private_thread_info
*info
)
484 delete info
->thread_handle
;
488 /* This data could be associated with a target, but we do not always
489 have access to the current target when we need it, so for now it is
490 static. This will be fine for as long as only one target is in use
492 static struct remote_state
*remote_state
;
494 static struct remote_state
*
495 get_remote_state_raw (void)
500 /* Allocate a new struct remote_state with xmalloc, initialize it, and
503 static struct remote_state
*
504 new_remote_state (void)
506 struct remote_state
*result
= XCNEW (struct remote_state
);
508 /* The default buffer size is unimportant; it will be expanded
509 whenever a larger buffer is needed. */
510 result
->buf_size
= 400;
511 result
->buf
= (char *) xmalloc (result
->buf_size
);
512 result
->remote_traceframe_number
= -1;
513 result
->last_sent_signal
= GDB_SIGNAL_0
;
514 result
->last_resume_exec_dir
= EXEC_FORWARD
;
520 /* Description of the remote protocol for a given architecture. */
524 long offset
; /* Offset into G packet. */
525 long regnum
; /* GDB's internal register number. */
526 LONGEST pnum
; /* Remote protocol register number. */
527 int in_g_packet
; /* Always part of G packet. */
528 /* long size in bytes; == register_size (target_gdbarch (), regnum);
530 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
534 struct remote_arch_state
536 /* Description of the remote protocol registers. */
537 long sizeof_g_packet
;
539 /* Description of the remote protocol registers indexed by REGNUM
540 (making an array gdbarch_num_regs in size). */
541 struct packet_reg
*regs
;
543 /* This is the size (in chars) of the first response to the ``g''
544 packet. It is used as a heuristic when determining the maximum
545 size of memory-read and memory-write packets. A target will
546 typically only reserve a buffer large enough to hold the ``g''
547 packet. The size does not include packet overhead (headers and
549 long actual_register_packet_size
;
551 /* This is the maximum size (in chars) of a non read/write packet.
552 It is also used as a cap on the size of read/write packets. */
553 long remote_packet_size
;
556 /* Utility: generate error from an incoming stub packet. */
558 trace_error (char *buf
)
561 return; /* not an error msg */
564 case '1': /* malformed packet error */
565 if (*++buf
== '0') /* general case: */
566 error (_("remote.c: error in outgoing packet."));
568 error (_("remote.c: error in outgoing packet at field #%ld."),
569 strtol (buf
, NULL
, 16));
571 error (_("Target returns error code '%s'."), buf
);
575 /* Utility: wait for reply from stub, while accepting "O" packets. */
578 remote_get_noisy_reply ()
580 struct remote_state
*rs
= get_remote_state ();
582 do /* Loop on reply from remote stub. */
586 QUIT
; /* Allow user to bail out with ^C. */
587 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
591 else if (startswith (buf
, "qRelocInsn:"))
594 CORE_ADDR from
, to
, org_to
;
596 int adjusted_size
= 0;
599 p
= buf
+ strlen ("qRelocInsn:");
600 pp
= unpack_varlen_hex (p
, &ul
);
602 error (_("invalid qRelocInsn packet: %s"), buf
);
606 unpack_varlen_hex (p
, &ul
);
613 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
616 CATCH (ex
, RETURN_MASK_ALL
)
618 if (ex
.error
== MEMORY_ERROR
)
620 /* Propagate memory errors silently back to the
621 target. The stub may have limited the range of
622 addresses we can write to, for example. */
626 /* Something unexpectedly bad happened. Be verbose
627 so we can tell what, and propagate the error back
628 to the stub, so it doesn't get stuck waiting for
630 exception_fprintf (gdb_stderr
, ex
,
631 _("warning: relocating instruction: "));
639 adjusted_size
= to
- org_to
;
641 xsnprintf (buf
, rs
->buf_size
, "qRelocInsn:%x", adjusted_size
);
645 else if (buf
[0] == 'O' && buf
[1] != 'K')
646 remote_console_output (buf
+ 1); /* 'O' message from stub */
648 return buf
; /* Here's the actual reply. */
653 /* Handle for retreving the remote protocol data from gdbarch. */
654 static struct gdbarch_data
*remote_gdbarch_data_handle
;
656 static struct remote_arch_state
*
657 get_remote_arch_state (struct gdbarch
*gdbarch
)
659 gdb_assert (gdbarch
!= NULL
);
660 return ((struct remote_arch_state
*)
661 gdbarch_data (gdbarch
, remote_gdbarch_data_handle
));
664 /* Fetch the global remote target state. */
666 static struct remote_state
*
667 get_remote_state (void)
669 /* Make sure that the remote architecture state has been
670 initialized, because doing so might reallocate rs->buf. Any
671 function which calls getpkt also needs to be mindful of changes
672 to rs->buf, but this call limits the number of places which run
674 get_remote_arch_state (target_gdbarch ());
676 return get_remote_state_raw ();
679 /* Cleanup routine for the remote module's pspace data. */
682 remote_pspace_data_cleanup (struct program_space
*pspace
, void *arg
)
684 char *remote_exec_file
= (char *) arg
;
686 xfree (remote_exec_file
);
689 /* Fetch the remote exec-file from the current program space. */
692 get_remote_exec_file (void)
694 char *remote_exec_file
;
697 = (char *) program_space_data (current_program_space
,
699 if (remote_exec_file
== NULL
)
702 return remote_exec_file
;
705 /* Set the remote exec file for PSPACE. */
708 set_pspace_remote_exec_file (struct program_space
*pspace
,
709 char *remote_exec_file
)
711 char *old_file
= (char *) program_space_data (pspace
, remote_pspace_data
);
714 set_program_space_data (pspace
, remote_pspace_data
,
715 xstrdup (remote_exec_file
));
718 /* The "set/show remote exec-file" set command hook. */
721 set_remote_exec_file (char *ignored
, int from_tty
,
722 struct cmd_list_element
*c
)
724 gdb_assert (remote_exec_file_var
!= NULL
);
725 set_pspace_remote_exec_file (current_program_space
, remote_exec_file_var
);
728 /* The "set/show remote exec-file" show command hook. */
731 show_remote_exec_file (struct ui_file
*file
, int from_tty
,
732 struct cmd_list_element
*cmd
, const char *value
)
734 fprintf_filtered (file
, "%s\n", remote_exec_file_var
);
738 compare_pnums (const void *lhs_
, const void *rhs_
)
740 const struct packet_reg
* const *lhs
741 = (const struct packet_reg
* const *) lhs_
;
742 const struct packet_reg
* const *rhs
743 = (const struct packet_reg
* const *) rhs_
;
745 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
747 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
754 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
756 int regnum
, num_remote_regs
, offset
;
757 struct packet_reg
**remote_regs
;
759 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
761 struct packet_reg
*r
= ®s
[regnum
];
763 if (register_size (gdbarch
, regnum
) == 0)
764 /* Do not try to fetch zero-sized (placeholder) registers. */
767 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
772 /* Define the g/G packet format as the contents of each register
773 with a remote protocol number, in order of ascending protocol
776 remote_regs
= XALLOCAVEC (struct packet_reg
*, gdbarch_num_regs (gdbarch
));
777 for (num_remote_regs
= 0, regnum
= 0;
778 regnum
< gdbarch_num_regs (gdbarch
);
780 if (regs
[regnum
].pnum
!= -1)
781 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
783 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
786 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
788 remote_regs
[regnum
]->in_g_packet
= 1;
789 remote_regs
[regnum
]->offset
= offset
;
790 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
796 /* Given the architecture described by GDBARCH, return the remote
797 protocol register's number and the register's offset in the g/G
798 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
799 If the target does not have a mapping for REGNUM, return false,
800 otherwise, return true. */
803 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
804 int *pnum
, int *poffset
)
806 struct packet_reg
*regs
;
807 struct cleanup
*old_chain
;
809 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
811 regs
= XCNEWVEC (struct packet_reg
, gdbarch_num_regs (gdbarch
));
812 old_chain
= make_cleanup (xfree
, regs
);
814 map_regcache_remote_table (gdbarch
, regs
);
816 *pnum
= regs
[regnum
].pnum
;
817 *poffset
= regs
[regnum
].offset
;
819 do_cleanups (old_chain
);
825 init_remote_state (struct gdbarch
*gdbarch
)
827 struct remote_state
*rs
= get_remote_state_raw ();
828 struct remote_arch_state
*rsa
;
830 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
832 /* Use the architecture to build a regnum<->pnum table, which will be
833 1:1 unless a feature set specifies otherwise. */
834 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
835 gdbarch_num_regs (gdbarch
),
838 /* Record the maximum possible size of the g packet - it may turn out
840 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
842 /* Default maximum number of characters in a packet body. Many
843 remote stubs have a hardwired buffer size of 400 bytes
844 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
845 as the maximum packet-size to ensure that the packet and an extra
846 NUL character can always fit in the buffer. This stops GDB
847 trashing stubs that try to squeeze an extra NUL into what is
848 already a full buffer (As of 1999-12-04 that was most stubs). */
849 rsa
->remote_packet_size
= 400 - 1;
851 /* This one is filled in when a ``g'' packet is received. */
852 rsa
->actual_register_packet_size
= 0;
854 /* Should rsa->sizeof_g_packet needs more space than the
855 default, adjust the size accordingly. Remember that each byte is
856 encoded as two characters. 32 is the overhead for the packet
857 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
858 (``$NN:G...#NN'') is a better guess, the below has been padded a
860 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
861 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
863 /* Make sure that the packet buffer is plenty big enough for
864 this architecture. */
865 if (rs
->buf_size
< rsa
->remote_packet_size
)
867 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
868 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
874 /* Return the current allowed size of a remote packet. This is
875 inferred from the current architecture, and should be used to
876 limit the length of outgoing packets. */
878 get_remote_packet_size (void)
880 struct remote_state
*rs
= get_remote_state ();
881 remote_arch_state
*rsa
= get_remote_arch_state (target_gdbarch ());
883 if (rs
->explicit_packet_size
)
884 return rs
->explicit_packet_size
;
886 return rsa
->remote_packet_size
;
889 static struct packet_reg
*
890 packet_reg_from_regnum (struct gdbarch
*gdbarch
, struct remote_arch_state
*rsa
,
893 if (regnum
< 0 && regnum
>= gdbarch_num_regs (gdbarch
))
897 struct packet_reg
*r
= &rsa
->regs
[regnum
];
899 gdb_assert (r
->regnum
== regnum
);
904 static struct packet_reg
*
905 packet_reg_from_pnum (struct gdbarch
*gdbarch
, struct remote_arch_state
*rsa
,
910 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
912 struct packet_reg
*r
= &rsa
->regs
[i
];
920 static struct target_ops remote_ops
;
922 static struct target_ops extended_remote_ops
;
924 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
925 ``forever'' still use the normal timeout mechanism. This is
926 currently used by the ASYNC code to guarentee that target reads
927 during the initial connect always time-out. Once getpkt has been
928 modified to return a timeout indication and, in turn
929 remote_wait()/wait_for_inferior() have gained a timeout parameter
931 static int wait_forever_enabled_p
= 1;
933 /* Allow the user to specify what sequence to send to the remote
934 when he requests a program interruption: Although ^C is usually
935 what remote systems expect (this is the default, here), it is
936 sometimes preferable to send a break. On other systems such
937 as the Linux kernel, a break followed by g, which is Magic SysRq g
938 is required in order to interrupt the execution. */
939 const char interrupt_sequence_control_c
[] = "Ctrl-C";
940 const char interrupt_sequence_break
[] = "BREAK";
941 const char interrupt_sequence_break_g
[] = "BREAK-g";
942 static const char *const interrupt_sequence_modes
[] =
944 interrupt_sequence_control_c
,
945 interrupt_sequence_break
,
946 interrupt_sequence_break_g
,
949 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
952 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
953 struct cmd_list_element
*c
,
956 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
957 fprintf_filtered (file
,
958 _("Send the ASCII ETX character (Ctrl-c) "
959 "to the remote target to interrupt the "
960 "execution of the program.\n"));
961 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
962 fprintf_filtered (file
,
963 _("send a break signal to the remote target "
964 "to interrupt the execution of the program.\n"));
965 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
966 fprintf_filtered (file
,
967 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
968 "the remote target to interrupt the execution "
969 "of Linux kernel.\n"));
971 internal_error (__FILE__
, __LINE__
,
972 _("Invalid value for interrupt_sequence_mode: %s."),
973 interrupt_sequence_mode
);
976 /* This boolean variable specifies whether interrupt_sequence is sent
977 to the remote target when gdb connects to it.
978 This is mostly needed when you debug the Linux kernel: The Linux kernel
979 expects BREAK g which is Magic SysRq g for connecting gdb. */
980 static int interrupt_on_connect
= 0;
982 /* This variable is used to implement the "set/show remotebreak" commands.
983 Since these commands are now deprecated in favor of "set/show remote
984 interrupt-sequence", it no longer has any effect on the code. */
985 static int remote_break
;
988 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
991 interrupt_sequence_mode
= interrupt_sequence_break
;
993 interrupt_sequence_mode
= interrupt_sequence_control_c
;
997 show_remotebreak (struct ui_file
*file
, int from_tty
,
998 struct cmd_list_element
*c
,
1003 /* This variable sets the number of bits in an address that are to be
1004 sent in a memory ("M" or "m") packet. Normally, after stripping
1005 leading zeros, the entire address would be sent. This variable
1006 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
1007 initial implementation of remote.c restricted the address sent in
1008 memory packets to ``host::sizeof long'' bytes - (typically 32
1009 bits). Consequently, for 64 bit targets, the upper 32 bits of an
1010 address was never sent. Since fixing this bug may cause a break in
1011 some remote targets this variable is principly provided to
1012 facilitate backward compatibility. */
1014 static unsigned int remote_address_size
;
1016 /* Temporary to track who currently owns the terminal. See
1017 remote_terminal_* for more details. */
1019 static int remote_async_terminal_ours_p
;
1022 /* User configurable variables for the number of characters in a
1023 memory read/write packet. MIN (rsa->remote_packet_size,
1024 rsa->sizeof_g_packet) is the default. Some targets need smaller
1025 values (fifo overruns, et.al.) and some users need larger values
1026 (speed up transfers). The variables ``preferred_*'' (the user
1027 request), ``current_*'' (what was actually set) and ``forced_*''
1028 (Positive - a soft limit, negative - a hard limit). */
1030 struct memory_packet_config
1037 /* The default max memory-write-packet-size. The 16k is historical.
1038 (It came from older GDB's using alloca for buffers and the
1039 knowledge (folklore?) that some hosts don't cope very well with
1040 large alloca calls.) */
1041 #define DEFAULT_MAX_MEMORY_PACKET_SIZE 16384
1043 /* The minimum remote packet size for memory transfers. Ensures we
1044 can write at least one byte. */
1045 #define MIN_MEMORY_PACKET_SIZE 20
1047 /* Compute the current size of a read/write packet. Since this makes
1048 use of ``actual_register_packet_size'' the computation is dynamic. */
1051 get_memory_packet_size (struct memory_packet_config
*config
)
1053 struct remote_state
*rs
= get_remote_state ();
1054 remote_arch_state
*rsa
= get_remote_arch_state (target_gdbarch ());
1057 if (config
->fixed_p
)
1059 if (config
->size
<= 0)
1060 what_they_get
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1062 what_they_get
= config
->size
;
1066 what_they_get
= get_remote_packet_size ();
1067 /* Limit the packet to the size specified by the user. */
1068 if (config
->size
> 0
1069 && what_they_get
> config
->size
)
1070 what_they_get
= config
->size
;
1072 /* Limit it to the size of the targets ``g'' response unless we have
1073 permission from the stub to use a larger packet size. */
1074 if (rs
->explicit_packet_size
== 0
1075 && rsa
->actual_register_packet_size
> 0
1076 && what_they_get
> rsa
->actual_register_packet_size
)
1077 what_they_get
= rsa
->actual_register_packet_size
;
1079 if (what_they_get
< MIN_MEMORY_PACKET_SIZE
)
1080 what_they_get
= MIN_MEMORY_PACKET_SIZE
;
1082 /* Make sure there is room in the global buffer for this packet
1083 (including its trailing NUL byte). */
1084 if (rs
->buf_size
< what_they_get
+ 1)
1086 rs
->buf_size
= 2 * what_they_get
;
1087 rs
->buf
= (char *) xrealloc (rs
->buf
, 2 * what_they_get
);
1090 return what_they_get
;
1093 /* Update the size of a read/write packet. If they user wants
1094 something really big then do a sanity check. */
1097 set_memory_packet_size (const char *args
, struct memory_packet_config
*config
)
1099 int fixed_p
= config
->fixed_p
;
1100 long size
= config
->size
;
1103 error (_("Argument required (integer, `fixed' or `limited')."));
1104 else if (strcmp (args
, "hard") == 0
1105 || strcmp (args
, "fixed") == 0)
1107 else if (strcmp (args
, "soft") == 0
1108 || strcmp (args
, "limit") == 0)
1114 size
= strtoul (args
, &end
, 0);
1116 error (_("Invalid %s (bad syntax)."), config
->name
);
1118 /* Instead of explicitly capping the size of a packet to or
1119 disallowing it, the user is allowed to set the size to
1120 something arbitrarily large. */
1123 /* So that the query shows the correct value. */
1125 size
= DEFAULT_MAX_MEMORY_PACKET_SIZE
;
1128 if (fixed_p
&& !config
->fixed_p
)
1130 if (! query (_("The target may not be able to correctly handle a %s\n"
1131 "of %ld bytes. Change the packet size? "),
1132 config
->name
, size
))
1133 error (_("Packet size not changed."));
1135 /* Update the config. */
1136 config
->fixed_p
= fixed_p
;
1137 config
->size
= size
;
1141 show_memory_packet_size (struct memory_packet_config
*config
)
1143 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
1144 if (config
->fixed_p
)
1145 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
1146 get_memory_packet_size (config
));
1148 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1149 get_memory_packet_size (config
));
1152 static struct memory_packet_config memory_write_packet_config
=
1154 "memory-write-packet-size",
1158 set_memory_write_packet_size (const char *args
, int from_tty
)
1160 set_memory_packet_size (args
, &memory_write_packet_config
);
1164 show_memory_write_packet_size (const char *args
, int from_tty
)
1166 show_memory_packet_size (&memory_write_packet_config
);
1170 get_memory_write_packet_size (void)
1172 return get_memory_packet_size (&memory_write_packet_config
);
1175 static struct memory_packet_config memory_read_packet_config
=
1177 "memory-read-packet-size",
1181 set_memory_read_packet_size (const char *args
, int from_tty
)
1183 set_memory_packet_size (args
, &memory_read_packet_config
);
1187 show_memory_read_packet_size (const char *args
, int from_tty
)
1189 show_memory_packet_size (&memory_read_packet_config
);
1193 get_memory_read_packet_size (void)
1195 long size
= get_memory_packet_size (&memory_read_packet_config
);
1197 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1198 extra buffer size argument before the memory read size can be
1199 increased beyond this. */
1200 if (size
> get_remote_packet_size ())
1201 size
= get_remote_packet_size ();
1206 /* Generic configuration support for packets the stub optionally
1207 supports. Allows the user to specify the use of the packet as well
1208 as allowing GDB to auto-detect support in the remote stub. */
1212 PACKET_SUPPORT_UNKNOWN
= 0,
1217 struct packet_config
1222 /* If auto, GDB auto-detects support for this packet or feature,
1223 either through qSupported, or by trying the packet and looking
1224 at the response. If true, GDB assumes the target supports this
1225 packet. If false, the packet is disabled. Configs that don't
1226 have an associated command always have this set to auto. */
1227 enum auto_boolean detect
;
1229 /* Does the target support this packet? */
1230 enum packet_support support
;
1233 /* Analyze a packet's return value and update the packet config
1243 static enum packet_support
packet_config_support (struct packet_config
*config
);
1244 static enum packet_support
packet_support (int packet
);
1247 show_packet_config_cmd (struct packet_config
*config
)
1249 const char *support
= "internal-error";
1251 switch (packet_config_support (config
))
1254 support
= "enabled";
1256 case PACKET_DISABLE
:
1257 support
= "disabled";
1259 case PACKET_SUPPORT_UNKNOWN
:
1260 support
= "unknown";
1263 switch (config
->detect
)
1265 case AUTO_BOOLEAN_AUTO
:
1266 printf_filtered (_("Support for the `%s' packet "
1267 "is auto-detected, currently %s.\n"),
1268 config
->name
, support
);
1270 case AUTO_BOOLEAN_TRUE
:
1271 case AUTO_BOOLEAN_FALSE
:
1272 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1273 config
->name
, support
);
1279 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1280 const char *title
, int legacy
)
1286 config
->name
= name
;
1287 config
->title
= title
;
1288 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1290 show_doc
= xstrprintf ("Show current use of remote "
1291 "protocol `%s' (%s) packet",
1293 /* set/show TITLE-packet {auto,on,off} */
1294 cmd_name
= xstrprintf ("%s-packet", title
);
1295 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1296 &config
->detect
, set_doc
,
1297 show_doc
, NULL
, /* help_doc */
1299 show_remote_protocol_packet_cmd
,
1300 &remote_set_cmdlist
, &remote_show_cmdlist
);
1301 /* The command code copies the documentation strings. */
1304 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1309 legacy_name
= xstrprintf ("%s-packet", name
);
1310 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1311 &remote_set_cmdlist
);
1312 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1313 &remote_show_cmdlist
);
1317 static enum packet_result
1318 packet_check_result (const char *buf
)
1322 /* The stub recognized the packet request. Check that the
1323 operation succeeded. */
1325 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1327 /* "Enn" - definitly an error. */
1328 return PACKET_ERROR
;
1330 /* Always treat "E." as an error. This will be used for
1331 more verbose error messages, such as E.memtypes. */
1332 if (buf
[0] == 'E' && buf
[1] == '.')
1333 return PACKET_ERROR
;
1335 /* The packet may or may not be OK. Just assume it is. */
1339 /* The stub does not support the packet. */
1340 return PACKET_UNKNOWN
;
1343 static enum packet_result
1344 packet_ok (const char *buf
, struct packet_config
*config
)
1346 enum packet_result result
;
1348 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1349 && config
->support
== PACKET_DISABLE
)
1350 internal_error (__FILE__
, __LINE__
,
1351 _("packet_ok: attempt to use a disabled packet"));
1353 result
= packet_check_result (buf
);
1358 /* The stub recognized the packet request. */
1359 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1362 fprintf_unfiltered (gdb_stdlog
,
1363 "Packet %s (%s) is supported\n",
1364 config
->name
, config
->title
);
1365 config
->support
= PACKET_ENABLE
;
1368 case PACKET_UNKNOWN
:
1369 /* The stub does not support the packet. */
1370 if (config
->detect
== AUTO_BOOLEAN_AUTO
1371 && config
->support
== PACKET_ENABLE
)
1373 /* If the stub previously indicated that the packet was
1374 supported then there is a protocol error. */
1375 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1376 config
->name
, config
->title
);
1378 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1380 /* The user set it wrong. */
1381 error (_("Enabled packet %s (%s) not recognized by stub"),
1382 config
->name
, config
->title
);
1386 fprintf_unfiltered (gdb_stdlog
,
1387 "Packet %s (%s) is NOT supported\n",
1388 config
->name
, config
->title
);
1389 config
->support
= PACKET_DISABLE
;
1410 PACKET_vFile_pwrite
,
1412 PACKET_vFile_unlink
,
1413 PACKET_vFile_readlink
,
1416 PACKET_qXfer_features
,
1417 PACKET_qXfer_exec_file
,
1418 PACKET_qXfer_libraries
,
1419 PACKET_qXfer_libraries_svr4
,
1420 PACKET_qXfer_memory_map
,
1421 PACKET_qXfer_spu_read
,
1422 PACKET_qXfer_spu_write
,
1423 PACKET_qXfer_osdata
,
1424 PACKET_qXfer_threads
,
1425 PACKET_qXfer_statictrace_read
,
1426 PACKET_qXfer_traceframe_info
,
1432 PACKET_QPassSignals
,
1433 PACKET_QCatchSyscalls
,
1434 PACKET_QProgramSignals
,
1435 PACKET_QSetWorkingDir
,
1436 PACKET_QStartupWithShell
,
1437 PACKET_QEnvironmentHexEncoded
,
1438 PACKET_QEnvironmentReset
,
1439 PACKET_QEnvironmentUnset
,
1441 PACKET_qSearch_memory
,
1444 PACKET_QStartNoAckMode
,
1446 PACKET_qXfer_siginfo_read
,
1447 PACKET_qXfer_siginfo_write
,
1450 /* Support for conditional tracepoints. */
1451 PACKET_ConditionalTracepoints
,
1453 /* Support for target-side breakpoint conditions. */
1454 PACKET_ConditionalBreakpoints
,
1456 /* Support for target-side breakpoint commands. */
1457 PACKET_BreakpointCommands
,
1459 /* Support for fast tracepoints. */
1460 PACKET_FastTracepoints
,
1462 /* Support for static tracepoints. */
1463 PACKET_StaticTracepoints
,
1465 /* Support for installing tracepoints while a trace experiment is
1467 PACKET_InstallInTrace
,
1471 PACKET_TracepointSource
,
1474 PACKET_QDisableRandomization
,
1476 PACKET_QTBuffer_size
,
1480 PACKET_qXfer_btrace
,
1482 /* Support for the QNonStop packet. */
1485 /* Support for the QThreadEvents packet. */
1486 PACKET_QThreadEvents
,
1488 /* Support for multi-process extensions. */
1489 PACKET_multiprocess_feature
,
1491 /* Support for enabling and disabling tracepoints while a trace
1492 experiment is running. */
1493 PACKET_EnableDisableTracepoints_feature
,
1495 /* Support for collecting strings using the tracenz bytecode. */
1496 PACKET_tracenz_feature
,
1498 /* Support for continuing to run a trace experiment while GDB is
1500 PACKET_DisconnectedTracing_feature
,
1502 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1503 PACKET_augmented_libraries_svr4_read_feature
,
1505 /* Support for the qXfer:btrace-conf:read packet. */
1506 PACKET_qXfer_btrace_conf
,
1508 /* Support for the Qbtrace-conf:bts:size packet. */
1509 PACKET_Qbtrace_conf_bts_size
,
1511 /* Support for swbreak+ feature. */
1512 PACKET_swbreak_feature
,
1514 /* Support for hwbreak+ feature. */
1515 PACKET_hwbreak_feature
,
1517 /* Support for fork events. */
1518 PACKET_fork_event_feature
,
1520 /* Support for vfork events. */
1521 PACKET_vfork_event_feature
,
1523 /* Support for the Qbtrace-conf:pt:size packet. */
1524 PACKET_Qbtrace_conf_pt_size
,
1526 /* Support for exec events. */
1527 PACKET_exec_event_feature
,
1529 /* Support for query supported vCont actions. */
1530 PACKET_vContSupported
,
1532 /* Support remote CTRL-C. */
1535 /* Support TARGET_WAITKIND_NO_RESUMED. */
1541 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1543 /* Returns the packet's corresponding "set remote foo-packet" command
1544 state. See struct packet_config for more details. */
1546 static enum auto_boolean
1547 packet_set_cmd_state (int packet
)
1549 return remote_protocol_packets
[packet
].detect
;
1552 /* Returns whether a given packet or feature is supported. This takes
1553 into account the state of the corresponding "set remote foo-packet"
1554 command, which may be used to bypass auto-detection. */
1556 static enum packet_support
1557 packet_config_support (struct packet_config
*config
)
1559 switch (config
->detect
)
1561 case AUTO_BOOLEAN_TRUE
:
1562 return PACKET_ENABLE
;
1563 case AUTO_BOOLEAN_FALSE
:
1564 return PACKET_DISABLE
;
1565 case AUTO_BOOLEAN_AUTO
:
1566 return config
->support
;
1568 gdb_assert_not_reached (_("bad switch"));
1572 /* Same as packet_config_support, but takes the packet's enum value as
1575 static enum packet_support
1576 packet_support (int packet
)
1578 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1580 return packet_config_support (config
);
1584 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1585 struct cmd_list_element
*c
,
1588 struct packet_config
*packet
;
1590 for (packet
= remote_protocol_packets
;
1591 packet
< &remote_protocol_packets
[PACKET_MAX
];
1594 if (&packet
->detect
== c
->var
)
1596 show_packet_config_cmd (packet
);
1600 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1604 /* Should we try one of the 'Z' requests? */
1608 Z_PACKET_SOFTWARE_BP
,
1609 Z_PACKET_HARDWARE_BP
,
1616 /* For compatibility with older distributions. Provide a ``set remote
1617 Z-packet ...'' command that updates all the Z packet types. */
1619 static enum auto_boolean remote_Z_packet_detect
;
1622 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1623 struct cmd_list_element
*c
)
1627 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1628 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1632 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1633 struct cmd_list_element
*c
,
1638 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1640 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1644 /* Returns true if the multi-process extensions are in effect. */
1647 remote_multi_process_p (struct remote_state
*rs
)
1649 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1652 /* Returns true if fork events are supported. */
1655 remote_fork_event_p (struct remote_state
*rs
)
1657 return packet_support (PACKET_fork_event_feature
) == PACKET_ENABLE
;
1660 /* Returns true if vfork events are supported. */
1663 remote_vfork_event_p (struct remote_state
*rs
)
1665 return packet_support (PACKET_vfork_event_feature
) == PACKET_ENABLE
;
1668 /* Returns true if exec events are supported. */
1671 remote_exec_event_p (struct remote_state
*rs
)
1673 return packet_support (PACKET_exec_event_feature
) == PACKET_ENABLE
;
1676 /* Insert fork catchpoint target routine. If fork events are enabled
1677 then return success, nothing more to do. */
1680 remote_insert_fork_catchpoint (struct target_ops
*ops
, int pid
)
1682 struct remote_state
*rs
= get_remote_state ();
1684 return !remote_fork_event_p (rs
);
1687 /* Remove fork catchpoint target routine. Nothing to do, just
1691 remote_remove_fork_catchpoint (struct target_ops
*ops
, int pid
)
1696 /* Insert vfork catchpoint target routine. If vfork events are enabled
1697 then return success, nothing more to do. */
1700 remote_insert_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1702 struct remote_state
*rs
= get_remote_state ();
1704 return !remote_vfork_event_p (rs
);
1707 /* Remove vfork catchpoint target routine. Nothing to do, just
1711 remote_remove_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1716 /* Insert exec catchpoint target routine. If exec events are
1717 enabled, just return success. */
1720 remote_insert_exec_catchpoint (struct target_ops
*ops
, int pid
)
1722 struct remote_state
*rs
= get_remote_state ();
1724 return !remote_exec_event_p (rs
);
1727 /* Remove exec catchpoint target routine. Nothing to do, just
1731 remote_remove_exec_catchpoint (struct target_ops
*ops
, int pid
)
1737 /* Asynchronous signal handle registered as event loop source for
1738 when we have pending events ready to be passed to the core. */
1740 static struct async_event_handler
*remote_async_inferior_event_token
;
1744 static ptid_t magic_null_ptid
;
1745 static ptid_t not_sent_ptid
;
1746 static ptid_t any_thread_ptid
;
1748 /* Find out if the stub attached to PID (and hence GDB should offer to
1749 detach instead of killing it when bailing out). */
1752 remote_query_attached (int pid
)
1754 struct remote_state
*rs
= get_remote_state ();
1755 size_t size
= get_remote_packet_size ();
1757 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1760 if (remote_multi_process_p (rs
))
1761 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1763 xsnprintf (rs
->buf
, size
, "qAttached");
1766 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1768 switch (packet_ok (rs
->buf
,
1769 &remote_protocol_packets
[PACKET_qAttached
]))
1772 if (strcmp (rs
->buf
, "1") == 0)
1776 warning (_("Remote failure reply: %s"), rs
->buf
);
1778 case PACKET_UNKNOWN
:
1785 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1786 has been invented by GDB, instead of reported by the target. Since
1787 we can be connected to a remote system before before knowing about
1788 any inferior, mark the target with execution when we find the first
1789 inferior. If ATTACHED is 1, then we had just attached to this
1790 inferior. If it is 0, then we just created this inferior. If it
1791 is -1, then try querying the remote stub to find out if it had
1792 attached to the inferior or not. If TRY_OPEN_EXEC is true then
1793 attempt to open this inferior's executable as the main executable
1794 if no main executable is open already. */
1796 static struct inferior
*
1797 remote_add_inferior (int fake_pid_p
, int pid
, int attached
,
1800 struct inferior
*inf
;
1802 /* Check whether this process we're learning about is to be
1803 considered attached, or if is to be considered to have been
1804 spawned by the stub. */
1806 attached
= remote_query_attached (pid
);
1808 if (gdbarch_has_global_solist (target_gdbarch ()))
1810 /* If the target shares code across all inferiors, then every
1811 attach adds a new inferior. */
1812 inf
= add_inferior (pid
);
1814 /* ... and every inferior is bound to the same program space.
1815 However, each inferior may still have its own address
1817 inf
->aspace
= maybe_new_address_space ();
1818 inf
->pspace
= current_program_space
;
1822 /* In the traditional debugging scenario, there's a 1-1 match
1823 between program/address spaces. We simply bind the inferior
1824 to the program space's address space. */
1825 inf
= current_inferior ();
1826 inferior_appeared (inf
, pid
);
1829 inf
->attach_flag
= attached
;
1830 inf
->fake_pid_p
= fake_pid_p
;
1832 /* If no main executable is currently open then attempt to
1833 open the file that was executed to create this inferior. */
1834 if (try_open_exec
&& get_exec_file (0) == NULL
)
1835 exec_file_locate_attach (pid
, 0, 1);
1840 static struct private_thread_info
*
1841 get_private_info_thread (struct thread_info
*info
);
1843 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1844 according to RUNNING. */
1847 remote_add_thread (ptid_t ptid
, int running
, int executing
)
1849 struct remote_state
*rs
= get_remote_state ();
1850 struct thread_info
*thread
;
1852 /* GDB historically didn't pull threads in the initial connection
1853 setup. If the remote target doesn't even have a concept of
1854 threads (e.g., a bare-metal target), even if internally we
1855 consider that a single-threaded target, mentioning a new thread
1856 might be confusing to the user. Be silent then, preserving the
1857 age old behavior. */
1858 if (rs
->starting_up
)
1859 thread
= add_thread_silent (ptid
);
1861 thread
= add_thread (ptid
);
1863 get_private_info_thread (thread
)->vcont_resumed
= executing
;
1864 set_executing (ptid
, executing
);
1865 set_running (ptid
, running
);
1868 /* Come here when we learn about a thread id from the remote target.
1869 It may be the first time we hear about such thread, so take the
1870 opportunity to add it to GDB's thread list. In case this is the
1871 first time we're noticing its corresponding inferior, add it to
1872 GDB's inferior list as well. EXECUTING indicates whether the
1873 thread is (internally) executing or stopped. */
1876 remote_notice_new_inferior (ptid_t currthread
, int executing
)
1878 /* In non-stop mode, we assume new found threads are (externally)
1879 running until proven otherwise with a stop reply. In all-stop,
1880 we can only get here if all threads are stopped. */
1881 int running
= target_is_non_stop_p () ? 1 : 0;
1883 /* If this is a new thread, add it to GDB's thread list.
1884 If we leave it up to WFI to do this, bad things will happen. */
1886 if (in_thread_list (currthread
) && is_exited (currthread
))
1888 /* We're seeing an event on a thread id we knew had exited.
1889 This has to be a new thread reusing the old id. Add it. */
1890 remote_add_thread (currthread
, running
, executing
);
1894 if (!in_thread_list (currthread
))
1896 struct inferior
*inf
= NULL
;
1897 int pid
= ptid_get_pid (currthread
);
1899 if (ptid_is_pid (inferior_ptid
)
1900 && pid
== ptid_get_pid (inferior_ptid
))
1902 /* inferior_ptid has no thread member yet. This can happen
1903 with the vAttach -> remote_wait,"TAAthread:" path if the
1904 stub doesn't support qC. This is the first stop reported
1905 after an attach, so this is the main thread. Update the
1906 ptid in the thread list. */
1907 if (in_thread_list (pid_to_ptid (pid
)))
1908 thread_change_ptid (inferior_ptid
, currthread
);
1911 remote_add_thread (currthread
, running
, executing
);
1912 inferior_ptid
= currthread
;
1917 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1919 /* inferior_ptid is not set yet. This can happen with the
1920 vRun -> remote_wait,"TAAthread:" path if the stub
1921 doesn't support qC. This is the first stop reported
1922 after an attach, so this is the main thread. Update the
1923 ptid in the thread list. */
1924 thread_change_ptid (inferior_ptid
, currthread
);
1928 /* When connecting to a target remote, or to a target
1929 extended-remote which already was debugging an inferior, we
1930 may not know about it yet. Add it before adding its child
1931 thread, so notifications are emitted in a sensible order. */
1932 if (!in_inferior_list (ptid_get_pid (currthread
)))
1934 struct remote_state
*rs
= get_remote_state ();
1935 int fake_pid_p
= !remote_multi_process_p (rs
);
1937 inf
= remote_add_inferior (fake_pid_p
,
1938 ptid_get_pid (currthread
), -1, 1);
1941 /* This is really a new thread. Add it. */
1942 remote_add_thread (currthread
, running
, executing
);
1944 /* If we found a new inferior, let the common code do whatever
1945 it needs to with it (e.g., read shared libraries, insert
1946 breakpoints), unless we're just setting up an all-stop
1950 struct remote_state
*rs
= get_remote_state ();
1952 if (!rs
->starting_up
)
1953 notice_new_inferior (currthread
, executing
, 0);
1958 /* Return THREAD's private thread data, creating it if necessary. */
1960 static struct private_thread_info
*
1961 get_private_info_thread (struct thread_info
*thread
)
1963 gdb_assert (thread
!= NULL
);
1965 if (thread
->priv
== NULL
)
1967 struct private_thread_info
*priv
= XNEW (struct private_thread_info
);
1969 thread
->private_dtor
= free_private_thread_info
;
1970 thread
->priv
= priv
;
1976 priv
->last_resume_step
= 0;
1977 priv
->last_resume_sig
= GDB_SIGNAL_0
;
1978 priv
->vcont_resumed
= 0;
1979 priv
->thread_handle
= nullptr;
1982 return thread
->priv
;
1985 /* Return PTID's private thread data, creating it if necessary. */
1987 static struct private_thread_info
*
1988 get_private_info_ptid (ptid_t ptid
)
1990 struct thread_info
*info
= find_thread_ptid (ptid
);
1992 return get_private_info_thread (info
);
1995 /* Call this function as a result of
1996 1) A halt indication (T packet) containing a thread id
1997 2) A direct query of currthread
1998 3) Successful execution of set thread */
2001 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
2003 rs
->general_thread
= currthread
;
2006 /* If 'QPassSignals' is supported, tell the remote stub what signals
2007 it can simply pass through to the inferior without reporting. */
2010 remote_pass_signals (struct target_ops
*self
,
2011 int numsigs
, unsigned char *pass_signals
)
2013 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
2015 char *pass_packet
, *p
;
2017 struct remote_state
*rs
= get_remote_state ();
2019 gdb_assert (numsigs
< 256);
2020 for (i
= 0; i
< numsigs
; i
++)
2022 if (pass_signals
[i
])
2025 pass_packet
= (char *) xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
2026 strcpy (pass_packet
, "QPassSignals:");
2027 p
= pass_packet
+ strlen (pass_packet
);
2028 for (i
= 0; i
< numsigs
; i
++)
2030 if (pass_signals
[i
])
2033 *p
++ = tohex (i
>> 4);
2034 *p
++ = tohex (i
& 15);
2043 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
2045 putpkt (pass_packet
);
2046 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2047 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
2048 if (rs
->last_pass_packet
)
2049 xfree (rs
->last_pass_packet
);
2050 rs
->last_pass_packet
= pass_packet
;
2053 xfree (pass_packet
);
2057 /* If 'QCatchSyscalls' is supported, tell the remote stub
2058 to report syscalls to GDB. */
2061 remote_set_syscall_catchpoint (struct target_ops
*self
,
2062 int pid
, int needed
, int any_count
,
2063 int table_size
, int *table
)
2066 enum packet_result result
;
2069 if (packet_support (PACKET_QCatchSyscalls
) == PACKET_DISABLE
)
2071 /* Not supported. */
2075 if (needed
&& !any_count
)
2079 /* Count how many syscalls are to be caught (table[sysno] != 0). */
2080 for (i
= 0; i
< table_size
; i
++)
2089 fprintf_unfiltered (gdb_stdlog
,
2090 "remote_set_syscall_catchpoint "
2091 "pid %d needed %d any_count %d n_sysno %d\n",
2092 pid
, needed
, any_count
, n_sysno
);
2097 /* Prepare a packet with the sysno list, assuming max 8+1
2098 characters for a sysno. If the resulting packet size is too
2099 big, fallback on the non-selective packet. */
2100 const int maxpktsz
= strlen ("QCatchSyscalls:1") + n_sysno
* 9 + 1;
2102 catch_packet
= (char *) xmalloc (maxpktsz
);
2103 strcpy (catch_packet
, "QCatchSyscalls:1");
2112 /* Add in catch_packet each syscall to be caught (table[i] != 0). */
2113 for (i
= 0; i
< table_size
; i
++)
2116 p
+= xsnprintf (p
, catch_packet
+ maxpktsz
- p
, ";%x", i
);
2119 if (strlen (catch_packet
) > get_remote_packet_size ())
2121 /* catch_packet too big. Fallback to less efficient
2122 non selective mode, with GDB doing the filtering. */
2123 catch_packet
[sizeof ("QCatchSyscalls:1") - 1] = 0;
2127 catch_packet
= xstrdup ("QCatchSyscalls:0");
2130 struct cleanup
*old_chain
= make_cleanup (xfree
, catch_packet
);
2131 struct remote_state
*rs
= get_remote_state ();
2133 putpkt (catch_packet
);
2134 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2135 result
= packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QCatchSyscalls
]);
2136 do_cleanups (old_chain
);
2137 if (result
== PACKET_OK
)
2144 /* If 'QProgramSignals' is supported, tell the remote stub what
2145 signals it should pass through to the inferior when detaching. */
2148 remote_program_signals (struct target_ops
*self
,
2149 int numsigs
, unsigned char *signals
)
2151 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
2155 struct remote_state
*rs
= get_remote_state ();
2157 gdb_assert (numsigs
< 256);
2158 for (i
= 0; i
< numsigs
; i
++)
2163 packet
= (char *) xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
2164 strcpy (packet
, "QProgramSignals:");
2165 p
= packet
+ strlen (packet
);
2166 for (i
= 0; i
< numsigs
; i
++)
2168 if (signal_pass_state (i
))
2171 *p
++ = tohex (i
>> 4);
2172 *p
++ = tohex (i
& 15);
2181 if (!rs
->last_program_signals_packet
2182 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
2185 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2186 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
2187 xfree (rs
->last_program_signals_packet
);
2188 rs
->last_program_signals_packet
= packet
;
2195 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
2196 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
2197 thread. If GEN is set, set the general thread, if not, then set
2198 the step/continue thread. */
2200 set_thread (ptid_t ptid
, int gen
)
2202 struct remote_state
*rs
= get_remote_state ();
2203 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
2204 char *buf
= rs
->buf
;
2205 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
2207 if (ptid_equal (state
, ptid
))
2211 *buf
++ = gen
? 'g' : 'c';
2212 if (ptid_equal (ptid
, magic_null_ptid
))
2213 xsnprintf (buf
, endbuf
- buf
, "0");
2214 else if (ptid_equal (ptid
, any_thread_ptid
))
2215 xsnprintf (buf
, endbuf
- buf
, "0");
2216 else if (ptid_equal (ptid
, minus_one_ptid
))
2217 xsnprintf (buf
, endbuf
- buf
, "-1");
2219 write_ptid (buf
, endbuf
, ptid
);
2221 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2223 rs
->general_thread
= ptid
;
2225 rs
->continue_thread
= ptid
;
2229 set_general_thread (ptid_t ptid
)
2231 set_thread (ptid
, 1);
2235 set_continue_thread (ptid_t ptid
)
2237 set_thread (ptid
, 0);
2240 /* Change the remote current process. Which thread within the process
2241 ends up selected isn't important, as long as it is the same process
2242 as what INFERIOR_PTID points to.
2244 This comes from that fact that there is no explicit notion of
2245 "selected process" in the protocol. The selected process for
2246 general operations is the process the selected general thread
2250 set_general_process (void)
2252 struct remote_state
*rs
= get_remote_state ();
2254 /* If the remote can't handle multiple processes, don't bother. */
2255 if (!remote_multi_process_p (rs
))
2258 /* We only need to change the remote current thread if it's pointing
2259 at some other process. */
2260 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
2261 set_general_thread (inferior_ptid
);
2265 /* Return nonzero if this is the main thread that we made up ourselves
2266 to model non-threaded targets as single-threaded. */
2269 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
2271 if (ptid_equal (ptid
, magic_null_ptid
))
2272 /* The main thread is always alive. */
2275 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
2276 /* The main thread is always alive. This can happen after a
2277 vAttach, if the remote side doesn't support
2284 /* Return nonzero if the thread PTID is still alive on the remote
2288 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
2290 struct remote_state
*rs
= get_remote_state ();
2293 /* Check if this is a thread that we made up ourselves to model
2294 non-threaded targets as single-threaded. */
2295 if (remote_thread_always_alive (ops
, ptid
))
2299 endp
= rs
->buf
+ get_remote_packet_size ();
2302 write_ptid (p
, endp
, ptid
);
2305 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2306 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
2309 /* Return a pointer to a thread name if we know it and NULL otherwise.
2310 The thread_info object owns the memory for the name. */
2313 remote_thread_name (struct target_ops
*ops
, struct thread_info
*info
)
2315 if (info
->priv
!= NULL
)
2316 return info
->priv
->name
;
2321 /* About these extended threadlist and threadinfo packets. They are
2322 variable length packets but, the fields within them are often fixed
2323 length. They are redundent enough to send over UDP as is the
2324 remote protocol in general. There is a matching unit test module
2327 /* WARNING: This threadref data structure comes from the remote O.S.,
2328 libstub protocol encoding, and remote.c. It is not particularly
2331 /* Right now, the internal structure is int. We want it to be bigger.
2332 Plan to fix this. */
2334 typedef int gdb_threadref
; /* Internal GDB thread reference. */
2336 /* gdb_ext_thread_info is an internal GDB data structure which is
2337 equivalent to the reply of the remote threadinfo packet. */
2339 struct gdb_ext_thread_info
2341 threadref threadid
; /* External form of thread reference. */
2342 int active
; /* Has state interesting to GDB?
2344 char display
[256]; /* Brief state display, name,
2345 blocked/suspended. */
2346 char shortname
[32]; /* To be used to name threads. */
2347 char more_display
[256]; /* Long info, statistics, queue depth,
2351 /* The volume of remote transfers can be limited by submitting
2352 a mask containing bits specifying the desired information.
2353 Use a union of these values as the 'selection' parameter to
2354 get_thread_info. FIXME: Make these TAG names more thread specific. */
2356 #define TAG_THREADID 1
2357 #define TAG_EXISTS 2
2358 #define TAG_DISPLAY 4
2359 #define TAG_THREADNAME 8
2360 #define TAG_MOREDISPLAY 16
2362 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2364 static char *unpack_nibble (char *buf
, int *val
);
2366 static char *unpack_byte (char *buf
, int *value
);
2368 static char *pack_int (char *buf
, int value
);
2370 static char *unpack_int (char *buf
, int *value
);
2372 static char *unpack_string (char *src
, char *dest
, int length
);
2374 static char *pack_threadid (char *pkt
, threadref
*id
);
2376 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2378 void int_to_threadref (threadref
*id
, int value
);
2380 static int threadref_to_int (threadref
*ref
);
2382 static void copy_threadref (threadref
*dest
, threadref
*src
);
2384 static int threadmatch (threadref
*dest
, threadref
*src
);
2386 static char *pack_threadinfo_request (char *pkt
, int mode
,
2389 static int remote_unpack_thread_info_response (char *pkt
,
2390 threadref
*expectedref
,
2391 struct gdb_ext_thread_info
2395 static int remote_get_threadinfo (threadref
*threadid
,
2396 int fieldset
, /*TAG mask */
2397 struct gdb_ext_thread_info
*info
);
2399 static char *pack_threadlist_request (char *pkt
, int startflag
,
2401 threadref
*nextthread
);
2403 static int parse_threadlist_response (char *pkt
,
2405 threadref
*original_echo
,
2406 threadref
*resultlist
,
2409 static int remote_get_threadlist (int startflag
,
2410 threadref
*nextthread
,
2414 threadref
*threadlist
);
2416 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2418 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2419 void *context
, int looplimit
);
2421 static int remote_newthread_step (threadref
*ref
, void *context
);
2424 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2425 buffer we're allowed to write to. Returns
2426 BUF+CHARACTERS_WRITTEN. */
2429 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2432 struct remote_state
*rs
= get_remote_state ();
2434 if (remote_multi_process_p (rs
))
2436 pid
= ptid_get_pid (ptid
);
2438 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2440 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2442 tid
= ptid_get_lwp (ptid
);
2444 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2446 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2451 /* Extract a PTID from BUF. If non-null, OBUF is set to one past the
2452 last parsed char. Returns null_ptid if no thread id is found, and
2453 throws an error if the thread id has an invalid format. */
2456 read_ptid (const char *buf
, const char **obuf
)
2458 const char *p
= buf
;
2460 ULONGEST pid
= 0, tid
= 0;
2464 /* Multi-process ptid. */
2465 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2467 error (_("invalid remote ptid: %s"), p
);
2470 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2473 return ptid_build (pid
, tid
, 0);
2476 /* No multi-process. Just a tid. */
2477 pp
= unpack_varlen_hex (p
, &tid
);
2479 /* Return null_ptid when no thread id is found. */
2487 /* Since the stub is not sending a process id, then default to
2488 what's in inferior_ptid, unless it's null at this point. If so,
2489 then since there's no way to know the pid of the reported
2490 threads, use the magic number. */
2491 if (ptid_equal (inferior_ptid
, null_ptid
))
2492 pid
= ptid_get_pid (magic_null_ptid
);
2494 pid
= ptid_get_pid (inferior_ptid
);
2498 return ptid_build (pid
, tid
, 0);
2504 if (ch
>= 'a' && ch
<= 'f')
2505 return ch
- 'a' + 10;
2506 if (ch
>= '0' && ch
<= '9')
2508 if (ch
>= 'A' && ch
<= 'F')
2509 return ch
- 'A' + 10;
2514 stub_unpack_int (char *buff
, int fieldlength
)
2521 nibble
= stubhex (*buff
++);
2525 retval
= retval
<< 4;
2531 unpack_nibble (char *buf
, int *val
)
2533 *val
= fromhex (*buf
++);
2538 unpack_byte (char *buf
, int *value
)
2540 *value
= stub_unpack_int (buf
, 2);
2545 pack_int (char *buf
, int value
)
2547 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2548 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2549 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2550 buf
= pack_hex_byte (buf
, (value
& 0xff));
2555 unpack_int (char *buf
, int *value
)
2557 *value
= stub_unpack_int (buf
, 8);
2561 #if 0 /* Currently unused, uncomment when needed. */
2562 static char *pack_string (char *pkt
, char *string
);
2565 pack_string (char *pkt
, char *string
)
2570 len
= strlen (string
);
2572 len
= 200; /* Bigger than most GDB packets, junk??? */
2573 pkt
= pack_hex_byte (pkt
, len
);
2577 if ((ch
== '\0') || (ch
== '#'))
2578 ch
= '*'; /* Protect encapsulation. */
2583 #endif /* 0 (unused) */
2586 unpack_string (char *src
, char *dest
, int length
)
2595 pack_threadid (char *pkt
, threadref
*id
)
2598 unsigned char *altid
;
2600 altid
= (unsigned char *) id
;
2601 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2603 pkt
= pack_hex_byte (pkt
, *altid
++);
2609 unpack_threadid (char *inbuf
, threadref
*id
)
2612 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2615 altref
= (char *) id
;
2617 while (inbuf
< limit
)
2619 x
= stubhex (*inbuf
++);
2620 y
= stubhex (*inbuf
++);
2621 *altref
++ = (x
<< 4) | y
;
2626 /* Externally, threadrefs are 64 bits but internally, they are still
2627 ints. This is due to a mismatch of specifications. We would like
2628 to use 64bit thread references internally. This is an adapter
2632 int_to_threadref (threadref
*id
, int value
)
2634 unsigned char *scan
;
2636 scan
= (unsigned char *) id
;
2642 *scan
++ = (value
>> 24) & 0xff;
2643 *scan
++ = (value
>> 16) & 0xff;
2644 *scan
++ = (value
>> 8) & 0xff;
2645 *scan
++ = (value
& 0xff);
2649 threadref_to_int (threadref
*ref
)
2652 unsigned char *scan
;
2658 value
= (value
<< 8) | ((*scan
++) & 0xff);
2663 copy_threadref (threadref
*dest
, threadref
*src
)
2666 unsigned char *csrc
, *cdest
;
2668 csrc
= (unsigned char *) src
;
2669 cdest
= (unsigned char *) dest
;
2676 threadmatch (threadref
*dest
, threadref
*src
)
2678 /* Things are broken right now, so just assume we got a match. */
2680 unsigned char *srcp
, *destp
;
2682 srcp
= (char *) src
;
2683 destp
= (char *) dest
;
2687 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2694 threadid:1, # always request threadid
2701 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2704 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2706 *pkt
++ = 'q'; /* Info Query */
2707 *pkt
++ = 'P'; /* process or thread info */
2708 pkt
= pack_int (pkt
, mode
); /* mode */
2709 pkt
= pack_threadid (pkt
, id
); /* threadid */
2710 *pkt
= '\0'; /* terminate */
2714 /* These values tag the fields in a thread info response packet. */
2715 /* Tagging the fields allows us to request specific fields and to
2716 add more fields as time goes by. */
2718 #define TAG_THREADID 1 /* Echo the thread identifier. */
2719 #define TAG_EXISTS 2 /* Is this process defined enough to
2720 fetch registers and its stack? */
2721 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2722 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2723 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2727 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2728 struct gdb_ext_thread_info
*info
)
2730 struct remote_state
*rs
= get_remote_state ();
2734 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2737 /* info->threadid = 0; FIXME: implement zero_threadref. */
2739 info
->display
[0] = '\0';
2740 info
->shortname
[0] = '\0';
2741 info
->more_display
[0] = '\0';
2743 /* Assume the characters indicating the packet type have been
2745 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2746 pkt
= unpack_threadid (pkt
, &ref
);
2749 warning (_("Incomplete response to threadinfo request."));
2750 if (!threadmatch (&ref
, expectedref
))
2751 { /* This is an answer to a different request. */
2752 warning (_("ERROR RMT Thread info mismatch."));
2755 copy_threadref (&info
->threadid
, &ref
);
2757 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2759 /* Packets are terminated with nulls. */
2760 while ((pkt
< limit
) && mask
&& *pkt
)
2762 pkt
= unpack_int (pkt
, &tag
); /* tag */
2763 pkt
= unpack_byte (pkt
, &length
); /* length */
2764 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2766 warning (_("ERROR RMT: threadinfo tag mismatch."));
2770 if (tag
== TAG_THREADID
)
2774 warning (_("ERROR RMT: length of threadid is not 16."));
2778 pkt
= unpack_threadid (pkt
, &ref
);
2779 mask
= mask
& ~TAG_THREADID
;
2782 if (tag
== TAG_EXISTS
)
2784 info
->active
= stub_unpack_int (pkt
, length
);
2786 mask
= mask
& ~(TAG_EXISTS
);
2789 warning (_("ERROR RMT: 'exists' length too long."));
2795 if (tag
== TAG_THREADNAME
)
2797 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2798 mask
= mask
& ~TAG_THREADNAME
;
2801 if (tag
== TAG_DISPLAY
)
2803 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2804 mask
= mask
& ~TAG_DISPLAY
;
2807 if (tag
== TAG_MOREDISPLAY
)
2809 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2810 mask
= mask
& ~TAG_MOREDISPLAY
;
2813 warning (_("ERROR RMT: unknown thread info tag."));
2814 break; /* Not a tag we know about. */
2820 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2821 struct gdb_ext_thread_info
*info
)
2823 struct remote_state
*rs
= get_remote_state ();
2826 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2828 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2830 if (rs
->buf
[0] == '\0')
2833 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2838 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2841 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2842 threadref
*nextthread
)
2844 *pkt
++ = 'q'; /* info query packet */
2845 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2846 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2847 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2848 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2853 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2856 parse_threadlist_response (char *pkt
, int result_limit
,
2857 threadref
*original_echo
, threadref
*resultlist
,
2860 struct remote_state
*rs
= get_remote_state ();
2862 int count
, resultcount
, done
;
2865 /* Assume the 'q' and 'M chars have been stripped. */
2866 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2867 /* done parse past here */
2868 pkt
= unpack_byte (pkt
, &count
); /* count field */
2869 pkt
= unpack_nibble (pkt
, &done
);
2870 /* The first threadid is the argument threadid. */
2871 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2872 while ((count
-- > 0) && (pkt
< limit
))
2874 pkt
= unpack_threadid (pkt
, resultlist
++);
2875 if (resultcount
++ >= result_limit
)
2883 /* Fetch the next batch of threads from the remote. Returns -1 if the
2884 qL packet is not supported, 0 on error and 1 on success. */
2887 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2888 int *done
, int *result_count
, threadref
*threadlist
)
2890 struct remote_state
*rs
= get_remote_state ();
2893 /* Trancate result limit to be smaller than the packet size. */
2894 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2895 >= get_remote_packet_size ())
2896 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2898 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2900 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2901 if (*rs
->buf
== '\0')
2903 /* Packet not supported. */
2908 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2909 &rs
->echo_nextthread
, threadlist
, done
);
2911 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2913 /* FIXME: This is a good reason to drop the packet. */
2914 /* Possably, there is a duplicate response. */
2916 retransmit immediatly - race conditions
2917 retransmit after timeout - yes
2919 wait for packet, then exit
2921 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2922 return 0; /* I choose simply exiting. */
2924 if (*result_count
<= 0)
2928 warning (_("RMT ERROR : failed to get remote thread list."));
2931 return result
; /* break; */
2933 if (*result_count
> result_limit
)
2936 warning (_("RMT ERROR: threadlist response longer than requested."));
2942 /* Fetch the list of remote threads, with the qL packet, and call
2943 STEPFUNCTION for each thread found. Stops iterating and returns 1
2944 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2945 STEPFUNCTION returns false. If the packet is not supported,
2949 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2952 struct remote_state
*rs
= get_remote_state ();
2953 int done
, i
, result_count
;
2961 if (loopcount
++ > looplimit
)
2964 warning (_("Remote fetch threadlist -infinite loop-."));
2967 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2968 MAXTHREADLISTRESULTS
,
2969 &done
, &result_count
,
2970 rs
->resultthreadlist
);
2973 /* Clear for later iterations. */
2975 /* Setup to resume next batch of thread references, set nextthread. */
2976 if (result_count
>= 1)
2977 copy_threadref (&rs
->nextthread
,
2978 &rs
->resultthreadlist
[result_count
- 1]);
2980 while (result_count
--)
2982 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2992 /* A thread found on the remote target. */
2994 typedef struct thread_item
2996 /* The thread's PTID. */
2999 /* The thread's extra info. May be NULL. */
3002 /* The thread's name. May be NULL. */
3005 /* The core the thread was running on. -1 if not known. */
3008 /* The thread handle associated with the thread. */
3009 gdb::byte_vector
*thread_handle
;
3012 DEF_VEC_O(thread_item_t
);
3014 /* Context passed around to the various methods listing remote
3015 threads. As new threads are found, they're added to the ITEMS
3018 struct threads_listing_context
3020 /* The threads found on the remote target. */
3021 VEC (thread_item_t
) *items
;
3024 /* Discard the contents of the constructed thread listing context. */
3027 clear_threads_listing_context (void *p
)
3029 struct threads_listing_context
*context
3030 = (struct threads_listing_context
*) p
;
3032 struct thread_item
*item
;
3034 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
3036 xfree (item
->extra
);
3038 delete item
->thread_handle
;
3041 VEC_free (thread_item_t
, context
->items
);
3044 /* Remove the thread specified as the related_pid field of WS
3045 from the CONTEXT list. */
3048 threads_listing_context_remove (struct target_waitstatus
*ws
,
3049 struct threads_listing_context
*context
)
3051 struct thread_item
*item
;
3053 ptid_t child_ptid
= ws
->value
.related_pid
;
3055 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
3057 if (ptid_equal (item
->ptid
, child_ptid
))
3059 VEC_ordered_remove (thread_item_t
, context
->items
, i
);
3066 remote_newthread_step (threadref
*ref
, void *data
)
3068 struct threads_listing_context
*context
3069 = (struct threads_listing_context
*) data
;
3070 struct thread_item item
;
3071 int pid
= ptid_get_pid (inferior_ptid
);
3073 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
3077 item
.thread_handle
= nullptr;
3079 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3081 return 1; /* continue iterator */
3084 #define CRAZY_MAX_THREADS 1000
3087 remote_current_thread (ptid_t oldpid
)
3089 struct remote_state
*rs
= get_remote_state ();
3092 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3093 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
3098 result
= read_ptid (&rs
->buf
[2], &obuf
);
3099 if (*obuf
!= '\0' && remote_debug
)
3100 fprintf_unfiltered (gdb_stdlog
,
3101 "warning: garbage in qC reply\n");
3109 /* List remote threads using the deprecated qL packet. */
3112 remote_get_threads_with_ql (struct target_ops
*ops
,
3113 struct threads_listing_context
*context
)
3115 if (remote_threadlist_iterator (remote_newthread_step
, context
,
3116 CRAZY_MAX_THREADS
) >= 0)
3122 #if defined(HAVE_LIBEXPAT)
3125 start_thread (struct gdb_xml_parser
*parser
,
3126 const struct gdb_xml_element
*element
,
3127 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
3129 struct threads_listing_context
*data
3130 = (struct threads_listing_context
*) user_data
;
3132 struct thread_item item
;
3134 struct gdb_xml_value
*attr
;
3136 id
= (char *) xml_find_attribute (attributes
, "id")->value
;
3137 item
.ptid
= read_ptid (id
, NULL
);
3139 attr
= xml_find_attribute (attributes
, "core");
3141 item
.core
= *(ULONGEST
*) attr
->value
;
3145 attr
= xml_find_attribute (attributes
, "name");
3146 item
.name
= attr
!= NULL
? xstrdup ((const char *) attr
->value
) : NULL
;
3148 attr
= xml_find_attribute (attributes
, "handle");
3151 item
.thread_handle
= new gdb::byte_vector
3152 (strlen ((const char *) attr
->value
) / 2);
3153 hex2bin ((const char *) attr
->value
, item
.thread_handle
->data (),
3154 item
.thread_handle
->size ());
3157 item
.thread_handle
= nullptr;
3161 VEC_safe_push (thread_item_t
, data
->items
, &item
);
3165 end_thread (struct gdb_xml_parser
*parser
,
3166 const struct gdb_xml_element
*element
,
3167 void *user_data
, const char *body_text
)
3169 struct threads_listing_context
*data
3170 = (struct threads_listing_context
*) user_data
;
3172 if (body_text
&& *body_text
)
3173 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
3176 const struct gdb_xml_attribute thread_attributes
[] = {
3177 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
3178 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
3179 { "name", GDB_XML_AF_OPTIONAL
, NULL
, NULL
},
3180 { "handle", GDB_XML_AF_OPTIONAL
, NULL
, NULL
},
3181 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
3184 const struct gdb_xml_element thread_children
[] = {
3185 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3188 const struct gdb_xml_element threads_children
[] = {
3189 { "thread", thread_attributes
, thread_children
,
3190 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
3191 start_thread
, end_thread
},
3192 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3195 const struct gdb_xml_element threads_elements
[] = {
3196 { "threads", NULL
, threads_children
,
3197 GDB_XML_EF_NONE
, NULL
, NULL
},
3198 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3203 /* List remote threads using qXfer:threads:read. */
3206 remote_get_threads_with_qxfer (struct target_ops
*ops
,
3207 struct threads_listing_context
*context
)
3209 #if defined(HAVE_LIBEXPAT)
3210 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3212 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
3213 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
3215 if (xml
!= NULL
&& *xml
!= '\0')
3217 gdb_xml_parse_quick (_("threads"), "threads.dtd",
3218 threads_elements
, xml
, context
);
3221 do_cleanups (back_to
);
3229 /* List remote threads using qfThreadInfo/qsThreadInfo. */
3232 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
3233 struct threads_listing_context
*context
)
3235 struct remote_state
*rs
= get_remote_state ();
3237 if (rs
->use_threadinfo_query
)
3241 putpkt ("qfThreadInfo");
3242 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3244 if (bufp
[0] != '\0') /* q packet recognized */
3246 while (*bufp
++ == 'm') /* reply contains one or more TID */
3250 struct thread_item item
;
3252 item
.ptid
= read_ptid (bufp
, &bufp
);
3256 item
.thread_handle
= nullptr;
3258 VEC_safe_push (thread_item_t
, context
->items
, &item
);
3260 while (*bufp
++ == ','); /* comma-separated list */
3261 putpkt ("qsThreadInfo");
3262 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3269 /* Packet not recognized. */
3270 rs
->use_threadinfo_query
= 0;
3277 /* Implement the to_update_thread_list function for the remote
3281 remote_update_thread_list (struct target_ops
*ops
)
3283 struct threads_listing_context context
;
3284 struct cleanup
*old_chain
;
3287 context
.items
= NULL
;
3288 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
3290 /* We have a few different mechanisms to fetch the thread list. Try
3291 them all, starting with the most preferred one first, falling
3292 back to older methods. */
3293 if (remote_get_threads_with_qxfer (ops
, &context
)
3294 || remote_get_threads_with_qthreadinfo (ops
, &context
)
3295 || remote_get_threads_with_ql (ops
, &context
))
3298 struct thread_item
*item
;
3299 struct thread_info
*tp
, *tmp
;
3303 if (VEC_empty (thread_item_t
, context
.items
)
3304 && remote_thread_always_alive (ops
, inferior_ptid
))
3306 /* Some targets don't really support threads, but still
3307 reply an (empty) thread list in response to the thread
3308 listing packets, instead of replying "packet not
3309 supported". Exit early so we don't delete the main
3311 do_cleanups (old_chain
);
3315 /* CONTEXT now holds the current thread list on the remote
3316 target end. Delete GDB-side threads no longer found on the
3318 ALL_THREADS_SAFE (tp
, tmp
)
3321 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3324 if (ptid_equal (item
->ptid
, tp
->ptid
))
3328 if (i
== VEC_length (thread_item_t
, context
.items
))
3331 delete_thread (tp
->ptid
);
3335 /* Remove any unreported fork child threads from CONTEXT so
3336 that we don't interfere with follow fork, which is where
3337 creation of such threads is handled. */
3338 remove_new_fork_children (&context
);
3340 /* And now add threads we don't know about yet to our list. */
3342 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
3345 if (!ptid_equal (item
->ptid
, null_ptid
))
3347 struct private_thread_info
*info
;
3348 /* In non-stop mode, we assume new found threads are
3349 executing until proven otherwise with a stop reply.
3350 In all-stop, we can only get here if all threads are
3352 int executing
= target_is_non_stop_p () ? 1 : 0;
3354 remote_notice_new_inferior (item
->ptid
, executing
);
3356 info
= get_private_info_ptid (item
->ptid
);
3357 info
->core
= item
->core
;
3358 info
->extra
= item
->extra
;
3360 info
->name
= item
->name
;
3362 info
->thread_handle
= item
->thread_handle
;
3363 item
->thread_handle
= nullptr;
3370 /* If no thread listing method is supported, then query whether
3371 each known thread is alive, one by one, with the T packet.
3372 If the target doesn't support threads at all, then this is a
3373 no-op. See remote_thread_alive. */
3377 do_cleanups (old_chain
);
3381 * Collect a descriptive string about the given thread.
3382 * The target may say anything it wants to about the thread
3383 * (typically info about its blocked / runnable state, name, etc.).
3384 * This string will appear in the info threads display.
3386 * Optional: targets are not required to implement this function.
3390 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
3392 struct remote_state
*rs
= get_remote_state ();
3396 struct gdb_ext_thread_info threadinfo
;
3397 static char display_buf
[100]; /* arbitrary... */
3398 int n
= 0; /* position in display_buf */
3400 if (rs
->remote_desc
== 0) /* paranoia */
3401 internal_error (__FILE__
, __LINE__
,
3402 _("remote_threads_extra_info"));
3404 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
3405 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
3406 /* This is the main thread which was added by GDB. The remote
3407 server doesn't know about it. */
3410 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3412 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
3414 if (info
&& info
->priv
)
3415 return info
->priv
->extra
;
3420 if (rs
->use_threadextra_query
)
3423 char *endb
= rs
->buf
+ get_remote_packet_size ();
3425 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
3427 write_ptid (b
, endb
, tp
->ptid
);
3430 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3431 if (rs
->buf
[0] != 0)
3433 n
= std::min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
3434 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
3435 display_buf
[result
] = '\0';
3440 /* If the above query fails, fall back to the old method. */
3441 rs
->use_threadextra_query
= 0;
3442 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3443 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3444 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
3445 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
3446 if (threadinfo
.active
)
3448 if (*threadinfo
.shortname
)
3449 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
3450 " Name: %s,", threadinfo
.shortname
);
3451 if (*threadinfo
.display
)
3452 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3453 " State: %s,", threadinfo
.display
);
3454 if (*threadinfo
.more_display
)
3455 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3456 " Priority: %s", threadinfo
.more_display
);
3460 /* For purely cosmetic reasons, clear up trailing commas. */
3461 if (',' == display_buf
[n
-1])
3462 display_buf
[n
-1] = ' ';
3471 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
3472 struct static_tracepoint_marker
*marker
)
3474 struct remote_state
*rs
= get_remote_state ();
3477 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3479 p
+= hexnumstr (p
, addr
);
3481 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3485 error (_("Remote failure reply: %s"), p
);
3489 parse_static_tracepoint_marker_definition (p
, NULL
, marker
);
3496 static VEC(static_tracepoint_marker_p
) *
3497 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3500 struct remote_state
*rs
= get_remote_state ();
3501 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3502 struct static_tracepoint_marker
*marker
= NULL
;
3503 struct cleanup
*old_chain
;
3506 /* Ask for a first packet of static tracepoint marker
3509 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3512 error (_("Remote failure reply: %s"), p
);
3514 old_chain
= make_cleanup (free_current_marker
, &marker
);
3519 marker
= XCNEW (struct static_tracepoint_marker
);
3523 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3525 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3527 VEC_safe_push (static_tracepoint_marker_p
,
3533 release_static_tracepoint_marker (marker
);
3534 memset (marker
, 0, sizeof (*marker
));
3537 while (*p
++ == ','); /* comma-separated list */
3538 /* Ask for another packet of static tracepoint definition. */
3540 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3544 do_cleanups (old_chain
);
3549 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3552 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3554 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3558 /* Restart the remote side; this is an extended protocol operation. */
3561 extended_remote_restart (void)
3563 struct remote_state
*rs
= get_remote_state ();
3565 /* Send the restart command; for reasons I don't understand the
3566 remote side really expects a number after the "R". */
3567 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3570 remote_fileio_reset ();
3573 /* Clean up connection to a remote debugger. */
3576 remote_close (struct target_ops
*self
)
3578 struct remote_state
*rs
= get_remote_state ();
3580 if (rs
->remote_desc
== NULL
)
3581 return; /* already closed */
3583 /* Make sure we leave stdin registered in the event loop. */
3584 remote_terminal_ours (self
);
3586 serial_close (rs
->remote_desc
);
3587 rs
->remote_desc
= NULL
;
3589 /* We don't have a connection to the remote stub anymore. Get rid
3590 of all the inferiors and their threads we were controlling.
3591 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3592 will be unable to find the thread corresponding to (pid, 0, 0). */
3593 inferior_ptid
= null_ptid
;
3594 discard_all_inferiors ();
3596 /* We are closing the remote target, so we should discard
3597 everything of this target. */
3598 discard_pending_stop_replies_in_queue (rs
);
3600 if (remote_async_inferior_event_token
)
3601 delete_async_event_handler (&remote_async_inferior_event_token
);
3603 remote_notif_state_xfree (rs
->notif_state
);
3605 trace_reset_local_state ();
3608 /* Query the remote side for the text, data and bss offsets. */
3613 struct remote_state
*rs
= get_remote_state ();
3616 int lose
, num_segments
= 0, do_sections
, do_segments
;
3617 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3618 struct section_offsets
*offs
;
3619 struct symfile_segment_data
*data
;
3621 if (symfile_objfile
== NULL
)
3624 putpkt ("qOffsets");
3625 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3628 if (buf
[0] == '\000')
3629 return; /* Return silently. Stub doesn't support
3633 warning (_("Remote failure reply: %s"), buf
);
3637 /* Pick up each field in turn. This used to be done with scanf, but
3638 scanf will make trouble if CORE_ADDR size doesn't match
3639 conversion directives correctly. The following code will work
3640 with any size of CORE_ADDR. */
3641 text_addr
= data_addr
= bss_addr
= 0;
3645 if (startswith (ptr
, "Text="))
3648 /* Don't use strtol, could lose on big values. */
3649 while (*ptr
&& *ptr
!= ';')
3650 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3652 if (startswith (ptr
, ";Data="))
3655 while (*ptr
&& *ptr
!= ';')
3656 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3661 if (!lose
&& startswith (ptr
, ";Bss="))
3664 while (*ptr
&& *ptr
!= ';')
3665 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3667 if (bss_addr
!= data_addr
)
3668 warning (_("Target reported unsupported offsets: %s"), buf
);
3673 else if (startswith (ptr
, "TextSeg="))
3676 /* Don't use strtol, could lose on big values. */
3677 while (*ptr
&& *ptr
!= ';')
3678 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3681 if (startswith (ptr
, ";DataSeg="))
3684 while (*ptr
&& *ptr
!= ';')
3685 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3693 error (_("Malformed response to offset query, %s"), buf
);
3694 else if (*ptr
!= '\0')
3695 warning (_("Target reported unsupported offsets: %s"), buf
);
3697 offs
= ((struct section_offsets
*)
3698 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3699 memcpy (offs
, symfile_objfile
->section_offsets
,
3700 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3702 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3703 do_segments
= (data
!= NULL
);
3704 do_sections
= num_segments
== 0;
3706 if (num_segments
> 0)
3708 segments
[0] = text_addr
;
3709 segments
[1] = data_addr
;
3711 /* If we have two segments, we can still try to relocate everything
3712 by assuming that the .text and .data offsets apply to the whole
3713 text and data segments. Convert the offsets given in the packet
3714 to base addresses for symfile_map_offsets_to_segments. */
3715 else if (data
&& data
->num_segments
== 2)
3717 segments
[0] = data
->segment_bases
[0] + text_addr
;
3718 segments
[1] = data
->segment_bases
[1] + data_addr
;
3721 /* If the object file has only one segment, assume that it is text
3722 rather than data; main programs with no writable data are rare,
3723 but programs with no code are useless. Of course the code might
3724 have ended up in the data segment... to detect that we would need
3725 the permissions here. */
3726 else if (data
&& data
->num_segments
== 1)
3728 segments
[0] = data
->segment_bases
[0] + text_addr
;
3731 /* There's no way to relocate by segment. */
3737 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3738 offs
, num_segments
, segments
);
3740 if (ret
== 0 && !do_sections
)
3741 error (_("Can not handle qOffsets TextSeg "
3742 "response with this symbol file"));
3749 free_symfile_segment_data (data
);
3753 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3755 /* This is a temporary kludge to force data and bss to use the
3756 same offsets because that's what nlmconv does now. The real
3757 solution requires changes to the stub and remote.c that I
3758 don't have time to do right now. */
3760 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3761 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3764 objfile_relocate (symfile_objfile
, offs
);
3767 /* Send interrupt_sequence to remote target. */
3769 send_interrupt_sequence (void)
3771 struct remote_state
*rs
= get_remote_state ();
3773 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3774 remote_serial_write ("\x03", 1);
3775 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3776 serial_send_break (rs
->remote_desc
);
3777 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3779 serial_send_break (rs
->remote_desc
);
3780 remote_serial_write ("g", 1);
3783 internal_error (__FILE__
, __LINE__
,
3784 _("Invalid value for interrupt_sequence_mode: %s."),
3785 interrupt_sequence_mode
);
3789 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3790 and extract the PTID. Returns NULL_PTID if not found. */
3793 stop_reply_extract_thread (char *stop_reply
)
3795 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3799 /* Txx r:val ; r:val (...) */
3802 /* Look for "register" named "thread". */
3807 p1
= strchr (p
, ':');
3811 if (strncmp (p
, "thread", p1
- p
) == 0)
3812 return read_ptid (++p1
, &p
);
3814 p1
= strchr (p
, ';');
3826 /* Determine the remote side's current thread. If we have a stop
3827 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3828 "thread" register we can extract the current thread from. If not,
3829 ask the remote which is the current thread with qC. The former
3830 method avoids a roundtrip. */
3833 get_current_thread (char *wait_status
)
3835 ptid_t ptid
= null_ptid
;
3837 /* Note we don't use remote_parse_stop_reply as that makes use of
3838 the target architecture, which we haven't yet fully determined at
3840 if (wait_status
!= NULL
)
3841 ptid
= stop_reply_extract_thread (wait_status
);
3842 if (ptid_equal (ptid
, null_ptid
))
3843 ptid
= remote_current_thread (inferior_ptid
);
3848 /* Query the remote target for which is the current thread/process,
3849 add it to our tables, and update INFERIOR_PTID. The caller is
3850 responsible for setting the state such that the remote end is ready
3851 to return the current thread.
3853 This function is called after handling the '?' or 'vRun' packets,
3854 whose response is a stop reply from which we can also try
3855 extracting the thread. If the target doesn't support the explicit
3856 qC query, we infer the current thread from that stop reply, passed
3857 in in WAIT_STATUS, which may be NULL. */
3860 add_current_inferior_and_thread (char *wait_status
)
3862 struct remote_state
*rs
= get_remote_state ();
3865 inferior_ptid
= null_ptid
;
3867 /* Now, if we have thread information, update inferior_ptid. */
3868 ptid_t curr_ptid
= get_current_thread (wait_status
);
3870 if (curr_ptid
!= null_ptid
)
3872 if (!remote_multi_process_p (rs
))
3877 /* Without this, some commands which require an active target
3878 (such as kill) won't work. This variable serves (at least)
3879 double duty as both the pid of the target process (if it has
3880 such), and as a flag indicating that a target is active. */
3881 curr_ptid
= magic_null_ptid
;
3885 remote_add_inferior (fake_pid_p
, ptid_get_pid (curr_ptid
), -1, 1);
3887 /* Add the main thread and switch to it. Don't try reading
3888 registers yet, since we haven't fetched the target description
3890 thread_info
*tp
= add_thread_silent (curr_ptid
);
3891 switch_to_thread_no_regs (tp
);
3894 /* Print info about a thread that was found already stopped on
3898 print_one_stopped_thread (struct thread_info
*thread
)
3900 struct target_waitstatus
*ws
= &thread
->suspend
.waitstatus
;
3902 switch_to_thread (thread
->ptid
);
3903 stop_pc
= get_frame_pc (get_current_frame ());
3904 set_current_sal_from_frame (get_current_frame ());
3906 thread
->suspend
.waitstatus_pending_p
= 0;
3908 if (ws
->kind
== TARGET_WAITKIND_STOPPED
)
3910 enum gdb_signal sig
= ws
->value
.sig
;
3912 if (signal_print_state (sig
))
3913 observer_notify_signal_received (sig
);
3915 observer_notify_normal_stop (NULL
, 1);
3918 /* Process all initial stop replies the remote side sent in response
3919 to the ? packet. These indicate threads that were already stopped
3920 on initial connection. We mark these threads as stopped and print
3921 their current frame before giving the user the prompt. */
3924 process_initial_stop_replies (int from_tty
)
3926 int pending_stop_replies
= stop_reply_queue_length ();
3927 struct inferior
*inf
;
3928 struct thread_info
*thread
;
3929 struct thread_info
*selected
= NULL
;
3930 struct thread_info
*lowest_stopped
= NULL
;
3931 struct thread_info
*first
= NULL
;
3933 /* Consume the initial pending events. */
3934 while (pending_stop_replies
-- > 0)
3936 ptid_t waiton_ptid
= minus_one_ptid
;
3938 struct target_waitstatus ws
;
3939 int ignore_event
= 0;
3940 struct thread_info
*thread
;
3942 memset (&ws
, 0, sizeof (ws
));
3943 event_ptid
= target_wait (waiton_ptid
, &ws
, TARGET_WNOHANG
);
3945 print_target_wait_results (waiton_ptid
, event_ptid
, &ws
);
3949 case TARGET_WAITKIND_IGNORE
:
3950 case TARGET_WAITKIND_NO_RESUMED
:
3951 case TARGET_WAITKIND_SIGNALLED
:
3952 case TARGET_WAITKIND_EXITED
:
3953 /* We shouldn't see these, but if we do, just ignore. */
3955 fprintf_unfiltered (gdb_stdlog
, "remote: event ignored\n");
3959 case TARGET_WAITKIND_EXECD
:
3960 xfree (ws
.value
.execd_pathname
);
3969 thread
= find_thread_ptid (event_ptid
);
3971 if (ws
.kind
== TARGET_WAITKIND_STOPPED
)
3973 enum gdb_signal sig
= ws
.value
.sig
;
3975 /* Stubs traditionally report SIGTRAP as initial signal,
3976 instead of signal 0. Suppress it. */
3977 if (sig
== GDB_SIGNAL_TRAP
)
3979 thread
->suspend
.stop_signal
= sig
;
3983 thread
->suspend
.waitstatus
= ws
;
3985 if (ws
.kind
!= TARGET_WAITKIND_STOPPED
3986 || ws
.value
.sig
!= GDB_SIGNAL_0
)
3987 thread
->suspend
.waitstatus_pending_p
= 1;
3989 set_executing (event_ptid
, 0);
3990 set_running (event_ptid
, 0);
3991 thread
->priv
->vcont_resumed
= 0;
3994 /* "Notice" the new inferiors before anything related to
3995 registers/memory. */
4001 inf
->needs_setup
= 1;
4005 thread
= any_live_thread_of_process (inf
->pid
);
4006 notice_new_inferior (thread
->ptid
,
4007 thread
->state
== THREAD_RUNNING
,
4012 /* If all-stop on top of non-stop, pause all threads. Note this
4013 records the threads' stop pc, so must be done after "noticing"
4017 stop_all_threads ();
4019 /* If all threads of an inferior were already stopped, we
4020 haven't setup the inferior yet. */
4026 if (inf
->needs_setup
)
4028 thread
= any_live_thread_of_process (inf
->pid
);
4029 switch_to_thread_no_regs (thread
);
4035 /* Now go over all threads that are stopped, and print their current
4036 frame. If all-stop, then if there's a signalled thread, pick
4038 ALL_NON_EXITED_THREADS (thread
)
4044 set_running (thread
->ptid
, 0);
4045 else if (thread
->state
!= THREAD_STOPPED
)
4048 if (selected
== NULL
4049 && thread
->suspend
.waitstatus_pending_p
)
4052 if (lowest_stopped
== NULL
4053 || thread
->inf
->num
< lowest_stopped
->inf
->num
4054 || thread
->per_inf_num
< lowest_stopped
->per_inf_num
)
4055 lowest_stopped
= thread
;
4058 print_one_stopped_thread (thread
);
4061 /* In all-stop, we only print the status of one thread, and leave
4062 others with their status pending. */
4067 thread
= lowest_stopped
;
4071 print_one_stopped_thread (thread
);
4074 /* For "info program". */
4075 thread
= inferior_thread ();
4076 if (thread
->state
== THREAD_STOPPED
)
4077 set_last_target_status (inferior_ptid
, thread
->suspend
.waitstatus
);
4080 /* Start the remote connection and sync state. */
4083 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
4085 struct remote_state
*rs
= get_remote_state ();
4086 struct packet_config
*noack_config
;
4087 char *wait_status
= NULL
;
4089 /* Signal other parts that we're going through the initial setup,
4090 and so things may not be stable yet. E.g., we don't try to
4091 install tracepoints until we've relocated symbols. Also, a
4092 Ctrl-C before we're connected and synced up can't interrupt the
4093 target. Instead, it offers to drop the (potentially wedged)
4095 rs
->starting_up
= 1;
4099 if (interrupt_on_connect
)
4100 send_interrupt_sequence ();
4102 /* Ack any packet which the remote side has already sent. */
4103 remote_serial_write ("+", 1);
4105 /* The first packet we send to the target is the optional "supported
4106 packets" request. If the target can answer this, it will tell us
4107 which later probes to skip. */
4108 remote_query_supported ();
4110 /* If the stub wants to get a QAllow, compose one and send it. */
4111 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
4112 remote_set_permissions (target
);
4114 /* gdbserver < 7.7 (before its fix from 2013-12-11) did reply to any
4115 unknown 'v' packet with string "OK". "OK" gets interpreted by GDB
4116 as a reply to known packet. For packet "vFile:setfs:" it is an
4117 invalid reply and GDB would return error in
4118 remote_hostio_set_filesystem, making remote files access impossible.
4119 Disable "vFile:setfs:" in such case. Do not disable other 'v' packets as
4120 other "vFile" packets get correctly detected even on gdbserver < 7.7. */
4122 const char v_mustreplyempty
[] = "vMustReplyEmpty";
4124 putpkt (v_mustreplyempty
);
4125 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4126 if (strcmp (rs
->buf
, "OK") == 0)
4127 remote_protocol_packets
[PACKET_vFile_setfs
].support
= PACKET_DISABLE
;
4128 else if (strcmp (rs
->buf
, "") != 0)
4129 error (_("Remote replied unexpectedly to '%s': %s"), v_mustreplyempty
,
4133 /* Next, we possibly activate noack mode.
4135 If the QStartNoAckMode packet configuration is set to AUTO,
4136 enable noack mode if the stub reported a wish for it with
4139 If set to TRUE, then enable noack mode even if the stub didn't
4140 report it in qSupported. If the stub doesn't reply OK, the
4141 session ends with an error.
4143 If FALSE, then don't activate noack mode, regardless of what the
4144 stub claimed should be the default with qSupported. */
4146 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
4147 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
4149 putpkt ("QStartNoAckMode");
4150 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4151 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
4157 /* Tell the remote that we are using the extended protocol. */
4159 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4162 /* Let the target know which signals it is allowed to pass down to
4164 update_signals_program_target ();
4166 /* Next, if the target can specify a description, read it. We do
4167 this before anything involving memory or registers. */
4168 target_find_description ();
4170 /* Next, now that we know something about the target, update the
4171 address spaces in the program spaces. */
4172 update_address_spaces ();
4174 /* On OSs where the list of libraries is global to all
4175 processes, we fetch them early. */
4176 if (gdbarch_has_global_solist (target_gdbarch ()))
4177 solib_add (NULL
, from_tty
, auto_solib_add
);
4179 if (target_is_non_stop_p ())
4181 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
4182 error (_("Non-stop mode requested, but remote "
4183 "does not support non-stop"));
4185 putpkt ("QNonStop:1");
4186 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4188 if (strcmp (rs
->buf
, "OK") != 0)
4189 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
4191 /* Find about threads and processes the stub is already
4192 controlling. We default to adding them in the running state.
4193 The '?' query below will then tell us about which threads are
4195 remote_update_thread_list (target
);
4197 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
4199 /* Don't assume that the stub can operate in all-stop mode.
4200 Request it explicitly. */
4201 putpkt ("QNonStop:0");
4202 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4204 if (strcmp (rs
->buf
, "OK") != 0)
4205 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
4208 /* Upload TSVs regardless of whether the target is running or not. The
4209 remote stub, such as GDBserver, may have some predefined or builtin
4210 TSVs, even if the target is not running. */
4211 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4213 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
4215 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
4216 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
4219 /* Check whether the target is running now. */
4221 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4223 if (!target_is_non_stop_p ())
4225 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
4228 error (_("The target is not running (try extended-remote?)"));
4230 /* We're connected, but not running. Drop out before we
4231 call start_remote. */
4232 rs
->starting_up
= 0;
4237 /* Save the reply for later. */
4238 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
4239 strcpy (wait_status
, rs
->buf
);
4242 /* Fetch thread list. */
4243 target_update_thread_list ();
4245 /* Let the stub know that we want it to return the thread. */
4246 set_continue_thread (minus_one_ptid
);
4248 if (thread_count () == 0)
4250 /* Target has no concept of threads at all. GDB treats
4251 non-threaded target as single-threaded; add a main
4253 add_current_inferior_and_thread (wait_status
);
4257 /* We have thread information; select the thread the target
4258 says should be current. If we're reconnecting to a
4259 multi-threaded program, this will ideally be the thread
4260 that last reported an event before GDB disconnected. */
4261 inferior_ptid
= get_current_thread (wait_status
);
4262 if (ptid_equal (inferior_ptid
, null_ptid
))
4264 /* Odd... The target was able to list threads, but not
4265 tell us which thread was current (no "thread"
4266 register in T stop reply?). Just pick the first
4267 thread in the thread list then. */
4270 fprintf_unfiltered (gdb_stdlog
,
4271 "warning: couldn't determine remote "
4272 "current thread; picking first in list.\n");
4274 inferior_ptid
= thread_list
->ptid
;
4278 /* init_wait_for_inferior should be called before get_offsets in order
4279 to manage `inserted' flag in bp loc in a correct state.
4280 breakpoint_init_inferior, called from init_wait_for_inferior, set
4281 `inserted' flag to 0, while before breakpoint_re_set, called from
4282 start_remote, set `inserted' flag to 1. In the initialization of
4283 inferior, breakpoint_init_inferior should be called first, and then
4284 breakpoint_re_set can be called. If this order is broken, state of
4285 `inserted' flag is wrong, and cause some problems on breakpoint
4287 init_wait_for_inferior ();
4289 get_offsets (); /* Get text, data & bss offsets. */
4291 /* If we could not find a description using qXfer, and we know
4292 how to do it some other way, try again. This is not
4293 supported for non-stop; it could be, but it is tricky if
4294 there are no stopped threads when we connect. */
4295 if (remote_read_description_p (target
)
4296 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
4298 target_clear_description ();
4299 target_find_description ();
4302 /* Use the previously fetched status. */
4303 gdb_assert (wait_status
!= NULL
);
4304 strcpy (rs
->buf
, wait_status
);
4305 rs
->cached_wait_status
= 1;
4307 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
4311 /* Clear WFI global state. Do this before finding about new
4312 threads and inferiors, and setting the current inferior.
4313 Otherwise we would clear the proceed status of the current
4314 inferior when we want its stop_soon state to be preserved
4315 (see notice_new_inferior). */
4316 init_wait_for_inferior ();
4318 /* In non-stop, we will either get an "OK", meaning that there
4319 are no stopped threads at this time; or, a regular stop
4320 reply. In the latter case, there may be more than one thread
4321 stopped --- we pull them all out using the vStopped
4323 if (strcmp (rs
->buf
, "OK") != 0)
4325 struct notif_client
*notif
= ¬if_client_stop
;
4327 /* remote_notif_get_pending_replies acks this one, and gets
4329 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
4330 = remote_notif_parse (notif
, rs
->buf
);
4331 remote_notif_get_pending_events (notif
);
4334 if (thread_count () == 0)
4337 error (_("The target is not running (try extended-remote?)"));
4339 /* We're connected, but not running. Drop out before we
4340 call start_remote. */
4341 rs
->starting_up
= 0;
4345 /* In non-stop mode, any cached wait status will be stored in
4346 the stop reply queue. */
4347 gdb_assert (wait_status
== NULL
);
4349 /* Report all signals during attach/startup. */
4350 remote_pass_signals (target
, 0, NULL
);
4352 /* If there are already stopped threads, mark them stopped and
4353 report their stops before giving the prompt to the user. */
4354 process_initial_stop_replies (from_tty
);
4356 if (target_can_async_p ())
4360 /* If we connected to a live target, do some additional setup. */
4361 if (target_has_execution
)
4363 if (symfile_objfile
) /* No use without a symbol-file. */
4364 remote_check_symbols ();
4367 /* Possibly the target has been engaged in a trace run started
4368 previously; find out where things are at. */
4369 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
4371 struct uploaded_tp
*uploaded_tps
= NULL
;
4373 if (current_trace_status ()->running
)
4374 printf_filtered (_("Trace is already running on the target.\n"));
4376 remote_upload_tracepoints (target
, &uploaded_tps
);
4378 merge_uploaded_tracepoints (&uploaded_tps
);
4381 /* Possibly the target has been engaged in a btrace record started
4382 previously; find out where things are at. */
4383 remote_btrace_maybe_reopen ();
4385 /* The thread and inferior lists are now synchronized with the
4386 target, our symbols have been relocated, and we're merged the
4387 target's tracepoints with ours. We're done with basic start
4389 rs
->starting_up
= 0;
4391 /* Maybe breakpoints are global and need to be inserted now. */
4392 if (breakpoints_should_be_inserted_now ())
4393 insert_breakpoints ();
4396 /* Open a connection to a remote debugger.
4397 NAME is the filename used for communication. */
4400 remote_open (const char *name
, int from_tty
)
4402 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
4405 /* Open a connection to a remote debugger using the extended
4406 remote gdb protocol. NAME is the filename used for communication. */
4409 extended_remote_open (const char *name
, int from_tty
)
4411 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
4414 /* Reset all packets back to "unknown support". Called when opening a
4415 new connection to a remote target. */
4418 reset_all_packet_configs_support (void)
4422 for (i
= 0; i
< PACKET_MAX
; i
++)
4423 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4426 /* Initialize all packet configs. */
4429 init_all_packet_configs (void)
4433 for (i
= 0; i
< PACKET_MAX
; i
++)
4435 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
4436 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
4440 /* Symbol look-up. */
4443 remote_check_symbols (void)
4445 struct remote_state
*rs
= get_remote_state ();
4446 char *msg
, *reply
, *tmp
;
4449 struct cleanup
*old_chain
;
4451 /* The remote side has no concept of inferiors that aren't running
4452 yet, it only knows about running processes. If we're connected
4453 but our current inferior is not running, we should not invite the
4454 remote target to request symbol lookups related to its
4455 (unrelated) current process. */
4456 if (!target_has_execution
)
4459 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
4462 /* Make sure the remote is pointing at the right process. Note
4463 there's no way to select "no process". */
4464 set_general_process ();
4466 /* Allocate a message buffer. We can't reuse the input buffer in RS,
4467 because we need both at the same time. */
4468 msg
= (char *) xmalloc (get_remote_packet_size ());
4469 old_chain
= make_cleanup (xfree
, msg
);
4470 reply
= (char *) xmalloc (get_remote_packet_size ());
4471 make_cleanup (free_current_contents
, &reply
);
4472 reply_size
= get_remote_packet_size ();
4474 /* Invite target to request symbol lookups. */
4476 putpkt ("qSymbol::");
4477 getpkt (&reply
, &reply_size
, 0);
4478 packet_ok (reply
, &remote_protocol_packets
[PACKET_qSymbol
]);
4480 while (startswith (reply
, "qSymbol:"))
4482 struct bound_minimal_symbol sym
;
4485 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
4487 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
4488 if (sym
.minsym
== NULL
)
4489 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
4492 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4493 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
4495 /* If this is a function address, return the start of code
4496 instead of any data function descriptor. */
4497 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
4501 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
4502 phex_nz (sym_addr
, addr_size
), &reply
[8]);
4506 getpkt (&reply
, &reply_size
, 0);
4509 do_cleanups (old_chain
);
4512 static struct serial
*
4513 remote_serial_open (const char *name
)
4515 static int udp_warning
= 0;
4517 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
4518 of in ser-tcp.c, because it is the remote protocol assuming that the
4519 serial connection is reliable and not the serial connection promising
4521 if (!udp_warning
&& startswith (name
, "udp:"))
4523 warning (_("The remote protocol may be unreliable over UDP.\n"
4524 "Some events may be lost, rendering further debugging "
4529 return serial_open (name
);
4532 /* Inform the target of our permission settings. The permission flags
4533 work without this, but if the target knows the settings, it can do
4534 a couple things. First, it can add its own check, to catch cases
4535 that somehow manage to get by the permissions checks in target
4536 methods. Second, if the target is wired to disallow particular
4537 settings (for instance, a system in the field that is not set up to
4538 be able to stop at a breakpoint), it can object to any unavailable
4542 remote_set_permissions (struct target_ops
*self
)
4544 struct remote_state
*rs
= get_remote_state ();
4546 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
4547 "WriteReg:%x;WriteMem:%x;"
4548 "InsertBreak:%x;InsertTrace:%x;"
4549 "InsertFastTrace:%x;Stop:%x",
4550 may_write_registers
, may_write_memory
,
4551 may_insert_breakpoints
, may_insert_tracepoints
,
4552 may_insert_fast_tracepoints
, may_stop
);
4554 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4556 /* If the target didn't like the packet, warn the user. Do not try
4557 to undo the user's settings, that would just be maddening. */
4558 if (strcmp (rs
->buf
, "OK") != 0)
4559 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
4562 /* This type describes each known response to the qSupported
4564 struct protocol_feature
4566 /* The name of this protocol feature. */
4569 /* The default for this protocol feature. */
4570 enum packet_support default_support
;
4572 /* The function to call when this feature is reported, or after
4573 qSupported processing if the feature is not supported.
4574 The first argument points to this structure. The second
4575 argument indicates whether the packet requested support be
4576 enabled, disabled, or probed (or the default, if this function
4577 is being called at the end of processing and this feature was
4578 not reported). The third argument may be NULL; if not NULL, it
4579 is a NUL-terminated string taken from the packet following
4580 this feature's name and an equals sign. */
4581 void (*func
) (const struct protocol_feature
*, enum packet_support
,
4584 /* The corresponding packet for this feature. Only used if
4585 FUNC is remote_supported_packet. */
4590 remote_supported_packet (const struct protocol_feature
*feature
,
4591 enum packet_support support
,
4592 const char *argument
)
4596 warning (_("Remote qSupported response supplied an unexpected value for"
4597 " \"%s\"."), feature
->name
);
4601 remote_protocol_packets
[feature
->packet
].support
= support
;
4605 remote_packet_size (const struct protocol_feature
*feature
,
4606 enum packet_support support
, const char *value
)
4608 struct remote_state
*rs
= get_remote_state ();
4613 if (support
!= PACKET_ENABLE
)
4616 if (value
== NULL
|| *value
== '\0')
4618 warning (_("Remote target reported \"%s\" without a size."),
4624 packet_size
= strtol (value
, &value_end
, 16);
4625 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
4627 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4628 feature
->name
, value
);
4632 /* Record the new maximum packet size. */
4633 rs
->explicit_packet_size
= packet_size
;
4636 static const struct protocol_feature remote_protocol_features
[] = {
4637 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4638 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4639 PACKET_qXfer_auxv
},
4640 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
4641 PACKET_qXfer_exec_file
},
4642 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4643 PACKET_qXfer_features
},
4644 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4645 PACKET_qXfer_libraries
},
4646 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4647 PACKET_qXfer_libraries_svr4
},
4648 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4649 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4650 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4651 PACKET_qXfer_memory_map
},
4652 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4653 PACKET_qXfer_spu_read
},
4654 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4655 PACKET_qXfer_spu_write
},
4656 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4657 PACKET_qXfer_osdata
},
4658 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4659 PACKET_qXfer_threads
},
4660 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4661 PACKET_qXfer_traceframe_info
},
4662 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4663 PACKET_QPassSignals
},
4664 { "QCatchSyscalls", PACKET_DISABLE
, remote_supported_packet
,
4665 PACKET_QCatchSyscalls
},
4666 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4667 PACKET_QProgramSignals
},
4668 { "QSetWorkingDir", PACKET_DISABLE
, remote_supported_packet
,
4669 PACKET_QSetWorkingDir
},
4670 { "QStartupWithShell", PACKET_DISABLE
, remote_supported_packet
,
4671 PACKET_QStartupWithShell
},
4672 { "QEnvironmentHexEncoded", PACKET_DISABLE
, remote_supported_packet
,
4673 PACKET_QEnvironmentHexEncoded
},
4674 { "QEnvironmentReset", PACKET_DISABLE
, remote_supported_packet
,
4675 PACKET_QEnvironmentReset
},
4676 { "QEnvironmentUnset", PACKET_DISABLE
, remote_supported_packet
,
4677 PACKET_QEnvironmentUnset
},
4678 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4679 PACKET_QStartNoAckMode
},
4680 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4681 PACKET_multiprocess_feature
},
4682 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4683 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4684 PACKET_qXfer_siginfo_read
},
4685 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4686 PACKET_qXfer_siginfo_write
},
4687 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4688 PACKET_ConditionalTracepoints
},
4689 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4690 PACKET_ConditionalBreakpoints
},
4691 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4692 PACKET_BreakpointCommands
},
4693 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4694 PACKET_FastTracepoints
},
4695 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4696 PACKET_StaticTracepoints
},
4697 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4698 PACKET_InstallInTrace
},
4699 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4700 PACKET_DisconnectedTracing_feature
},
4701 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4703 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4705 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4706 PACKET_TracepointSource
},
4707 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4709 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4710 PACKET_EnableDisableTracepoints_feature
},
4711 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4712 PACKET_qXfer_fdpic
},
4713 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4715 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4716 PACKET_QDisableRandomization
},
4717 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4718 { "QTBuffer:size", PACKET_DISABLE
,
4719 remote_supported_packet
, PACKET_QTBuffer_size
},
4720 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4721 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4722 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4723 { "Qbtrace:pt", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_pt
},
4724 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4725 PACKET_qXfer_btrace
},
4726 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4727 PACKET_qXfer_btrace_conf
},
4728 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4729 PACKET_Qbtrace_conf_bts_size
},
4730 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4731 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4732 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4733 PACKET_fork_event_feature
},
4734 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4735 PACKET_vfork_event_feature
},
4736 { "exec-events", PACKET_DISABLE
, remote_supported_packet
,
4737 PACKET_exec_event_feature
},
4738 { "Qbtrace-conf:pt:size", PACKET_DISABLE
, remote_supported_packet
,
4739 PACKET_Qbtrace_conf_pt_size
},
4740 { "vContSupported", PACKET_DISABLE
, remote_supported_packet
, PACKET_vContSupported
},
4741 { "QThreadEvents", PACKET_DISABLE
, remote_supported_packet
, PACKET_QThreadEvents
},
4742 { "no-resumed", PACKET_DISABLE
, remote_supported_packet
, PACKET_no_resumed
},
4745 static char *remote_support_xml
;
4747 /* Register string appended to "xmlRegisters=" in qSupported query. */
4750 register_remote_support_xml (const char *xml
)
4752 #if defined(HAVE_LIBEXPAT)
4753 if (remote_support_xml
== NULL
)
4754 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4757 char *copy
= xstrdup (remote_support_xml
+ 13);
4758 char *p
= strtok (copy
, ",");
4762 if (strcmp (p
, xml
) == 0)
4769 while ((p
= strtok (NULL
, ",")) != NULL
);
4772 remote_support_xml
= reconcat (remote_support_xml
,
4773 remote_support_xml
, ",", xml
,
4780 remote_query_supported_append (char *msg
, const char *append
)
4783 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4785 return xstrdup (append
);
4789 remote_query_supported (void)
4791 struct remote_state
*rs
= get_remote_state ();
4794 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4796 /* The packet support flags are handled differently for this packet
4797 than for most others. We treat an error, a disabled packet, and
4798 an empty response identically: any features which must be reported
4799 to be used will be automatically disabled. An empty buffer
4800 accomplishes this, since that is also the representation for a list
4801 containing no features. */
4804 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4807 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4809 if (packet_set_cmd_state (PACKET_multiprocess_feature
) != AUTO_BOOLEAN_FALSE
)
4810 q
= remote_query_supported_append (q
, "multiprocess+");
4812 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4813 q
= remote_query_supported_append (q
, "swbreak+");
4814 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4815 q
= remote_query_supported_append (q
, "hwbreak+");
4817 q
= remote_query_supported_append (q
, "qRelocInsn+");
4819 if (packet_set_cmd_state (PACKET_fork_event_feature
)
4820 != AUTO_BOOLEAN_FALSE
)
4821 q
= remote_query_supported_append (q
, "fork-events+");
4822 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
4823 != AUTO_BOOLEAN_FALSE
)
4824 q
= remote_query_supported_append (q
, "vfork-events+");
4825 if (packet_set_cmd_state (PACKET_exec_event_feature
)
4826 != AUTO_BOOLEAN_FALSE
)
4827 q
= remote_query_supported_append (q
, "exec-events+");
4829 if (packet_set_cmd_state (PACKET_vContSupported
) != AUTO_BOOLEAN_FALSE
)
4830 q
= remote_query_supported_append (q
, "vContSupported+");
4832 if (packet_set_cmd_state (PACKET_QThreadEvents
) != AUTO_BOOLEAN_FALSE
)
4833 q
= remote_query_supported_append (q
, "QThreadEvents+");
4835 if (packet_set_cmd_state (PACKET_no_resumed
) != AUTO_BOOLEAN_FALSE
)
4836 q
= remote_query_supported_append (q
, "no-resumed+");
4838 /* Keep this one last to work around a gdbserver <= 7.10 bug in
4839 the qSupported:xmlRegisters=i386 handling. */
4840 if (remote_support_xml
!= NULL
)
4841 q
= remote_query_supported_append (q
, remote_support_xml
);
4843 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4846 do_cleanups (old_chain
);
4848 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4850 /* If an error occured, warn, but do not return - just reset the
4851 buffer to empty and go on to disable features. */
4852 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4855 warning (_("Remote failure reply: %s"), rs
->buf
);
4860 memset (seen
, 0, sizeof (seen
));
4865 enum packet_support is_supported
;
4866 char *p
, *end
, *name_end
, *value
;
4868 /* First separate out this item from the rest of the packet. If
4869 there's another item after this, we overwrite the separator
4870 (terminated strings are much easier to work with). */
4872 end
= strchr (p
, ';');
4875 end
= p
+ strlen (p
);
4885 warning (_("empty item in \"qSupported\" response"));
4890 name_end
= strchr (p
, '=');
4893 /* This is a name=value entry. */
4894 is_supported
= PACKET_ENABLE
;
4895 value
= name_end
+ 1;
4904 is_supported
= PACKET_ENABLE
;
4908 is_supported
= PACKET_DISABLE
;
4912 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4916 warning (_("unrecognized item \"%s\" "
4917 "in \"qSupported\" response"), p
);
4923 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4924 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4926 const struct protocol_feature
*feature
;
4929 feature
= &remote_protocol_features
[i
];
4930 feature
->func (feature
, is_supported
, value
);
4935 /* If we increased the packet size, make sure to increase the global
4936 buffer size also. We delay this until after parsing the entire
4937 qSupported packet, because this is the same buffer we were
4939 if (rs
->buf_size
< rs
->explicit_packet_size
)
4941 rs
->buf_size
= rs
->explicit_packet_size
;
4942 rs
->buf
= (char *) xrealloc (rs
->buf
, rs
->buf_size
);
4945 /* Handle the defaults for unmentioned features. */
4946 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4949 const struct protocol_feature
*feature
;
4951 feature
= &remote_protocol_features
[i
];
4952 feature
->func (feature
, feature
->default_support
, NULL
);
4956 /* Serial QUIT handler for the remote serial descriptor.
4958 Defers handling a Ctrl-C until we're done with the current
4959 command/response packet sequence, unless:
4961 - We're setting up the connection. Don't send a remote interrupt
4962 request, as we're not fully synced yet. Quit immediately
4965 - The target has been resumed in the foreground
4966 (target_terminal::is_ours is false) with a synchronous resume
4967 packet, and we're blocked waiting for the stop reply, thus a
4968 Ctrl-C should be immediately sent to the target.
4970 - We get a second Ctrl-C while still within the same serial read or
4971 write. In that case the serial is seemingly wedged --- offer to
4974 - We see a second Ctrl-C without target response, after having
4975 previously interrupted the target. In that case the target/stub
4976 is probably wedged --- offer to quit/disconnect.
4980 remote_serial_quit_handler (void)
4982 struct remote_state
*rs
= get_remote_state ();
4984 if (check_quit_flag ())
4986 /* If we're starting up, we're not fully synced yet. Quit
4988 if (rs
->starting_up
)
4990 else if (rs
->got_ctrlc_during_io
)
4992 if (query (_("The target is not responding to GDB commands.\n"
4993 "Stop debugging it? ")))
4994 remote_unpush_and_throw ();
4996 /* If ^C has already been sent once, offer to disconnect. */
4997 else if (!target_terminal::is_ours () && rs
->ctrlc_pending_p
)
4999 /* All-stop protocol, and blocked waiting for stop reply. Send
5000 an interrupt request. */
5001 else if (!target_terminal::is_ours () && rs
->waiting_for_stop_reply
)
5002 target_interrupt (inferior_ptid
);
5004 rs
->got_ctrlc_during_io
= 1;
5008 /* Remove any of the remote.c targets from target stack. Upper targets depend
5009 on it so remove them first. */
5012 remote_unpush_target (void)
5014 pop_all_targets_at_and_above (process_stratum
);
5018 remote_unpush_and_throw (void)
5020 remote_unpush_target ();
5021 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
5025 remote_open_1 (const char *name
, int from_tty
,
5026 struct target_ops
*target
, int extended_p
)
5028 struct remote_state
*rs
= get_remote_state ();
5031 error (_("To open a remote debug connection, you need to specify what\n"
5032 "serial device is attached to the remote system\n"
5033 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
5035 /* See FIXME above. */
5036 if (!target_async_permitted
)
5037 wait_forever_enabled_p
= 1;
5039 /* If we're connected to a running target, target_preopen will kill it.
5040 Ask this question first, before target_preopen has a chance to kill
5042 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
5045 && !query (_("Already connected to a remote target. Disconnect? ")))
5046 error (_("Still connected."));
5049 /* Here the possibly existing remote target gets unpushed. */
5050 target_preopen (from_tty
);
5052 /* Make sure we send the passed signals list the next time we resume. */
5053 xfree (rs
->last_pass_packet
);
5054 rs
->last_pass_packet
= NULL
;
5056 /* Make sure we send the program signals list the next time we
5058 xfree (rs
->last_program_signals_packet
);
5059 rs
->last_program_signals_packet
= NULL
;
5061 remote_fileio_reset ();
5062 reopen_exec_file ();
5065 rs
->remote_desc
= remote_serial_open (name
);
5066 if (!rs
->remote_desc
)
5067 perror_with_name (name
);
5069 if (baud_rate
!= -1)
5071 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
5073 /* The requested speed could not be set. Error out to
5074 top level after closing remote_desc. Take care to
5075 set remote_desc to NULL to avoid closing remote_desc
5077 serial_close (rs
->remote_desc
);
5078 rs
->remote_desc
= NULL
;
5079 perror_with_name (name
);
5083 serial_setparity (rs
->remote_desc
, serial_parity
);
5084 serial_raw (rs
->remote_desc
);
5086 /* If there is something sitting in the buffer we might take it as a
5087 response to a command, which would be bad. */
5088 serial_flush_input (rs
->remote_desc
);
5092 puts_filtered ("Remote debugging using ");
5093 puts_filtered (name
);
5094 puts_filtered ("\n");
5096 push_target (target
); /* Switch to using remote target now. */
5098 /* Register extra event sources in the event loop. */
5099 remote_async_inferior_event_token
5100 = create_async_event_handler (remote_async_inferior_event_handler
,
5102 rs
->notif_state
= remote_notif_state_allocate ();
5104 /* Reset the target state; these things will be queried either by
5105 remote_query_supported or as they are needed. */
5106 reset_all_packet_configs_support ();
5107 rs
->cached_wait_status
= 0;
5108 rs
->explicit_packet_size
= 0;
5110 rs
->extended
= extended_p
;
5111 rs
->waiting_for_stop_reply
= 0;
5112 rs
->ctrlc_pending_p
= 0;
5113 rs
->got_ctrlc_during_io
= 0;
5115 rs
->general_thread
= not_sent_ptid
;
5116 rs
->continue_thread
= not_sent_ptid
;
5117 rs
->remote_traceframe_number
= -1;
5119 rs
->last_resume_exec_dir
= EXEC_FORWARD
;
5121 /* Probe for ability to use "ThreadInfo" query, as required. */
5122 rs
->use_threadinfo_query
= 1;
5123 rs
->use_threadextra_query
= 1;
5125 readahead_cache_invalidate ();
5127 /* Start out by owning the terminal. */
5128 remote_async_terminal_ours_p
= 1;
5130 if (target_async_permitted
)
5132 /* FIXME: cagney/1999-09-23: During the initial connection it is
5133 assumed that the target is already ready and able to respond to
5134 requests. Unfortunately remote_start_remote() eventually calls
5135 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
5136 around this. Eventually a mechanism that allows
5137 wait_for_inferior() to expect/get timeouts will be
5139 wait_forever_enabled_p
= 0;
5142 /* First delete any symbols previously loaded from shared libraries. */
5143 no_shared_libraries (NULL
, 0);
5146 init_thread_list ();
5148 /* Start the remote connection. If error() or QUIT, discard this
5149 target (we'd otherwise be in an inconsistent state) and then
5150 propogate the error on up the exception chain. This ensures that
5151 the caller doesn't stumble along blindly assuming that the
5152 function succeeded. The CLI doesn't have this problem but other
5153 UI's, such as MI do.
5155 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
5156 this function should return an error indication letting the
5157 caller restore the previous state. Unfortunately the command
5158 ``target remote'' is directly wired to this function making that
5159 impossible. On a positive note, the CLI side of this problem has
5160 been fixed - the function set_cmd_context() makes it possible for
5161 all the ``target ....'' commands to share a common callback
5162 function. See cli-dump.c. */
5167 remote_start_remote (from_tty
, target
, extended_p
);
5169 CATCH (ex
, RETURN_MASK_ALL
)
5171 /* Pop the partially set up target - unless something else did
5172 already before throwing the exception. */
5173 if (rs
->remote_desc
!= NULL
)
5174 remote_unpush_target ();
5175 if (target_async_permitted
)
5176 wait_forever_enabled_p
= 1;
5177 throw_exception (ex
);
5182 remote_btrace_reset ();
5184 if (target_async_permitted
)
5185 wait_forever_enabled_p
= 1;
5188 /* Detach the specified process. */
5191 remote_detach_pid (int pid
)
5193 struct remote_state
*rs
= get_remote_state ();
5195 if (remote_multi_process_p (rs
))
5196 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
5198 strcpy (rs
->buf
, "D");
5201 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5203 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
5205 else if (rs
->buf
[0] == '\0')
5206 error (_("Remote doesn't know how to detach"));
5208 error (_("Can't detach process."));
5211 /* This detaches a program to which we previously attached, using
5212 inferior_ptid to identify the process. After this is done, GDB
5213 can be used to debug some other program. We better not have left
5214 any breakpoints in the target program or it'll die when it hits
5218 remote_detach_1 (const char *args
, int from_tty
)
5220 int pid
= ptid_get_pid (inferior_ptid
);
5221 struct remote_state
*rs
= get_remote_state ();
5222 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
5226 error (_("Argument given to \"detach\" when remotely debugging."));
5228 if (!target_has_execution
)
5229 error (_("No process to detach from."));
5231 target_announce_detach (from_tty
);
5233 /* Tell the remote target to detach. */
5234 remote_detach_pid (pid
);
5236 /* Exit only if this is the only active inferior. */
5237 if (from_tty
&& !rs
->extended
&& number_of_live_inferiors () == 1)
5238 puts_filtered (_("Ending remote debugging.\n"));
5240 /* Check to see if we are detaching a fork parent. Note that if we
5241 are detaching a fork child, tp == NULL. */
5242 is_fork_parent
= (tp
!= NULL
5243 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
5245 /* If doing detach-on-fork, we don't mourn, because that will delete
5246 breakpoints that should be available for the followed inferior. */
5247 if (!is_fork_parent
)
5248 target_mourn_inferior (inferior_ptid
);
5251 inferior_ptid
= null_ptid
;
5252 detach_inferior (pid
);
5257 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5259 remote_detach_1 (args
, from_tty
);
5263 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
5265 remote_detach_1 (args
, from_tty
);
5268 /* Target follow-fork function for remote targets. On entry, and
5269 at return, the current inferior is the fork parent.
5271 Note that although this is currently only used for extended-remote,
5272 it is named remote_follow_fork in anticipation of using it for the
5273 remote target as well. */
5276 remote_follow_fork (struct target_ops
*ops
, int follow_child
,
5279 struct remote_state
*rs
= get_remote_state ();
5280 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
5282 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
5283 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
5285 /* When following the parent and detaching the child, we detach
5286 the child here. For the case of following the child and
5287 detaching the parent, the detach is done in the target-
5288 independent follow fork code in infrun.c. We can't use
5289 target_detach when detaching an unfollowed child because
5290 the client side doesn't know anything about the child. */
5291 if (detach_fork
&& !follow_child
)
5293 /* Detach the fork child. */
5297 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
5298 child_pid
= ptid_get_pid (child_ptid
);
5300 remote_detach_pid (child_pid
);
5301 detach_inferior (child_pid
);
5307 /* Target follow-exec function for remote targets. Save EXECD_PATHNAME
5308 in the program space of the new inferior. On entry and at return the
5309 current inferior is the exec'ing inferior. INF is the new exec'd
5310 inferior, which may be the same as the exec'ing inferior unless
5311 follow-exec-mode is "new". */
5314 remote_follow_exec (struct target_ops
*ops
,
5315 struct inferior
*inf
, char *execd_pathname
)
5317 /* We know that this is a target file name, so if it has the "target:"
5318 prefix we strip it off before saving it in the program space. */
5319 if (is_target_filename (execd_pathname
))
5320 execd_pathname
+= strlen (TARGET_SYSROOT_PREFIX
);
5322 set_pspace_remote_exec_file (inf
->pspace
, execd_pathname
);
5325 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
5328 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
5331 error (_("Argument given to \"disconnect\" when remotely debugging."));
5333 /* Make sure we unpush even the extended remote targets. Calling
5334 target_mourn_inferior won't unpush, and remote_mourn won't
5335 unpush if there is more than one inferior left. */
5336 unpush_target (target
);
5337 generic_mourn_inferior ();
5340 puts_filtered ("Ending remote debugging.\n");
5343 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
5344 be chatty about it. */
5347 extended_remote_attach (struct target_ops
*target
, const char *args
,
5350 struct remote_state
*rs
= get_remote_state ();
5352 char *wait_status
= NULL
;
5354 pid
= parse_pid_to_attach (args
);
5356 /* Remote PID can be freely equal to getpid, do not check it here the same
5357 way as in other targets. */
5359 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
5360 error (_("This target does not support attaching to a process"));
5364 char *exec_file
= get_exec_file (0);
5367 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
5368 target_pid_to_str (pid_to_ptid (pid
)));
5370 printf_unfiltered (_("Attaching to %s\n"),
5371 target_pid_to_str (pid_to_ptid (pid
)));
5373 gdb_flush (gdb_stdout
);
5376 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
5378 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5380 switch (packet_ok (rs
->buf
,
5381 &remote_protocol_packets
[PACKET_vAttach
]))
5384 if (!target_is_non_stop_p ())
5386 /* Save the reply for later. */
5387 wait_status
= (char *) alloca (strlen (rs
->buf
) + 1);
5388 strcpy (wait_status
, rs
->buf
);
5390 else if (strcmp (rs
->buf
, "OK") != 0)
5391 error (_("Attaching to %s failed with: %s"),
5392 target_pid_to_str (pid_to_ptid (pid
)),
5395 case PACKET_UNKNOWN
:
5396 error (_("This target does not support attaching to a process"));
5398 error (_("Attaching to %s failed"),
5399 target_pid_to_str (pid_to_ptid (pid
)));
5402 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
5404 inferior_ptid
= pid_to_ptid (pid
);
5406 if (target_is_non_stop_p ())
5408 struct thread_info
*thread
;
5410 /* Get list of threads. */
5411 remote_update_thread_list (target
);
5413 thread
= first_thread_of_process (pid
);
5415 inferior_ptid
= thread
->ptid
;
5417 inferior_ptid
= pid_to_ptid (pid
);
5419 /* Invalidate our notion of the remote current thread. */
5420 record_currthread (rs
, minus_one_ptid
);
5424 /* Now, if we have thread information, update inferior_ptid. */
5425 inferior_ptid
= remote_current_thread (inferior_ptid
);
5427 /* Add the main thread to the thread list. */
5428 add_thread_silent (inferior_ptid
);
5431 /* Next, if the target can specify a description, read it. We do
5432 this before anything involving memory or registers. */
5433 target_find_description ();
5435 if (!target_is_non_stop_p ())
5437 /* Use the previously fetched status. */
5438 gdb_assert (wait_status
!= NULL
);
5440 if (target_can_async_p ())
5442 struct notif_event
*reply
5443 = remote_notif_parse (¬if_client_stop
, wait_status
);
5445 push_stop_reply ((struct stop_reply
*) reply
);
5451 gdb_assert (wait_status
!= NULL
);
5452 strcpy (rs
->buf
, wait_status
);
5453 rs
->cached_wait_status
= 1;
5457 gdb_assert (wait_status
== NULL
);
5460 /* Implementation of the to_post_attach method. */
5463 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
5465 /* Get text, data & bss offsets. */
5468 /* In certain cases GDB might not have had the chance to start
5469 symbol lookup up until now. This could happen if the debugged
5470 binary is not using shared libraries, the vsyscall page is not
5471 present (on Linux) and the binary itself hadn't changed since the
5472 debugging process was started. */
5473 if (symfile_objfile
!= NULL
)
5474 remote_check_symbols();
5478 /* Check for the availability of vCont. This function should also check
5482 remote_vcont_probe (struct remote_state
*rs
)
5486 strcpy (rs
->buf
, "vCont?");
5488 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5491 /* Make sure that the features we assume are supported. */
5492 if (startswith (buf
, "vCont"))
5495 int support_c
, support_C
;
5497 rs
->supports_vCont
.s
= 0;
5498 rs
->supports_vCont
.S
= 0;
5501 rs
->supports_vCont
.t
= 0;
5502 rs
->supports_vCont
.r
= 0;
5503 while (p
&& *p
== ';')
5506 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5507 rs
->supports_vCont
.s
= 1;
5508 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5509 rs
->supports_vCont
.S
= 1;
5510 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5512 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5514 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5515 rs
->supports_vCont
.t
= 1;
5516 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
5517 rs
->supports_vCont
.r
= 1;
5519 p
= strchr (p
, ';');
5522 /* If c, and C are not all supported, we can't use vCont. Clearing
5523 BUF will make packet_ok disable the packet. */
5524 if (!support_c
|| !support_C
)
5528 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
5531 /* Helper function for building "vCont" resumptions. Write a
5532 resumption to P. ENDP points to one-passed-the-end of the buffer
5533 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
5534 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
5535 resumed thread should be single-stepped and/or signalled. If PTID
5536 equals minus_one_ptid, then all threads are resumed; if PTID
5537 represents a process, then all threads of the process are resumed;
5538 the thread to be stepped and/or signalled is given in the global
5542 append_resumption (char *p
, char *endp
,
5543 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5545 struct remote_state
*rs
= get_remote_state ();
5547 if (step
&& siggnal
!= GDB_SIGNAL_0
)
5548 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
5550 /* GDB is willing to range step. */
5551 && use_range_stepping
5552 /* Target supports range stepping. */
5553 && rs
->supports_vCont
.r
5554 /* We don't currently support range stepping multiple
5555 threads with a wildcard (though the protocol allows it,
5556 so stubs shouldn't make an active effort to forbid
5558 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5560 struct thread_info
*tp
;
5562 if (ptid_equal (ptid
, minus_one_ptid
))
5564 /* If we don't know about the target thread's tid, then
5565 we're resuming magic_null_ptid (see caller). */
5566 tp
= find_thread_ptid (magic_null_ptid
);
5569 tp
= find_thread_ptid (ptid
);
5570 gdb_assert (tp
!= NULL
);
5572 if (tp
->control
.may_range_step
)
5574 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
5576 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
5577 phex_nz (tp
->control
.step_range_start
,
5579 phex_nz (tp
->control
.step_range_end
,
5583 p
+= xsnprintf (p
, endp
- p
, ";s");
5586 p
+= xsnprintf (p
, endp
- p
, ";s");
5587 else if (siggnal
!= GDB_SIGNAL_0
)
5588 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
5590 p
+= xsnprintf (p
, endp
- p
, ";c");
5592 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
5596 /* All (-1) threads of process. */
5597 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5599 p
+= xsnprintf (p
, endp
- p
, ":");
5600 p
= write_ptid (p
, endp
, nptid
);
5602 else if (!ptid_equal (ptid
, minus_one_ptid
))
5604 p
+= xsnprintf (p
, endp
- p
, ":");
5605 p
= write_ptid (p
, endp
, ptid
);
5611 /* Clear the thread's private info on resume. */
5614 resume_clear_thread_private_info (struct thread_info
*thread
)
5616 if (thread
->priv
!= NULL
)
5618 thread
->priv
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5619 thread
->priv
->watch_data_address
= 0;
5623 /* Append a vCont continue-with-signal action for threads that have a
5624 non-zero stop signal. */
5627 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
5629 struct thread_info
*thread
;
5631 ALL_NON_EXITED_THREADS (thread
)
5632 if (ptid_match (thread
->ptid
, ptid
)
5633 && !ptid_equal (inferior_ptid
, thread
->ptid
)
5634 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
5636 p
= append_resumption (p
, endp
, thread
->ptid
,
5637 0, thread
->suspend
.stop_signal
);
5638 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5639 resume_clear_thread_private_info (thread
);
5645 /* Set the target running, using the packets that use Hc
5649 remote_resume_with_hc (struct target_ops
*ops
,
5650 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5652 struct remote_state
*rs
= get_remote_state ();
5653 struct thread_info
*thread
;
5656 rs
->last_sent_signal
= siggnal
;
5657 rs
->last_sent_step
= step
;
5659 /* The c/s/C/S resume packets use Hc, so set the continue
5661 if (ptid_equal (ptid
, minus_one_ptid
))
5662 set_continue_thread (any_thread_ptid
);
5664 set_continue_thread (ptid
);
5666 ALL_NON_EXITED_THREADS (thread
)
5667 resume_clear_thread_private_info (thread
);
5670 if (execution_direction
== EXEC_REVERSE
)
5672 /* We don't pass signals to the target in reverse exec mode. */
5673 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5674 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5677 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5678 error (_("Remote reverse-step not supported."));
5679 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5680 error (_("Remote reverse-continue not supported."));
5682 strcpy (buf
, step
? "bs" : "bc");
5684 else if (siggnal
!= GDB_SIGNAL_0
)
5686 buf
[0] = step
? 'S' : 'C';
5687 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5688 buf
[2] = tohex (((int) siggnal
) & 0xf);
5692 strcpy (buf
, step
? "s" : "c");
5697 /* Resume the remote inferior by using a "vCont" packet. The thread
5698 to be resumed is PTID; STEP and SIGGNAL indicate whether the
5699 resumed thread should be single-stepped and/or signalled. If PTID
5700 equals minus_one_ptid, then all threads are resumed; the thread to
5701 be stepped and/or signalled is given in the global INFERIOR_PTID.
5702 This function returns non-zero iff it resumes the inferior.
5704 This function issues a strict subset of all possible vCont commands
5708 remote_resume_with_vcont (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5710 struct remote_state
*rs
= get_remote_state ();
5714 /* No reverse execution actions defined for vCont. */
5715 if (execution_direction
== EXEC_REVERSE
)
5718 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5719 remote_vcont_probe (rs
);
5721 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
5725 endp
= rs
->buf
+ get_remote_packet_size ();
5727 /* If we could generate a wider range of packets, we'd have to worry
5728 about overflowing BUF. Should there be a generic
5729 "multi-part-packet" packet? */
5731 p
+= xsnprintf (p
, endp
- p
, "vCont");
5733 if (ptid_equal (ptid
, magic_null_ptid
))
5735 /* MAGIC_NULL_PTID means that we don't have any active threads,
5736 so we don't have any TID numbers the inferior will
5737 understand. Make sure to only send forms that do not specify
5739 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
5741 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
5743 /* Resume all threads (of all processes, or of a single
5744 process), with preference for INFERIOR_PTID. This assumes
5745 inferior_ptid belongs to the set of all threads we are about
5747 if (step
|| siggnal
!= GDB_SIGNAL_0
)
5749 /* Step inferior_ptid, with or without signal. */
5750 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
5753 /* Also pass down any pending signaled resumption for other
5754 threads not the current. */
5755 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
5757 /* And continue others without a signal. */
5758 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
5762 /* Scheduler locking; resume only PTID. */
5763 append_resumption (p
, endp
, ptid
, step
, siggnal
);
5766 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
5769 if (target_is_non_stop_p ())
5771 /* In non-stop, the stub replies to vCont with "OK". The stop
5772 reply will be reported asynchronously by means of a `%Stop'
5774 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5775 if (strcmp (rs
->buf
, "OK") != 0)
5776 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5782 /* Tell the remote machine to resume. */
5785 remote_resume (struct target_ops
*ops
,
5786 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5788 struct remote_state
*rs
= get_remote_state ();
5790 /* When connected in non-stop mode, the core resumes threads
5791 individually. Resuming remote threads directly in target_resume
5792 would thus result in sending one packet per thread. Instead, to
5793 minimize roundtrip latency, here we just store the resume
5794 request; the actual remote resumption will be done in
5795 target_commit_resume / remote_commit_resume, where we'll be able
5796 to do vCont action coalescing. */
5797 if (target_is_non_stop_p () && execution_direction
!= EXEC_REVERSE
)
5799 struct private_thread_info
*remote_thr
;
5801 if (ptid_equal (minus_one_ptid
, ptid
) || ptid_is_pid (ptid
))
5802 remote_thr
= get_private_info_ptid (inferior_ptid
);
5804 remote_thr
= get_private_info_ptid (ptid
);
5805 remote_thr
->last_resume_step
= step
;
5806 remote_thr
->last_resume_sig
= siggnal
;
5810 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5811 (explained in remote-notif.c:handle_notification) so
5812 remote_notif_process is not called. We need find a place where
5813 it is safe to start a 'vNotif' sequence. It is good to do it
5814 before resuming inferior, because inferior was stopped and no RSP
5815 traffic at that moment. */
5816 if (!target_is_non_stop_p ())
5817 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
5819 rs
->last_resume_exec_dir
= execution_direction
;
5821 /* Prefer vCont, and fallback to s/c/S/C, which use Hc. */
5822 if (!remote_resume_with_vcont (ptid
, step
, siggnal
))
5823 remote_resume_with_hc (ops
, ptid
, step
, siggnal
);
5825 /* We are about to start executing the inferior, let's register it
5826 with the event loop. NOTE: this is the one place where all the
5827 execution commands end up. We could alternatively do this in each
5828 of the execution commands in infcmd.c. */
5829 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5830 into infcmd.c in order to allow inferior function calls to work
5831 NOT asynchronously. */
5832 if (target_can_async_p ())
5835 /* We've just told the target to resume. The remote server will
5836 wait for the inferior to stop, and then send a stop reply. In
5837 the mean time, we can't start another command/query ourselves
5838 because the stub wouldn't be ready to process it. This applies
5839 only to the base all-stop protocol, however. In non-stop (which
5840 only supports vCont), the stub replies with an "OK", and is
5841 immediate able to process further serial input. */
5842 if (!target_is_non_stop_p ())
5843 rs
->waiting_for_stop_reply
= 1;
5846 static void check_pending_events_prevent_wildcard_vcont
5847 (int *may_global_wildcard_vcont
);
5848 static int is_pending_fork_parent_thread (struct thread_info
*thread
);
5850 /* Private per-inferior info for target remote processes. */
5852 struct private_inferior
5854 /* Whether we can send a wildcard vCont for this process. */
5855 int may_wildcard_vcont
;
5858 /* Structure used to track the construction of a vCont packet in the
5859 outgoing packet buffer. This is used to send multiple vCont
5860 packets if we have more actions than would fit a single packet. */
5862 struct vcont_builder
5864 /* Pointer to the first action. P points here if no action has been
5868 /* Where the next action will be appended. */
5871 /* The end of the buffer. Must never write past this. */
5875 /* Prepare the outgoing buffer for a new vCont packet. */
5878 vcont_builder_restart (struct vcont_builder
*builder
)
5880 struct remote_state
*rs
= get_remote_state ();
5882 builder
->p
= rs
->buf
;
5883 builder
->endp
= rs
->buf
+ get_remote_packet_size ();
5884 builder
->p
+= xsnprintf (builder
->p
, builder
->endp
- builder
->p
, "vCont");
5885 builder
->first_action
= builder
->p
;
5888 /* If the vCont packet being built has any action, send it to the
5892 vcont_builder_flush (struct vcont_builder
*builder
)
5894 struct remote_state
*rs
;
5896 if (builder
->p
== builder
->first_action
)
5899 rs
= get_remote_state ();
5901 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5902 if (strcmp (rs
->buf
, "OK") != 0)
5903 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5906 /* The largest action is range-stepping, with its two addresses. This
5907 is more than sufficient. If a new, bigger action is created, it'll
5908 quickly trigger a failed assertion in append_resumption (and we'll
5910 #define MAX_ACTION_SIZE 200
5912 /* Append a new vCont action in the outgoing packet being built. If
5913 the action doesn't fit the packet along with previous actions, push
5914 what we've got so far to the remote end and start over a new vCont
5915 packet (with the new action). */
5918 vcont_builder_push_action (struct vcont_builder
*builder
,
5919 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5921 char buf
[MAX_ACTION_SIZE
+ 1];
5925 endp
= append_resumption (buf
, buf
+ sizeof (buf
),
5926 ptid
, step
, siggnal
);
5928 /* Check whether this new action would fit in the vCont packet along
5929 with previous actions. If not, send what we've got so far and
5930 start a new vCont packet. */
5932 if (rsize
> builder
->endp
- builder
->p
)
5934 vcont_builder_flush (builder
);
5935 vcont_builder_restart (builder
);
5937 /* Should now fit. */
5938 gdb_assert (rsize
<= builder
->endp
- builder
->p
);
5941 memcpy (builder
->p
, buf
, rsize
);
5942 builder
->p
+= rsize
;
5946 /* to_commit_resume implementation. */
5949 remote_commit_resume (struct target_ops
*ops
)
5951 struct remote_state
*rs
= get_remote_state ();
5952 struct inferior
*inf
;
5953 struct thread_info
*tp
;
5954 int any_process_wildcard
;
5955 int may_global_wildcard_vcont
;
5956 struct vcont_builder vcont_builder
;
5958 /* If connected in all-stop mode, we'd send the remote resume
5959 request directly from remote_resume. Likewise if
5960 reverse-debugging, as there are no defined vCont actions for
5961 reverse execution. */
5962 if (!target_is_non_stop_p () || execution_direction
== EXEC_REVERSE
)
5965 /* Try to send wildcard actions ("vCont;c" or "vCont;c:pPID.-1")
5966 instead of resuming all threads of each process individually.
5967 However, if any thread of a process must remain halted, we can't
5968 send wildcard resumes and must send one action per thread.
5970 Care must be taken to not resume threads/processes the server
5971 side already told us are stopped, but the core doesn't know about
5972 yet, because the events are still in the vStopped notification
5975 #1 => vCont s:p1.1;c
5977 #3 <= %Stopped T05 p1.1
5982 #8 (infrun handles the stop for p1.1 and continues stepping)
5983 #9 => vCont s:p1.1;c
5985 The last vCont above would resume thread p1.2 by mistake, because
5986 the server has no idea that the event for p1.2 had not been
5989 The server side must similarly ignore resume actions for the
5990 thread that has a pending %Stopped notification (and any other
5991 threads with events pending), until GDB acks the notification
5992 with vStopped. Otherwise, e.g., the following case is
5995 #1 => g (or any other packet)
5997 #3 <= %Stopped T05 p1.2
5998 #4 => vCont s:p1.1;c
6001 Above, the server must not resume thread p1.2. GDB can't know
6002 that p1.2 stopped until it acks the %Stopped notification, and
6003 since from GDB's perspective all threads should be running, it
6006 Finally, special care must also be given to handling fork/vfork
6007 events. A (v)fork event actually tells us that two processes
6008 stopped -- the parent and the child. Until we follow the fork,
6009 we must not resume the child. Therefore, if we have a pending
6010 fork follow, we must not send a global wildcard resume action
6011 (vCont;c). We can still send process-wide wildcards though. */
6013 /* Start by assuming a global wildcard (vCont;c) is possible. */
6014 may_global_wildcard_vcont
= 1;
6016 /* And assume every process is individually wildcard-able too. */
6017 ALL_NON_EXITED_INFERIORS (inf
)
6019 if (inf
->priv
== NULL
)
6020 inf
->priv
= XNEW (struct private_inferior
);
6021 inf
->priv
->may_wildcard_vcont
= 1;
6024 /* Check for any pending events (not reported or processed yet) and
6025 disable process and global wildcard resumes appropriately. */
6026 check_pending_events_prevent_wildcard_vcont (&may_global_wildcard_vcont
);
6028 ALL_NON_EXITED_THREADS (tp
)
6030 /* If a thread of a process is not meant to be resumed, then we
6031 can't wildcard that process. */
6034 tp
->inf
->priv
->may_wildcard_vcont
= 0;
6036 /* And if we can't wildcard a process, we can't wildcard
6037 everything either. */
6038 may_global_wildcard_vcont
= 0;
6042 /* If a thread is the parent of an unfollowed fork, then we
6043 can't do a global wildcard, as that would resume the fork
6045 if (is_pending_fork_parent_thread (tp
))
6046 may_global_wildcard_vcont
= 0;
6049 /* Now let's build the vCont packet(s). Actions must be appended
6050 from narrower to wider scopes (thread -> process -> global). If
6051 we end up with too many actions for a single packet vcont_builder
6052 flushes the current vCont packet to the remote side and starts a
6054 vcont_builder_restart (&vcont_builder
);
6056 /* Threads first. */
6057 ALL_NON_EXITED_THREADS (tp
)
6059 struct private_thread_info
*remote_thr
= tp
->priv
;
6061 if (!tp
->executing
|| remote_thr
->vcont_resumed
)
6064 gdb_assert (!thread_is_in_step_over_chain (tp
));
6066 if (!remote_thr
->last_resume_step
6067 && remote_thr
->last_resume_sig
== GDB_SIGNAL_0
6068 && tp
->inf
->priv
->may_wildcard_vcont
)
6070 /* We'll send a wildcard resume instead. */
6071 remote_thr
->vcont_resumed
= 1;
6075 vcont_builder_push_action (&vcont_builder
, tp
->ptid
,
6076 remote_thr
->last_resume_step
,
6077 remote_thr
->last_resume_sig
);
6078 remote_thr
->vcont_resumed
= 1;
6081 /* Now check whether we can send any process-wide wildcard. This is
6082 to avoid sending a global wildcard in the case nothing is
6083 supposed to be resumed. */
6084 any_process_wildcard
= 0;
6086 ALL_NON_EXITED_INFERIORS (inf
)
6088 if (inf
->priv
->may_wildcard_vcont
)
6090 any_process_wildcard
= 1;
6095 if (any_process_wildcard
)
6097 /* If all processes are wildcard-able, then send a single "c"
6098 action, otherwise, send an "all (-1) threads of process"
6099 continue action for each running process, if any. */
6100 if (may_global_wildcard_vcont
)
6102 vcont_builder_push_action (&vcont_builder
, minus_one_ptid
,
6107 ALL_NON_EXITED_INFERIORS (inf
)
6109 if (inf
->priv
->may_wildcard_vcont
)
6111 vcont_builder_push_action (&vcont_builder
,
6112 pid_to_ptid (inf
->pid
),
6119 vcont_builder_flush (&vcont_builder
);
6124 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
6125 thread, all threads of a remote process, or all threads of all
6129 remote_stop_ns (ptid_t ptid
)
6131 struct remote_state
*rs
= get_remote_state ();
6133 char *endp
= rs
->buf
+ get_remote_packet_size ();
6135 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
6136 remote_vcont_probe (rs
);
6138 if (!rs
->supports_vCont
.t
)
6139 error (_("Remote server does not support stopping threads"));
6141 if (ptid_equal (ptid
, minus_one_ptid
)
6142 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
6143 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
6148 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
6150 if (ptid_is_pid (ptid
))
6151 /* All (-1) threads of process. */
6152 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
6155 /* Small optimization: if we already have a stop reply for
6156 this thread, no use in telling the stub we want this
6158 if (peek_stop_reply (ptid
))
6164 write_ptid (p
, endp
, nptid
);
6167 /* In non-stop, we get an immediate OK reply. The stop reply will
6168 come in asynchronously by notification. */
6170 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6171 if (strcmp (rs
->buf
, "OK") != 0)
6172 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
6175 /* All-stop version of target_interrupt. Sends a break or a ^C to
6176 interrupt the remote target. It is undefined which thread of which
6177 process reports the interrupt. */
6180 remote_interrupt_as (void)
6182 struct remote_state
*rs
= get_remote_state ();
6184 rs
->ctrlc_pending_p
= 1;
6186 /* If the inferior is stopped already, but the core didn't know
6187 about it yet, just ignore the request. The cached wait status
6188 will be collected in remote_wait. */
6189 if (rs
->cached_wait_status
)
6192 /* Send interrupt_sequence to remote target. */
6193 send_interrupt_sequence ();
6196 /* Non-stop version of target_interrupt. Uses `vCtrlC' to interrupt
6197 the remote target. It is undefined which thread of which process
6198 reports the interrupt. Throws an error if the packet is not
6199 supported by the server. */
6202 remote_interrupt_ns (void)
6204 struct remote_state
*rs
= get_remote_state ();
6206 char *endp
= rs
->buf
+ get_remote_packet_size ();
6208 xsnprintf (p
, endp
- p
, "vCtrlC");
6210 /* In non-stop, we get an immediate OK reply. The stop reply will
6211 come in asynchronously by notification. */
6213 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6215 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vCtrlC
]))
6219 case PACKET_UNKNOWN
:
6220 error (_("No support for interrupting the remote target."));
6222 error (_("Interrupting target failed: %s"), rs
->buf
);
6226 /* Implement the to_stop function for the remote targets. */
6229 remote_stop (struct target_ops
*self
, ptid_t ptid
)
6232 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
6234 if (target_is_non_stop_p ())
6235 remote_stop_ns (ptid
);
6238 /* We don't currently have a way to transparently pause the
6239 remote target in all-stop mode. Interrupt it instead. */
6240 remote_interrupt_as ();
6244 /* Implement the to_interrupt function for the remote targets. */
6247 remote_interrupt (struct target_ops
*self
, ptid_t ptid
)
6249 struct remote_state
*rs
= get_remote_state ();
6252 fprintf_unfiltered (gdb_stdlog
, "remote_interrupt called\n");
6254 if (target_is_non_stop_p ())
6255 remote_interrupt_ns ();
6257 remote_interrupt_as ();
6260 /* Implement the to_pass_ctrlc function for the remote targets. */
6263 remote_pass_ctrlc (struct target_ops
*self
)
6265 struct remote_state
*rs
= get_remote_state ();
6268 fprintf_unfiltered (gdb_stdlog
, "remote_pass_ctrlc called\n");
6270 /* If we're starting up, we're not fully synced yet. Quit
6272 if (rs
->starting_up
)
6274 /* If ^C has already been sent once, offer to disconnect. */
6275 else if (rs
->ctrlc_pending_p
)
6278 target_interrupt (inferior_ptid
);
6281 /* Ask the user what to do when an interrupt is received. */
6284 interrupt_query (void)
6286 struct remote_state
*rs
= get_remote_state ();
6288 if (rs
->waiting_for_stop_reply
&& rs
->ctrlc_pending_p
)
6290 if (query (_("The target is not responding to interrupt requests.\n"
6291 "Stop debugging it? ")))
6293 remote_unpush_target ();
6294 throw_error (TARGET_CLOSE_ERROR
, _("Disconnected from target."));
6299 if (query (_("Interrupted while waiting for the program.\n"
6300 "Give up waiting? ")))
6305 /* Enable/disable target terminal ownership. Most targets can use
6306 terminal groups to control terminal ownership. Remote targets are
6307 different in that explicit transfer of ownership to/from GDB/target
6311 remote_terminal_inferior (struct target_ops
*self
)
6313 /* FIXME: cagney/1999-09-27: Make calls to target_terminal::*()
6314 idempotent. The event-loop GDB talking to an asynchronous target
6315 with a synchronous command calls this function from both
6316 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
6317 transfer the terminal to the target when it shouldn't this guard
6319 if (!remote_async_terminal_ours_p
)
6321 remote_async_terminal_ours_p
= 0;
6322 /* NOTE: At this point we could also register our selves as the
6323 recipient of all input. Any characters typed could then be
6324 passed on down to the target. */
6328 remote_terminal_ours (struct target_ops
*self
)
6330 /* See FIXME in remote_terminal_inferior. */
6331 if (remote_async_terminal_ours_p
)
6333 remote_async_terminal_ours_p
= 1;
6337 remote_console_output (char *msg
)
6341 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
6344 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
6348 fputs_unfiltered (tb
, gdb_stdtarg
);
6350 gdb_flush (gdb_stdtarg
);
6353 DEF_VEC_O(cached_reg_t
);
6355 typedef struct stop_reply
6357 struct notif_event base
;
6359 /* The identifier of the thread about this event */
6362 /* The remote state this event is associated with. When the remote
6363 connection, represented by a remote_state object, is closed,
6364 all the associated stop_reply events should be released. */
6365 struct remote_state
*rs
;
6367 struct target_waitstatus ws
;
6369 /* The architecture associated with the expedited registers. */
6372 /* Expedited registers. This makes remote debugging a bit more
6373 efficient for those targets that provide critical registers as
6374 part of their normal status mechanism (as another roundtrip to
6375 fetch them is avoided). */
6376 VEC(cached_reg_t
) *regcache
;
6378 enum target_stop_reason stop_reason
;
6380 CORE_ADDR watch_data_address
;
6385 DECLARE_QUEUE_P (stop_reply_p
);
6386 DEFINE_QUEUE_P (stop_reply_p
);
6387 /* The list of already fetched and acknowledged stop events. This
6388 queue is used for notification Stop, and other notifications
6389 don't need queue for their events, because the notification events
6390 of Stop can't be consumed immediately, so that events should be
6391 queued first, and be consumed by remote_wait_{ns,as} one per
6392 time. Other notifications can consume their events immediately,
6393 so queue is not needed for them. */
6394 static QUEUE (stop_reply_p
) *stop_reply_queue
;
6397 stop_reply_xfree (struct stop_reply
*r
)
6399 notif_event_xfree ((struct notif_event
*) r
);
6402 /* Return the length of the stop reply queue. */
6405 stop_reply_queue_length (void)
6407 return QUEUE_length (stop_reply_p
, stop_reply_queue
);
6411 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
6412 struct notif_event
*event
)
6414 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
6418 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
6419 struct notif_event
*event
)
6421 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
6424 putpkt (self
->ack_command
);
6426 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
6427 /* We got an unknown stop reply. */
6428 error (_("Unknown stop reply"));
6430 push_stop_reply (stop_reply
);
6434 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
6436 /* We can't get pending events in remote_notif_process for
6437 notification stop, and we have to do this in remote_wait_ns
6438 instead. If we fetch all queued events from stub, remote stub
6439 may exit and we have no chance to process them back in
6441 mark_async_event_handler (remote_async_inferior_event_token
);
6446 stop_reply_dtr (struct notif_event
*event
)
6448 struct stop_reply
*r
= (struct stop_reply
*) event
;
6453 VEC_iterate (cached_reg_t
, r
->regcache
, ix
, reg
);
6457 VEC_free (cached_reg_t
, r
->regcache
);
6460 static struct notif_event
*
6461 remote_notif_stop_alloc_reply (void)
6463 /* We cast to a pointer to the "base class". */
6464 struct notif_event
*r
= (struct notif_event
*) XNEW (struct stop_reply
);
6466 r
->dtr
= stop_reply_dtr
;
6471 /* A client of notification Stop. */
6473 struct notif_client notif_client_stop
=
6477 remote_notif_stop_parse
,
6478 remote_notif_stop_ack
,
6479 remote_notif_stop_can_get_pending_events
,
6480 remote_notif_stop_alloc_reply
,
6484 /* A parameter to pass data in and out. */
6486 struct queue_iter_param
6489 struct stop_reply
*output
;
6492 /* Determine if THREAD_PTID is a pending fork parent thread. ARG contains
6493 the pid of the process that owns the threads we want to check, or
6494 -1 if we want to check all threads. */
6497 is_pending_fork_parent (struct target_waitstatus
*ws
, int event_pid
,
6500 if (ws
->kind
== TARGET_WAITKIND_FORKED
6501 || ws
->kind
== TARGET_WAITKIND_VFORKED
)
6503 if (event_pid
== -1 || event_pid
== ptid_get_pid (thread_ptid
))
6510 /* Return the thread's pending status used to determine whether the
6511 thread is a fork parent stopped at a fork event. */
6513 static struct target_waitstatus
*
6514 thread_pending_fork_status (struct thread_info
*thread
)
6516 if (thread
->suspend
.waitstatus_pending_p
)
6517 return &thread
->suspend
.waitstatus
;
6519 return &thread
->pending_follow
;
6522 /* Determine if THREAD is a pending fork parent thread. */
6525 is_pending_fork_parent_thread (struct thread_info
*thread
)
6527 struct target_waitstatus
*ws
= thread_pending_fork_status (thread
);
6530 return is_pending_fork_parent (ws
, pid
, thread
->ptid
);
6533 /* Check whether EVENT is a fork event, and if it is, remove the
6534 fork child from the context list passed in DATA. */
6537 remove_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
6538 QUEUE_ITER (stop_reply_p
) *iter
,
6542 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6543 struct threads_listing_context
*context
6544 = (struct threads_listing_context
*) param
->input
;
6546 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
6547 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
6548 || event
->ws
.kind
== TARGET_WAITKIND_THREAD_EXITED
)
6549 threads_listing_context_remove (&event
->ws
, context
);
6554 /* If CONTEXT contains any fork child threads that have not been
6555 reported yet, remove them from the CONTEXT list. If such a
6556 thread exists it is because we are stopped at a fork catchpoint
6557 and have not yet called follow_fork, which will set up the
6558 host-side data structures for the new process. */
6561 remove_new_fork_children (struct threads_listing_context
*context
)
6563 struct thread_info
* thread
;
6565 struct notif_client
*notif
= ¬if_client_stop
;
6566 struct queue_iter_param param
;
6568 /* For any threads stopped at a fork event, remove the corresponding
6569 fork child threads from the CONTEXT list. */
6570 ALL_NON_EXITED_THREADS (thread
)
6572 struct target_waitstatus
*ws
= thread_pending_fork_status (thread
);
6574 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
6576 threads_listing_context_remove (ws
, context
);
6580 /* Check for any pending fork events (not reported or processed yet)
6581 in process PID and remove those fork child threads from the
6582 CONTEXT list as well. */
6583 remote_notif_get_pending_events (notif
);
6584 param
.input
= context
;
6585 param
.output
= NULL
;
6586 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6587 remove_child_of_pending_fork
, ¶m
);
6590 /* Check whether EVENT would prevent a global or process wildcard
6594 check_pending_event_prevents_wildcard_vcont_callback
6595 (QUEUE (stop_reply_p
) *q
,
6596 QUEUE_ITER (stop_reply_p
) *iter
,
6600 struct inferior
*inf
;
6601 int *may_global_wildcard_vcont
= (int *) data
;
6603 if (event
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
6604 || event
->ws
.kind
== TARGET_WAITKIND_NO_HISTORY
)
6607 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
6608 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
6609 *may_global_wildcard_vcont
= 0;
6611 inf
= find_inferior_ptid (event
->ptid
);
6613 /* This may be the first time we heard about this process.
6614 Regardless, we must not do a global wildcard resume, otherwise
6615 we'd resume this process too. */
6616 *may_global_wildcard_vcont
= 0;
6618 inf
->priv
->may_wildcard_vcont
= 0;
6623 /* Check whether any event pending in the vStopped queue would prevent
6624 a global or process wildcard vCont action. Clear
6625 *may_global_wildcard if we can't do a global wildcard (vCont;c),
6626 and clear the event inferior's may_wildcard_vcont flag if we can't
6627 do a process-wide wildcard resume (vCont;c:pPID.-1). */
6630 check_pending_events_prevent_wildcard_vcont (int *may_global_wildcard
)
6632 struct notif_client
*notif
= ¬if_client_stop
;
6634 remote_notif_get_pending_events (notif
);
6635 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6636 check_pending_event_prevents_wildcard_vcont_callback
,
6637 may_global_wildcard
);
6640 /* Remove stop replies in the queue if its pid is equal to the given
6644 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
6645 QUEUE_ITER (stop_reply_p
) *iter
,
6649 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6650 struct inferior
*inf
= (struct inferior
*) param
->input
;
6652 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
6654 stop_reply_xfree (event
);
6655 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6661 /* Discard all pending stop replies of inferior INF. */
6664 discard_pending_stop_replies (struct inferior
*inf
)
6666 struct queue_iter_param param
;
6667 struct stop_reply
*reply
;
6668 struct remote_state
*rs
= get_remote_state ();
6669 struct remote_notif_state
*rns
= rs
->notif_state
;
6671 /* This function can be notified when an inferior exists. When the
6672 target is not remote, the notification state is NULL. */
6673 if (rs
->remote_desc
== NULL
)
6676 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
6678 /* Discard the in-flight notification. */
6679 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
6681 stop_reply_xfree (reply
);
6682 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
6686 param
.output
= NULL
;
6687 /* Discard the stop replies we have already pulled with
6689 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6690 remove_stop_reply_for_inferior
, ¶m
);
6693 /* If its remote state is equal to the given remote state,
6694 remove EVENT from the stop reply queue. */
6697 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
6698 QUEUE_ITER (stop_reply_p
) *iter
,
6702 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6703 struct remote_state
*rs
= (struct remote_state
*) param
->input
;
6705 if (event
->rs
== rs
)
6707 stop_reply_xfree (event
);
6708 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6714 /* Discard the stop replies for RS in stop_reply_queue. */
6717 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
6719 struct queue_iter_param param
;
6722 param
.output
= NULL
;
6723 /* Discard the stop replies we have already pulled with
6725 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6726 remove_stop_reply_of_remote_state
, ¶m
);
6729 /* A parameter to pass data in and out. */
6732 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
6733 QUEUE_ITER (stop_reply_p
) *iter
,
6737 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
6738 ptid_t
*ptid
= (ptid_t
*) param
->input
;
6740 if (ptid_match (event
->ptid
, *ptid
))
6742 param
->output
= event
;
6743 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
6750 /* Remove the first reply in 'stop_reply_queue' which matches
6753 static struct stop_reply
*
6754 remote_notif_remove_queued_reply (ptid_t ptid
)
6756 struct queue_iter_param param
;
6758 param
.input
= &ptid
;
6759 param
.output
= NULL
;
6761 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6762 remote_notif_remove_once_on_match
, ¶m
);
6764 fprintf_unfiltered (gdb_stdlog
,
6765 "notif: discard queued event: 'Stop' in %s\n",
6766 target_pid_to_str (ptid
));
6768 return param
.output
;
6771 /* Look for a queued stop reply belonging to PTID. If one is found,
6772 remove it from the queue, and return it. Returns NULL if none is
6773 found. If there are still queued events left to process, tell the
6774 event loop to get back to target_wait soon. */
6776 static struct stop_reply
*
6777 queued_stop_reply (ptid_t ptid
)
6779 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
6781 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6782 /* There's still at least an event left. */
6783 mark_async_event_handler (remote_async_inferior_event_token
);
6788 /* Push a fully parsed stop reply in the stop reply queue. Since we
6789 know that we now have at least one queued event left to pass to the
6790 core side, tell the event loop to get back to target_wait soon. */
6793 push_stop_reply (struct stop_reply
*new_event
)
6795 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
6798 fprintf_unfiltered (gdb_stdlog
,
6799 "notif: push 'Stop' %s to queue %d\n",
6800 target_pid_to_str (new_event
->ptid
),
6801 QUEUE_length (stop_reply_p
,
6804 mark_async_event_handler (remote_async_inferior_event_token
);
6808 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
6809 QUEUE_ITER (stop_reply_p
) *iter
,
6810 struct stop_reply
*event
,
6813 ptid_t
*ptid
= (ptid_t
*) data
;
6815 return !(ptid_equal (*ptid
, event
->ptid
)
6816 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
6819 /* Returns true if we have a stop reply for PTID. */
6822 peek_stop_reply (ptid_t ptid
)
6824 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
6825 stop_reply_match_ptid_and_ws
, &ptid
);
6828 /* Helper for remote_parse_stop_reply. Return nonzero if the substring
6829 starting with P and ending with PEND matches PREFIX. */
6832 strprefix (const char *p
, const char *pend
, const char *prefix
)
6834 for ( ; p
< pend
; p
++, prefix
++)
6837 return *prefix
== '\0';
6840 /* Parse the stop reply in BUF. Either the function succeeds, and the
6841 result is stored in EVENT, or throws an error. */
6844 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
6846 remote_arch_state
*rsa
= NULL
;
6851 event
->ptid
= null_ptid
;
6852 event
->rs
= get_remote_state ();
6853 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
6854 event
->ws
.value
.integer
= 0;
6855 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6856 event
->regcache
= NULL
;
6861 case 'T': /* Status with PC, SP, FP, ... */
6862 /* Expedited reply, containing Signal, {regno, reg} repeat. */
6863 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
6865 n... = register number
6866 r... = register contents
6869 p
= &buf
[3]; /* after Txx */
6875 p1
= strchr (p
, ':');
6877 error (_("Malformed packet(a) (missing colon): %s\n\
6881 error (_("Malformed packet(a) (missing register number): %s\n\
6885 /* Some "registers" are actually extended stop information.
6886 Note if you're adding a new entry here: GDB 7.9 and
6887 earlier assume that all register "numbers" that start
6888 with an hex digit are real register numbers. Make sure
6889 the server only sends such a packet if it knows the
6890 client understands it. */
6892 if (strprefix (p
, p1
, "thread"))
6893 event
->ptid
= read_ptid (++p1
, &p
);
6894 else if (strprefix (p
, p1
, "syscall_entry"))
6898 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_ENTRY
;
6899 p
= unpack_varlen_hex (++p1
, &sysno
);
6900 event
->ws
.value
.syscall_number
= (int) sysno
;
6902 else if (strprefix (p
, p1
, "syscall_return"))
6906 event
->ws
.kind
= TARGET_WAITKIND_SYSCALL_RETURN
;
6907 p
= unpack_varlen_hex (++p1
, &sysno
);
6908 event
->ws
.value
.syscall_number
= (int) sysno
;
6910 else if (strprefix (p
, p1
, "watch")
6911 || strprefix (p
, p1
, "rwatch")
6912 || strprefix (p
, p1
, "awatch"))
6914 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
6915 p
= unpack_varlen_hex (++p1
, &addr
);
6916 event
->watch_data_address
= (CORE_ADDR
) addr
;
6918 else if (strprefix (p
, p1
, "swbreak"))
6920 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
6922 /* Make sure the stub doesn't forget to indicate support
6924 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
6925 error (_("Unexpected swbreak stop reason"));
6927 /* The value part is documented as "must be empty",
6928 though we ignore it, in case we ever decide to make
6929 use of it in a backward compatible way. */
6930 p
= strchrnul (p1
+ 1, ';');
6932 else if (strprefix (p
, p1
, "hwbreak"))
6934 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
6936 /* Make sure the stub doesn't forget to indicate support
6938 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
6939 error (_("Unexpected hwbreak stop reason"));
6942 p
= strchrnul (p1
+ 1, ';');
6944 else if (strprefix (p
, p1
, "library"))
6946 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
6947 p
= strchrnul (p1
+ 1, ';');
6949 else if (strprefix (p
, p1
, "replaylog"))
6951 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
6952 /* p1 will indicate "begin" or "end", but it makes
6953 no difference for now, so ignore it. */
6954 p
= strchrnul (p1
+ 1, ';');
6956 else if (strprefix (p
, p1
, "core"))
6960 p
= unpack_varlen_hex (++p1
, &c
);
6963 else if (strprefix (p
, p1
, "fork"))
6965 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6966 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
6968 else if (strprefix (p
, p1
, "vfork"))
6970 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
6971 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
6973 else if (strprefix (p
, p1
, "vforkdone"))
6975 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
6976 p
= strchrnul (p1
+ 1, ';');
6978 else if (strprefix (p
, p1
, "exec"))
6981 char pathname
[PATH_MAX
];
6984 /* Determine the length of the execd pathname. */
6985 p
= unpack_varlen_hex (++p1
, &ignored
);
6986 pathlen
= (p
- p1
) / 2;
6988 /* Save the pathname for event reporting and for
6989 the next run command. */
6990 hex2bin (p1
, (gdb_byte
*) pathname
, pathlen
);
6991 pathname
[pathlen
] = '\0';
6993 /* This is freed during event handling. */
6994 event
->ws
.value
.execd_pathname
= xstrdup (pathname
);
6995 event
->ws
.kind
= TARGET_WAITKIND_EXECD
;
6997 /* Skip the registers included in this packet, since
6998 they may be for an architecture different from the
6999 one used by the original program. */
7002 else if (strprefix (p
, p1
, "create"))
7004 event
->ws
.kind
= TARGET_WAITKIND_THREAD_CREATED
;
7005 p
= strchrnul (p1
+ 1, ';');
7014 p
= strchrnul (p1
+ 1, ';');
7019 /* Maybe a real ``P'' register number. */
7020 p_temp
= unpack_varlen_hex (p
, &pnum
);
7021 /* If the first invalid character is the colon, we got a
7022 register number. Otherwise, it's an unknown stop
7026 /* If we haven't parsed the event's thread yet, find
7027 it now, in order to find the architecture of the
7028 reported expedited registers. */
7029 if (event
->ptid
== null_ptid
)
7031 const char *thr
= strstr (p1
+ 1, ";thread:");
7033 event
->ptid
= read_ptid (thr
+ strlen (";thread:"),
7036 event
->ptid
= magic_null_ptid
;
7041 inferior
*inf
= (event
->ptid
== null_ptid
7043 : find_inferior_ptid (event
->ptid
));
7044 /* If this is the first time we learn anything
7045 about this process, skip the registers
7046 included in this packet, since we don't yet
7047 know which architecture to use to parse them.
7048 We'll determine the architecture later when
7049 we process the stop reply and retrieve the
7050 target description, via
7051 remote_notice_new_inferior ->
7052 post_create_inferior. */
7055 p
= strchrnul (p1
+ 1, ';');
7060 event
->arch
= inf
->gdbarch
;
7061 rsa
= get_remote_arch_state (event
->arch
);
7065 = packet_reg_from_pnum (event
->arch
, rsa
, pnum
);
7066 cached_reg_t cached_reg
;
7069 error (_("Remote sent bad register number %s: %s\n\
7071 hex_string (pnum
), p
, buf
);
7073 cached_reg
.num
= reg
->regnum
;
7074 cached_reg
.data
= (gdb_byte
*)
7075 xmalloc (register_size (event
->arch
, reg
->regnum
));
7078 fieldsize
= hex2bin (p
, cached_reg
.data
,
7079 register_size (event
->arch
, reg
->regnum
));
7081 if (fieldsize
< register_size (event
->arch
, reg
->regnum
))
7082 warning (_("Remote reply is too short: %s"), buf
);
7084 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
7088 /* Not a number. Silently skip unknown optional
7090 p
= strchrnul (p1
+ 1, ';');
7095 error (_("Remote register badly formatted: %s\nhere: %s"),
7100 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
7104 case 'S': /* Old style status, just signal only. */
7108 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
7109 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
7110 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
7111 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
7113 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
7116 case 'w': /* Thread exited. */
7121 event
->ws
.kind
= TARGET_WAITKIND_THREAD_EXITED
;
7122 p
= unpack_varlen_hex (&buf
[1], &value
);
7123 event
->ws
.value
.integer
= value
;
7125 error (_("stop reply packet badly formatted: %s"), buf
);
7126 event
->ptid
= read_ptid (++p
, NULL
);
7129 case 'W': /* Target exited. */
7136 /* GDB used to accept only 2 hex chars here. Stubs should
7137 only send more if they detect GDB supports multi-process
7139 p
= unpack_varlen_hex (&buf
[1], &value
);
7143 /* The remote process exited. */
7144 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
7145 event
->ws
.value
.integer
= value
;
7149 /* The remote process exited with a signal. */
7150 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
7151 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
7152 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
7154 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
7157 /* If no process is specified, assume inferior_ptid. */
7158 pid
= ptid_get_pid (inferior_ptid
);
7167 else if (startswith (p
, "process:"))
7171 p
+= sizeof ("process:") - 1;
7172 unpack_varlen_hex (p
, &upid
);
7176 error (_("unknown stop reply packet: %s"), buf
);
7179 error (_("unknown stop reply packet: %s"), buf
);
7180 event
->ptid
= pid_to_ptid (pid
);
7184 event
->ws
.kind
= TARGET_WAITKIND_NO_RESUMED
;
7185 event
->ptid
= minus_one_ptid
;
7189 if (target_is_non_stop_p () && ptid_equal (event
->ptid
, null_ptid
))
7190 error (_("No process or thread specified in stop reply: %s"), buf
);
7193 /* When the stub wants to tell GDB about a new notification reply, it
7194 sends a notification (%Stop, for example). Those can come it at
7195 any time, hence, we have to make sure that any pending
7196 putpkt/getpkt sequence we're making is finished, before querying
7197 the stub for more events with the corresponding ack command
7198 (vStopped, for example). E.g., if we started a vStopped sequence
7199 immediately upon receiving the notification, something like this
7207 1.6) <-- (registers reply to step #1.3)
7209 Obviously, the reply in step #1.6 would be unexpected to a vStopped
7212 To solve this, whenever we parse a %Stop notification successfully,
7213 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
7214 doing whatever we were doing:
7220 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
7221 2.5) <-- (registers reply to step #2.3)
7223 Eventualy after step #2.5, we return to the event loop, which
7224 notices there's an event on the
7225 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
7226 associated callback --- the function below. At this point, we're
7227 always safe to start a vStopped sequence. :
7230 2.7) <-- T05 thread:2
7236 remote_notif_get_pending_events (struct notif_client
*nc
)
7238 struct remote_state
*rs
= get_remote_state ();
7240 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
7243 fprintf_unfiltered (gdb_stdlog
,
7244 "notif: process: '%s' ack pending event\n",
7248 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
7249 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
7253 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7254 if (strcmp (rs
->buf
, "OK") == 0)
7257 remote_notif_ack (nc
, rs
->buf
);
7263 fprintf_unfiltered (gdb_stdlog
,
7264 "notif: process: '%s' no pending reply\n",
7269 /* Called when it is decided that STOP_REPLY holds the info of the
7270 event that is to be returned to the core. This function always
7271 destroys STOP_REPLY. */
7274 process_stop_reply (struct stop_reply
*stop_reply
,
7275 struct target_waitstatus
*status
)
7279 *status
= stop_reply
->ws
;
7280 ptid
= stop_reply
->ptid
;
7282 /* If no thread/process was reported by the stub, assume the current
7284 if (ptid_equal (ptid
, null_ptid
))
7285 ptid
= inferior_ptid
;
7287 if (status
->kind
!= TARGET_WAITKIND_EXITED
7288 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
7289 && status
->kind
!= TARGET_WAITKIND_NO_RESUMED
)
7291 struct private_thread_info
*remote_thr
;
7293 /* Expedited registers. */
7294 if (stop_reply
->regcache
)
7296 struct regcache
*regcache
7297 = get_thread_arch_regcache (ptid
, stop_reply
->arch
);
7302 VEC_iterate (cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
7305 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
7309 VEC_free (cached_reg_t
, stop_reply
->regcache
);
7312 remote_notice_new_inferior (ptid
, 0);
7313 remote_thr
= get_private_info_ptid (ptid
);
7314 remote_thr
->core
= stop_reply
->core
;
7315 remote_thr
->stop_reason
= stop_reply
->stop_reason
;
7316 remote_thr
->watch_data_address
= stop_reply
->watch_data_address
;
7317 remote_thr
->vcont_resumed
= 0;
7320 stop_reply_xfree (stop_reply
);
7324 /* The non-stop mode version of target_wait. */
7327 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7329 struct remote_state
*rs
= get_remote_state ();
7330 struct stop_reply
*stop_reply
;
7334 /* If in non-stop mode, get out of getpkt even if a
7335 notification is received. */
7337 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
7338 0 /* forever */, &is_notif
);
7341 if (ret
!= -1 && !is_notif
)
7344 case 'E': /* Error of some sort. */
7345 /* We're out of sync with the target now. Did it continue
7346 or not? We can't tell which thread it was in non-stop,
7347 so just ignore this. */
7348 warning (_("Remote failure reply: %s"), rs
->buf
);
7350 case 'O': /* Console output. */
7351 remote_console_output (rs
->buf
+ 1);
7354 warning (_("Invalid remote reply: %s"), rs
->buf
);
7358 /* Acknowledge a pending stop reply that may have arrived in the
7360 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
7361 remote_notif_get_pending_events (¬if_client_stop
);
7363 /* If indeed we noticed a stop reply, we're done. */
7364 stop_reply
= queued_stop_reply (ptid
);
7365 if (stop_reply
!= NULL
)
7366 return process_stop_reply (stop_reply
, status
);
7368 /* Still no event. If we're just polling for an event, then
7369 return to the event loop. */
7370 if (options
& TARGET_WNOHANG
)
7372 status
->kind
= TARGET_WAITKIND_IGNORE
;
7373 return minus_one_ptid
;
7376 /* Otherwise do a blocking wait. */
7377 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
7378 1 /* forever */, &is_notif
);
7382 /* Wait until the remote machine stops, then return, storing status in
7383 STATUS just as `wait' would. */
7386 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7388 struct remote_state
*rs
= get_remote_state ();
7389 ptid_t event_ptid
= null_ptid
;
7391 struct stop_reply
*stop_reply
;
7395 status
->kind
= TARGET_WAITKIND_IGNORE
;
7396 status
->value
.integer
= 0;
7398 stop_reply
= queued_stop_reply (ptid
);
7399 if (stop_reply
!= NULL
)
7400 return process_stop_reply (stop_reply
, status
);
7402 if (rs
->cached_wait_status
)
7403 /* Use the cached wait status, but only once. */
7404 rs
->cached_wait_status
= 0;
7409 int forever
= ((options
& TARGET_WNOHANG
) == 0
7410 && wait_forever_enabled_p
);
7412 if (!rs
->waiting_for_stop_reply
)
7414 status
->kind
= TARGET_WAITKIND_NO_RESUMED
;
7415 return minus_one_ptid
;
7418 /* FIXME: cagney/1999-09-27: If we're in async mode we should
7419 _never_ wait for ever -> test on target_is_async_p().
7420 However, before we do that we need to ensure that the caller
7421 knows how to take the target into/out of async mode. */
7422 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
7423 forever
, &is_notif
);
7425 /* GDB gets a notification. Return to core as this event is
7427 if (ret
!= -1 && is_notif
)
7428 return minus_one_ptid
;
7430 if (ret
== -1 && (options
& TARGET_WNOHANG
) != 0)
7431 return minus_one_ptid
;
7436 /* Assume that the target has acknowledged Ctrl-C unless we receive
7437 an 'F' or 'O' packet. */
7438 if (buf
[0] != 'F' && buf
[0] != 'O')
7439 rs
->ctrlc_pending_p
= 0;
7443 case 'E': /* Error of some sort. */
7444 /* We're out of sync with the target now. Did it continue or
7445 not? Not is more likely, so report a stop. */
7446 rs
->waiting_for_stop_reply
= 0;
7448 warning (_("Remote failure reply: %s"), buf
);
7449 status
->kind
= TARGET_WAITKIND_STOPPED
;
7450 status
->value
.sig
= GDB_SIGNAL_0
;
7452 case 'F': /* File-I/O request. */
7453 /* GDB may access the inferior memory while handling the File-I/O
7454 request, but we don't want GDB accessing memory while waiting
7455 for a stop reply. See the comments in putpkt_binary. Set
7456 waiting_for_stop_reply to 0 temporarily. */
7457 rs
->waiting_for_stop_reply
= 0;
7458 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
7459 rs
->ctrlc_pending_p
= 0;
7460 /* GDB handled the File-I/O request, and the target is running
7461 again. Keep waiting for events. */
7462 rs
->waiting_for_stop_reply
= 1;
7464 case 'N': case 'T': case 'S': case 'X': case 'W':
7466 struct stop_reply
*stop_reply
;
7468 /* There is a stop reply to handle. */
7469 rs
->waiting_for_stop_reply
= 0;
7472 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
7475 event_ptid
= process_stop_reply (stop_reply
, status
);
7478 case 'O': /* Console output. */
7479 remote_console_output (buf
+ 1);
7482 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
7484 /* Zero length reply means that we tried 'S' or 'C' and the
7485 remote system doesn't support it. */
7486 target_terminal::ours_for_output ();
7488 ("Can't send signals to this remote system. %s not sent.\n",
7489 gdb_signal_to_name (rs
->last_sent_signal
));
7490 rs
->last_sent_signal
= GDB_SIGNAL_0
;
7491 target_terminal::inferior ();
7493 strcpy (buf
, rs
->last_sent_step
? "s" : "c");
7497 /* else fallthrough */
7499 warning (_("Invalid remote reply: %s"), buf
);
7503 if (status
->kind
== TARGET_WAITKIND_NO_RESUMED
)
7504 return minus_one_ptid
;
7505 else if (status
->kind
== TARGET_WAITKIND_IGNORE
)
7507 /* Nothing interesting happened. If we're doing a non-blocking
7508 poll, we're done. Otherwise, go back to waiting. */
7509 if (options
& TARGET_WNOHANG
)
7510 return minus_one_ptid
;
7514 else if (status
->kind
!= TARGET_WAITKIND_EXITED
7515 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
7517 if (!ptid_equal (event_ptid
, null_ptid
))
7518 record_currthread (rs
, event_ptid
);
7520 event_ptid
= inferior_ptid
;
7523 /* A process exit. Invalidate our notion of current thread. */
7524 record_currthread (rs
, minus_one_ptid
);
7529 /* Wait until the remote machine stops, then return, storing status in
7530 STATUS just as `wait' would. */
7533 remote_wait (struct target_ops
*ops
,
7534 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
7538 if (target_is_non_stop_p ())
7539 event_ptid
= remote_wait_ns (ptid
, status
, options
);
7541 event_ptid
= remote_wait_as (ptid
, status
, options
);
7543 if (target_is_async_p ())
7545 /* If there are are events left in the queue tell the event loop
7547 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
7548 mark_async_event_handler (remote_async_inferior_event_token
);
7554 /* Fetch a single register using a 'p' packet. */
7557 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
7559 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7560 struct remote_state
*rs
= get_remote_state ();
7562 gdb_byte
*regp
= (gdb_byte
*) alloca (register_size (gdbarch
, reg
->regnum
));
7565 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
7568 if (reg
->pnum
== -1)
7573 p
+= hexnumstr (p
, reg
->pnum
);
7576 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7580 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
7584 case PACKET_UNKNOWN
:
7587 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
7588 gdbarch_register_name (get_regcache_arch (regcache
),
7593 /* If this register is unfetchable, tell the regcache. */
7596 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7600 /* Otherwise, parse and supply the value. */
7606 error (_("fetch_register_using_p: early buf termination"));
7608 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7611 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
7615 /* Fetch the registers included in the target's 'g' packet. */
7618 send_g_packet (void)
7620 struct remote_state
*rs
= get_remote_state ();
7623 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
7624 remote_send (&rs
->buf
, &rs
->buf_size
);
7626 /* We can get out of synch in various cases. If the first character
7627 in the buffer is not a hex character, assume that has happened
7628 and try to fetch another packet to read. */
7629 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
7630 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
7631 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
7632 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
7635 fprintf_unfiltered (gdb_stdlog
,
7636 "Bad register packet; fetching a new packet\n");
7637 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7640 buf_len
= strlen (rs
->buf
);
7642 /* Sanity check the received packet. */
7643 if (buf_len
% 2 != 0)
7644 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
7650 process_g_packet (struct regcache
*regcache
)
7652 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7653 struct remote_state
*rs
= get_remote_state ();
7654 remote_arch_state
*rsa
= get_remote_arch_state (gdbarch
);
7659 buf_len
= strlen (rs
->buf
);
7661 /* Further sanity checks, with knowledge of the architecture. */
7662 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
7663 error (_("Remote 'g' packet reply is too long (expected %ld bytes, got %d "
7664 "bytes): %s"), rsa
->sizeof_g_packet
, buf_len
/ 2, rs
->buf
);
7666 /* Save the size of the packet sent to us by the target. It is used
7667 as a heuristic when determining the max size of packets that the
7668 target can safely receive. */
7669 if (rsa
->actual_register_packet_size
== 0)
7670 rsa
->actual_register_packet_size
= buf_len
;
7672 /* If this is smaller than we guessed the 'g' packet would be,
7673 update our records. A 'g' reply that doesn't include a register's
7674 value implies either that the register is not available, or that
7675 the 'p' packet must be used. */
7676 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
7678 long sizeof_g_packet
= buf_len
/ 2;
7680 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7682 long offset
= rsa
->regs
[i
].offset
;
7683 long reg_size
= register_size (gdbarch
, i
);
7685 if (rsa
->regs
[i
].pnum
== -1)
7688 if (offset
>= sizeof_g_packet
)
7689 rsa
->regs
[i
].in_g_packet
= 0;
7690 else if (offset
+ reg_size
> sizeof_g_packet
)
7691 error (_("Truncated register %d in remote 'g' packet"), i
);
7693 rsa
->regs
[i
].in_g_packet
= 1;
7696 /* Looks valid enough, we can assume this is the correct length
7697 for a 'g' packet. It's important not to adjust
7698 rsa->sizeof_g_packet if we have truncated registers otherwise
7699 this "if" won't be run the next time the method is called
7700 with a packet of the same size and one of the internal errors
7701 below will trigger instead. */
7702 rsa
->sizeof_g_packet
= sizeof_g_packet
;
7705 regs
= (char *) alloca (rsa
->sizeof_g_packet
);
7707 /* Unimplemented registers read as all bits zero. */
7708 memset (regs
, 0, rsa
->sizeof_g_packet
);
7710 /* Reply describes registers byte by byte, each byte encoded as two
7711 hex characters. Suck them all up, then supply them to the
7712 register cacheing/storage mechanism. */
7715 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
7717 if (p
[0] == 0 || p
[1] == 0)
7718 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
7719 internal_error (__FILE__
, __LINE__
,
7720 _("unexpected end of 'g' packet reply"));
7722 if (p
[0] == 'x' && p
[1] == 'x')
7723 regs
[i
] = 0; /* 'x' */
7725 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
7729 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7731 struct packet_reg
*r
= &rsa
->regs
[i
];
7732 long reg_size
= register_size (gdbarch
, i
);
7736 if ((r
->offset
+ reg_size
) * 2 > strlen (rs
->buf
))
7737 /* This shouldn't happen - we adjusted in_g_packet above. */
7738 internal_error (__FILE__
, __LINE__
,
7739 _("unexpected end of 'g' packet reply"));
7740 else if (rs
->buf
[r
->offset
* 2] == 'x')
7742 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
7743 /* The register isn't available, mark it as such (at
7744 the same time setting the value to zero). */
7745 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
7748 regcache_raw_supply (regcache
, r
->regnum
,
7755 fetch_registers_using_g (struct regcache
*regcache
)
7758 process_g_packet (regcache
);
7761 /* Make the remote selected traceframe match GDB's selected
7765 set_remote_traceframe (void)
7768 struct remote_state
*rs
= get_remote_state ();
7770 if (rs
->remote_traceframe_number
== get_traceframe_number ())
7773 /* Avoid recursion, remote_trace_find calls us again. */
7774 rs
->remote_traceframe_number
= get_traceframe_number ();
7776 newnum
= target_trace_find (tfind_number
,
7777 get_traceframe_number (), 0, 0, NULL
);
7779 /* Should not happen. If it does, all bets are off. */
7780 if (newnum
!= get_traceframe_number ())
7781 warning (_("could not set remote traceframe"));
7785 remote_fetch_registers (struct target_ops
*ops
,
7786 struct regcache
*regcache
, int regnum
)
7788 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7789 remote_arch_state
*rsa
= get_remote_arch_state (gdbarch
);
7792 set_remote_traceframe ();
7793 set_general_thread (regcache_get_ptid (regcache
));
7797 packet_reg
*reg
= packet_reg_from_regnum (gdbarch
, rsa
, regnum
);
7799 gdb_assert (reg
!= NULL
);
7801 /* If this register might be in the 'g' packet, try that first -
7802 we are likely to read more than one register. If this is the
7803 first 'g' packet, we might be overly optimistic about its
7804 contents, so fall back to 'p'. */
7805 if (reg
->in_g_packet
)
7807 fetch_registers_using_g (regcache
);
7808 if (reg
->in_g_packet
)
7812 if (fetch_register_using_p (regcache
, reg
))
7815 /* This register is not available. */
7816 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
7821 fetch_registers_using_g (regcache
);
7823 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7824 if (!rsa
->regs
[i
].in_g_packet
)
7825 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
7827 /* This register is not available. */
7828 regcache_raw_supply (regcache
, i
, NULL
);
7832 /* Prepare to store registers. Since we may send them all (using a
7833 'G' request), we have to read out the ones we don't want to change
7837 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
7839 remote_arch_state
*rsa
= get_remote_arch_state (regcache
->arch ());
7842 /* Make sure the entire registers array is valid. */
7843 switch (packet_support (PACKET_P
))
7845 case PACKET_DISABLE
:
7846 case PACKET_SUPPORT_UNKNOWN
:
7847 /* Make sure all the necessary registers are cached. */
7848 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7849 if (rsa
->regs
[i
].in_g_packet
)
7850 regcache_raw_update (regcache
, rsa
->regs
[i
].regnum
);
7857 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
7858 packet was not recognized. */
7861 store_register_using_P (const struct regcache
*regcache
,
7862 struct packet_reg
*reg
)
7864 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7865 struct remote_state
*rs
= get_remote_state ();
7866 /* Try storing a single register. */
7867 char *buf
= rs
->buf
;
7868 gdb_byte
*regp
= (gdb_byte
*) alloca (register_size (gdbarch
, reg
->regnum
));
7871 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
7874 if (reg
->pnum
== -1)
7877 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
7878 p
= buf
+ strlen (buf
);
7879 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
7880 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
7882 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7884 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
7889 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
7890 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
7891 case PACKET_UNKNOWN
:
7894 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
7898 /* Store register REGNUM, or all registers if REGNUM == -1, from the
7899 contents of the register cache buffer. FIXME: ignores errors. */
7902 store_registers_using_G (const struct regcache
*regcache
)
7904 struct remote_state
*rs
= get_remote_state ();
7905 remote_arch_state
*rsa
= get_remote_arch_state (regcache
->arch ());
7909 /* Extract all the registers in the regcache copying them into a
7914 regs
= (gdb_byte
*) alloca (rsa
->sizeof_g_packet
);
7915 memset (regs
, 0, rsa
->sizeof_g_packet
);
7916 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
7918 struct packet_reg
*r
= &rsa
->regs
[i
];
7921 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
7925 /* Command describes registers byte by byte,
7926 each byte encoded as two hex characters. */
7929 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
7931 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7932 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
7933 error (_("Could not write registers; remote failure reply '%s'"),
7937 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
7938 of the register cache buffer. FIXME: ignores errors. */
7941 remote_store_registers (struct target_ops
*ops
,
7942 struct regcache
*regcache
, int regnum
)
7944 struct gdbarch
*gdbarch
= regcache
->arch ();
7945 remote_arch_state
*rsa
= get_remote_arch_state (gdbarch
);
7948 set_remote_traceframe ();
7949 set_general_thread (regcache_get_ptid (regcache
));
7953 packet_reg
*reg
= packet_reg_from_regnum (gdbarch
, rsa
, regnum
);
7955 gdb_assert (reg
!= NULL
);
7957 /* Always prefer to store registers using the 'P' packet if
7958 possible; we often change only a small number of registers.
7959 Sometimes we change a larger number; we'd need help from a
7960 higher layer to know to use 'G'. */
7961 if (store_register_using_P (regcache
, reg
))
7964 /* For now, don't complain if we have no way to write the
7965 register. GDB loses track of unavailable registers too
7966 easily. Some day, this may be an error. We don't have
7967 any way to read the register, either... */
7968 if (!reg
->in_g_packet
)
7971 store_registers_using_G (regcache
);
7975 store_registers_using_G (regcache
);
7977 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
7978 if (!rsa
->regs
[i
].in_g_packet
)
7979 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
7980 /* See above for why we do not issue an error here. */
7985 /* Return the number of hex digits in num. */
7988 hexnumlen (ULONGEST num
)
7992 for (i
= 0; num
!= 0; i
++)
7995 return std::max (i
, 1);
7998 /* Set BUF to the minimum number of hex digits representing NUM. */
8001 hexnumstr (char *buf
, ULONGEST num
)
8003 int len
= hexnumlen (num
);
8005 return hexnumnstr (buf
, num
, len
);
8009 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
8012 hexnumnstr (char *buf
, ULONGEST num
, int width
)
8018 for (i
= width
- 1; i
>= 0; i
--)
8020 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
8027 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
8030 remote_address_masked (CORE_ADDR addr
)
8032 unsigned int address_size
= remote_address_size
;
8034 /* If "remoteaddresssize" was not set, default to target address size. */
8036 address_size
= gdbarch_addr_bit (target_gdbarch ());
8038 if (address_size
> 0
8039 && address_size
< (sizeof (ULONGEST
) * 8))
8041 /* Only create a mask when that mask can safely be constructed
8042 in a ULONGEST variable. */
8045 mask
= (mask
<< address_size
) - 1;
8051 /* Determine whether the remote target supports binary downloading.
8052 This is accomplished by sending a no-op memory write of zero length
8053 to the target at the specified address. It does not suffice to send
8054 the whole packet, since many stubs strip the eighth bit and
8055 subsequently compute a wrong checksum, which causes real havoc with
8058 NOTE: This can still lose if the serial line is not eight-bit
8059 clean. In cases like this, the user should clear "remote
8063 check_binary_download (CORE_ADDR addr
)
8065 struct remote_state
*rs
= get_remote_state ();
8067 switch (packet_support (PACKET_X
))
8069 case PACKET_DISABLE
:
8073 case PACKET_SUPPORT_UNKNOWN
:
8079 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8081 p
+= hexnumstr (p
, (ULONGEST
) 0);
8085 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
8086 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8088 if (rs
->buf
[0] == '\0')
8091 fprintf_unfiltered (gdb_stdlog
,
8092 "binary downloading NOT "
8093 "supported by target\n");
8094 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
8099 fprintf_unfiltered (gdb_stdlog
,
8100 "binary downloading supported by target\n");
8101 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
8108 /* Helper function to resize the payload in order to try to get a good
8109 alignment. We try to write an amount of data such that the next write will
8110 start on an address aligned on REMOTE_ALIGN_WRITES. */
8113 align_for_efficient_write (int todo
, CORE_ADDR memaddr
)
8115 return ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
8118 /* Write memory data directly to the remote machine.
8119 This does not inform the data cache; the data cache uses this.
8120 HEADER is the starting part of the packet.
8121 MEMADDR is the address in the remote memory space.
8122 MYADDR is the address of the buffer in our space.
8123 LEN_UNITS is the number of addressable units to write.
8124 UNIT_SIZE is the length in bytes of an addressable unit.
8125 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
8126 should send data as binary ('X'), or hex-encoded ('M').
8128 The function creates packet of the form
8129 <HEADER><ADDRESS>,<LENGTH>:<DATA>
8131 where encoding of <DATA> is terminated by PACKET_FORMAT.
8133 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
8136 Return the transferred status, error or OK (an
8137 'enum target_xfer_status' value). Save the number of addressable units
8138 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
8140 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
8141 exchange between gdb and the stub could look like (?? in place of the
8147 -> $M1000,3:eeeeffffeeee#??
8151 <- eeeeffffeeeedddd */
8153 static enum target_xfer_status
8154 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
8155 const gdb_byte
*myaddr
, ULONGEST len_units
,
8156 int unit_size
, ULONGEST
*xfered_len_units
,
8157 char packet_format
, int use_length
)
8159 struct remote_state
*rs
= get_remote_state ();
8165 int payload_capacity_bytes
;
8166 int payload_length_bytes
;
8168 if (packet_format
!= 'X' && packet_format
!= 'M')
8169 internal_error (__FILE__
, __LINE__
,
8170 _("remote_write_bytes_aux: bad packet format"));
8173 return TARGET_XFER_EOF
;
8175 payload_capacity_bytes
= get_memory_write_packet_size ();
8177 /* The packet buffer will be large enough for the payload;
8178 get_memory_packet_size ensures this. */
8181 /* Compute the size of the actual payload by subtracting out the
8182 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
8184 payload_capacity_bytes
-= strlen ("$,:#NN");
8186 /* The comma won't be used. */
8187 payload_capacity_bytes
+= 1;
8188 payload_capacity_bytes
-= strlen (header
);
8189 payload_capacity_bytes
-= hexnumlen (memaddr
);
8191 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
8193 strcat (rs
->buf
, header
);
8194 p
= rs
->buf
+ strlen (header
);
8196 /* Compute a best guess of the number of bytes actually transfered. */
8197 if (packet_format
== 'X')
8199 /* Best guess at number of bytes that will fit. */
8200 todo_units
= std::min (len_units
,
8201 (ULONGEST
) payload_capacity_bytes
/ unit_size
);
8203 payload_capacity_bytes
-= hexnumlen (todo_units
);
8204 todo_units
= std::min (todo_units
, payload_capacity_bytes
/ unit_size
);
8208 /* Number of bytes that will fit. */
8210 = std::min (len_units
,
8211 (ULONGEST
) (payload_capacity_bytes
/ unit_size
) / 2);
8213 payload_capacity_bytes
-= hexnumlen (todo_units
);
8214 todo_units
= std::min (todo_units
,
8215 (payload_capacity_bytes
/ unit_size
) / 2);
8218 if (todo_units
<= 0)
8219 internal_error (__FILE__
, __LINE__
,
8220 _("minimum packet size too small to write data"));
8222 /* If we already need another packet, then try to align the end
8223 of this packet to a useful boundary. */
8224 if (todo_units
> 2 * REMOTE_ALIGN_WRITES
&& todo_units
< len_units
)
8225 todo_units
= align_for_efficient_write (todo_units
, memaddr
);
8227 /* Append "<memaddr>". */
8228 memaddr
= remote_address_masked (memaddr
);
8229 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
8236 /* Append the length and retain its location and size. It may need to be
8237 adjusted once the packet body has been created. */
8239 plenlen
= hexnumstr (p
, (ULONGEST
) todo_units
);
8247 /* Append the packet body. */
8248 if (packet_format
== 'X')
8250 /* Binary mode. Send target system values byte by byte, in
8251 increasing byte addresses. Only escape certain critical
8253 payload_length_bytes
=
8254 remote_escape_output (myaddr
, todo_units
, unit_size
, (gdb_byte
*) p
,
8255 &units_written
, payload_capacity_bytes
);
8257 /* If not all TODO units fit, then we'll need another packet. Make
8258 a second try to keep the end of the packet aligned. Don't do
8259 this if the packet is tiny. */
8260 if (units_written
< todo_units
&& units_written
> 2 * REMOTE_ALIGN_WRITES
)
8264 new_todo_units
= align_for_efficient_write (units_written
, memaddr
);
8266 if (new_todo_units
!= units_written
)
8267 payload_length_bytes
=
8268 remote_escape_output (myaddr
, new_todo_units
, unit_size
,
8269 (gdb_byte
*) p
, &units_written
,
8270 payload_capacity_bytes
);
8273 p
+= payload_length_bytes
;
8274 if (use_length
&& units_written
< todo_units
)
8276 /* Escape chars have filled up the buffer prematurely,
8277 and we have actually sent fewer units than planned.
8278 Fix-up the length field of the packet. Use the same
8279 number of characters as before. */
8280 plen
+= hexnumnstr (plen
, (ULONGEST
) units_written
,
8282 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
8287 /* Normal mode: Send target system values byte by byte, in
8288 increasing byte addresses. Each byte is encoded as a two hex
8290 p
+= 2 * bin2hex (myaddr
, p
, todo_units
* unit_size
);
8291 units_written
= todo_units
;
8294 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
8295 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8297 if (rs
->buf
[0] == 'E')
8298 return TARGET_XFER_E_IO
;
8300 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
8301 send fewer units than we'd planned. */
8302 *xfered_len_units
= (ULONGEST
) units_written
;
8303 return TARGET_XFER_OK
;
8306 /* Write memory data directly to the remote machine.
8307 This does not inform the data cache; the data cache uses this.
8308 MEMADDR is the address in the remote memory space.
8309 MYADDR is the address of the buffer in our space.
8310 LEN is the number of bytes.
8312 Return the transferred status, error or OK (an
8313 'enum target_xfer_status' value). Save the number of bytes
8314 transferred in *XFERED_LEN. Only transfer a single packet. */
8316 static enum target_xfer_status
8317 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
8318 int unit_size
, ULONGEST
*xfered_len
)
8320 const char *packet_format
= NULL
;
8322 /* Check whether the target supports binary download. */
8323 check_binary_download (memaddr
);
8325 switch (packet_support (PACKET_X
))
8328 packet_format
= "X";
8330 case PACKET_DISABLE
:
8331 packet_format
= "M";
8333 case PACKET_SUPPORT_UNKNOWN
:
8334 internal_error (__FILE__
, __LINE__
,
8335 _("remote_write_bytes: bad internal state"));
8337 internal_error (__FILE__
, __LINE__
, _("bad switch"));
8340 return remote_write_bytes_aux (packet_format
,
8341 memaddr
, myaddr
, len
, unit_size
, xfered_len
,
8342 packet_format
[0], 1);
8345 /* Read memory data directly from the remote machine.
8346 This does not use the data cache; the data cache uses this.
8347 MEMADDR is the address in the remote memory space.
8348 MYADDR is the address of the buffer in our space.
8349 LEN_UNITS is the number of addressable memory units to read..
8350 UNIT_SIZE is the length in bytes of an addressable unit.
8352 Return the transferred status, error or OK (an
8353 'enum target_xfer_status' value). Save the number of bytes
8354 transferred in *XFERED_LEN_UNITS.
8356 See the comment of remote_write_bytes_aux for an example of
8357 memory read/write exchange between gdb and the stub. */
8359 static enum target_xfer_status
8360 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len_units
,
8361 int unit_size
, ULONGEST
*xfered_len_units
)
8363 struct remote_state
*rs
= get_remote_state ();
8364 int buf_size_bytes
; /* Max size of packet output buffer. */
8369 buf_size_bytes
= get_memory_read_packet_size ();
8370 /* The packet buffer will be large enough for the payload;
8371 get_memory_packet_size ensures this. */
8373 /* Number of units that will fit. */
8374 todo_units
= std::min (len_units
,
8375 (ULONGEST
) (buf_size_bytes
/ unit_size
) / 2);
8377 /* Construct "m"<memaddr>","<len>". */
8378 memaddr
= remote_address_masked (memaddr
);
8381 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
8383 p
+= hexnumstr (p
, (ULONGEST
) todo_units
);
8386 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8387 if (rs
->buf
[0] == 'E'
8388 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
8389 && rs
->buf
[3] == '\0')
8390 return TARGET_XFER_E_IO
;
8391 /* Reply describes memory byte by byte, each byte encoded as two hex
8394 decoded_bytes
= hex2bin (p
, myaddr
, todo_units
* unit_size
);
8395 /* Return what we have. Let higher layers handle partial reads. */
8396 *xfered_len_units
= (ULONGEST
) (decoded_bytes
/ unit_size
);
8397 return TARGET_XFER_OK
;
8400 /* Using the set of read-only target sections of remote, read live
8403 For interface/parameters/return description see target.h,
8406 static enum target_xfer_status
8407 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
8408 ULONGEST memaddr
, ULONGEST len
,
8409 int unit_size
, ULONGEST
*xfered_len
)
8411 struct target_section
*secp
;
8412 struct target_section_table
*table
;
8414 secp
= target_section_by_addr (ops
, memaddr
);
8416 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
8417 secp
->the_bfd_section
)
8420 struct target_section
*p
;
8421 ULONGEST memend
= memaddr
+ len
;
8423 table
= target_get_section_table (ops
);
8425 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
8427 if (memaddr
>= p
->addr
)
8429 if (memend
<= p
->endaddr
)
8431 /* Entire transfer is within this section. */
8432 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
8435 else if (memaddr
>= p
->endaddr
)
8437 /* This section ends before the transfer starts. */
8442 /* This section overlaps the transfer. Just do half. */
8443 len
= p
->endaddr
- memaddr
;
8444 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
8451 return TARGET_XFER_EOF
;
8454 /* Similar to remote_read_bytes_1, but it reads from the remote stub
8455 first if the requested memory is unavailable in traceframe.
8456 Otherwise, fall back to remote_read_bytes_1. */
8458 static enum target_xfer_status
8459 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
8460 gdb_byte
*myaddr
, ULONGEST len
, int unit_size
,
8461 ULONGEST
*xfered_len
)
8464 return TARGET_XFER_EOF
;
8466 if (get_traceframe_number () != -1)
8468 std::vector
<mem_range
> available
;
8470 /* If we fail to get the set of available memory, then the
8471 target does not support querying traceframe info, and so we
8472 attempt reading from the traceframe anyway (assuming the
8473 target implements the old QTro packet then). */
8474 if (traceframe_available_memory (&available
, memaddr
, len
))
8476 if (available
.empty () || available
[0].start
!= memaddr
)
8478 enum target_xfer_status res
;
8480 /* Don't read into the traceframe's available
8482 if (!available
.empty ())
8484 LONGEST oldlen
= len
;
8486 len
= available
[0].start
- memaddr
;
8487 gdb_assert (len
<= oldlen
);
8490 /* This goes through the topmost target again. */
8491 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
8492 len
, unit_size
, xfered_len
);
8493 if (res
== TARGET_XFER_OK
)
8494 return TARGET_XFER_OK
;
8497 /* No use trying further, we know some memory starting
8498 at MEMADDR isn't available. */
8500 return TARGET_XFER_UNAVAILABLE
;
8504 /* Don't try to read more than how much is available, in
8505 case the target implements the deprecated QTro packet to
8506 cater for older GDBs (the target's knowledge of read-only
8507 sections may be outdated by now). */
8508 len
= available
[0].length
;
8512 return remote_read_bytes_1 (memaddr
, myaddr
, len
, unit_size
, xfered_len
);
8517 /* Sends a packet with content determined by the printf format string
8518 FORMAT and the remaining arguments, then gets the reply. Returns
8519 whether the packet was a success, a failure, or unknown. */
8521 static enum packet_result
remote_send_printf (const char *format
, ...)
8522 ATTRIBUTE_PRINTF (1, 2);
8524 static enum packet_result
8525 remote_send_printf (const char *format
, ...)
8527 struct remote_state
*rs
= get_remote_state ();
8528 int max_size
= get_remote_packet_size ();
8531 va_start (ap
, format
);
8534 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
8535 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
8537 if (putpkt (rs
->buf
) < 0)
8538 error (_("Communication problem with target."));
8541 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8543 return packet_check_result (rs
->buf
);
8546 /* Flash writing can take quite some time. We'll set
8547 effectively infinite timeout for flash operations.
8548 In future, we'll need to decide on a better approach. */
8549 static const int remote_flash_timeout
= 1000;
8552 remote_flash_erase (struct target_ops
*ops
,
8553 ULONGEST address
, LONGEST length
)
8555 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8556 enum packet_result ret
;
8557 scoped_restore restore_timeout
8558 = make_scoped_restore (&remote_timeout
, remote_flash_timeout
);
8560 ret
= remote_send_printf ("vFlashErase:%s,%s",
8561 phex (address
, addr_size
),
8565 case PACKET_UNKNOWN
:
8566 error (_("Remote target does not support flash erase"));
8568 error (_("Error erasing flash with vFlashErase packet"));
8574 static enum target_xfer_status
8575 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
8576 ULONGEST length
, ULONGEST
*xfered_len
,
8577 const gdb_byte
*data
)
8579 scoped_restore restore_timeout
8580 = make_scoped_restore (&remote_timeout
, remote_flash_timeout
);
8581 return remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 1,
8586 remote_flash_done (struct target_ops
*ops
)
8590 scoped_restore restore_timeout
8591 = make_scoped_restore (&remote_timeout
, remote_flash_timeout
);
8593 ret
= remote_send_printf ("vFlashDone");
8597 case PACKET_UNKNOWN
:
8598 error (_("Remote target does not support vFlashDone"));
8600 error (_("Error finishing flash operation"));
8607 remote_files_info (struct target_ops
*ignore
)
8609 puts_filtered ("Debugging a target over a serial line.\n");
8612 /* Stuff for dealing with the packets which are part of this protocol.
8613 See comment at top of file for details. */
8615 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
8616 error to higher layers. Called when a serial error is detected.
8617 The exception message is STRING, followed by a colon and a blank,
8618 the system error message for errno at function entry and final dot
8619 for output compatibility with throw_perror_with_name. */
8622 unpush_and_perror (const char *string
)
8624 int saved_errno
= errno
;
8626 remote_unpush_target ();
8627 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
8628 safe_strerror (saved_errno
));
8631 /* Read a single character from the remote end. The current quit
8632 handler is overridden to avoid quitting in the middle of packet
8633 sequence, as that would break communication with the remote server.
8634 See remote_serial_quit_handler for more detail. */
8637 readchar (int timeout
)
8640 struct remote_state
*rs
= get_remote_state ();
8643 scoped_restore restore_quit
8644 = make_scoped_restore (&quit_handler
, remote_serial_quit_handler
);
8646 rs
->got_ctrlc_during_io
= 0;
8648 ch
= serial_readchar (rs
->remote_desc
, timeout
);
8650 if (rs
->got_ctrlc_during_io
)
8657 switch ((enum serial_rc
) ch
)
8660 remote_unpush_target ();
8661 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
8664 unpush_and_perror (_("Remote communication error. "
8665 "Target disconnected."));
8667 case SERIAL_TIMEOUT
:
8673 /* Wrapper for serial_write that closes the target and throws if
8674 writing fails. The current quit handler is overridden to avoid
8675 quitting in the middle of packet sequence, as that would break
8676 communication with the remote server. See
8677 remote_serial_quit_handler for more detail. */
8680 remote_serial_write (const char *str
, int len
)
8682 struct remote_state
*rs
= get_remote_state ();
8684 scoped_restore restore_quit
8685 = make_scoped_restore (&quit_handler
, remote_serial_quit_handler
);
8687 rs
->got_ctrlc_during_io
= 0;
8689 if (serial_write (rs
->remote_desc
, str
, len
))
8691 unpush_and_perror (_("Remote communication error. "
8692 "Target disconnected."));
8695 if (rs
->got_ctrlc_during_io
)
8699 /* Send the command in *BUF to the remote machine, and read the reply
8700 into *BUF. Report an error if we get an error reply. Resize
8701 *BUF using xrealloc if necessary to hold the result, and update
8705 remote_send (char **buf
,
8709 getpkt (buf
, sizeof_buf
, 0);
8711 if ((*buf
)[0] == 'E')
8712 error (_("Remote failure reply: %s"), *buf
);
8715 /* Return a string representing an escaped version of BUF, of len N.
8716 E.g. \n is converted to \\n, \t to \\t, etc. */
8719 escape_buffer (const char *buf
, int n
)
8723 stb
.putstrn (buf
, n
, '\\');
8724 return std::move (stb
.string ());
8727 /* Display a null-terminated packet on stdout, for debugging, using C
8731 print_packet (const char *buf
)
8733 puts_filtered ("\"");
8734 fputstr_filtered (buf
, '"', gdb_stdout
);
8735 puts_filtered ("\"");
8739 putpkt (const char *buf
)
8741 return putpkt_binary (buf
, strlen (buf
));
8744 /* Send a packet to the remote machine, with error checking. The data
8745 of the packet is in BUF. The string in BUF can be at most
8746 get_remote_packet_size () - 5 to account for the $, # and checksum,
8747 and for a possible /0 if we are debugging (remote_debug) and want
8748 to print the sent packet as a string. */
8751 putpkt_binary (const char *buf
, int cnt
)
8753 struct remote_state
*rs
= get_remote_state ();
8755 unsigned char csum
= 0;
8756 char *buf2
= (char *) xmalloc (cnt
+ 6);
8757 struct cleanup
*old_chain
= make_cleanup (xfree
, buf2
);
8763 /* Catch cases like trying to read memory or listing threads while
8764 we're waiting for a stop reply. The remote server wouldn't be
8765 ready to handle this request, so we'd hang and timeout. We don't
8766 have to worry about this in synchronous mode, because in that
8767 case it's not possible to issue a command while the target is
8768 running. This is not a problem in non-stop mode, because in that
8769 case, the stub is always ready to process serial input. */
8770 if (!target_is_non_stop_p ()
8771 && target_is_async_p ()
8772 && rs
->waiting_for_stop_reply
)
8774 error (_("Cannot execute this command while the target is running.\n"
8775 "Use the \"interrupt\" command to stop the target\n"
8776 "and then try again."));
8779 /* We're sending out a new packet. Make sure we don't look at a
8780 stale cached response. */
8781 rs
->cached_wait_status
= 0;
8783 /* Copy the packet into buffer BUF2, encapsulating it
8784 and giving it a checksum. */
8789 for (i
= 0; i
< cnt
; i
++)
8795 *p
++ = tohex ((csum
>> 4) & 0xf);
8796 *p
++ = tohex (csum
& 0xf);
8798 /* Send it over and over until we get a positive ack. */
8802 int started_error_output
= 0;
8808 int len
= (int) (p
- buf2
);
8811 = escape_buffer (buf2
, std::min (len
, REMOTE_DEBUG_MAX_CHAR
));
8813 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s", str
.c_str ());
8815 if (str
.length () > REMOTE_DEBUG_MAX_CHAR
)
8817 fprintf_unfiltered (gdb_stdlog
, "[%zu bytes omitted]",
8818 str
.length () - REMOTE_DEBUG_MAX_CHAR
);
8821 fprintf_unfiltered (gdb_stdlog
, "...");
8823 gdb_flush (gdb_stdlog
);
8825 remote_serial_write (buf2
, p
- buf2
);
8827 /* If this is a no acks version of the remote protocol, send the
8828 packet and move on. */
8832 /* Read until either a timeout occurs (-2) or '+' is read.
8833 Handle any notification that arrives in the mean time. */
8836 ch
= readchar (remote_timeout
);
8844 case SERIAL_TIMEOUT
:
8847 if (started_error_output
)
8849 putchar_unfiltered ('\n');
8850 started_error_output
= 0;
8859 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
8860 do_cleanups (old_chain
);
8864 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
8866 case SERIAL_TIMEOUT
:
8870 do_cleanups (old_chain
);
8873 break; /* Retransmit buffer. */
8877 fprintf_unfiltered (gdb_stdlog
,
8878 "Packet instead of Ack, ignoring it\n");
8879 /* It's probably an old response sent because an ACK
8880 was lost. Gobble up the packet and ack it so it
8881 doesn't get retransmitted when we resend this
8884 remote_serial_write ("+", 1);
8885 continue; /* Now, go look for +. */
8892 /* If we got a notification, handle it, and go back to looking
8894 /* We've found the start of a notification. Now
8895 collect the data. */
8896 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
8901 std::string str
= escape_buffer (rs
->buf
, val
);
8903 fprintf_unfiltered (gdb_stdlog
,
8904 " Notification received: %s\n",
8907 handle_notification (rs
->notif_state
, rs
->buf
);
8908 /* We're in sync now, rewait for the ack. */
8915 if (!started_error_output
)
8917 started_error_output
= 1;
8918 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8920 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8921 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
8930 if (!started_error_output
)
8932 started_error_output
= 1;
8933 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
8935 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
8939 break; /* Here to retransmit. */
8943 /* This is wrong. If doing a long backtrace, the user should be
8944 able to get out next time we call QUIT, without anything as
8945 violent as interrupt_query. If we want to provide a way out of
8946 here without getting to the next QUIT, it should be based on
8947 hitting ^C twice as in remote_wait. */
8956 do_cleanups (old_chain
);
8960 /* Come here after finding the start of a frame when we expected an
8961 ack. Do our best to discard the rest of this packet. */
8970 c
= readchar (remote_timeout
);
8973 case SERIAL_TIMEOUT
:
8974 /* Nothing we can do. */
8977 /* Discard the two bytes of checksum and stop. */
8978 c
= readchar (remote_timeout
);
8980 c
= readchar (remote_timeout
);
8983 case '*': /* Run length encoding. */
8984 /* Discard the repeat count. */
8985 c
= readchar (remote_timeout
);
8990 /* A regular character. */
8996 /* Come here after finding the start of the frame. Collect the rest
8997 into *BUF, verifying the checksum, length, and handling run-length
8998 compression. NUL terminate the buffer. If there is not enough room,
8999 expand *BUF using xrealloc.
9001 Returns -1 on error, number of characters in buffer (ignoring the
9002 trailing NULL) on success. (could be extended to return one of the
9003 SERIAL status indications). */
9006 read_frame (char **buf_p
,
9013 struct remote_state
*rs
= get_remote_state ();
9020 c
= readchar (remote_timeout
);
9023 case SERIAL_TIMEOUT
:
9025 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
9029 fputs_filtered ("Saw new packet start in middle of old one\n",
9031 return -1; /* Start a new packet, count retries. */
9034 unsigned char pktcsum
;
9040 check_0
= readchar (remote_timeout
);
9042 check_1
= readchar (remote_timeout
);
9044 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
9047 fputs_filtered ("Timeout in checksum, retrying\n",
9051 else if (check_0
< 0 || check_1
< 0)
9054 fputs_filtered ("Communication error in checksum\n",
9059 /* Don't recompute the checksum; with no ack packets we
9060 don't have any way to indicate a packet retransmission
9065 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
9066 if (csum
== pktcsum
)
9071 std::string str
= escape_buffer (buf
, bc
);
9073 fprintf_unfiltered (gdb_stdlog
,
9074 "Bad checksum, sentsum=0x%x, "
9075 "csum=0x%x, buf=%s\n",
9076 pktcsum
, csum
, str
.c_str ());
9078 /* Number of characters in buffer ignoring trailing
9082 case '*': /* Run length encoding. */
9087 c
= readchar (remote_timeout
);
9089 repeat
= c
- ' ' + 3; /* Compute repeat count. */
9091 /* The character before ``*'' is repeated. */
9093 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
9095 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
9097 /* Make some more room in the buffer. */
9098 *sizeof_buf
+= repeat
;
9099 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
9103 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
9109 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
9113 if (bc
>= *sizeof_buf
- 1)
9115 /* Make some more room in the buffer. */
9117 *buf_p
= (char *) xrealloc (*buf_p
, *sizeof_buf
);
9128 /* Read a packet from the remote machine, with error checking, and
9129 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
9130 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
9131 rather than timing out; this is used (in synchronous mode) to wait
9132 for a target that is is executing user code to stop. */
9133 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
9134 don't have to change all the calls to getpkt to deal with the
9135 return value, because at the moment I don't know what the right
9136 thing to do it for those. */
9142 getpkt_sane (buf
, sizeof_buf
, forever
);
9146 /* Read a packet from the remote machine, with error checking, and
9147 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
9148 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
9149 rather than timing out; this is used (in synchronous mode) to wait
9150 for a target that is is executing user code to stop. If FOREVER ==
9151 0, this function is allowed to time out gracefully and return an
9152 indication of this to the caller. Otherwise return the number of
9153 bytes read. If EXPECTING_NOTIF, consider receiving a notification
9154 enough reason to return to the caller. *IS_NOTIF is an output
9155 boolean that indicates whether *BUF holds a notification or not
9156 (a regular packet). */
9159 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
9160 int expecting_notif
, int *is_notif
)
9162 struct remote_state
*rs
= get_remote_state ();
9168 /* We're reading a new response. Make sure we don't look at a
9169 previously cached response. */
9170 rs
->cached_wait_status
= 0;
9172 strcpy (*buf
, "timeout");
9175 timeout
= watchdog
> 0 ? watchdog
: -1;
9176 else if (expecting_notif
)
9177 timeout
= 0; /* There should already be a char in the buffer. If
9180 timeout
= remote_timeout
;
9184 /* Process any number of notifications, and then return when
9188 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
9190 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
9192 /* This can loop forever if the remote side sends us
9193 characters continuously, but if it pauses, we'll get
9194 SERIAL_TIMEOUT from readchar because of timeout. Then
9195 we'll count that as a retry.
9197 Note that even when forever is set, we will only wait
9198 forever prior to the start of a packet. After that, we
9199 expect characters to arrive at a brisk pace. They should
9200 show up within remote_timeout intervals. */
9202 c
= readchar (timeout
);
9203 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
9205 if (c
== SERIAL_TIMEOUT
)
9207 if (expecting_notif
)
9208 return -1; /* Don't complain, it's normal to not get
9209 anything in this case. */
9211 if (forever
) /* Watchdog went off? Kill the target. */
9213 remote_unpush_target ();
9214 throw_error (TARGET_CLOSE_ERROR
,
9215 _("Watchdog timeout has expired. "
9216 "Target detached."));
9219 fputs_filtered ("Timed out.\n", gdb_stdlog
);
9223 /* We've found the start of a packet or notification.
9224 Now collect the data. */
9225 val
= read_frame (buf
, sizeof_buf
);
9230 remote_serial_write ("-", 1);
9233 if (tries
> MAX_TRIES
)
9235 /* We have tried hard enough, and just can't receive the
9236 packet/notification. Give up. */
9237 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
9239 /* Skip the ack char if we're in no-ack mode. */
9240 if (!rs
->noack_mode
)
9241 remote_serial_write ("+", 1);
9245 /* If we got an ordinary packet, return that to our caller. */
9251 = escape_buffer (*buf
,
9252 std::min (val
, REMOTE_DEBUG_MAX_CHAR
));
9254 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s",
9257 if (str
.length () > REMOTE_DEBUG_MAX_CHAR
)
9259 fprintf_unfiltered (gdb_stdlog
, "[%zu bytes omitted]",
9260 str
.length () - REMOTE_DEBUG_MAX_CHAR
);
9263 fprintf_unfiltered (gdb_stdlog
, "\n");
9266 /* Skip the ack char if we're in no-ack mode. */
9267 if (!rs
->noack_mode
)
9268 remote_serial_write ("+", 1);
9269 if (is_notif
!= NULL
)
9274 /* If we got a notification, handle it, and go back to looking
9278 gdb_assert (c
== '%');
9282 std::string str
= escape_buffer (*buf
, val
);
9284 fprintf_unfiltered (gdb_stdlog
,
9285 " Notification received: %s\n",
9288 if (is_notif
!= NULL
)
9291 handle_notification (rs
->notif_state
, *buf
);
9293 /* Notifications require no acknowledgement. */
9295 if (expecting_notif
)
9302 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
9304 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
9308 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
9311 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
9315 /* Check whether EVENT is a fork event for the process specified
9316 by the pid passed in DATA, and if it is, kill the fork child. */
9319 kill_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
9320 QUEUE_ITER (stop_reply_p
) *iter
,
9324 struct queue_iter_param
*param
= (struct queue_iter_param
*) data
;
9325 int parent_pid
= *(int *) param
->input
;
9327 if (is_pending_fork_parent (&event
->ws
, parent_pid
, event
->ptid
))
9329 struct remote_state
*rs
= get_remote_state ();
9330 int child_pid
= ptid_get_pid (event
->ws
.value
.related_pid
);
9333 res
= remote_vkill (child_pid
, rs
);
9335 error (_("Can't kill fork child process %d"), child_pid
);
9341 /* Kill any new fork children of process PID that haven't been
9342 processed by follow_fork. */
9345 kill_new_fork_children (int pid
, struct remote_state
*rs
)
9347 struct thread_info
*thread
;
9348 struct notif_client
*notif
= ¬if_client_stop
;
9349 struct queue_iter_param param
;
9351 /* Kill the fork child threads of any threads in process PID
9352 that are stopped at a fork event. */
9353 ALL_NON_EXITED_THREADS (thread
)
9355 struct target_waitstatus
*ws
= &thread
->pending_follow
;
9357 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
9359 struct remote_state
*rs
= get_remote_state ();
9360 int child_pid
= ptid_get_pid (ws
->value
.related_pid
);
9363 res
= remote_vkill (child_pid
, rs
);
9365 error (_("Can't kill fork child process %d"), child_pid
);
9369 /* Check for any pending fork events (not reported or processed yet)
9370 in process PID and kill those fork child threads as well. */
9371 remote_notif_get_pending_events (notif
);
9373 param
.output
= NULL
;
9374 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
9375 kill_child_of_pending_fork
, ¶m
);
9379 /* Target hook to kill the current inferior. */
9382 remote_kill (struct target_ops
*ops
)
9385 int pid
= ptid_get_pid (inferior_ptid
);
9386 struct remote_state
*rs
= get_remote_state ();
9388 if (packet_support (PACKET_vKill
) != PACKET_DISABLE
)
9390 /* If we're stopped while forking and we haven't followed yet,
9391 kill the child task. We need to do this before killing the
9392 parent task because if this is a vfork then the parent will
9394 kill_new_fork_children (pid
, rs
);
9396 res
= remote_vkill (pid
, rs
);
9399 target_mourn_inferior (inferior_ptid
);
9404 /* If we are in 'target remote' mode and we are killing the only
9405 inferior, then we will tell gdbserver to exit and unpush the
9407 if (res
== -1 && !remote_multi_process_p (rs
)
9408 && number_of_live_inferiors () == 1)
9412 /* We've killed the remote end, we get to mourn it. If we are
9413 not in extended mode, mourning the inferior also unpushes
9414 remote_ops from the target stack, which closes the remote
9416 target_mourn_inferior (inferior_ptid
);
9421 error (_("Can't kill process"));
9424 /* Send a kill request to the target using the 'vKill' packet. */
9427 remote_vkill (int pid
, struct remote_state
*rs
)
9429 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
9432 /* Tell the remote target to detach. */
9433 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
9435 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9437 switch (packet_ok (rs
->buf
,
9438 &remote_protocol_packets
[PACKET_vKill
]))
9444 case PACKET_UNKNOWN
:
9447 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
9451 /* Send a kill request to the target using the 'k' packet. */
9454 remote_kill_k (void)
9456 /* Catch errors so the user can quit from gdb even when we
9457 aren't on speaking terms with the remote system. */
9462 CATCH (ex
, RETURN_MASK_ERROR
)
9464 if (ex
.error
== TARGET_CLOSE_ERROR
)
9466 /* If we got an (EOF) error that caused the target
9467 to go away, then we're done, that's what we wanted.
9468 "k" is susceptible to cause a premature EOF, given
9469 that the remote server isn't actually required to
9470 reply to "k", and it can happen that it doesn't
9471 even get to reply ACK to the "k". */
9475 /* Otherwise, something went wrong. We didn't actually kill
9476 the target. Just propagate the exception, and let the
9477 user or higher layers decide what to do. */
9478 throw_exception (ex
);
9484 remote_mourn (struct target_ops
*target
)
9486 struct remote_state
*rs
= get_remote_state ();
9488 /* In 'target remote' mode with one inferior, we close the connection. */
9489 if (!rs
->extended
&& number_of_live_inferiors () <= 1)
9491 unpush_target (target
);
9493 /* remote_close takes care of doing most of the clean up. */
9494 generic_mourn_inferior ();
9498 /* In case we got here due to an error, but we're going to stay
9500 rs
->waiting_for_stop_reply
= 0;
9502 /* If the current general thread belonged to the process we just
9503 detached from or has exited, the remote side current general
9504 thread becomes undefined. Considering a case like this:
9506 - We just got here due to a detach.
9507 - The process that we're detaching from happens to immediately
9508 report a global breakpoint being hit in non-stop mode, in the
9509 same thread we had selected before.
9510 - GDB attaches to this process again.
9511 - This event happens to be the next event we handle.
9513 GDB would consider that the current general thread didn't need to
9514 be set on the stub side (with Hg), since for all it knew,
9515 GENERAL_THREAD hadn't changed.
9517 Notice that although in all-stop mode, the remote server always
9518 sets the current thread to the thread reporting the stop event,
9519 that doesn't happen in non-stop mode; in non-stop, the stub *must
9520 not* change the current thread when reporting a breakpoint hit,
9521 due to the decoupling of event reporting and event handling.
9523 To keep things simple, we always invalidate our notion of the
9525 record_currthread (rs
, minus_one_ptid
);
9527 /* Call common code to mark the inferior as not running. */
9528 generic_mourn_inferior ();
9530 if (!have_inferiors ())
9532 if (!remote_multi_process_p (rs
))
9534 /* Check whether the target is running now - some remote stubs
9535 automatically restart after kill. */
9537 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9539 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
9541 /* Assume that the target has been restarted. Set
9542 inferior_ptid so that bits of core GDB realizes
9543 there's something here, e.g., so that the user can
9544 say "kill" again. */
9545 inferior_ptid
= magic_null_ptid
;
9552 extended_remote_supports_disable_randomization (struct target_ops
*self
)
9554 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
9558 extended_remote_disable_randomization (int val
)
9560 struct remote_state
*rs
= get_remote_state ();
9563 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
9566 reply
= remote_get_noisy_reply ();
9568 error (_("Target does not support QDisableRandomization."));
9569 if (strcmp (reply
, "OK") != 0)
9570 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
9574 extended_remote_run (const std::string
&args
)
9576 struct remote_state
*rs
= get_remote_state ();
9578 const char *remote_exec_file
= get_remote_exec_file ();
9580 /* If the user has disabled vRun support, or we have detected that
9581 support is not available, do not try it. */
9582 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
9585 strcpy (rs
->buf
, "vRun;");
9586 len
= strlen (rs
->buf
);
9588 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
9589 error (_("Remote file name too long for run packet"));
9590 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
9591 strlen (remote_exec_file
));
9597 gdb_argv
argv (args
.c_str ());
9598 for (i
= 0; argv
[i
] != NULL
; i
++)
9600 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
9601 error (_("Argument list too long for run packet"));
9602 rs
->buf
[len
++] = ';';
9603 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
9608 rs
->buf
[len
++] = '\0';
9611 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9613 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
9616 /* We have a wait response. All is well. */
9618 case PACKET_UNKNOWN
:
9621 if (remote_exec_file
[0] == '\0')
9622 error (_("Running the default executable on the remote target failed; "
9623 "try \"set remote exec-file\"?"));
9625 error (_("Running \"%s\" on the remote target failed"),
9628 gdb_assert_not_reached (_("bad switch"));
9632 /* Helper function to send set/unset environment packets. ACTION is
9633 either "set" or "unset". PACKET is either "QEnvironmentHexEncoded"
9634 or "QEnvironmentUnsetVariable". VALUE is the variable to be
9638 send_environment_packet (struct remote_state
*rs
,
9643 /* Convert the environment variable to an hex string, which
9644 is the best format to be transmitted over the wire. */
9645 std::string encoded_value
= bin2hex ((const gdb_byte
*) value
,
9648 xsnprintf (rs
->buf
, get_remote_packet_size (),
9649 "%s:%s", packet
, encoded_value
.c_str ());
9652 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9653 if (strcmp (rs
->buf
, "OK") != 0)
9654 warning (_("Unable to %s environment variable '%s' on remote."),
9658 /* Helper function to handle the QEnvironment* packets. */
9661 extended_remote_environment_support (struct remote_state
*rs
)
9663 if (packet_support (PACKET_QEnvironmentReset
) != PACKET_DISABLE
)
9665 putpkt ("QEnvironmentReset");
9666 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9667 if (strcmp (rs
->buf
, "OK") != 0)
9668 warning (_("Unable to reset environment on remote."));
9671 gdb_environ
*e
= ¤t_inferior ()->environment
;
9673 if (packet_support (PACKET_QEnvironmentHexEncoded
) != PACKET_DISABLE
)
9674 for (const std::string
&el
: e
->user_set_env ())
9675 send_environment_packet (rs
, "set", "QEnvironmentHexEncoded",
9678 if (packet_support (PACKET_QEnvironmentUnset
) != PACKET_DISABLE
)
9679 for (const std::string
&el
: e
->user_unset_env ())
9680 send_environment_packet (rs
, "unset", "QEnvironmentUnset", el
.c_str ());
9683 /* Helper function to set the current working directory for the
9684 inferior in the remote target. */
9687 extended_remote_set_inferior_cwd (struct remote_state
*rs
)
9689 if (packet_support (PACKET_QSetWorkingDir
) != PACKET_DISABLE
)
9691 const char *inferior_cwd
= get_inferior_cwd ();
9693 if (inferior_cwd
!= NULL
)
9695 std::string hexpath
= bin2hex ((const gdb_byte
*) inferior_cwd
,
9696 strlen (inferior_cwd
));
9698 xsnprintf (rs
->buf
, get_remote_packet_size (),
9699 "QSetWorkingDir:%s", hexpath
.c_str ());
9703 /* An empty inferior_cwd means that the user wants us to
9704 reset the remote server's inferior's cwd. */
9705 xsnprintf (rs
->buf
, get_remote_packet_size (),
9710 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9711 if (packet_ok (rs
->buf
,
9712 &remote_protocol_packets
[PACKET_QSetWorkingDir
])
9715 Remote replied unexpectedly while setting the inferior's working\n\
9722 /* In the extended protocol we want to be able to do things like
9723 "run" and have them basically work as expected. So we need
9724 a special create_inferior function. We support changing the
9725 executable file and the command line arguments, but not the
9729 extended_remote_create_inferior (struct target_ops
*ops
,
9730 const char *exec_file
,
9731 const std::string
&args
,
9732 char **env
, int from_tty
)
9736 struct remote_state
*rs
= get_remote_state ();
9737 const char *remote_exec_file
= get_remote_exec_file ();
9739 /* If running asynchronously, register the target file descriptor
9740 with the event loop. */
9741 if (target_can_async_p ())
9744 /* Disable address space randomization if requested (and supported). */
9745 if (extended_remote_supports_disable_randomization (ops
))
9746 extended_remote_disable_randomization (disable_randomization
);
9748 /* If startup-with-shell is on, we inform gdbserver to start the
9749 remote inferior using a shell. */
9750 if (packet_support (PACKET_QStartupWithShell
) != PACKET_DISABLE
)
9752 xsnprintf (rs
->buf
, get_remote_packet_size (),
9753 "QStartupWithShell:%d", startup_with_shell
? 1 : 0);
9755 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9756 if (strcmp (rs
->buf
, "OK") != 0)
9758 Remote replied unexpectedly while setting startup-with-shell: %s"),
9762 extended_remote_environment_support (rs
);
9764 extended_remote_set_inferior_cwd (rs
);
9766 /* Now restart the remote server. */
9767 run_worked
= extended_remote_run (args
) != -1;
9770 /* vRun was not supported. Fail if we need it to do what the
9772 if (remote_exec_file
[0])
9773 error (_("Remote target does not support \"set remote exec-file\""));
9775 error (_("Remote target does not support \"set args\" or run <ARGS>"));
9777 /* Fall back to "R". */
9778 extended_remote_restart ();
9781 if (!have_inferiors ())
9783 /* Clean up from the last time we ran, before we mark the target
9784 running again. This will mark breakpoints uninserted, and
9785 get_offsets may insert breakpoints. */
9786 init_thread_list ();
9787 init_wait_for_inferior ();
9790 /* vRun's success return is a stop reply. */
9791 stop_reply
= run_worked
? rs
->buf
: NULL
;
9792 add_current_inferior_and_thread (stop_reply
);
9794 /* Get updated offsets, if the stub uses qOffsets. */
9799 /* Given a location's target info BP_TGT and the packet buffer BUF, output
9800 the list of conditions (in agent expression bytecode format), if any, the
9801 target needs to evaluate. The output is placed into the packet buffer
9802 started from BUF and ended at BUF_END. */
9805 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
9806 struct bp_target_info
*bp_tgt
, char *buf
,
9809 if (bp_tgt
->conditions
.empty ())
9812 buf
+= strlen (buf
);
9813 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
9816 /* Send conditions to the target. */
9817 for (agent_expr
*aexpr
: bp_tgt
->conditions
)
9819 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
9820 buf
+= strlen (buf
);
9821 for (int i
= 0; i
< aexpr
->len
; ++i
)
9822 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9829 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
9830 struct bp_target_info
*bp_tgt
, char *buf
)
9832 if (bp_tgt
->tcommands
.empty ())
9835 buf
+= strlen (buf
);
9837 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
9838 buf
+= strlen (buf
);
9840 /* Concatenate all the agent expressions that are commands into the
9842 for (agent_expr
*aexpr
: bp_tgt
->tcommands
)
9844 sprintf (buf
, "X%x,", aexpr
->len
);
9845 buf
+= strlen (buf
);
9846 for (int i
= 0; i
< aexpr
->len
; ++i
)
9847 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
9852 /* Insert a breakpoint. On targets that have software breakpoint
9853 support, we ask the remote target to do the work; on targets
9854 which don't, we insert a traditional memory breakpoint. */
9857 remote_insert_breakpoint (struct target_ops
*ops
,
9858 struct gdbarch
*gdbarch
,
9859 struct bp_target_info
*bp_tgt
)
9861 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
9862 If it succeeds, then set the support to PACKET_ENABLE. If it
9863 fails, and the user has explicitly requested the Z support then
9864 report an error, otherwise, mark it disabled and go on. */
9866 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9868 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
9869 struct remote_state
*rs
;
9873 /* Make sure the remote is pointing at the right process, if
9875 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9876 set_general_process ();
9878 rs
= get_remote_state ();
9880 endbuf
= rs
->buf
+ get_remote_packet_size ();
9885 addr
= (ULONGEST
) remote_address_masked (addr
);
9886 p
+= hexnumstr (p
, addr
);
9887 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->kind
);
9889 if (remote_supports_cond_breakpoints (ops
))
9890 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
9892 if (remote_can_run_breakpoint_commands (ops
))
9893 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
9896 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9898 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
9904 case PACKET_UNKNOWN
:
9909 /* If this breakpoint has target-side commands but this stub doesn't
9910 support Z0 packets, throw error. */
9911 if (!bp_tgt
->tcommands
.empty ())
9912 throw_error (NOT_SUPPORTED_ERROR
, _("\
9913 Target doesn't support breakpoints that have target side commands."));
9915 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
9919 remote_remove_breakpoint (struct target_ops
*ops
,
9920 struct gdbarch
*gdbarch
,
9921 struct bp_target_info
*bp_tgt
,
9922 enum remove_bp_reason reason
)
9924 CORE_ADDR addr
= bp_tgt
->placed_address
;
9925 struct remote_state
*rs
= get_remote_state ();
9927 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
9930 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9932 /* Make sure the remote is pointing at the right process, if
9934 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9935 set_general_process ();
9941 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
9942 p
+= hexnumstr (p
, addr
);
9943 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->kind
);
9946 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9948 return (rs
->buf
[0] == 'E');
9951 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
, reason
);
9954 static enum Z_packet_type
9955 watchpoint_to_Z_packet (int type
)
9960 return Z_PACKET_WRITE_WP
;
9963 return Z_PACKET_READ_WP
;
9966 return Z_PACKET_ACCESS_WP
;
9969 internal_error (__FILE__
, __LINE__
,
9970 _("hw_bp_to_z: bad watchpoint type %d"), type
);
9975 remote_insert_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
9976 enum target_hw_bp_type type
, struct expression
*cond
)
9978 struct remote_state
*rs
= get_remote_state ();
9979 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9981 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
9983 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
9986 /* Make sure the remote is pointing at the right process, if
9988 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9989 set_general_process ();
9991 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
9992 p
= strchr (rs
->buf
, '\0');
9993 addr
= remote_address_masked (addr
);
9994 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9995 xsnprintf (p
, endbuf
- p
, ",%x", len
);
9998 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10000 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
10004 case PACKET_UNKNOWN
:
10009 internal_error (__FILE__
, __LINE__
,
10010 _("remote_insert_watchpoint: reached end of function"));
10014 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
10015 CORE_ADDR start
, int length
)
10017 CORE_ADDR diff
= remote_address_masked (addr
- start
);
10019 return diff
< length
;
10024 remote_remove_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
10025 enum target_hw_bp_type type
, struct expression
*cond
)
10027 struct remote_state
*rs
= get_remote_state ();
10028 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10030 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
10032 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
10035 /* Make sure the remote is pointing at the right process, if
10037 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
10038 set_general_process ();
10040 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
10041 p
= strchr (rs
->buf
, '\0');
10042 addr
= remote_address_masked (addr
);
10043 p
+= hexnumstr (p
, (ULONGEST
) addr
);
10044 xsnprintf (p
, endbuf
- p
, ",%x", len
);
10046 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10048 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
10051 case PACKET_UNKNOWN
:
10056 internal_error (__FILE__
, __LINE__
,
10057 _("remote_remove_watchpoint: reached end of function"));
10061 int remote_hw_watchpoint_limit
= -1;
10062 int remote_hw_watchpoint_length_limit
= -1;
10063 int remote_hw_breakpoint_limit
= -1;
10066 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
10067 CORE_ADDR addr
, int len
)
10069 if (remote_hw_watchpoint_length_limit
== 0)
10071 else if (remote_hw_watchpoint_length_limit
< 0)
10073 else if (len
<= remote_hw_watchpoint_length_limit
)
10080 remote_check_watch_resources (struct target_ops
*self
,
10081 enum bptype type
, int cnt
, int ot
)
10083 if (type
== bp_hardware_breakpoint
)
10085 if (remote_hw_breakpoint_limit
== 0)
10087 else if (remote_hw_breakpoint_limit
< 0)
10089 else if (cnt
<= remote_hw_breakpoint_limit
)
10094 if (remote_hw_watchpoint_limit
== 0)
10096 else if (remote_hw_watchpoint_limit
< 0)
10100 else if (cnt
<= remote_hw_watchpoint_limit
)
10106 /* The to_stopped_by_sw_breakpoint method of target remote. */
10109 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
10111 struct thread_info
*thread
= inferior_thread ();
10113 return (thread
->priv
!= NULL
10114 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
);
10117 /* The to_supports_stopped_by_sw_breakpoint method of target
10121 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
10123 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
10126 /* The to_stopped_by_hw_breakpoint method of target remote. */
10129 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
10131 struct thread_info
*thread
= inferior_thread ();
10133 return (thread
->priv
!= NULL
10134 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
);
10137 /* The to_supports_stopped_by_hw_breakpoint method of target
10141 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
10143 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
10147 remote_stopped_by_watchpoint (struct target_ops
*ops
)
10149 struct thread_info
*thread
= inferior_thread ();
10151 return (thread
->priv
!= NULL
10152 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
);
10156 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
10158 struct thread_info
*thread
= inferior_thread ();
10160 if (thread
->priv
!= NULL
10161 && thread
->priv
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
)
10163 *addr_p
= thread
->priv
->watch_data_address
;
10172 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
10173 struct bp_target_info
*bp_tgt
)
10175 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
10176 struct remote_state
*rs
;
10180 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
10183 /* Make sure the remote is pointing at the right process, if
10185 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
10186 set_general_process ();
10188 rs
= get_remote_state ();
10190 endbuf
= rs
->buf
+ get_remote_packet_size ();
10196 addr
= remote_address_masked (addr
);
10197 p
+= hexnumstr (p
, (ULONGEST
) addr
);
10198 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->kind
);
10200 if (remote_supports_cond_breakpoints (self
))
10201 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
10203 if (remote_can_run_breakpoint_commands (self
))
10204 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
10207 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10209 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
10212 if (rs
->buf
[1] == '.')
10214 message
= strchr (rs
->buf
+ 2, '.');
10216 error (_("Remote failure reply: %s"), message
+ 1);
10219 case PACKET_UNKNOWN
:
10224 internal_error (__FILE__
, __LINE__
,
10225 _("remote_insert_hw_breakpoint: reached end of function"));
10230 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
10231 struct bp_target_info
*bp_tgt
)
10234 struct remote_state
*rs
= get_remote_state ();
10236 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10238 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
10241 /* Make sure the remote is pointing at the right process, if
10243 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
10244 set_general_process ();
10250 addr
= remote_address_masked (bp_tgt
->placed_address
);
10251 p
+= hexnumstr (p
, (ULONGEST
) addr
);
10252 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->kind
);
10255 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10257 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
10260 case PACKET_UNKNOWN
:
10265 internal_error (__FILE__
, __LINE__
,
10266 _("remote_remove_hw_breakpoint: reached end of function"));
10269 /* Verify memory using the "qCRC:" request. */
10272 remote_verify_memory (struct target_ops
*ops
,
10273 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
10275 struct remote_state
*rs
= get_remote_state ();
10276 unsigned long host_crc
, target_crc
;
10279 /* It doesn't make sense to use qCRC if the remote target is
10280 connected but not running. */
10281 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
10283 enum packet_result result
;
10285 /* Make sure the remote is pointing at the right process. */
10286 set_general_process ();
10288 /* FIXME: assumes lma can fit into long. */
10289 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
10290 (long) lma
, (long) size
);
10293 /* Be clever; compute the host_crc before waiting for target
10295 host_crc
= xcrc32 (data
, size
, 0xffffffff);
10297 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10299 result
= packet_ok (rs
->buf
,
10300 &remote_protocol_packets
[PACKET_qCRC
]);
10301 if (result
== PACKET_ERROR
)
10303 else if (result
== PACKET_OK
)
10305 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
10306 target_crc
= target_crc
* 16 + fromhex (*tmp
);
10308 return (host_crc
== target_crc
);
10312 return simple_verify_memory (ops
, data
, lma
, size
);
10315 /* compare-sections command
10317 With no arguments, compares each loadable section in the exec bfd
10318 with the same memory range on the target, and reports mismatches.
10319 Useful for verifying the image on the target against the exec file. */
10322 compare_sections_command (const char *args
, int from_tty
)
10325 struct cleanup
*old_chain
;
10326 gdb_byte
*sectdata
;
10327 const char *sectname
;
10328 bfd_size_type size
;
10331 int mismatched
= 0;
10336 error (_("command cannot be used without an exec file"));
10338 /* Make sure the remote is pointing at the right process. */
10339 set_general_process ();
10341 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
10347 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10349 if (!(s
->flags
& SEC_LOAD
))
10350 continue; /* Skip non-loadable section. */
10352 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
10353 continue; /* Skip writeable sections */
10355 size
= bfd_get_section_size (s
);
10357 continue; /* Skip zero-length section. */
10359 sectname
= bfd_get_section_name (exec_bfd
, s
);
10360 if (args
&& strcmp (args
, sectname
) != 0)
10361 continue; /* Not the section selected by user. */
10363 matched
= 1; /* Do this section. */
10366 sectdata
= (gdb_byte
*) xmalloc (size
);
10367 old_chain
= make_cleanup (xfree
, sectdata
);
10368 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
10370 res
= target_verify_memory (sectdata
, lma
, size
);
10373 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
10374 paddress (target_gdbarch (), lma
),
10375 paddress (target_gdbarch (), lma
+ size
));
10377 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
10378 paddress (target_gdbarch (), lma
),
10379 paddress (target_gdbarch (), lma
+ size
));
10381 printf_filtered ("matched.\n");
10384 printf_filtered ("MIS-MATCHED!\n");
10388 do_cleanups (old_chain
);
10390 if (mismatched
> 0)
10391 warning (_("One or more sections of the target image does not match\n\
10392 the loaded file\n"));
10393 if (args
&& !matched
)
10394 printf_filtered (_("No loaded section named '%s'.\n"), args
);
10397 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
10398 into remote target. The number of bytes written to the remote
10399 target is returned, or -1 for error. */
10401 static enum target_xfer_status
10402 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
10403 const char *annex
, const gdb_byte
*writebuf
,
10404 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
10405 struct packet_config
*packet
)
10409 struct remote_state
*rs
= get_remote_state ();
10410 int max_size
= get_memory_write_packet_size ();
10412 if (packet
->support
== PACKET_DISABLE
)
10413 return TARGET_XFER_E_IO
;
10415 /* Insert header. */
10416 i
= snprintf (rs
->buf
, max_size
,
10417 "qXfer:%s:write:%s:%s:",
10418 object_name
, annex
? annex
: "",
10419 phex_nz (offset
, sizeof offset
));
10420 max_size
-= (i
+ 1);
10422 /* Escape as much data as fits into rs->buf. */
10423 buf_len
= remote_escape_output
10424 (writebuf
, len
, 1, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
10426 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
10427 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
10428 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10429 return TARGET_XFER_E_IO
;
10431 unpack_varlen_hex (rs
->buf
, &n
);
10434 return TARGET_XFER_OK
;
10437 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
10438 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
10439 number of bytes read is returned, or 0 for EOF, or -1 for error.
10440 The number of bytes read may be less than LEN without indicating an
10441 EOF. PACKET is checked and updated to indicate whether the remote
10442 target supports this object. */
10444 static enum target_xfer_status
10445 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
10447 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
10448 ULONGEST
*xfered_len
,
10449 struct packet_config
*packet
)
10451 struct remote_state
*rs
= get_remote_state ();
10452 LONGEST i
, n
, packet_len
;
10454 if (packet
->support
== PACKET_DISABLE
)
10455 return TARGET_XFER_E_IO
;
10457 /* Check whether we've cached an end-of-object packet that matches
10459 if (rs
->finished_object
)
10461 if (strcmp (object_name
, rs
->finished_object
) == 0
10462 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
10463 && offset
== rs
->finished_offset
)
10464 return TARGET_XFER_EOF
;
10467 /* Otherwise, we're now reading something different. Discard
10469 xfree (rs
->finished_object
);
10470 xfree (rs
->finished_annex
);
10471 rs
->finished_object
= NULL
;
10472 rs
->finished_annex
= NULL
;
10475 /* Request only enough to fit in a single packet. The actual data
10476 may not, since we don't know how much of it will need to be escaped;
10477 the target is free to respond with slightly less data. We subtract
10478 five to account for the response type and the protocol frame. */
10479 n
= std::min
<LONGEST
> (get_remote_packet_size () - 5, len
);
10480 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
10481 object_name
, annex
? annex
: "",
10482 phex_nz (offset
, sizeof offset
),
10483 phex_nz (n
, sizeof n
));
10484 i
= putpkt (rs
->buf
);
10486 return TARGET_XFER_E_IO
;
10489 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
10490 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10491 return TARGET_XFER_E_IO
;
10493 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
10494 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
10496 /* 'm' means there is (or at least might be) more data after this
10497 batch. That does not make sense unless there's at least one byte
10498 of data in this reply. */
10499 if (rs
->buf
[0] == 'm' && packet_len
== 1)
10500 error (_("Remote qXfer reply contained no data."));
10502 /* Got some data. */
10503 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
10504 packet_len
- 1, readbuf
, n
);
10506 /* 'l' is an EOF marker, possibly including a final block of data,
10507 or possibly empty. If we have the final block of a non-empty
10508 object, record this fact to bypass a subsequent partial read. */
10509 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
10511 rs
->finished_object
= xstrdup (object_name
);
10512 rs
->finished_annex
= xstrdup (annex
? annex
: "");
10513 rs
->finished_offset
= offset
+ i
;
10517 return TARGET_XFER_EOF
;
10521 return TARGET_XFER_OK
;
10525 static enum target_xfer_status
10526 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
10527 const char *annex
, gdb_byte
*readbuf
,
10528 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
10529 ULONGEST
*xfered_len
)
10531 struct remote_state
*rs
;
10535 int unit_size
= gdbarch_addressable_memory_unit_size (target_gdbarch ());
10537 set_remote_traceframe ();
10538 set_general_thread (inferior_ptid
);
10540 rs
= get_remote_state ();
10542 /* Handle memory using the standard memory routines. */
10543 if (object
== TARGET_OBJECT_MEMORY
)
10545 /* If the remote target is connected but not running, we should
10546 pass this request down to a lower stratum (e.g. the executable
10548 if (!target_has_execution
)
10549 return TARGET_XFER_EOF
;
10551 if (writebuf
!= NULL
)
10552 return remote_write_bytes (offset
, writebuf
, len
, unit_size
,
10555 return remote_read_bytes (ops
, offset
, readbuf
, len
, unit_size
,
10559 /* Handle SPU memory using qxfer packets. */
10560 if (object
== TARGET_OBJECT_SPU
)
10563 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
10564 xfered_len
, &remote_protocol_packets
10565 [PACKET_qXfer_spu_read
]);
10567 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
10568 xfered_len
, &remote_protocol_packets
10569 [PACKET_qXfer_spu_write
]);
10572 /* Handle extra signal info using qxfer packets. */
10573 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
10576 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
10577 xfered_len
, &remote_protocol_packets
10578 [PACKET_qXfer_siginfo_read
]);
10580 return remote_write_qxfer (ops
, "siginfo", annex
,
10581 writebuf
, offset
, len
, xfered_len
,
10582 &remote_protocol_packets
10583 [PACKET_qXfer_siginfo_write
]);
10586 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
10589 return remote_read_qxfer (ops
, "statictrace", annex
,
10590 readbuf
, offset
, len
, xfered_len
,
10591 &remote_protocol_packets
10592 [PACKET_qXfer_statictrace_read
]);
10594 return TARGET_XFER_E_IO
;
10597 /* Only handle flash writes. */
10598 if (writebuf
!= NULL
)
10602 case TARGET_OBJECT_FLASH
:
10603 return remote_flash_write (ops
, offset
, len
, xfered_len
,
10607 return TARGET_XFER_E_IO
;
10611 /* Map pre-existing objects onto letters. DO NOT do this for new
10612 objects!!! Instead specify new query packets. */
10615 case TARGET_OBJECT_AVR
:
10619 case TARGET_OBJECT_AUXV
:
10620 gdb_assert (annex
== NULL
);
10621 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
10623 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
10625 case TARGET_OBJECT_AVAILABLE_FEATURES
:
10626 return remote_read_qxfer
10627 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
10628 &remote_protocol_packets
[PACKET_qXfer_features
]);
10630 case TARGET_OBJECT_LIBRARIES
:
10631 return remote_read_qxfer
10632 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
10633 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
10635 case TARGET_OBJECT_LIBRARIES_SVR4
:
10636 return remote_read_qxfer
10637 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
10638 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
10640 case TARGET_OBJECT_MEMORY_MAP
:
10641 gdb_assert (annex
== NULL
);
10642 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
10644 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
10646 case TARGET_OBJECT_OSDATA
:
10647 /* Should only get here if we're connected. */
10648 gdb_assert (rs
->remote_desc
);
10649 return remote_read_qxfer
10650 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
10651 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
10653 case TARGET_OBJECT_THREADS
:
10654 gdb_assert (annex
== NULL
);
10655 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
10657 &remote_protocol_packets
[PACKET_qXfer_threads
]);
10659 case TARGET_OBJECT_TRACEFRAME_INFO
:
10660 gdb_assert (annex
== NULL
);
10661 return remote_read_qxfer
10662 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
10663 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
10665 case TARGET_OBJECT_FDPIC
:
10666 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
10668 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
10670 case TARGET_OBJECT_OPENVMS_UIB
:
10671 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
10673 &remote_protocol_packets
[PACKET_qXfer_uib
]);
10675 case TARGET_OBJECT_BTRACE
:
10676 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
10678 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
10680 case TARGET_OBJECT_BTRACE_CONF
:
10681 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
10683 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
10685 case TARGET_OBJECT_EXEC_FILE
:
10686 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
10688 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
10691 return TARGET_XFER_E_IO
;
10694 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
10695 large enough let the caller deal with it. */
10696 if (len
< get_remote_packet_size ())
10697 return TARGET_XFER_E_IO
;
10698 len
= get_remote_packet_size ();
10700 /* Except for querying the minimum buffer size, target must be open. */
10701 if (!rs
->remote_desc
)
10702 error (_("remote query is only available after target open"));
10704 gdb_assert (annex
!= NULL
);
10705 gdb_assert (readbuf
!= NULL
);
10709 *p2
++ = query_type
;
10711 /* We used one buffer char for the remote protocol q command and
10712 another for the query type. As the remote protocol encapsulation
10713 uses 4 chars plus one extra in case we are debugging
10714 (remote_debug), we have PBUFZIZ - 7 left to pack the query
10717 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
10719 /* Bad caller may have sent forbidden characters. */
10720 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
10725 gdb_assert (annex
[i
] == '\0');
10727 i
= putpkt (rs
->buf
);
10729 return TARGET_XFER_E_IO
;
10731 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10732 strcpy ((char *) readbuf
, rs
->buf
);
10734 *xfered_len
= strlen ((char *) readbuf
);
10735 return TARGET_XFER_OK
;
10738 /* Implementation of to_get_memory_xfer_limit. */
10741 remote_get_memory_xfer_limit (struct target_ops
*ops
)
10743 return get_memory_write_packet_size ();
10747 remote_search_memory (struct target_ops
* ops
,
10748 CORE_ADDR start_addr
, ULONGEST search_space_len
,
10749 const gdb_byte
*pattern
, ULONGEST pattern_len
,
10750 CORE_ADDR
*found_addrp
)
10752 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
10753 struct remote_state
*rs
= get_remote_state ();
10754 int max_size
= get_memory_write_packet_size ();
10755 struct packet_config
*packet
=
10756 &remote_protocol_packets
[PACKET_qSearch_memory
];
10757 /* Number of packet bytes used to encode the pattern;
10758 this could be more than PATTERN_LEN due to escape characters. */
10759 int escaped_pattern_len
;
10760 /* Amount of pattern that was encodable in the packet. */
10761 int used_pattern_len
;
10764 ULONGEST found_addr
;
10766 /* Don't go to the target if we don't have to.
10767 This is done before checking packet->support to avoid the possibility that
10768 a success for this edge case means the facility works in general. */
10769 if (pattern_len
> search_space_len
)
10771 if (pattern_len
== 0)
10773 *found_addrp
= start_addr
;
10777 /* If we already know the packet isn't supported, fall back to the simple
10778 way of searching memory. */
10780 if (packet_config_support (packet
) == PACKET_DISABLE
)
10782 /* Target doesn't provided special support, fall back and use the
10783 standard support (copy memory and do the search here). */
10784 return simple_search_memory (ops
, start_addr
, search_space_len
,
10785 pattern
, pattern_len
, found_addrp
);
10788 /* Make sure the remote is pointing at the right process. */
10789 set_general_process ();
10791 /* Insert header. */
10792 i
= snprintf (rs
->buf
, max_size
,
10793 "qSearch:memory:%s;%s;",
10794 phex_nz (start_addr
, addr_size
),
10795 phex_nz (search_space_len
, sizeof (search_space_len
)));
10796 max_size
-= (i
+ 1);
10798 /* Escape as much data as fits into rs->buf. */
10799 escaped_pattern_len
=
10800 remote_escape_output (pattern
, pattern_len
, 1, (gdb_byte
*) rs
->buf
+ i
,
10801 &used_pattern_len
, max_size
);
10803 /* Bail if the pattern is too large. */
10804 if (used_pattern_len
!= pattern_len
)
10805 error (_("Pattern is too large to transmit to remote target."));
10807 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
10808 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
10809 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
10811 /* The request may not have worked because the command is not
10812 supported. If so, fall back to the simple way. */
10813 if (packet
->support
== PACKET_DISABLE
)
10815 return simple_search_memory (ops
, start_addr
, search_space_len
,
10816 pattern
, pattern_len
, found_addrp
);
10821 if (rs
->buf
[0] == '0')
10823 else if (rs
->buf
[0] == '1')
10826 if (rs
->buf
[1] != ',')
10827 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10828 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
10829 *found_addrp
= found_addr
;
10832 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
10838 remote_rcmd (struct target_ops
*self
, const char *command
,
10839 struct ui_file
*outbuf
)
10841 struct remote_state
*rs
= get_remote_state ();
10844 if (!rs
->remote_desc
)
10845 error (_("remote rcmd is only available after target open"));
10847 /* Send a NULL command across as an empty command. */
10848 if (command
== NULL
)
10851 /* The query prefix. */
10852 strcpy (rs
->buf
, "qRcmd,");
10853 p
= strchr (rs
->buf
, '\0');
10855 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
10856 > get_remote_packet_size ())
10857 error (_("\"monitor\" command ``%s'' is too long."), command
);
10859 /* Encode the actual command. */
10860 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
10862 if (putpkt (rs
->buf
) < 0)
10863 error (_("Communication problem with target."));
10865 /* get/display the response */
10870 /* XXX - see also remote_get_noisy_reply(). */
10871 QUIT
; /* Allow user to bail out with ^C. */
10873 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
10875 /* Timeout. Continue to (try to) read responses.
10876 This is better than stopping with an error, assuming the stub
10877 is still executing the (long) monitor command.
10878 If needed, the user can interrupt gdb using C-c, obtaining
10879 an effect similar to stop on timeout. */
10883 if (buf
[0] == '\0')
10884 error (_("Target does not support this command."));
10885 if (buf
[0] == 'O' && buf
[1] != 'K')
10887 remote_console_output (buf
+ 1); /* 'O' message from stub. */
10890 if (strcmp (buf
, "OK") == 0)
10892 if (strlen (buf
) == 3 && buf
[0] == 'E'
10893 && isdigit (buf
[1]) && isdigit (buf
[2]))
10895 error (_("Protocol error with Rcmd"));
10897 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
10899 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
10901 fputc_unfiltered (c
, outbuf
);
10907 static VEC(mem_region_s
) *
10908 remote_memory_map (struct target_ops
*ops
)
10910 VEC(mem_region_s
) *result
= NULL
;
10911 char *text
= target_read_stralloc (¤t_target
,
10912 TARGET_OBJECT_MEMORY_MAP
, NULL
);
10916 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10918 result
= parse_memory_map (text
);
10919 do_cleanups (back_to
);
10926 packet_command (const char *args
, int from_tty
)
10928 struct remote_state
*rs
= get_remote_state ();
10930 if (!rs
->remote_desc
)
10931 error (_("command can only be used with remote target"));
10934 error (_("remote-packet command requires packet text as argument"));
10936 puts_filtered ("sending: ");
10937 print_packet (args
);
10938 puts_filtered ("\n");
10941 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10942 puts_filtered ("received: ");
10943 print_packet (rs
->buf
);
10944 puts_filtered ("\n");
10948 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
10950 static void display_thread_info (struct gdb_ext_thread_info
*info
);
10952 static void threadset_test_cmd (char *cmd
, int tty
);
10954 static void threadalive_test (char *cmd
, int tty
);
10956 static void threadlist_test_cmd (char *cmd
, int tty
);
10958 int get_and_display_threadinfo (threadref
*ref
);
10960 static void threadinfo_test_cmd (char *cmd
, int tty
);
10962 static int thread_display_step (threadref
*ref
, void *context
);
10964 static void threadlist_update_test_cmd (char *cmd
, int tty
);
10966 static void init_remote_threadtests (void);
10968 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
10971 threadset_test_cmd (char *cmd
, int tty
)
10973 int sample_thread
= SAMPLE_THREAD
;
10975 printf_filtered (_("Remote threadset test\n"));
10976 set_general_thread (sample_thread
);
10981 threadalive_test (char *cmd
, int tty
)
10983 int sample_thread
= SAMPLE_THREAD
;
10984 int pid
= ptid_get_pid (inferior_ptid
);
10985 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
10987 if (remote_thread_alive (ptid
))
10988 printf_filtered ("PASS: Thread alive test\n");
10990 printf_filtered ("FAIL: Thread alive test\n");
10993 void output_threadid (char *title
, threadref
*ref
);
10996 output_threadid (char *title
, threadref
*ref
)
11000 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
11002 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
11006 threadlist_test_cmd (char *cmd
, int tty
)
11009 threadref nextthread
;
11010 int done
, result_count
;
11011 threadref threadlist
[3];
11013 printf_filtered ("Remote Threadlist test\n");
11014 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
11015 &result_count
, &threadlist
[0]))
11016 printf_filtered ("FAIL: threadlist test\n");
11019 threadref
*scan
= threadlist
;
11020 threadref
*limit
= scan
+ result_count
;
11022 while (scan
< limit
)
11023 output_threadid (" thread ", scan
++);
11028 display_thread_info (struct gdb_ext_thread_info
*info
)
11030 output_threadid ("Threadid: ", &info
->threadid
);
11031 printf_filtered ("Name: %s\n ", info
->shortname
);
11032 printf_filtered ("State: %s\n", info
->display
);
11033 printf_filtered ("other: %s\n\n", info
->more_display
);
11037 get_and_display_threadinfo (threadref
*ref
)
11041 struct gdb_ext_thread_info threadinfo
;
11043 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
11044 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
11045 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
11046 display_thread_info (&threadinfo
);
11051 threadinfo_test_cmd (char *cmd
, int tty
)
11053 int athread
= SAMPLE_THREAD
;
11057 int_to_threadref (&thread
, athread
);
11058 printf_filtered ("Remote Threadinfo test\n");
11059 if (!get_and_display_threadinfo (&thread
))
11060 printf_filtered ("FAIL cannot get thread info\n");
11064 thread_display_step (threadref
*ref
, void *context
)
11066 /* output_threadid(" threadstep ",ref); *//* simple test */
11067 return get_and_display_threadinfo (ref
);
11071 threadlist_update_test_cmd (char *cmd
, int tty
)
11073 printf_filtered ("Remote Threadlist update test\n");
11074 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
11078 init_remote_threadtests (void)
11080 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
11081 _("Fetch and print the remote list of "
11082 "thread identifiers, one pkt only"));
11083 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
11084 _("Fetch and display info about one thread"));
11085 add_com ("tset", class_obscure
, threadset_test_cmd
,
11086 _("Test setting to a different thread"));
11087 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
11088 _("Iterate through updating all remote thread info"));
11089 add_com ("talive", class_obscure
, threadalive_test
,
11090 _(" Remote thread alive test "));
11095 /* Convert a thread ID to a string. Returns the string in a static
11098 static const char *
11099 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
11101 static char buf
[64];
11102 struct remote_state
*rs
= get_remote_state ();
11104 if (ptid_equal (ptid
, null_ptid
))
11105 return normal_pid_to_str (ptid
);
11106 else if (ptid_is_pid (ptid
))
11108 /* Printing an inferior target id. */
11110 /* When multi-process extensions are off, there's no way in the
11111 remote protocol to know the remote process id, if there's any
11112 at all. There's one exception --- when we're connected with
11113 target extended-remote, and we manually attached to a process
11114 with "attach PID". We don't record anywhere a flag that
11115 allows us to distinguish that case from the case of
11116 connecting with extended-remote and the stub already being
11117 attached to a process, and reporting yes to qAttached, hence
11118 no smart special casing here. */
11119 if (!remote_multi_process_p (rs
))
11121 xsnprintf (buf
, sizeof buf
, "Remote target");
11125 return normal_pid_to_str (ptid
);
11129 if (ptid_equal (magic_null_ptid
, ptid
))
11130 xsnprintf (buf
, sizeof buf
, "Thread <main>");
11131 else if (remote_multi_process_p (rs
))
11132 if (ptid_get_lwp (ptid
) == 0)
11133 return normal_pid_to_str (ptid
);
11135 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
11136 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
11138 xsnprintf (buf
, sizeof buf
, "Thread %ld",
11139 ptid_get_lwp (ptid
));
11144 /* Get the address of the thread local variable in OBJFILE which is
11145 stored at OFFSET within the thread local storage for thread PTID. */
11148 remote_get_thread_local_address (struct target_ops
*ops
,
11149 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
11151 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
11153 struct remote_state
*rs
= get_remote_state ();
11155 char *endp
= rs
->buf
+ get_remote_packet_size ();
11156 enum packet_result result
;
11158 strcpy (p
, "qGetTLSAddr:");
11160 p
= write_ptid (p
, endp
, ptid
);
11162 p
+= hexnumstr (p
, offset
);
11164 p
+= hexnumstr (p
, lm
);
11168 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11169 result
= packet_ok (rs
->buf
,
11170 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
11171 if (result
== PACKET_OK
)
11175 unpack_varlen_hex (rs
->buf
, &result
);
11178 else if (result
== PACKET_UNKNOWN
)
11179 throw_error (TLS_GENERIC_ERROR
,
11180 _("Remote target doesn't support qGetTLSAddr packet"));
11182 throw_error (TLS_GENERIC_ERROR
,
11183 _("Remote target failed to process qGetTLSAddr request"));
11186 throw_error (TLS_GENERIC_ERROR
,
11187 _("TLS not supported or disabled on this target"));
11192 /* Provide thread local base, i.e. Thread Information Block address.
11193 Returns 1 if ptid is found and thread_local_base is non zero. */
11196 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
11198 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
11200 struct remote_state
*rs
= get_remote_state ();
11202 char *endp
= rs
->buf
+ get_remote_packet_size ();
11203 enum packet_result result
;
11205 strcpy (p
, "qGetTIBAddr:");
11207 p
= write_ptid (p
, endp
, ptid
);
11211 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11212 result
= packet_ok (rs
->buf
,
11213 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
11214 if (result
== PACKET_OK
)
11218 unpack_varlen_hex (rs
->buf
, &result
);
11220 *addr
= (CORE_ADDR
) result
;
11223 else if (result
== PACKET_UNKNOWN
)
11224 error (_("Remote target doesn't support qGetTIBAddr packet"));
11226 error (_("Remote target failed to process qGetTIBAddr request"));
11229 error (_("qGetTIBAddr not supported or disabled on this target"));
11234 /* Support for inferring a target description based on the current
11235 architecture and the size of a 'g' packet. While the 'g' packet
11236 can have any size (since optional registers can be left off the
11237 end), some sizes are easily recognizable given knowledge of the
11238 approximate architecture. */
11240 struct remote_g_packet_guess
11243 const struct target_desc
*tdesc
;
11245 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
11246 DEF_VEC_O(remote_g_packet_guess_s
);
11248 struct remote_g_packet_data
11250 VEC(remote_g_packet_guess_s
) *guesses
;
11253 static struct gdbarch_data
*remote_g_packet_data_handle
;
11256 remote_g_packet_data_init (struct obstack
*obstack
)
11258 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
11262 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
11263 const struct target_desc
*tdesc
)
11265 struct remote_g_packet_data
*data
11266 = ((struct remote_g_packet_data
*)
11267 gdbarch_data (gdbarch
, remote_g_packet_data_handle
));
11268 struct remote_g_packet_guess new_guess
, *guess
;
11271 gdb_assert (tdesc
!= NULL
);
11274 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
11276 if (guess
->bytes
== bytes
)
11277 internal_error (__FILE__
, __LINE__
,
11278 _("Duplicate g packet description added for size %d"),
11281 new_guess
.bytes
= bytes
;
11282 new_guess
.tdesc
= tdesc
;
11283 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
11286 /* Return 1 if remote_read_description would do anything on this target
11287 and architecture, 0 otherwise. */
11290 remote_read_description_p (struct target_ops
*target
)
11292 struct remote_g_packet_data
*data
11293 = ((struct remote_g_packet_data
*)
11294 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
11296 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
11302 static const struct target_desc
*
11303 remote_read_description (struct target_ops
*target
)
11305 struct remote_g_packet_data
*data
11306 = ((struct remote_g_packet_data
*)
11307 gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
));
11309 /* Do not try this during initial connection, when we do not know
11310 whether there is a running but stopped thread. */
11311 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
11312 return target
->beneath
->to_read_description (target
->beneath
);
11314 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
11316 struct remote_g_packet_guess
*guess
;
11318 int bytes
= send_g_packet ();
11321 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
11323 if (guess
->bytes
== bytes
)
11324 return guess
->tdesc
;
11326 /* We discard the g packet. A minor optimization would be to
11327 hold on to it, and fill the register cache once we have selected
11328 an architecture, but it's too tricky to do safely. */
11331 return target
->beneath
->to_read_description (target
->beneath
);
11334 /* Remote file transfer support. This is host-initiated I/O, not
11335 target-initiated; for target-initiated, see remote-fileio.c. */
11337 /* If *LEFT is at least the length of STRING, copy STRING to
11338 *BUFFER, update *BUFFER to point to the new end of the buffer, and
11339 decrease *LEFT. Otherwise raise an error. */
11342 remote_buffer_add_string (char **buffer
, int *left
, const char *string
)
11344 int len
= strlen (string
);
11347 error (_("Packet too long for target."));
11349 memcpy (*buffer
, string
, len
);
11353 /* NUL-terminate the buffer as a convenience, if there is
11359 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
11360 *BUFFER, update *BUFFER to point to the new end of the buffer, and
11361 decrease *LEFT. Otherwise raise an error. */
11364 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
11367 if (2 * len
> *left
)
11368 error (_("Packet too long for target."));
11370 bin2hex (bytes
, *buffer
, len
);
11371 *buffer
+= 2 * len
;
11374 /* NUL-terminate the buffer as a convenience, if there is
11380 /* If *LEFT is large enough, convert VALUE to hex and add it to
11381 *BUFFER, update *BUFFER to point to the new end of the buffer, and
11382 decrease *LEFT. Otherwise raise an error. */
11385 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
11387 int len
= hexnumlen (value
);
11390 error (_("Packet too long for target."));
11392 hexnumstr (*buffer
, value
);
11396 /* NUL-terminate the buffer as a convenience, if there is
11402 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
11403 value, *REMOTE_ERRNO to the remote error number or zero if none
11404 was included, and *ATTACHMENT to point to the start of the annex
11405 if any. The length of the packet isn't needed here; there may
11406 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
11408 Return 0 if the packet could be parsed, -1 if it could not. If
11409 -1 is returned, the other variables may not be initialized. */
11412 remote_hostio_parse_result (char *buffer
, int *retcode
,
11413 int *remote_errno
, char **attachment
)
11418 *attachment
= NULL
;
11420 if (buffer
[0] != 'F')
11424 *retcode
= strtol (&buffer
[1], &p
, 16);
11425 if (errno
!= 0 || p
== &buffer
[1])
11428 /* Check for ",errno". */
11432 *remote_errno
= strtol (p
+ 1, &p2
, 16);
11433 if (errno
!= 0 || p
+ 1 == p2
)
11438 /* Check for ";attachment". If there is no attachment, the
11439 packet should end here. */
11442 *attachment
= p
+ 1;
11445 else if (*p
== '\0')
11451 /* Send a prepared I/O packet to the target and read its response.
11452 The prepared packet is in the global RS->BUF before this function
11453 is called, and the answer is there when we return.
11455 COMMAND_BYTES is the length of the request to send, which may include
11456 binary data. WHICH_PACKET is the packet configuration to check
11457 before attempting a packet. If an error occurs, *REMOTE_ERRNO
11458 is set to the error number and -1 is returned. Otherwise the value
11459 returned by the function is returned.
11461 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
11462 attachment is expected; an error will be reported if there's a
11463 mismatch. If one is found, *ATTACHMENT will be set to point into
11464 the packet buffer and *ATTACHMENT_LEN will be set to the
11465 attachment's length. */
11468 remote_hostio_send_command (int command_bytes
, int which_packet
,
11469 int *remote_errno
, char **attachment
,
11470 int *attachment_len
)
11472 struct remote_state
*rs
= get_remote_state ();
11473 int ret
, bytes_read
;
11474 char *attachment_tmp
;
11476 if (!rs
->remote_desc
11477 || packet_support (which_packet
) == PACKET_DISABLE
)
11479 *remote_errno
= FILEIO_ENOSYS
;
11483 putpkt_binary (rs
->buf
, command_bytes
);
11484 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
11486 /* If it timed out, something is wrong. Don't try to parse the
11488 if (bytes_read
< 0)
11490 *remote_errno
= FILEIO_EINVAL
;
11494 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
11497 *remote_errno
= FILEIO_EINVAL
;
11499 case PACKET_UNKNOWN
:
11500 *remote_errno
= FILEIO_ENOSYS
;
11506 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
11509 *remote_errno
= FILEIO_EINVAL
;
11513 /* Make sure we saw an attachment if and only if we expected one. */
11514 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
11515 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
11517 *remote_errno
= FILEIO_EINVAL
;
11521 /* If an attachment was found, it must point into the packet buffer;
11522 work out how many bytes there were. */
11523 if (attachment_tmp
!= NULL
)
11525 *attachment
= attachment_tmp
;
11526 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
11532 /* Invalidate the readahead cache. */
11535 readahead_cache_invalidate (void)
11537 struct remote_state
*rs
= get_remote_state ();
11539 rs
->readahead_cache
.fd
= -1;
11542 /* Invalidate the readahead cache if it is holding data for FD. */
11545 readahead_cache_invalidate_fd (int fd
)
11547 struct remote_state
*rs
= get_remote_state ();
11549 if (rs
->readahead_cache
.fd
== fd
)
11550 rs
->readahead_cache
.fd
= -1;
11553 /* Set the filesystem remote_hostio functions that take FILENAME
11554 arguments will use. Return 0 on success, or -1 if an error
11555 occurs (and set *REMOTE_ERRNO). */
11558 remote_hostio_set_filesystem (struct inferior
*inf
, int *remote_errno
)
11560 struct remote_state
*rs
= get_remote_state ();
11561 int required_pid
= (inf
== NULL
|| inf
->fake_pid_p
) ? 0 : inf
->pid
;
11563 int left
= get_remote_packet_size () - 1;
11567 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
11570 if (rs
->fs_pid
!= -1 && required_pid
== rs
->fs_pid
)
11573 remote_buffer_add_string (&p
, &left
, "vFile:setfs:");
11575 xsnprintf (arg
, sizeof (arg
), "%x", required_pid
);
11576 remote_buffer_add_string (&p
, &left
, arg
);
11578 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_setfs
,
11579 remote_errno
, NULL
, NULL
);
11581 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
11585 rs
->fs_pid
= required_pid
;
11590 /* Implementation of to_fileio_open. */
11593 remote_hostio_open (struct target_ops
*self
,
11594 struct inferior
*inf
, const char *filename
,
11595 int flags
, int mode
, int warn_if_slow
,
11598 struct remote_state
*rs
= get_remote_state ();
11600 int left
= get_remote_packet_size () - 1;
11604 static int warning_issued
= 0;
11606 printf_unfiltered (_("Reading %s from remote target...\n"),
11609 if (!warning_issued
)
11611 warning (_("File transfers from remote targets can be slow."
11612 " Use \"set sysroot\" to access files locally"
11614 warning_issued
= 1;
11618 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11621 remote_buffer_add_string (&p
, &left
, "vFile:open:");
11623 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11624 strlen (filename
));
11625 remote_buffer_add_string (&p
, &left
, ",");
11627 remote_buffer_add_int (&p
, &left
, flags
);
11628 remote_buffer_add_string (&p
, &left
, ",");
11630 remote_buffer_add_int (&p
, &left
, mode
);
11632 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
11633 remote_errno
, NULL
, NULL
);
11636 /* Implementation of to_fileio_pwrite. */
11639 remote_hostio_pwrite (struct target_ops
*self
,
11640 int fd
, const gdb_byte
*write_buf
, int len
,
11641 ULONGEST offset
, int *remote_errno
)
11643 struct remote_state
*rs
= get_remote_state ();
11645 int left
= get_remote_packet_size ();
11648 readahead_cache_invalidate_fd (fd
);
11650 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
11652 remote_buffer_add_int (&p
, &left
, fd
);
11653 remote_buffer_add_string (&p
, &left
, ",");
11655 remote_buffer_add_int (&p
, &left
, offset
);
11656 remote_buffer_add_string (&p
, &left
, ",");
11658 p
+= remote_escape_output (write_buf
, len
, 1, (gdb_byte
*) p
, &out_len
,
11659 get_remote_packet_size () - (p
- rs
->buf
));
11661 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
11662 remote_errno
, NULL
, NULL
);
11665 /* Helper for the implementation of to_fileio_pread. Read the file
11666 from the remote side with vFile:pread. */
11669 remote_hostio_pread_vFile (struct target_ops
*self
,
11670 int fd
, gdb_byte
*read_buf
, int len
,
11671 ULONGEST offset
, int *remote_errno
)
11673 struct remote_state
*rs
= get_remote_state ();
11676 int left
= get_remote_packet_size ();
11677 int ret
, attachment_len
;
11680 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
11682 remote_buffer_add_int (&p
, &left
, fd
);
11683 remote_buffer_add_string (&p
, &left
, ",");
11685 remote_buffer_add_int (&p
, &left
, len
);
11686 remote_buffer_add_string (&p
, &left
, ",");
11688 remote_buffer_add_int (&p
, &left
, offset
);
11690 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
11691 remote_errno
, &attachment
,
11697 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11699 if (read_len
!= ret
)
11700 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
11705 /* Serve pread from the readahead cache. Returns number of bytes
11706 read, or 0 if the request can't be served from the cache. */
11709 remote_hostio_pread_from_cache (struct remote_state
*rs
,
11710 int fd
, gdb_byte
*read_buf
, size_t len
,
11713 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11715 if (cache
->fd
== fd
11716 && cache
->offset
<= offset
11717 && offset
< cache
->offset
+ cache
->bufsize
)
11719 ULONGEST max
= cache
->offset
+ cache
->bufsize
;
11721 if (offset
+ len
> max
)
11722 len
= max
- offset
;
11724 memcpy (read_buf
, cache
->buf
+ offset
- cache
->offset
, len
);
11731 /* Implementation of to_fileio_pread. */
11734 remote_hostio_pread (struct target_ops
*self
,
11735 int fd
, gdb_byte
*read_buf
, int len
,
11736 ULONGEST offset
, int *remote_errno
)
11739 struct remote_state
*rs
= get_remote_state ();
11740 struct readahead_cache
*cache
= &rs
->readahead_cache
;
11742 ret
= remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11745 cache
->hit_count
++;
11748 fprintf_unfiltered (gdb_stdlog
, "readahead cache hit %s\n",
11749 pulongest (cache
->hit_count
));
11753 cache
->miss_count
++;
11755 fprintf_unfiltered (gdb_stdlog
, "readahead cache miss %s\n",
11756 pulongest (cache
->miss_count
));
11759 cache
->offset
= offset
;
11760 cache
->bufsize
= get_remote_packet_size ();
11761 cache
->buf
= (gdb_byte
*) xrealloc (cache
->buf
, cache
->bufsize
);
11763 ret
= remote_hostio_pread_vFile (self
, cache
->fd
, cache
->buf
, cache
->bufsize
,
11764 cache
->offset
, remote_errno
);
11767 readahead_cache_invalidate_fd (fd
);
11771 cache
->bufsize
= ret
;
11772 return remote_hostio_pread_from_cache (rs
, fd
, read_buf
, len
, offset
);
11775 /* Implementation of to_fileio_close. */
11778 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
11780 struct remote_state
*rs
= get_remote_state ();
11782 int left
= get_remote_packet_size () - 1;
11784 readahead_cache_invalidate_fd (fd
);
11786 remote_buffer_add_string (&p
, &left
, "vFile:close:");
11788 remote_buffer_add_int (&p
, &left
, fd
);
11790 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
11791 remote_errno
, NULL
, NULL
);
11794 /* Implementation of to_fileio_unlink. */
11797 remote_hostio_unlink (struct target_ops
*self
,
11798 struct inferior
*inf
, const char *filename
,
11801 struct remote_state
*rs
= get_remote_state ();
11803 int left
= get_remote_packet_size () - 1;
11805 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11808 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
11810 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11811 strlen (filename
));
11813 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
11814 remote_errno
, NULL
, NULL
);
11817 /* Implementation of to_fileio_readlink. */
11820 remote_hostio_readlink (struct target_ops
*self
,
11821 struct inferior
*inf
, const char *filename
,
11824 struct remote_state
*rs
= get_remote_state ();
11827 int left
= get_remote_packet_size ();
11828 int len
, attachment_len
;
11832 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
11835 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
11837 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
11838 strlen (filename
));
11840 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
11841 remote_errno
, &attachment
,
11847 ret
= (char *) xmalloc (len
+ 1);
11849 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11850 (gdb_byte
*) ret
, len
);
11851 if (read_len
!= len
)
11852 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
11858 /* Implementation of to_fileio_fstat. */
11861 remote_hostio_fstat (struct target_ops
*self
,
11862 int fd
, struct stat
*st
,
11865 struct remote_state
*rs
= get_remote_state ();
11867 int left
= get_remote_packet_size ();
11868 int attachment_len
, ret
;
11870 struct fio_stat fst
;
11873 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
11875 remote_buffer_add_int (&p
, &left
, fd
);
11877 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
11878 remote_errno
, &attachment
,
11882 if (*remote_errno
!= FILEIO_ENOSYS
)
11885 /* Strictly we should return -1, ENOSYS here, but when
11886 "set sysroot remote:" was implemented in August 2008
11887 BFD's need for a stat function was sidestepped with
11888 this hack. This was not remedied until March 2015
11889 so we retain the previous behavior to avoid breaking
11892 Note that the memset is a March 2015 addition; older
11893 GDBs set st_size *and nothing else* so the structure
11894 would have garbage in all other fields. This might
11895 break something but retaining the previous behavior
11896 here would be just too wrong. */
11898 memset (st
, 0, sizeof (struct stat
));
11899 st
->st_size
= INT_MAX
;
11903 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
11904 (gdb_byte
*) &fst
, sizeof (fst
));
11906 if (read_len
!= ret
)
11907 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
11909 if (read_len
!= sizeof (fst
))
11910 error (_("vFile:fstat returned %d bytes, but expecting %d."),
11911 read_len
, (int) sizeof (fst
));
11913 remote_fileio_to_host_stat (&fst
, st
);
11918 /* Implementation of to_filesystem_is_local. */
11921 remote_filesystem_is_local (struct target_ops
*self
)
11923 /* Valgrind GDB presents itself as a remote target but works
11924 on the local filesystem: it does not implement remote get
11925 and users are not expected to set a sysroot. To handle
11926 this case we treat the remote filesystem as local if the
11927 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
11928 does not support vFile:open. */
11929 if (strcmp (gdb_sysroot
, TARGET_SYSROOT_PREFIX
) == 0)
11931 enum packet_support ps
= packet_support (PACKET_vFile_open
);
11933 if (ps
== PACKET_SUPPORT_UNKNOWN
)
11935 int fd
, remote_errno
;
11937 /* Try opening a file to probe support. The supplied
11938 filename is irrelevant, we only care about whether
11939 the stub recognizes the packet or not. */
11940 fd
= remote_hostio_open (self
, NULL
, "just probing",
11941 FILEIO_O_RDONLY
, 0700, 0,
11945 remote_hostio_close (self
, fd
, &remote_errno
);
11947 ps
= packet_support (PACKET_vFile_open
);
11950 if (ps
== PACKET_DISABLE
)
11952 static int warning_issued
= 0;
11954 if (!warning_issued
)
11956 warning (_("remote target does not support file"
11957 " transfer, attempting to access files"
11958 " from local filesystem."));
11959 warning_issued
= 1;
11970 remote_fileio_errno_to_host (int errnum
)
11976 case FILEIO_ENOENT
:
11984 case FILEIO_EACCES
:
11986 case FILEIO_EFAULT
:
11990 case FILEIO_EEXIST
:
11992 case FILEIO_ENODEV
:
11994 case FILEIO_ENOTDIR
:
11996 case FILEIO_EISDIR
:
11998 case FILEIO_EINVAL
:
12000 case FILEIO_ENFILE
:
12002 case FILEIO_EMFILE
:
12006 case FILEIO_ENOSPC
:
12008 case FILEIO_ESPIPE
:
12012 case FILEIO_ENOSYS
:
12014 case FILEIO_ENAMETOOLONG
:
12015 return ENAMETOOLONG
;
12021 remote_hostio_error (int errnum
)
12023 int host_error
= remote_fileio_errno_to_host (errnum
);
12025 if (host_error
== -1)
12026 error (_("Unknown remote I/O error %d"), errnum
);
12028 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
12032 remote_hostio_close_cleanup (void *opaque
)
12034 int fd
= *(int *) opaque
;
12037 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
12041 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
12043 struct cleanup
*back_to
, *close_cleanup
;
12044 int retcode
, fd
, remote_errno
, bytes
, io_size
;
12046 int bytes_in_buffer
;
12049 struct remote_state
*rs
= get_remote_state ();
12051 if (!rs
->remote_desc
)
12052 error (_("command can only be used with remote target"));
12054 gdb_file_up file
= gdb_fopen_cloexec (local_file
, "rb");
12056 perror_with_name (local_file
);
12058 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
12059 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
12061 0700, 0, &remote_errno
);
12063 remote_hostio_error (remote_errno
);
12065 /* Send up to this many bytes at once. They won't all fit in the
12066 remote packet limit, so we'll transfer slightly fewer. */
12067 io_size
= get_remote_packet_size ();
12068 buffer
= (gdb_byte
*) xmalloc (io_size
);
12069 back_to
= make_cleanup (xfree
, buffer
);
12071 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
12073 bytes_in_buffer
= 0;
12076 while (bytes_in_buffer
|| !saw_eof
)
12080 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
12081 io_size
- bytes_in_buffer
,
12085 if (ferror (file
.get ()))
12086 error (_("Error reading %s."), local_file
);
12089 /* EOF. Unless there is something still in the
12090 buffer from the last iteration, we are done. */
12092 if (bytes_in_buffer
== 0)
12100 bytes
+= bytes_in_buffer
;
12101 bytes_in_buffer
= 0;
12103 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
12105 offset
, &remote_errno
);
12108 remote_hostio_error (remote_errno
);
12109 else if (retcode
== 0)
12110 error (_("Remote write of %d bytes returned 0!"), bytes
);
12111 else if (retcode
< bytes
)
12113 /* Short write. Save the rest of the read data for the next
12115 bytes_in_buffer
= bytes
- retcode
;
12116 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
12122 discard_cleanups (close_cleanup
);
12123 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
12124 remote_hostio_error (remote_errno
);
12127 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
12128 do_cleanups (back_to
);
12132 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
12134 struct cleanup
*back_to
, *close_cleanup
;
12135 int fd
, remote_errno
, bytes
, io_size
;
12138 struct remote_state
*rs
= get_remote_state ();
12140 if (!rs
->remote_desc
)
12141 error (_("command can only be used with remote target"));
12143 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
12144 remote_file
, FILEIO_O_RDONLY
, 0, 0,
12147 remote_hostio_error (remote_errno
);
12149 gdb_file_up file
= gdb_fopen_cloexec (local_file
, "wb");
12151 perror_with_name (local_file
);
12153 /* Send up to this many bytes at once. They won't all fit in the
12154 remote packet limit, so we'll transfer slightly fewer. */
12155 io_size
= get_remote_packet_size ();
12156 buffer
= (gdb_byte
*) xmalloc (io_size
);
12157 back_to
= make_cleanup (xfree
, buffer
);
12159 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
12164 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
12165 fd
, buffer
, io_size
, offset
, &remote_errno
);
12167 /* Success, but no bytes, means end-of-file. */
12170 remote_hostio_error (remote_errno
);
12174 bytes
= fwrite (buffer
, 1, bytes
, file
.get ());
12176 perror_with_name (local_file
);
12179 discard_cleanups (close_cleanup
);
12180 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
12181 remote_hostio_error (remote_errno
);
12184 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
12185 do_cleanups (back_to
);
12189 remote_file_delete (const char *remote_file
, int from_tty
)
12191 int retcode
, remote_errno
;
12192 struct remote_state
*rs
= get_remote_state ();
12194 if (!rs
->remote_desc
)
12195 error (_("command can only be used with remote target"));
12197 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
12198 NULL
, remote_file
, &remote_errno
);
12200 remote_hostio_error (remote_errno
);
12203 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
12207 remote_put_command (const char *args
, int from_tty
)
12210 error_no_arg (_("file to put"));
12212 gdb_argv
argv (args
);
12213 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
12214 error (_("Invalid parameters to remote put"));
12216 remote_file_put (argv
[0], argv
[1], from_tty
);
12220 remote_get_command (const char *args
, int from_tty
)
12223 error_no_arg (_("file to get"));
12225 gdb_argv
argv (args
);
12226 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
12227 error (_("Invalid parameters to remote get"));
12229 remote_file_get (argv
[0], argv
[1], from_tty
);
12233 remote_delete_command (const char *args
, int from_tty
)
12236 error_no_arg (_("file to delete"));
12238 gdb_argv
argv (args
);
12239 if (argv
[0] == NULL
|| argv
[1] != NULL
)
12240 error (_("Invalid parameters to remote delete"));
12242 remote_file_delete (argv
[0], from_tty
);
12246 remote_command (const char *args
, int from_tty
)
12248 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
12252 remote_can_execute_reverse (struct target_ops
*self
)
12254 if (packet_support (PACKET_bs
) == PACKET_ENABLE
12255 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
12262 remote_supports_non_stop (struct target_ops
*self
)
12268 remote_supports_disable_randomization (struct target_ops
*self
)
12270 /* Only supported in extended mode. */
12275 remote_supports_multi_process (struct target_ops
*self
)
12277 struct remote_state
*rs
= get_remote_state ();
12279 return remote_multi_process_p (rs
);
12283 remote_supports_cond_tracepoints (void)
12285 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
12289 remote_supports_cond_breakpoints (struct target_ops
*self
)
12291 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
12295 remote_supports_fast_tracepoints (void)
12297 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
12301 remote_supports_static_tracepoints (void)
12303 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
12307 remote_supports_install_in_trace (void)
12309 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
12313 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
12315 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
12320 remote_supports_string_tracing (struct target_ops
*self
)
12322 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
12326 remote_can_run_breakpoint_commands (struct target_ops
*self
)
12328 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
12332 remote_trace_init (struct target_ops
*self
)
12334 struct remote_state
*rs
= get_remote_state ();
12337 remote_get_noisy_reply ();
12338 if (strcmp (rs
->buf
, "OK") != 0)
12339 error (_("Target does not support this command."));
12342 static void free_actions_list (char **actions_list
);
12343 static void free_actions_list_cleanup_wrapper (void *);
12345 free_actions_list_cleanup_wrapper (void *al
)
12347 free_actions_list ((char **) al
);
12351 free_actions_list (char **actions_list
)
12355 if (actions_list
== 0)
12358 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
12359 xfree (actions_list
[ndx
]);
12361 xfree (actions_list
);
12364 /* Recursive routine to walk through command list including loops, and
12365 download packets for each command. */
12368 remote_download_command_source (int num
, ULONGEST addr
,
12369 struct command_line
*cmds
)
12371 struct remote_state
*rs
= get_remote_state ();
12372 struct command_line
*cmd
;
12374 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
12376 QUIT
; /* Allow user to bail out with ^C. */
12377 strcpy (rs
->buf
, "QTDPsrc:");
12378 encode_source_string (num
, addr
, "cmd", cmd
->line
,
12379 rs
->buf
+ strlen (rs
->buf
),
12380 rs
->buf_size
- strlen (rs
->buf
));
12382 remote_get_noisy_reply ();
12383 if (strcmp (rs
->buf
, "OK"))
12384 warning (_("Target does not support source download."));
12386 if (cmd
->control_type
== while_control
12387 || cmd
->control_type
== while_stepping_control
)
12389 remote_download_command_source (num
, addr
, *cmd
->body_list
);
12391 QUIT
; /* Allow user to bail out with ^C. */
12392 strcpy (rs
->buf
, "QTDPsrc:");
12393 encode_source_string (num
, addr
, "cmd", "end",
12394 rs
->buf
+ strlen (rs
->buf
),
12395 rs
->buf_size
- strlen (rs
->buf
));
12397 remote_get_noisy_reply ();
12398 if (strcmp (rs
->buf
, "OK"))
12399 warning (_("Target does not support source download."));
12405 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
12407 #define BUF_SIZE 2048
12411 char buf
[BUF_SIZE
];
12412 char **tdp_actions
;
12413 char **stepping_actions
;
12415 struct cleanup
*old_chain
= NULL
;
12417 struct breakpoint
*b
= loc
->owner
;
12418 struct tracepoint
*t
= (struct tracepoint
*) b
;
12419 struct remote_state
*rs
= get_remote_state ();
12421 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
12422 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
12424 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
12427 tpaddr
= loc
->address
;
12428 sprintf_vma (addrbuf
, tpaddr
);
12429 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
12430 addrbuf
, /* address */
12431 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
12432 t
->step_count
, t
->pass_count
);
12433 /* Fast tracepoints are mostly handled by the target, but we can
12434 tell the target how big of an instruction block should be moved
12436 if (b
->type
== bp_fast_tracepoint
)
12438 /* Only test for support at download time; we may not know
12439 target capabilities at definition time. */
12440 if (remote_supports_fast_tracepoints ())
12442 if (gdbarch_fast_tracepoint_valid_at (loc
->gdbarch
, tpaddr
,
12444 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
12445 gdb_insn_length (loc
->gdbarch
, tpaddr
));
12447 /* If it passed validation at definition but fails now,
12448 something is very wrong. */
12449 internal_error (__FILE__
, __LINE__
,
12450 _("Fast tracepoint not "
12451 "valid during download"));
12454 /* Fast tracepoints are functionally identical to regular
12455 tracepoints, so don't take lack of support as a reason to
12456 give up on the trace run. */
12457 warning (_("Target does not support fast tracepoints, "
12458 "downloading %d as regular tracepoint"), b
->number
);
12460 else if (b
->type
== bp_static_tracepoint
)
12462 /* Only test for support at download time; we may not know
12463 target capabilities at definition time. */
12464 if (remote_supports_static_tracepoints ())
12466 struct static_tracepoint_marker marker
;
12468 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
12469 strcat (buf
, ":S");
12471 error (_("Static tracepoint not valid during download"));
12474 /* Fast tracepoints are functionally identical to regular
12475 tracepoints, so don't take lack of support as a reason
12476 to give up on the trace run. */
12477 error (_("Target does not support static tracepoints"));
12479 /* If the tracepoint has a conditional, make it into an agent
12480 expression and append to the definition. */
12483 /* Only test support at download time, we may not know target
12484 capabilities at definition time. */
12485 if (remote_supports_cond_tracepoints ())
12487 agent_expr_up aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
.get ());
12488 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
12490 pkt
= buf
+ strlen (buf
);
12491 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
12492 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
12496 warning (_("Target does not support conditional tracepoints, "
12497 "ignoring tp %d cond"), b
->number
);
12500 if (b
->commands
|| *default_collect
)
12503 remote_get_noisy_reply ();
12504 if (strcmp (rs
->buf
, "OK"))
12505 error (_("Target does not support tracepoints."));
12507 /* do_single_steps (t); */
12510 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
12512 QUIT
; /* Allow user to bail out with ^C. */
12513 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
12514 b
->number
, addrbuf
, /* address */
12516 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
12519 remote_get_noisy_reply ();
12520 if (strcmp (rs
->buf
, "OK"))
12521 error (_("Error on target while setting tracepoints."));
12524 if (stepping_actions
)
12526 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
12528 QUIT
; /* Allow user to bail out with ^C. */
12529 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
12530 b
->number
, addrbuf
, /* address */
12531 ((ndx
== 0) ? "S" : ""),
12532 stepping_actions
[ndx
],
12533 (stepping_actions
[ndx
+ 1] ? "-" : ""));
12535 remote_get_noisy_reply ();
12536 if (strcmp (rs
->buf
, "OK"))
12537 error (_("Error on target while setting tracepoints."));
12541 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
12543 if (b
->location
!= NULL
)
12545 strcpy (buf
, "QTDPsrc:");
12546 encode_source_string (b
->number
, loc
->address
, "at",
12547 event_location_to_string (b
->location
.get ()),
12548 buf
+ strlen (buf
), 2048 - strlen (buf
));
12550 remote_get_noisy_reply ();
12551 if (strcmp (rs
->buf
, "OK"))
12552 warning (_("Target does not support source download."));
12554 if (b
->cond_string
)
12556 strcpy (buf
, "QTDPsrc:");
12557 encode_source_string (b
->number
, loc
->address
,
12558 "cond", b
->cond_string
, buf
+ strlen (buf
),
12559 2048 - strlen (buf
));
12561 remote_get_noisy_reply ();
12562 if (strcmp (rs
->buf
, "OK"))
12563 warning (_("Target does not support source download."));
12565 remote_download_command_source (b
->number
, loc
->address
,
12566 breakpoint_commands (b
));
12569 do_cleanups (old_chain
);
12573 remote_can_download_tracepoint (struct target_ops
*self
)
12575 struct remote_state
*rs
= get_remote_state ();
12576 struct trace_status
*ts
;
12579 /* Don't try to install tracepoints until we've relocated our
12580 symbols, and fetched and merged the target's tracepoint list with
12582 if (rs
->starting_up
)
12585 ts
= current_trace_status ();
12586 status
= remote_get_trace_status (self
, ts
);
12588 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
12591 /* If we are in a tracing experiment, but remote stub doesn't support
12592 installing tracepoint in trace, we have to return. */
12593 if (!remote_supports_install_in_trace ())
12601 remote_download_trace_state_variable (struct target_ops
*self
,
12602 struct trace_state_variable
*tsv
)
12604 struct remote_state
*rs
= get_remote_state ();
12607 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
12608 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
12610 p
= rs
->buf
+ strlen (rs
->buf
);
12611 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
12612 error (_("Trace state variable name too long for tsv definition packet"));
12613 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
12616 remote_get_noisy_reply ();
12617 if (*rs
->buf
== '\0')
12618 error (_("Target does not support this command."));
12619 if (strcmp (rs
->buf
, "OK") != 0)
12620 error (_("Error on target while downloading trace state variable."));
12624 remote_enable_tracepoint (struct target_ops
*self
,
12625 struct bp_location
*location
)
12627 struct remote_state
*rs
= get_remote_state ();
12630 sprintf_vma (addr_buf
, location
->address
);
12631 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
12632 location
->owner
->number
, addr_buf
);
12634 remote_get_noisy_reply ();
12635 if (*rs
->buf
== '\0')
12636 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
12637 if (strcmp (rs
->buf
, "OK") != 0)
12638 error (_("Error on target while enabling tracepoint."));
12642 remote_disable_tracepoint (struct target_ops
*self
,
12643 struct bp_location
*location
)
12645 struct remote_state
*rs
= get_remote_state ();
12648 sprintf_vma (addr_buf
, location
->address
);
12649 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
12650 location
->owner
->number
, addr_buf
);
12652 remote_get_noisy_reply ();
12653 if (*rs
->buf
== '\0')
12654 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
12655 if (strcmp (rs
->buf
, "OK") != 0)
12656 error (_("Error on target while disabling tracepoint."));
12660 remote_trace_set_readonly_regions (struct target_ops
*self
)
12664 bfd_size_type size
;
12670 return; /* No information to give. */
12672 struct remote_state
*rs
= get_remote_state ();
12674 strcpy (rs
->buf
, "QTro");
12675 offset
= strlen (rs
->buf
);
12676 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
12678 char tmp1
[40], tmp2
[40];
12681 if ((s
->flags
& SEC_LOAD
) == 0 ||
12682 /* (s->flags & SEC_CODE) == 0 || */
12683 (s
->flags
& SEC_READONLY
) == 0)
12687 vma
= bfd_get_section_vma (abfd
, s
);
12688 size
= bfd_get_section_size (s
);
12689 sprintf_vma (tmp1
, vma
);
12690 sprintf_vma (tmp2
, vma
+ size
);
12691 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
12692 if (offset
+ sec_length
+ 1 > rs
->buf_size
)
12694 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
12696 Too many sections for read-only sections definition packet."));
12699 xsnprintf (rs
->buf
+ offset
, rs
->buf_size
- offset
, ":%s,%s",
12701 offset
+= sec_length
;
12706 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12711 remote_trace_start (struct target_ops
*self
)
12713 struct remote_state
*rs
= get_remote_state ();
12715 putpkt ("QTStart");
12716 remote_get_noisy_reply ();
12717 if (*rs
->buf
== '\0')
12718 error (_("Target does not support this command."));
12719 if (strcmp (rs
->buf
, "OK") != 0)
12720 error (_("Bogus reply from target: %s"), rs
->buf
);
12724 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
12726 /* Initialize it just to avoid a GCC false warning. */
12728 /* FIXME we need to get register block size some other way. */
12729 extern int trace_regblock_size
;
12730 enum packet_result result
;
12731 struct remote_state
*rs
= get_remote_state ();
12733 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
12736 trace_regblock_size
12737 = get_remote_arch_state (target_gdbarch ())->sizeof_g_packet
;
12739 putpkt ("qTStatus");
12743 p
= remote_get_noisy_reply ();
12745 CATCH (ex
, RETURN_MASK_ERROR
)
12747 if (ex
.error
!= TARGET_CLOSE_ERROR
)
12749 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
12752 throw_exception (ex
);
12756 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
12758 /* If the remote target doesn't do tracing, flag it. */
12759 if (result
== PACKET_UNKNOWN
)
12762 /* We're working with a live target. */
12763 ts
->filename
= NULL
;
12766 error (_("Bogus trace status reply from target: %s"), rs
->buf
);
12768 /* Function 'parse_trace_status' sets default value of each field of
12769 'ts' at first, so we don't have to do it here. */
12770 parse_trace_status (p
, ts
);
12772 return ts
->running
;
12776 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
12777 struct uploaded_tp
*utp
)
12779 struct remote_state
*rs
= get_remote_state ();
12781 struct bp_location
*loc
;
12782 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
12783 size_t size
= get_remote_packet_size ();
12788 tp
->traceframe_usage
= 0;
12789 for (loc
= tp
->loc
; loc
; loc
= loc
->next
)
12791 /* If the tracepoint was never downloaded, don't go asking for
12793 if (tp
->number_on_target
== 0)
12795 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
12796 phex_nz (loc
->address
, 0));
12798 reply
= remote_get_noisy_reply ();
12799 if (reply
&& *reply
)
12802 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12808 utp
->hit_count
= 0;
12809 utp
->traceframe_usage
= 0;
12810 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
12811 phex_nz (utp
->addr
, 0));
12813 reply
= remote_get_noisy_reply ();
12814 if (reply
&& *reply
)
12817 parse_tracepoint_status (reply
+ 1, bp
, utp
);
12823 remote_trace_stop (struct target_ops
*self
)
12825 struct remote_state
*rs
= get_remote_state ();
12828 remote_get_noisy_reply ();
12829 if (*rs
->buf
== '\0')
12830 error (_("Target does not support this command."));
12831 if (strcmp (rs
->buf
, "OK") != 0)
12832 error (_("Bogus reply from target: %s"), rs
->buf
);
12836 remote_trace_find (struct target_ops
*self
,
12837 enum trace_find_type type
, int num
,
12838 CORE_ADDR addr1
, CORE_ADDR addr2
,
12841 struct remote_state
*rs
= get_remote_state ();
12842 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12844 int target_frameno
= -1, target_tracept
= -1;
12846 /* Lookups other than by absolute frame number depend on the current
12847 trace selected, so make sure it is correct on the remote end
12849 if (type
!= tfind_number
)
12850 set_remote_traceframe ();
12853 strcpy (p
, "QTFrame:");
12854 p
= strchr (p
, '\0');
12858 xsnprintf (p
, endbuf
- p
, "%x", num
);
12861 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
12864 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
12867 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
12868 phex_nz (addr2
, 0));
12870 case tfind_outside
:
12871 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
12872 phex_nz (addr2
, 0));
12875 error (_("Unknown trace find type %d"), type
);
12879 reply
= remote_get_noisy_reply ();
12880 if (*reply
== '\0')
12881 error (_("Target does not support this command."));
12883 while (reply
&& *reply
)
12888 target_frameno
= (int) strtol (p
, &reply
, 16);
12890 error (_("Unable to parse trace frame number"));
12891 /* Don't update our remote traceframe number cache on failure
12892 to select a remote traceframe. */
12893 if (target_frameno
== -1)
12898 target_tracept
= (int) strtol (p
, &reply
, 16);
12900 error (_("Unable to parse tracepoint number"));
12902 case 'O': /* "OK"? */
12903 if (reply
[1] == 'K' && reply
[2] == '\0')
12906 error (_("Bogus reply from target: %s"), reply
);
12909 error (_("Bogus reply from target: %s"), reply
);
12912 *tpp
= target_tracept
;
12914 rs
->remote_traceframe_number
= target_frameno
;
12915 return target_frameno
;
12919 remote_get_trace_state_variable_value (struct target_ops
*self
,
12920 int tsvnum
, LONGEST
*val
)
12922 struct remote_state
*rs
= get_remote_state ();
12926 set_remote_traceframe ();
12928 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
12930 reply
= remote_get_noisy_reply ();
12931 if (reply
&& *reply
)
12935 unpack_varlen_hex (reply
+ 1, &uval
);
12936 *val
= (LONGEST
) uval
;
12944 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
12946 struct remote_state
*rs
= get_remote_state ();
12950 strcpy (p
, "QTSave:");
12952 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
12953 error (_("Remote file name too long for trace save packet"));
12954 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
12957 reply
= remote_get_noisy_reply ();
12958 if (*reply
== '\0')
12959 error (_("Target does not support this command."));
12960 if (strcmp (reply
, "OK") != 0)
12961 error (_("Bogus reply from target: %s"), reply
);
12965 /* This is basically a memory transfer, but needs to be its own packet
12966 because we don't know how the target actually organizes its trace
12967 memory, plus we want to be able to ask for as much as possible, but
12968 not be unhappy if we don't get as much as we ask for. */
12971 remote_get_raw_trace_data (struct target_ops
*self
,
12972 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
12974 struct remote_state
*rs
= get_remote_state ();
12980 strcpy (p
, "qTBuffer:");
12982 p
+= hexnumstr (p
, offset
);
12984 p
+= hexnumstr (p
, len
);
12988 reply
= remote_get_noisy_reply ();
12989 if (reply
&& *reply
)
12991 /* 'l' by itself means we're at the end of the buffer and
12992 there is nothing more to get. */
12996 /* Convert the reply into binary. Limit the number of bytes to
12997 convert according to our passed-in buffer size, rather than
12998 what was returned in the packet; if the target is
12999 unexpectedly generous and gives us a bigger reply than we
13000 asked for, we don't want to crash. */
13001 rslt
= hex2bin (reply
, buf
, len
);
13005 /* Something went wrong, flag as an error. */
13010 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
13012 struct remote_state
*rs
= get_remote_state ();
13014 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
13018 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
13020 reply
= remote_get_noisy_reply ();
13021 if (*reply
== '\0')
13022 error (_("Target does not support this command."));
13023 if (strcmp (reply
, "OK") != 0)
13024 error (_("Bogus reply from target: %s"), reply
);
13027 warning (_("Target does not support disconnected tracing."));
13031 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
13033 struct thread_info
*info
= find_thread_ptid (ptid
);
13035 if (info
&& info
->priv
)
13036 return info
->priv
->core
;
13041 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
13043 struct remote_state
*rs
= get_remote_state ();
13046 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
13048 reply
= remote_get_noisy_reply ();
13049 if (*reply
== '\0')
13050 error (_("Target does not support this command."));
13051 if (strcmp (reply
, "OK") != 0)
13052 error (_("Bogus reply from target: %s"), reply
);
13055 static traceframe_info_up
13056 remote_traceframe_info (struct target_ops
*self
)
13060 text
= target_read_stralloc (¤t_target
,
13061 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
13064 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
13065 traceframe_info_up info
= parse_traceframe_info (text
);
13067 do_cleanups (back_to
);
13074 /* Handle the qTMinFTPILen packet. Returns the minimum length of
13075 instruction on which a fast tracepoint may be placed. Returns -1
13076 if the packet is not supported, and 0 if the minimum instruction
13077 length is unknown. */
13080 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
13082 struct remote_state
*rs
= get_remote_state ();
13085 /* If we're not debugging a process yet, the IPA can't be
13087 if (!target_has_execution
)
13090 /* Make sure the remote is pointing at the right process. */
13091 set_general_process ();
13093 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
13095 reply
= remote_get_noisy_reply ();
13096 if (*reply
== '\0')
13100 ULONGEST min_insn_len
;
13102 unpack_varlen_hex (reply
, &min_insn_len
);
13104 return (int) min_insn_len
;
13109 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
13111 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
13113 struct remote_state
*rs
= get_remote_state ();
13114 char *buf
= rs
->buf
;
13115 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
13116 enum packet_result result
;
13118 gdb_assert (val
>= 0 || val
== -1);
13119 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
13120 /* Send -1 as literal "-1" to avoid host size dependency. */
13124 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
13127 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
13130 remote_get_noisy_reply ();
13131 result
= packet_ok (rs
->buf
,
13132 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
13134 if (result
!= PACKET_OK
)
13135 warning (_("Bogus reply from target: %s"), rs
->buf
);
13140 remote_set_trace_notes (struct target_ops
*self
,
13141 const char *user
, const char *notes
,
13142 const char *stop_notes
)
13144 struct remote_state
*rs
= get_remote_state ();
13146 char *buf
= rs
->buf
;
13147 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
13150 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
13153 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
13154 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
13160 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
13161 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
13167 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
13168 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
13172 /* Ensure the buffer is terminated. */
13176 reply
= remote_get_noisy_reply ();
13177 if (*reply
== '\0')
13180 if (strcmp (reply
, "OK") != 0)
13181 error (_("Bogus reply from target: %s"), reply
);
13187 remote_use_agent (struct target_ops
*self
, int use
)
13189 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
13191 struct remote_state
*rs
= get_remote_state ();
13193 /* If the stub supports QAgent. */
13194 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
13196 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13198 if (strcmp (rs
->buf
, "OK") == 0)
13209 remote_can_use_agent (struct target_ops
*self
)
13211 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
13214 struct btrace_target_info
13216 /* The ptid of the traced thread. */
13219 /* The obtained branch trace configuration. */
13220 struct btrace_config conf
;
13223 /* Reset our idea of our target's btrace configuration. */
13226 remote_btrace_reset (void)
13228 struct remote_state
*rs
= get_remote_state ();
13230 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
13233 /* Check whether the target supports branch tracing. */
13236 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
13238 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
13240 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
13245 case BTRACE_FORMAT_NONE
:
13248 case BTRACE_FORMAT_BTS
:
13249 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
13251 case BTRACE_FORMAT_PT
:
13252 /* The trace is decoded on the host. Even if our target supports it,
13253 we still need to have libipt to decode the trace. */
13254 #if defined (HAVE_LIBIPT)
13255 return (packet_support (PACKET_Qbtrace_pt
) == PACKET_ENABLE
);
13256 #else /* !defined (HAVE_LIBIPT) */
13258 #endif /* !defined (HAVE_LIBIPT) */
13261 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
13264 /* Synchronize the configuration with the target. */
13267 btrace_sync_conf (const struct btrace_config
*conf
)
13269 struct packet_config
*packet
;
13270 struct remote_state
*rs
;
13271 char *buf
, *pos
, *endbuf
;
13273 rs
= get_remote_state ();
13275 endbuf
= buf
+ get_remote_packet_size ();
13277 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
13278 if (packet_config_support (packet
) == PACKET_ENABLE
13279 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
13282 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
13286 getpkt (&buf
, &rs
->buf_size
, 0);
13288 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
13290 if (buf
[0] == 'E' && buf
[1] == '.')
13291 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
13293 error (_("Failed to configure the BTS buffer size."));
13296 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
13299 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
];
13300 if (packet_config_support (packet
) == PACKET_ENABLE
13301 && conf
->pt
.size
!= rs
->btrace_config
.pt
.size
)
13304 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
13308 getpkt (&buf
, &rs
->buf_size
, 0);
13310 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
13312 if (buf
[0] == 'E' && buf
[1] == '.')
13313 error (_("Failed to configure the trace buffer size: %s"), buf
+ 2);
13315 error (_("Failed to configure the trace buffer size."));
13318 rs
->btrace_config
.pt
.size
= conf
->pt
.size
;
13322 /* Read the current thread's btrace configuration from the target and
13323 store it into CONF. */
13326 btrace_read_config (struct btrace_config
*conf
)
13330 xml
= target_read_stralloc (¤t_target
,
13331 TARGET_OBJECT_BTRACE_CONF
, "");
13334 struct cleanup
*cleanup
;
13336 cleanup
= make_cleanup (xfree
, xml
);
13337 parse_xml_btrace_conf (conf
, xml
);
13338 do_cleanups (cleanup
);
13342 /* Maybe reopen target btrace. */
13345 remote_btrace_maybe_reopen (void)
13347 struct remote_state
*rs
= get_remote_state ();
13348 struct thread_info
*tp
;
13349 int btrace_target_pushed
= 0;
13352 scoped_restore_current_thread restore_thread
;
13354 ALL_NON_EXITED_THREADS (tp
)
13356 set_general_thread (tp
->ptid
);
13358 memset (&rs
->btrace_config
, 0x00, sizeof (struct btrace_config
));
13359 btrace_read_config (&rs
->btrace_config
);
13361 if (rs
->btrace_config
.format
== BTRACE_FORMAT_NONE
)
13364 #if !defined (HAVE_LIBIPT)
13365 if (rs
->btrace_config
.format
== BTRACE_FORMAT_PT
)
13370 warning (_("GDB does not support Intel Processor Trace. "
13371 "\"record\" will not work in this session."));
13376 #endif /* !defined (HAVE_LIBIPT) */
13378 /* Push target, once, but before anything else happens. This way our
13379 changes to the threads will be cleaned up by unpushing the target
13380 in case btrace_read_config () throws. */
13381 if (!btrace_target_pushed
)
13383 btrace_target_pushed
= 1;
13384 record_btrace_push_target ();
13385 printf_filtered (_("Target is recording using %s.\n"),
13386 btrace_format_string (rs
->btrace_config
.format
));
13389 tp
->btrace
.target
= XCNEW (struct btrace_target_info
);
13390 tp
->btrace
.target
->ptid
= tp
->ptid
;
13391 tp
->btrace
.target
->conf
= rs
->btrace_config
;
13395 /* Enable branch tracing. */
13397 static struct btrace_target_info
*
13398 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
13399 const struct btrace_config
*conf
)
13401 struct btrace_target_info
*tinfo
= NULL
;
13402 struct packet_config
*packet
= NULL
;
13403 struct remote_state
*rs
= get_remote_state ();
13404 char *buf
= rs
->buf
;
13405 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
13407 switch (conf
->format
)
13409 case BTRACE_FORMAT_BTS
:
13410 packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
13413 case BTRACE_FORMAT_PT
:
13414 packet
= &remote_protocol_packets
[PACKET_Qbtrace_pt
];
13418 if (packet
== NULL
|| packet_config_support (packet
) != PACKET_ENABLE
)
13419 error (_("Target does not support branch tracing."));
13421 btrace_sync_conf (conf
);
13423 set_general_thread (ptid
);
13425 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
13427 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13429 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
13431 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
13432 error (_("Could not enable branch tracing for %s: %s"),
13433 target_pid_to_str (ptid
), rs
->buf
+ 2);
13435 error (_("Could not enable branch tracing for %s."),
13436 target_pid_to_str (ptid
));
13439 tinfo
= XCNEW (struct btrace_target_info
);
13440 tinfo
->ptid
= ptid
;
13442 /* If we fail to read the configuration, we lose some information, but the
13443 tracing itself is not impacted. */
13446 btrace_read_config (&tinfo
->conf
);
13448 CATCH (err
, RETURN_MASK_ERROR
)
13450 if (err
.message
!= NULL
)
13451 warning ("%s", err
.message
);
13458 /* Disable branch tracing. */
13461 remote_disable_btrace (struct target_ops
*self
,
13462 struct btrace_target_info
*tinfo
)
13464 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
13465 struct remote_state
*rs
= get_remote_state ();
13466 char *buf
= rs
->buf
;
13467 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
13469 if (packet_config_support (packet
) != PACKET_ENABLE
)
13470 error (_("Target does not support branch tracing."));
13472 set_general_thread (tinfo
->ptid
);
13474 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
13476 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13478 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
13480 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
13481 error (_("Could not disable branch tracing for %s: %s"),
13482 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
13484 error (_("Could not disable branch tracing for %s."),
13485 target_pid_to_str (tinfo
->ptid
));
13491 /* Teardown branch tracing. */
13494 remote_teardown_btrace (struct target_ops
*self
,
13495 struct btrace_target_info
*tinfo
)
13497 /* We must not talk to the target during teardown. */
13501 /* Read the branch trace. */
13503 static enum btrace_error
13504 remote_read_btrace (struct target_ops
*self
,
13505 struct btrace_data
*btrace
,
13506 struct btrace_target_info
*tinfo
,
13507 enum btrace_read_type type
)
13509 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
13510 struct cleanup
*cleanup
;
13514 if (packet_config_support (packet
) != PACKET_ENABLE
)
13515 error (_("Target does not support branch tracing."));
13517 #if !defined(HAVE_LIBEXPAT)
13518 error (_("Cannot process branch tracing result. XML parsing not supported."));
13523 case BTRACE_READ_ALL
:
13526 case BTRACE_READ_NEW
:
13529 case BTRACE_READ_DELTA
:
13533 internal_error (__FILE__
, __LINE__
,
13534 _("Bad branch tracing read type: %u."),
13535 (unsigned int) type
);
13538 xml
= target_read_stralloc (¤t_target
,
13539 TARGET_OBJECT_BTRACE
, annex
);
13541 return BTRACE_ERR_UNKNOWN
;
13543 cleanup
= make_cleanup (xfree
, xml
);
13544 parse_xml_btrace (btrace
, xml
);
13545 do_cleanups (cleanup
);
13547 return BTRACE_ERR_NONE
;
13550 static const struct btrace_config
*
13551 remote_btrace_conf (struct target_ops
*self
,
13552 const struct btrace_target_info
*tinfo
)
13554 return &tinfo
->conf
;
13558 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
13560 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
13564 /* Implementation of to_load. */
13567 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
13569 generic_load (name
, from_tty
);
13572 /* Accepts an integer PID; returns a string representing a file that
13573 can be opened on the remote side to get the symbols for the child
13574 process. Returns NULL if the operation is not supported. */
13577 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
13579 static char *filename
= NULL
;
13580 struct inferior
*inf
;
13581 char *annex
= NULL
;
13583 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
13586 if (filename
!= NULL
)
13589 inf
= find_inferior_pid (pid
);
13591 internal_error (__FILE__
, __LINE__
,
13592 _("not currently attached to process %d"), pid
);
13594 if (!inf
->fake_pid_p
)
13596 const int annex_size
= 9;
13598 annex
= (char *) alloca (annex_size
);
13599 xsnprintf (annex
, annex_size
, "%x", pid
);
13602 filename
= target_read_stralloc (¤t_target
,
13603 TARGET_OBJECT_EXEC_FILE
, annex
);
13608 /* Implement the to_can_do_single_step target_ops method. */
13611 remote_can_do_single_step (struct target_ops
*ops
)
13613 /* We can only tell whether target supports single step or not by
13614 supported s and S vCont actions if the stub supports vContSupported
13615 feature. If the stub doesn't support vContSupported feature,
13616 we have conservatively to think target doesn't supports single
13618 if (packet_support (PACKET_vContSupported
) == PACKET_ENABLE
)
13620 struct remote_state
*rs
= get_remote_state ();
13622 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
13623 remote_vcont_probe (rs
);
13625 return rs
->supports_vCont
.s
&& rs
->supports_vCont
.S
;
13631 /* Implementation of the to_execution_direction method for the remote
13634 static enum exec_direction_kind
13635 remote_execution_direction (struct target_ops
*self
)
13637 struct remote_state
*rs
= get_remote_state ();
13639 return rs
->last_resume_exec_dir
;
13642 /* Return pointer to the thread_info struct which corresponds to
13643 THREAD_HANDLE (having length HANDLE_LEN). */
13645 static struct thread_info
*
13646 remote_thread_handle_to_thread_info (struct target_ops
*ops
,
13647 const gdb_byte
*thread_handle
,
13649 struct inferior
*inf
)
13651 struct thread_info
*tp
;
13653 ALL_NON_EXITED_THREADS (tp
)
13655 struct private_thread_info
*priv
= get_private_info_thread (tp
);
13657 if (tp
->inf
== inf
&& priv
!= NULL
)
13659 if (handle_len
!= priv
->thread_handle
->size ())
13660 error (_("Thread handle size mismatch: %d vs %zu (from remote)"),
13661 handle_len
, priv
->thread_handle
->size ());
13662 if (memcmp (thread_handle
, priv
->thread_handle
->data (),
13672 init_remote_ops (void)
13674 remote_ops
.to_shortname
= "remote";
13675 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
13676 remote_ops
.to_doc
=
13677 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13678 Specify the serial device it is connected to\n\
13679 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
13680 remote_ops
.to_open
= remote_open
;
13681 remote_ops
.to_close
= remote_close
;
13682 remote_ops
.to_detach
= remote_detach
;
13683 remote_ops
.to_disconnect
= remote_disconnect
;
13684 remote_ops
.to_resume
= remote_resume
;
13685 remote_ops
.to_commit_resume
= remote_commit_resume
;
13686 remote_ops
.to_wait
= remote_wait
;
13687 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
13688 remote_ops
.to_store_registers
= remote_store_registers
;
13689 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
13690 remote_ops
.to_files_info
= remote_files_info
;
13691 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
13692 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
13693 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
13694 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
13695 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
13696 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
13697 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
13698 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
13699 remote_ops
.to_watchpoint_addr_within_range
=
13700 remote_watchpoint_addr_within_range
;
13701 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
13702 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
13703 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
13704 remote_ops
.to_region_ok_for_hw_watchpoint
13705 = remote_region_ok_for_hw_watchpoint
;
13706 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
13707 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
13708 remote_ops
.to_kill
= remote_kill
;
13709 remote_ops
.to_load
= remote_load
;
13710 remote_ops
.to_mourn_inferior
= remote_mourn
;
13711 remote_ops
.to_pass_signals
= remote_pass_signals
;
13712 remote_ops
.to_set_syscall_catchpoint
= remote_set_syscall_catchpoint
;
13713 remote_ops
.to_program_signals
= remote_program_signals
;
13714 remote_ops
.to_thread_alive
= remote_thread_alive
;
13715 remote_ops
.to_thread_name
= remote_thread_name
;
13716 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
13717 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
13718 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
13719 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
13720 remote_ops
.to_stop
= remote_stop
;
13721 remote_ops
.to_interrupt
= remote_interrupt
;
13722 remote_ops
.to_pass_ctrlc
= remote_pass_ctrlc
;
13723 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
13724 remote_ops
.to_get_memory_xfer_limit
= remote_get_memory_xfer_limit
;
13725 remote_ops
.to_rcmd
= remote_rcmd
;
13726 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
13727 remote_ops
.to_log_command
= serial_log_command
;
13728 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
13729 remote_ops
.to_stratum
= process_stratum
;
13730 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
13731 remote_ops
.to_has_memory
= default_child_has_memory
;
13732 remote_ops
.to_has_stack
= default_child_has_stack
;
13733 remote_ops
.to_has_registers
= default_child_has_registers
;
13734 remote_ops
.to_has_execution
= default_child_has_execution
;
13735 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
13736 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
13737 remote_ops
.to_magic
= OPS_MAGIC
;
13738 remote_ops
.to_memory_map
= remote_memory_map
;
13739 remote_ops
.to_flash_erase
= remote_flash_erase
;
13740 remote_ops
.to_flash_done
= remote_flash_done
;
13741 remote_ops
.to_read_description
= remote_read_description
;
13742 remote_ops
.to_search_memory
= remote_search_memory
;
13743 remote_ops
.to_can_async_p
= remote_can_async_p
;
13744 remote_ops
.to_is_async_p
= remote_is_async_p
;
13745 remote_ops
.to_async
= remote_async
;
13746 remote_ops
.to_thread_events
= remote_thread_events
;
13747 remote_ops
.to_can_do_single_step
= remote_can_do_single_step
;
13748 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
13749 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
13750 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
13751 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
13752 remote_ops
.to_supports_disable_randomization
13753 = remote_supports_disable_randomization
;
13754 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
13755 remote_ops
.to_fileio_open
= remote_hostio_open
;
13756 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
13757 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
13758 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
13759 remote_ops
.to_fileio_close
= remote_hostio_close
;
13760 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
13761 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
13762 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
13763 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
13764 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
13765 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
13766 remote_ops
.to_trace_init
= remote_trace_init
;
13767 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
13768 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
13769 remote_ops
.to_download_trace_state_variable
13770 = remote_download_trace_state_variable
;
13771 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
13772 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
13773 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
13774 remote_ops
.to_trace_start
= remote_trace_start
;
13775 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
13776 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
13777 remote_ops
.to_trace_stop
= remote_trace_stop
;
13778 remote_ops
.to_trace_find
= remote_trace_find
;
13779 remote_ops
.to_get_trace_state_variable_value
13780 = remote_get_trace_state_variable_value
;
13781 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
13782 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
13783 remote_ops
.to_upload_trace_state_variables
13784 = remote_upload_trace_state_variables
;
13785 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
13786 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
13787 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
13788 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
13789 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
13790 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
13791 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
13792 remote_ops
.to_verify_memory
= remote_verify_memory
;
13793 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
13794 remote_ops
.to_set_permissions
= remote_set_permissions
;
13795 remote_ops
.to_static_tracepoint_marker_at
13796 = remote_static_tracepoint_marker_at
;
13797 remote_ops
.to_static_tracepoint_markers_by_strid
13798 = remote_static_tracepoint_markers_by_strid
;
13799 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
13800 remote_ops
.to_use_agent
= remote_use_agent
;
13801 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
13802 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
13803 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
13804 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
13805 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
13806 remote_ops
.to_read_btrace
= remote_read_btrace
;
13807 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
13808 remote_ops
.to_augmented_libraries_svr4_read
=
13809 remote_augmented_libraries_svr4_read
;
13810 remote_ops
.to_follow_fork
= remote_follow_fork
;
13811 remote_ops
.to_follow_exec
= remote_follow_exec
;
13812 remote_ops
.to_insert_fork_catchpoint
= remote_insert_fork_catchpoint
;
13813 remote_ops
.to_remove_fork_catchpoint
= remote_remove_fork_catchpoint
;
13814 remote_ops
.to_insert_vfork_catchpoint
= remote_insert_vfork_catchpoint
;
13815 remote_ops
.to_remove_vfork_catchpoint
= remote_remove_vfork_catchpoint
;
13816 remote_ops
.to_insert_exec_catchpoint
= remote_insert_exec_catchpoint
;
13817 remote_ops
.to_remove_exec_catchpoint
= remote_remove_exec_catchpoint
;
13818 remote_ops
.to_execution_direction
= remote_execution_direction
;
13819 remote_ops
.to_thread_handle_to_thread_info
=
13820 remote_thread_handle_to_thread_info
;
13823 /* Set up the extended remote vector by making a copy of the standard
13824 remote vector and adding to it. */
13827 init_extended_remote_ops (void)
13829 extended_remote_ops
= remote_ops
;
13831 extended_remote_ops
.to_shortname
= "extended-remote";
13832 extended_remote_ops
.to_longname
=
13833 "Extended remote serial target in gdb-specific protocol";
13834 extended_remote_ops
.to_doc
=
13835 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
13836 Specify the serial device it is connected to (e.g. /dev/ttya).";
13837 extended_remote_ops
.to_open
= extended_remote_open
;
13838 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
13839 extended_remote_ops
.to_detach
= extended_remote_detach
;
13840 extended_remote_ops
.to_attach
= extended_remote_attach
;
13841 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
13842 extended_remote_ops
.to_supports_disable_randomization
13843 = extended_remote_supports_disable_randomization
;
13847 remote_can_async_p (struct target_ops
*ops
)
13849 struct remote_state
*rs
= get_remote_state ();
13851 /* We don't go async if the user has explicitly prevented it with the
13852 "maint set target-async" command. */
13853 if (!target_async_permitted
)
13856 /* We're async whenever the serial device is. */
13857 return serial_can_async_p (rs
->remote_desc
);
13861 remote_is_async_p (struct target_ops
*ops
)
13863 struct remote_state
*rs
= get_remote_state ();
13865 if (!target_async_permitted
)
13866 /* We only enable async when the user specifically asks for it. */
13869 /* We're async whenever the serial device is. */
13870 return serial_is_async_p (rs
->remote_desc
);
13873 /* Pass the SERIAL event on and up to the client. One day this code
13874 will be able to delay notifying the client of an event until the
13875 point where an entire packet has been received. */
13877 static serial_event_ftype remote_async_serial_handler
;
13880 remote_async_serial_handler (struct serial
*scb
, void *context
)
13882 /* Don't propogate error information up to the client. Instead let
13883 the client find out about the error by querying the target. */
13884 inferior_event_handler (INF_REG_EVENT
, NULL
);
13888 remote_async_inferior_event_handler (gdb_client_data data
)
13890 inferior_event_handler (INF_REG_EVENT
, NULL
);
13894 remote_async (struct target_ops
*ops
, int enable
)
13896 struct remote_state
*rs
= get_remote_state ();
13900 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
13902 /* If there are pending events in the stop reply queue tell the
13903 event loop to process them. */
13904 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
13905 mark_async_event_handler (remote_async_inferior_event_token
);
13906 /* For simplicity, below we clear the pending events token
13907 without remembering whether it is marked, so here we always
13908 mark it. If there's actually no pending notification to
13909 process, this ends up being a no-op (other than a spurious
13910 event-loop wakeup). */
13911 if (target_is_non_stop_p ())
13912 mark_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13916 serial_async (rs
->remote_desc
, NULL
, NULL
);
13917 /* If the core is disabling async, it doesn't want to be
13918 disturbed with target events. Clear all async event sources
13920 clear_async_event_handler (remote_async_inferior_event_token
);
13921 if (target_is_non_stop_p ())
13922 clear_async_event_handler (rs
->notif_state
->get_pending_events_token
);
13926 /* Implementation of the to_thread_events method. */
13929 remote_thread_events (struct target_ops
*ops
, int enable
)
13931 struct remote_state
*rs
= get_remote_state ();
13932 size_t size
= get_remote_packet_size ();
13934 if (packet_support (PACKET_QThreadEvents
) == PACKET_DISABLE
)
13937 xsnprintf (rs
->buf
, size
, "QThreadEvents:%x", enable
? 1 : 0);
13939 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
13941 switch (packet_ok (rs
->buf
,
13942 &remote_protocol_packets
[PACKET_QThreadEvents
]))
13945 if (strcmp (rs
->buf
, "OK") != 0)
13946 error (_("Remote refused setting thread events: %s"), rs
->buf
);
13949 warning (_("Remote failure reply: %s"), rs
->buf
);
13951 case PACKET_UNKNOWN
:
13957 set_remote_cmd (const char *args
, int from_tty
)
13959 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
13963 show_remote_cmd (const char *args
, int from_tty
)
13965 /* We can't just use cmd_show_list here, because we want to skip
13966 the redundant "show remote Z-packet" and the legacy aliases. */
13967 struct cmd_list_element
*list
= remote_show_cmdlist
;
13968 struct ui_out
*uiout
= current_uiout
;
13970 ui_out_emit_tuple
tuple_emitter (uiout
, "showlist");
13971 for (; list
!= NULL
; list
= list
->next
)
13972 if (strcmp (list
->name
, "Z-packet") == 0)
13974 else if (list
->type
== not_set_cmd
)
13975 /* Alias commands are exactly like the original, except they
13976 don't have the normal type. */
13980 ui_out_emit_tuple
option_emitter (uiout
, "option");
13982 uiout
->field_string ("name", list
->name
);
13983 uiout
->text (": ");
13984 if (list
->type
== show_cmd
)
13985 do_show_command (NULL
, from_tty
, list
);
13987 cmd_func (list
, NULL
, from_tty
);
13992 /* Function to be called whenever a new objfile (shlib) is detected. */
13994 remote_new_objfile (struct objfile
*objfile
)
13996 struct remote_state
*rs
= get_remote_state ();
13998 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
13999 remote_check_symbols ();
14002 /* Pull all the tracepoints defined on the target and create local
14003 data structures representing them. We don't want to create real
14004 tracepoints yet, we don't want to mess up the user's existing
14008 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
14010 struct remote_state
*rs
= get_remote_state ();
14013 /* Ask for a first packet of tracepoint definition. */
14015 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
14017 while (*p
&& *p
!= 'l')
14019 parse_tracepoint_definition (p
, utpp
);
14020 /* Ask for another packet of tracepoint definition. */
14022 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
14029 remote_upload_trace_state_variables (struct target_ops
*self
,
14030 struct uploaded_tsv
**utsvp
)
14032 struct remote_state
*rs
= get_remote_state ();
14035 /* Ask for a first packet of variable definition. */
14037 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
14039 while (*p
&& *p
!= 'l')
14041 parse_tsv_definition (p
, utsvp
);
14042 /* Ask for another packet of variable definition. */
14044 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
14050 /* The "set/show range-stepping" show hook. */
14053 show_range_stepping (struct ui_file
*file
, int from_tty
,
14054 struct cmd_list_element
*c
,
14057 fprintf_filtered (file
,
14058 _("Debugger's willingness to use range stepping "
14059 "is %s.\n"), value
);
14062 /* The "set/show range-stepping" set hook. */
14065 set_range_stepping (char *ignore_args
, int from_tty
,
14066 struct cmd_list_element
*c
)
14068 struct remote_state
*rs
= get_remote_state ();
14070 /* Whene enabling, check whether range stepping is actually
14071 supported by the target, and warn if not. */
14072 if (use_range_stepping
)
14074 if (rs
->remote_desc
!= NULL
)
14076 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
14077 remote_vcont_probe (rs
);
14079 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
14080 && rs
->supports_vCont
.r
)
14084 warning (_("Range stepping is not supported by the current target"));
14089 _initialize_remote (void)
14091 struct cmd_list_element
*cmd
;
14092 const char *cmd_name
;
14094 /* architecture specific data */
14095 remote_gdbarch_data_handle
=
14096 gdbarch_data_register_post_init (init_remote_state
);
14097 remote_g_packet_data_handle
=
14098 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
14101 = register_program_space_data_with_cleanup (NULL
,
14102 remote_pspace_data_cleanup
);
14104 /* Initialize the per-target state. At the moment there is only one
14105 of these, not one per target. Only one target is active at a
14107 remote_state
= new_remote_state ();
14109 init_remote_ops ();
14110 add_target (&remote_ops
);
14112 init_extended_remote_ops ();
14113 add_target (&extended_remote_ops
);
14115 /* Hook into new objfile notification. */
14116 observer_attach_new_objfile (remote_new_objfile
);
14117 /* We're no longer interested in notification events of an inferior
14119 observer_attach_inferior_exit (discard_pending_stop_replies
);
14122 init_remote_threadtests ();
14125 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
14126 /* set/show remote ... */
14128 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
14129 Remote protocol specific variables\n\
14130 Configure various remote-protocol specific variables such as\n\
14131 the packets being used"),
14132 &remote_set_cmdlist
, "set remote ",
14133 0 /* allow-unknown */, &setlist
);
14134 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
14135 Remote protocol specific variables\n\
14136 Configure various remote-protocol specific variables such as\n\
14137 the packets being used"),
14138 &remote_show_cmdlist
, "show remote ",
14139 0 /* allow-unknown */, &showlist
);
14141 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
14142 Compare section data on target to the exec file.\n\
14143 Argument is a single section name (default: all loaded sections).\n\
14144 To compare only read-only loaded sections, specify the -r option."),
14147 add_cmd ("packet", class_maintenance
, packet_command
, _("\
14148 Send an arbitrary packet to a remote target.\n\
14149 maintenance packet TEXT\n\
14150 If GDB is talking to an inferior via the GDB serial protocol, then\n\
14151 this command sends the string TEXT to the inferior, and displays the\n\
14152 response packet. GDB supplies the initial `$' character, and the\n\
14153 terminating `#' character and checksum."),
14156 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
14157 Set whether to send break if interrupted."), _("\
14158 Show whether to send break if interrupted."), _("\
14159 If set, a break, instead of a cntrl-c, is sent to the remote target."),
14160 set_remotebreak
, show_remotebreak
,
14161 &setlist
, &showlist
);
14162 cmd_name
= "remotebreak";
14163 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
14164 deprecate_cmd (cmd
, "set remote interrupt-sequence");
14165 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
14166 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
14167 deprecate_cmd (cmd
, "show remote interrupt-sequence");
14169 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
14170 interrupt_sequence_modes
, &interrupt_sequence_mode
,
14172 Set interrupt sequence to remote target."), _("\
14173 Show interrupt sequence to remote target."), _("\
14174 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
14175 NULL
, show_interrupt_sequence
,
14176 &remote_set_cmdlist
,
14177 &remote_show_cmdlist
);
14179 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
14180 &interrupt_on_connect
, _("\
14181 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
14182 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
14183 If set, interrupt sequence is sent to remote target."),
14185 &remote_set_cmdlist
, &remote_show_cmdlist
);
14187 /* Install commands for configuring memory read/write packets. */
14189 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
14190 Set the maximum number of bytes per memory write packet (deprecated)."),
14192 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
14193 Show the maximum number of bytes per memory write packet (deprecated)."),
14195 add_cmd ("memory-write-packet-size", no_class
,
14196 set_memory_write_packet_size
, _("\
14197 Set the maximum number of bytes per memory-write packet.\n\
14198 Specify the number of bytes in a packet or 0 (zero) for the\n\
14199 default packet size. The actual limit is further reduced\n\
14200 dependent on the target. Specify ``fixed'' to disable the\n\
14201 further restriction and ``limit'' to enable that restriction."),
14202 &remote_set_cmdlist
);
14203 add_cmd ("memory-read-packet-size", no_class
,
14204 set_memory_read_packet_size
, _("\
14205 Set the maximum number of bytes per memory-read packet.\n\
14206 Specify the number of bytes in a packet or 0 (zero) for the\n\
14207 default packet size. The actual limit is further reduced\n\
14208 dependent on the target. Specify ``fixed'' to disable the\n\
14209 further restriction and ``limit'' to enable that restriction."),
14210 &remote_set_cmdlist
);
14211 add_cmd ("memory-write-packet-size", no_class
,
14212 show_memory_write_packet_size
,
14213 _("Show the maximum number of bytes per memory-write packet."),
14214 &remote_show_cmdlist
);
14215 add_cmd ("memory-read-packet-size", no_class
,
14216 show_memory_read_packet_size
,
14217 _("Show the maximum number of bytes per memory-read packet."),
14218 &remote_show_cmdlist
);
14220 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
14221 &remote_hw_watchpoint_limit
, _("\
14222 Set the maximum number of target hardware watchpoints."), _("\
14223 Show the maximum number of target hardware watchpoints."), _("\
14224 Specify a negative limit for unlimited."),
14225 NULL
, NULL
, /* FIXME: i18n: The maximum
14226 number of target hardware
14227 watchpoints is %s. */
14228 &remote_set_cmdlist
, &remote_show_cmdlist
);
14229 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
14230 &remote_hw_watchpoint_length_limit
, _("\
14231 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
14232 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
14233 Specify a negative limit for unlimited."),
14234 NULL
, NULL
, /* FIXME: i18n: The maximum
14235 length (in bytes) of a target
14236 hardware watchpoint is %s. */
14237 &remote_set_cmdlist
, &remote_show_cmdlist
);
14238 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
14239 &remote_hw_breakpoint_limit
, _("\
14240 Set the maximum number of target hardware breakpoints."), _("\
14241 Show the maximum number of target hardware breakpoints."), _("\
14242 Specify a negative limit for unlimited."),
14243 NULL
, NULL
, /* FIXME: i18n: The maximum
14244 number of target hardware
14245 breakpoints is %s. */
14246 &remote_set_cmdlist
, &remote_show_cmdlist
);
14248 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
14249 &remote_address_size
, _("\
14250 Set the maximum size of the address (in bits) in a memory packet."), _("\
14251 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
14253 NULL
, /* FIXME: i18n: */
14254 &setlist
, &showlist
);
14256 init_all_packet_configs ();
14258 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
14259 "X", "binary-download", 1);
14261 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
14262 "vCont", "verbose-resume", 0);
14264 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
14265 "QPassSignals", "pass-signals", 0);
14267 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QCatchSyscalls
],
14268 "QCatchSyscalls", "catch-syscalls", 0);
14270 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
14271 "QProgramSignals", "program-signals", 0);
14273 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QSetWorkingDir
],
14274 "QSetWorkingDir", "set-working-dir", 0);
14276 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartupWithShell
],
14277 "QStartupWithShell", "startup-with-shell", 0);
14279 add_packet_config_cmd (&remote_protocol_packets
14280 [PACKET_QEnvironmentHexEncoded
],
14281 "QEnvironmentHexEncoded", "environment-hex-encoded",
14284 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QEnvironmentReset
],
14285 "QEnvironmentReset", "environment-reset",
14288 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QEnvironmentUnset
],
14289 "QEnvironmentUnset", "environment-unset",
14292 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
14293 "qSymbol", "symbol-lookup", 0);
14295 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
14296 "P", "set-register", 1);
14298 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
14299 "p", "fetch-register", 1);
14301 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
14302 "Z0", "software-breakpoint", 0);
14304 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
14305 "Z1", "hardware-breakpoint", 0);
14307 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
14308 "Z2", "write-watchpoint", 0);
14310 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
14311 "Z3", "read-watchpoint", 0);
14313 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
14314 "Z4", "access-watchpoint", 0);
14316 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
14317 "qXfer:auxv:read", "read-aux-vector", 0);
14319 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
14320 "qXfer:exec-file:read", "pid-to-exec-file", 0);
14322 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
14323 "qXfer:features:read", "target-features", 0);
14325 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
14326 "qXfer:libraries:read", "library-info", 0);
14328 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
14329 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
14331 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
14332 "qXfer:memory-map:read", "memory-map", 0);
14334 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
14335 "qXfer:spu:read", "read-spu-object", 0);
14337 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
14338 "qXfer:spu:write", "write-spu-object", 0);
14340 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
14341 "qXfer:osdata:read", "osdata", 0);
14343 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
14344 "qXfer:threads:read", "threads", 0);
14346 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
14347 "qXfer:siginfo:read", "read-siginfo-object", 0);
14349 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
14350 "qXfer:siginfo:write", "write-siginfo-object", 0);
14352 add_packet_config_cmd
14353 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
14354 "qXfer:traceframe-info:read", "traceframe-info", 0);
14356 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
14357 "qXfer:uib:read", "unwind-info-block", 0);
14359 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
14360 "qGetTLSAddr", "get-thread-local-storage-address",
14363 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
14364 "qGetTIBAddr", "get-thread-information-block-address",
14367 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
14368 "bc", "reverse-continue", 0);
14370 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
14371 "bs", "reverse-step", 0);
14373 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
14374 "qSupported", "supported-packets", 0);
14376 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
14377 "qSearch:memory", "search-memory", 0);
14379 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
14380 "qTStatus", "trace-status", 0);
14382 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_setfs
],
14383 "vFile:setfs", "hostio-setfs", 0);
14385 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
14386 "vFile:open", "hostio-open", 0);
14388 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
14389 "vFile:pread", "hostio-pread", 0);
14391 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
14392 "vFile:pwrite", "hostio-pwrite", 0);
14394 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
14395 "vFile:close", "hostio-close", 0);
14397 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
14398 "vFile:unlink", "hostio-unlink", 0);
14400 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
14401 "vFile:readlink", "hostio-readlink", 0);
14403 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
14404 "vFile:fstat", "hostio-fstat", 0);
14406 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
14407 "vAttach", "attach", 0);
14409 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
14412 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
14413 "QStartNoAckMode", "noack", 0);
14415 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
14416 "vKill", "kill", 0);
14418 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
14419 "qAttached", "query-attached", 0);
14421 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
14422 "ConditionalTracepoints",
14423 "conditional-tracepoints", 0);
14425 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
14426 "ConditionalBreakpoints",
14427 "conditional-breakpoints", 0);
14429 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
14430 "BreakpointCommands",
14431 "breakpoint-commands", 0);
14433 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
14434 "FastTracepoints", "fast-tracepoints", 0);
14436 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
14437 "TracepointSource", "TracepointSource", 0);
14439 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
14440 "QAllow", "allow", 0);
14442 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
14443 "StaticTracepoints", "static-tracepoints", 0);
14445 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
14446 "InstallInTrace", "install-in-trace", 0);
14448 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
14449 "qXfer:statictrace:read", "read-sdata-object", 0);
14451 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
14452 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
14454 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
14455 "QDisableRandomization", "disable-randomization", 0);
14457 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
14458 "QAgent", "agent", 0);
14460 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
14461 "QTBuffer:size", "trace-buffer-size", 0);
14463 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
14464 "Qbtrace:off", "disable-btrace", 0);
14466 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
14467 "Qbtrace:bts", "enable-btrace-bts", 0);
14469 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_pt
],
14470 "Qbtrace:pt", "enable-btrace-pt", 0);
14472 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
14473 "qXfer:btrace", "read-btrace", 0);
14475 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
14476 "qXfer:btrace-conf", "read-btrace-conf", 0);
14478 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
14479 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
14481 add_packet_config_cmd (&remote_protocol_packets
[PACKET_multiprocess_feature
],
14482 "multiprocess-feature", "multiprocess-feature", 0);
14484 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
14485 "swbreak-feature", "swbreak-feature", 0);
14487 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
14488 "hwbreak-feature", "hwbreak-feature", 0);
14490 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
14491 "fork-event-feature", "fork-event-feature", 0);
14493 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
14494 "vfork-event-feature", "vfork-event-feature", 0);
14496 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
],
14497 "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
14499 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vContSupported
],
14500 "vContSupported", "verbose-resume-supported", 0);
14502 add_packet_config_cmd (&remote_protocol_packets
[PACKET_exec_event_feature
],
14503 "exec-event-feature", "exec-event-feature", 0);
14505 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCtrlC
],
14506 "vCtrlC", "ctrl-c", 0);
14508 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QThreadEvents
],
14509 "QThreadEvents", "thread-events", 0);
14511 add_packet_config_cmd (&remote_protocol_packets
[PACKET_no_resumed
],
14512 "N stop reply", "no-resumed-stop-reply", 0);
14514 /* Assert that we've registered "set remote foo-packet" commands
14515 for all packet configs. */
14519 for (i
= 0; i
< PACKET_MAX
; i
++)
14521 /* Ideally all configs would have a command associated. Some
14522 still don't though. */
14527 case PACKET_QNonStop
:
14528 case PACKET_EnableDisableTracepoints_feature
:
14529 case PACKET_tracenz_feature
:
14530 case PACKET_DisconnectedTracing_feature
:
14531 case PACKET_augmented_libraries_svr4_read_feature
:
14533 /* Additions to this list need to be well justified:
14534 pre-existing packets are OK; new packets are not. */
14542 /* This catches both forgetting to add a config command, and
14543 forgetting to remove a packet from the exception list. */
14544 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
14548 /* Keep the old ``set remote Z-packet ...'' working. Each individual
14549 Z sub-packet has its own set and show commands, but users may
14550 have sets to this variable in their .gdbinit files (or in their
14552 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
14553 &remote_Z_packet_detect
, _("\
14554 Set use of remote protocol `Z' packets"), _("\
14555 Show use of remote protocol `Z' packets "), _("\
14556 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
14558 set_remote_protocol_Z_packet_cmd
,
14559 show_remote_protocol_Z_packet_cmd
,
14560 /* FIXME: i18n: Use of remote protocol
14561 `Z' packets is %s. */
14562 &remote_set_cmdlist
, &remote_show_cmdlist
);
14564 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
14565 Manipulate files on the remote system\n\
14566 Transfer files to and from the remote target system."),
14567 &remote_cmdlist
, "remote ",
14568 0 /* allow-unknown */, &cmdlist
);
14570 add_cmd ("put", class_files
, remote_put_command
,
14571 _("Copy a local file to the remote system."),
14574 add_cmd ("get", class_files
, remote_get_command
,
14575 _("Copy a remote file to the local system."),
14578 add_cmd ("delete", class_files
, remote_delete_command
,
14579 _("Delete a remote file."),
14582 add_setshow_string_noescape_cmd ("exec-file", class_files
,
14583 &remote_exec_file_var
, _("\
14584 Set the remote pathname for \"run\""), _("\
14585 Show the remote pathname for \"run\""), NULL
,
14586 set_remote_exec_file
,
14587 show_remote_exec_file
,
14588 &remote_set_cmdlist
,
14589 &remote_show_cmdlist
);
14591 add_setshow_boolean_cmd ("range-stepping", class_run
,
14592 &use_range_stepping
, _("\
14593 Enable or disable range stepping."), _("\
14594 Show whether target-assisted range stepping is enabled."), _("\
14595 If on, and the target supports it, when stepping a source line, GDB\n\
14596 tells the target to step the corresponding range of addresses itself instead\n\
14597 of issuing multiple single-steps. This speeds up source level\n\
14598 stepping. If off, GDB always issues single-steps, even if range\n\
14599 stepping is supported by the target. The default is on."),
14600 set_range_stepping
,
14601 show_range_stepping
,
14605 /* Eventually initialize fileio. See fileio.c */
14606 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
14608 /* Take advantage of the fact that the TID field is not used, to tag
14609 special ptids with it set to != 0. */
14610 magic_null_ptid
= ptid_build (42000, -1, 1);
14611 not_sent_ptid
= ptid_build (42000, -2, 1);
14612 any_thread_ptid
= ptid_build (42000, 0, 1);