1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2015 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 "event-loop.h"
51 #include "event-top.h"
57 #include "gdbcore.h" /* for exec_bfd */
59 #include "remote-fileio.h"
60 #include "gdb/fileio.h"
62 #include "xml-support.h"
64 #include "memory-map.h"
66 #include "tracepoint.h"
72 /* Temp hacks for tracepoint encoding migration. */
73 static char *target_buf
;
74 static long target_buf_size
;
76 /* The size to align memory write packets, when practical. The protocol
77 does not guarantee any alignment, and gdb will generate short
78 writes and unaligned writes, but even as a best-effort attempt this
79 can improve bulk transfers. For instance, if a write is misaligned
80 relative to the target's data bus, the stub may need to make an extra
81 round trip fetching data from the target. This doesn't make a
82 huge difference, but it's easy to do, so we try to be helpful.
84 The alignment chosen is arbitrary; usually data bus width is
85 important here, not the possibly larger cache line size. */
86 enum { REMOTE_ALIGN_WRITES
= 16 };
88 /* Prototypes for local functions. */
89 static void async_cleanup_sigint_signal_handler (void *dummy
);
90 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
91 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
92 int forever
, int *is_notif
);
94 static void async_handle_remote_sigint (int);
95 static void async_handle_remote_sigint_twice (int);
97 static void remote_files_info (struct target_ops
*ignore
);
99 static void remote_prepare_to_store (struct target_ops
*self
,
100 struct regcache
*regcache
);
102 static void remote_open_1 (const char *, int, struct target_ops
*,
105 static void remote_close (struct target_ops
*self
);
107 static void remote_mourn (struct target_ops
*ops
);
109 static void extended_remote_restart (void);
111 static void extended_remote_mourn (struct target_ops
*);
113 static void remote_send (char **buf
, long *sizeof_buf_p
);
115 static int readchar (int timeout
);
117 static void remote_serial_write (const char *str
, int len
);
119 static void remote_kill (struct target_ops
*ops
);
121 static int remote_can_async_p (struct target_ops
*);
123 static int remote_is_async_p (struct target_ops
*);
125 static void remote_async (struct target_ops
*ops
, int enable
);
127 static void sync_remote_interrupt_twice (int signo
);
129 static void interrupt_query (void);
131 static void set_general_thread (struct ptid ptid
);
132 static void set_continue_thread (struct ptid ptid
);
134 static void get_offsets (void);
136 static void skip_frame (void);
138 static long read_frame (char **buf_p
, long *sizeof_buf
);
140 static int hexnumlen (ULONGEST num
);
142 static void init_remote_ops (void);
144 static void init_extended_remote_ops (void);
146 static void remote_stop (struct target_ops
*self
, ptid_t
);
148 static int stubhex (int ch
);
150 static int hexnumstr (char *, ULONGEST
);
152 static int hexnumnstr (char *, ULONGEST
, int);
154 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
156 static void print_packet (const char *);
158 static void compare_sections_command (char *, int);
160 static void packet_command (char *, int);
162 static int stub_unpack_int (char *buff
, int fieldlength
);
164 static ptid_t
remote_current_thread (ptid_t oldptid
);
166 static int putpkt_binary (const char *buf
, int cnt
);
168 static void check_binary_download (CORE_ADDR addr
);
170 struct packet_config
;
172 static void show_packet_config_cmd (struct packet_config
*config
);
174 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
176 struct cmd_list_element
*c
,
179 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
180 static ptid_t
read_ptid (char *buf
, char **obuf
);
182 static void remote_set_permissions (struct target_ops
*self
);
185 static int remote_get_trace_status (struct target_ops
*self
,
186 struct trace_status
*ts
);
188 static int remote_upload_tracepoints (struct target_ops
*self
,
189 struct uploaded_tp
**utpp
);
191 static int remote_upload_trace_state_variables (struct target_ops
*self
,
192 struct uploaded_tsv
**utsvp
);
194 static void remote_query_supported (void);
196 static void remote_check_symbols (void);
198 void _initialize_remote (void);
201 static void stop_reply_xfree (struct stop_reply
*);
202 static void remote_parse_stop_reply (char *, struct stop_reply
*);
203 static void push_stop_reply (struct stop_reply
*);
204 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
205 static int peek_stop_reply (ptid_t ptid
);
207 static void remote_async_inferior_event_handler (gdb_client_data
);
209 static void remote_terminal_ours (struct target_ops
*self
);
211 static int remote_read_description_p (struct target_ops
*target
);
213 static void remote_console_output (char *msg
);
215 static int remote_supports_cond_breakpoints (struct target_ops
*self
);
217 static int remote_can_run_breakpoint_commands (struct target_ops
*self
);
219 static void remote_btrace_reset (void);
223 static struct cmd_list_element
*remote_cmdlist
;
225 /* For "set remote" and "show remote". */
227 static struct cmd_list_element
*remote_set_cmdlist
;
228 static struct cmd_list_element
*remote_show_cmdlist
;
230 /* Stub vCont actions support.
232 Each field is a boolean flag indicating whether the stub reports
233 support for the corresponding action. */
235 struct vCont_action_support
244 /* Controls whether GDB is willing to use range stepping. */
246 static int use_range_stepping
= 1;
248 #define OPAQUETHREADBYTES 8
250 /* a 64 bit opaque identifier */
251 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
253 /* About this many threadisds fit in a packet. */
255 #define MAXTHREADLISTRESULTS 32
257 /* Description of the remote protocol state for the currently
258 connected target. This is per-target state, and independent of the
259 selected architecture. */
263 /* A buffer to use for incoming packets, and its current size. The
264 buffer is grown dynamically for larger incoming packets.
265 Outgoing packets may also be constructed in this buffer.
266 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
267 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
272 /* True if we're going through initial connection setup (finding out
273 about the remote side's threads, relocating symbols, etc.). */
276 /* If we negotiated packet size explicitly (and thus can bypass
277 heuristics for the largest packet size that will not overflow
278 a buffer in the stub), this will be set to that packet size.
279 Otherwise zero, meaning to use the guessed size. */
280 long explicit_packet_size
;
282 /* remote_wait is normally called when the target is running and
283 waits for a stop reply packet. But sometimes we need to call it
284 when the target is already stopped. We can send a "?" packet
285 and have remote_wait read the response. Or, if we already have
286 the response, we can stash it in BUF and tell remote_wait to
287 skip calling getpkt. This flag is set when BUF contains a
288 stop reply packet and the target is not waiting. */
289 int cached_wait_status
;
291 /* True, if in no ack mode. That is, neither GDB nor the stub will
292 expect acks from each other. The connection is assumed to be
296 /* True if we're connected in extended remote mode. */
299 /* True if we resumed the target and we're waiting for the target to
300 stop. In the mean time, we can't start another command/query.
301 The remote server wouldn't be ready to process it, so we'd
302 timeout waiting for a reply that would never come and eventually
303 we'd close the connection. This can happen in asynchronous mode
304 because we allow GDB commands while the target is running. */
305 int waiting_for_stop_reply
;
307 /* The status of the stub support for the various vCont actions. */
308 struct vCont_action_support supports_vCont
;
310 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
311 responded to that. */
314 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
315 remote_open knows that we don't have a file open when the program
317 struct serial
*remote_desc
;
319 /* These are the threads which we last sent to the remote system. The
320 TID member will be -1 for all or -2 for not sent yet. */
321 ptid_t general_thread
;
322 ptid_t continue_thread
;
324 /* This is the traceframe which we last selected on the remote system.
325 It will be -1 if no traceframe is selected. */
326 int remote_traceframe_number
;
328 char *last_pass_packet
;
330 /* The last QProgramSignals packet sent to the target. We bypass
331 sending a new program signals list down to the target if the new
332 packet is exactly the same as the last we sent. IOW, we only let
333 the target know about program signals list changes. */
334 char *last_program_signals_packet
;
336 enum gdb_signal last_sent_signal
;
340 char *finished_object
;
341 char *finished_annex
;
342 ULONGEST finished_offset
;
344 /* Should we try the 'ThreadInfo' query packet?
346 This variable (NOT available to the user: auto-detect only!)
347 determines whether GDB will use the new, simpler "ThreadInfo"
348 query or the older, more complex syntax for thread queries.
349 This is an auto-detect variable (set to true at each connect,
350 and set to false when the target fails to recognize it). */
351 int use_threadinfo_query
;
352 int use_threadextra_query
;
354 /* This is set to the data address of the access causing the target
355 to stop for a watchpoint. */
356 CORE_ADDR remote_watch_data_address
;
358 /* Whether the target stopped for a breakpoint/watchpoint. */
359 enum target_stop_reason stop_reason
;
361 threadref echo_nextthread
;
362 threadref nextthread
;
363 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
365 /* The state of remote notification. */
366 struct remote_notif_state
*notif_state
;
368 /* The branch trace configuration. */
369 struct btrace_config btrace_config
;
372 /* Private data that we'll store in (struct thread_info)->private. */
373 struct private_thread_info
380 free_private_thread_info (struct private_thread_info
*info
)
386 /* This data could be associated with a target, but we do not always
387 have access to the current target when we need it, so for now it is
388 static. This will be fine for as long as only one target is in use
390 static struct remote_state
*remote_state
;
392 static struct remote_state
*
393 get_remote_state_raw (void)
398 /* Allocate a new struct remote_state with xmalloc, initialize it, and
401 static struct remote_state
*
402 new_remote_state (void)
404 struct remote_state
*result
= XCNEW (struct remote_state
);
406 /* The default buffer size is unimportant; it will be expanded
407 whenever a larger buffer is needed. */
408 result
->buf_size
= 400;
409 result
->buf
= xmalloc (result
->buf_size
);
410 result
->remote_traceframe_number
= -1;
411 result
->last_sent_signal
= GDB_SIGNAL_0
;
416 /* Description of the remote protocol for a given architecture. */
420 long offset
; /* Offset into G packet. */
421 long regnum
; /* GDB's internal register number. */
422 LONGEST pnum
; /* Remote protocol register number. */
423 int in_g_packet
; /* Always part of G packet. */
424 /* long size in bytes; == register_size (target_gdbarch (), regnum);
426 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
430 struct remote_arch_state
432 /* Description of the remote protocol registers. */
433 long sizeof_g_packet
;
435 /* Description of the remote protocol registers indexed by REGNUM
436 (making an array gdbarch_num_regs in size). */
437 struct packet_reg
*regs
;
439 /* This is the size (in chars) of the first response to the ``g''
440 packet. It is used as a heuristic when determining the maximum
441 size of memory-read and memory-write packets. A target will
442 typically only reserve a buffer large enough to hold the ``g''
443 packet. The size does not include packet overhead (headers and
445 long actual_register_packet_size
;
447 /* This is the maximum size (in chars) of a non read/write packet.
448 It is also used as a cap on the size of read/write packets. */
449 long remote_packet_size
;
452 /* Utility: generate error from an incoming stub packet. */
454 trace_error (char *buf
)
457 return; /* not an error msg */
460 case '1': /* malformed packet error */
461 if (*++buf
== '0') /* general case: */
462 error (_("remote.c: error in outgoing packet."));
464 error (_("remote.c: error in outgoing packet at field #%ld."),
465 strtol (buf
, NULL
, 16));
467 error (_("Target returns error code '%s'."), buf
);
471 /* Utility: wait for reply from stub, while accepting "O" packets. */
473 remote_get_noisy_reply (char **buf_p
,
476 do /* Loop on reply from remote stub. */
480 QUIT
; /* Allow user to bail out with ^C. */
481 getpkt (buf_p
, sizeof_buf
, 0);
485 else if (startswith (buf
, "qRelocInsn:"))
488 CORE_ADDR from
, to
, org_to
;
490 int adjusted_size
= 0;
493 p
= buf
+ strlen ("qRelocInsn:");
494 pp
= unpack_varlen_hex (p
, &ul
);
496 error (_("invalid qRelocInsn packet: %s"), buf
);
500 unpack_varlen_hex (p
, &ul
);
507 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
510 CATCH (ex
, RETURN_MASK_ALL
)
512 if (ex
.error
== MEMORY_ERROR
)
514 /* Propagate memory errors silently back to the
515 target. The stub may have limited the range of
516 addresses we can write to, for example. */
520 /* Something unexpectedly bad happened. Be verbose
521 so we can tell what, and propagate the error back
522 to the stub, so it doesn't get stuck waiting for
524 exception_fprintf (gdb_stderr
, ex
,
525 _("warning: relocating instruction: "));
533 adjusted_size
= to
- org_to
;
535 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
539 else if (buf
[0] == 'O' && buf
[1] != 'K')
540 remote_console_output (buf
+ 1); /* 'O' message from stub */
542 return buf
; /* Here's the actual reply. */
547 /* Handle for retreving the remote protocol data from gdbarch. */
548 static struct gdbarch_data
*remote_gdbarch_data_handle
;
550 static struct remote_arch_state
*
551 get_remote_arch_state (void)
553 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
);
556 /* Fetch the global remote target state. */
558 static struct remote_state
*
559 get_remote_state (void)
561 /* Make sure that the remote architecture state has been
562 initialized, because doing so might reallocate rs->buf. Any
563 function which calls getpkt also needs to be mindful of changes
564 to rs->buf, but this call limits the number of places which run
566 get_remote_arch_state ();
568 return get_remote_state_raw ();
572 compare_pnums (const void *lhs_
, const void *rhs_
)
574 const struct packet_reg
* const *lhs
= lhs_
;
575 const struct packet_reg
* const *rhs
= rhs_
;
577 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
579 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
586 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
588 int regnum
, num_remote_regs
, offset
;
589 struct packet_reg
**remote_regs
;
591 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
593 struct packet_reg
*r
= ®s
[regnum
];
595 if (register_size (gdbarch
, regnum
) == 0)
596 /* Do not try to fetch zero-sized (placeholder) registers. */
599 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
604 /* Define the g/G packet format as the contents of each register
605 with a remote protocol number, in order of ascending protocol
608 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
609 * sizeof (struct packet_reg
*));
610 for (num_remote_regs
= 0, regnum
= 0;
611 regnum
< gdbarch_num_regs (gdbarch
);
613 if (regs
[regnum
].pnum
!= -1)
614 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
616 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
619 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
621 remote_regs
[regnum
]->in_g_packet
= 1;
622 remote_regs
[regnum
]->offset
= offset
;
623 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
629 /* Given the architecture described by GDBARCH, return the remote
630 protocol register's number and the register's offset in the g/G
631 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
632 If the target does not have a mapping for REGNUM, return false,
633 otherwise, return true. */
636 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
637 int *pnum
, int *poffset
)
640 struct packet_reg
*regs
;
641 struct cleanup
*old_chain
;
643 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
645 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
646 old_chain
= make_cleanup (xfree
, regs
);
648 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
650 *pnum
= regs
[regnum
].pnum
;
651 *poffset
= regs
[regnum
].offset
;
653 do_cleanups (old_chain
);
659 init_remote_state (struct gdbarch
*gdbarch
)
661 struct remote_state
*rs
= get_remote_state_raw ();
662 struct remote_arch_state
*rsa
;
664 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
666 /* Use the architecture to build a regnum<->pnum table, which will be
667 1:1 unless a feature set specifies otherwise. */
668 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
669 gdbarch_num_regs (gdbarch
),
672 /* Record the maximum possible size of the g packet - it may turn out
674 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
676 /* Default maximum number of characters in a packet body. Many
677 remote stubs have a hardwired buffer size of 400 bytes
678 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
679 as the maximum packet-size to ensure that the packet and an extra
680 NUL character can always fit in the buffer. This stops GDB
681 trashing stubs that try to squeeze an extra NUL into what is
682 already a full buffer (As of 1999-12-04 that was most stubs). */
683 rsa
->remote_packet_size
= 400 - 1;
685 /* This one is filled in when a ``g'' packet is received. */
686 rsa
->actual_register_packet_size
= 0;
688 /* Should rsa->sizeof_g_packet needs more space than the
689 default, adjust the size accordingly. Remember that each byte is
690 encoded as two characters. 32 is the overhead for the packet
691 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
692 (``$NN:G...#NN'') is a better guess, the below has been padded a
694 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
695 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
697 /* Make sure that the packet buffer is plenty big enough for
698 this architecture. */
699 if (rs
->buf_size
< rsa
->remote_packet_size
)
701 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
702 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
708 /* Return the current allowed size of a remote packet. This is
709 inferred from the current architecture, and should be used to
710 limit the length of outgoing packets. */
712 get_remote_packet_size (void)
714 struct remote_state
*rs
= get_remote_state ();
715 struct remote_arch_state
*rsa
= get_remote_arch_state ();
717 if (rs
->explicit_packet_size
)
718 return rs
->explicit_packet_size
;
720 return rsa
->remote_packet_size
;
723 static struct packet_reg
*
724 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
726 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
730 struct packet_reg
*r
= &rsa
->regs
[regnum
];
732 gdb_assert (r
->regnum
== regnum
);
737 static struct packet_reg
*
738 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
742 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
744 struct packet_reg
*r
= &rsa
->regs
[i
];
752 static struct target_ops remote_ops
;
754 static struct target_ops extended_remote_ops
;
756 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
757 ``forever'' still use the normal timeout mechanism. This is
758 currently used by the ASYNC code to guarentee that target reads
759 during the initial connect always time-out. Once getpkt has been
760 modified to return a timeout indication and, in turn
761 remote_wait()/wait_for_inferior() have gained a timeout parameter
763 static int wait_forever_enabled_p
= 1;
765 /* Allow the user to specify what sequence to send to the remote
766 when he requests a program interruption: Although ^C is usually
767 what remote systems expect (this is the default, here), it is
768 sometimes preferable to send a break. On other systems such
769 as the Linux kernel, a break followed by g, which is Magic SysRq g
770 is required in order to interrupt the execution. */
771 const char interrupt_sequence_control_c
[] = "Ctrl-C";
772 const char interrupt_sequence_break
[] = "BREAK";
773 const char interrupt_sequence_break_g
[] = "BREAK-g";
774 static const char *const interrupt_sequence_modes
[] =
776 interrupt_sequence_control_c
,
777 interrupt_sequence_break
,
778 interrupt_sequence_break_g
,
781 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
784 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
785 struct cmd_list_element
*c
,
788 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
789 fprintf_filtered (file
,
790 _("Send the ASCII ETX character (Ctrl-c) "
791 "to the remote target to interrupt the "
792 "execution of the program.\n"));
793 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
794 fprintf_filtered (file
,
795 _("send a break signal to the remote target "
796 "to interrupt the execution of the program.\n"));
797 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
798 fprintf_filtered (file
,
799 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
800 "the remote target to interrupt the execution "
801 "of Linux kernel.\n"));
803 internal_error (__FILE__
, __LINE__
,
804 _("Invalid value for interrupt_sequence_mode: %s."),
805 interrupt_sequence_mode
);
808 /* This boolean variable specifies whether interrupt_sequence is sent
809 to the remote target when gdb connects to it.
810 This is mostly needed when you debug the Linux kernel: The Linux kernel
811 expects BREAK g which is Magic SysRq g for connecting gdb. */
812 static int interrupt_on_connect
= 0;
814 /* This variable is used to implement the "set/show remotebreak" commands.
815 Since these commands are now deprecated in favor of "set/show remote
816 interrupt-sequence", it no longer has any effect on the code. */
817 static int remote_break
;
820 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
823 interrupt_sequence_mode
= interrupt_sequence_break
;
825 interrupt_sequence_mode
= interrupt_sequence_control_c
;
829 show_remotebreak (struct ui_file
*file
, int from_tty
,
830 struct cmd_list_element
*c
,
835 /* This variable sets the number of bits in an address that are to be
836 sent in a memory ("M" or "m") packet. Normally, after stripping
837 leading zeros, the entire address would be sent. This variable
838 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
839 initial implementation of remote.c restricted the address sent in
840 memory packets to ``host::sizeof long'' bytes - (typically 32
841 bits). Consequently, for 64 bit targets, the upper 32 bits of an
842 address was never sent. Since fixing this bug may cause a break in
843 some remote targets this variable is principly provided to
844 facilitate backward compatibility. */
846 static unsigned int remote_address_size
;
848 /* Temporary to track who currently owns the terminal. See
849 remote_terminal_* for more details. */
851 static int remote_async_terminal_ours_p
;
853 /* The executable file to use for "run" on the remote side. */
855 static char *remote_exec_file
= "";
858 /* User configurable variables for the number of characters in a
859 memory read/write packet. MIN (rsa->remote_packet_size,
860 rsa->sizeof_g_packet) is the default. Some targets need smaller
861 values (fifo overruns, et.al.) and some users need larger values
862 (speed up transfers). The variables ``preferred_*'' (the user
863 request), ``current_*'' (what was actually set) and ``forced_*''
864 (Positive - a soft limit, negative - a hard limit). */
866 struct memory_packet_config
873 /* Compute the current size of a read/write packet. Since this makes
874 use of ``actual_register_packet_size'' the computation is dynamic. */
877 get_memory_packet_size (struct memory_packet_config
*config
)
879 struct remote_state
*rs
= get_remote_state ();
880 struct remote_arch_state
*rsa
= get_remote_arch_state ();
882 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
883 law?) that some hosts don't cope very well with large alloca()
884 calls. Eventually the alloca() code will be replaced by calls to
885 xmalloc() and make_cleanups() allowing this restriction to either
886 be lifted or removed. */
887 #ifndef MAX_REMOTE_PACKET_SIZE
888 #define MAX_REMOTE_PACKET_SIZE 16384
890 /* NOTE: 20 ensures we can write at least one byte. */
891 #ifndef MIN_REMOTE_PACKET_SIZE
892 #define MIN_REMOTE_PACKET_SIZE 20
897 if (config
->size
<= 0)
898 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
900 what_they_get
= config
->size
;
904 what_they_get
= get_remote_packet_size ();
905 /* Limit the packet to the size specified by the user. */
907 && what_they_get
> config
->size
)
908 what_they_get
= config
->size
;
910 /* Limit it to the size of the targets ``g'' response unless we have
911 permission from the stub to use a larger packet size. */
912 if (rs
->explicit_packet_size
== 0
913 && rsa
->actual_register_packet_size
> 0
914 && what_they_get
> rsa
->actual_register_packet_size
)
915 what_they_get
= rsa
->actual_register_packet_size
;
917 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
918 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
919 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
920 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
922 /* Make sure there is room in the global buffer for this packet
923 (including its trailing NUL byte). */
924 if (rs
->buf_size
< what_they_get
+ 1)
926 rs
->buf_size
= 2 * what_they_get
;
927 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
930 return what_they_get
;
933 /* Update the size of a read/write packet. If they user wants
934 something really big then do a sanity check. */
937 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
939 int fixed_p
= config
->fixed_p
;
940 long size
= config
->size
;
943 error (_("Argument required (integer, `fixed' or `limited')."));
944 else if (strcmp (args
, "hard") == 0
945 || strcmp (args
, "fixed") == 0)
947 else if (strcmp (args
, "soft") == 0
948 || strcmp (args
, "limit") == 0)
954 size
= strtoul (args
, &end
, 0);
956 error (_("Invalid %s (bad syntax)."), config
->name
);
958 /* Instead of explicitly capping the size of a packet to
959 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
960 instead allowed to set the size to something arbitrarily
962 if (size
> MAX_REMOTE_PACKET_SIZE
)
963 error (_("Invalid %s (too large)."), config
->name
);
967 if (fixed_p
&& !config
->fixed_p
)
969 if (! query (_("The target may not be able to correctly handle a %s\n"
970 "of %ld bytes. Change the packet size? "),
972 error (_("Packet size not changed."));
974 /* Update the config. */
975 config
->fixed_p
= fixed_p
;
980 show_memory_packet_size (struct memory_packet_config
*config
)
982 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
984 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
985 get_memory_packet_size (config
));
987 printf_filtered (_("Packets are limited to %ld bytes.\n"),
988 get_memory_packet_size (config
));
991 static struct memory_packet_config memory_write_packet_config
=
993 "memory-write-packet-size",
997 set_memory_write_packet_size (char *args
, int from_tty
)
999 set_memory_packet_size (args
, &memory_write_packet_config
);
1003 show_memory_write_packet_size (char *args
, int from_tty
)
1005 show_memory_packet_size (&memory_write_packet_config
);
1009 get_memory_write_packet_size (void)
1011 return get_memory_packet_size (&memory_write_packet_config
);
1014 static struct memory_packet_config memory_read_packet_config
=
1016 "memory-read-packet-size",
1020 set_memory_read_packet_size (char *args
, int from_tty
)
1022 set_memory_packet_size (args
, &memory_read_packet_config
);
1026 show_memory_read_packet_size (char *args
, int from_tty
)
1028 show_memory_packet_size (&memory_read_packet_config
);
1032 get_memory_read_packet_size (void)
1034 long size
= get_memory_packet_size (&memory_read_packet_config
);
1036 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1037 extra buffer size argument before the memory read size can be
1038 increased beyond this. */
1039 if (size
> get_remote_packet_size ())
1040 size
= get_remote_packet_size ();
1045 /* Generic configuration support for packets the stub optionally
1046 supports. Allows the user to specify the use of the packet as well
1047 as allowing GDB to auto-detect support in the remote stub. */
1051 PACKET_SUPPORT_UNKNOWN
= 0,
1056 struct packet_config
1061 /* If auto, GDB auto-detects support for this packet or feature,
1062 either through qSupported, or by trying the packet and looking
1063 at the response. If true, GDB assumes the target supports this
1064 packet. If false, the packet is disabled. Configs that don't
1065 have an associated command always have this set to auto. */
1066 enum auto_boolean detect
;
1068 /* Does the target support this packet? */
1069 enum packet_support support
;
1072 /* Analyze a packet's return value and update the packet config
1082 static enum packet_support
packet_config_support (struct packet_config
*config
);
1083 static enum packet_support
packet_support (int packet
);
1086 show_packet_config_cmd (struct packet_config
*config
)
1088 char *support
= "internal-error";
1090 switch (packet_config_support (config
))
1093 support
= "enabled";
1095 case PACKET_DISABLE
:
1096 support
= "disabled";
1098 case PACKET_SUPPORT_UNKNOWN
:
1099 support
= "unknown";
1102 switch (config
->detect
)
1104 case AUTO_BOOLEAN_AUTO
:
1105 printf_filtered (_("Support for the `%s' packet "
1106 "is auto-detected, currently %s.\n"),
1107 config
->name
, support
);
1109 case AUTO_BOOLEAN_TRUE
:
1110 case AUTO_BOOLEAN_FALSE
:
1111 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1112 config
->name
, support
);
1118 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1119 const char *title
, int legacy
)
1125 config
->name
= name
;
1126 config
->title
= title
;
1127 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1129 show_doc
= xstrprintf ("Show current use of remote "
1130 "protocol `%s' (%s) packet",
1132 /* set/show TITLE-packet {auto,on,off} */
1133 cmd_name
= xstrprintf ("%s-packet", title
);
1134 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1135 &config
->detect
, set_doc
,
1136 show_doc
, NULL
, /* help_doc */
1138 show_remote_protocol_packet_cmd
,
1139 &remote_set_cmdlist
, &remote_show_cmdlist
);
1140 /* The command code copies the documentation strings. */
1143 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1148 legacy_name
= xstrprintf ("%s-packet", name
);
1149 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1150 &remote_set_cmdlist
);
1151 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1152 &remote_show_cmdlist
);
1156 static enum packet_result
1157 packet_check_result (const char *buf
)
1161 /* The stub recognized the packet request. Check that the
1162 operation succeeded. */
1164 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1166 /* "Enn" - definitly an error. */
1167 return PACKET_ERROR
;
1169 /* Always treat "E." as an error. This will be used for
1170 more verbose error messages, such as E.memtypes. */
1171 if (buf
[0] == 'E' && buf
[1] == '.')
1172 return PACKET_ERROR
;
1174 /* The packet may or may not be OK. Just assume it is. */
1178 /* The stub does not support the packet. */
1179 return PACKET_UNKNOWN
;
1182 static enum packet_result
1183 packet_ok (const char *buf
, struct packet_config
*config
)
1185 enum packet_result result
;
1187 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1188 && config
->support
== PACKET_DISABLE
)
1189 internal_error (__FILE__
, __LINE__
,
1190 _("packet_ok: attempt to use a disabled packet"));
1192 result
= packet_check_result (buf
);
1197 /* The stub recognized the packet request. */
1198 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1201 fprintf_unfiltered (gdb_stdlog
,
1202 "Packet %s (%s) is supported\n",
1203 config
->name
, config
->title
);
1204 config
->support
= PACKET_ENABLE
;
1207 case PACKET_UNKNOWN
:
1208 /* The stub does not support the packet. */
1209 if (config
->detect
== AUTO_BOOLEAN_AUTO
1210 && config
->support
== PACKET_ENABLE
)
1212 /* If the stub previously indicated that the packet was
1213 supported then there is a protocol error. */
1214 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1215 config
->name
, config
->title
);
1217 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1219 /* The user set it wrong. */
1220 error (_("Enabled packet %s (%s) not recognized by stub"),
1221 config
->name
, config
->title
);
1225 fprintf_unfiltered (gdb_stdlog
,
1226 "Packet %s (%s) is NOT supported\n",
1227 config
->name
, config
->title
);
1228 config
->support
= PACKET_DISABLE
;
1248 PACKET_vFile_pwrite
,
1250 PACKET_vFile_unlink
,
1251 PACKET_vFile_readlink
,
1254 PACKET_qXfer_features
,
1255 PACKET_qXfer_exec_file
,
1256 PACKET_qXfer_libraries
,
1257 PACKET_qXfer_libraries_svr4
,
1258 PACKET_qXfer_memory_map
,
1259 PACKET_qXfer_spu_read
,
1260 PACKET_qXfer_spu_write
,
1261 PACKET_qXfer_osdata
,
1262 PACKET_qXfer_threads
,
1263 PACKET_qXfer_statictrace_read
,
1264 PACKET_qXfer_traceframe_info
,
1270 PACKET_QPassSignals
,
1271 PACKET_QProgramSignals
,
1273 PACKET_qSearch_memory
,
1276 PACKET_QStartNoAckMode
,
1278 PACKET_qXfer_siginfo_read
,
1279 PACKET_qXfer_siginfo_write
,
1282 /* Support for conditional tracepoints. */
1283 PACKET_ConditionalTracepoints
,
1285 /* Support for target-side breakpoint conditions. */
1286 PACKET_ConditionalBreakpoints
,
1288 /* Support for target-side breakpoint commands. */
1289 PACKET_BreakpointCommands
,
1291 /* Support for fast tracepoints. */
1292 PACKET_FastTracepoints
,
1294 /* Support for static tracepoints. */
1295 PACKET_StaticTracepoints
,
1297 /* Support for installing tracepoints while a trace experiment is
1299 PACKET_InstallInTrace
,
1303 PACKET_TracepointSource
,
1306 PACKET_QDisableRandomization
,
1308 PACKET_QTBuffer_size
,
1311 PACKET_qXfer_btrace
,
1313 /* Support for the QNonStop packet. */
1316 /* Support for multi-process extensions. */
1317 PACKET_multiprocess_feature
,
1319 /* Support for enabling and disabling tracepoints while a trace
1320 experiment is running. */
1321 PACKET_EnableDisableTracepoints_feature
,
1323 /* Support for collecting strings using the tracenz bytecode. */
1324 PACKET_tracenz_feature
,
1326 /* Support for continuing to run a trace experiment while GDB is
1328 PACKET_DisconnectedTracing_feature
,
1330 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1331 PACKET_augmented_libraries_svr4_read_feature
,
1333 /* Support for the qXfer:btrace-conf:read packet. */
1334 PACKET_qXfer_btrace_conf
,
1336 /* Support for the Qbtrace-conf:bts:size packet. */
1337 PACKET_Qbtrace_conf_bts_size
,
1339 /* Support for swbreak+ feature. */
1340 PACKET_swbreak_feature
,
1342 /* Support for hwbreak+ feature. */
1343 PACKET_hwbreak_feature
,
1348 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1350 /* Returns the packet's corresponding "set remote foo-packet" command
1351 state. See struct packet_config for more details. */
1353 static enum auto_boolean
1354 packet_set_cmd_state (int packet
)
1356 return remote_protocol_packets
[packet
].detect
;
1359 /* Returns whether a given packet or feature is supported. This takes
1360 into account the state of the corresponding "set remote foo-packet"
1361 command, which may be used to bypass auto-detection. */
1363 static enum packet_support
1364 packet_config_support (struct packet_config
*config
)
1366 switch (config
->detect
)
1368 case AUTO_BOOLEAN_TRUE
:
1369 return PACKET_ENABLE
;
1370 case AUTO_BOOLEAN_FALSE
:
1371 return PACKET_DISABLE
;
1372 case AUTO_BOOLEAN_AUTO
:
1373 return config
->support
;
1375 gdb_assert_not_reached (_("bad switch"));
1379 /* Same as packet_config_support, but takes the packet's enum value as
1382 static enum packet_support
1383 packet_support (int packet
)
1385 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1387 return packet_config_support (config
);
1391 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1392 struct cmd_list_element
*c
,
1395 struct packet_config
*packet
;
1397 for (packet
= remote_protocol_packets
;
1398 packet
< &remote_protocol_packets
[PACKET_MAX
];
1401 if (&packet
->detect
== c
->var
)
1403 show_packet_config_cmd (packet
);
1407 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1411 /* Should we try one of the 'Z' requests? */
1415 Z_PACKET_SOFTWARE_BP
,
1416 Z_PACKET_HARDWARE_BP
,
1423 /* For compatibility with older distributions. Provide a ``set remote
1424 Z-packet ...'' command that updates all the Z packet types. */
1426 static enum auto_boolean remote_Z_packet_detect
;
1429 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1430 struct cmd_list_element
*c
)
1434 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1435 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1439 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1440 struct cmd_list_element
*c
,
1445 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1447 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1451 /* Returns true if the multi-process extensions are in effect. */
1454 remote_multi_process_p (struct remote_state
*rs
)
1456 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1459 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1460 static struct async_signal_handler
*async_sigint_remote_twice_token
;
1461 static struct async_signal_handler
*async_sigint_remote_token
;
1464 /* Asynchronous signal handle registered as event loop source for
1465 when we have pending events ready to be passed to the core. */
1467 static struct async_event_handler
*remote_async_inferior_event_token
;
1471 static ptid_t magic_null_ptid
;
1472 static ptid_t not_sent_ptid
;
1473 static ptid_t any_thread_ptid
;
1475 /* Find out if the stub attached to PID (and hence GDB should offer to
1476 detach instead of killing it when bailing out). */
1479 remote_query_attached (int pid
)
1481 struct remote_state
*rs
= get_remote_state ();
1482 size_t size
= get_remote_packet_size ();
1484 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1487 if (remote_multi_process_p (rs
))
1488 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1490 xsnprintf (rs
->buf
, size
, "qAttached");
1493 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1495 switch (packet_ok (rs
->buf
,
1496 &remote_protocol_packets
[PACKET_qAttached
]))
1499 if (strcmp (rs
->buf
, "1") == 0)
1503 warning (_("Remote failure reply: %s"), rs
->buf
);
1505 case PACKET_UNKNOWN
:
1512 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1513 has been invented by GDB, instead of reported by the target. Since
1514 we can be connected to a remote system before before knowing about
1515 any inferior, mark the target with execution when we find the first
1516 inferior. If ATTACHED is 1, then we had just attached to this
1517 inferior. If it is 0, then we just created this inferior. If it
1518 is -1, then try querying the remote stub to find out if it had
1519 attached to the inferior or not. */
1521 static struct inferior
*
1522 remote_add_inferior (int fake_pid_p
, int pid
, int attached
)
1524 struct inferior
*inf
;
1526 /* Check whether this process we're learning about is to be
1527 considered attached, or if is to be considered to have been
1528 spawned by the stub. */
1530 attached
= remote_query_attached (pid
);
1532 if (gdbarch_has_global_solist (target_gdbarch ()))
1534 /* If the target shares code across all inferiors, then every
1535 attach adds a new inferior. */
1536 inf
= add_inferior (pid
);
1538 /* ... and every inferior is bound to the same program space.
1539 However, each inferior may still have its own address
1541 inf
->aspace
= maybe_new_address_space ();
1542 inf
->pspace
= current_program_space
;
1546 /* In the traditional debugging scenario, there's a 1-1 match
1547 between program/address spaces. We simply bind the inferior
1548 to the program space's address space. */
1549 inf
= current_inferior ();
1550 inferior_appeared (inf
, pid
);
1553 inf
->attach_flag
= attached
;
1554 inf
->fake_pid_p
= fake_pid_p
;
1559 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1560 according to RUNNING. */
1563 remote_add_thread (ptid_t ptid
, int running
)
1565 struct remote_state
*rs
= get_remote_state ();
1567 /* GDB historically didn't pull threads in the initial connection
1568 setup. If the remote target doesn't even have a concept of
1569 threads (e.g., a bare-metal target), even if internally we
1570 consider that a single-threaded target, mentioning a new thread
1571 might be confusing to the user. Be silent then, preserving the
1572 age old behavior. */
1573 if (rs
->starting_up
)
1574 add_thread_silent (ptid
);
1578 set_executing (ptid
, running
);
1579 set_running (ptid
, running
);
1582 /* Come here when we learn about a thread id from the remote target.
1583 It may be the first time we hear about such thread, so take the
1584 opportunity to add it to GDB's thread list. In case this is the
1585 first time we're noticing its corresponding inferior, add it to
1586 GDB's inferior list as well. */
1589 remote_notice_new_inferior (ptid_t currthread
, int running
)
1591 /* If this is a new thread, add it to GDB's thread list.
1592 If we leave it up to WFI to do this, bad things will happen. */
1594 if (in_thread_list (currthread
) && is_exited (currthread
))
1596 /* We're seeing an event on a thread id we knew had exited.
1597 This has to be a new thread reusing the old id. Add it. */
1598 remote_add_thread (currthread
, running
);
1602 if (!in_thread_list (currthread
))
1604 struct inferior
*inf
= NULL
;
1605 int pid
= ptid_get_pid (currthread
);
1607 if (ptid_is_pid (inferior_ptid
)
1608 && pid
== ptid_get_pid (inferior_ptid
))
1610 /* inferior_ptid has no thread member yet. This can happen
1611 with the vAttach -> remote_wait,"TAAthread:" path if the
1612 stub doesn't support qC. This is the first stop reported
1613 after an attach, so this is the main thread. Update the
1614 ptid in the thread list. */
1615 if (in_thread_list (pid_to_ptid (pid
)))
1616 thread_change_ptid (inferior_ptid
, currthread
);
1619 remote_add_thread (currthread
, running
);
1620 inferior_ptid
= currthread
;
1625 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1627 /* inferior_ptid is not set yet. This can happen with the
1628 vRun -> remote_wait,"TAAthread:" path if the stub
1629 doesn't support qC. This is the first stop reported
1630 after an attach, so this is the main thread. Update the
1631 ptid in the thread list. */
1632 thread_change_ptid (inferior_ptid
, currthread
);
1636 /* When connecting to a target remote, or to a target
1637 extended-remote which already was debugging an inferior, we
1638 may not know about it yet. Add it before adding its child
1639 thread, so notifications are emitted in a sensible order. */
1640 if (!in_inferior_list (ptid_get_pid (currthread
)))
1642 struct remote_state
*rs
= get_remote_state ();
1643 int fake_pid_p
= !remote_multi_process_p (rs
);
1645 inf
= remote_add_inferior (fake_pid_p
,
1646 ptid_get_pid (currthread
), -1);
1649 /* This is really a new thread. Add it. */
1650 remote_add_thread (currthread
, running
);
1652 /* If we found a new inferior, let the common code do whatever
1653 it needs to with it (e.g., read shared libraries, insert
1654 breakpoints), unless we're just setting up an all-stop
1658 struct remote_state
*rs
= get_remote_state ();
1660 if (non_stop
|| !rs
->starting_up
)
1661 notice_new_inferior (currthread
, running
, 0);
1666 /* Return the private thread data, creating it if necessary. */
1668 static struct private_thread_info
*
1669 demand_private_info (ptid_t ptid
)
1671 struct thread_info
*info
= find_thread_ptid (ptid
);
1677 info
->priv
= xmalloc (sizeof (*(info
->priv
)));
1678 info
->private_dtor
= free_private_thread_info
;
1679 info
->priv
->core
= -1;
1680 info
->priv
->extra
= 0;
1686 /* Call this function as a result of
1687 1) A halt indication (T packet) containing a thread id
1688 2) A direct query of currthread
1689 3) Successful execution of set thread */
1692 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1694 rs
->general_thread
= currthread
;
1697 /* If 'QPassSignals' is supported, tell the remote stub what signals
1698 it can simply pass through to the inferior without reporting. */
1701 remote_pass_signals (struct target_ops
*self
,
1702 int numsigs
, unsigned char *pass_signals
)
1704 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
1706 char *pass_packet
, *p
;
1708 struct remote_state
*rs
= get_remote_state ();
1710 gdb_assert (numsigs
< 256);
1711 for (i
= 0; i
< numsigs
; i
++)
1713 if (pass_signals
[i
])
1716 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1717 strcpy (pass_packet
, "QPassSignals:");
1718 p
= pass_packet
+ strlen (pass_packet
);
1719 for (i
= 0; i
< numsigs
; i
++)
1721 if (pass_signals
[i
])
1724 *p
++ = tohex (i
>> 4);
1725 *p
++ = tohex (i
& 15);
1734 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1736 putpkt (pass_packet
);
1737 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1738 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1739 if (rs
->last_pass_packet
)
1740 xfree (rs
->last_pass_packet
);
1741 rs
->last_pass_packet
= pass_packet
;
1744 xfree (pass_packet
);
1748 /* If 'QProgramSignals' is supported, tell the remote stub what
1749 signals it should pass through to the inferior when detaching. */
1752 remote_program_signals (struct target_ops
*self
,
1753 int numsigs
, unsigned char *signals
)
1755 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
1759 struct remote_state
*rs
= get_remote_state ();
1761 gdb_assert (numsigs
< 256);
1762 for (i
= 0; i
< numsigs
; i
++)
1767 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1768 strcpy (packet
, "QProgramSignals:");
1769 p
= packet
+ strlen (packet
);
1770 for (i
= 0; i
< numsigs
; i
++)
1772 if (signal_pass_state (i
))
1775 *p
++ = tohex (i
>> 4);
1776 *p
++ = tohex (i
& 15);
1785 if (!rs
->last_program_signals_packet
1786 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
1789 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1790 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1791 xfree (rs
->last_program_signals_packet
);
1792 rs
->last_program_signals_packet
= packet
;
1799 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1800 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1801 thread. If GEN is set, set the general thread, if not, then set
1802 the step/continue thread. */
1804 set_thread (struct ptid ptid
, int gen
)
1806 struct remote_state
*rs
= get_remote_state ();
1807 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
1808 char *buf
= rs
->buf
;
1809 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1811 if (ptid_equal (state
, ptid
))
1815 *buf
++ = gen
? 'g' : 'c';
1816 if (ptid_equal (ptid
, magic_null_ptid
))
1817 xsnprintf (buf
, endbuf
- buf
, "0");
1818 else if (ptid_equal (ptid
, any_thread_ptid
))
1819 xsnprintf (buf
, endbuf
- buf
, "0");
1820 else if (ptid_equal (ptid
, minus_one_ptid
))
1821 xsnprintf (buf
, endbuf
- buf
, "-1");
1823 write_ptid (buf
, endbuf
, ptid
);
1825 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1827 rs
->general_thread
= ptid
;
1829 rs
->continue_thread
= ptid
;
1833 set_general_thread (struct ptid ptid
)
1835 set_thread (ptid
, 1);
1839 set_continue_thread (struct ptid ptid
)
1841 set_thread (ptid
, 0);
1844 /* Change the remote current process. Which thread within the process
1845 ends up selected isn't important, as long as it is the same process
1846 as what INFERIOR_PTID points to.
1848 This comes from that fact that there is no explicit notion of
1849 "selected process" in the protocol. The selected process for
1850 general operations is the process the selected general thread
1854 set_general_process (void)
1856 struct remote_state
*rs
= get_remote_state ();
1858 /* If the remote can't handle multiple processes, don't bother. */
1859 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1862 /* We only need to change the remote current thread if it's pointing
1863 at some other process. */
1864 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
1865 set_general_thread (inferior_ptid
);
1869 /* Return nonzero if this is the main thread that we made up ourselves
1870 to model non-threaded targets as single-threaded. */
1873 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
1875 struct remote_state
*rs
= get_remote_state ();
1878 if (ptid_equal (ptid
, magic_null_ptid
))
1879 /* The main thread is always alive. */
1882 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
1883 /* The main thread is always alive. This can happen after a
1884 vAttach, if the remote side doesn't support
1891 /* Return nonzero if the thread PTID is still alive on the remote
1895 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1897 struct remote_state
*rs
= get_remote_state ();
1900 /* Check if this is a thread that we made up ourselves to model
1901 non-threaded targets as single-threaded. */
1902 if (remote_thread_always_alive (ops
, ptid
))
1906 endp
= rs
->buf
+ get_remote_packet_size ();
1909 write_ptid (p
, endp
, ptid
);
1912 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1913 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1916 /* About these extended threadlist and threadinfo packets. They are
1917 variable length packets but, the fields within them are often fixed
1918 length. They are redundent enough to send over UDP as is the
1919 remote protocol in general. There is a matching unit test module
1922 /* WARNING: This threadref data structure comes from the remote O.S.,
1923 libstub protocol encoding, and remote.c. It is not particularly
1926 /* Right now, the internal structure is int. We want it to be bigger.
1927 Plan to fix this. */
1929 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1931 /* gdb_ext_thread_info is an internal GDB data structure which is
1932 equivalent to the reply of the remote threadinfo packet. */
1934 struct gdb_ext_thread_info
1936 threadref threadid
; /* External form of thread reference. */
1937 int active
; /* Has state interesting to GDB?
1939 char display
[256]; /* Brief state display, name,
1940 blocked/suspended. */
1941 char shortname
[32]; /* To be used to name threads. */
1942 char more_display
[256]; /* Long info, statistics, queue depth,
1946 /* The volume of remote transfers can be limited by submitting
1947 a mask containing bits specifying the desired information.
1948 Use a union of these values as the 'selection' parameter to
1949 get_thread_info. FIXME: Make these TAG names more thread specific. */
1951 #define TAG_THREADID 1
1952 #define TAG_EXISTS 2
1953 #define TAG_DISPLAY 4
1954 #define TAG_THREADNAME 8
1955 #define TAG_MOREDISPLAY 16
1957 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1959 static char *unpack_nibble (char *buf
, int *val
);
1961 static char *unpack_byte (char *buf
, int *value
);
1963 static char *pack_int (char *buf
, int value
);
1965 static char *unpack_int (char *buf
, int *value
);
1967 static char *unpack_string (char *src
, char *dest
, int length
);
1969 static char *pack_threadid (char *pkt
, threadref
*id
);
1971 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1973 void int_to_threadref (threadref
*id
, int value
);
1975 static int threadref_to_int (threadref
*ref
);
1977 static void copy_threadref (threadref
*dest
, threadref
*src
);
1979 static int threadmatch (threadref
*dest
, threadref
*src
);
1981 static char *pack_threadinfo_request (char *pkt
, int mode
,
1984 static int remote_unpack_thread_info_response (char *pkt
,
1985 threadref
*expectedref
,
1986 struct gdb_ext_thread_info
1990 static int remote_get_threadinfo (threadref
*threadid
,
1991 int fieldset
, /*TAG mask */
1992 struct gdb_ext_thread_info
*info
);
1994 static char *pack_threadlist_request (char *pkt
, int startflag
,
1996 threadref
*nextthread
);
1998 static int parse_threadlist_response (char *pkt
,
2000 threadref
*original_echo
,
2001 threadref
*resultlist
,
2004 static int remote_get_threadlist (int startflag
,
2005 threadref
*nextthread
,
2009 threadref
*threadlist
);
2011 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2013 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2014 void *context
, int looplimit
);
2016 static int remote_newthread_step (threadref
*ref
, void *context
);
2019 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2020 buffer we're allowed to write to. Returns
2021 BUF+CHARACTERS_WRITTEN. */
2024 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2027 struct remote_state
*rs
= get_remote_state ();
2029 if (remote_multi_process_p (rs
))
2031 pid
= ptid_get_pid (ptid
);
2033 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2035 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2037 tid
= ptid_get_lwp (ptid
);
2039 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2041 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2046 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2047 passed the last parsed char. Returns null_ptid on error. */
2050 read_ptid (char *buf
, char **obuf
)
2054 ULONGEST pid
= 0, tid
= 0;
2058 /* Multi-process ptid. */
2059 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2061 error (_("invalid remote ptid: %s"), p
);
2064 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2067 return ptid_build (pid
, tid
, 0);
2070 /* No multi-process. Just a tid. */
2071 pp
= unpack_varlen_hex (p
, &tid
);
2073 /* Since the stub is not sending a process id, then default to
2074 what's in inferior_ptid, unless it's null at this point. If so,
2075 then since there's no way to know the pid of the reported
2076 threads, use the magic number. */
2077 if (ptid_equal (inferior_ptid
, null_ptid
))
2078 pid
= ptid_get_pid (magic_null_ptid
);
2080 pid
= ptid_get_pid (inferior_ptid
);
2084 return ptid_build (pid
, tid
, 0);
2090 if (ch
>= 'a' && ch
<= 'f')
2091 return ch
- 'a' + 10;
2092 if (ch
>= '0' && ch
<= '9')
2094 if (ch
>= 'A' && ch
<= 'F')
2095 return ch
- 'A' + 10;
2100 stub_unpack_int (char *buff
, int fieldlength
)
2107 nibble
= stubhex (*buff
++);
2111 retval
= retval
<< 4;
2117 unpack_nibble (char *buf
, int *val
)
2119 *val
= fromhex (*buf
++);
2124 unpack_byte (char *buf
, int *value
)
2126 *value
= stub_unpack_int (buf
, 2);
2131 pack_int (char *buf
, int value
)
2133 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2134 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2135 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2136 buf
= pack_hex_byte (buf
, (value
& 0xff));
2141 unpack_int (char *buf
, int *value
)
2143 *value
= stub_unpack_int (buf
, 8);
2147 #if 0 /* Currently unused, uncomment when needed. */
2148 static char *pack_string (char *pkt
, char *string
);
2151 pack_string (char *pkt
, char *string
)
2156 len
= strlen (string
);
2158 len
= 200; /* Bigger than most GDB packets, junk??? */
2159 pkt
= pack_hex_byte (pkt
, len
);
2163 if ((ch
== '\0') || (ch
== '#'))
2164 ch
= '*'; /* Protect encapsulation. */
2169 #endif /* 0 (unused) */
2172 unpack_string (char *src
, char *dest
, int length
)
2181 pack_threadid (char *pkt
, threadref
*id
)
2184 unsigned char *altid
;
2186 altid
= (unsigned char *) id
;
2187 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2189 pkt
= pack_hex_byte (pkt
, *altid
++);
2195 unpack_threadid (char *inbuf
, threadref
*id
)
2198 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2201 altref
= (char *) id
;
2203 while (inbuf
< limit
)
2205 x
= stubhex (*inbuf
++);
2206 y
= stubhex (*inbuf
++);
2207 *altref
++ = (x
<< 4) | y
;
2212 /* Externally, threadrefs are 64 bits but internally, they are still
2213 ints. This is due to a mismatch of specifications. We would like
2214 to use 64bit thread references internally. This is an adapter
2218 int_to_threadref (threadref
*id
, int value
)
2220 unsigned char *scan
;
2222 scan
= (unsigned char *) id
;
2228 *scan
++ = (value
>> 24) & 0xff;
2229 *scan
++ = (value
>> 16) & 0xff;
2230 *scan
++ = (value
>> 8) & 0xff;
2231 *scan
++ = (value
& 0xff);
2235 threadref_to_int (threadref
*ref
)
2238 unsigned char *scan
;
2244 value
= (value
<< 8) | ((*scan
++) & 0xff);
2249 copy_threadref (threadref
*dest
, threadref
*src
)
2252 unsigned char *csrc
, *cdest
;
2254 csrc
= (unsigned char *) src
;
2255 cdest
= (unsigned char *) dest
;
2262 threadmatch (threadref
*dest
, threadref
*src
)
2264 /* Things are broken right now, so just assume we got a match. */
2266 unsigned char *srcp
, *destp
;
2268 srcp
= (char *) src
;
2269 destp
= (char *) dest
;
2273 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2280 threadid:1, # always request threadid
2287 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2290 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2292 *pkt
++ = 'q'; /* Info Query */
2293 *pkt
++ = 'P'; /* process or thread info */
2294 pkt
= pack_int (pkt
, mode
); /* mode */
2295 pkt
= pack_threadid (pkt
, id
); /* threadid */
2296 *pkt
= '\0'; /* terminate */
2300 /* These values tag the fields in a thread info response packet. */
2301 /* Tagging the fields allows us to request specific fields and to
2302 add more fields as time goes by. */
2304 #define TAG_THREADID 1 /* Echo the thread identifier. */
2305 #define TAG_EXISTS 2 /* Is this process defined enough to
2306 fetch registers and its stack? */
2307 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2308 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2309 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2313 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2314 struct gdb_ext_thread_info
*info
)
2316 struct remote_state
*rs
= get_remote_state ();
2320 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2323 /* info->threadid = 0; FIXME: implement zero_threadref. */
2325 info
->display
[0] = '\0';
2326 info
->shortname
[0] = '\0';
2327 info
->more_display
[0] = '\0';
2329 /* Assume the characters indicating the packet type have been
2331 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2332 pkt
= unpack_threadid (pkt
, &ref
);
2335 warning (_("Incomplete response to threadinfo request."));
2336 if (!threadmatch (&ref
, expectedref
))
2337 { /* This is an answer to a different request. */
2338 warning (_("ERROR RMT Thread info mismatch."));
2341 copy_threadref (&info
->threadid
, &ref
);
2343 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2345 /* Packets are terminated with nulls. */
2346 while ((pkt
< limit
) && mask
&& *pkt
)
2348 pkt
= unpack_int (pkt
, &tag
); /* tag */
2349 pkt
= unpack_byte (pkt
, &length
); /* length */
2350 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2352 warning (_("ERROR RMT: threadinfo tag mismatch."));
2356 if (tag
== TAG_THREADID
)
2360 warning (_("ERROR RMT: length of threadid is not 16."));
2364 pkt
= unpack_threadid (pkt
, &ref
);
2365 mask
= mask
& ~TAG_THREADID
;
2368 if (tag
== TAG_EXISTS
)
2370 info
->active
= stub_unpack_int (pkt
, length
);
2372 mask
= mask
& ~(TAG_EXISTS
);
2375 warning (_("ERROR RMT: 'exists' length too long."));
2381 if (tag
== TAG_THREADNAME
)
2383 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2384 mask
= mask
& ~TAG_THREADNAME
;
2387 if (tag
== TAG_DISPLAY
)
2389 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2390 mask
= mask
& ~TAG_DISPLAY
;
2393 if (tag
== TAG_MOREDISPLAY
)
2395 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2396 mask
= mask
& ~TAG_MOREDISPLAY
;
2399 warning (_("ERROR RMT: unknown thread info tag."));
2400 break; /* Not a tag we know about. */
2406 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2407 struct gdb_ext_thread_info
*info
)
2409 struct remote_state
*rs
= get_remote_state ();
2412 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2414 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2416 if (rs
->buf
[0] == '\0')
2419 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2424 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2427 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2428 threadref
*nextthread
)
2430 *pkt
++ = 'q'; /* info query packet */
2431 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2432 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2433 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2434 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2439 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2442 parse_threadlist_response (char *pkt
, int result_limit
,
2443 threadref
*original_echo
, threadref
*resultlist
,
2446 struct remote_state
*rs
= get_remote_state ();
2448 int count
, resultcount
, done
;
2451 /* Assume the 'q' and 'M chars have been stripped. */
2452 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2453 /* done parse past here */
2454 pkt
= unpack_byte (pkt
, &count
); /* count field */
2455 pkt
= unpack_nibble (pkt
, &done
);
2456 /* The first threadid is the argument threadid. */
2457 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2458 while ((count
-- > 0) && (pkt
< limit
))
2460 pkt
= unpack_threadid (pkt
, resultlist
++);
2461 if (resultcount
++ >= result_limit
)
2469 /* Fetch the next batch of threads from the remote. Returns -1 if the
2470 qL packet is not supported, 0 on error and 1 on success. */
2473 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2474 int *done
, int *result_count
, threadref
*threadlist
)
2476 struct remote_state
*rs
= get_remote_state ();
2479 /* Trancate result limit to be smaller than the packet size. */
2480 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2481 >= get_remote_packet_size ())
2482 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2484 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2486 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2487 if (*rs
->buf
== '\0')
2489 /* Packet not supported. */
2494 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2495 &rs
->echo_nextthread
, threadlist
, done
);
2497 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2499 /* FIXME: This is a good reason to drop the packet. */
2500 /* Possably, there is a duplicate response. */
2502 retransmit immediatly - race conditions
2503 retransmit after timeout - yes
2505 wait for packet, then exit
2507 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2508 return 0; /* I choose simply exiting. */
2510 if (*result_count
<= 0)
2514 warning (_("RMT ERROR : failed to get remote thread list."));
2517 return result
; /* break; */
2519 if (*result_count
> result_limit
)
2522 warning (_("RMT ERROR: threadlist response longer than requested."));
2528 /* Fetch the list of remote threads, with the qL packet, and call
2529 STEPFUNCTION for each thread found. Stops iterating and returns 1
2530 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2531 STEPFUNCTION returns false. If the packet is not supported,
2535 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2538 struct remote_state
*rs
= get_remote_state ();
2539 int done
, i
, result_count
;
2547 if (loopcount
++ > looplimit
)
2550 warning (_("Remote fetch threadlist -infinite loop-."));
2553 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2554 MAXTHREADLISTRESULTS
,
2555 &done
, &result_count
,
2556 rs
->resultthreadlist
);
2559 /* Clear for later iterations. */
2561 /* Setup to resume next batch of thread references, set nextthread. */
2562 if (result_count
>= 1)
2563 copy_threadref (&rs
->nextthread
,
2564 &rs
->resultthreadlist
[result_count
- 1]);
2566 while (result_count
--)
2568 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2578 /* A thread found on the remote target. */
2580 typedef struct thread_item
2582 /* The thread's PTID. */
2585 /* The thread's extra info. May be NULL. */
2588 /* The core the thread was running on. -1 if not known. */
2591 DEF_VEC_O(thread_item_t
);
2593 /* Context passed around to the various methods listing remote
2594 threads. As new threads are found, they're added to the ITEMS
2597 struct threads_listing_context
2599 /* The threads found on the remote target. */
2600 VEC (thread_item_t
) *items
;
2603 /* Discard the contents of the constructed thread listing context. */
2606 clear_threads_listing_context (void *p
)
2608 struct threads_listing_context
*context
= p
;
2610 struct thread_item
*item
;
2612 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2613 xfree (item
->extra
);
2615 VEC_free (thread_item_t
, context
->items
);
2619 remote_newthread_step (threadref
*ref
, void *data
)
2621 struct threads_listing_context
*context
= data
;
2622 struct thread_item item
;
2623 int pid
= ptid_get_pid (inferior_ptid
);
2625 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
2629 VEC_safe_push (thread_item_t
, context
->items
, &item
);
2631 return 1; /* continue iterator */
2634 #define CRAZY_MAX_THREADS 1000
2637 remote_current_thread (ptid_t oldpid
)
2639 struct remote_state
*rs
= get_remote_state ();
2642 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2643 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2644 return read_ptid (&rs
->buf
[2], NULL
);
2649 /* List remote threads using the deprecated qL packet. */
2652 remote_get_threads_with_ql (struct target_ops
*ops
,
2653 struct threads_listing_context
*context
)
2655 if (remote_threadlist_iterator (remote_newthread_step
, context
,
2656 CRAZY_MAX_THREADS
) >= 0)
2662 #if defined(HAVE_LIBEXPAT)
2665 start_thread (struct gdb_xml_parser
*parser
,
2666 const struct gdb_xml_element
*element
,
2667 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2669 struct threads_listing_context
*data
= user_data
;
2671 struct thread_item item
;
2673 struct gdb_xml_value
*attr
;
2675 id
= xml_find_attribute (attributes
, "id")->value
;
2676 item
.ptid
= read_ptid (id
, NULL
);
2678 attr
= xml_find_attribute (attributes
, "core");
2680 item
.core
= *(ULONGEST
*) attr
->value
;
2686 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2690 end_thread (struct gdb_xml_parser
*parser
,
2691 const struct gdb_xml_element
*element
,
2692 void *user_data
, const char *body_text
)
2694 struct threads_listing_context
*data
= user_data
;
2696 if (body_text
&& *body_text
)
2697 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2700 const struct gdb_xml_attribute thread_attributes
[] = {
2701 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2702 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2703 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2706 const struct gdb_xml_element thread_children
[] = {
2707 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2710 const struct gdb_xml_element threads_children
[] = {
2711 { "thread", thread_attributes
, thread_children
,
2712 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2713 start_thread
, end_thread
},
2714 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2717 const struct gdb_xml_element threads_elements
[] = {
2718 { "threads", NULL
, threads_children
,
2719 GDB_XML_EF_NONE
, NULL
, NULL
},
2720 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2725 /* List remote threads using qXfer:threads:read. */
2728 remote_get_threads_with_qxfer (struct target_ops
*ops
,
2729 struct threads_listing_context
*context
)
2731 #if defined(HAVE_LIBEXPAT)
2732 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
2734 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
2735 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2737 if (xml
!= NULL
&& *xml
!= '\0')
2739 gdb_xml_parse_quick (_("threads"), "threads.dtd",
2740 threads_elements
, xml
, context
);
2743 do_cleanups (back_to
);
2751 /* List remote threads using qfThreadInfo/qsThreadInfo. */
2754 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
2755 struct threads_listing_context
*context
)
2757 struct remote_state
*rs
= get_remote_state ();
2759 if (rs
->use_threadinfo_query
)
2763 putpkt ("qfThreadInfo");
2764 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2766 if (bufp
[0] != '\0') /* q packet recognized */
2768 while (*bufp
++ == 'm') /* reply contains one or more TID */
2772 struct thread_item item
;
2774 item
.ptid
= read_ptid (bufp
, &bufp
);
2778 VEC_safe_push (thread_item_t
, context
->items
, &item
);
2780 while (*bufp
++ == ','); /* comma-separated list */
2781 putpkt ("qsThreadInfo");
2782 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2789 /* Packet not recognized. */
2790 rs
->use_threadinfo_query
= 0;
2797 /* Implement the to_update_thread_list function for the remote
2801 remote_update_thread_list (struct target_ops
*ops
)
2803 struct remote_state
*rs
= get_remote_state ();
2804 struct threads_listing_context context
;
2805 struct cleanup
*old_chain
;
2808 context
.items
= NULL
;
2809 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
2811 /* We have a few different mechanisms to fetch the thread list. Try
2812 them all, starting with the most preferred one first, falling
2813 back to older methods. */
2814 if (remote_get_threads_with_qxfer (ops
, &context
)
2815 || remote_get_threads_with_qthreadinfo (ops
, &context
)
2816 || remote_get_threads_with_ql (ops
, &context
))
2819 struct thread_item
*item
;
2820 struct thread_info
*tp
, *tmp
;
2824 if (VEC_empty (thread_item_t
, context
.items
)
2825 && remote_thread_always_alive (ops
, inferior_ptid
))
2827 /* Some targets don't really support threads, but still
2828 reply an (empty) thread list in response to the thread
2829 listing packets, instead of replying "packet not
2830 supported". Exit early so we don't delete the main
2832 do_cleanups (old_chain
);
2836 /* CONTEXT now holds the current thread list on the remote
2837 target end. Delete GDB-side threads no longer found on the
2839 ALL_THREADS_SAFE (tp
, tmp
)
2842 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2845 if (ptid_equal (item
->ptid
, tp
->ptid
))
2849 if (i
== VEC_length (thread_item_t
, context
.items
))
2852 delete_thread (tp
->ptid
);
2856 /* And now add threads we don't know about yet to our list. */
2858 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2861 if (!ptid_equal (item
->ptid
, null_ptid
))
2863 struct private_thread_info
*info
;
2864 /* In non-stop mode, we assume new found threads are
2865 running until proven otherwise with a stop reply. In
2866 all-stop, we can only get here if all threads are
2868 int running
= non_stop
? 1 : 0;
2870 remote_notice_new_inferior (item
->ptid
, running
);
2872 info
= demand_private_info (item
->ptid
);
2873 info
->core
= item
->core
;
2874 info
->extra
= item
->extra
;
2882 /* If no thread listing method is supported, then query whether
2883 each known thread is alive, one by one, with the T packet.
2884 If the target doesn't support threads at all, then this is a
2885 no-op. See remote_thread_alive. */
2889 do_cleanups (old_chain
);
2893 * Collect a descriptive string about the given thread.
2894 * The target may say anything it wants to about the thread
2895 * (typically info about its blocked / runnable state, name, etc.).
2896 * This string will appear in the info threads display.
2898 * Optional: targets are not required to implement this function.
2902 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
2904 struct remote_state
*rs
= get_remote_state ();
2908 struct gdb_ext_thread_info threadinfo
;
2909 static char display_buf
[100]; /* arbitrary... */
2910 int n
= 0; /* position in display_buf */
2912 if (rs
->remote_desc
== 0) /* paranoia */
2913 internal_error (__FILE__
, __LINE__
,
2914 _("remote_threads_extra_info"));
2916 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2917 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
2918 /* This is the main thread which was added by GDB. The remote
2919 server doesn't know about it. */
2922 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
2924 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2926 if (info
&& info
->priv
)
2927 return info
->priv
->extra
;
2932 if (rs
->use_threadextra_query
)
2935 char *endb
= rs
->buf
+ get_remote_packet_size ();
2937 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2939 write_ptid (b
, endb
, tp
->ptid
);
2942 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2943 if (rs
->buf
[0] != 0)
2945 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2946 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2947 display_buf
[result
] = '\0';
2952 /* If the above query fails, fall back to the old method. */
2953 rs
->use_threadextra_query
= 0;
2954 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2955 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2956 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
2957 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2958 if (threadinfo
.active
)
2960 if (*threadinfo
.shortname
)
2961 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2962 " Name: %s,", threadinfo
.shortname
);
2963 if (*threadinfo
.display
)
2964 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2965 " State: %s,", threadinfo
.display
);
2966 if (*threadinfo
.more_display
)
2967 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2968 " Priority: %s", threadinfo
.more_display
);
2972 /* For purely cosmetic reasons, clear up trailing commas. */
2973 if (',' == display_buf
[n
-1])
2974 display_buf
[n
-1] = ' ';
2983 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
2984 struct static_tracepoint_marker
*marker
)
2986 struct remote_state
*rs
= get_remote_state ();
2989 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
2991 p
+= hexnumstr (p
, addr
);
2993 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2997 error (_("Remote failure reply: %s"), p
);
3001 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3008 static VEC(static_tracepoint_marker_p
) *
3009 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3012 struct remote_state
*rs
= get_remote_state ();
3013 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3014 struct static_tracepoint_marker
*marker
= NULL
;
3015 struct cleanup
*old_chain
;
3018 /* Ask for a first packet of static tracepoint marker
3021 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3024 error (_("Remote failure reply: %s"), p
);
3026 old_chain
= make_cleanup (free_current_marker
, &marker
);
3031 marker
= XCNEW (struct static_tracepoint_marker
);
3035 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3037 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3039 VEC_safe_push (static_tracepoint_marker_p
,
3045 release_static_tracepoint_marker (marker
);
3046 memset (marker
, 0, sizeof (*marker
));
3049 while (*p
++ == ','); /* comma-separated list */
3050 /* Ask for another packet of static tracepoint definition. */
3052 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3056 do_cleanups (old_chain
);
3061 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3064 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3066 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3070 /* Restart the remote side; this is an extended protocol operation. */
3073 extended_remote_restart (void)
3075 struct remote_state
*rs
= get_remote_state ();
3077 /* Send the restart command; for reasons I don't understand the
3078 remote side really expects a number after the "R". */
3079 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3082 remote_fileio_reset ();
3085 /* Clean up connection to a remote debugger. */
3088 remote_close (struct target_ops
*self
)
3090 struct remote_state
*rs
= get_remote_state ();
3092 if (rs
->remote_desc
== NULL
)
3093 return; /* already closed */
3095 /* Make sure we leave stdin registered in the event loop, and we
3096 don't leave the async SIGINT signal handler installed. */
3097 remote_terminal_ours (self
);
3099 serial_close (rs
->remote_desc
);
3100 rs
->remote_desc
= NULL
;
3102 /* We don't have a connection to the remote stub anymore. Get rid
3103 of all the inferiors and their threads we were controlling.
3104 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3105 will be unable to find the thread corresponding to (pid, 0, 0). */
3106 inferior_ptid
= null_ptid
;
3107 discard_all_inferiors ();
3109 /* We are closing the remote target, so we should discard
3110 everything of this target. */
3111 discard_pending_stop_replies_in_queue (rs
);
3113 if (remote_async_inferior_event_token
)
3114 delete_async_event_handler (&remote_async_inferior_event_token
);
3116 remote_notif_state_xfree (rs
->notif_state
);
3118 trace_reset_local_state ();
3121 /* Query the remote side for the text, data and bss offsets. */
3126 struct remote_state
*rs
= get_remote_state ();
3129 int lose
, num_segments
= 0, do_sections
, do_segments
;
3130 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3131 struct section_offsets
*offs
;
3132 struct symfile_segment_data
*data
;
3134 if (symfile_objfile
== NULL
)
3137 putpkt ("qOffsets");
3138 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3141 if (buf
[0] == '\000')
3142 return; /* Return silently. Stub doesn't support
3146 warning (_("Remote failure reply: %s"), buf
);
3150 /* Pick up each field in turn. This used to be done with scanf, but
3151 scanf will make trouble if CORE_ADDR size doesn't match
3152 conversion directives correctly. The following code will work
3153 with any size of CORE_ADDR. */
3154 text_addr
= data_addr
= bss_addr
= 0;
3158 if (startswith (ptr
, "Text="))
3161 /* Don't use strtol, could lose on big values. */
3162 while (*ptr
&& *ptr
!= ';')
3163 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3165 if (startswith (ptr
, ";Data="))
3168 while (*ptr
&& *ptr
!= ';')
3169 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3174 if (!lose
&& startswith (ptr
, ";Bss="))
3177 while (*ptr
&& *ptr
!= ';')
3178 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3180 if (bss_addr
!= data_addr
)
3181 warning (_("Target reported unsupported offsets: %s"), buf
);
3186 else if (startswith (ptr
, "TextSeg="))
3189 /* Don't use strtol, could lose on big values. */
3190 while (*ptr
&& *ptr
!= ';')
3191 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3194 if (startswith (ptr
, ";DataSeg="))
3197 while (*ptr
&& *ptr
!= ';')
3198 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3206 error (_("Malformed response to offset query, %s"), buf
);
3207 else if (*ptr
!= '\0')
3208 warning (_("Target reported unsupported offsets: %s"), buf
);
3210 offs
= ((struct section_offsets
*)
3211 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3212 memcpy (offs
, symfile_objfile
->section_offsets
,
3213 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3215 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3216 do_segments
= (data
!= NULL
);
3217 do_sections
= num_segments
== 0;
3219 if (num_segments
> 0)
3221 segments
[0] = text_addr
;
3222 segments
[1] = data_addr
;
3224 /* If we have two segments, we can still try to relocate everything
3225 by assuming that the .text and .data offsets apply to the whole
3226 text and data segments. Convert the offsets given in the packet
3227 to base addresses for symfile_map_offsets_to_segments. */
3228 else if (data
&& data
->num_segments
== 2)
3230 segments
[0] = data
->segment_bases
[0] + text_addr
;
3231 segments
[1] = data
->segment_bases
[1] + data_addr
;
3234 /* If the object file has only one segment, assume that it is text
3235 rather than data; main programs with no writable data are rare,
3236 but programs with no code are useless. Of course the code might
3237 have ended up in the data segment... to detect that we would need
3238 the permissions here. */
3239 else if (data
&& data
->num_segments
== 1)
3241 segments
[0] = data
->segment_bases
[0] + text_addr
;
3244 /* There's no way to relocate by segment. */
3250 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3251 offs
, num_segments
, segments
);
3253 if (ret
== 0 && !do_sections
)
3254 error (_("Can not handle qOffsets TextSeg "
3255 "response with this symbol file"));
3262 free_symfile_segment_data (data
);
3266 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3268 /* This is a temporary kludge to force data and bss to use the
3269 same offsets because that's what nlmconv does now. The real
3270 solution requires changes to the stub and remote.c that I
3271 don't have time to do right now. */
3273 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3274 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3277 objfile_relocate (symfile_objfile
, offs
);
3280 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3281 threads we know are stopped already. This is used during the
3282 initial remote connection in non-stop mode --- threads that are
3283 reported as already being stopped are left stopped. */
3286 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3288 /* If we have a stop reply for this thread, it must be stopped. */
3289 if (peek_stop_reply (thread
->ptid
))
3290 set_stop_requested (thread
->ptid
, 1);
3295 /* Send interrupt_sequence to remote target. */
3297 send_interrupt_sequence (void)
3299 struct remote_state
*rs
= get_remote_state ();
3301 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3302 remote_serial_write ("\x03", 1);
3303 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3304 serial_send_break (rs
->remote_desc
);
3305 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3307 serial_send_break (rs
->remote_desc
);
3308 remote_serial_write ("g", 1);
3311 internal_error (__FILE__
, __LINE__
,
3312 _("Invalid value for interrupt_sequence_mode: %s."),
3313 interrupt_sequence_mode
);
3317 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3318 and extract the PTID. Returns NULL_PTID if not found. */
3321 stop_reply_extract_thread (char *stop_reply
)
3323 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3327 /* Txx r:val ; r:val (...) */
3330 /* Look for "register" named "thread". */
3335 p1
= strchr (p
, ':');
3339 if (strncmp (p
, "thread", p1
- p
) == 0)
3340 return read_ptid (++p1
, &p
);
3342 p1
= strchr (p
, ';');
3354 /* Determine the remote side's current thread. If we have a stop
3355 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3356 "thread" register we can extract the current thread from. If not,
3357 ask the remote which is the current thread with qC. The former
3358 method avoids a roundtrip. */
3361 get_current_thread (char *wait_status
)
3365 /* Note we don't use remote_parse_stop_reply as that makes use of
3366 the target architecture, which we haven't yet fully determined at
3368 if (wait_status
!= NULL
)
3369 ptid
= stop_reply_extract_thread (wait_status
);
3370 if (ptid_equal (ptid
, null_ptid
))
3371 ptid
= remote_current_thread (inferior_ptid
);
3376 /* Query the remote target for which is the current thread/process,
3377 add it to our tables, and update INFERIOR_PTID. The caller is
3378 responsible for setting the state such that the remote end is ready
3379 to return the current thread.
3381 This function is called after handling the '?' or 'vRun' packets,
3382 whose response is a stop reply from which we can also try
3383 extracting the thread. If the target doesn't support the explicit
3384 qC query, we infer the current thread from that stop reply, passed
3385 in in WAIT_STATUS, which may be NULL. */
3388 add_current_inferior_and_thread (char *wait_status
)
3390 struct remote_state
*rs
= get_remote_state ();
3392 ptid_t ptid
= null_ptid
;
3394 inferior_ptid
= null_ptid
;
3396 /* Now, if we have thread information, update inferior_ptid. */
3397 ptid
= get_current_thread (wait_status
);
3399 if (!ptid_equal (ptid
, null_ptid
))
3401 if (!remote_multi_process_p (rs
))
3404 inferior_ptid
= ptid
;
3408 /* Without this, some commands which require an active target
3409 (such as kill) won't work. This variable serves (at least)
3410 double duty as both the pid of the target process (if it has
3411 such), and as a flag indicating that a target is active. */
3412 inferior_ptid
= magic_null_ptid
;
3416 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1);
3418 /* Add the main thread. */
3419 add_thread_silent (inferior_ptid
);
3423 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3425 struct remote_state
*rs
= get_remote_state ();
3426 struct packet_config
*noack_config
;
3427 char *wait_status
= NULL
;
3429 immediate_quit
++; /* Allow user to interrupt it. */
3432 if (interrupt_on_connect
)
3433 send_interrupt_sequence ();
3435 /* Ack any packet which the remote side has already sent. */
3436 serial_write (rs
->remote_desc
, "+", 1);
3438 /* Signal other parts that we're going through the initial setup,
3439 and so things may not be stable yet. */
3440 rs
->starting_up
= 1;
3442 /* The first packet we send to the target is the optional "supported
3443 packets" request. If the target can answer this, it will tell us
3444 which later probes to skip. */
3445 remote_query_supported ();
3447 /* If the stub wants to get a QAllow, compose one and send it. */
3448 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
3449 remote_set_permissions (target
);
3451 /* Next, we possibly activate noack mode.
3453 If the QStartNoAckMode packet configuration is set to AUTO,
3454 enable noack mode if the stub reported a wish for it with
3457 If set to TRUE, then enable noack mode even if the stub didn't
3458 report it in qSupported. If the stub doesn't reply OK, the
3459 session ends with an error.
3461 If FALSE, then don't activate noack mode, regardless of what the
3462 stub claimed should be the default with qSupported. */
3464 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3465 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
3467 putpkt ("QStartNoAckMode");
3468 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3469 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3475 /* Tell the remote that we are using the extended protocol. */
3477 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3480 /* Let the target know which signals it is allowed to pass down to
3482 update_signals_program_target ();
3484 /* Next, if the target can specify a description, read it. We do
3485 this before anything involving memory or registers. */
3486 target_find_description ();
3488 /* Next, now that we know something about the target, update the
3489 address spaces in the program spaces. */
3490 update_address_spaces ();
3492 /* On OSs where the list of libraries is global to all
3493 processes, we fetch them early. */
3494 if (gdbarch_has_global_solist (target_gdbarch ()))
3495 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3499 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
3500 error (_("Non-stop mode requested, but remote "
3501 "does not support non-stop"));
3503 putpkt ("QNonStop:1");
3504 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3506 if (strcmp (rs
->buf
, "OK") != 0)
3507 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3509 /* Find about threads and processes the stub is already
3510 controlling. We default to adding them in the running state.
3511 The '?' query below will then tell us about which threads are
3513 remote_update_thread_list (target
);
3515 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
3517 /* Don't assume that the stub can operate in all-stop mode.
3518 Request it explicitly. */
3519 putpkt ("QNonStop:0");
3520 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3522 if (strcmp (rs
->buf
, "OK") != 0)
3523 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3526 /* Upload TSVs regardless of whether the target is running or not. The
3527 remote stub, such as GDBserver, may have some predefined or builtin
3528 TSVs, even if the target is not running. */
3529 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3531 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3533 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
3534 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3537 /* Check whether the target is running now. */
3539 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3545 struct inferior
*inf
;
3547 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3550 error (_("The target is not running (try extended-remote?)"));
3552 /* We're connected, but not running. Drop out before we
3553 call start_remote. */
3554 rs
->starting_up
= 0;
3559 /* Save the reply for later. */
3560 wait_status
= alloca (strlen (rs
->buf
) + 1);
3561 strcpy (wait_status
, rs
->buf
);
3564 /* Fetch thread list. */
3565 target_update_thread_list ();
3567 /* Let the stub know that we want it to return the thread. */
3568 set_continue_thread (minus_one_ptid
);
3570 if (thread_count () == 0)
3572 /* Target has no concept of threads at all. GDB treats
3573 non-threaded target as single-threaded; add a main
3575 add_current_inferior_and_thread (wait_status
);
3579 /* We have thread information; select the thread the target
3580 says should be current. If we're reconnecting to a
3581 multi-threaded program, this will ideally be the thread
3582 that last reported an event before GDB disconnected. */
3583 inferior_ptid
= get_current_thread (wait_status
);
3584 if (ptid_equal (inferior_ptid
, null_ptid
))
3586 /* Odd... The target was able to list threads, but not
3587 tell us which thread was current (no "thread"
3588 register in T stop reply?). Just pick the first
3589 thread in the thread list then. */
3590 inferior_ptid
= thread_list
->ptid
;
3594 /* init_wait_for_inferior should be called before get_offsets in order
3595 to manage `inserted' flag in bp loc in a correct state.
3596 breakpoint_init_inferior, called from init_wait_for_inferior, set
3597 `inserted' flag to 0, while before breakpoint_re_set, called from
3598 start_remote, set `inserted' flag to 1. In the initialization of
3599 inferior, breakpoint_init_inferior should be called first, and then
3600 breakpoint_re_set can be called. If this order is broken, state of
3601 `inserted' flag is wrong, and cause some problems on breakpoint
3603 init_wait_for_inferior ();
3605 get_offsets (); /* Get text, data & bss offsets. */
3607 /* If we could not find a description using qXfer, and we know
3608 how to do it some other way, try again. This is not
3609 supported for non-stop; it could be, but it is tricky if
3610 there are no stopped threads when we connect. */
3611 if (remote_read_description_p (target
)
3612 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3614 target_clear_description ();
3615 target_find_description ();
3618 /* Use the previously fetched status. */
3619 gdb_assert (wait_status
!= NULL
);
3620 strcpy (rs
->buf
, wait_status
);
3621 rs
->cached_wait_status
= 1;
3624 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3628 /* Clear WFI global state. Do this before finding about new
3629 threads and inferiors, and setting the current inferior.
3630 Otherwise we would clear the proceed status of the current
3631 inferior when we want its stop_soon state to be preserved
3632 (see notice_new_inferior). */
3633 init_wait_for_inferior ();
3635 /* In non-stop, we will either get an "OK", meaning that there
3636 are no stopped threads at this time; or, a regular stop
3637 reply. In the latter case, there may be more than one thread
3638 stopped --- we pull them all out using the vStopped
3640 if (strcmp (rs
->buf
, "OK") != 0)
3642 struct notif_client
*notif
= ¬if_client_stop
;
3644 /* remote_notif_get_pending_replies acks this one, and gets
3646 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
3647 = remote_notif_parse (notif
, rs
->buf
);
3648 remote_notif_get_pending_events (notif
);
3650 /* Make sure that threads that were stopped remain
3652 iterate_over_threads (set_stop_requested_callback
, NULL
);
3655 if (target_can_async_p ())
3658 if (thread_count () == 0)
3661 error (_("The target is not running (try extended-remote?)"));
3663 /* We're connected, but not running. Drop out before we
3664 call start_remote. */
3665 rs
->starting_up
= 0;
3669 /* Let the stub know that we want it to return the thread. */
3671 /* Force the stub to choose a thread. */
3672 set_general_thread (null_ptid
);
3675 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3676 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3677 error (_("remote didn't report the current thread in non-stop mode"));
3679 get_offsets (); /* Get text, data & bss offsets. */
3681 /* In non-stop mode, any cached wait status will be stored in
3682 the stop reply queue. */
3683 gdb_assert (wait_status
== NULL
);
3685 /* Report all signals during attach/startup. */
3686 remote_pass_signals (target
, 0, NULL
);
3689 /* If we connected to a live target, do some additional setup. */
3690 if (target_has_execution
)
3692 if (symfile_objfile
) /* No use without a symbol-file. */
3693 remote_check_symbols ();
3696 /* Possibly the target has been engaged in a trace run started
3697 previously; find out where things are at. */
3698 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3700 struct uploaded_tp
*uploaded_tps
= NULL
;
3702 if (current_trace_status ()->running
)
3703 printf_filtered (_("Trace is already running on the target.\n"));
3705 remote_upload_tracepoints (target
, &uploaded_tps
);
3707 merge_uploaded_tracepoints (&uploaded_tps
);
3710 /* The thread and inferior lists are now synchronized with the
3711 target, our symbols have been relocated, and we're merged the
3712 target's tracepoints with ours. We're done with basic start
3714 rs
->starting_up
= 0;
3716 /* Maybe breakpoints are global and need to be inserted now. */
3717 if (breakpoints_should_be_inserted_now ())
3718 insert_breakpoints ();
3721 /* Open a connection to a remote debugger.
3722 NAME is the filename used for communication. */
3725 remote_open (const char *name
, int from_tty
)
3727 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3730 /* Open a connection to a remote debugger using the extended
3731 remote gdb protocol. NAME is the filename used for communication. */
3734 extended_remote_open (const char *name
, int from_tty
)
3736 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3739 /* Reset all packets back to "unknown support". Called when opening a
3740 new connection to a remote target. */
3743 reset_all_packet_configs_support (void)
3747 for (i
= 0; i
< PACKET_MAX
; i
++)
3748 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
3751 /* Initialize all packet configs. */
3754 init_all_packet_configs (void)
3758 for (i
= 0; i
< PACKET_MAX
; i
++)
3760 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
3761 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
3765 /* Symbol look-up. */
3768 remote_check_symbols (void)
3770 struct remote_state
*rs
= get_remote_state ();
3771 char *msg
, *reply
, *tmp
;
3772 struct bound_minimal_symbol sym
;
3775 /* The remote side has no concept of inferiors that aren't running
3776 yet, it only knows about running processes. If we're connected
3777 but our current inferior is not running, we should not invite the
3778 remote target to request symbol lookups related to its
3779 (unrelated) current process. */
3780 if (!target_has_execution
)
3783 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
3786 /* Make sure the remote is pointing at the right process. Note
3787 there's no way to select "no process". */
3788 set_general_process ();
3790 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3791 because we need both at the same time. */
3792 msg
= alloca (get_remote_packet_size ());
3794 /* Invite target to request symbol lookups. */
3796 putpkt ("qSymbol::");
3797 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3798 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3801 while (startswith (reply
, "qSymbol:"))
3803 struct bound_minimal_symbol sym
;
3806 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3808 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3809 if (sym
.minsym
== NULL
)
3810 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3813 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
3814 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
3816 /* If this is a function address, return the start of code
3817 instead of any data function descriptor. */
3818 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3822 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3823 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3827 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3832 static struct serial
*
3833 remote_serial_open (const char *name
)
3835 static int udp_warning
= 0;
3837 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3838 of in ser-tcp.c, because it is the remote protocol assuming that the
3839 serial connection is reliable and not the serial connection promising
3841 if (!udp_warning
&& startswith (name
, "udp:"))
3843 warning (_("The remote protocol may be unreliable over UDP.\n"
3844 "Some events may be lost, rendering further debugging "
3849 return serial_open (name
);
3852 /* Inform the target of our permission settings. The permission flags
3853 work without this, but if the target knows the settings, it can do
3854 a couple things. First, it can add its own check, to catch cases
3855 that somehow manage to get by the permissions checks in target
3856 methods. Second, if the target is wired to disallow particular
3857 settings (for instance, a system in the field that is not set up to
3858 be able to stop at a breakpoint), it can object to any unavailable
3862 remote_set_permissions (struct target_ops
*self
)
3864 struct remote_state
*rs
= get_remote_state ();
3866 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
3867 "WriteReg:%x;WriteMem:%x;"
3868 "InsertBreak:%x;InsertTrace:%x;"
3869 "InsertFastTrace:%x;Stop:%x",
3870 may_write_registers
, may_write_memory
,
3871 may_insert_breakpoints
, may_insert_tracepoints
,
3872 may_insert_fast_tracepoints
, may_stop
);
3874 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3876 /* If the target didn't like the packet, warn the user. Do not try
3877 to undo the user's settings, that would just be maddening. */
3878 if (strcmp (rs
->buf
, "OK") != 0)
3879 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3882 /* This type describes each known response to the qSupported
3884 struct protocol_feature
3886 /* The name of this protocol feature. */
3889 /* The default for this protocol feature. */
3890 enum packet_support default_support
;
3892 /* The function to call when this feature is reported, or after
3893 qSupported processing if the feature is not supported.
3894 The first argument points to this structure. The second
3895 argument indicates whether the packet requested support be
3896 enabled, disabled, or probed (or the default, if this function
3897 is being called at the end of processing and this feature was
3898 not reported). The third argument may be NULL; if not NULL, it
3899 is a NUL-terminated string taken from the packet following
3900 this feature's name and an equals sign. */
3901 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3904 /* The corresponding packet for this feature. Only used if
3905 FUNC is remote_supported_packet. */
3910 remote_supported_packet (const struct protocol_feature
*feature
,
3911 enum packet_support support
,
3912 const char *argument
)
3916 warning (_("Remote qSupported response supplied an unexpected value for"
3917 " \"%s\"."), feature
->name
);
3921 remote_protocol_packets
[feature
->packet
].support
= support
;
3925 remote_packet_size (const struct protocol_feature
*feature
,
3926 enum packet_support support
, const char *value
)
3928 struct remote_state
*rs
= get_remote_state ();
3933 if (support
!= PACKET_ENABLE
)
3936 if (value
== NULL
|| *value
== '\0')
3938 warning (_("Remote target reported \"%s\" without a size."),
3944 packet_size
= strtol (value
, &value_end
, 16);
3945 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3947 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3948 feature
->name
, value
);
3952 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3954 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3955 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3956 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3959 /* Record the new maximum packet size. */
3960 rs
->explicit_packet_size
= packet_size
;
3963 static const struct protocol_feature remote_protocol_features
[] = {
3964 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3965 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3966 PACKET_qXfer_auxv
},
3967 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
3968 PACKET_qXfer_exec_file
},
3969 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3970 PACKET_qXfer_features
},
3971 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3972 PACKET_qXfer_libraries
},
3973 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
3974 PACKET_qXfer_libraries_svr4
},
3975 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
3976 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
3977 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3978 PACKET_qXfer_memory_map
},
3979 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3980 PACKET_qXfer_spu_read
},
3981 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3982 PACKET_qXfer_spu_write
},
3983 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3984 PACKET_qXfer_osdata
},
3985 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3986 PACKET_qXfer_threads
},
3987 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
3988 PACKET_qXfer_traceframe_info
},
3989 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3990 PACKET_QPassSignals
},
3991 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
3992 PACKET_QProgramSignals
},
3993 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3994 PACKET_QStartNoAckMode
},
3995 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
3996 PACKET_multiprocess_feature
},
3997 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
3998 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3999 PACKET_qXfer_siginfo_read
},
4000 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4001 PACKET_qXfer_siginfo_write
},
4002 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4003 PACKET_ConditionalTracepoints
},
4004 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4005 PACKET_ConditionalBreakpoints
},
4006 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4007 PACKET_BreakpointCommands
},
4008 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4009 PACKET_FastTracepoints
},
4010 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4011 PACKET_StaticTracepoints
},
4012 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4013 PACKET_InstallInTrace
},
4014 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4015 PACKET_DisconnectedTracing_feature
},
4016 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4018 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4020 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4021 PACKET_TracepointSource
},
4022 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4024 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4025 PACKET_EnableDisableTracepoints_feature
},
4026 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4027 PACKET_qXfer_fdpic
},
4028 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4030 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4031 PACKET_QDisableRandomization
},
4032 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4033 { "QTBuffer:size", PACKET_DISABLE
,
4034 remote_supported_packet
, PACKET_QTBuffer_size
},
4035 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4036 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4037 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4038 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4039 PACKET_qXfer_btrace
},
4040 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4041 PACKET_qXfer_btrace_conf
},
4042 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4043 PACKET_Qbtrace_conf_bts_size
},
4044 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4045 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4048 static char *remote_support_xml
;
4050 /* Register string appended to "xmlRegisters=" in qSupported query. */
4053 register_remote_support_xml (const char *xml
)
4055 #if defined(HAVE_LIBEXPAT)
4056 if (remote_support_xml
== NULL
)
4057 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4060 char *copy
= xstrdup (remote_support_xml
+ 13);
4061 char *p
= strtok (copy
, ",");
4065 if (strcmp (p
, xml
) == 0)
4072 while ((p
= strtok (NULL
, ",")) != NULL
);
4075 remote_support_xml
= reconcat (remote_support_xml
,
4076 remote_support_xml
, ",", xml
,
4083 remote_query_supported_append (char *msg
, const char *append
)
4086 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4088 return xstrdup (append
);
4092 remote_query_supported (void)
4094 struct remote_state
*rs
= get_remote_state ();
4097 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4099 /* The packet support flags are handled differently for this packet
4100 than for most others. We treat an error, a disabled packet, and
4101 an empty response identically: any features which must be reported
4102 to be used will be automatically disabled. An empty buffer
4103 accomplishes this, since that is also the representation for a list
4104 containing no features. */
4107 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4110 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4112 q
= remote_query_supported_append (q
, "multiprocess+");
4114 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4115 q
= remote_query_supported_append (q
, "swbreak+");
4116 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4117 q
= remote_query_supported_append (q
, "hwbreak+");
4119 if (remote_support_xml
)
4120 q
= remote_query_supported_append (q
, remote_support_xml
);
4122 q
= remote_query_supported_append (q
, "qRelocInsn+");
4124 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4127 do_cleanups (old_chain
);
4129 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4131 /* If an error occured, warn, but do not return - just reset the
4132 buffer to empty and go on to disable features. */
4133 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4136 warning (_("Remote failure reply: %s"), rs
->buf
);
4141 memset (seen
, 0, sizeof (seen
));
4146 enum packet_support is_supported
;
4147 char *p
, *end
, *name_end
, *value
;
4149 /* First separate out this item from the rest of the packet. If
4150 there's another item after this, we overwrite the separator
4151 (terminated strings are much easier to work with). */
4153 end
= strchr (p
, ';');
4156 end
= p
+ strlen (p
);
4166 warning (_("empty item in \"qSupported\" response"));
4171 name_end
= strchr (p
, '=');
4174 /* This is a name=value entry. */
4175 is_supported
= PACKET_ENABLE
;
4176 value
= name_end
+ 1;
4185 is_supported
= PACKET_ENABLE
;
4189 is_supported
= PACKET_DISABLE
;
4193 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4197 warning (_("unrecognized item \"%s\" "
4198 "in \"qSupported\" response"), p
);
4204 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4205 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4207 const struct protocol_feature
*feature
;
4210 feature
= &remote_protocol_features
[i
];
4211 feature
->func (feature
, is_supported
, value
);
4216 /* If we increased the packet size, make sure to increase the global
4217 buffer size also. We delay this until after parsing the entire
4218 qSupported packet, because this is the same buffer we were
4220 if (rs
->buf_size
< rs
->explicit_packet_size
)
4222 rs
->buf_size
= rs
->explicit_packet_size
;
4223 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4226 /* Handle the defaults for unmentioned features. */
4227 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4230 const struct protocol_feature
*feature
;
4232 feature
= &remote_protocol_features
[i
];
4233 feature
->func (feature
, feature
->default_support
, NULL
);
4237 /* Remove any of the remote.c targets from target stack. Upper targets depend
4238 on it so remove them first. */
4241 remote_unpush_target (void)
4243 pop_all_targets_above (process_stratum
- 1);
4247 remote_open_1 (const char *name
, int from_tty
,
4248 struct target_ops
*target
, int extended_p
)
4250 struct remote_state
*rs
= get_remote_state ();
4253 error (_("To open a remote debug connection, you need to specify what\n"
4254 "serial device is attached to the remote system\n"
4255 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4257 /* See FIXME above. */
4258 if (!target_async_permitted
)
4259 wait_forever_enabled_p
= 1;
4261 /* If we're connected to a running target, target_preopen will kill it.
4262 Ask this question first, before target_preopen has a chance to kill
4264 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4267 && !query (_("Already connected to a remote target. Disconnect? ")))
4268 error (_("Still connected."));
4271 /* Here the possibly existing remote target gets unpushed. */
4272 target_preopen (from_tty
);
4274 /* Make sure we send the passed signals list the next time we resume. */
4275 xfree (rs
->last_pass_packet
);
4276 rs
->last_pass_packet
= NULL
;
4278 /* Make sure we send the program signals list the next time we
4280 xfree (rs
->last_program_signals_packet
);
4281 rs
->last_program_signals_packet
= NULL
;
4283 remote_fileio_reset ();
4284 reopen_exec_file ();
4287 rs
->remote_desc
= remote_serial_open (name
);
4288 if (!rs
->remote_desc
)
4289 perror_with_name (name
);
4291 if (baud_rate
!= -1)
4293 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4295 /* The requested speed could not be set. Error out to
4296 top level after closing remote_desc. Take care to
4297 set remote_desc to NULL to avoid closing remote_desc
4299 serial_close (rs
->remote_desc
);
4300 rs
->remote_desc
= NULL
;
4301 perror_with_name (name
);
4305 serial_setparity (rs
->remote_desc
, serial_parity
);
4306 serial_raw (rs
->remote_desc
);
4308 /* If there is something sitting in the buffer we might take it as a
4309 response to a command, which would be bad. */
4310 serial_flush_input (rs
->remote_desc
);
4314 puts_filtered ("Remote debugging using ");
4315 puts_filtered (name
);
4316 puts_filtered ("\n");
4318 push_target (target
); /* Switch to using remote target now. */
4320 /* Register extra event sources in the event loop. */
4321 remote_async_inferior_event_token
4322 = create_async_event_handler (remote_async_inferior_event_handler
,
4324 rs
->notif_state
= remote_notif_state_allocate ();
4326 /* Reset the target state; these things will be queried either by
4327 remote_query_supported or as they are needed. */
4328 reset_all_packet_configs_support ();
4329 rs
->cached_wait_status
= 0;
4330 rs
->explicit_packet_size
= 0;
4332 rs
->extended
= extended_p
;
4333 rs
->waiting_for_stop_reply
= 0;
4334 rs
->ctrlc_pending_p
= 0;
4336 rs
->general_thread
= not_sent_ptid
;
4337 rs
->continue_thread
= not_sent_ptid
;
4338 rs
->remote_traceframe_number
= -1;
4340 /* Probe for ability to use "ThreadInfo" query, as required. */
4341 rs
->use_threadinfo_query
= 1;
4342 rs
->use_threadextra_query
= 1;
4344 if (target_async_permitted
)
4346 /* With this target we start out by owning the terminal. */
4347 remote_async_terminal_ours_p
= 1;
4349 /* FIXME: cagney/1999-09-23: During the initial connection it is
4350 assumed that the target is already ready and able to respond to
4351 requests. Unfortunately remote_start_remote() eventually calls
4352 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4353 around this. Eventually a mechanism that allows
4354 wait_for_inferior() to expect/get timeouts will be
4356 wait_forever_enabled_p
= 0;
4359 /* First delete any symbols previously loaded from shared libraries. */
4360 no_shared_libraries (NULL
, 0);
4363 init_thread_list ();
4365 /* Start the remote connection. If error() or QUIT, discard this
4366 target (we'd otherwise be in an inconsistent state) and then
4367 propogate the error on up the exception chain. This ensures that
4368 the caller doesn't stumble along blindly assuming that the
4369 function succeeded. The CLI doesn't have this problem but other
4370 UI's, such as MI do.
4372 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4373 this function should return an error indication letting the
4374 caller restore the previous state. Unfortunately the command
4375 ``target remote'' is directly wired to this function making that
4376 impossible. On a positive note, the CLI side of this problem has
4377 been fixed - the function set_cmd_context() makes it possible for
4378 all the ``target ....'' commands to share a common callback
4379 function. See cli-dump.c. */
4384 remote_start_remote (from_tty
, target
, extended_p
);
4386 CATCH (ex
, RETURN_MASK_ALL
)
4388 /* Pop the partially set up target - unless something else did
4389 already before throwing the exception. */
4390 if (rs
->remote_desc
!= NULL
)
4391 remote_unpush_target ();
4392 if (target_async_permitted
)
4393 wait_forever_enabled_p
= 1;
4394 throw_exception (ex
);
4399 remote_btrace_reset ();
4401 if (target_async_permitted
)
4402 wait_forever_enabled_p
= 1;
4405 /* This takes a program previously attached to and detaches it. After
4406 this is done, GDB can be used to debug some other program. We
4407 better not have left any breakpoints in the target program or it'll
4408 die when it hits one. */
4411 remote_detach_1 (const char *args
, int from_tty
, int extended
)
4413 int pid
= ptid_get_pid (inferior_ptid
);
4414 struct remote_state
*rs
= get_remote_state ();
4417 error (_("Argument given to \"detach\" when remotely debugging."));
4419 if (!target_has_execution
)
4420 error (_("No process to detach from."));
4424 char *exec_file
= get_exec_file (0);
4425 if (exec_file
== NULL
)
4427 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4428 target_pid_to_str (pid_to_ptid (pid
)));
4429 gdb_flush (gdb_stdout
);
4432 /* Tell the remote target to detach. */
4433 if (remote_multi_process_p (rs
))
4434 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4436 strcpy (rs
->buf
, "D");
4439 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4441 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4443 else if (rs
->buf
[0] == '\0')
4444 error (_("Remote doesn't know how to detach"));
4446 error (_("Can't detach process."));
4448 if (from_tty
&& !extended
)
4449 puts_filtered (_("Ending remote debugging.\n"));
4451 target_mourn_inferior ();
4455 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4457 remote_detach_1 (args
, from_tty
, 0);
4461 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4463 remote_detach_1 (args
, from_tty
, 1);
4466 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4469 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
4472 error (_("Argument given to \"disconnect\" when remotely debugging."));
4474 /* Make sure we unpush even the extended remote targets; mourn
4475 won't do it. So call remote_mourn directly instead of
4476 target_mourn_inferior. */
4477 remote_mourn (target
);
4480 puts_filtered ("Ending remote debugging.\n");
4483 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4484 be chatty about it. */
4487 extended_remote_attach (struct target_ops
*target
, const char *args
,
4490 struct remote_state
*rs
= get_remote_state ();
4492 char *wait_status
= NULL
;
4494 pid
= parse_pid_to_attach (args
);
4496 /* Remote PID can be freely equal to getpid, do not check it here the same
4497 way as in other targets. */
4499 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
4500 error (_("This target does not support attaching to a process"));
4504 char *exec_file
= get_exec_file (0);
4507 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4508 target_pid_to_str (pid_to_ptid (pid
)));
4510 printf_unfiltered (_("Attaching to %s\n"),
4511 target_pid_to_str (pid_to_ptid (pid
)));
4513 gdb_flush (gdb_stdout
);
4516 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4518 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4520 switch (packet_ok (rs
->buf
,
4521 &remote_protocol_packets
[PACKET_vAttach
]))
4526 /* Save the reply for later. */
4527 wait_status
= alloca (strlen (rs
->buf
) + 1);
4528 strcpy (wait_status
, rs
->buf
);
4530 else if (strcmp (rs
->buf
, "OK") != 0)
4531 error (_("Attaching to %s failed with: %s"),
4532 target_pid_to_str (pid_to_ptid (pid
)),
4535 case PACKET_UNKNOWN
:
4536 error (_("This target does not support attaching to a process"));
4538 error (_("Attaching to %s failed"),
4539 target_pid_to_str (pid_to_ptid (pid
)));
4542 set_current_inferior (remote_add_inferior (0, pid
, 1));
4544 inferior_ptid
= pid_to_ptid (pid
);
4548 struct thread_info
*thread
;
4550 /* Get list of threads. */
4551 remote_update_thread_list (target
);
4553 thread
= first_thread_of_process (pid
);
4555 inferior_ptid
= thread
->ptid
;
4557 inferior_ptid
= pid_to_ptid (pid
);
4559 /* Invalidate our notion of the remote current thread. */
4560 record_currthread (rs
, minus_one_ptid
);
4564 /* Now, if we have thread information, update inferior_ptid. */
4565 inferior_ptid
= remote_current_thread (inferior_ptid
);
4567 /* Add the main thread to the thread list. */
4568 add_thread_silent (inferior_ptid
);
4571 /* Next, if the target can specify a description, read it. We do
4572 this before anything involving memory or registers. */
4573 target_find_description ();
4577 /* Use the previously fetched status. */
4578 gdb_assert (wait_status
!= NULL
);
4580 if (target_can_async_p ())
4582 struct notif_event
*reply
4583 = remote_notif_parse (¬if_client_stop
, wait_status
);
4585 push_stop_reply ((struct stop_reply
*) reply
);
4591 gdb_assert (wait_status
!= NULL
);
4592 strcpy (rs
->buf
, wait_status
);
4593 rs
->cached_wait_status
= 1;
4597 gdb_assert (wait_status
== NULL
);
4600 /* Implementation of the to_post_attach method. */
4603 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
4605 /* In certain cases GDB might not have had the chance to start
4606 symbol lookup up until now. This could happen if the debugged
4607 binary is not using shared libraries, the vsyscall page is not
4608 present (on Linux) and the binary itself hadn't changed since the
4609 debugging process was started. */
4610 if (symfile_objfile
!= NULL
)
4611 remote_check_symbols();
4615 /* Check for the availability of vCont. This function should also check
4619 remote_vcont_probe (struct remote_state
*rs
)
4623 strcpy (rs
->buf
, "vCont?");
4625 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4628 /* Make sure that the features we assume are supported. */
4629 if (startswith (buf
, "vCont"))
4632 int support_s
, support_S
, support_c
, support_C
;
4638 rs
->supports_vCont
.t
= 0;
4639 rs
->supports_vCont
.r
= 0;
4640 while (p
&& *p
== ';')
4643 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4645 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4647 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4649 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4651 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4652 rs
->supports_vCont
.t
= 1;
4653 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4654 rs
->supports_vCont
.r
= 1;
4656 p
= strchr (p
, ';');
4659 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4660 BUF will make packet_ok disable the packet. */
4661 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4665 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4668 /* Helper function for building "vCont" resumptions. Write a
4669 resumption to P. ENDP points to one-passed-the-end of the buffer
4670 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4671 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4672 resumed thread should be single-stepped and/or signalled. If PTID
4673 equals minus_one_ptid, then all threads are resumed; if PTID
4674 represents a process, then all threads of the process are resumed;
4675 the thread to be stepped and/or signalled is given in the global
4679 append_resumption (char *p
, char *endp
,
4680 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4682 struct remote_state
*rs
= get_remote_state ();
4684 if (step
&& siggnal
!= GDB_SIGNAL_0
)
4685 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4687 /* GDB is willing to range step. */
4688 && use_range_stepping
4689 /* Target supports range stepping. */
4690 && rs
->supports_vCont
.r
4691 /* We don't currently support range stepping multiple
4692 threads with a wildcard (though the protocol allows it,
4693 so stubs shouldn't make an active effort to forbid
4695 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4697 struct thread_info
*tp
;
4699 if (ptid_equal (ptid
, minus_one_ptid
))
4701 /* If we don't know about the target thread's tid, then
4702 we're resuming magic_null_ptid (see caller). */
4703 tp
= find_thread_ptid (magic_null_ptid
);
4706 tp
= find_thread_ptid (ptid
);
4707 gdb_assert (tp
!= NULL
);
4709 if (tp
->control
.may_range_step
)
4711 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4713 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
4714 phex_nz (tp
->control
.step_range_start
,
4716 phex_nz (tp
->control
.step_range_end
,
4720 p
+= xsnprintf (p
, endp
- p
, ";s");
4723 p
+= xsnprintf (p
, endp
- p
, ";s");
4724 else if (siggnal
!= GDB_SIGNAL_0
)
4725 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4727 p
+= xsnprintf (p
, endp
- p
, ";c");
4729 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4733 /* All (-1) threads of process. */
4734 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
4736 p
+= xsnprintf (p
, endp
- p
, ":");
4737 p
= write_ptid (p
, endp
, nptid
);
4739 else if (!ptid_equal (ptid
, minus_one_ptid
))
4741 p
+= xsnprintf (p
, endp
- p
, ":");
4742 p
= write_ptid (p
, endp
, ptid
);
4748 /* Append a vCont continue-with-signal action for threads that have a
4749 non-zero stop signal. */
4752 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
4754 struct thread_info
*thread
;
4756 ALL_NON_EXITED_THREADS (thread
)
4757 if (ptid_match (thread
->ptid
, ptid
)
4758 && !ptid_equal (inferior_ptid
, thread
->ptid
)
4759 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
4761 p
= append_resumption (p
, endp
, thread
->ptid
,
4762 0, thread
->suspend
.stop_signal
);
4763 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4769 /* Resume the remote inferior by using a "vCont" packet. The thread
4770 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4771 resumed thread should be single-stepped and/or signalled. If PTID
4772 equals minus_one_ptid, then all threads are resumed; the thread to
4773 be stepped and/or signalled is given in the global INFERIOR_PTID.
4774 This function returns non-zero iff it resumes the inferior.
4776 This function issues a strict subset of all possible vCont commands at the
4780 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4782 struct remote_state
*rs
= get_remote_state ();
4786 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
4787 remote_vcont_probe (rs
);
4789 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
4793 endp
= rs
->buf
+ get_remote_packet_size ();
4795 /* If we could generate a wider range of packets, we'd have to worry
4796 about overflowing BUF. Should there be a generic
4797 "multi-part-packet" packet? */
4799 p
+= xsnprintf (p
, endp
- p
, "vCont");
4801 if (ptid_equal (ptid
, magic_null_ptid
))
4803 /* MAGIC_NULL_PTID means that we don't have any active threads,
4804 so we don't have any TID numbers the inferior will
4805 understand. Make sure to only send forms that do not specify
4807 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4809 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4811 /* Resume all threads (of all processes, or of a single
4812 process), with preference for INFERIOR_PTID. This assumes
4813 inferior_ptid belongs to the set of all threads we are about
4815 if (step
|| siggnal
!= GDB_SIGNAL_0
)
4817 /* Step inferior_ptid, with or without signal. */
4818 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4821 /* Also pass down any pending signaled resumption for other
4822 threads not the current. */
4823 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
4825 /* And continue others without a signal. */
4826 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
4830 /* Scheduler locking; resume only PTID. */
4831 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4834 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4839 /* In non-stop, the stub replies to vCont with "OK". The stop
4840 reply will be reported asynchronously by means of a `%Stop'
4842 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4843 if (strcmp (rs
->buf
, "OK") != 0)
4844 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4850 /* Tell the remote machine to resume. */
4853 remote_resume (struct target_ops
*ops
,
4854 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4856 struct remote_state
*rs
= get_remote_state ();
4859 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
4860 (explained in remote-notif.c:handle_notification) so
4861 remote_notif_process is not called. We need find a place where
4862 it is safe to start a 'vNotif' sequence. It is good to do it
4863 before resuming inferior, because inferior was stopped and no RSP
4864 traffic at that moment. */
4866 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
4868 rs
->last_sent_signal
= siggnal
;
4869 rs
->last_sent_step
= step
;
4871 /* The vCont packet doesn't need to specify threads via Hc. */
4872 /* No reverse support (yet) for vCont. */
4873 if (execution_direction
!= EXEC_REVERSE
)
4874 if (remote_vcont_resume (ptid
, step
, siggnal
))
4877 /* All other supported resume packets do use Hc, so set the continue
4879 if (ptid_equal (ptid
, minus_one_ptid
))
4880 set_continue_thread (any_thread_ptid
);
4882 set_continue_thread (ptid
);
4885 if (execution_direction
== EXEC_REVERSE
)
4887 /* We don't pass signals to the target in reverse exec mode. */
4888 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
4889 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4892 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
4893 error (_("Remote reverse-step not supported."));
4894 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
4895 error (_("Remote reverse-continue not supported."));
4897 strcpy (buf
, step
? "bs" : "bc");
4899 else if (siggnal
!= GDB_SIGNAL_0
)
4901 buf
[0] = step
? 'S' : 'C';
4902 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4903 buf
[2] = tohex (((int) siggnal
) & 0xf);
4907 strcpy (buf
, step
? "s" : "c");
4912 /* We are about to start executing the inferior, let's register it
4913 with the event loop. NOTE: this is the one place where all the
4914 execution commands end up. We could alternatively do this in each
4915 of the execution commands in infcmd.c. */
4916 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4917 into infcmd.c in order to allow inferior function calls to work
4918 NOT asynchronously. */
4919 if (target_can_async_p ())
4922 /* We've just told the target to resume. The remote server will
4923 wait for the inferior to stop, and then send a stop reply. In
4924 the mean time, we can't start another command/query ourselves
4925 because the stub wouldn't be ready to process it. This applies
4926 only to the base all-stop protocol, however. In non-stop (which
4927 only supports vCont), the stub replies with an "OK", and is
4928 immediate able to process further serial input. */
4930 rs
->waiting_for_stop_reply
= 1;
4934 /* Set up the signal handler for SIGINT, while the target is
4935 executing, ovewriting the 'regular' SIGINT signal handler. */
4937 async_initialize_sigint_signal_handler (void)
4939 signal (SIGINT
, async_handle_remote_sigint
);
4942 /* Signal handler for SIGINT, while the target is executing. */
4944 async_handle_remote_sigint (int sig
)
4946 signal (sig
, async_handle_remote_sigint_twice
);
4947 /* Note we need to go through gdb_call_async_signal_handler in order
4948 to wake up the event loop on Windows. */
4949 gdb_call_async_signal_handler (async_sigint_remote_token
, 0);
4952 /* Signal handler for SIGINT, installed after SIGINT has already been
4953 sent once. It will take effect the second time that the user sends
4956 async_handle_remote_sigint_twice (int sig
)
4958 signal (sig
, async_handle_remote_sigint
);
4959 /* See note in async_handle_remote_sigint. */
4960 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 0);
4963 /* Perform the real interruption of the target execution, in response
4966 async_remote_interrupt (gdb_client_data arg
)
4969 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
4971 target_stop (inferior_ptid
);
4974 /* Perform interrupt, if the first attempt did not succeed. Just give
4975 up on the target alltogether. */
4977 async_remote_interrupt_twice (gdb_client_data arg
)
4980 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
4985 /* Reinstall the usual SIGINT handlers, after the target has
4988 async_cleanup_sigint_signal_handler (void *dummy
)
4990 signal (SIGINT
, handle_sigint
);
4993 /* Send ^C to target to halt it. Target will respond, and send us a
4995 static void (*ofunc
) (int);
4997 /* The command line interface's stop routine. This function is installed
4998 as a signal handler for SIGINT. The first time a user requests a
4999 stop, we call remote_stop to send a break or ^C. If there is no
5000 response from the target (it didn't stop when the user requested it),
5001 we ask the user if he'd like to detach from the target. */
5003 sync_remote_interrupt (int signo
)
5005 /* If this doesn't work, try more severe steps. */
5006 signal (signo
, sync_remote_interrupt_twice
);
5008 gdb_call_async_signal_handler (async_sigint_remote_token
, 1);
5011 /* The user typed ^C twice. */
5014 sync_remote_interrupt_twice (int signo
)
5016 signal (signo
, ofunc
);
5017 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 1);
5018 signal (signo
, sync_remote_interrupt
);
5021 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5022 thread, all threads of a remote process, or all threads of all
5026 remote_stop_ns (ptid_t ptid
)
5028 struct remote_state
*rs
= get_remote_state ();
5030 char *endp
= rs
->buf
+ get_remote_packet_size ();
5032 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5033 remote_vcont_probe (rs
);
5035 if (!rs
->supports_vCont
.t
)
5036 error (_("Remote server does not support stopping threads"));
5038 if (ptid_equal (ptid
, minus_one_ptid
)
5039 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5040 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5045 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5047 if (ptid_is_pid (ptid
))
5048 /* All (-1) threads of process. */
5049 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5052 /* Small optimization: if we already have a stop reply for
5053 this thread, no use in telling the stub we want this
5055 if (peek_stop_reply (ptid
))
5061 write_ptid (p
, endp
, nptid
);
5064 /* In non-stop, we get an immediate OK reply. The stop reply will
5065 come in asynchronously by notification. */
5067 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5068 if (strcmp (rs
->buf
, "OK") != 0)
5069 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5072 /* All-stop version of target_stop. Sends a break or a ^C to stop the
5073 remote target. It is undefined which thread of which process
5074 reports the stop. */
5077 remote_stop_as (ptid_t ptid
)
5079 struct remote_state
*rs
= get_remote_state ();
5081 rs
->ctrlc_pending_p
= 1;
5083 /* If the inferior is stopped already, but the core didn't know
5084 about it yet, just ignore the request. The cached wait status
5085 will be collected in remote_wait. */
5086 if (rs
->cached_wait_status
)
5089 /* Send interrupt_sequence to remote target. */
5090 send_interrupt_sequence ();
5093 /* This is the generic stop called via the target vector. When a target
5094 interrupt is requested, either by the command line or the GUI, we
5095 will eventually end up here. */
5098 remote_stop (struct target_ops
*self
, ptid_t ptid
)
5101 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5104 remote_stop_ns (ptid
);
5106 remote_stop_as (ptid
);
5109 /* Ask the user what to do when an interrupt is received. */
5112 interrupt_query (void)
5114 target_terminal_ours ();
5116 if (target_is_async_p ())
5118 signal (SIGINT
, handle_sigint
);
5123 if (query (_("Interrupted while waiting for the program.\n\
5124 Give up (and stop debugging it)? ")))
5126 remote_unpush_target ();
5131 target_terminal_inferior ();
5134 /* Enable/disable target terminal ownership. Most targets can use
5135 terminal groups to control terminal ownership. Remote targets are
5136 different in that explicit transfer of ownership to/from GDB/target
5140 remote_terminal_inferior (struct target_ops
*self
)
5142 if (!target_async_permitted
)
5143 /* Nothing to do. */
5146 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5147 idempotent. The event-loop GDB talking to an asynchronous target
5148 with a synchronous command calls this function from both
5149 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5150 transfer the terminal to the target when it shouldn't this guard
5152 if (!remote_async_terminal_ours_p
)
5154 delete_file_handler (input_fd
);
5155 remote_async_terminal_ours_p
= 0;
5156 async_initialize_sigint_signal_handler ();
5157 /* NOTE: At this point we could also register our selves as the
5158 recipient of all input. Any characters typed could then be
5159 passed on down to the target. */
5163 remote_terminal_ours (struct target_ops
*self
)
5165 if (!target_async_permitted
)
5166 /* Nothing to do. */
5169 /* See FIXME in remote_terminal_inferior. */
5170 if (remote_async_terminal_ours_p
)
5172 async_cleanup_sigint_signal_handler (NULL
);
5173 add_file_handler (input_fd
, stdin_event_handler
, 0);
5174 remote_async_terminal_ours_p
= 1;
5178 remote_console_output (char *msg
)
5182 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5185 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5189 fputs_unfiltered (tb
, gdb_stdtarg
);
5191 gdb_flush (gdb_stdtarg
);
5194 typedef struct cached_reg
5197 gdb_byte data
[MAX_REGISTER_SIZE
];
5200 DEF_VEC_O(cached_reg_t
);
5202 typedef struct stop_reply
5204 struct notif_event base
;
5206 /* The identifier of the thread about this event */
5209 /* The remote state this event is associated with. When the remote
5210 connection, represented by a remote_state object, is closed,
5211 all the associated stop_reply events should be released. */
5212 struct remote_state
*rs
;
5214 struct target_waitstatus ws
;
5216 /* Expedited registers. This makes remote debugging a bit more
5217 efficient for those targets that provide critical registers as
5218 part of their normal status mechanism (as another roundtrip to
5219 fetch them is avoided). */
5220 VEC(cached_reg_t
) *regcache
;
5222 enum target_stop_reason stop_reason
;
5224 CORE_ADDR watch_data_address
;
5229 DECLARE_QUEUE_P (stop_reply_p
);
5230 DEFINE_QUEUE_P (stop_reply_p
);
5231 /* The list of already fetched and acknowledged stop events. This
5232 queue is used for notification Stop, and other notifications
5233 don't need queue for their events, because the notification events
5234 of Stop can't be consumed immediately, so that events should be
5235 queued first, and be consumed by remote_wait_{ns,as} one per
5236 time. Other notifications can consume their events immediately,
5237 so queue is not needed for them. */
5238 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5241 stop_reply_xfree (struct stop_reply
*r
)
5243 notif_event_xfree ((struct notif_event
*) r
);
5247 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5248 struct notif_event
*event
)
5250 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5254 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5255 struct notif_event
*event
)
5257 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5260 putpkt ((char *) self
->ack_command
);
5262 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5263 /* We got an unknown stop reply. */
5264 error (_("Unknown stop reply"));
5266 push_stop_reply (stop_reply
);
5270 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5272 /* We can't get pending events in remote_notif_process for
5273 notification stop, and we have to do this in remote_wait_ns
5274 instead. If we fetch all queued events from stub, remote stub
5275 may exit and we have no chance to process them back in
5277 mark_async_event_handler (remote_async_inferior_event_token
);
5282 stop_reply_dtr (struct notif_event
*event
)
5284 struct stop_reply
*r
= (struct stop_reply
*) event
;
5286 VEC_free (cached_reg_t
, r
->regcache
);
5289 static struct notif_event
*
5290 remote_notif_stop_alloc_reply (void)
5292 struct notif_event
*r
5293 = (struct notif_event
*) XNEW (struct stop_reply
);
5295 r
->dtr
= stop_reply_dtr
;
5300 /* A client of notification Stop. */
5302 struct notif_client notif_client_stop
=
5306 remote_notif_stop_parse
,
5307 remote_notif_stop_ack
,
5308 remote_notif_stop_can_get_pending_events
,
5309 remote_notif_stop_alloc_reply
,
5313 /* A parameter to pass data in and out. */
5315 struct queue_iter_param
5318 struct stop_reply
*output
;
5321 /* Remove stop replies in the queue if its pid is equal to the given
5325 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
5326 QUEUE_ITER (stop_reply_p
) *iter
,
5330 struct queue_iter_param
*param
= data
;
5331 struct inferior
*inf
= param
->input
;
5333 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
5335 stop_reply_xfree (event
);
5336 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5342 /* Discard all pending stop replies of inferior INF. */
5345 discard_pending_stop_replies (struct inferior
*inf
)
5348 struct queue_iter_param param
;
5349 struct stop_reply
*reply
;
5350 struct remote_state
*rs
= get_remote_state ();
5351 struct remote_notif_state
*rns
= rs
->notif_state
;
5353 /* This function can be notified when an inferior exists. When the
5354 target is not remote, the notification state is NULL. */
5355 if (rs
->remote_desc
== NULL
)
5358 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
5360 /* Discard the in-flight notification. */
5361 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
5363 stop_reply_xfree (reply
);
5364 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
5368 param
.output
= NULL
;
5369 /* Discard the stop replies we have already pulled with
5371 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5372 remove_stop_reply_for_inferior
, ¶m
);
5375 /* If its remote state is equal to the given remote state,
5376 remove EVENT from the stop reply queue. */
5379 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
5380 QUEUE_ITER (stop_reply_p
) *iter
,
5384 struct queue_iter_param
*param
= data
;
5385 struct remote_state
*rs
= param
->input
;
5387 if (event
->rs
== rs
)
5389 stop_reply_xfree (event
);
5390 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5396 /* Discard the stop replies for RS in stop_reply_queue. */
5399 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
5401 struct queue_iter_param param
;
5404 param
.output
= NULL
;
5405 /* Discard the stop replies we have already pulled with
5407 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5408 remove_stop_reply_of_remote_state
, ¶m
);
5411 /* A parameter to pass data in and out. */
5414 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5415 QUEUE_ITER (stop_reply_p
) *iter
,
5419 struct queue_iter_param
*param
= data
;
5420 ptid_t
*ptid
= param
->input
;
5422 if (ptid_match (event
->ptid
, *ptid
))
5424 param
->output
= event
;
5425 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5432 /* Remove the first reply in 'stop_reply_queue' which matches
5435 static struct stop_reply
*
5436 remote_notif_remove_queued_reply (ptid_t ptid
)
5438 struct queue_iter_param param
;
5440 param
.input
= &ptid
;
5441 param
.output
= NULL
;
5443 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5444 remote_notif_remove_once_on_match
, ¶m
);
5446 fprintf_unfiltered (gdb_stdlog
,
5447 "notif: discard queued event: 'Stop' in %s\n",
5448 target_pid_to_str (ptid
));
5450 return param
.output
;
5453 /* Look for a queued stop reply belonging to PTID. If one is found,
5454 remove it from the queue, and return it. Returns NULL if none is
5455 found. If there are still queued events left to process, tell the
5456 event loop to get back to target_wait soon. */
5458 static struct stop_reply
*
5459 queued_stop_reply (ptid_t ptid
)
5461 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
5463 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5464 /* There's still at least an event left. */
5465 mark_async_event_handler (remote_async_inferior_event_token
);
5470 /* Push a fully parsed stop reply in the stop reply queue. Since we
5471 know that we now have at least one queued event left to pass to the
5472 core side, tell the event loop to get back to target_wait soon. */
5475 push_stop_reply (struct stop_reply
*new_event
)
5477 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
5480 fprintf_unfiltered (gdb_stdlog
,
5481 "notif: push 'Stop' %s to queue %d\n",
5482 target_pid_to_str (new_event
->ptid
),
5483 QUEUE_length (stop_reply_p
,
5486 mark_async_event_handler (remote_async_inferior_event_token
);
5490 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
5491 QUEUE_ITER (stop_reply_p
) *iter
,
5492 struct stop_reply
*event
,
5495 ptid_t
*ptid
= data
;
5497 return !(ptid_equal (*ptid
, event
->ptid
)
5498 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5501 /* Returns true if we have a stop reply for PTID. */
5504 peek_stop_reply (ptid_t ptid
)
5506 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5507 stop_reply_match_ptid_and_ws
, &ptid
);
5510 /* Skip PACKET until the next semi-colon (or end of string). */
5513 skip_to_semicolon (char *p
)
5515 while (*p
!= '\0' && *p
!= ';')
5520 /* Parse the stop reply in BUF. Either the function succeeds, and the
5521 result is stored in EVENT, or throws an error. */
5524 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5526 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5530 event
->ptid
= null_ptid
;
5531 event
->rs
= get_remote_state ();
5532 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5533 event
->ws
.value
.integer
= 0;
5534 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5535 event
->regcache
= NULL
;
5540 case 'T': /* Status with PC, SP, FP, ... */
5541 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5542 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5544 n... = register number
5545 r... = register contents
5548 p
= &buf
[3]; /* after Txx */
5554 p1
= strchr (p
, ':');
5556 error (_("Malformed packet(a) (missing colon): %s\n\
5560 error (_("Malformed packet(a) (missing register number): %s\n\
5564 /* Some "registers" are actually extended stop information.
5565 Note if you're adding a new entry here: GDB 7.9 and
5566 earlier assume that all register "numbers" that start
5567 with an hex digit are real register numbers. Make sure
5568 the server only sends such a packet if it knows the
5569 client understands it. */
5571 if (strncmp (p
, "thread", p1
- p
) == 0)
5572 event
->ptid
= read_ptid (++p1
, &p
);
5573 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5574 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5575 || (strncmp (p
, "awatch", p1
- p
) == 0))
5577 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
5578 p
= unpack_varlen_hex (++p1
, &addr
);
5579 event
->watch_data_address
= (CORE_ADDR
) addr
;
5581 else if (strncmp (p
, "swbreak", p1
- p
) == 0)
5583 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
5585 /* Make sure the stub doesn't forget to indicate support
5587 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
5588 error (_("Unexpected swbreak stop reason"));
5590 /* The value part is documented as "must be empty",
5591 though we ignore it, in case we ever decide to make
5592 use of it in a backward compatible way. */
5593 p
= skip_to_semicolon (p1
+ 1);
5595 else if (strncmp (p
, "hwbreak", p1
- p
) == 0)
5597 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
5599 /* Make sure the stub doesn't forget to indicate support
5601 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
5602 error (_("Unexpected hwbreak stop reason"));
5605 p
= skip_to_semicolon (p1
+ 1);
5607 else if (strncmp (p
, "library", p1
- p
) == 0)
5609 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5610 p
= skip_to_semicolon (p1
+ 1);
5612 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5614 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5615 /* p1 will indicate "begin" or "end", but it makes
5616 no difference for now, so ignore it. */
5617 p
= skip_to_semicolon (p1
+ 1);
5619 else if (strncmp (p
, "core", p1
- p
) == 0)
5623 p
= unpack_varlen_hex (++p1
, &c
);
5631 /* Maybe a real ``P'' register number. */
5632 p_temp
= unpack_varlen_hex (p
, &pnum
);
5633 /* If the first invalid character is the colon, we got a
5634 register number. Otherwise, it's an unknown stop
5638 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5639 cached_reg_t cached_reg
;
5642 error (_("Remote sent bad register number %s: %s\n\
5644 hex_string (pnum
), p
, buf
);
5646 cached_reg
.num
= reg
->regnum
;
5649 fieldsize
= hex2bin (p
, cached_reg
.data
,
5650 register_size (target_gdbarch (),
5653 if (fieldsize
< register_size (target_gdbarch (),
5655 warning (_("Remote reply is too short: %s"), buf
);
5657 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5661 /* Not a number. Silently skip unknown optional
5663 p
= skip_to_semicolon (p1
+ 1);
5668 error (_("Remote register badly formatted: %s\nhere: %s"),
5673 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5677 case 'S': /* Old style status, just signal only. */
5681 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5682 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
5683 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
5684 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
5686 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
5689 case 'W': /* Target exited. */
5696 /* GDB used to accept only 2 hex chars here. Stubs should
5697 only send more if they detect GDB supports multi-process
5699 p
= unpack_varlen_hex (&buf
[1], &value
);
5703 /* The remote process exited. */
5704 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5705 event
->ws
.value
.integer
= value
;
5709 /* The remote process exited with a signal. */
5710 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5711 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
5712 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
5714 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
5717 /* If no process is specified, assume inferior_ptid. */
5718 pid
= ptid_get_pid (inferior_ptid
);
5727 else if (startswith (p
, "process:"))
5731 p
+= sizeof ("process:") - 1;
5732 unpack_varlen_hex (p
, &upid
);
5736 error (_("unknown stop reply packet: %s"), buf
);
5739 error (_("unknown stop reply packet: %s"), buf
);
5740 event
->ptid
= pid_to_ptid (pid
);
5745 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5746 error (_("No process or thread specified in stop reply: %s"), buf
);
5749 /* When the stub wants to tell GDB about a new notification reply, it
5750 sends a notification (%Stop, for example). Those can come it at
5751 any time, hence, we have to make sure that any pending
5752 putpkt/getpkt sequence we're making is finished, before querying
5753 the stub for more events with the corresponding ack command
5754 (vStopped, for example). E.g., if we started a vStopped sequence
5755 immediately upon receiving the notification, something like this
5763 1.6) <-- (registers reply to step #1.3)
5765 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5768 To solve this, whenever we parse a %Stop notification successfully,
5769 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5770 doing whatever we were doing:
5776 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5777 2.5) <-- (registers reply to step #2.3)
5779 Eventualy after step #2.5, we return to the event loop, which
5780 notices there's an event on the
5781 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5782 associated callback --- the function below. At this point, we're
5783 always safe to start a vStopped sequence. :
5786 2.7) <-- T05 thread:2
5792 remote_notif_get_pending_events (struct notif_client
*nc
)
5794 struct remote_state
*rs
= get_remote_state ();
5796 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
5799 fprintf_unfiltered (gdb_stdlog
,
5800 "notif: process: '%s' ack pending event\n",
5804 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
5805 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
5809 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5810 if (strcmp (rs
->buf
, "OK") == 0)
5813 remote_notif_ack (nc
, rs
->buf
);
5819 fprintf_unfiltered (gdb_stdlog
,
5820 "notif: process: '%s' no pending reply\n",
5825 /* Called when it is decided that STOP_REPLY holds the info of the
5826 event that is to be returned to the core. This function always
5827 destroys STOP_REPLY. */
5830 process_stop_reply (struct stop_reply
*stop_reply
,
5831 struct target_waitstatus
*status
)
5835 *status
= stop_reply
->ws
;
5836 ptid
= stop_reply
->ptid
;
5838 /* If no thread/process was reported by the stub, assume the current
5840 if (ptid_equal (ptid
, null_ptid
))
5841 ptid
= inferior_ptid
;
5843 if (status
->kind
!= TARGET_WAITKIND_EXITED
5844 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5846 struct remote_state
*rs
= get_remote_state ();
5848 /* Expedited registers. */
5849 if (stop_reply
->regcache
)
5851 struct regcache
*regcache
5852 = get_thread_arch_regcache (ptid
, target_gdbarch ());
5857 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5859 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5860 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5863 rs
->stop_reason
= stop_reply
->stop_reason
;
5864 rs
->remote_watch_data_address
= stop_reply
->watch_data_address
;
5866 remote_notice_new_inferior (ptid
, 0);
5867 demand_private_info (ptid
)->core
= stop_reply
->core
;
5870 stop_reply_xfree (stop_reply
);
5874 /* The non-stop mode version of target_wait. */
5877 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5879 struct remote_state
*rs
= get_remote_state ();
5880 struct stop_reply
*stop_reply
;
5884 /* If in non-stop mode, get out of getpkt even if a
5885 notification is received. */
5887 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5888 0 /* forever */, &is_notif
);
5891 if (ret
!= -1 && !is_notif
)
5894 case 'E': /* Error of some sort. */
5895 /* We're out of sync with the target now. Did it continue
5896 or not? We can't tell which thread it was in non-stop,
5897 so just ignore this. */
5898 warning (_("Remote failure reply: %s"), rs
->buf
);
5900 case 'O': /* Console output. */
5901 remote_console_output (rs
->buf
+ 1);
5904 warning (_("Invalid remote reply: %s"), rs
->buf
);
5908 /* Acknowledge a pending stop reply that may have arrived in the
5910 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
5911 remote_notif_get_pending_events (¬if_client_stop
);
5913 /* If indeed we noticed a stop reply, we're done. */
5914 stop_reply
= queued_stop_reply (ptid
);
5915 if (stop_reply
!= NULL
)
5916 return process_stop_reply (stop_reply
, status
);
5918 /* Still no event. If we're just polling for an event, then
5919 return to the event loop. */
5920 if (options
& TARGET_WNOHANG
)
5922 status
->kind
= TARGET_WAITKIND_IGNORE
;
5923 return minus_one_ptid
;
5926 /* Otherwise do a blocking wait. */
5927 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5928 1 /* forever */, &is_notif
);
5932 /* Wait until the remote machine stops, then return, storing status in
5933 STATUS just as `wait' would. */
5936 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5938 struct remote_state
*rs
= get_remote_state ();
5939 ptid_t event_ptid
= null_ptid
;
5941 struct stop_reply
*stop_reply
;
5945 status
->kind
= TARGET_WAITKIND_IGNORE
;
5946 status
->value
.integer
= 0;
5948 stop_reply
= queued_stop_reply (ptid
);
5949 if (stop_reply
!= NULL
)
5950 return process_stop_reply (stop_reply
, status
);
5952 if (rs
->cached_wait_status
)
5953 /* Use the cached wait status, but only once. */
5954 rs
->cached_wait_status
= 0;
5960 if (!target_is_async_p ())
5962 ofunc
= signal (SIGINT
, sync_remote_interrupt
);
5963 /* If the user hit C-c before this packet, or between packets,
5964 pretend that it was hit right here. */
5965 if (check_quit_flag ())
5968 sync_remote_interrupt (SIGINT
);
5972 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5973 _never_ wait for ever -> test on target_is_async_p().
5974 However, before we do that we need to ensure that the caller
5975 knows how to take the target into/out of async mode. */
5976 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5977 wait_forever_enabled_p
, &is_notif
);
5979 if (!target_is_async_p ())
5980 signal (SIGINT
, ofunc
);
5982 /* GDB gets a notification. Return to core as this event is
5984 if (ret
!= -1 && is_notif
)
5985 return minus_one_ptid
;
5990 rs
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5992 /* We got something. */
5993 rs
->waiting_for_stop_reply
= 0;
5995 /* Assume that the target has acknowledged Ctrl-C unless we receive
5996 an 'F' or 'O' packet. */
5997 if (buf
[0] != 'F' && buf
[0] != 'O')
5998 rs
->ctrlc_pending_p
= 0;
6002 case 'E': /* Error of some sort. */
6003 /* We're out of sync with the target now. Did it continue or
6004 not? Not is more likely, so report a stop. */
6005 warning (_("Remote failure reply: %s"), buf
);
6006 status
->kind
= TARGET_WAITKIND_STOPPED
;
6007 status
->value
.sig
= GDB_SIGNAL_0
;
6009 case 'F': /* File-I/O request. */
6010 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6011 rs
->ctrlc_pending_p
= 0;
6013 case 'T': case 'S': case 'X': case 'W':
6015 struct stop_reply
*stop_reply
6016 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6019 event_ptid
= process_stop_reply (stop_reply
, status
);
6022 case 'O': /* Console output. */
6023 remote_console_output (buf
+ 1);
6025 /* The target didn't really stop; keep waiting. */
6026 rs
->waiting_for_stop_reply
= 1;
6030 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
6032 /* Zero length reply means that we tried 'S' or 'C' and the
6033 remote system doesn't support it. */
6034 target_terminal_ours_for_output ();
6036 ("Can't send signals to this remote system. %s not sent.\n",
6037 gdb_signal_to_name (rs
->last_sent_signal
));
6038 rs
->last_sent_signal
= GDB_SIGNAL_0
;
6039 target_terminal_inferior ();
6041 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
6042 putpkt ((char *) buf
);
6044 /* We just told the target to resume, so a stop reply is in
6046 rs
->waiting_for_stop_reply
= 1;
6049 /* else fallthrough */
6051 warning (_("Invalid remote reply: %s"), buf
);
6053 rs
->waiting_for_stop_reply
= 1;
6057 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
6059 /* Nothing interesting happened. If we're doing a non-blocking
6060 poll, we're done. Otherwise, go back to waiting. */
6061 if (options
& TARGET_WNOHANG
)
6062 return minus_one_ptid
;
6066 else if (status
->kind
!= TARGET_WAITKIND_EXITED
6067 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6069 if (!ptid_equal (event_ptid
, null_ptid
))
6070 record_currthread (rs
, event_ptid
);
6072 event_ptid
= inferior_ptid
;
6075 /* A process exit. Invalidate our notion of current thread. */
6076 record_currthread (rs
, minus_one_ptid
);
6081 /* Wait until the remote machine stops, then return, storing status in
6082 STATUS just as `wait' would. */
6085 remote_wait (struct target_ops
*ops
,
6086 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6091 event_ptid
= remote_wait_ns (ptid
, status
, options
);
6093 event_ptid
= remote_wait_as (ptid
, status
, options
);
6095 if (target_is_async_p ())
6097 /* If there are are events left in the queue tell the event loop
6099 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6100 mark_async_event_handler (remote_async_inferior_event_token
);
6106 /* Fetch a single register using a 'p' packet. */
6109 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6111 struct remote_state
*rs
= get_remote_state ();
6113 char regp
[MAX_REGISTER_SIZE
];
6116 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
6119 if (reg
->pnum
== -1)
6124 p
+= hexnumstr (p
, reg
->pnum
);
6127 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6131 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6135 case PACKET_UNKNOWN
:
6138 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6139 gdbarch_register_name (get_regcache_arch (regcache
),
6144 /* If this register is unfetchable, tell the regcache. */
6147 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6151 /* Otherwise, parse and supply the value. */
6157 error (_("fetch_register_using_p: early buf termination"));
6159 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6162 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6166 /* Fetch the registers included in the target's 'g' packet. */
6169 send_g_packet (void)
6171 struct remote_state
*rs
= get_remote_state ();
6174 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6175 remote_send (&rs
->buf
, &rs
->buf_size
);
6177 /* We can get out of synch in various cases. If the first character
6178 in the buffer is not a hex character, assume that has happened
6179 and try to fetch another packet to read. */
6180 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6181 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6182 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6183 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6186 fprintf_unfiltered (gdb_stdlog
,
6187 "Bad register packet; fetching a new packet\n");
6188 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6191 buf_len
= strlen (rs
->buf
);
6193 /* Sanity check the received packet. */
6194 if (buf_len
% 2 != 0)
6195 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6201 process_g_packet (struct regcache
*regcache
)
6203 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6204 struct remote_state
*rs
= get_remote_state ();
6205 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6210 buf_len
= strlen (rs
->buf
);
6212 /* Further sanity checks, with knowledge of the architecture. */
6213 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6214 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6216 /* Save the size of the packet sent to us by the target. It is used
6217 as a heuristic when determining the max size of packets that the
6218 target can safely receive. */
6219 if (rsa
->actual_register_packet_size
== 0)
6220 rsa
->actual_register_packet_size
= buf_len
;
6222 /* If this is smaller than we guessed the 'g' packet would be,
6223 update our records. A 'g' reply that doesn't include a register's
6224 value implies either that the register is not available, or that
6225 the 'p' packet must be used. */
6226 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6228 rsa
->sizeof_g_packet
= buf_len
/ 2;
6230 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6232 if (rsa
->regs
[i
].pnum
== -1)
6235 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6236 rsa
->regs
[i
].in_g_packet
= 0;
6238 rsa
->regs
[i
].in_g_packet
= 1;
6242 regs
= alloca (rsa
->sizeof_g_packet
);
6244 /* Unimplemented registers read as all bits zero. */
6245 memset (regs
, 0, rsa
->sizeof_g_packet
);
6247 /* Reply describes registers byte by byte, each byte encoded as two
6248 hex characters. Suck them all up, then supply them to the
6249 register cacheing/storage mechanism. */
6252 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6254 if (p
[0] == 0 || p
[1] == 0)
6255 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6256 internal_error (__FILE__
, __LINE__
,
6257 _("unexpected end of 'g' packet reply"));
6259 if (p
[0] == 'x' && p
[1] == 'x')
6260 regs
[i
] = 0; /* 'x' */
6262 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6266 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6268 struct packet_reg
*r
= &rsa
->regs
[i
];
6272 if (r
->offset
* 2 >= strlen (rs
->buf
))
6273 /* This shouldn't happen - we adjusted in_g_packet above. */
6274 internal_error (__FILE__
, __LINE__
,
6275 _("unexpected end of 'g' packet reply"));
6276 else if (rs
->buf
[r
->offset
* 2] == 'x')
6278 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6279 /* The register isn't available, mark it as such (at
6280 the same time setting the value to zero). */
6281 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6284 regcache_raw_supply (regcache
, r
->regnum
,
6291 fetch_registers_using_g (struct regcache
*regcache
)
6294 process_g_packet (regcache
);
6297 /* Make the remote selected traceframe match GDB's selected
6301 set_remote_traceframe (void)
6304 struct remote_state
*rs
= get_remote_state ();
6306 if (rs
->remote_traceframe_number
== get_traceframe_number ())
6309 /* Avoid recursion, remote_trace_find calls us again. */
6310 rs
->remote_traceframe_number
= get_traceframe_number ();
6312 newnum
= target_trace_find (tfind_number
,
6313 get_traceframe_number (), 0, 0, NULL
);
6315 /* Should not happen. If it does, all bets are off. */
6316 if (newnum
!= get_traceframe_number ())
6317 warning (_("could not set remote traceframe"));
6321 remote_fetch_registers (struct target_ops
*ops
,
6322 struct regcache
*regcache
, int regnum
)
6324 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6327 set_remote_traceframe ();
6328 set_general_thread (inferior_ptid
);
6332 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6334 gdb_assert (reg
!= NULL
);
6336 /* If this register might be in the 'g' packet, try that first -
6337 we are likely to read more than one register. If this is the
6338 first 'g' packet, we might be overly optimistic about its
6339 contents, so fall back to 'p'. */
6340 if (reg
->in_g_packet
)
6342 fetch_registers_using_g (regcache
);
6343 if (reg
->in_g_packet
)
6347 if (fetch_register_using_p (regcache
, reg
))
6350 /* This register is not available. */
6351 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6356 fetch_registers_using_g (regcache
);
6358 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6359 if (!rsa
->regs
[i
].in_g_packet
)
6360 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6362 /* This register is not available. */
6363 regcache_raw_supply (regcache
, i
, NULL
);
6367 /* Prepare to store registers. Since we may send them all (using a
6368 'G' request), we have to read out the ones we don't want to change
6372 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
6374 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6376 gdb_byte buf
[MAX_REGISTER_SIZE
];
6378 /* Make sure the entire registers array is valid. */
6379 switch (packet_support (PACKET_P
))
6381 case PACKET_DISABLE
:
6382 case PACKET_SUPPORT_UNKNOWN
:
6383 /* Make sure all the necessary registers are cached. */
6384 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6385 if (rsa
->regs
[i
].in_g_packet
)
6386 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6393 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6394 packet was not recognized. */
6397 store_register_using_P (const struct regcache
*regcache
,
6398 struct packet_reg
*reg
)
6400 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6401 struct remote_state
*rs
= get_remote_state ();
6402 /* Try storing a single register. */
6403 char *buf
= rs
->buf
;
6404 gdb_byte regp
[MAX_REGISTER_SIZE
];
6407 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
6410 if (reg
->pnum
== -1)
6413 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6414 p
= buf
+ strlen (buf
);
6415 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6416 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6418 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6420 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6425 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6426 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6427 case PACKET_UNKNOWN
:
6430 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6434 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6435 contents of the register cache buffer. FIXME: ignores errors. */
6438 store_registers_using_G (const struct regcache
*regcache
)
6440 struct remote_state
*rs
= get_remote_state ();
6441 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6445 /* Extract all the registers in the regcache copying them into a
6450 regs
= alloca (rsa
->sizeof_g_packet
);
6451 memset (regs
, 0, rsa
->sizeof_g_packet
);
6452 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6454 struct packet_reg
*r
= &rsa
->regs
[i
];
6457 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6461 /* Command describes registers byte by byte,
6462 each byte encoded as two hex characters. */
6465 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6467 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6469 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6470 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6471 error (_("Could not write registers; remote failure reply '%s'"),
6475 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6476 of the register cache buffer. FIXME: ignores errors. */
6479 remote_store_registers (struct target_ops
*ops
,
6480 struct regcache
*regcache
, int regnum
)
6482 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6485 set_remote_traceframe ();
6486 set_general_thread (inferior_ptid
);
6490 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6492 gdb_assert (reg
!= NULL
);
6494 /* Always prefer to store registers using the 'P' packet if
6495 possible; we often change only a small number of registers.
6496 Sometimes we change a larger number; we'd need help from a
6497 higher layer to know to use 'G'. */
6498 if (store_register_using_P (regcache
, reg
))
6501 /* For now, don't complain if we have no way to write the
6502 register. GDB loses track of unavailable registers too
6503 easily. Some day, this may be an error. We don't have
6504 any way to read the register, either... */
6505 if (!reg
->in_g_packet
)
6508 store_registers_using_G (regcache
);
6512 store_registers_using_G (regcache
);
6514 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6515 if (!rsa
->regs
[i
].in_g_packet
)
6516 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6517 /* See above for why we do not issue an error here. */
6522 /* Return the number of hex digits in num. */
6525 hexnumlen (ULONGEST num
)
6529 for (i
= 0; num
!= 0; i
++)
6535 /* Set BUF to the minimum number of hex digits representing NUM. */
6538 hexnumstr (char *buf
, ULONGEST num
)
6540 int len
= hexnumlen (num
);
6542 return hexnumnstr (buf
, num
, len
);
6546 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6549 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6555 for (i
= width
- 1; i
>= 0; i
--)
6557 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6564 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6567 remote_address_masked (CORE_ADDR addr
)
6569 unsigned int address_size
= remote_address_size
;
6571 /* If "remoteaddresssize" was not set, default to target address size. */
6573 address_size
= gdbarch_addr_bit (target_gdbarch ());
6575 if (address_size
> 0
6576 && address_size
< (sizeof (ULONGEST
) * 8))
6578 /* Only create a mask when that mask can safely be constructed
6579 in a ULONGEST variable. */
6582 mask
= (mask
<< address_size
) - 1;
6588 /* Determine whether the remote target supports binary downloading.
6589 This is accomplished by sending a no-op memory write of zero length
6590 to the target at the specified address. It does not suffice to send
6591 the whole packet, since many stubs strip the eighth bit and
6592 subsequently compute a wrong checksum, which causes real havoc with
6595 NOTE: This can still lose if the serial line is not eight-bit
6596 clean. In cases like this, the user should clear "remote
6600 check_binary_download (CORE_ADDR addr
)
6602 struct remote_state
*rs
= get_remote_state ();
6604 switch (packet_support (PACKET_X
))
6606 case PACKET_DISABLE
:
6610 case PACKET_SUPPORT_UNKNOWN
:
6616 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6618 p
+= hexnumstr (p
, (ULONGEST
) 0);
6622 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6623 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6625 if (rs
->buf
[0] == '\0')
6628 fprintf_unfiltered (gdb_stdlog
,
6629 "binary downloading NOT "
6630 "supported by target\n");
6631 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6636 fprintf_unfiltered (gdb_stdlog
,
6637 "binary downloading supported by target\n");
6638 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6645 /* Write memory data directly to the remote machine.
6646 This does not inform the data cache; the data cache uses this.
6647 HEADER is the starting part of the packet.
6648 MEMADDR is the address in the remote memory space.
6649 MYADDR is the address of the buffer in our space.
6650 LEN is the number of bytes.
6651 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6652 should send data as binary ('X'), or hex-encoded ('M').
6654 The function creates packet of the form
6655 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6657 where encoding of <DATA> is termined by PACKET_FORMAT.
6659 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6662 Return the transferred status, error or OK (an
6663 'enum target_xfer_status' value). Save the number of bytes
6664 transferred in *XFERED_LEN. Only transfer a single packet. */
6666 static enum target_xfer_status
6667 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6668 const gdb_byte
*myaddr
, ULONGEST len
,
6669 ULONGEST
*xfered_len
, char packet_format
,
6672 struct remote_state
*rs
= get_remote_state ();
6682 if (packet_format
!= 'X' && packet_format
!= 'M')
6683 internal_error (__FILE__
, __LINE__
,
6684 _("remote_write_bytes_aux: bad packet format"));
6687 return TARGET_XFER_EOF
;
6689 payload_size
= get_memory_write_packet_size ();
6691 /* The packet buffer will be large enough for the payload;
6692 get_memory_packet_size ensures this. */
6695 /* Compute the size of the actual payload by subtracting out the
6696 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6698 payload_size
-= strlen ("$,:#NN");
6700 /* The comma won't be used. */
6702 header_length
= strlen (header
);
6703 payload_size
-= header_length
;
6704 payload_size
-= hexnumlen (memaddr
);
6706 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6708 strcat (rs
->buf
, header
);
6709 p
= rs
->buf
+ strlen (header
);
6711 /* Compute a best guess of the number of bytes actually transfered. */
6712 if (packet_format
== 'X')
6714 /* Best guess at number of bytes that will fit. */
6715 todo
= min (len
, payload_size
);
6717 payload_size
-= hexnumlen (todo
);
6718 todo
= min (todo
, payload_size
);
6722 /* Num bytes that will fit. */
6723 todo
= min (len
, payload_size
/ 2);
6725 payload_size
-= hexnumlen (todo
);
6726 todo
= min (todo
, payload_size
/ 2);
6730 internal_error (__FILE__
, __LINE__
,
6731 _("minimum packet size too small to write data"));
6733 /* If we already need another packet, then try to align the end
6734 of this packet to a useful boundary. */
6735 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6736 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6738 /* Append "<memaddr>". */
6739 memaddr
= remote_address_masked (memaddr
);
6740 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6747 /* Append <len>. Retain the location/size of <len>. It may need to
6748 be adjusted once the packet body has been created. */
6750 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6758 /* Append the packet body. */
6759 if (packet_format
== 'X')
6761 /* Binary mode. Send target system values byte by byte, in
6762 increasing byte addresses. Only escape certain critical
6764 payload_length
= remote_escape_output (myaddr
, todo
, (gdb_byte
*) p
,
6765 &nr_bytes
, payload_size
);
6767 /* If not all TODO bytes fit, then we'll need another packet. Make
6768 a second try to keep the end of the packet aligned. Don't do
6769 this if the packet is tiny. */
6770 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6774 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6776 if (new_nr_bytes
!= nr_bytes
)
6777 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6778 (gdb_byte
*) p
, &nr_bytes
,
6782 p
+= payload_length
;
6783 if (use_length
&& nr_bytes
< todo
)
6785 /* Escape chars have filled up the buffer prematurely,
6786 and we have actually sent fewer bytes than planned.
6787 Fix-up the length field of the packet. Use the same
6788 number of characters as before. */
6789 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6790 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6795 /* Normal mode: Send target system values byte by byte, in
6796 increasing byte addresses. Each byte is encoded as a two hex
6798 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6802 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6803 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6805 if (rs
->buf
[0] == 'E')
6806 return TARGET_XFER_E_IO
;
6808 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6809 fewer bytes than we'd planned. */
6810 *xfered_len
= (ULONGEST
) nr_bytes
;
6811 return TARGET_XFER_OK
;
6814 /* Write memory data directly to the remote machine.
6815 This does not inform the data cache; the data cache uses this.
6816 MEMADDR is the address in the remote memory space.
6817 MYADDR is the address of the buffer in our space.
6818 LEN is the number of bytes.
6820 Return the transferred status, error or OK (an
6821 'enum target_xfer_status' value). Save the number of bytes
6822 transferred in *XFERED_LEN. Only transfer a single packet. */
6824 static enum target_xfer_status
6825 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
6826 ULONGEST
*xfered_len
)
6828 char *packet_format
= 0;
6830 /* Check whether the target supports binary download. */
6831 check_binary_download (memaddr
);
6833 switch (packet_support (PACKET_X
))
6836 packet_format
= "X";
6838 case PACKET_DISABLE
:
6839 packet_format
= "M";
6841 case PACKET_SUPPORT_UNKNOWN
:
6842 internal_error (__FILE__
, __LINE__
,
6843 _("remote_write_bytes: bad internal state"));
6845 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6848 return remote_write_bytes_aux (packet_format
,
6849 memaddr
, myaddr
, len
, xfered_len
,
6850 packet_format
[0], 1);
6853 /* Read memory data directly from the remote machine.
6854 This does not use the data cache; the data cache uses this.
6855 MEMADDR is the address in the remote memory space.
6856 MYADDR is the address of the buffer in our space.
6857 LEN is the number of bytes.
6859 Return the transferred status, error or OK (an
6860 'enum target_xfer_status' value). Save the number of bytes
6861 transferred in *XFERED_LEN. */
6863 static enum target_xfer_status
6864 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len
,
6865 ULONGEST
*xfered_len
)
6867 struct remote_state
*rs
= get_remote_state ();
6868 int max_buf_size
; /* Max size of packet output buffer. */
6873 max_buf_size
= get_memory_read_packet_size ();
6874 /* The packet buffer will be large enough for the payload;
6875 get_memory_packet_size ensures this. */
6877 /* Number if bytes that will fit. */
6878 todo
= min (len
, max_buf_size
/ 2);
6880 /* Construct "m"<memaddr>","<len>". */
6881 memaddr
= remote_address_masked (memaddr
);
6884 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6886 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6889 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6890 if (rs
->buf
[0] == 'E'
6891 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6892 && rs
->buf
[3] == '\0')
6893 return TARGET_XFER_E_IO
;
6894 /* Reply describes memory byte by byte, each byte encoded as two hex
6897 i
= hex2bin (p
, myaddr
, todo
);
6898 /* Return what we have. Let higher layers handle partial reads. */
6899 *xfered_len
= (ULONGEST
) i
;
6900 return TARGET_XFER_OK
;
6903 /* Using the set of read-only target sections of remote, read live
6906 For interface/parameters/return description see target.h,
6909 static enum target_xfer_status
6910 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
6911 ULONGEST memaddr
, ULONGEST len
,
6912 ULONGEST
*xfered_len
)
6914 struct target_section
*secp
;
6915 struct target_section_table
*table
;
6917 secp
= target_section_by_addr (ops
, memaddr
);
6919 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
6920 secp
->the_bfd_section
)
6923 struct target_section
*p
;
6924 ULONGEST memend
= memaddr
+ len
;
6926 table
= target_get_section_table (ops
);
6928 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
6930 if (memaddr
>= p
->addr
)
6932 if (memend
<= p
->endaddr
)
6934 /* Entire transfer is within this section. */
6935 return remote_read_bytes_1 (memaddr
, readbuf
, len
,
6938 else if (memaddr
>= p
->endaddr
)
6940 /* This section ends before the transfer starts. */
6945 /* This section overlaps the transfer. Just do half. */
6946 len
= p
->endaddr
- memaddr
;
6947 return remote_read_bytes_1 (memaddr
, readbuf
, len
,
6954 return TARGET_XFER_EOF
;
6957 /* Similar to remote_read_bytes_1, but it reads from the remote stub
6958 first if the requested memory is unavailable in traceframe.
6959 Otherwise, fall back to remote_read_bytes_1. */
6961 static enum target_xfer_status
6962 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
6963 gdb_byte
*myaddr
, ULONGEST len
, ULONGEST
*xfered_len
)
6966 return TARGET_XFER_EOF
;
6968 if (get_traceframe_number () != -1)
6970 VEC(mem_range_s
) *available
;
6972 /* If we fail to get the set of available memory, then the
6973 target does not support querying traceframe info, and so we
6974 attempt reading from the traceframe anyway (assuming the
6975 target implements the old QTro packet then). */
6976 if (traceframe_available_memory (&available
, memaddr
, len
))
6978 struct cleanup
*old_chain
;
6980 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
6982 if (VEC_empty (mem_range_s
, available
)
6983 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
6985 enum target_xfer_status res
;
6987 /* Don't read into the traceframe's available
6989 if (!VEC_empty (mem_range_s
, available
))
6991 LONGEST oldlen
= len
;
6993 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
6994 gdb_assert (len
<= oldlen
);
6997 do_cleanups (old_chain
);
6999 /* This goes through the topmost target again. */
7000 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
7002 if (res
== TARGET_XFER_OK
)
7003 return TARGET_XFER_OK
;
7006 /* No use trying further, we know some memory starting
7007 at MEMADDR isn't available. */
7009 return TARGET_XFER_UNAVAILABLE
;
7013 /* Don't try to read more than how much is available, in
7014 case the target implements the deprecated QTro packet to
7015 cater for older GDBs (the target's knowledge of read-only
7016 sections may be outdated by now). */
7017 len
= VEC_index (mem_range_s
, available
, 0)->length
;
7019 do_cleanups (old_chain
);
7023 return remote_read_bytes_1 (memaddr
, myaddr
, len
, xfered_len
);
7028 /* Sends a packet with content determined by the printf format string
7029 FORMAT and the remaining arguments, then gets the reply. Returns
7030 whether the packet was a success, a failure, or unknown. */
7032 static enum packet_result
remote_send_printf (const char *format
, ...)
7033 ATTRIBUTE_PRINTF (1, 2);
7035 static enum packet_result
7036 remote_send_printf (const char *format
, ...)
7038 struct remote_state
*rs
= get_remote_state ();
7039 int max_size
= get_remote_packet_size ();
7042 va_start (ap
, format
);
7045 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
7046 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
7048 if (putpkt (rs
->buf
) < 0)
7049 error (_("Communication problem with target."));
7052 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7054 return packet_check_result (rs
->buf
);
7058 restore_remote_timeout (void *p
)
7060 int value
= *(int *)p
;
7062 remote_timeout
= value
;
7065 /* Flash writing can take quite some time. We'll set
7066 effectively infinite timeout for flash operations.
7067 In future, we'll need to decide on a better approach. */
7068 static const int remote_flash_timeout
= 1000;
7071 remote_flash_erase (struct target_ops
*ops
,
7072 ULONGEST address
, LONGEST length
)
7074 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
7075 int saved_remote_timeout
= remote_timeout
;
7076 enum packet_result ret
;
7077 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7078 &saved_remote_timeout
);
7080 remote_timeout
= remote_flash_timeout
;
7082 ret
= remote_send_printf ("vFlashErase:%s,%s",
7083 phex (address
, addr_size
),
7087 case PACKET_UNKNOWN
:
7088 error (_("Remote target does not support flash erase"));
7090 error (_("Error erasing flash with vFlashErase packet"));
7095 do_cleanups (back_to
);
7098 static enum target_xfer_status
7099 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
7100 ULONGEST length
, ULONGEST
*xfered_len
,
7101 const gdb_byte
*data
)
7103 int saved_remote_timeout
= remote_timeout
;
7104 enum target_xfer_status ret
;
7105 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7106 &saved_remote_timeout
);
7108 remote_timeout
= remote_flash_timeout
;
7109 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
,
7111 do_cleanups (back_to
);
7117 remote_flash_done (struct target_ops
*ops
)
7119 int saved_remote_timeout
= remote_timeout
;
7121 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7122 &saved_remote_timeout
);
7124 remote_timeout
= remote_flash_timeout
;
7125 ret
= remote_send_printf ("vFlashDone");
7126 do_cleanups (back_to
);
7130 case PACKET_UNKNOWN
:
7131 error (_("Remote target does not support vFlashDone"));
7133 error (_("Error finishing flash operation"));
7140 remote_files_info (struct target_ops
*ignore
)
7142 puts_filtered ("Debugging a target over a serial line.\n");
7145 /* Stuff for dealing with the packets which are part of this protocol.
7146 See comment at top of file for details. */
7148 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7149 error to higher layers. Called when a serial error is detected.
7150 The exception message is STRING, followed by a colon and a blank,
7151 the system error message for errno at function entry and final dot
7152 for output compatibility with throw_perror_with_name. */
7155 unpush_and_perror (const char *string
)
7157 int saved_errno
= errno
;
7159 remote_unpush_target ();
7160 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
7161 safe_strerror (saved_errno
));
7164 /* Read a single character from the remote end. */
7167 readchar (int timeout
)
7170 struct remote_state
*rs
= get_remote_state ();
7172 ch
= serial_readchar (rs
->remote_desc
, timeout
);
7177 switch ((enum serial_rc
) ch
)
7180 remote_unpush_target ();
7181 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7184 unpush_and_perror (_("Remote communication error. "
7185 "Target disconnected."));
7187 case SERIAL_TIMEOUT
:
7193 /* Wrapper for serial_write that closes the target and throws if
7197 remote_serial_write (const char *str
, int len
)
7199 struct remote_state
*rs
= get_remote_state ();
7201 if (serial_write (rs
->remote_desc
, str
, len
))
7203 unpush_and_perror (_("Remote communication error. "
7204 "Target disconnected."));
7208 /* Send the command in *BUF to the remote machine, and read the reply
7209 into *BUF. Report an error if we get an error reply. Resize
7210 *BUF using xrealloc if necessary to hold the result, and update
7214 remote_send (char **buf
,
7218 getpkt (buf
, sizeof_buf
, 0);
7220 if ((*buf
)[0] == 'E')
7221 error (_("Remote failure reply: %s"), *buf
);
7224 /* Return a pointer to an xmalloc'ed string representing an escaped
7225 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7226 etc. The caller is responsible for releasing the returned
7230 escape_buffer (const char *buf
, int n
)
7232 struct cleanup
*old_chain
;
7233 struct ui_file
*stb
;
7236 stb
= mem_fileopen ();
7237 old_chain
= make_cleanup_ui_file_delete (stb
);
7239 fputstrn_unfiltered (buf
, n
, '\\', stb
);
7240 str
= ui_file_xstrdup (stb
, NULL
);
7241 do_cleanups (old_chain
);
7245 /* Display a null-terminated packet on stdout, for debugging, using C
7249 print_packet (const char *buf
)
7251 puts_filtered ("\"");
7252 fputstr_filtered (buf
, '"', gdb_stdout
);
7253 puts_filtered ("\"");
7257 putpkt (const char *buf
)
7259 return putpkt_binary (buf
, strlen (buf
));
7262 /* Send a packet to the remote machine, with error checking. The data
7263 of the packet is in BUF. The string in BUF can be at most
7264 get_remote_packet_size () - 5 to account for the $, # and checksum,
7265 and for a possible /0 if we are debugging (remote_debug) and want
7266 to print the sent packet as a string. */
7269 putpkt_binary (const char *buf
, int cnt
)
7271 struct remote_state
*rs
= get_remote_state ();
7273 unsigned char csum
= 0;
7274 char *buf2
= alloca (cnt
+ 6);
7281 /* Catch cases like trying to read memory or listing threads while
7282 we're waiting for a stop reply. The remote server wouldn't be
7283 ready to handle this request, so we'd hang and timeout. We don't
7284 have to worry about this in synchronous mode, because in that
7285 case it's not possible to issue a command while the target is
7286 running. This is not a problem in non-stop mode, because in that
7287 case, the stub is always ready to process serial input. */
7288 if (!non_stop
&& target_is_async_p () && rs
->waiting_for_stop_reply
)
7290 error (_("Cannot execute this command while the target is running.\n"
7291 "Use the \"interrupt\" command to stop the target\n"
7292 "and then try again."));
7295 /* We're sending out a new packet. Make sure we don't look at a
7296 stale cached response. */
7297 rs
->cached_wait_status
= 0;
7299 /* Copy the packet into buffer BUF2, encapsulating it
7300 and giving it a checksum. */
7305 for (i
= 0; i
< cnt
; i
++)
7311 *p
++ = tohex ((csum
>> 4) & 0xf);
7312 *p
++ = tohex (csum
& 0xf);
7314 /* Send it over and over until we get a positive ack. */
7318 int started_error_output
= 0;
7322 struct cleanup
*old_chain
;
7326 str
= escape_buffer (buf2
, p
- buf2
);
7327 old_chain
= make_cleanup (xfree
, str
);
7328 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7329 gdb_flush (gdb_stdlog
);
7330 do_cleanups (old_chain
);
7332 remote_serial_write (buf2
, p
- buf2
);
7334 /* If this is a no acks version of the remote protocol, send the
7335 packet and move on. */
7339 /* Read until either a timeout occurs (-2) or '+' is read.
7340 Handle any notification that arrives in the mean time. */
7343 ch
= readchar (remote_timeout
);
7351 case SERIAL_TIMEOUT
:
7354 if (started_error_output
)
7356 putchar_unfiltered ('\n');
7357 started_error_output
= 0;
7366 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7370 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7372 case SERIAL_TIMEOUT
:
7376 break; /* Retransmit buffer. */
7380 fprintf_unfiltered (gdb_stdlog
,
7381 "Packet instead of Ack, ignoring it\n");
7382 /* It's probably an old response sent because an ACK
7383 was lost. Gobble up the packet and ack it so it
7384 doesn't get retransmitted when we resend this
7387 remote_serial_write ("+", 1);
7388 continue; /* Now, go look for +. */
7395 /* If we got a notification, handle it, and go back to looking
7397 /* We've found the start of a notification. Now
7398 collect the data. */
7399 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7404 struct cleanup
*old_chain
;
7407 str
= escape_buffer (rs
->buf
, val
);
7408 old_chain
= make_cleanup (xfree
, str
);
7409 fprintf_unfiltered (gdb_stdlog
,
7410 " Notification received: %s\n",
7412 do_cleanups (old_chain
);
7414 handle_notification (rs
->notif_state
, rs
->buf
);
7415 /* We're in sync now, rewait for the ack. */
7422 if (!started_error_output
)
7424 started_error_output
= 1;
7425 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7427 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7428 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7437 if (!started_error_output
)
7439 started_error_output
= 1;
7440 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7442 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7446 break; /* Here to retransmit. */
7450 /* This is wrong. If doing a long backtrace, the user should be
7451 able to get out next time we call QUIT, without anything as
7452 violent as interrupt_query. If we want to provide a way out of
7453 here without getting to the next QUIT, it should be based on
7454 hitting ^C twice as in remote_wait. */
7465 /* Come here after finding the start of a frame when we expected an
7466 ack. Do our best to discard the rest of this packet. */
7475 c
= readchar (remote_timeout
);
7478 case SERIAL_TIMEOUT
:
7479 /* Nothing we can do. */
7482 /* Discard the two bytes of checksum and stop. */
7483 c
= readchar (remote_timeout
);
7485 c
= readchar (remote_timeout
);
7488 case '*': /* Run length encoding. */
7489 /* Discard the repeat count. */
7490 c
= readchar (remote_timeout
);
7495 /* A regular character. */
7501 /* Come here after finding the start of the frame. Collect the rest
7502 into *BUF, verifying the checksum, length, and handling run-length
7503 compression. NUL terminate the buffer. If there is not enough room,
7504 expand *BUF using xrealloc.
7506 Returns -1 on error, number of characters in buffer (ignoring the
7507 trailing NULL) on success. (could be extended to return one of the
7508 SERIAL status indications). */
7511 read_frame (char **buf_p
,
7518 struct remote_state
*rs
= get_remote_state ();
7525 c
= readchar (remote_timeout
);
7528 case SERIAL_TIMEOUT
:
7530 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7534 fputs_filtered ("Saw new packet start in middle of old one\n",
7536 return -1; /* Start a new packet, count retries. */
7539 unsigned char pktcsum
;
7545 check_0
= readchar (remote_timeout
);
7547 check_1
= readchar (remote_timeout
);
7549 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7552 fputs_filtered ("Timeout in checksum, retrying\n",
7556 else if (check_0
< 0 || check_1
< 0)
7559 fputs_filtered ("Communication error in checksum\n",
7564 /* Don't recompute the checksum; with no ack packets we
7565 don't have any way to indicate a packet retransmission
7570 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7571 if (csum
== pktcsum
)
7576 struct cleanup
*old_chain
;
7579 str
= escape_buffer (buf
, bc
);
7580 old_chain
= make_cleanup (xfree
, str
);
7581 fprintf_unfiltered (gdb_stdlog
,
7582 "Bad checksum, sentsum=0x%x, "
7583 "csum=0x%x, buf=%s\n",
7584 pktcsum
, csum
, str
);
7585 do_cleanups (old_chain
);
7587 /* Number of characters in buffer ignoring trailing
7591 case '*': /* Run length encoding. */
7596 c
= readchar (remote_timeout
);
7598 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7600 /* The character before ``*'' is repeated. */
7602 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7604 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7606 /* Make some more room in the buffer. */
7607 *sizeof_buf
+= repeat
;
7608 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7612 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7618 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7622 if (bc
>= *sizeof_buf
- 1)
7624 /* Make some more room in the buffer. */
7626 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7637 /* Read a packet from the remote machine, with error checking, and
7638 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7639 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7640 rather than timing out; this is used (in synchronous mode) to wait
7641 for a target that is is executing user code to stop. */
7642 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7643 don't have to change all the calls to getpkt to deal with the
7644 return value, because at the moment I don't know what the right
7645 thing to do it for those. */
7653 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7657 /* Read a packet from the remote machine, with error checking, and
7658 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7659 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7660 rather than timing out; this is used (in synchronous mode) to wait
7661 for a target that is is executing user code to stop. If FOREVER ==
7662 0, this function is allowed to time out gracefully and return an
7663 indication of this to the caller. Otherwise return the number of
7664 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7665 enough reason to return to the caller. *IS_NOTIF is an output
7666 boolean that indicates whether *BUF holds a notification or not
7667 (a regular packet). */
7670 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7671 int expecting_notif
, int *is_notif
)
7673 struct remote_state
*rs
= get_remote_state ();
7679 /* We're reading a new response. Make sure we don't look at a
7680 previously cached response. */
7681 rs
->cached_wait_status
= 0;
7683 strcpy (*buf
, "timeout");
7686 timeout
= watchdog
> 0 ? watchdog
: -1;
7687 else if (expecting_notif
)
7688 timeout
= 0; /* There should already be a char in the buffer. If
7691 timeout
= remote_timeout
;
7695 /* Process any number of notifications, and then return when
7699 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
7701 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7703 /* This can loop forever if the remote side sends us
7704 characters continuously, but if it pauses, we'll get
7705 SERIAL_TIMEOUT from readchar because of timeout. Then
7706 we'll count that as a retry.
7708 Note that even when forever is set, we will only wait
7709 forever prior to the start of a packet. After that, we
7710 expect characters to arrive at a brisk pace. They should
7711 show up within remote_timeout intervals. */
7713 c
= readchar (timeout
);
7714 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7716 if (c
== SERIAL_TIMEOUT
)
7718 if (expecting_notif
)
7719 return -1; /* Don't complain, it's normal to not get
7720 anything in this case. */
7722 if (forever
) /* Watchdog went off? Kill the target. */
7725 remote_unpush_target ();
7726 throw_error (TARGET_CLOSE_ERROR
,
7727 _("Watchdog timeout has expired. "
7728 "Target detached."));
7731 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7735 /* We've found the start of a packet or notification.
7736 Now collect the data. */
7737 val
= read_frame (buf
, sizeof_buf
);
7742 remote_serial_write ("-", 1);
7745 if (tries
> MAX_TRIES
)
7747 /* We have tried hard enough, and just can't receive the
7748 packet/notification. Give up. */
7749 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7751 /* Skip the ack char if we're in no-ack mode. */
7752 if (!rs
->noack_mode
)
7753 remote_serial_write ("+", 1);
7757 /* If we got an ordinary packet, return that to our caller. */
7762 struct cleanup
*old_chain
;
7765 str
= escape_buffer (*buf
, val
);
7766 old_chain
= make_cleanup (xfree
, str
);
7767 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7768 do_cleanups (old_chain
);
7771 /* Skip the ack char if we're in no-ack mode. */
7772 if (!rs
->noack_mode
)
7773 remote_serial_write ("+", 1);
7774 if (is_notif
!= NULL
)
7779 /* If we got a notification, handle it, and go back to looking
7783 gdb_assert (c
== '%');
7787 struct cleanup
*old_chain
;
7790 str
= escape_buffer (*buf
, val
);
7791 old_chain
= make_cleanup (xfree
, str
);
7792 fprintf_unfiltered (gdb_stdlog
,
7793 " Notification received: %s\n",
7795 do_cleanups (old_chain
);
7797 if (is_notif
!= NULL
)
7800 handle_notification (rs
->notif_state
, *buf
);
7802 /* Notifications require no acknowledgement. */
7804 if (expecting_notif
)
7811 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7813 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
7817 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
7820 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
7826 remote_kill (struct target_ops
*ops
)
7829 /* Catch errors so the user can quit from gdb even when we
7830 aren't on speaking terms with the remote system. */
7835 CATCH (ex
, RETURN_MASK_ERROR
)
7837 if (ex
.error
== TARGET_CLOSE_ERROR
)
7839 /* If we got an (EOF) error that caused the target
7840 to go away, then we're done, that's what we wanted.
7841 "k" is susceptible to cause a premature EOF, given
7842 that the remote server isn't actually required to
7843 reply to "k", and it can happen that it doesn't
7844 even get to reply ACK to the "k". */
7848 /* Otherwise, something went wrong. We didn't actually kill
7849 the target. Just propagate the exception, and let the
7850 user or higher layers decide what to do. */
7851 throw_exception (ex
);
7855 /* We've killed the remote end, we get to mourn it. Since this is
7856 target remote, single-process, mourning the inferior also
7857 unpushes remote_ops. */
7858 target_mourn_inferior ();
7862 remote_vkill (int pid
, struct remote_state
*rs
)
7864 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
7867 /* Tell the remote target to detach. */
7868 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
7870 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7872 switch (packet_ok (rs
->buf
,
7873 &remote_protocol_packets
[PACKET_vKill
]))
7879 case PACKET_UNKNOWN
:
7882 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
7887 extended_remote_kill (struct target_ops
*ops
)
7890 int pid
= ptid_get_pid (inferior_ptid
);
7891 struct remote_state
*rs
= get_remote_state ();
7893 res
= remote_vkill (pid
, rs
);
7894 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
7896 /* Don't try 'k' on a multi-process aware stub -- it has no way
7897 to specify the pid. */
7901 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7902 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7905 /* Don't wait for it to die. I'm not really sure it matters whether
7906 we do or not. For the existing stubs, kill is a noop. */
7912 error (_("Can't kill process"));
7914 target_mourn_inferior ();
7918 remote_mourn (struct target_ops
*target
)
7920 unpush_target (target
);
7922 /* remote_close takes care of doing most of the clean up. */
7923 generic_mourn_inferior ();
7927 extended_remote_mourn (struct target_ops
*target
)
7929 struct remote_state
*rs
= get_remote_state ();
7931 /* In case we got here due to an error, but we're going to stay
7933 rs
->waiting_for_stop_reply
= 0;
7935 /* If the current general thread belonged to the process we just
7936 detached from or has exited, the remote side current general
7937 thread becomes undefined. Considering a case like this:
7939 - We just got here due to a detach.
7940 - The process that we're detaching from happens to immediately
7941 report a global breakpoint being hit in non-stop mode, in the
7942 same thread we had selected before.
7943 - GDB attaches to this process again.
7944 - This event happens to be the next event we handle.
7946 GDB would consider that the current general thread didn't need to
7947 be set on the stub side (with Hg), since for all it knew,
7948 GENERAL_THREAD hadn't changed.
7950 Notice that although in all-stop mode, the remote server always
7951 sets the current thread to the thread reporting the stop event,
7952 that doesn't happen in non-stop mode; in non-stop, the stub *must
7953 not* change the current thread when reporting a breakpoint hit,
7954 due to the decoupling of event reporting and event handling.
7956 To keep things simple, we always invalidate our notion of the
7958 record_currthread (rs
, minus_one_ptid
);
7960 /* Unlike "target remote", we do not want to unpush the target; then
7961 the next time the user says "run", we won't be connected. */
7963 /* Call common code to mark the inferior as not running. */
7964 generic_mourn_inferior ();
7966 if (!have_inferiors ())
7968 if (!remote_multi_process_p (rs
))
7970 /* Check whether the target is running now - some remote stubs
7971 automatically restart after kill. */
7973 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7975 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7977 /* Assume that the target has been restarted. Set
7978 inferior_ptid so that bits of core GDB realizes
7979 there's something here, e.g., so that the user can
7980 say "kill" again. */
7981 inferior_ptid
= magic_null_ptid
;
7988 extended_remote_supports_disable_randomization (struct target_ops
*self
)
7990 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
7994 extended_remote_disable_randomization (int val
)
7996 struct remote_state
*rs
= get_remote_state ();
7999 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
8002 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
8004 error (_("Target does not support QDisableRandomization."));
8005 if (strcmp (reply
, "OK") != 0)
8006 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
8010 extended_remote_run (char *args
)
8012 struct remote_state
*rs
= get_remote_state ();
8015 /* If the user has disabled vRun support, or we have detected that
8016 support is not available, do not try it. */
8017 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
8020 strcpy (rs
->buf
, "vRun;");
8021 len
= strlen (rs
->buf
);
8023 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
8024 error (_("Remote file name too long for run packet"));
8025 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
8026 strlen (remote_exec_file
));
8028 gdb_assert (args
!= NULL
);
8031 struct cleanup
*back_to
;
8035 argv
= gdb_buildargv (args
);
8036 back_to
= make_cleanup_freeargv (argv
);
8037 for (i
= 0; argv
[i
] != NULL
; i
++)
8039 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
8040 error (_("Argument list too long for run packet"));
8041 rs
->buf
[len
++] = ';';
8042 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
8045 do_cleanups (back_to
);
8048 rs
->buf
[len
++] = '\0';
8051 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8053 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
8056 /* We have a wait response. All is well. */
8058 case PACKET_UNKNOWN
:
8061 if (remote_exec_file
[0] == '\0')
8062 error (_("Running the default executable on the remote target failed; "
8063 "try \"set remote exec-file\"?"));
8065 error (_("Running \"%s\" on the remote target failed"),
8068 gdb_assert_not_reached (_("bad switch"));
8072 /* In the extended protocol we want to be able to do things like
8073 "run" and have them basically work as expected. So we need
8074 a special create_inferior function. We support changing the
8075 executable file and the command line arguments, but not the
8079 extended_remote_create_inferior (struct target_ops
*ops
,
8080 char *exec_file
, char *args
,
8081 char **env
, int from_tty
)
8085 struct remote_state
*rs
= get_remote_state ();
8087 /* If running asynchronously, register the target file descriptor
8088 with the event loop. */
8089 if (target_can_async_p ())
8092 /* Disable address space randomization if requested (and supported). */
8093 if (extended_remote_supports_disable_randomization (ops
))
8094 extended_remote_disable_randomization (disable_randomization
);
8096 /* Now restart the remote server. */
8097 run_worked
= extended_remote_run (args
) != -1;
8100 /* vRun was not supported. Fail if we need it to do what the
8102 if (remote_exec_file
[0])
8103 error (_("Remote target does not support \"set remote exec-file\""));
8105 error (_("Remote target does not support \"set args\" or run <ARGS>"));
8107 /* Fall back to "R". */
8108 extended_remote_restart ();
8111 if (!have_inferiors ())
8113 /* Clean up from the last time we ran, before we mark the target
8114 running again. This will mark breakpoints uninserted, and
8115 get_offsets may insert breakpoints. */
8116 init_thread_list ();
8117 init_wait_for_inferior ();
8120 /* vRun's success return is a stop reply. */
8121 stop_reply
= run_worked
? rs
->buf
: NULL
;
8122 add_current_inferior_and_thread (stop_reply
);
8124 /* Get updated offsets, if the stub uses qOffsets. */
8129 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8130 the list of conditions (in agent expression bytecode format), if any, the
8131 target needs to evaluate. The output is placed into the packet buffer
8132 started from BUF and ended at BUF_END. */
8135 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
8136 struct bp_target_info
*bp_tgt
, char *buf
,
8139 struct agent_expr
*aexpr
= NULL
;
8142 char *buf_start
= buf
;
8144 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
8147 buf
+= strlen (buf
);
8148 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8151 /* Send conditions to the target and free the vector. */
8153 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8156 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8157 buf
+= strlen (buf
);
8158 for (i
= 0; i
< aexpr
->len
; ++i
)
8159 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8166 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8167 struct bp_target_info
*bp_tgt
, char *buf
)
8169 struct agent_expr
*aexpr
= NULL
;
8172 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8175 buf
+= strlen (buf
);
8177 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8178 buf
+= strlen (buf
);
8180 /* Concatenate all the agent expressions that are commands into the
8183 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8186 sprintf (buf
, "X%x,", aexpr
->len
);
8187 buf
+= strlen (buf
);
8188 for (i
= 0; i
< aexpr
->len
; ++i
)
8189 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8194 /* Insert a breakpoint. On targets that have software breakpoint
8195 support, we ask the remote target to do the work; on targets
8196 which don't, we insert a traditional memory breakpoint. */
8199 remote_insert_breakpoint (struct target_ops
*ops
,
8200 struct gdbarch
*gdbarch
,
8201 struct bp_target_info
*bp_tgt
)
8203 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8204 If it succeeds, then set the support to PACKET_ENABLE. If it
8205 fails, and the user has explicitly requested the Z support then
8206 report an error, otherwise, mark it disabled and go on. */
8208 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8210 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
8211 struct remote_state
*rs
;
8214 struct condition_list
*cond
= NULL
;
8216 /* Make sure the remote is pointing at the right process, if
8218 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8219 set_general_process ();
8221 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8223 rs
= get_remote_state ();
8225 endbuf
= rs
->buf
+ get_remote_packet_size ();
8230 addr
= (ULONGEST
) remote_address_masked (addr
);
8231 p
+= hexnumstr (p
, addr
);
8232 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8234 if (remote_supports_cond_breakpoints (ops
))
8235 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8237 if (remote_can_run_breakpoint_commands (ops
))
8238 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8241 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8243 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8248 bp_tgt
->placed_address
= addr
;
8249 bp_tgt
->placed_size
= bpsize
;
8251 case PACKET_UNKNOWN
:
8256 /* If this breakpoint has target-side commands but this stub doesn't
8257 support Z0 packets, throw error. */
8258 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8259 throw_error (NOT_SUPPORTED_ERROR
, _("\
8260 Target doesn't support breakpoints that have target side commands."));
8262 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
8266 remote_remove_breakpoint (struct target_ops
*ops
,
8267 struct gdbarch
*gdbarch
,
8268 struct bp_target_info
*bp_tgt
)
8270 CORE_ADDR addr
= bp_tgt
->placed_address
;
8271 struct remote_state
*rs
= get_remote_state ();
8273 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8276 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8278 /* Make sure the remote is pointing at the right process, if
8280 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8281 set_general_process ();
8287 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8288 p
+= hexnumstr (p
, addr
);
8289 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8292 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8294 return (rs
->buf
[0] == 'E');
8297 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
);
8301 watchpoint_to_Z_packet (int type
)
8306 return Z_PACKET_WRITE_WP
;
8309 return Z_PACKET_READ_WP
;
8312 return Z_PACKET_ACCESS_WP
;
8315 internal_error (__FILE__
, __LINE__
,
8316 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8321 remote_insert_watchpoint (struct target_ops
*self
,
8322 CORE_ADDR addr
, int len
, int type
,
8323 struct expression
*cond
)
8325 struct remote_state
*rs
= get_remote_state ();
8326 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8328 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8330 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
8333 /* Make sure the remote is pointing at the right process, if
8335 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8336 set_general_process ();
8338 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8339 p
= strchr (rs
->buf
, '\0');
8340 addr
= remote_address_masked (addr
);
8341 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8342 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8345 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8347 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8351 case PACKET_UNKNOWN
:
8356 internal_error (__FILE__
, __LINE__
,
8357 _("remote_insert_watchpoint: reached end of function"));
8361 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8362 CORE_ADDR start
, int length
)
8364 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8366 return diff
< length
;
8371 remote_remove_watchpoint (struct target_ops
*self
,
8372 CORE_ADDR addr
, int len
, int type
,
8373 struct expression
*cond
)
8375 struct remote_state
*rs
= get_remote_state ();
8376 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8378 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8380 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
8383 /* Make sure the remote is pointing at the right process, if
8385 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8386 set_general_process ();
8388 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8389 p
= strchr (rs
->buf
, '\0');
8390 addr
= remote_address_masked (addr
);
8391 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8392 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8394 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8396 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8399 case PACKET_UNKNOWN
:
8404 internal_error (__FILE__
, __LINE__
,
8405 _("remote_remove_watchpoint: reached end of function"));
8409 int remote_hw_watchpoint_limit
= -1;
8410 int remote_hw_watchpoint_length_limit
= -1;
8411 int remote_hw_breakpoint_limit
= -1;
8414 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
8415 CORE_ADDR addr
, int len
)
8417 if (remote_hw_watchpoint_length_limit
== 0)
8419 else if (remote_hw_watchpoint_length_limit
< 0)
8421 else if (len
<= remote_hw_watchpoint_length_limit
)
8428 remote_check_watch_resources (struct target_ops
*self
,
8429 int type
, int cnt
, int ot
)
8431 if (type
== bp_hardware_breakpoint
)
8433 if (remote_hw_breakpoint_limit
== 0)
8435 else if (remote_hw_breakpoint_limit
< 0)
8437 else if (cnt
<= remote_hw_breakpoint_limit
)
8442 if (remote_hw_watchpoint_limit
== 0)
8444 else if (remote_hw_watchpoint_limit
< 0)
8448 else if (cnt
<= remote_hw_watchpoint_limit
)
8454 /* The to_stopped_by_sw_breakpoint method of target remote. */
8457 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
8459 struct remote_state
*rs
= get_remote_state ();
8461 return rs
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
;
8464 /* The to_supports_stopped_by_sw_breakpoint method of target
8468 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
8470 struct remote_state
*rs
= get_remote_state ();
8472 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
8475 /* The to_stopped_by_hw_breakpoint method of target remote. */
8478 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
8480 struct remote_state
*rs
= get_remote_state ();
8482 return rs
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
;
8485 /* The to_supports_stopped_by_hw_breakpoint method of target
8489 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
8491 struct remote_state
*rs
= get_remote_state ();
8493 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
8497 remote_stopped_by_watchpoint (struct target_ops
*ops
)
8499 struct remote_state
*rs
= get_remote_state ();
8501 return rs
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
;
8505 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
8507 struct remote_state
*rs
= get_remote_state ();
8510 if (remote_stopped_by_watchpoint (target
))
8512 *addr_p
= rs
->remote_watch_data_address
;
8521 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
8522 struct bp_target_info
*bp_tgt
)
8524 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
8525 struct remote_state
*rs
;
8530 /* The length field should be set to the size of a breakpoint
8531 instruction, even though we aren't inserting one ourselves. */
8533 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8535 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
8538 /* Make sure the remote is pointing at the right process, if
8540 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8541 set_general_process ();
8543 rs
= get_remote_state ();
8545 endbuf
= rs
->buf
+ get_remote_packet_size ();
8551 addr
= remote_address_masked (addr
);
8552 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8553 xsnprintf (p
, endbuf
- p
, ",%x", bpsize
);
8555 if (remote_supports_cond_breakpoints (self
))
8556 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8558 if (remote_can_run_breakpoint_commands (self
))
8559 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8562 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8564 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8567 if (rs
->buf
[1] == '.')
8569 message
= strchr (rs
->buf
+ 2, '.');
8571 error (_("Remote failure reply: %s"), message
+ 1);
8574 case PACKET_UNKNOWN
:
8577 bp_tgt
->placed_address
= addr
;
8578 bp_tgt
->placed_size
= bpsize
;
8581 internal_error (__FILE__
, __LINE__
,
8582 _("remote_insert_hw_breakpoint: reached end of function"));
8587 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
8588 struct bp_target_info
*bp_tgt
)
8591 struct remote_state
*rs
= get_remote_state ();
8593 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8595 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
8598 /* Make sure the remote is pointing at the right process, if
8600 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8601 set_general_process ();
8607 addr
= remote_address_masked (bp_tgt
->placed_address
);
8608 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8609 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8612 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8614 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8617 case PACKET_UNKNOWN
:
8622 internal_error (__FILE__
, __LINE__
,
8623 _("remote_remove_hw_breakpoint: reached end of function"));
8626 /* Verify memory using the "qCRC:" request. */
8629 remote_verify_memory (struct target_ops
*ops
,
8630 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8632 struct remote_state
*rs
= get_remote_state ();
8633 unsigned long host_crc
, target_crc
;
8636 /* It doesn't make sense to use qCRC if the remote target is
8637 connected but not running. */
8638 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
8640 enum packet_result result
;
8642 /* Make sure the remote is pointing at the right process. */
8643 set_general_process ();
8645 /* FIXME: assumes lma can fit into long. */
8646 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8647 (long) lma
, (long) size
);
8650 /* Be clever; compute the host_crc before waiting for target
8652 host_crc
= xcrc32 (data
, size
, 0xffffffff);
8654 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8656 result
= packet_ok (rs
->buf
,
8657 &remote_protocol_packets
[PACKET_qCRC
]);
8658 if (result
== PACKET_ERROR
)
8660 else if (result
== PACKET_OK
)
8662 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8663 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8665 return (host_crc
== target_crc
);
8669 return simple_verify_memory (ops
, data
, lma
, size
);
8672 /* compare-sections command
8674 With no arguments, compares each loadable section in the exec bfd
8675 with the same memory range on the target, and reports mismatches.
8676 Useful for verifying the image on the target against the exec file. */
8679 compare_sections_command (char *args
, int from_tty
)
8682 struct cleanup
*old_chain
;
8684 const char *sectname
;
8693 error (_("command cannot be used without an exec file"));
8695 /* Make sure the remote is pointing at the right process. */
8696 set_general_process ();
8698 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
8704 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8706 if (!(s
->flags
& SEC_LOAD
))
8707 continue; /* Skip non-loadable section. */
8709 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
8710 continue; /* Skip writeable sections */
8712 size
= bfd_get_section_size (s
);
8714 continue; /* Skip zero-length section. */
8716 sectname
= bfd_get_section_name (exec_bfd
, s
);
8717 if (args
&& strcmp (args
, sectname
) != 0)
8718 continue; /* Not the section selected by user. */
8720 matched
= 1; /* Do this section. */
8723 sectdata
= xmalloc (size
);
8724 old_chain
= make_cleanup (xfree
, sectdata
);
8725 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8727 res
= target_verify_memory (sectdata
, lma
, size
);
8730 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8731 paddress (target_gdbarch (), lma
),
8732 paddress (target_gdbarch (), lma
+ size
));
8734 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8735 paddress (target_gdbarch (), lma
),
8736 paddress (target_gdbarch (), lma
+ size
));
8738 printf_filtered ("matched.\n");
8741 printf_filtered ("MIS-MATCHED!\n");
8745 do_cleanups (old_chain
);
8748 warning (_("One or more sections of the target image does not match\n\
8749 the loaded file\n"));
8750 if (args
&& !matched
)
8751 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8754 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8755 into remote target. The number of bytes written to the remote
8756 target is returned, or -1 for error. */
8758 static enum target_xfer_status
8759 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8760 const char *annex
, const gdb_byte
*writebuf
,
8761 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
8762 struct packet_config
*packet
)
8766 struct remote_state
*rs
= get_remote_state ();
8767 int max_size
= get_memory_write_packet_size ();
8769 if (packet
->support
== PACKET_DISABLE
)
8770 return TARGET_XFER_E_IO
;
8772 /* Insert header. */
8773 i
= snprintf (rs
->buf
, max_size
,
8774 "qXfer:%s:write:%s:%s:",
8775 object_name
, annex
? annex
: "",
8776 phex_nz (offset
, sizeof offset
));
8777 max_size
-= (i
+ 1);
8779 /* Escape as much data as fits into rs->buf. */
8780 buf_len
= remote_escape_output
8781 (writebuf
, len
, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
8783 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8784 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8785 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8786 return TARGET_XFER_E_IO
;
8788 unpack_varlen_hex (rs
->buf
, &n
);
8791 return TARGET_XFER_OK
;
8794 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8795 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8796 number of bytes read is returned, or 0 for EOF, or -1 for error.
8797 The number of bytes read may be less than LEN without indicating an
8798 EOF. PACKET is checked and updated to indicate whether the remote
8799 target supports this object. */
8801 static enum target_xfer_status
8802 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8804 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8805 ULONGEST
*xfered_len
,
8806 struct packet_config
*packet
)
8808 struct remote_state
*rs
= get_remote_state ();
8809 LONGEST i
, n
, packet_len
;
8811 if (packet
->support
== PACKET_DISABLE
)
8812 return TARGET_XFER_E_IO
;
8814 /* Check whether we've cached an end-of-object packet that matches
8816 if (rs
->finished_object
)
8818 if (strcmp (object_name
, rs
->finished_object
) == 0
8819 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
8820 && offset
== rs
->finished_offset
)
8821 return TARGET_XFER_EOF
;
8824 /* Otherwise, we're now reading something different. Discard
8826 xfree (rs
->finished_object
);
8827 xfree (rs
->finished_annex
);
8828 rs
->finished_object
= NULL
;
8829 rs
->finished_annex
= NULL
;
8832 /* Request only enough to fit in a single packet. The actual data
8833 may not, since we don't know how much of it will need to be escaped;
8834 the target is free to respond with slightly less data. We subtract
8835 five to account for the response type and the protocol frame. */
8836 n
= min (get_remote_packet_size () - 5, len
);
8837 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8838 object_name
, annex
? annex
: "",
8839 phex_nz (offset
, sizeof offset
),
8840 phex_nz (n
, sizeof n
));
8841 i
= putpkt (rs
->buf
);
8843 return TARGET_XFER_E_IO
;
8846 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8847 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8848 return TARGET_XFER_E_IO
;
8850 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8851 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8853 /* 'm' means there is (or at least might be) more data after this
8854 batch. That does not make sense unless there's at least one byte
8855 of data in this reply. */
8856 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8857 error (_("Remote qXfer reply contained no data."));
8859 /* Got some data. */
8860 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
8861 packet_len
- 1, readbuf
, n
);
8863 /* 'l' is an EOF marker, possibly including a final block of data,
8864 or possibly empty. If we have the final block of a non-empty
8865 object, record this fact to bypass a subsequent partial read. */
8866 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8868 rs
->finished_object
= xstrdup (object_name
);
8869 rs
->finished_annex
= xstrdup (annex
? annex
: "");
8870 rs
->finished_offset
= offset
+ i
;
8874 return TARGET_XFER_EOF
;
8878 return TARGET_XFER_OK
;
8882 static enum target_xfer_status
8883 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8884 const char *annex
, gdb_byte
*readbuf
,
8885 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
8886 ULONGEST
*xfered_len
)
8888 struct remote_state
*rs
;
8893 set_remote_traceframe ();
8894 set_general_thread (inferior_ptid
);
8896 rs
= get_remote_state ();
8898 /* Handle memory using the standard memory routines. */
8899 if (object
== TARGET_OBJECT_MEMORY
)
8901 /* If the remote target is connected but not running, we should
8902 pass this request down to a lower stratum (e.g. the executable
8904 if (!target_has_execution
)
8905 return TARGET_XFER_EOF
;
8907 if (writebuf
!= NULL
)
8908 return remote_write_bytes (offset
, writebuf
, len
, xfered_len
);
8910 return remote_read_bytes (ops
, offset
, readbuf
, len
, xfered_len
);
8913 /* Handle SPU memory using qxfer packets. */
8914 if (object
== TARGET_OBJECT_SPU
)
8917 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8918 xfered_len
, &remote_protocol_packets
8919 [PACKET_qXfer_spu_read
]);
8921 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8922 xfered_len
, &remote_protocol_packets
8923 [PACKET_qXfer_spu_write
]);
8926 /* Handle extra signal info using qxfer packets. */
8927 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8930 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8931 xfered_len
, &remote_protocol_packets
8932 [PACKET_qXfer_siginfo_read
]);
8934 return remote_write_qxfer (ops
, "siginfo", annex
,
8935 writebuf
, offset
, len
, xfered_len
,
8936 &remote_protocol_packets
8937 [PACKET_qXfer_siginfo_write
]);
8940 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8943 return remote_read_qxfer (ops
, "statictrace", annex
,
8944 readbuf
, offset
, len
, xfered_len
,
8945 &remote_protocol_packets
8946 [PACKET_qXfer_statictrace_read
]);
8948 return TARGET_XFER_E_IO
;
8951 /* Only handle flash writes. */
8952 if (writebuf
!= NULL
)
8958 case TARGET_OBJECT_FLASH
:
8959 return remote_flash_write (ops
, offset
, len
, xfered_len
,
8963 return TARGET_XFER_E_IO
;
8967 /* Map pre-existing objects onto letters. DO NOT do this for new
8968 objects!!! Instead specify new query packets. */
8971 case TARGET_OBJECT_AVR
:
8975 case TARGET_OBJECT_AUXV
:
8976 gdb_assert (annex
== NULL
);
8977 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8979 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8981 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8982 return remote_read_qxfer
8983 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
8984 &remote_protocol_packets
[PACKET_qXfer_features
]);
8986 case TARGET_OBJECT_LIBRARIES
:
8987 return remote_read_qxfer
8988 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
8989 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8991 case TARGET_OBJECT_LIBRARIES_SVR4
:
8992 return remote_read_qxfer
8993 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
8994 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
8996 case TARGET_OBJECT_MEMORY_MAP
:
8997 gdb_assert (annex
== NULL
);
8998 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
9000 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
9002 case TARGET_OBJECT_OSDATA
:
9003 /* Should only get here if we're connected. */
9004 gdb_assert (rs
->remote_desc
);
9005 return remote_read_qxfer
9006 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
9007 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
9009 case TARGET_OBJECT_THREADS
:
9010 gdb_assert (annex
== NULL
);
9011 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
9013 &remote_protocol_packets
[PACKET_qXfer_threads
]);
9015 case TARGET_OBJECT_TRACEFRAME_INFO
:
9016 gdb_assert (annex
== NULL
);
9017 return remote_read_qxfer
9018 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
9019 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
9021 case TARGET_OBJECT_FDPIC
:
9022 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
9024 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
9026 case TARGET_OBJECT_OPENVMS_UIB
:
9027 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
9029 &remote_protocol_packets
[PACKET_qXfer_uib
]);
9031 case TARGET_OBJECT_BTRACE
:
9032 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
9034 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
9036 case TARGET_OBJECT_BTRACE_CONF
:
9037 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
9039 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
9041 case TARGET_OBJECT_EXEC_FILE
:
9042 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
9044 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
9047 return TARGET_XFER_E_IO
;
9050 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
9051 large enough let the caller deal with it. */
9052 if (len
< get_remote_packet_size ())
9053 return TARGET_XFER_E_IO
;
9054 len
= get_remote_packet_size ();
9056 /* Except for querying the minimum buffer size, target must be open. */
9057 if (!rs
->remote_desc
)
9058 error (_("remote query is only available after target open"));
9060 gdb_assert (annex
!= NULL
);
9061 gdb_assert (readbuf
!= NULL
);
9067 /* We used one buffer char for the remote protocol q command and
9068 another for the query type. As the remote protocol encapsulation
9069 uses 4 chars plus one extra in case we are debugging
9070 (remote_debug), we have PBUFZIZ - 7 left to pack the query
9073 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
9075 /* Bad caller may have sent forbidden characters. */
9076 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
9081 gdb_assert (annex
[i
] == '\0');
9083 i
= putpkt (rs
->buf
);
9085 return TARGET_XFER_E_IO
;
9087 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9088 strcpy ((char *) readbuf
, rs
->buf
);
9090 *xfered_len
= strlen ((char *) readbuf
);
9091 return TARGET_XFER_OK
;
9095 remote_search_memory (struct target_ops
* ops
,
9096 CORE_ADDR start_addr
, ULONGEST search_space_len
,
9097 const gdb_byte
*pattern
, ULONGEST pattern_len
,
9098 CORE_ADDR
*found_addrp
)
9100 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
9101 struct remote_state
*rs
= get_remote_state ();
9102 int max_size
= get_memory_write_packet_size ();
9103 struct packet_config
*packet
=
9104 &remote_protocol_packets
[PACKET_qSearch_memory
];
9105 /* Number of packet bytes used to encode the pattern;
9106 this could be more than PATTERN_LEN due to escape characters. */
9107 int escaped_pattern_len
;
9108 /* Amount of pattern that was encodable in the packet. */
9109 int used_pattern_len
;
9112 ULONGEST found_addr
;
9114 /* Don't go to the target if we don't have to.
9115 This is done before checking packet->support to avoid the possibility that
9116 a success for this edge case means the facility works in general. */
9117 if (pattern_len
> search_space_len
)
9119 if (pattern_len
== 0)
9121 *found_addrp
= start_addr
;
9125 /* If we already know the packet isn't supported, fall back to the simple
9126 way of searching memory. */
9128 if (packet_config_support (packet
) == PACKET_DISABLE
)
9130 /* Target doesn't provided special support, fall back and use the
9131 standard support (copy memory and do the search here). */
9132 return simple_search_memory (ops
, start_addr
, search_space_len
,
9133 pattern
, pattern_len
, found_addrp
);
9136 /* Make sure the remote is pointing at the right process. */
9137 set_general_process ();
9139 /* Insert header. */
9140 i
= snprintf (rs
->buf
, max_size
,
9141 "qSearch:memory:%s;%s;",
9142 phex_nz (start_addr
, addr_size
),
9143 phex_nz (search_space_len
, sizeof (search_space_len
)));
9144 max_size
-= (i
+ 1);
9146 /* Escape as much data as fits into rs->buf. */
9147 escaped_pattern_len
=
9148 remote_escape_output (pattern
, pattern_len
, (gdb_byte
*) rs
->buf
+ i
,
9149 &used_pattern_len
, max_size
);
9151 /* Bail if the pattern is too large. */
9152 if (used_pattern_len
!= pattern_len
)
9153 error (_("Pattern is too large to transmit to remote target."));
9155 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
9156 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9157 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9159 /* The request may not have worked because the command is not
9160 supported. If so, fall back to the simple way. */
9161 if (packet
->support
== PACKET_DISABLE
)
9163 return simple_search_memory (ops
, start_addr
, search_space_len
,
9164 pattern
, pattern_len
, found_addrp
);
9169 if (rs
->buf
[0] == '0')
9171 else if (rs
->buf
[0] == '1')
9174 if (rs
->buf
[1] != ',')
9175 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9176 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
9177 *found_addrp
= found_addr
;
9180 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9186 remote_rcmd (struct target_ops
*self
, const char *command
,
9187 struct ui_file
*outbuf
)
9189 struct remote_state
*rs
= get_remote_state ();
9192 if (!rs
->remote_desc
)
9193 error (_("remote rcmd is only available after target open"));
9195 /* Send a NULL command across as an empty command. */
9196 if (command
== NULL
)
9199 /* The query prefix. */
9200 strcpy (rs
->buf
, "qRcmd,");
9201 p
= strchr (rs
->buf
, '\0');
9203 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
9204 > get_remote_packet_size ())
9205 error (_("\"monitor\" command ``%s'' is too long."), command
);
9207 /* Encode the actual command. */
9208 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
9210 if (putpkt (rs
->buf
) < 0)
9211 error (_("Communication problem with target."));
9213 /* get/display the response */
9218 /* XXX - see also remote_get_noisy_reply(). */
9219 QUIT
; /* Allow user to bail out with ^C. */
9221 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
9223 /* Timeout. Continue to (try to) read responses.
9224 This is better than stopping with an error, assuming the stub
9225 is still executing the (long) monitor command.
9226 If needed, the user can interrupt gdb using C-c, obtaining
9227 an effect similar to stop on timeout. */
9232 error (_("Target does not support this command."));
9233 if (buf
[0] == 'O' && buf
[1] != 'K')
9235 remote_console_output (buf
+ 1); /* 'O' message from stub. */
9238 if (strcmp (buf
, "OK") == 0)
9240 if (strlen (buf
) == 3 && buf
[0] == 'E'
9241 && isdigit (buf
[1]) && isdigit (buf
[2]))
9243 error (_("Protocol error with Rcmd"));
9245 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9247 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9249 fputc_unfiltered (c
, outbuf
);
9255 static VEC(mem_region_s
) *
9256 remote_memory_map (struct target_ops
*ops
)
9258 VEC(mem_region_s
) *result
= NULL
;
9259 char *text
= target_read_stralloc (¤t_target
,
9260 TARGET_OBJECT_MEMORY_MAP
, NULL
);
9264 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
9266 result
= parse_memory_map (text
);
9267 do_cleanups (back_to
);
9274 packet_command (char *args
, int from_tty
)
9276 struct remote_state
*rs
= get_remote_state ();
9278 if (!rs
->remote_desc
)
9279 error (_("command can only be used with remote target"));
9282 error (_("remote-packet command requires packet text as argument"));
9284 puts_filtered ("sending: ");
9285 print_packet (args
);
9286 puts_filtered ("\n");
9289 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9290 puts_filtered ("received: ");
9291 print_packet (rs
->buf
);
9292 puts_filtered ("\n");
9296 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9298 static void display_thread_info (struct gdb_ext_thread_info
*info
);
9300 static void threadset_test_cmd (char *cmd
, int tty
);
9302 static void threadalive_test (char *cmd
, int tty
);
9304 static void threadlist_test_cmd (char *cmd
, int tty
);
9306 int get_and_display_threadinfo (threadref
*ref
);
9308 static void threadinfo_test_cmd (char *cmd
, int tty
);
9310 static int thread_display_step (threadref
*ref
, void *context
);
9312 static void threadlist_update_test_cmd (char *cmd
, int tty
);
9314 static void init_remote_threadtests (void);
9316 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9319 threadset_test_cmd (char *cmd
, int tty
)
9321 int sample_thread
= SAMPLE_THREAD
;
9323 printf_filtered (_("Remote threadset test\n"));
9324 set_general_thread (sample_thread
);
9329 threadalive_test (char *cmd
, int tty
)
9331 int sample_thread
= SAMPLE_THREAD
;
9332 int pid
= ptid_get_pid (inferior_ptid
);
9333 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
9335 if (remote_thread_alive (ptid
))
9336 printf_filtered ("PASS: Thread alive test\n");
9338 printf_filtered ("FAIL: Thread alive test\n");
9341 void output_threadid (char *title
, threadref
*ref
);
9344 output_threadid (char *title
, threadref
*ref
)
9348 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
9350 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
9354 threadlist_test_cmd (char *cmd
, int tty
)
9357 threadref nextthread
;
9358 int done
, result_count
;
9359 threadref threadlist
[3];
9361 printf_filtered ("Remote Threadlist test\n");
9362 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9363 &result_count
, &threadlist
[0]))
9364 printf_filtered ("FAIL: threadlist test\n");
9367 threadref
*scan
= threadlist
;
9368 threadref
*limit
= scan
+ result_count
;
9370 while (scan
< limit
)
9371 output_threadid (" thread ", scan
++);
9376 display_thread_info (struct gdb_ext_thread_info
*info
)
9378 output_threadid ("Threadid: ", &info
->threadid
);
9379 printf_filtered ("Name: %s\n ", info
->shortname
);
9380 printf_filtered ("State: %s\n", info
->display
);
9381 printf_filtered ("other: %s\n\n", info
->more_display
);
9385 get_and_display_threadinfo (threadref
*ref
)
9389 struct gdb_ext_thread_info threadinfo
;
9391 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9392 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9393 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9394 display_thread_info (&threadinfo
);
9399 threadinfo_test_cmd (char *cmd
, int tty
)
9401 int athread
= SAMPLE_THREAD
;
9405 int_to_threadref (&thread
, athread
);
9406 printf_filtered ("Remote Threadinfo test\n");
9407 if (!get_and_display_threadinfo (&thread
))
9408 printf_filtered ("FAIL cannot get thread info\n");
9412 thread_display_step (threadref
*ref
, void *context
)
9414 /* output_threadid(" threadstep ",ref); *//* simple test */
9415 return get_and_display_threadinfo (ref
);
9419 threadlist_update_test_cmd (char *cmd
, int tty
)
9421 printf_filtered ("Remote Threadlist update test\n");
9422 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9426 init_remote_threadtests (void)
9428 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9429 _("Fetch and print the remote list of "
9430 "thread identifiers, one pkt only"));
9431 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9432 _("Fetch and display info about one thread"));
9433 add_com ("tset", class_obscure
, threadset_test_cmd
,
9434 _("Test setting to a different thread"));
9435 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9436 _("Iterate through updating all remote thread info"));
9437 add_com ("talive", class_obscure
, threadalive_test
,
9438 _(" Remote thread alive test "));
9443 /* Convert a thread ID to a string. Returns the string in a static
9447 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
9449 static char buf
[64];
9450 struct remote_state
*rs
= get_remote_state ();
9452 if (ptid_equal (ptid
, null_ptid
))
9453 return normal_pid_to_str (ptid
);
9454 else if (ptid_is_pid (ptid
))
9456 /* Printing an inferior target id. */
9458 /* When multi-process extensions are off, there's no way in the
9459 remote protocol to know the remote process id, if there's any
9460 at all. There's one exception --- when we're connected with
9461 target extended-remote, and we manually attached to a process
9462 with "attach PID". We don't record anywhere a flag that
9463 allows us to distinguish that case from the case of
9464 connecting with extended-remote and the stub already being
9465 attached to a process, and reporting yes to qAttached, hence
9466 no smart special casing here. */
9467 if (!remote_multi_process_p (rs
))
9469 xsnprintf (buf
, sizeof buf
, "Remote target");
9473 return normal_pid_to_str (ptid
);
9477 if (ptid_equal (magic_null_ptid
, ptid
))
9478 xsnprintf (buf
, sizeof buf
, "Thread <main>");
9479 else if (rs
->extended
&& remote_multi_process_p (rs
))
9480 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
9481 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
9483 xsnprintf (buf
, sizeof buf
, "Thread %ld",
9484 ptid_get_lwp (ptid
));
9489 /* Get the address of the thread local variable in OBJFILE which is
9490 stored at OFFSET within the thread local storage for thread PTID. */
9493 remote_get_thread_local_address (struct target_ops
*ops
,
9494 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
9496 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
9498 struct remote_state
*rs
= get_remote_state ();
9500 char *endp
= rs
->buf
+ get_remote_packet_size ();
9501 enum packet_result result
;
9503 strcpy (p
, "qGetTLSAddr:");
9505 p
= write_ptid (p
, endp
, ptid
);
9507 p
+= hexnumstr (p
, offset
);
9509 p
+= hexnumstr (p
, lm
);
9513 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9514 result
= packet_ok (rs
->buf
,
9515 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
9516 if (result
== PACKET_OK
)
9520 unpack_varlen_hex (rs
->buf
, &result
);
9523 else if (result
== PACKET_UNKNOWN
)
9524 throw_error (TLS_GENERIC_ERROR
,
9525 _("Remote target doesn't support qGetTLSAddr packet"));
9527 throw_error (TLS_GENERIC_ERROR
,
9528 _("Remote target failed to process qGetTLSAddr request"));
9531 throw_error (TLS_GENERIC_ERROR
,
9532 _("TLS not supported or disabled on this target"));
9537 /* Provide thread local base, i.e. Thread Information Block address.
9538 Returns 1 if ptid is found and thread_local_base is non zero. */
9541 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
9543 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
9545 struct remote_state
*rs
= get_remote_state ();
9547 char *endp
= rs
->buf
+ get_remote_packet_size ();
9548 enum packet_result result
;
9550 strcpy (p
, "qGetTIBAddr:");
9552 p
= write_ptid (p
, endp
, ptid
);
9556 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9557 result
= packet_ok (rs
->buf
,
9558 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
9559 if (result
== PACKET_OK
)
9563 unpack_varlen_hex (rs
->buf
, &result
);
9565 *addr
= (CORE_ADDR
) result
;
9568 else if (result
== PACKET_UNKNOWN
)
9569 error (_("Remote target doesn't support qGetTIBAddr packet"));
9571 error (_("Remote target failed to process qGetTIBAddr request"));
9574 error (_("qGetTIBAddr not supported or disabled on this target"));
9579 /* Support for inferring a target description based on the current
9580 architecture and the size of a 'g' packet. While the 'g' packet
9581 can have any size (since optional registers can be left off the
9582 end), some sizes are easily recognizable given knowledge of the
9583 approximate architecture. */
9585 struct remote_g_packet_guess
9588 const struct target_desc
*tdesc
;
9590 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
9591 DEF_VEC_O(remote_g_packet_guess_s
);
9593 struct remote_g_packet_data
9595 VEC(remote_g_packet_guess_s
) *guesses
;
9598 static struct gdbarch_data
*remote_g_packet_data_handle
;
9601 remote_g_packet_data_init (struct obstack
*obstack
)
9603 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
9607 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
9608 const struct target_desc
*tdesc
)
9610 struct remote_g_packet_data
*data
9611 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
9612 struct remote_g_packet_guess new_guess
, *guess
;
9615 gdb_assert (tdesc
!= NULL
);
9618 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9620 if (guess
->bytes
== bytes
)
9621 internal_error (__FILE__
, __LINE__
,
9622 _("Duplicate g packet description added for size %d"),
9625 new_guess
.bytes
= bytes
;
9626 new_guess
.tdesc
= tdesc
;
9627 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
9630 /* Return 1 if remote_read_description would do anything on this target
9631 and architecture, 0 otherwise. */
9634 remote_read_description_p (struct target_ops
*target
)
9636 struct remote_g_packet_data
*data
9637 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9639 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9645 static const struct target_desc
*
9646 remote_read_description (struct target_ops
*target
)
9648 struct remote_g_packet_data
*data
9649 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9651 /* Do not try this during initial connection, when we do not know
9652 whether there is a running but stopped thread. */
9653 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
9654 return target
->beneath
->to_read_description (target
->beneath
);
9656 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9658 struct remote_g_packet_guess
*guess
;
9660 int bytes
= send_g_packet ();
9663 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9665 if (guess
->bytes
== bytes
)
9666 return guess
->tdesc
;
9668 /* We discard the g packet. A minor optimization would be to
9669 hold on to it, and fill the register cache once we have selected
9670 an architecture, but it's too tricky to do safely. */
9673 return target
->beneath
->to_read_description (target
->beneath
);
9676 /* Remote file transfer support. This is host-initiated I/O, not
9677 target-initiated; for target-initiated, see remote-fileio.c. */
9679 /* If *LEFT is at least the length of STRING, copy STRING to
9680 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9681 decrease *LEFT. Otherwise raise an error. */
9684 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9686 int len
= strlen (string
);
9689 error (_("Packet too long for target."));
9691 memcpy (*buffer
, string
, len
);
9695 /* NUL-terminate the buffer as a convenience, if there is
9701 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9702 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9703 decrease *LEFT. Otherwise raise an error. */
9706 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9709 if (2 * len
> *left
)
9710 error (_("Packet too long for target."));
9712 bin2hex (bytes
, *buffer
, len
);
9716 /* NUL-terminate the buffer as a convenience, if there is
9722 /* If *LEFT is large enough, convert VALUE to hex and add it to
9723 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9724 decrease *LEFT. Otherwise raise an error. */
9727 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9729 int len
= hexnumlen (value
);
9732 error (_("Packet too long for target."));
9734 hexnumstr (*buffer
, value
);
9738 /* NUL-terminate the buffer as a convenience, if there is
9744 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9745 value, *REMOTE_ERRNO to the remote error number or zero if none
9746 was included, and *ATTACHMENT to point to the start of the annex
9747 if any. The length of the packet isn't needed here; there may
9748 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9750 Return 0 if the packet could be parsed, -1 if it could not. If
9751 -1 is returned, the other variables may not be initialized. */
9754 remote_hostio_parse_result (char *buffer
, int *retcode
,
9755 int *remote_errno
, char **attachment
)
9762 if (buffer
[0] != 'F')
9766 *retcode
= strtol (&buffer
[1], &p
, 16);
9767 if (errno
!= 0 || p
== &buffer
[1])
9770 /* Check for ",errno". */
9774 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9775 if (errno
!= 0 || p
+ 1 == p2
)
9780 /* Check for ";attachment". If there is no attachment, the
9781 packet should end here. */
9784 *attachment
= p
+ 1;
9787 else if (*p
== '\0')
9793 /* Send a prepared I/O packet to the target and read its response.
9794 The prepared packet is in the global RS->BUF before this function
9795 is called, and the answer is there when we return.
9797 COMMAND_BYTES is the length of the request to send, which may include
9798 binary data. WHICH_PACKET is the packet configuration to check
9799 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9800 is set to the error number and -1 is returned. Otherwise the value
9801 returned by the function is returned.
9803 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9804 attachment is expected; an error will be reported if there's a
9805 mismatch. If one is found, *ATTACHMENT will be set to point into
9806 the packet buffer and *ATTACHMENT_LEN will be set to the
9807 attachment's length. */
9810 remote_hostio_send_command (int command_bytes
, int which_packet
,
9811 int *remote_errno
, char **attachment
,
9812 int *attachment_len
)
9814 struct remote_state
*rs
= get_remote_state ();
9815 int ret
, bytes_read
;
9816 char *attachment_tmp
;
9818 if (!rs
->remote_desc
9819 || packet_support (which_packet
) == PACKET_DISABLE
)
9821 *remote_errno
= FILEIO_ENOSYS
;
9825 putpkt_binary (rs
->buf
, command_bytes
);
9826 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9828 /* If it timed out, something is wrong. Don't try to parse the
9832 *remote_errno
= FILEIO_EINVAL
;
9836 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9839 *remote_errno
= FILEIO_EINVAL
;
9841 case PACKET_UNKNOWN
:
9842 *remote_errno
= FILEIO_ENOSYS
;
9848 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9851 *remote_errno
= FILEIO_EINVAL
;
9855 /* Make sure we saw an attachment if and only if we expected one. */
9856 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9857 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9859 *remote_errno
= FILEIO_EINVAL
;
9863 /* If an attachment was found, it must point into the packet buffer;
9864 work out how many bytes there were. */
9865 if (attachment_tmp
!= NULL
)
9867 *attachment
= attachment_tmp
;
9868 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9874 /* Return nonzero if the filesystem accessed by the target_fileio_*
9875 methods is the local filesystem, zero otherwise. */
9878 remote_filesystem_is_local (struct target_ops
*self
)
9883 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9884 remote file descriptor, or -1 if an error occurs (and set
9888 remote_hostio_open (struct target_ops
*self
,
9889 const char *filename
, int flags
, int mode
,
9892 struct remote_state
*rs
= get_remote_state ();
9894 int left
= get_remote_packet_size () - 1;
9896 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9898 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9900 remote_buffer_add_string (&p
, &left
, ",");
9902 remote_buffer_add_int (&p
, &left
, flags
);
9903 remote_buffer_add_string (&p
, &left
, ",");
9905 remote_buffer_add_int (&p
, &left
, mode
);
9907 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9908 remote_errno
, NULL
, NULL
);
9911 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9912 Return the number of bytes written, or -1 if an error occurs (and
9913 set *REMOTE_ERRNO). */
9916 remote_hostio_pwrite (struct target_ops
*self
,
9917 int fd
, const gdb_byte
*write_buf
, int len
,
9918 ULONGEST offset
, int *remote_errno
)
9920 struct remote_state
*rs
= get_remote_state ();
9922 int left
= get_remote_packet_size ();
9925 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9927 remote_buffer_add_int (&p
, &left
, fd
);
9928 remote_buffer_add_string (&p
, &left
, ",");
9930 remote_buffer_add_int (&p
, &left
, offset
);
9931 remote_buffer_add_string (&p
, &left
, ",");
9933 p
+= remote_escape_output (write_buf
, len
, (gdb_byte
*) p
, &out_len
,
9934 get_remote_packet_size () - (p
- rs
->buf
));
9936 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9937 remote_errno
, NULL
, NULL
);
9940 /* Read up to LEN bytes FD on the remote target into READ_BUF
9941 Return the number of bytes read, or -1 if an error occurs (and
9942 set *REMOTE_ERRNO). */
9945 remote_hostio_pread (struct target_ops
*self
,
9946 int fd
, gdb_byte
*read_buf
, int len
,
9947 ULONGEST offset
, int *remote_errno
)
9949 struct remote_state
*rs
= get_remote_state ();
9952 int left
= get_remote_packet_size ();
9953 int ret
, attachment_len
;
9956 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9958 remote_buffer_add_int (&p
, &left
, fd
);
9959 remote_buffer_add_string (&p
, &left
, ",");
9961 remote_buffer_add_int (&p
, &left
, len
);
9962 remote_buffer_add_string (&p
, &left
, ",");
9964 remote_buffer_add_int (&p
, &left
, offset
);
9966 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9967 remote_errno
, &attachment
,
9973 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
9975 if (read_len
!= ret
)
9976 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9981 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9982 (and set *REMOTE_ERRNO). */
9985 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
9987 struct remote_state
*rs
= get_remote_state ();
9989 int left
= get_remote_packet_size () - 1;
9991 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9993 remote_buffer_add_int (&p
, &left
, fd
);
9995 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9996 remote_errno
, NULL
, NULL
);
9999 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
10000 occurs (and set *REMOTE_ERRNO). */
10003 remote_hostio_unlink (struct target_ops
*self
,
10004 const char *filename
, int *remote_errno
)
10006 struct remote_state
*rs
= get_remote_state ();
10008 int left
= get_remote_packet_size () - 1;
10010 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
10012 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10013 strlen (filename
));
10015 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
10016 remote_errno
, NULL
, NULL
);
10019 /* Read value of symbolic link FILENAME on the remote target. Return
10020 a null-terminated string allocated via xmalloc, or NULL if an error
10021 occurs (and set *REMOTE_ERRNO). */
10024 remote_hostio_readlink (struct target_ops
*self
,
10025 const char *filename
, int *remote_errno
)
10027 struct remote_state
*rs
= get_remote_state ();
10030 int left
= get_remote_packet_size ();
10031 int len
, attachment_len
;
10035 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
10037 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10038 strlen (filename
));
10040 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
10041 remote_errno
, &attachment
,
10047 ret
= xmalloc (len
+ 1);
10049 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10050 (gdb_byte
*) ret
, len
);
10051 if (read_len
!= len
)
10052 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
10058 /* Read information about the open file FD on the remote target
10059 into ST. Return 0 on success, or -1 if an error occurs (and
10060 set *REMOTE_ERRNO). */
10063 remote_hostio_fstat (struct target_ops
*self
,
10064 int fd
, struct stat
*st
,
10067 struct remote_state
*rs
= get_remote_state ();
10069 int left
= get_remote_packet_size ();
10070 int attachment_len
, ret
;
10072 struct fio_stat fst
;
10075 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
10077 remote_buffer_add_int (&p
, &left
, fd
);
10079 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
10080 remote_errno
, &attachment
,
10084 if (*remote_errno
!= FILEIO_ENOSYS
)
10087 /* Strictly we should return -1, ENOSYS here, but when
10088 "set sysroot remote:" was implemented in August 2008
10089 BFD's need for a stat function was sidestepped with
10090 this hack. This was not remedied until March 2015
10091 so we retain the previous behavior to avoid breaking
10094 Note that the memset is a March 2015 addition; older
10095 GDBs set st_size *and nothing else* so the structure
10096 would have garbage in all other fields. This might
10097 break something but retaining the previous behavior
10098 here would be just too wrong. */
10100 memset (st
, 0, sizeof (struct stat
));
10101 st
->st_size
= INT_MAX
;
10105 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10106 (gdb_byte
*) &fst
, sizeof (fst
));
10108 if (read_len
!= ret
)
10109 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
10111 if (read_len
!= sizeof (fst
))
10112 error (_("vFile:fstat returned %d bytes, but expecting %d."),
10113 read_len
, (int) sizeof (fst
));
10115 remote_fileio_to_host_stat (&fst
, st
);
10121 remote_fileio_errno_to_host (int errnum
)
10127 case FILEIO_ENOENT
:
10135 case FILEIO_EACCES
:
10137 case FILEIO_EFAULT
:
10141 case FILEIO_EEXIST
:
10143 case FILEIO_ENODEV
:
10145 case FILEIO_ENOTDIR
:
10147 case FILEIO_EISDIR
:
10149 case FILEIO_EINVAL
:
10151 case FILEIO_ENFILE
:
10153 case FILEIO_EMFILE
:
10157 case FILEIO_ENOSPC
:
10159 case FILEIO_ESPIPE
:
10163 case FILEIO_ENOSYS
:
10165 case FILEIO_ENAMETOOLONG
:
10166 return ENAMETOOLONG
;
10172 remote_hostio_error (int errnum
)
10174 int host_error
= remote_fileio_errno_to_host (errnum
);
10176 if (host_error
== -1)
10177 error (_("Unknown remote I/O error %d"), errnum
);
10179 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
10183 remote_hostio_close_cleanup (void *opaque
)
10185 int fd
= *(int *) opaque
;
10188 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
10192 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
10194 struct cleanup
*back_to
, *close_cleanup
;
10195 int retcode
, fd
, remote_errno
, bytes
, io_size
;
10198 int bytes_in_buffer
;
10201 struct remote_state
*rs
= get_remote_state ();
10203 if (!rs
->remote_desc
)
10204 error (_("command can only be used with remote target"));
10206 file
= gdb_fopen_cloexec (local_file
, "rb");
10208 perror_with_name (local_file
);
10209 back_to
= make_cleanup_fclose (file
);
10211 fd
= remote_hostio_open (find_target_at (process_stratum
),
10212 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
10214 0700, &remote_errno
);
10216 remote_hostio_error (remote_errno
);
10218 /* Send up to this many bytes at once. They won't all fit in the
10219 remote packet limit, so we'll transfer slightly fewer. */
10220 io_size
= get_remote_packet_size ();
10221 buffer
= xmalloc (io_size
);
10222 make_cleanup (xfree
, buffer
);
10224 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10226 bytes_in_buffer
= 0;
10229 while (bytes_in_buffer
|| !saw_eof
)
10233 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
10234 io_size
- bytes_in_buffer
,
10239 error (_("Error reading %s."), local_file
);
10242 /* EOF. Unless there is something still in the
10243 buffer from the last iteration, we are done. */
10245 if (bytes_in_buffer
== 0)
10253 bytes
+= bytes_in_buffer
;
10254 bytes_in_buffer
= 0;
10256 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
10258 offset
, &remote_errno
);
10261 remote_hostio_error (remote_errno
);
10262 else if (retcode
== 0)
10263 error (_("Remote write of %d bytes returned 0!"), bytes
);
10264 else if (retcode
< bytes
)
10266 /* Short write. Save the rest of the read data for the next
10268 bytes_in_buffer
= bytes
- retcode
;
10269 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
10275 discard_cleanups (close_cleanup
);
10276 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
10277 remote_hostio_error (remote_errno
);
10280 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
10281 do_cleanups (back_to
);
10285 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
10287 struct cleanup
*back_to
, *close_cleanup
;
10288 int fd
, remote_errno
, bytes
, io_size
;
10292 struct remote_state
*rs
= get_remote_state ();
10294 if (!rs
->remote_desc
)
10295 error (_("command can only be used with remote target"));
10297 fd
= remote_hostio_open (find_target_at (process_stratum
),
10298 remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
10300 remote_hostio_error (remote_errno
);
10302 file
= gdb_fopen_cloexec (local_file
, "wb");
10304 perror_with_name (local_file
);
10305 back_to
= make_cleanup_fclose (file
);
10307 /* Send up to this many bytes at once. They won't all fit in the
10308 remote packet limit, so we'll transfer slightly fewer. */
10309 io_size
= get_remote_packet_size ();
10310 buffer
= xmalloc (io_size
);
10311 make_cleanup (xfree
, buffer
);
10313 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10318 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
10319 fd
, buffer
, io_size
, offset
, &remote_errno
);
10321 /* Success, but no bytes, means end-of-file. */
10324 remote_hostio_error (remote_errno
);
10328 bytes
= fwrite (buffer
, 1, bytes
, file
);
10330 perror_with_name (local_file
);
10333 discard_cleanups (close_cleanup
);
10334 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
10335 remote_hostio_error (remote_errno
);
10338 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
10339 do_cleanups (back_to
);
10343 remote_file_delete (const char *remote_file
, int from_tty
)
10345 int retcode
, remote_errno
;
10346 struct remote_state
*rs
= get_remote_state ();
10348 if (!rs
->remote_desc
)
10349 error (_("command can only be used with remote target"));
10351 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
10352 remote_file
, &remote_errno
);
10354 remote_hostio_error (remote_errno
);
10357 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
10361 remote_put_command (char *args
, int from_tty
)
10363 struct cleanup
*back_to
;
10367 error_no_arg (_("file to put"));
10369 argv
= gdb_buildargv (args
);
10370 back_to
= make_cleanup_freeargv (argv
);
10371 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10372 error (_("Invalid parameters to remote put"));
10374 remote_file_put (argv
[0], argv
[1], from_tty
);
10376 do_cleanups (back_to
);
10380 remote_get_command (char *args
, int from_tty
)
10382 struct cleanup
*back_to
;
10386 error_no_arg (_("file to get"));
10388 argv
= gdb_buildargv (args
);
10389 back_to
= make_cleanup_freeargv (argv
);
10390 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10391 error (_("Invalid parameters to remote get"));
10393 remote_file_get (argv
[0], argv
[1], from_tty
);
10395 do_cleanups (back_to
);
10399 remote_delete_command (char *args
, int from_tty
)
10401 struct cleanup
*back_to
;
10405 error_no_arg (_("file to delete"));
10407 argv
= gdb_buildargv (args
);
10408 back_to
= make_cleanup_freeargv (argv
);
10409 if (argv
[0] == NULL
|| argv
[1] != NULL
)
10410 error (_("Invalid parameters to remote delete"));
10412 remote_file_delete (argv
[0], from_tty
);
10414 do_cleanups (back_to
);
10418 remote_command (char *args
, int from_tty
)
10420 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
10424 remote_can_execute_reverse (struct target_ops
*self
)
10426 if (packet_support (PACKET_bs
) == PACKET_ENABLE
10427 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
10434 remote_supports_non_stop (struct target_ops
*self
)
10440 remote_supports_disable_randomization (struct target_ops
*self
)
10442 /* Only supported in extended mode. */
10447 remote_supports_multi_process (struct target_ops
*self
)
10449 struct remote_state
*rs
= get_remote_state ();
10451 /* Only extended-remote handles being attached to multiple
10452 processes, even though plain remote can use the multi-process
10453 thread id extensions, so that GDB knows the target process's
10455 return rs
->extended
&& remote_multi_process_p (rs
);
10459 remote_supports_cond_tracepoints (void)
10461 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
10465 remote_supports_cond_breakpoints (struct target_ops
*self
)
10467 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
10471 remote_supports_fast_tracepoints (void)
10473 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
10477 remote_supports_static_tracepoints (void)
10479 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
10483 remote_supports_install_in_trace (void)
10485 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
10489 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
10491 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
10496 remote_supports_string_tracing (struct target_ops
*self
)
10498 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
10502 remote_can_run_breakpoint_commands (struct target_ops
*self
)
10504 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
10508 remote_trace_init (struct target_ops
*self
)
10511 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10512 if (strcmp (target_buf
, "OK") != 0)
10513 error (_("Target does not support this command."));
10516 static void free_actions_list (char **actions_list
);
10517 static void free_actions_list_cleanup_wrapper (void *);
10519 free_actions_list_cleanup_wrapper (void *al
)
10521 free_actions_list (al
);
10525 free_actions_list (char **actions_list
)
10529 if (actions_list
== 0)
10532 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
10533 xfree (actions_list
[ndx
]);
10535 xfree (actions_list
);
10538 /* Recursive routine to walk through command list including loops, and
10539 download packets for each command. */
10542 remote_download_command_source (int num
, ULONGEST addr
,
10543 struct command_line
*cmds
)
10545 struct remote_state
*rs
= get_remote_state ();
10546 struct command_line
*cmd
;
10548 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
10550 QUIT
; /* Allow user to bail out with ^C. */
10551 strcpy (rs
->buf
, "QTDPsrc:");
10552 encode_source_string (num
, addr
, "cmd", cmd
->line
,
10553 rs
->buf
+ strlen (rs
->buf
),
10554 rs
->buf_size
- strlen (rs
->buf
));
10556 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10557 if (strcmp (target_buf
, "OK"))
10558 warning (_("Target does not support source download."));
10560 if (cmd
->control_type
== while_control
10561 || cmd
->control_type
== while_stepping_control
)
10563 remote_download_command_source (num
, addr
, *cmd
->body_list
);
10565 QUIT
; /* Allow user to bail out with ^C. */
10566 strcpy (rs
->buf
, "QTDPsrc:");
10567 encode_source_string (num
, addr
, "cmd", "end",
10568 rs
->buf
+ strlen (rs
->buf
),
10569 rs
->buf_size
- strlen (rs
->buf
));
10571 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10572 if (strcmp (target_buf
, "OK"))
10573 warning (_("Target does not support source download."));
10579 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
10581 #define BUF_SIZE 2048
10585 char buf
[BUF_SIZE
];
10586 char **tdp_actions
;
10587 char **stepping_actions
;
10589 struct cleanup
*old_chain
= NULL
;
10590 struct agent_expr
*aexpr
;
10591 struct cleanup
*aexpr_chain
= NULL
;
10593 struct breakpoint
*b
= loc
->owner
;
10594 struct tracepoint
*t
= (struct tracepoint
*) b
;
10596 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
10597 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
10599 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
10602 tpaddr
= loc
->address
;
10603 sprintf_vma (addrbuf
, tpaddr
);
10604 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
10605 addrbuf
, /* address */
10606 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
10607 t
->step_count
, t
->pass_count
);
10608 /* Fast tracepoints are mostly handled by the target, but we can
10609 tell the target how big of an instruction block should be moved
10611 if (b
->type
== bp_fast_tracepoint
)
10613 /* Only test for support at download time; we may not know
10614 target capabilities at definition time. */
10615 if (remote_supports_fast_tracepoints ())
10619 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
10620 tpaddr
, &isize
, NULL
))
10621 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
10624 /* If it passed validation at definition but fails now,
10625 something is very wrong. */
10626 internal_error (__FILE__
, __LINE__
,
10627 _("Fast tracepoint not "
10628 "valid during download"));
10631 /* Fast tracepoints are functionally identical to regular
10632 tracepoints, so don't take lack of support as a reason to
10633 give up on the trace run. */
10634 warning (_("Target does not support fast tracepoints, "
10635 "downloading %d as regular tracepoint"), b
->number
);
10637 else if (b
->type
== bp_static_tracepoint
)
10639 /* Only test for support at download time; we may not know
10640 target capabilities at definition time. */
10641 if (remote_supports_static_tracepoints ())
10643 struct static_tracepoint_marker marker
;
10645 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
10646 strcat (buf
, ":S");
10648 error (_("Static tracepoint not valid during download"));
10651 /* Fast tracepoints are functionally identical to regular
10652 tracepoints, so don't take lack of support as a reason
10653 to give up on the trace run. */
10654 error (_("Target does not support static tracepoints"));
10656 /* If the tracepoint has a conditional, make it into an agent
10657 expression and append to the definition. */
10660 /* Only test support at download time, we may not know target
10661 capabilities at definition time. */
10662 if (remote_supports_cond_tracepoints ())
10664 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
10665 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
10666 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
10668 pkt
= buf
+ strlen (buf
);
10669 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
10670 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
10672 do_cleanups (aexpr_chain
);
10675 warning (_("Target does not support conditional tracepoints, "
10676 "ignoring tp %d cond"), b
->number
);
10679 if (b
->commands
|| *default_collect
)
10682 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10683 if (strcmp (target_buf
, "OK"))
10684 error (_("Target does not support tracepoints."));
10686 /* do_single_steps (t); */
10689 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
10691 QUIT
; /* Allow user to bail out with ^C. */
10692 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
10693 b
->number
, addrbuf
, /* address */
10695 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
10698 remote_get_noisy_reply (&target_buf
,
10700 if (strcmp (target_buf
, "OK"))
10701 error (_("Error on target while setting tracepoints."));
10704 if (stepping_actions
)
10706 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10708 QUIT
; /* Allow user to bail out with ^C. */
10709 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
10710 b
->number
, addrbuf
, /* address */
10711 ((ndx
== 0) ? "S" : ""),
10712 stepping_actions
[ndx
],
10713 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10715 remote_get_noisy_reply (&target_buf
,
10717 if (strcmp (target_buf
, "OK"))
10718 error (_("Error on target while setting tracepoints."));
10722 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
10724 if (b
->addr_string
)
10726 strcpy (buf
, "QTDPsrc:");
10727 encode_source_string (b
->number
, loc
->address
,
10728 "at", b
->addr_string
, buf
+ strlen (buf
),
10729 2048 - strlen (buf
));
10732 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10733 if (strcmp (target_buf
, "OK"))
10734 warning (_("Target does not support source download."));
10736 if (b
->cond_string
)
10738 strcpy (buf
, "QTDPsrc:");
10739 encode_source_string (b
->number
, loc
->address
,
10740 "cond", b
->cond_string
, buf
+ strlen (buf
),
10741 2048 - strlen (buf
));
10743 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10744 if (strcmp (target_buf
, "OK"))
10745 warning (_("Target does not support source download."));
10747 remote_download_command_source (b
->number
, loc
->address
,
10748 breakpoint_commands (b
));
10751 do_cleanups (old_chain
);
10755 remote_can_download_tracepoint (struct target_ops
*self
)
10757 struct remote_state
*rs
= get_remote_state ();
10758 struct trace_status
*ts
;
10761 /* Don't try to install tracepoints until we've relocated our
10762 symbols, and fetched and merged the target's tracepoint list with
10764 if (rs
->starting_up
)
10767 ts
= current_trace_status ();
10768 status
= remote_get_trace_status (self
, ts
);
10770 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10773 /* If we are in a tracing experiment, but remote stub doesn't support
10774 installing tracepoint in trace, we have to return. */
10775 if (!remote_supports_install_in_trace ())
10783 remote_download_trace_state_variable (struct target_ops
*self
,
10784 struct trace_state_variable
*tsv
)
10786 struct remote_state
*rs
= get_remote_state ();
10789 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
10790 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
10792 p
= rs
->buf
+ strlen (rs
->buf
);
10793 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10794 error (_("Trace state variable name too long for tsv definition packet"));
10795 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
10798 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10799 if (*target_buf
== '\0')
10800 error (_("Target does not support this command."));
10801 if (strcmp (target_buf
, "OK") != 0)
10802 error (_("Error on target while downloading trace state variable."));
10806 remote_enable_tracepoint (struct target_ops
*self
,
10807 struct bp_location
*location
)
10809 struct remote_state
*rs
= get_remote_state ();
10812 sprintf_vma (addr_buf
, location
->address
);
10813 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
10814 location
->owner
->number
, addr_buf
);
10816 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10817 if (*rs
->buf
== '\0')
10818 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10819 if (strcmp (rs
->buf
, "OK") != 0)
10820 error (_("Error on target while enabling tracepoint."));
10824 remote_disable_tracepoint (struct target_ops
*self
,
10825 struct bp_location
*location
)
10827 struct remote_state
*rs
= get_remote_state ();
10830 sprintf_vma (addr_buf
, location
->address
);
10831 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
10832 location
->owner
->number
, addr_buf
);
10834 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10835 if (*rs
->buf
== '\0')
10836 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10837 if (strcmp (rs
->buf
, "OK") != 0)
10838 error (_("Error on target while disabling tracepoint."));
10842 remote_trace_set_readonly_regions (struct target_ops
*self
)
10846 bfd_size_type size
;
10852 return; /* No information to give. */
10854 strcpy (target_buf
, "QTro");
10855 offset
= strlen (target_buf
);
10856 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10858 char tmp1
[40], tmp2
[40];
10861 if ((s
->flags
& SEC_LOAD
) == 0 ||
10862 /* (s->flags & SEC_CODE) == 0 || */
10863 (s
->flags
& SEC_READONLY
) == 0)
10867 vma
= bfd_get_section_vma (abfd
, s
);
10868 size
= bfd_get_section_size (s
);
10869 sprintf_vma (tmp1
, vma
);
10870 sprintf_vma (tmp2
, vma
+ size
);
10871 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10872 if (offset
+ sec_length
+ 1 > target_buf_size
)
10874 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
10876 Too many sections for read-only sections definition packet."));
10879 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
10881 offset
+= sec_length
;
10885 putpkt (target_buf
);
10886 getpkt (&target_buf
, &target_buf_size
, 0);
10891 remote_trace_start (struct target_ops
*self
)
10893 putpkt ("QTStart");
10894 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10895 if (*target_buf
== '\0')
10896 error (_("Target does not support this command."));
10897 if (strcmp (target_buf
, "OK") != 0)
10898 error (_("Bogus reply from target: %s"), target_buf
);
10902 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
10904 /* Initialize it just to avoid a GCC false warning. */
10906 /* FIXME we need to get register block size some other way. */
10907 extern int trace_regblock_size
;
10908 enum packet_result result
;
10910 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
10913 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10915 putpkt ("qTStatus");
10919 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10921 CATCH (ex
, RETURN_MASK_ERROR
)
10923 if (ex
.error
!= TARGET_CLOSE_ERROR
)
10925 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10928 throw_exception (ex
);
10932 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
10934 /* If the remote target doesn't do tracing, flag it. */
10935 if (result
== PACKET_UNKNOWN
)
10938 /* We're working with a live target. */
10939 ts
->filename
= NULL
;
10942 error (_("Bogus trace status reply from target: %s"), target_buf
);
10944 /* Function 'parse_trace_status' sets default value of each field of
10945 'ts' at first, so we don't have to do it here. */
10946 parse_trace_status (p
, ts
);
10948 return ts
->running
;
10952 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
10953 struct uploaded_tp
*utp
)
10955 struct remote_state
*rs
= get_remote_state ();
10957 struct bp_location
*loc
;
10958 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10959 size_t size
= get_remote_packet_size ();
10963 tp
->base
.hit_count
= 0;
10964 tp
->traceframe_usage
= 0;
10965 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10967 /* If the tracepoint was never downloaded, don't go asking for
10969 if (tp
->number_on_target
== 0)
10971 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
10972 phex_nz (loc
->address
, 0));
10974 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10975 if (reply
&& *reply
)
10978 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10984 utp
->hit_count
= 0;
10985 utp
->traceframe_usage
= 0;
10986 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
10987 phex_nz (utp
->addr
, 0));
10989 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10990 if (reply
&& *reply
)
10993 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10999 remote_trace_stop (struct target_ops
*self
)
11002 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11003 if (*target_buf
== '\0')
11004 error (_("Target does not support this command."));
11005 if (strcmp (target_buf
, "OK") != 0)
11006 error (_("Bogus reply from target: %s"), target_buf
);
11010 remote_trace_find (struct target_ops
*self
,
11011 enum trace_find_type type
, int num
,
11012 CORE_ADDR addr1
, CORE_ADDR addr2
,
11015 struct remote_state
*rs
= get_remote_state ();
11016 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11018 int target_frameno
= -1, target_tracept
= -1;
11020 /* Lookups other than by absolute frame number depend on the current
11021 trace selected, so make sure it is correct on the remote end
11023 if (type
!= tfind_number
)
11024 set_remote_traceframe ();
11027 strcpy (p
, "QTFrame:");
11028 p
= strchr (p
, '\0');
11032 xsnprintf (p
, endbuf
- p
, "%x", num
);
11035 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
11038 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
11041 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
11042 phex_nz (addr2
, 0));
11044 case tfind_outside
:
11045 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
11046 phex_nz (addr2
, 0));
11049 error (_("Unknown trace find type %d"), type
);
11053 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
11054 if (*reply
== '\0')
11055 error (_("Target does not support this command."));
11057 while (reply
&& *reply
)
11062 target_frameno
= (int) strtol (p
, &reply
, 16);
11064 error (_("Unable to parse trace frame number"));
11065 /* Don't update our remote traceframe number cache on failure
11066 to select a remote traceframe. */
11067 if (target_frameno
== -1)
11072 target_tracept
= (int) strtol (p
, &reply
, 16);
11074 error (_("Unable to parse tracepoint number"));
11076 case 'O': /* "OK"? */
11077 if (reply
[1] == 'K' && reply
[2] == '\0')
11080 error (_("Bogus reply from target: %s"), reply
);
11083 error (_("Bogus reply from target: %s"), reply
);
11086 *tpp
= target_tracept
;
11088 rs
->remote_traceframe_number
= target_frameno
;
11089 return target_frameno
;
11093 remote_get_trace_state_variable_value (struct target_ops
*self
,
11094 int tsvnum
, LONGEST
*val
)
11096 struct remote_state
*rs
= get_remote_state ();
11100 set_remote_traceframe ();
11102 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
11104 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11105 if (reply
&& *reply
)
11109 unpack_varlen_hex (reply
+ 1, &uval
);
11110 *val
= (LONGEST
) uval
;
11118 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
11120 struct remote_state
*rs
= get_remote_state ();
11124 strcpy (p
, "QTSave:");
11126 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
11127 error (_("Remote file name too long for trace save packet"));
11128 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
11131 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11132 if (*reply
== '\0')
11133 error (_("Target does not support this command."));
11134 if (strcmp (reply
, "OK") != 0)
11135 error (_("Bogus reply from target: %s"), reply
);
11139 /* This is basically a memory transfer, but needs to be its own packet
11140 because we don't know how the target actually organizes its trace
11141 memory, plus we want to be able to ask for as much as possible, but
11142 not be unhappy if we don't get as much as we ask for. */
11145 remote_get_raw_trace_data (struct target_ops
*self
,
11146 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
11148 struct remote_state
*rs
= get_remote_state ();
11154 strcpy (p
, "qTBuffer:");
11156 p
+= hexnumstr (p
, offset
);
11158 p
+= hexnumstr (p
, len
);
11162 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11163 if (reply
&& *reply
)
11165 /* 'l' by itself means we're at the end of the buffer and
11166 there is nothing more to get. */
11170 /* Convert the reply into binary. Limit the number of bytes to
11171 convert according to our passed-in buffer size, rather than
11172 what was returned in the packet; if the target is
11173 unexpectedly generous and gives us a bigger reply than we
11174 asked for, we don't want to crash. */
11175 rslt
= hex2bin (target_buf
, buf
, len
);
11179 /* Something went wrong, flag as an error. */
11184 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
11186 struct remote_state
*rs
= get_remote_state ();
11188 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
11192 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
11194 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11195 if (*reply
== '\0')
11196 error (_("Target does not support this command."));
11197 if (strcmp (reply
, "OK") != 0)
11198 error (_("Bogus reply from target: %s"), reply
);
11201 warning (_("Target does not support disconnected tracing."));
11205 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
11207 struct thread_info
*info
= find_thread_ptid (ptid
);
11209 if (info
&& info
->priv
)
11210 return info
->priv
->core
;
11215 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
11217 struct remote_state
*rs
= get_remote_state ();
11220 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
11222 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11223 if (*reply
== '\0')
11224 error (_("Target does not support this command."));
11225 if (strcmp (reply
, "OK") != 0)
11226 error (_("Bogus reply from target: %s"), reply
);
11229 static struct traceframe_info
*
11230 remote_traceframe_info (struct target_ops
*self
)
11234 text
= target_read_stralloc (¤t_target
,
11235 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
11238 struct traceframe_info
*info
;
11239 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
11241 info
= parse_traceframe_info (text
);
11242 do_cleanups (back_to
);
11249 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11250 instruction on which a fast tracepoint may be placed. Returns -1
11251 if the packet is not supported, and 0 if the minimum instruction
11252 length is unknown. */
11255 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
11257 struct remote_state
*rs
= get_remote_state ();
11260 /* If we're not debugging a process yet, the IPA can't be
11262 if (!target_has_execution
)
11265 /* Make sure the remote is pointing at the right process. */
11266 set_general_process ();
11268 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
11270 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11271 if (*reply
== '\0')
11275 ULONGEST min_insn_len
;
11277 unpack_varlen_hex (reply
, &min_insn_len
);
11279 return (int) min_insn_len
;
11284 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
11286 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
11288 struct remote_state
*rs
= get_remote_state ();
11289 char *buf
= rs
->buf
;
11290 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11291 enum packet_result result
;
11293 gdb_assert (val
>= 0 || val
== -1);
11294 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
11295 /* Send -1 as literal "-1" to avoid host size dependency. */
11299 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
11302 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
11305 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11306 result
= packet_ok (rs
->buf
,
11307 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
11309 if (result
!= PACKET_OK
)
11310 warning (_("Bogus reply from target: %s"), rs
->buf
);
11315 remote_set_trace_notes (struct target_ops
*self
,
11316 const char *user
, const char *notes
,
11317 const char *stop_notes
)
11319 struct remote_state
*rs
= get_remote_state ();
11321 char *buf
= rs
->buf
;
11322 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11325 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
11328 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
11329 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
11335 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
11336 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
11342 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
11343 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
11347 /* Ensure the buffer is terminated. */
11351 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11352 if (*reply
== '\0')
11355 if (strcmp (reply
, "OK") != 0)
11356 error (_("Bogus reply from target: %s"), reply
);
11362 remote_use_agent (struct target_ops
*self
, int use
)
11364 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
11366 struct remote_state
*rs
= get_remote_state ();
11368 /* If the stub supports QAgent. */
11369 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
11371 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11373 if (strcmp (rs
->buf
, "OK") == 0)
11384 remote_can_use_agent (struct target_ops
*self
)
11386 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
11389 struct btrace_target_info
11391 /* The ptid of the traced thread. */
11394 /* The obtained branch trace configuration. */
11395 struct btrace_config conf
;
11398 /* Reset our idea of our target's btrace configuration. */
11401 remote_btrace_reset (void)
11403 struct remote_state
*rs
= get_remote_state ();
11405 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
11408 /* Check whether the target supports branch tracing. */
11411 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
11413 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
11415 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
11420 case BTRACE_FORMAT_NONE
:
11423 case BTRACE_FORMAT_BTS
:
11424 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
11427 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
11430 /* Synchronize the configuration with the target. */
11433 btrace_sync_conf (const struct btrace_config
*conf
)
11435 struct packet_config
*packet
;
11436 struct remote_state
*rs
;
11437 char *buf
, *pos
, *endbuf
;
11439 rs
= get_remote_state ();
11441 endbuf
= buf
+ get_remote_packet_size ();
11443 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
11444 if (packet_config_support (packet
) == PACKET_ENABLE
11445 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
11448 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
11452 getpkt (&buf
, &rs
->buf_size
, 0);
11454 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
11456 if (buf
[0] == 'E' && buf
[1] == '.')
11457 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
11459 error (_("Failed to configure the BTS buffer size."));
11462 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
11466 /* Read the current thread's btrace configuration from the target and
11467 store it into CONF. */
11470 btrace_read_config (struct btrace_config
*conf
)
11474 xml
= target_read_stralloc (¤t_target
,
11475 TARGET_OBJECT_BTRACE_CONF
, "");
11478 struct cleanup
*cleanup
;
11480 cleanup
= make_cleanup (xfree
, xml
);
11481 parse_xml_btrace_conf (conf
, xml
);
11482 do_cleanups (cleanup
);
11486 /* Enable branch tracing. */
11488 static struct btrace_target_info
*
11489 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
11490 const struct btrace_config
*conf
)
11492 struct btrace_target_info
*tinfo
= NULL
;
11493 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
11494 struct remote_state
*rs
= get_remote_state ();
11495 char *buf
= rs
->buf
;
11496 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11498 if (packet_config_support (packet
) != PACKET_ENABLE
)
11499 error (_("Target does not support branch tracing."));
11501 btrace_sync_conf (conf
);
11503 set_general_thread (ptid
);
11505 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11507 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11509 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11511 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11512 error (_("Could not enable branch tracing for %s: %s"),
11513 target_pid_to_str (ptid
), rs
->buf
+ 2);
11515 error (_("Could not enable branch tracing for %s."),
11516 target_pid_to_str (ptid
));
11519 tinfo
= xzalloc (sizeof (*tinfo
));
11520 tinfo
->ptid
= ptid
;
11522 /* If we fail to read the configuration, we lose some information, but the
11523 tracing itself is not impacted. */
11526 btrace_read_config (&tinfo
->conf
);
11528 CATCH (err
, RETURN_MASK_ERROR
)
11530 if (err
.message
!= NULL
)
11531 warning ("%s", err
.message
);
11538 /* Disable branch tracing. */
11541 remote_disable_btrace (struct target_ops
*self
,
11542 struct btrace_target_info
*tinfo
)
11544 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
11545 struct remote_state
*rs
= get_remote_state ();
11546 char *buf
= rs
->buf
;
11547 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11549 if (packet_config_support (packet
) != PACKET_ENABLE
)
11550 error (_("Target does not support branch tracing."));
11552 set_general_thread (tinfo
->ptid
);
11554 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
11556 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11558 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
11560 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
11561 error (_("Could not disable branch tracing for %s: %s"),
11562 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
11564 error (_("Could not disable branch tracing for %s."),
11565 target_pid_to_str (tinfo
->ptid
));
11571 /* Teardown branch tracing. */
11574 remote_teardown_btrace (struct target_ops
*self
,
11575 struct btrace_target_info
*tinfo
)
11577 /* We must not talk to the target during teardown. */
11581 /* Read the branch trace. */
11583 static enum btrace_error
11584 remote_read_btrace (struct target_ops
*self
,
11585 struct btrace_data
*btrace
,
11586 struct btrace_target_info
*tinfo
,
11587 enum btrace_read_type type
)
11589 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
11590 struct remote_state
*rs
= get_remote_state ();
11591 struct cleanup
*cleanup
;
11595 if (packet_config_support (packet
) != PACKET_ENABLE
)
11596 error (_("Target does not support branch tracing."));
11598 #if !defined(HAVE_LIBEXPAT)
11599 error (_("Cannot process branch tracing result. XML parsing not supported."));
11604 case BTRACE_READ_ALL
:
11607 case BTRACE_READ_NEW
:
11610 case BTRACE_READ_DELTA
:
11614 internal_error (__FILE__
, __LINE__
,
11615 _("Bad branch tracing read type: %u."),
11616 (unsigned int) type
);
11619 xml
= target_read_stralloc (¤t_target
,
11620 TARGET_OBJECT_BTRACE
, annex
);
11622 return BTRACE_ERR_UNKNOWN
;
11624 cleanup
= make_cleanup (xfree
, xml
);
11625 parse_xml_btrace (btrace
, xml
);
11626 do_cleanups (cleanup
);
11628 return BTRACE_ERR_NONE
;
11631 static const struct btrace_config
*
11632 remote_btrace_conf (struct target_ops
*self
,
11633 const struct btrace_target_info
*tinfo
)
11635 return &tinfo
->conf
;
11639 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
11641 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
11645 /* Implementation of to_load. */
11648 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
11650 generic_load (name
, from_tty
);
11653 /* Accepts an integer PID; returns a string representing a file that
11654 can be opened on the remote side to get the symbols for the child
11655 process. Returns NULL if the operation is not supported. */
11658 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
11660 static char *filename
= NULL
;
11663 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
11666 if (filename
!= NULL
)
11669 xsnprintf (annex
, sizeof (annex
), "%x", pid
);
11670 filename
= target_read_stralloc (¤t_target
,
11671 TARGET_OBJECT_EXEC_FILE
, annex
);
11677 init_remote_ops (void)
11679 remote_ops
.to_shortname
= "remote";
11680 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
11681 remote_ops
.to_doc
=
11682 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11683 Specify the serial device it is connected to\n\
11684 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
11685 remote_ops
.to_open
= remote_open
;
11686 remote_ops
.to_close
= remote_close
;
11687 remote_ops
.to_detach
= remote_detach
;
11688 remote_ops
.to_disconnect
= remote_disconnect
;
11689 remote_ops
.to_resume
= remote_resume
;
11690 remote_ops
.to_wait
= remote_wait
;
11691 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
11692 remote_ops
.to_store_registers
= remote_store_registers
;
11693 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
11694 remote_ops
.to_files_info
= remote_files_info
;
11695 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
11696 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
11697 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
11698 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
11699 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
11700 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
11701 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
11702 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
11703 remote_ops
.to_watchpoint_addr_within_range
=
11704 remote_watchpoint_addr_within_range
;
11705 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
11706 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
11707 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
11708 remote_ops
.to_region_ok_for_hw_watchpoint
11709 = remote_region_ok_for_hw_watchpoint
;
11710 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
11711 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
11712 remote_ops
.to_kill
= remote_kill
;
11713 remote_ops
.to_load
= remote_load
;
11714 remote_ops
.to_mourn_inferior
= remote_mourn
;
11715 remote_ops
.to_pass_signals
= remote_pass_signals
;
11716 remote_ops
.to_program_signals
= remote_program_signals
;
11717 remote_ops
.to_thread_alive
= remote_thread_alive
;
11718 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
11719 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
11720 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
11721 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
11722 remote_ops
.to_stop
= remote_stop
;
11723 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
11724 remote_ops
.to_rcmd
= remote_rcmd
;
11725 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
11726 remote_ops
.to_log_command
= serial_log_command
;
11727 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
11728 remote_ops
.to_stratum
= process_stratum
;
11729 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
11730 remote_ops
.to_has_memory
= default_child_has_memory
;
11731 remote_ops
.to_has_stack
= default_child_has_stack
;
11732 remote_ops
.to_has_registers
= default_child_has_registers
;
11733 remote_ops
.to_has_execution
= default_child_has_execution
;
11734 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
11735 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
11736 remote_ops
.to_magic
= OPS_MAGIC
;
11737 remote_ops
.to_memory_map
= remote_memory_map
;
11738 remote_ops
.to_flash_erase
= remote_flash_erase
;
11739 remote_ops
.to_flash_done
= remote_flash_done
;
11740 remote_ops
.to_read_description
= remote_read_description
;
11741 remote_ops
.to_search_memory
= remote_search_memory
;
11742 remote_ops
.to_can_async_p
= remote_can_async_p
;
11743 remote_ops
.to_is_async_p
= remote_is_async_p
;
11744 remote_ops
.to_async
= remote_async
;
11745 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
11746 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
11747 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
11748 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
11749 remote_ops
.to_supports_disable_randomization
11750 = remote_supports_disable_randomization
;
11751 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
11752 remote_ops
.to_fileio_open
= remote_hostio_open
;
11753 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
11754 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
11755 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
11756 remote_ops
.to_fileio_close
= remote_hostio_close
;
11757 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
11758 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
11759 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
11760 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
11761 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
11762 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
11763 remote_ops
.to_trace_init
= remote_trace_init
;
11764 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
11765 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
11766 remote_ops
.to_download_trace_state_variable
11767 = remote_download_trace_state_variable
;
11768 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
11769 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
11770 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
11771 remote_ops
.to_trace_start
= remote_trace_start
;
11772 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
11773 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
11774 remote_ops
.to_trace_stop
= remote_trace_stop
;
11775 remote_ops
.to_trace_find
= remote_trace_find
;
11776 remote_ops
.to_get_trace_state_variable_value
11777 = remote_get_trace_state_variable_value
;
11778 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
11779 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
11780 remote_ops
.to_upload_trace_state_variables
11781 = remote_upload_trace_state_variables
;
11782 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
11783 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
11784 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
11785 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
11786 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
11787 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
11788 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
11789 remote_ops
.to_verify_memory
= remote_verify_memory
;
11790 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
11791 remote_ops
.to_set_permissions
= remote_set_permissions
;
11792 remote_ops
.to_static_tracepoint_marker_at
11793 = remote_static_tracepoint_marker_at
;
11794 remote_ops
.to_static_tracepoint_markers_by_strid
11795 = remote_static_tracepoint_markers_by_strid
;
11796 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
11797 remote_ops
.to_use_agent
= remote_use_agent
;
11798 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
11799 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
11800 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
11801 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
11802 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
11803 remote_ops
.to_read_btrace
= remote_read_btrace
;
11804 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
11805 remote_ops
.to_augmented_libraries_svr4_read
=
11806 remote_augmented_libraries_svr4_read
;
11809 /* Set up the extended remote vector by making a copy of the standard
11810 remote vector and adding to it. */
11813 init_extended_remote_ops (void)
11815 extended_remote_ops
= remote_ops
;
11817 extended_remote_ops
.to_shortname
= "extended-remote";
11818 extended_remote_ops
.to_longname
=
11819 "Extended remote serial target in gdb-specific protocol";
11820 extended_remote_ops
.to_doc
=
11821 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11822 Specify the serial device it is connected to (e.g. /dev/ttya).";
11823 extended_remote_ops
.to_open
= extended_remote_open
;
11824 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
11825 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
11826 extended_remote_ops
.to_detach
= extended_remote_detach
;
11827 extended_remote_ops
.to_attach
= extended_remote_attach
;
11828 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
11829 extended_remote_ops
.to_kill
= extended_remote_kill
;
11830 extended_remote_ops
.to_supports_disable_randomization
11831 = extended_remote_supports_disable_randomization
;
11835 remote_can_async_p (struct target_ops
*ops
)
11837 struct remote_state
*rs
= get_remote_state ();
11839 if (!target_async_permitted
)
11840 /* We only enable async when the user specifically asks for it. */
11843 /* We're async whenever the serial device is. */
11844 return serial_can_async_p (rs
->remote_desc
);
11848 remote_is_async_p (struct target_ops
*ops
)
11850 struct remote_state
*rs
= get_remote_state ();
11852 if (!target_async_permitted
)
11853 /* We only enable async when the user specifically asks for it. */
11856 /* We're async whenever the serial device is. */
11857 return serial_is_async_p (rs
->remote_desc
);
11860 /* Pass the SERIAL event on and up to the client. One day this code
11861 will be able to delay notifying the client of an event until the
11862 point where an entire packet has been received. */
11864 static serial_event_ftype remote_async_serial_handler
;
11867 remote_async_serial_handler (struct serial
*scb
, void *context
)
11869 struct remote_state
*rs
= context
;
11871 /* Don't propogate error information up to the client. Instead let
11872 the client find out about the error by querying the target. */
11873 inferior_event_handler (INF_REG_EVENT
, NULL
);
11877 remote_async_inferior_event_handler (gdb_client_data data
)
11879 inferior_event_handler (INF_REG_EVENT
, NULL
);
11883 remote_async (struct target_ops
*ops
, int enable
)
11885 struct remote_state
*rs
= get_remote_state ();
11889 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
11891 /* If there are pending events in the stop reply queue tell the
11892 event loop to process them. */
11893 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
11894 mark_async_event_handler (remote_async_inferior_event_token
);
11898 serial_async (rs
->remote_desc
, NULL
, NULL
);
11899 clear_async_event_handler (remote_async_inferior_event_token
);
11904 set_remote_cmd (char *args
, int from_tty
)
11906 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
11910 show_remote_cmd (char *args
, int from_tty
)
11912 /* We can't just use cmd_show_list here, because we want to skip
11913 the redundant "show remote Z-packet" and the legacy aliases. */
11914 struct cleanup
*showlist_chain
;
11915 struct cmd_list_element
*list
= remote_show_cmdlist
;
11916 struct ui_out
*uiout
= current_uiout
;
11918 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
11919 for (; list
!= NULL
; list
= list
->next
)
11920 if (strcmp (list
->name
, "Z-packet") == 0)
11922 else if (list
->type
== not_set_cmd
)
11923 /* Alias commands are exactly like the original, except they
11924 don't have the normal type. */
11928 struct cleanup
*option_chain
11929 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
11931 ui_out_field_string (uiout
, "name", list
->name
);
11932 ui_out_text (uiout
, ": ");
11933 if (list
->type
== show_cmd
)
11934 do_show_command ((char *) NULL
, from_tty
, list
);
11936 cmd_func (list
, NULL
, from_tty
);
11937 /* Close the tuple. */
11938 do_cleanups (option_chain
);
11941 /* Close the tuple. */
11942 do_cleanups (showlist_chain
);
11946 /* Function to be called whenever a new objfile (shlib) is detected. */
11948 remote_new_objfile (struct objfile
*objfile
)
11950 struct remote_state
*rs
= get_remote_state ();
11952 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
11953 remote_check_symbols ();
11956 /* Pull all the tracepoints defined on the target and create local
11957 data structures representing them. We don't want to create real
11958 tracepoints yet, we don't want to mess up the user's existing
11962 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
11964 struct remote_state
*rs
= get_remote_state ();
11967 /* Ask for a first packet of tracepoint definition. */
11969 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11971 while (*p
&& *p
!= 'l')
11973 parse_tracepoint_definition (p
, utpp
);
11974 /* Ask for another packet of tracepoint definition. */
11976 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11983 remote_upload_trace_state_variables (struct target_ops
*self
,
11984 struct uploaded_tsv
**utsvp
)
11986 struct remote_state
*rs
= get_remote_state ();
11989 /* Ask for a first packet of variable definition. */
11991 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11993 while (*p
&& *p
!= 'l')
11995 parse_tsv_definition (p
, utsvp
);
11996 /* Ask for another packet of variable definition. */
11998 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12004 /* The "set/show range-stepping" show hook. */
12007 show_range_stepping (struct ui_file
*file
, int from_tty
,
12008 struct cmd_list_element
*c
,
12011 fprintf_filtered (file
,
12012 _("Debugger's willingness to use range stepping "
12013 "is %s.\n"), value
);
12016 /* The "set/show range-stepping" set hook. */
12019 set_range_stepping (char *ignore_args
, int from_tty
,
12020 struct cmd_list_element
*c
)
12022 struct remote_state
*rs
= get_remote_state ();
12024 /* Whene enabling, check whether range stepping is actually
12025 supported by the target, and warn if not. */
12026 if (use_range_stepping
)
12028 if (rs
->remote_desc
!= NULL
)
12030 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
12031 remote_vcont_probe (rs
);
12033 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
12034 && rs
->supports_vCont
.r
)
12038 warning (_("Range stepping is not supported by the current target"));
12043 _initialize_remote (void)
12045 struct remote_state
*rs
;
12046 struct cmd_list_element
*cmd
;
12047 const char *cmd_name
;
12049 /* architecture specific data */
12050 remote_gdbarch_data_handle
=
12051 gdbarch_data_register_post_init (init_remote_state
);
12052 remote_g_packet_data_handle
=
12053 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
12055 /* Initialize the per-target state. At the moment there is only one
12056 of these, not one per target. Only one target is active at a
12058 remote_state
= new_remote_state ();
12060 init_remote_ops ();
12061 add_target (&remote_ops
);
12063 init_extended_remote_ops ();
12064 add_target (&extended_remote_ops
);
12066 /* Hook into new objfile notification. */
12067 observer_attach_new_objfile (remote_new_objfile
);
12068 /* We're no longer interested in notification events of an inferior
12070 observer_attach_inferior_exit (discard_pending_stop_replies
);
12072 /* Set up signal handlers. */
12073 async_sigint_remote_token
=
12074 create_async_signal_handler (async_remote_interrupt
, NULL
);
12075 async_sigint_remote_twice_token
=
12076 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
12079 init_remote_threadtests ();
12082 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
12083 /* set/show remote ... */
12085 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
12086 Remote protocol specific variables\n\
12087 Configure various remote-protocol specific variables such as\n\
12088 the packets being used"),
12089 &remote_set_cmdlist
, "set remote ",
12090 0 /* allow-unknown */, &setlist
);
12091 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
12092 Remote protocol specific variables\n\
12093 Configure various remote-protocol specific variables such as\n\
12094 the packets being used"),
12095 &remote_show_cmdlist
, "show remote ",
12096 0 /* allow-unknown */, &showlist
);
12098 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
12099 Compare section data on target to the exec file.\n\
12100 Argument is a single section name (default: all loaded sections).\n\
12101 To compare only read-only loaded sections, specify the -r option."),
12104 add_cmd ("packet", class_maintenance
, packet_command
, _("\
12105 Send an arbitrary packet to a remote target.\n\
12106 maintenance packet TEXT\n\
12107 If GDB is talking to an inferior via the GDB serial protocol, then\n\
12108 this command sends the string TEXT to the inferior, and displays the\n\
12109 response packet. GDB supplies the initial `$' character, and the\n\
12110 terminating `#' character and checksum."),
12113 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
12114 Set whether to send break if interrupted."), _("\
12115 Show whether to send break if interrupted."), _("\
12116 If set, a break, instead of a cntrl-c, is sent to the remote target."),
12117 set_remotebreak
, show_remotebreak
,
12118 &setlist
, &showlist
);
12119 cmd_name
= "remotebreak";
12120 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
12121 deprecate_cmd (cmd
, "set remote interrupt-sequence");
12122 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
12123 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
12124 deprecate_cmd (cmd
, "show remote interrupt-sequence");
12126 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
12127 interrupt_sequence_modes
, &interrupt_sequence_mode
,
12129 Set interrupt sequence to remote target."), _("\
12130 Show interrupt sequence to remote target."), _("\
12131 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
12132 NULL
, show_interrupt_sequence
,
12133 &remote_set_cmdlist
,
12134 &remote_show_cmdlist
);
12136 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
12137 &interrupt_on_connect
, _("\
12138 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
12139 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
12140 If set, interrupt sequence is sent to remote target."),
12142 &remote_set_cmdlist
, &remote_show_cmdlist
);
12144 /* Install commands for configuring memory read/write packets. */
12146 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
12147 Set the maximum number of bytes per memory write packet (deprecated)."),
12149 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
12150 Show the maximum number of bytes per memory write packet (deprecated)."),
12152 add_cmd ("memory-write-packet-size", no_class
,
12153 set_memory_write_packet_size
, _("\
12154 Set the maximum number of bytes per memory-write packet.\n\
12155 Specify the number of bytes in a packet or 0 (zero) for the\n\
12156 default packet size. The actual limit is further reduced\n\
12157 dependent on the target. Specify ``fixed'' to disable the\n\
12158 further restriction and ``limit'' to enable that restriction."),
12159 &remote_set_cmdlist
);
12160 add_cmd ("memory-read-packet-size", no_class
,
12161 set_memory_read_packet_size
, _("\
12162 Set the maximum number of bytes per memory-read packet.\n\
12163 Specify the number of bytes in a packet or 0 (zero) for the\n\
12164 default packet size. The actual limit is further reduced\n\
12165 dependent on the target. Specify ``fixed'' to disable the\n\
12166 further restriction and ``limit'' to enable that restriction."),
12167 &remote_set_cmdlist
);
12168 add_cmd ("memory-write-packet-size", no_class
,
12169 show_memory_write_packet_size
,
12170 _("Show the maximum number of bytes per memory-write packet."),
12171 &remote_show_cmdlist
);
12172 add_cmd ("memory-read-packet-size", no_class
,
12173 show_memory_read_packet_size
,
12174 _("Show the maximum number of bytes per memory-read packet."),
12175 &remote_show_cmdlist
);
12177 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
12178 &remote_hw_watchpoint_limit
, _("\
12179 Set the maximum number of target hardware watchpoints."), _("\
12180 Show the maximum number of target hardware watchpoints."), _("\
12181 Specify a negative limit for unlimited."),
12182 NULL
, NULL
, /* FIXME: i18n: The maximum
12183 number of target hardware
12184 watchpoints is %s. */
12185 &remote_set_cmdlist
, &remote_show_cmdlist
);
12186 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
12187 &remote_hw_watchpoint_length_limit
, _("\
12188 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
12189 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
12190 Specify a negative limit for unlimited."),
12191 NULL
, NULL
, /* FIXME: i18n: The maximum
12192 length (in bytes) of a target
12193 hardware watchpoint is %s. */
12194 &remote_set_cmdlist
, &remote_show_cmdlist
);
12195 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
12196 &remote_hw_breakpoint_limit
, _("\
12197 Set the maximum number of target hardware breakpoints."), _("\
12198 Show the maximum number of target hardware breakpoints."), _("\
12199 Specify a negative limit for unlimited."),
12200 NULL
, NULL
, /* FIXME: i18n: The maximum
12201 number of target hardware
12202 breakpoints is %s. */
12203 &remote_set_cmdlist
, &remote_show_cmdlist
);
12205 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
12206 &remote_address_size
, _("\
12207 Set the maximum size of the address (in bits) in a memory packet."), _("\
12208 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
12210 NULL
, /* FIXME: i18n: */
12211 &setlist
, &showlist
);
12213 init_all_packet_configs ();
12215 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
12216 "X", "binary-download", 1);
12218 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
12219 "vCont", "verbose-resume", 0);
12221 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
12222 "QPassSignals", "pass-signals", 0);
12224 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
12225 "QProgramSignals", "program-signals", 0);
12227 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
12228 "qSymbol", "symbol-lookup", 0);
12230 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
12231 "P", "set-register", 1);
12233 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
12234 "p", "fetch-register", 1);
12236 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
12237 "Z0", "software-breakpoint", 0);
12239 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
12240 "Z1", "hardware-breakpoint", 0);
12242 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
12243 "Z2", "write-watchpoint", 0);
12245 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
12246 "Z3", "read-watchpoint", 0);
12248 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
12249 "Z4", "access-watchpoint", 0);
12251 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
12252 "qXfer:auxv:read", "read-aux-vector", 0);
12254 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
12255 "qXfer:exec-file:read", "pid-to-exec-file", 0);
12257 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
12258 "qXfer:features:read", "target-features", 0);
12260 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
12261 "qXfer:libraries:read", "library-info", 0);
12263 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
12264 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
12266 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
12267 "qXfer:memory-map:read", "memory-map", 0);
12269 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
12270 "qXfer:spu:read", "read-spu-object", 0);
12272 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
12273 "qXfer:spu:write", "write-spu-object", 0);
12275 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
12276 "qXfer:osdata:read", "osdata", 0);
12278 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
12279 "qXfer:threads:read", "threads", 0);
12281 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
12282 "qXfer:siginfo:read", "read-siginfo-object", 0);
12284 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
12285 "qXfer:siginfo:write", "write-siginfo-object", 0);
12287 add_packet_config_cmd
12288 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
12289 "qXfer:traceframe-info:read", "traceframe-info", 0);
12291 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
12292 "qXfer:uib:read", "unwind-info-block", 0);
12294 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
12295 "qGetTLSAddr", "get-thread-local-storage-address",
12298 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
12299 "qGetTIBAddr", "get-thread-information-block-address",
12302 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
12303 "bc", "reverse-continue", 0);
12305 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
12306 "bs", "reverse-step", 0);
12308 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
12309 "qSupported", "supported-packets", 0);
12311 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
12312 "qSearch:memory", "search-memory", 0);
12314 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
12315 "qTStatus", "trace-status", 0);
12317 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
12318 "vFile:open", "hostio-open", 0);
12320 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
12321 "vFile:pread", "hostio-pread", 0);
12323 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
12324 "vFile:pwrite", "hostio-pwrite", 0);
12326 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
12327 "vFile:close", "hostio-close", 0);
12329 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
12330 "vFile:unlink", "hostio-unlink", 0);
12332 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
12333 "vFile:readlink", "hostio-readlink", 0);
12335 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
12336 "vFile:fstat", "hostio-fstat", 0);
12338 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
12339 "vAttach", "attach", 0);
12341 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
12344 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
12345 "QStartNoAckMode", "noack", 0);
12347 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
12348 "vKill", "kill", 0);
12350 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
12351 "qAttached", "query-attached", 0);
12353 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
12354 "ConditionalTracepoints",
12355 "conditional-tracepoints", 0);
12357 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
12358 "ConditionalBreakpoints",
12359 "conditional-breakpoints", 0);
12361 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
12362 "BreakpointCommands",
12363 "breakpoint-commands", 0);
12365 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
12366 "FastTracepoints", "fast-tracepoints", 0);
12368 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
12369 "TracepointSource", "TracepointSource", 0);
12371 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
12372 "QAllow", "allow", 0);
12374 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
12375 "StaticTracepoints", "static-tracepoints", 0);
12377 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
12378 "InstallInTrace", "install-in-trace", 0);
12380 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
12381 "qXfer:statictrace:read", "read-sdata-object", 0);
12383 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
12384 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
12386 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
12387 "QDisableRandomization", "disable-randomization", 0);
12389 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
12390 "QAgent", "agent", 0);
12392 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
12393 "QTBuffer:size", "trace-buffer-size", 0);
12395 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
12396 "Qbtrace:off", "disable-btrace", 0);
12398 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
12399 "Qbtrace:bts", "enable-btrace", 0);
12401 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
12402 "qXfer:btrace", "read-btrace", 0);
12404 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
12405 "qXfer:btrace-conf", "read-btrace-conf", 0);
12407 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
12408 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
12410 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
12411 "swbreak-feature", "swbreak-feature", 0);
12413 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
12414 "hwbreak-feature", "hwbreak-feature", 0);
12416 /* Assert that we've registered "set remote foo-packet" commands
12417 for all packet configs. */
12421 for (i
= 0; i
< PACKET_MAX
; i
++)
12423 /* Ideally all configs would have a command associated. Some
12424 still don't though. */
12429 case PACKET_QNonStop
:
12430 case PACKET_multiprocess_feature
:
12431 case PACKET_EnableDisableTracepoints_feature
:
12432 case PACKET_tracenz_feature
:
12433 case PACKET_DisconnectedTracing_feature
:
12434 case PACKET_augmented_libraries_svr4_read_feature
:
12436 /* Additions to this list need to be well justified:
12437 pre-existing packets are OK; new packets are not. */
12445 /* This catches both forgetting to add a config command, and
12446 forgetting to remove a packet from the exception list. */
12447 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
12451 /* Keep the old ``set remote Z-packet ...'' working. Each individual
12452 Z sub-packet has its own set and show commands, but users may
12453 have sets to this variable in their .gdbinit files (or in their
12455 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
12456 &remote_Z_packet_detect
, _("\
12457 Set use of remote protocol `Z' packets"), _("\
12458 Show use of remote protocol `Z' packets "), _("\
12459 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
12461 set_remote_protocol_Z_packet_cmd
,
12462 show_remote_protocol_Z_packet_cmd
,
12463 /* FIXME: i18n: Use of remote protocol
12464 `Z' packets is %s. */
12465 &remote_set_cmdlist
, &remote_show_cmdlist
);
12467 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
12468 Manipulate files on the remote system\n\
12469 Transfer files to and from the remote target system."),
12470 &remote_cmdlist
, "remote ",
12471 0 /* allow-unknown */, &cmdlist
);
12473 add_cmd ("put", class_files
, remote_put_command
,
12474 _("Copy a local file to the remote system."),
12477 add_cmd ("get", class_files
, remote_get_command
,
12478 _("Copy a remote file to the local system."),
12481 add_cmd ("delete", class_files
, remote_delete_command
,
12482 _("Delete a remote file."),
12485 remote_exec_file
= xstrdup ("");
12486 add_setshow_string_noescape_cmd ("exec-file", class_files
,
12487 &remote_exec_file
, _("\
12488 Set the remote pathname for \"run\""), _("\
12489 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
12490 &remote_set_cmdlist
, &remote_show_cmdlist
);
12492 add_setshow_boolean_cmd ("range-stepping", class_run
,
12493 &use_range_stepping
, _("\
12494 Enable or disable range stepping."), _("\
12495 Show whether target-assisted range stepping is enabled."), _("\
12496 If on, and the target supports it, when stepping a source line, GDB\n\
12497 tells the target to step the corresponding range of addresses itself instead\n\
12498 of issuing multiple single-steps. This speeds up source level\n\
12499 stepping. If off, GDB always issues single-steps, even if range\n\
12500 stepping is supported by the target. The default is on."),
12501 set_range_stepping
,
12502 show_range_stepping
,
12506 /* Eventually initialize fileio. See fileio.c */
12507 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
12509 /* Take advantage of the fact that the TID field is not used, to tag
12510 special ptids with it set to != 0. */
12511 magic_null_ptid
= ptid_build (42000, -1, 1);
12512 not_sent_ptid
= ptid_build (42000, -2, 1);
12513 any_thread_ptid
= ptid_build (42000, 0, 1);
12515 target_buf_size
= 2048;
12516 target_buf
= xmalloc (target_buf_size
);