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"
51 #include "event-loop.h"
52 #include "event-top.h"
58 #include "gdbcore.h" /* for exec_bfd */
60 #include "remote-fileio.h"
61 #include "gdb/fileio.h"
63 #include "xml-support.h"
65 #include "memory-map.h"
67 #include "tracepoint.h"
73 /* Temp hacks for tracepoint encoding migration. */
74 static char *target_buf
;
75 static long target_buf_size
;
77 /* The size to align memory write packets, when practical. The protocol
78 does not guarantee any alignment, and gdb will generate short
79 writes and unaligned writes, but even as a best-effort attempt this
80 can improve bulk transfers. For instance, if a write is misaligned
81 relative to the target's data bus, the stub may need to make an extra
82 round trip fetching data from the target. This doesn't make a
83 huge difference, but it's easy to do, so we try to be helpful.
85 The alignment chosen is arbitrary; usually data bus width is
86 important here, not the possibly larger cache line size. */
87 enum { REMOTE_ALIGN_WRITES
= 16 };
89 /* Prototypes for local functions. */
90 static void async_cleanup_sigint_signal_handler (void *dummy
);
91 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
92 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
93 int forever
, int *is_notif
);
95 static void async_handle_remote_sigint (int);
96 static void async_handle_remote_sigint_twice (int);
98 static void remote_files_info (struct target_ops
*ignore
);
100 static void remote_prepare_to_store (struct target_ops
*self
,
101 struct regcache
*regcache
);
103 static void remote_open_1 (const char *, int, struct target_ops
*,
106 static void remote_close (struct target_ops
*self
);
110 static int remote_vkill (int pid
, struct remote_state
*rs
);
112 static void remote_mourn (struct target_ops
*ops
);
114 static void extended_remote_restart (void);
116 static void extended_remote_mourn (struct target_ops
*);
118 static void remote_send (char **buf
, long *sizeof_buf_p
);
120 static int readchar (int timeout
);
122 static void remote_serial_write (const char *str
, int len
);
124 static void remote_kill (struct target_ops
*ops
);
126 static int remote_can_async_p (struct target_ops
*);
128 static int remote_is_async_p (struct target_ops
*);
130 static void remote_async (struct target_ops
*ops
, int enable
);
132 static void sync_remote_interrupt_twice (int signo
);
134 static void interrupt_query (void);
136 static void set_general_thread (struct ptid ptid
);
137 static void set_continue_thread (struct ptid ptid
);
139 static void get_offsets (void);
141 static void skip_frame (void);
143 static long read_frame (char **buf_p
, long *sizeof_buf
);
145 static int hexnumlen (ULONGEST num
);
147 static void init_remote_ops (void);
149 static void init_extended_remote_ops (void);
151 static void remote_stop (struct target_ops
*self
, ptid_t
);
153 static int stubhex (int ch
);
155 static int hexnumstr (char *, ULONGEST
);
157 static int hexnumnstr (char *, ULONGEST
, int);
159 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
161 static void print_packet (const char *);
163 static void compare_sections_command (char *, int);
165 static void packet_command (char *, int);
167 static int stub_unpack_int (char *buff
, int fieldlength
);
169 static ptid_t
remote_current_thread (ptid_t oldptid
);
171 static int putpkt_binary (const char *buf
, int cnt
);
173 static void check_binary_download (CORE_ADDR addr
);
175 struct packet_config
;
177 static void show_packet_config_cmd (struct packet_config
*config
);
179 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
181 struct cmd_list_element
*c
,
184 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
185 static ptid_t
read_ptid (char *buf
, char **obuf
);
187 static void remote_set_permissions (struct target_ops
*self
);
189 static int remote_get_trace_status (struct target_ops
*self
,
190 struct trace_status
*ts
);
192 static int remote_upload_tracepoints (struct target_ops
*self
,
193 struct uploaded_tp
**utpp
);
195 static int remote_upload_trace_state_variables (struct target_ops
*self
,
196 struct uploaded_tsv
**utsvp
);
198 static void remote_query_supported (void);
200 static void remote_check_symbols (void);
202 void _initialize_remote (void);
205 static void stop_reply_xfree (struct stop_reply
*);
206 static void remote_parse_stop_reply (char *, struct stop_reply
*);
207 static void push_stop_reply (struct stop_reply
*);
208 static void discard_pending_stop_replies_in_queue (struct remote_state
*);
209 static int peek_stop_reply (ptid_t ptid
);
211 struct threads_listing_context
;
212 static void remove_new_fork_children (struct threads_listing_context
*);
214 static void remote_async_inferior_event_handler (gdb_client_data
);
216 static void remote_terminal_ours (struct target_ops
*self
);
218 static int remote_read_description_p (struct target_ops
*target
);
220 static void remote_console_output (char *msg
);
222 static int remote_supports_cond_breakpoints (struct target_ops
*self
);
224 static int remote_can_run_breakpoint_commands (struct target_ops
*self
);
226 static void remote_btrace_reset (void);
230 static struct cmd_list_element
*remote_cmdlist
;
232 /* For "set remote" and "show remote". */
234 static struct cmd_list_element
*remote_set_cmdlist
;
235 static struct cmd_list_element
*remote_show_cmdlist
;
237 /* Stub vCont actions support.
239 Each field is a boolean flag indicating whether the stub reports
240 support for the corresponding action. */
242 struct vCont_action_support
251 /* Controls whether GDB is willing to use range stepping. */
253 static int use_range_stepping
= 1;
255 #define OPAQUETHREADBYTES 8
257 /* a 64 bit opaque identifier */
258 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
260 /* About this many threadisds fit in a packet. */
262 #define MAXTHREADLISTRESULTS 32
264 /* Description of the remote protocol state for the currently
265 connected target. This is per-target state, and independent of the
266 selected architecture. */
270 /* A buffer to use for incoming packets, and its current size. The
271 buffer is grown dynamically for larger incoming packets.
272 Outgoing packets may also be constructed in this buffer.
273 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
274 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
279 /* True if we're going through initial connection setup (finding out
280 about the remote side's threads, relocating symbols, etc.). */
283 /* If we negotiated packet size explicitly (and thus can bypass
284 heuristics for the largest packet size that will not overflow
285 a buffer in the stub), this will be set to that packet size.
286 Otherwise zero, meaning to use the guessed size. */
287 long explicit_packet_size
;
289 /* remote_wait is normally called when the target is running and
290 waits for a stop reply packet. But sometimes we need to call it
291 when the target is already stopped. We can send a "?" packet
292 and have remote_wait read the response. Or, if we already have
293 the response, we can stash it in BUF and tell remote_wait to
294 skip calling getpkt. This flag is set when BUF contains a
295 stop reply packet and the target is not waiting. */
296 int cached_wait_status
;
298 /* True, if in no ack mode. That is, neither GDB nor the stub will
299 expect acks from each other. The connection is assumed to be
303 /* True if we're connected in extended remote mode. */
306 /* True if we resumed the target and we're waiting for the target to
307 stop. In the mean time, we can't start another command/query.
308 The remote server wouldn't be ready to process it, so we'd
309 timeout waiting for a reply that would never come and eventually
310 we'd close the connection. This can happen in asynchronous mode
311 because we allow GDB commands while the target is running. */
312 int waiting_for_stop_reply
;
314 /* The status of the stub support for the various vCont actions. */
315 struct vCont_action_support supports_vCont
;
317 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
318 responded to that. */
321 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
322 remote_open knows that we don't have a file open when the program
324 struct serial
*remote_desc
;
326 /* These are the threads which we last sent to the remote system. The
327 TID member will be -1 for all or -2 for not sent yet. */
328 ptid_t general_thread
;
329 ptid_t continue_thread
;
331 /* This is the traceframe which we last selected on the remote system.
332 It will be -1 if no traceframe is selected. */
333 int remote_traceframe_number
;
335 char *last_pass_packet
;
337 /* The last QProgramSignals packet sent to the target. We bypass
338 sending a new program signals list down to the target if the new
339 packet is exactly the same as the last we sent. IOW, we only let
340 the target know about program signals list changes. */
341 char *last_program_signals_packet
;
343 enum gdb_signal last_sent_signal
;
347 char *finished_object
;
348 char *finished_annex
;
349 ULONGEST finished_offset
;
351 /* Should we try the 'ThreadInfo' query packet?
353 This variable (NOT available to the user: auto-detect only!)
354 determines whether GDB will use the new, simpler "ThreadInfo"
355 query or the older, more complex syntax for thread queries.
356 This is an auto-detect variable (set to true at each connect,
357 and set to false when the target fails to recognize it). */
358 int use_threadinfo_query
;
359 int use_threadextra_query
;
361 /* This is set to the data address of the access causing the target
362 to stop for a watchpoint. */
363 CORE_ADDR remote_watch_data_address
;
365 /* Whether the target stopped for a breakpoint/watchpoint. */
366 enum target_stop_reason stop_reason
;
368 threadref echo_nextthread
;
369 threadref nextthread
;
370 threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
372 /* The state of remote notification. */
373 struct remote_notif_state
*notif_state
;
375 /* The branch trace configuration. */
376 struct btrace_config btrace_config
;
378 /* The argument to the last "vFile:setfs:" packet we sent, used
379 to avoid sending repeated unnecessary "vFile:setfs:" packets.
380 Initialized to -1 to indicate that no "vFile:setfs:" packet
381 has yet been sent. */
385 /* Private data that we'll store in (struct thread_info)->private. */
386 struct private_thread_info
393 free_private_thread_info (struct private_thread_info
*info
)
399 /* This data could be associated with a target, but we do not always
400 have access to the current target when we need it, so for now it is
401 static. This will be fine for as long as only one target is in use
403 static struct remote_state
*remote_state
;
405 static struct remote_state
*
406 get_remote_state_raw (void)
411 /* Allocate a new struct remote_state with xmalloc, initialize it, and
414 static struct remote_state
*
415 new_remote_state (void)
417 struct remote_state
*result
= XCNEW (struct remote_state
);
419 /* The default buffer size is unimportant; it will be expanded
420 whenever a larger buffer is needed. */
421 result
->buf_size
= 400;
422 result
->buf
= xmalloc (result
->buf_size
);
423 result
->remote_traceframe_number
= -1;
424 result
->last_sent_signal
= GDB_SIGNAL_0
;
430 /* Description of the remote protocol for a given architecture. */
434 long offset
; /* Offset into G packet. */
435 long regnum
; /* GDB's internal register number. */
436 LONGEST pnum
; /* Remote protocol register number. */
437 int in_g_packet
; /* Always part of G packet. */
438 /* long size in bytes; == register_size (target_gdbarch (), regnum);
440 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
444 struct remote_arch_state
446 /* Description of the remote protocol registers. */
447 long sizeof_g_packet
;
449 /* Description of the remote protocol registers indexed by REGNUM
450 (making an array gdbarch_num_regs in size). */
451 struct packet_reg
*regs
;
453 /* This is the size (in chars) of the first response to the ``g''
454 packet. It is used as a heuristic when determining the maximum
455 size of memory-read and memory-write packets. A target will
456 typically only reserve a buffer large enough to hold the ``g''
457 packet. The size does not include packet overhead (headers and
459 long actual_register_packet_size
;
461 /* This is the maximum size (in chars) of a non read/write packet.
462 It is also used as a cap on the size of read/write packets. */
463 long remote_packet_size
;
466 /* Utility: generate error from an incoming stub packet. */
468 trace_error (char *buf
)
471 return; /* not an error msg */
474 case '1': /* malformed packet error */
475 if (*++buf
== '0') /* general case: */
476 error (_("remote.c: error in outgoing packet."));
478 error (_("remote.c: error in outgoing packet at field #%ld."),
479 strtol (buf
, NULL
, 16));
481 error (_("Target returns error code '%s'."), buf
);
485 /* Utility: wait for reply from stub, while accepting "O" packets. */
487 remote_get_noisy_reply (char **buf_p
,
490 do /* Loop on reply from remote stub. */
494 QUIT
; /* Allow user to bail out with ^C. */
495 getpkt (buf_p
, sizeof_buf
, 0);
499 else if (startswith (buf
, "qRelocInsn:"))
502 CORE_ADDR from
, to
, org_to
;
504 int adjusted_size
= 0;
507 p
= buf
+ strlen ("qRelocInsn:");
508 pp
= unpack_varlen_hex (p
, &ul
);
510 error (_("invalid qRelocInsn packet: %s"), buf
);
514 unpack_varlen_hex (p
, &ul
);
521 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
524 CATCH (ex
, RETURN_MASK_ALL
)
526 if (ex
.error
== MEMORY_ERROR
)
528 /* Propagate memory errors silently back to the
529 target. The stub may have limited the range of
530 addresses we can write to, for example. */
534 /* Something unexpectedly bad happened. Be verbose
535 so we can tell what, and propagate the error back
536 to the stub, so it doesn't get stuck waiting for
538 exception_fprintf (gdb_stderr
, ex
,
539 _("warning: relocating instruction: "));
547 adjusted_size
= to
- org_to
;
549 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
553 else if (buf
[0] == 'O' && buf
[1] != 'K')
554 remote_console_output (buf
+ 1); /* 'O' message from stub */
556 return buf
; /* Here's the actual reply. */
561 /* Handle for retreving the remote protocol data from gdbarch. */
562 static struct gdbarch_data
*remote_gdbarch_data_handle
;
564 static struct remote_arch_state
*
565 get_remote_arch_state (void)
567 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
);
570 /* Fetch the global remote target state. */
572 static struct remote_state
*
573 get_remote_state (void)
575 /* Make sure that the remote architecture state has been
576 initialized, because doing so might reallocate rs->buf. Any
577 function which calls getpkt also needs to be mindful of changes
578 to rs->buf, but this call limits the number of places which run
580 get_remote_arch_state ();
582 return get_remote_state_raw ();
586 compare_pnums (const void *lhs_
, const void *rhs_
)
588 const struct packet_reg
* const *lhs
= lhs_
;
589 const struct packet_reg
* const *rhs
= rhs_
;
591 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
593 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
600 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
602 int regnum
, num_remote_regs
, offset
;
603 struct packet_reg
**remote_regs
;
605 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
607 struct packet_reg
*r
= ®s
[regnum
];
609 if (register_size (gdbarch
, regnum
) == 0)
610 /* Do not try to fetch zero-sized (placeholder) registers. */
613 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
618 /* Define the g/G packet format as the contents of each register
619 with a remote protocol number, in order of ascending protocol
622 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
623 * sizeof (struct packet_reg
*));
624 for (num_remote_regs
= 0, regnum
= 0;
625 regnum
< gdbarch_num_regs (gdbarch
);
627 if (regs
[regnum
].pnum
!= -1)
628 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
630 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
633 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
635 remote_regs
[regnum
]->in_g_packet
= 1;
636 remote_regs
[regnum
]->offset
= offset
;
637 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
643 /* Given the architecture described by GDBARCH, return the remote
644 protocol register's number and the register's offset in the g/G
645 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
646 If the target does not have a mapping for REGNUM, return false,
647 otherwise, return true. */
650 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
651 int *pnum
, int *poffset
)
654 struct packet_reg
*regs
;
655 struct cleanup
*old_chain
;
657 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
659 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
660 old_chain
= make_cleanup (xfree
, regs
);
662 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
664 *pnum
= regs
[regnum
].pnum
;
665 *poffset
= regs
[regnum
].offset
;
667 do_cleanups (old_chain
);
673 init_remote_state (struct gdbarch
*gdbarch
)
675 struct remote_state
*rs
= get_remote_state_raw ();
676 struct remote_arch_state
*rsa
;
678 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
680 /* Use the architecture to build a regnum<->pnum table, which will be
681 1:1 unless a feature set specifies otherwise. */
682 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
683 gdbarch_num_regs (gdbarch
),
686 /* Record the maximum possible size of the g packet - it may turn out
688 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
690 /* Default maximum number of characters in a packet body. Many
691 remote stubs have a hardwired buffer size of 400 bytes
692 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
693 as the maximum packet-size to ensure that the packet and an extra
694 NUL character can always fit in the buffer. This stops GDB
695 trashing stubs that try to squeeze an extra NUL into what is
696 already a full buffer (As of 1999-12-04 that was most stubs). */
697 rsa
->remote_packet_size
= 400 - 1;
699 /* This one is filled in when a ``g'' packet is received. */
700 rsa
->actual_register_packet_size
= 0;
702 /* Should rsa->sizeof_g_packet needs more space than the
703 default, adjust the size accordingly. Remember that each byte is
704 encoded as two characters. 32 is the overhead for the packet
705 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
706 (``$NN:G...#NN'') is a better guess, the below has been padded a
708 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
709 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
711 /* Make sure that the packet buffer is plenty big enough for
712 this architecture. */
713 if (rs
->buf_size
< rsa
->remote_packet_size
)
715 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
716 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
722 /* Return the current allowed size of a remote packet. This is
723 inferred from the current architecture, and should be used to
724 limit the length of outgoing packets. */
726 get_remote_packet_size (void)
728 struct remote_state
*rs
= get_remote_state ();
729 struct remote_arch_state
*rsa
= get_remote_arch_state ();
731 if (rs
->explicit_packet_size
)
732 return rs
->explicit_packet_size
;
734 return rsa
->remote_packet_size
;
737 static struct packet_reg
*
738 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
740 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
744 struct packet_reg
*r
= &rsa
->regs
[regnum
];
746 gdb_assert (r
->regnum
== regnum
);
751 static struct packet_reg
*
752 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
756 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
758 struct packet_reg
*r
= &rsa
->regs
[i
];
766 static struct target_ops remote_ops
;
768 static struct target_ops extended_remote_ops
;
770 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
771 ``forever'' still use the normal timeout mechanism. This is
772 currently used by the ASYNC code to guarentee that target reads
773 during the initial connect always time-out. Once getpkt has been
774 modified to return a timeout indication and, in turn
775 remote_wait()/wait_for_inferior() have gained a timeout parameter
777 static int wait_forever_enabled_p
= 1;
779 /* Allow the user to specify what sequence to send to the remote
780 when he requests a program interruption: Although ^C is usually
781 what remote systems expect (this is the default, here), it is
782 sometimes preferable to send a break. On other systems such
783 as the Linux kernel, a break followed by g, which is Magic SysRq g
784 is required in order to interrupt the execution. */
785 const char interrupt_sequence_control_c
[] = "Ctrl-C";
786 const char interrupt_sequence_break
[] = "BREAK";
787 const char interrupt_sequence_break_g
[] = "BREAK-g";
788 static const char *const interrupt_sequence_modes
[] =
790 interrupt_sequence_control_c
,
791 interrupt_sequence_break
,
792 interrupt_sequence_break_g
,
795 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
798 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
799 struct cmd_list_element
*c
,
802 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
803 fprintf_filtered (file
,
804 _("Send the ASCII ETX character (Ctrl-c) "
805 "to the remote target to interrupt the "
806 "execution of the program.\n"));
807 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
808 fprintf_filtered (file
,
809 _("send a break signal to the remote target "
810 "to interrupt the execution of the program.\n"));
811 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
812 fprintf_filtered (file
,
813 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
814 "the remote target to interrupt the execution "
815 "of Linux kernel.\n"));
817 internal_error (__FILE__
, __LINE__
,
818 _("Invalid value for interrupt_sequence_mode: %s."),
819 interrupt_sequence_mode
);
822 /* This boolean variable specifies whether interrupt_sequence is sent
823 to the remote target when gdb connects to it.
824 This is mostly needed when you debug the Linux kernel: The Linux kernel
825 expects BREAK g which is Magic SysRq g for connecting gdb. */
826 static int interrupt_on_connect
= 0;
828 /* This variable is used to implement the "set/show remotebreak" commands.
829 Since these commands are now deprecated in favor of "set/show remote
830 interrupt-sequence", it no longer has any effect on the code. */
831 static int remote_break
;
834 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
837 interrupt_sequence_mode
= interrupt_sequence_break
;
839 interrupt_sequence_mode
= interrupt_sequence_control_c
;
843 show_remotebreak (struct ui_file
*file
, int from_tty
,
844 struct cmd_list_element
*c
,
849 /* This variable sets the number of bits in an address that are to be
850 sent in a memory ("M" or "m") packet. Normally, after stripping
851 leading zeros, the entire address would be sent. This variable
852 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
853 initial implementation of remote.c restricted the address sent in
854 memory packets to ``host::sizeof long'' bytes - (typically 32
855 bits). Consequently, for 64 bit targets, the upper 32 bits of an
856 address was never sent. Since fixing this bug may cause a break in
857 some remote targets this variable is principly provided to
858 facilitate backward compatibility. */
860 static unsigned int remote_address_size
;
862 /* Temporary to track who currently owns the terminal. See
863 remote_terminal_* for more details. */
865 static int remote_async_terminal_ours_p
;
867 /* The executable file to use for "run" on the remote side. */
869 static char *remote_exec_file
= "";
872 /* User configurable variables for the number of characters in a
873 memory read/write packet. MIN (rsa->remote_packet_size,
874 rsa->sizeof_g_packet) is the default. Some targets need smaller
875 values (fifo overruns, et.al.) and some users need larger values
876 (speed up transfers). The variables ``preferred_*'' (the user
877 request), ``current_*'' (what was actually set) and ``forced_*''
878 (Positive - a soft limit, negative - a hard limit). */
880 struct memory_packet_config
887 /* Compute the current size of a read/write packet. Since this makes
888 use of ``actual_register_packet_size'' the computation is dynamic. */
891 get_memory_packet_size (struct memory_packet_config
*config
)
893 struct remote_state
*rs
= get_remote_state ();
894 struct remote_arch_state
*rsa
= get_remote_arch_state ();
896 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
897 law?) that some hosts don't cope very well with large alloca()
898 calls. Eventually the alloca() code will be replaced by calls to
899 xmalloc() and make_cleanups() allowing this restriction to either
900 be lifted or removed. */
901 #ifndef MAX_REMOTE_PACKET_SIZE
902 #define MAX_REMOTE_PACKET_SIZE 16384
904 /* NOTE: 20 ensures we can write at least one byte. */
905 #ifndef MIN_REMOTE_PACKET_SIZE
906 #define MIN_REMOTE_PACKET_SIZE 20
911 if (config
->size
<= 0)
912 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
914 what_they_get
= config
->size
;
918 what_they_get
= get_remote_packet_size ();
919 /* Limit the packet to the size specified by the user. */
921 && what_they_get
> config
->size
)
922 what_they_get
= config
->size
;
924 /* Limit it to the size of the targets ``g'' response unless we have
925 permission from the stub to use a larger packet size. */
926 if (rs
->explicit_packet_size
== 0
927 && rsa
->actual_register_packet_size
> 0
928 && what_they_get
> rsa
->actual_register_packet_size
)
929 what_they_get
= rsa
->actual_register_packet_size
;
931 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
932 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
933 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
934 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
936 /* Make sure there is room in the global buffer for this packet
937 (including its trailing NUL byte). */
938 if (rs
->buf_size
< what_they_get
+ 1)
940 rs
->buf_size
= 2 * what_they_get
;
941 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
944 return what_they_get
;
947 /* Update the size of a read/write packet. If they user wants
948 something really big then do a sanity check. */
951 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
953 int fixed_p
= config
->fixed_p
;
954 long size
= config
->size
;
957 error (_("Argument required (integer, `fixed' or `limited')."));
958 else if (strcmp (args
, "hard") == 0
959 || strcmp (args
, "fixed") == 0)
961 else if (strcmp (args
, "soft") == 0
962 || strcmp (args
, "limit") == 0)
968 size
= strtoul (args
, &end
, 0);
970 error (_("Invalid %s (bad syntax)."), config
->name
);
972 /* Instead of explicitly capping the size of a packet to
973 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
974 instead allowed to set the size to something arbitrarily
976 if (size
> MAX_REMOTE_PACKET_SIZE
)
977 error (_("Invalid %s (too large)."), config
->name
);
981 if (fixed_p
&& !config
->fixed_p
)
983 if (! query (_("The target may not be able to correctly handle a %s\n"
984 "of %ld bytes. Change the packet size? "),
986 error (_("Packet size not changed."));
988 /* Update the config. */
989 config
->fixed_p
= fixed_p
;
994 show_memory_packet_size (struct memory_packet_config
*config
)
996 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
998 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
999 get_memory_packet_size (config
));
1001 printf_filtered (_("Packets are limited to %ld bytes.\n"),
1002 get_memory_packet_size (config
));
1005 static struct memory_packet_config memory_write_packet_config
=
1007 "memory-write-packet-size",
1011 set_memory_write_packet_size (char *args
, int from_tty
)
1013 set_memory_packet_size (args
, &memory_write_packet_config
);
1017 show_memory_write_packet_size (char *args
, int from_tty
)
1019 show_memory_packet_size (&memory_write_packet_config
);
1023 get_memory_write_packet_size (void)
1025 return get_memory_packet_size (&memory_write_packet_config
);
1028 static struct memory_packet_config memory_read_packet_config
=
1030 "memory-read-packet-size",
1034 set_memory_read_packet_size (char *args
, int from_tty
)
1036 set_memory_packet_size (args
, &memory_read_packet_config
);
1040 show_memory_read_packet_size (char *args
, int from_tty
)
1042 show_memory_packet_size (&memory_read_packet_config
);
1046 get_memory_read_packet_size (void)
1048 long size
= get_memory_packet_size (&memory_read_packet_config
);
1050 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1051 extra buffer size argument before the memory read size can be
1052 increased beyond this. */
1053 if (size
> get_remote_packet_size ())
1054 size
= get_remote_packet_size ();
1059 /* Generic configuration support for packets the stub optionally
1060 supports. Allows the user to specify the use of the packet as well
1061 as allowing GDB to auto-detect support in the remote stub. */
1065 PACKET_SUPPORT_UNKNOWN
= 0,
1070 struct packet_config
1075 /* If auto, GDB auto-detects support for this packet or feature,
1076 either through qSupported, or by trying the packet and looking
1077 at the response. If true, GDB assumes the target supports this
1078 packet. If false, the packet is disabled. Configs that don't
1079 have an associated command always have this set to auto. */
1080 enum auto_boolean detect
;
1082 /* Does the target support this packet? */
1083 enum packet_support support
;
1086 /* Analyze a packet's return value and update the packet config
1096 static enum packet_support
packet_config_support (struct packet_config
*config
);
1097 static enum packet_support
packet_support (int packet
);
1100 show_packet_config_cmd (struct packet_config
*config
)
1102 char *support
= "internal-error";
1104 switch (packet_config_support (config
))
1107 support
= "enabled";
1109 case PACKET_DISABLE
:
1110 support
= "disabled";
1112 case PACKET_SUPPORT_UNKNOWN
:
1113 support
= "unknown";
1116 switch (config
->detect
)
1118 case AUTO_BOOLEAN_AUTO
:
1119 printf_filtered (_("Support for the `%s' packet "
1120 "is auto-detected, currently %s.\n"),
1121 config
->name
, support
);
1123 case AUTO_BOOLEAN_TRUE
:
1124 case AUTO_BOOLEAN_FALSE
:
1125 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1126 config
->name
, support
);
1132 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1133 const char *title
, int legacy
)
1139 config
->name
= name
;
1140 config
->title
= title
;
1141 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1143 show_doc
= xstrprintf ("Show current use of remote "
1144 "protocol `%s' (%s) packet",
1146 /* set/show TITLE-packet {auto,on,off} */
1147 cmd_name
= xstrprintf ("%s-packet", title
);
1148 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1149 &config
->detect
, set_doc
,
1150 show_doc
, NULL
, /* help_doc */
1152 show_remote_protocol_packet_cmd
,
1153 &remote_set_cmdlist
, &remote_show_cmdlist
);
1154 /* The command code copies the documentation strings. */
1157 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1162 legacy_name
= xstrprintf ("%s-packet", name
);
1163 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1164 &remote_set_cmdlist
);
1165 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1166 &remote_show_cmdlist
);
1170 static enum packet_result
1171 packet_check_result (const char *buf
)
1175 /* The stub recognized the packet request. Check that the
1176 operation succeeded. */
1178 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1180 /* "Enn" - definitly an error. */
1181 return PACKET_ERROR
;
1183 /* Always treat "E." as an error. This will be used for
1184 more verbose error messages, such as E.memtypes. */
1185 if (buf
[0] == 'E' && buf
[1] == '.')
1186 return PACKET_ERROR
;
1188 /* The packet may or may not be OK. Just assume it is. */
1192 /* The stub does not support the packet. */
1193 return PACKET_UNKNOWN
;
1196 static enum packet_result
1197 packet_ok (const char *buf
, struct packet_config
*config
)
1199 enum packet_result result
;
1201 if (config
->detect
!= AUTO_BOOLEAN_TRUE
1202 && config
->support
== PACKET_DISABLE
)
1203 internal_error (__FILE__
, __LINE__
,
1204 _("packet_ok: attempt to use a disabled packet"));
1206 result
= packet_check_result (buf
);
1211 /* The stub recognized the packet request. */
1212 if (config
->support
== PACKET_SUPPORT_UNKNOWN
)
1215 fprintf_unfiltered (gdb_stdlog
,
1216 "Packet %s (%s) is supported\n",
1217 config
->name
, config
->title
);
1218 config
->support
= PACKET_ENABLE
;
1221 case PACKET_UNKNOWN
:
1222 /* The stub does not support the packet. */
1223 if (config
->detect
== AUTO_BOOLEAN_AUTO
1224 && config
->support
== PACKET_ENABLE
)
1226 /* If the stub previously indicated that the packet was
1227 supported then there is a protocol error. */
1228 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1229 config
->name
, config
->title
);
1231 else if (config
->detect
== AUTO_BOOLEAN_TRUE
)
1233 /* The user set it wrong. */
1234 error (_("Enabled packet %s (%s) not recognized by stub"),
1235 config
->name
, config
->title
);
1239 fprintf_unfiltered (gdb_stdlog
,
1240 "Packet %s (%s) is NOT supported\n",
1241 config
->name
, config
->title
);
1242 config
->support
= PACKET_DISABLE
;
1263 PACKET_vFile_pwrite
,
1265 PACKET_vFile_unlink
,
1266 PACKET_vFile_readlink
,
1269 PACKET_qXfer_features
,
1270 PACKET_qXfer_exec_file
,
1271 PACKET_qXfer_libraries
,
1272 PACKET_qXfer_libraries_svr4
,
1273 PACKET_qXfer_memory_map
,
1274 PACKET_qXfer_spu_read
,
1275 PACKET_qXfer_spu_write
,
1276 PACKET_qXfer_osdata
,
1277 PACKET_qXfer_threads
,
1278 PACKET_qXfer_statictrace_read
,
1279 PACKET_qXfer_traceframe_info
,
1285 PACKET_QPassSignals
,
1286 PACKET_QProgramSignals
,
1288 PACKET_qSearch_memory
,
1291 PACKET_QStartNoAckMode
,
1293 PACKET_qXfer_siginfo_read
,
1294 PACKET_qXfer_siginfo_write
,
1297 /* Support for conditional tracepoints. */
1298 PACKET_ConditionalTracepoints
,
1300 /* Support for target-side breakpoint conditions. */
1301 PACKET_ConditionalBreakpoints
,
1303 /* Support for target-side breakpoint commands. */
1304 PACKET_BreakpointCommands
,
1306 /* Support for fast tracepoints. */
1307 PACKET_FastTracepoints
,
1309 /* Support for static tracepoints. */
1310 PACKET_StaticTracepoints
,
1312 /* Support for installing tracepoints while a trace experiment is
1314 PACKET_InstallInTrace
,
1318 PACKET_TracepointSource
,
1321 PACKET_QDisableRandomization
,
1323 PACKET_QTBuffer_size
,
1327 PACKET_qXfer_btrace
,
1329 /* Support for the QNonStop packet. */
1332 /* Support for multi-process extensions. */
1333 PACKET_multiprocess_feature
,
1335 /* Support for enabling and disabling tracepoints while a trace
1336 experiment is running. */
1337 PACKET_EnableDisableTracepoints_feature
,
1339 /* Support for collecting strings using the tracenz bytecode. */
1340 PACKET_tracenz_feature
,
1342 /* Support for continuing to run a trace experiment while GDB is
1344 PACKET_DisconnectedTracing_feature
,
1346 /* Support for qXfer:libraries-svr4:read with a non-empty annex. */
1347 PACKET_augmented_libraries_svr4_read_feature
,
1349 /* Support for the qXfer:btrace-conf:read packet. */
1350 PACKET_qXfer_btrace_conf
,
1352 /* Support for the Qbtrace-conf:bts:size packet. */
1353 PACKET_Qbtrace_conf_bts_size
,
1355 /* Support for swbreak+ feature. */
1356 PACKET_swbreak_feature
,
1358 /* Support for hwbreak+ feature. */
1359 PACKET_hwbreak_feature
,
1361 /* Support for fork events. */
1362 PACKET_fork_event_feature
,
1364 /* Support for vfork events. */
1365 PACKET_vfork_event_feature
,
1367 /* Support for the Qbtrace-conf:pt:size packet. */
1368 PACKET_Qbtrace_conf_pt_size
,
1373 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1375 /* Returns the packet's corresponding "set remote foo-packet" command
1376 state. See struct packet_config for more details. */
1378 static enum auto_boolean
1379 packet_set_cmd_state (int packet
)
1381 return remote_protocol_packets
[packet
].detect
;
1384 /* Returns whether a given packet or feature is supported. This takes
1385 into account the state of the corresponding "set remote foo-packet"
1386 command, which may be used to bypass auto-detection. */
1388 static enum packet_support
1389 packet_config_support (struct packet_config
*config
)
1391 switch (config
->detect
)
1393 case AUTO_BOOLEAN_TRUE
:
1394 return PACKET_ENABLE
;
1395 case AUTO_BOOLEAN_FALSE
:
1396 return PACKET_DISABLE
;
1397 case AUTO_BOOLEAN_AUTO
:
1398 return config
->support
;
1400 gdb_assert_not_reached (_("bad switch"));
1404 /* Same as packet_config_support, but takes the packet's enum value as
1407 static enum packet_support
1408 packet_support (int packet
)
1410 struct packet_config
*config
= &remote_protocol_packets
[packet
];
1412 return packet_config_support (config
);
1416 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1417 struct cmd_list_element
*c
,
1420 struct packet_config
*packet
;
1422 for (packet
= remote_protocol_packets
;
1423 packet
< &remote_protocol_packets
[PACKET_MAX
];
1426 if (&packet
->detect
== c
->var
)
1428 show_packet_config_cmd (packet
);
1432 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1436 /* Should we try one of the 'Z' requests? */
1440 Z_PACKET_SOFTWARE_BP
,
1441 Z_PACKET_HARDWARE_BP
,
1448 /* For compatibility with older distributions. Provide a ``set remote
1449 Z-packet ...'' command that updates all the Z packet types. */
1451 static enum auto_boolean remote_Z_packet_detect
;
1454 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1455 struct cmd_list_element
*c
)
1459 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1460 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1464 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1465 struct cmd_list_element
*c
,
1470 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1472 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1476 /* Returns true if the multi-process extensions are in effect. */
1479 remote_multi_process_p (struct remote_state
*rs
)
1481 return packet_support (PACKET_multiprocess_feature
) == PACKET_ENABLE
;
1484 /* Returns true if fork events are supported. */
1487 remote_fork_event_p (struct remote_state
*rs
)
1489 return packet_support (PACKET_fork_event_feature
) == PACKET_ENABLE
;
1492 /* Returns true if vfork events are supported. */
1495 remote_vfork_event_p (struct remote_state
*rs
)
1497 return packet_support (PACKET_vfork_event_feature
) == PACKET_ENABLE
;
1500 /* Insert fork catchpoint target routine. If fork events are enabled
1501 then return success, nothing more to do. */
1504 remote_insert_fork_catchpoint (struct target_ops
*ops
, int pid
)
1506 struct remote_state
*rs
= get_remote_state ();
1508 return !remote_fork_event_p (rs
);
1511 /* Remove fork catchpoint target routine. Nothing to do, just
1515 remote_remove_fork_catchpoint (struct target_ops
*ops
, int pid
)
1520 /* Insert vfork catchpoint target routine. If vfork events are enabled
1521 then return success, nothing more to do. */
1524 remote_insert_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1526 struct remote_state
*rs
= get_remote_state ();
1528 return !remote_vfork_event_p (rs
);
1531 /* Remove vfork catchpoint target routine. Nothing to do, just
1535 remote_remove_vfork_catchpoint (struct target_ops
*ops
, int pid
)
1540 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1541 static struct async_signal_handler
*async_sigint_remote_twice_token
;
1542 static struct async_signal_handler
*async_sigint_remote_token
;
1545 /* Asynchronous signal handle registered as event loop source for
1546 when we have pending events ready to be passed to the core. */
1548 static struct async_event_handler
*remote_async_inferior_event_token
;
1552 static ptid_t magic_null_ptid
;
1553 static ptid_t not_sent_ptid
;
1554 static ptid_t any_thread_ptid
;
1556 /* Find out if the stub attached to PID (and hence GDB should offer to
1557 detach instead of killing it when bailing out). */
1560 remote_query_attached (int pid
)
1562 struct remote_state
*rs
= get_remote_state ();
1563 size_t size
= get_remote_packet_size ();
1565 if (packet_support (PACKET_qAttached
) == PACKET_DISABLE
)
1568 if (remote_multi_process_p (rs
))
1569 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1571 xsnprintf (rs
->buf
, size
, "qAttached");
1574 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1576 switch (packet_ok (rs
->buf
,
1577 &remote_protocol_packets
[PACKET_qAttached
]))
1580 if (strcmp (rs
->buf
, "1") == 0)
1584 warning (_("Remote failure reply: %s"), rs
->buf
);
1586 case PACKET_UNKNOWN
:
1593 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1594 has been invented by GDB, instead of reported by the target. Since
1595 we can be connected to a remote system before before knowing about
1596 any inferior, mark the target with execution when we find the first
1597 inferior. If ATTACHED is 1, then we had just attached to this
1598 inferior. If it is 0, then we just created this inferior. If it
1599 is -1, then try querying the remote stub to find out if it had
1600 attached to the inferior or not. If TRY_OPEN_EXEC is true then
1601 attempt to open this inferior's executable as the main executable
1602 if no main executable is open already. */
1604 static struct inferior
*
1605 remote_add_inferior (int fake_pid_p
, int pid
, int attached
,
1608 struct inferior
*inf
;
1610 /* Check whether this process we're learning about is to be
1611 considered attached, or if is to be considered to have been
1612 spawned by the stub. */
1614 attached
= remote_query_attached (pid
);
1616 if (gdbarch_has_global_solist (target_gdbarch ()))
1618 /* If the target shares code across all inferiors, then every
1619 attach adds a new inferior. */
1620 inf
= add_inferior (pid
);
1622 /* ... and every inferior is bound to the same program space.
1623 However, each inferior may still have its own address
1625 inf
->aspace
= maybe_new_address_space ();
1626 inf
->pspace
= current_program_space
;
1630 /* In the traditional debugging scenario, there's a 1-1 match
1631 between program/address spaces. We simply bind the inferior
1632 to the program space's address space. */
1633 inf
= current_inferior ();
1634 inferior_appeared (inf
, pid
);
1637 inf
->attach_flag
= attached
;
1638 inf
->fake_pid_p
= fake_pid_p
;
1640 /* If no main executable is currently open then attempt to
1641 open the file that was executed to create this inferior. */
1642 if (try_open_exec
&& get_exec_file (0) == NULL
)
1643 exec_file_locate_attach (pid
, 1);
1648 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1649 according to RUNNING. */
1652 remote_add_thread (ptid_t ptid
, int running
)
1654 struct remote_state
*rs
= get_remote_state ();
1656 /* GDB historically didn't pull threads in the initial connection
1657 setup. If the remote target doesn't even have a concept of
1658 threads (e.g., a bare-metal target), even if internally we
1659 consider that a single-threaded target, mentioning a new thread
1660 might be confusing to the user. Be silent then, preserving the
1661 age old behavior. */
1662 if (rs
->starting_up
)
1663 add_thread_silent (ptid
);
1667 set_executing (ptid
, running
);
1668 set_running (ptid
, running
);
1671 /* Come here when we learn about a thread id from the remote target.
1672 It may be the first time we hear about such thread, so take the
1673 opportunity to add it to GDB's thread list. In case this is the
1674 first time we're noticing its corresponding inferior, add it to
1675 GDB's inferior list as well. */
1678 remote_notice_new_inferior (ptid_t currthread
, int running
)
1680 /* If this is a new thread, add it to GDB's thread list.
1681 If we leave it up to WFI to do this, bad things will happen. */
1683 if (in_thread_list (currthread
) && is_exited (currthread
))
1685 /* We're seeing an event on a thread id we knew had exited.
1686 This has to be a new thread reusing the old id. Add it. */
1687 remote_add_thread (currthread
, running
);
1691 if (!in_thread_list (currthread
))
1693 struct inferior
*inf
= NULL
;
1694 int pid
= ptid_get_pid (currthread
);
1696 if (ptid_is_pid (inferior_ptid
)
1697 && pid
== ptid_get_pid (inferior_ptid
))
1699 /* inferior_ptid has no thread member yet. This can happen
1700 with the vAttach -> remote_wait,"TAAthread:" path if the
1701 stub doesn't support qC. This is the first stop reported
1702 after an attach, so this is the main thread. Update the
1703 ptid in the thread list. */
1704 if (in_thread_list (pid_to_ptid (pid
)))
1705 thread_change_ptid (inferior_ptid
, currthread
);
1708 remote_add_thread (currthread
, running
);
1709 inferior_ptid
= currthread
;
1714 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1716 /* inferior_ptid is not set yet. This can happen with the
1717 vRun -> remote_wait,"TAAthread:" path if the stub
1718 doesn't support qC. This is the first stop reported
1719 after an attach, so this is the main thread. Update the
1720 ptid in the thread list. */
1721 thread_change_ptid (inferior_ptid
, currthread
);
1725 /* When connecting to a target remote, or to a target
1726 extended-remote which already was debugging an inferior, we
1727 may not know about it yet. Add it before adding its child
1728 thread, so notifications are emitted in a sensible order. */
1729 if (!in_inferior_list (ptid_get_pid (currthread
)))
1731 struct remote_state
*rs
= get_remote_state ();
1732 int fake_pid_p
= !remote_multi_process_p (rs
);
1734 inf
= remote_add_inferior (fake_pid_p
,
1735 ptid_get_pid (currthread
), -1, 1);
1738 /* This is really a new thread. Add it. */
1739 remote_add_thread (currthread
, running
);
1741 /* If we found a new inferior, let the common code do whatever
1742 it needs to with it (e.g., read shared libraries, insert
1743 breakpoints), unless we're just setting up an all-stop
1747 struct remote_state
*rs
= get_remote_state ();
1749 if (non_stop
|| !rs
->starting_up
)
1750 notice_new_inferior (currthread
, running
, 0);
1755 /* Return the private thread data, creating it if necessary. */
1757 static struct private_thread_info
*
1758 demand_private_info (ptid_t ptid
)
1760 struct thread_info
*info
= find_thread_ptid (ptid
);
1766 info
->priv
= xmalloc (sizeof (*(info
->priv
)));
1767 info
->private_dtor
= free_private_thread_info
;
1768 info
->priv
->core
= -1;
1769 info
->priv
->extra
= 0;
1775 /* Call this function as a result of
1776 1) A halt indication (T packet) containing a thread id
1777 2) A direct query of currthread
1778 3) Successful execution of set thread */
1781 record_currthread (struct remote_state
*rs
, ptid_t currthread
)
1783 rs
->general_thread
= currthread
;
1786 /* If 'QPassSignals' is supported, tell the remote stub what signals
1787 it can simply pass through to the inferior without reporting. */
1790 remote_pass_signals (struct target_ops
*self
,
1791 int numsigs
, unsigned char *pass_signals
)
1793 if (packet_support (PACKET_QPassSignals
) != PACKET_DISABLE
)
1795 char *pass_packet
, *p
;
1797 struct remote_state
*rs
= get_remote_state ();
1799 gdb_assert (numsigs
< 256);
1800 for (i
= 0; i
< numsigs
; i
++)
1802 if (pass_signals
[i
])
1805 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1806 strcpy (pass_packet
, "QPassSignals:");
1807 p
= pass_packet
+ strlen (pass_packet
);
1808 for (i
= 0; i
< numsigs
; i
++)
1810 if (pass_signals
[i
])
1813 *p
++ = tohex (i
>> 4);
1814 *p
++ = tohex (i
& 15);
1823 if (!rs
->last_pass_packet
|| strcmp (rs
->last_pass_packet
, pass_packet
))
1825 putpkt (pass_packet
);
1826 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1827 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1828 if (rs
->last_pass_packet
)
1829 xfree (rs
->last_pass_packet
);
1830 rs
->last_pass_packet
= pass_packet
;
1833 xfree (pass_packet
);
1837 /* If 'QProgramSignals' is supported, tell the remote stub what
1838 signals it should pass through to the inferior when detaching. */
1841 remote_program_signals (struct target_ops
*self
,
1842 int numsigs
, unsigned char *signals
)
1844 if (packet_support (PACKET_QProgramSignals
) != PACKET_DISABLE
)
1848 struct remote_state
*rs
= get_remote_state ();
1850 gdb_assert (numsigs
< 256);
1851 for (i
= 0; i
< numsigs
; i
++)
1856 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1857 strcpy (packet
, "QProgramSignals:");
1858 p
= packet
+ strlen (packet
);
1859 for (i
= 0; i
< numsigs
; i
++)
1861 if (signal_pass_state (i
))
1864 *p
++ = tohex (i
>> 4);
1865 *p
++ = tohex (i
& 15);
1874 if (!rs
->last_program_signals_packet
1875 || strcmp (rs
->last_program_signals_packet
, packet
) != 0)
1878 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1879 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1880 xfree (rs
->last_program_signals_packet
);
1881 rs
->last_program_signals_packet
= packet
;
1888 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1889 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1890 thread. If GEN is set, set the general thread, if not, then set
1891 the step/continue thread. */
1893 set_thread (struct ptid ptid
, int gen
)
1895 struct remote_state
*rs
= get_remote_state ();
1896 ptid_t state
= gen
? rs
->general_thread
: rs
->continue_thread
;
1897 char *buf
= rs
->buf
;
1898 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1900 if (ptid_equal (state
, ptid
))
1904 *buf
++ = gen
? 'g' : 'c';
1905 if (ptid_equal (ptid
, magic_null_ptid
))
1906 xsnprintf (buf
, endbuf
- buf
, "0");
1907 else if (ptid_equal (ptid
, any_thread_ptid
))
1908 xsnprintf (buf
, endbuf
- buf
, "0");
1909 else if (ptid_equal (ptid
, minus_one_ptid
))
1910 xsnprintf (buf
, endbuf
- buf
, "-1");
1912 write_ptid (buf
, endbuf
, ptid
);
1914 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1916 rs
->general_thread
= ptid
;
1918 rs
->continue_thread
= ptid
;
1922 set_general_thread (struct ptid ptid
)
1924 set_thread (ptid
, 1);
1928 set_continue_thread (struct ptid ptid
)
1930 set_thread (ptid
, 0);
1933 /* Change the remote current process. Which thread within the process
1934 ends up selected isn't important, as long as it is the same process
1935 as what INFERIOR_PTID points to.
1937 This comes from that fact that there is no explicit notion of
1938 "selected process" in the protocol. The selected process for
1939 general operations is the process the selected general thread
1943 set_general_process (void)
1945 struct remote_state
*rs
= get_remote_state ();
1947 /* If the remote can't handle multiple processes, don't bother. */
1948 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1951 /* We only need to change the remote current thread if it's pointing
1952 at some other process. */
1953 if (ptid_get_pid (rs
->general_thread
) != ptid_get_pid (inferior_ptid
))
1954 set_general_thread (inferior_ptid
);
1958 /* Return nonzero if this is the main thread that we made up ourselves
1959 to model non-threaded targets as single-threaded. */
1962 remote_thread_always_alive (struct target_ops
*ops
, ptid_t ptid
)
1964 struct remote_state
*rs
= get_remote_state ();
1967 if (ptid_equal (ptid
, magic_null_ptid
))
1968 /* The main thread is always alive. */
1971 if (ptid_get_pid (ptid
) != 0 && ptid_get_lwp (ptid
) == 0)
1972 /* The main thread is always alive. This can happen after a
1973 vAttach, if the remote side doesn't support
1980 /* Return nonzero if the thread PTID is still alive on the remote
1984 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1986 struct remote_state
*rs
= get_remote_state ();
1989 /* Check if this is a thread that we made up ourselves to model
1990 non-threaded targets as single-threaded. */
1991 if (remote_thread_always_alive (ops
, ptid
))
1995 endp
= rs
->buf
+ get_remote_packet_size ();
1998 write_ptid (p
, endp
, ptid
);
2001 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2002 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
2005 /* About these extended threadlist and threadinfo packets. They are
2006 variable length packets but, the fields within them are often fixed
2007 length. They are redundent enough to send over UDP as is the
2008 remote protocol in general. There is a matching unit test module
2011 /* WARNING: This threadref data structure comes from the remote O.S.,
2012 libstub protocol encoding, and remote.c. It is not particularly
2015 /* Right now, the internal structure is int. We want it to be bigger.
2016 Plan to fix this. */
2018 typedef int gdb_threadref
; /* Internal GDB thread reference. */
2020 /* gdb_ext_thread_info is an internal GDB data structure which is
2021 equivalent to the reply of the remote threadinfo packet. */
2023 struct gdb_ext_thread_info
2025 threadref threadid
; /* External form of thread reference. */
2026 int active
; /* Has state interesting to GDB?
2028 char display
[256]; /* Brief state display, name,
2029 blocked/suspended. */
2030 char shortname
[32]; /* To be used to name threads. */
2031 char more_display
[256]; /* Long info, statistics, queue depth,
2035 /* The volume of remote transfers can be limited by submitting
2036 a mask containing bits specifying the desired information.
2037 Use a union of these values as the 'selection' parameter to
2038 get_thread_info. FIXME: Make these TAG names more thread specific. */
2040 #define TAG_THREADID 1
2041 #define TAG_EXISTS 2
2042 #define TAG_DISPLAY 4
2043 #define TAG_THREADNAME 8
2044 #define TAG_MOREDISPLAY 16
2046 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
2048 static char *unpack_nibble (char *buf
, int *val
);
2050 static char *unpack_byte (char *buf
, int *value
);
2052 static char *pack_int (char *buf
, int value
);
2054 static char *unpack_int (char *buf
, int *value
);
2056 static char *unpack_string (char *src
, char *dest
, int length
);
2058 static char *pack_threadid (char *pkt
, threadref
*id
);
2060 static char *unpack_threadid (char *inbuf
, threadref
*id
);
2062 void int_to_threadref (threadref
*id
, int value
);
2064 static int threadref_to_int (threadref
*ref
);
2066 static void copy_threadref (threadref
*dest
, threadref
*src
);
2068 static int threadmatch (threadref
*dest
, threadref
*src
);
2070 static char *pack_threadinfo_request (char *pkt
, int mode
,
2073 static int remote_unpack_thread_info_response (char *pkt
,
2074 threadref
*expectedref
,
2075 struct gdb_ext_thread_info
2079 static int remote_get_threadinfo (threadref
*threadid
,
2080 int fieldset
, /*TAG mask */
2081 struct gdb_ext_thread_info
*info
);
2083 static char *pack_threadlist_request (char *pkt
, int startflag
,
2085 threadref
*nextthread
);
2087 static int parse_threadlist_response (char *pkt
,
2089 threadref
*original_echo
,
2090 threadref
*resultlist
,
2093 static int remote_get_threadlist (int startflag
,
2094 threadref
*nextthread
,
2098 threadref
*threadlist
);
2100 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
2102 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
2103 void *context
, int looplimit
);
2105 static int remote_newthread_step (threadref
*ref
, void *context
);
2108 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
2109 buffer we're allowed to write to. Returns
2110 BUF+CHARACTERS_WRITTEN. */
2113 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
2116 struct remote_state
*rs
= get_remote_state ();
2118 if (remote_multi_process_p (rs
))
2120 pid
= ptid_get_pid (ptid
);
2122 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
2124 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
2126 tid
= ptid_get_lwp (ptid
);
2128 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
2130 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
2135 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
2136 passed the last parsed char. Returns null_ptid on error. */
2139 read_ptid (char *buf
, char **obuf
)
2143 ULONGEST pid
= 0, tid
= 0;
2147 /* Multi-process ptid. */
2148 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2150 error (_("invalid remote ptid: %s"), p
);
2153 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2156 return ptid_build (pid
, tid
, 0);
2159 /* No multi-process. Just a tid. */
2160 pp
= unpack_varlen_hex (p
, &tid
);
2162 /* Return null_ptid when no thread id is found. */
2170 /* Since the stub is not sending a process id, then default to
2171 what's in inferior_ptid, unless it's null at this point. If so,
2172 then since there's no way to know the pid of the reported
2173 threads, use the magic number. */
2174 if (ptid_equal (inferior_ptid
, null_ptid
))
2175 pid
= ptid_get_pid (magic_null_ptid
);
2177 pid
= ptid_get_pid (inferior_ptid
);
2181 return ptid_build (pid
, tid
, 0);
2187 if (ch
>= 'a' && ch
<= 'f')
2188 return ch
- 'a' + 10;
2189 if (ch
>= '0' && ch
<= '9')
2191 if (ch
>= 'A' && ch
<= 'F')
2192 return ch
- 'A' + 10;
2197 stub_unpack_int (char *buff
, int fieldlength
)
2204 nibble
= stubhex (*buff
++);
2208 retval
= retval
<< 4;
2214 unpack_nibble (char *buf
, int *val
)
2216 *val
= fromhex (*buf
++);
2221 unpack_byte (char *buf
, int *value
)
2223 *value
= stub_unpack_int (buf
, 2);
2228 pack_int (char *buf
, int value
)
2230 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2231 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2232 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2233 buf
= pack_hex_byte (buf
, (value
& 0xff));
2238 unpack_int (char *buf
, int *value
)
2240 *value
= stub_unpack_int (buf
, 8);
2244 #if 0 /* Currently unused, uncomment when needed. */
2245 static char *pack_string (char *pkt
, char *string
);
2248 pack_string (char *pkt
, char *string
)
2253 len
= strlen (string
);
2255 len
= 200; /* Bigger than most GDB packets, junk??? */
2256 pkt
= pack_hex_byte (pkt
, len
);
2260 if ((ch
== '\0') || (ch
== '#'))
2261 ch
= '*'; /* Protect encapsulation. */
2266 #endif /* 0 (unused) */
2269 unpack_string (char *src
, char *dest
, int length
)
2278 pack_threadid (char *pkt
, threadref
*id
)
2281 unsigned char *altid
;
2283 altid
= (unsigned char *) id
;
2284 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2286 pkt
= pack_hex_byte (pkt
, *altid
++);
2292 unpack_threadid (char *inbuf
, threadref
*id
)
2295 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2298 altref
= (char *) id
;
2300 while (inbuf
< limit
)
2302 x
= stubhex (*inbuf
++);
2303 y
= stubhex (*inbuf
++);
2304 *altref
++ = (x
<< 4) | y
;
2309 /* Externally, threadrefs are 64 bits but internally, they are still
2310 ints. This is due to a mismatch of specifications. We would like
2311 to use 64bit thread references internally. This is an adapter
2315 int_to_threadref (threadref
*id
, int value
)
2317 unsigned char *scan
;
2319 scan
= (unsigned char *) id
;
2325 *scan
++ = (value
>> 24) & 0xff;
2326 *scan
++ = (value
>> 16) & 0xff;
2327 *scan
++ = (value
>> 8) & 0xff;
2328 *scan
++ = (value
& 0xff);
2332 threadref_to_int (threadref
*ref
)
2335 unsigned char *scan
;
2341 value
= (value
<< 8) | ((*scan
++) & 0xff);
2346 copy_threadref (threadref
*dest
, threadref
*src
)
2349 unsigned char *csrc
, *cdest
;
2351 csrc
= (unsigned char *) src
;
2352 cdest
= (unsigned char *) dest
;
2359 threadmatch (threadref
*dest
, threadref
*src
)
2361 /* Things are broken right now, so just assume we got a match. */
2363 unsigned char *srcp
, *destp
;
2365 srcp
= (char *) src
;
2366 destp
= (char *) dest
;
2370 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2377 threadid:1, # always request threadid
2384 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2387 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2389 *pkt
++ = 'q'; /* Info Query */
2390 *pkt
++ = 'P'; /* process or thread info */
2391 pkt
= pack_int (pkt
, mode
); /* mode */
2392 pkt
= pack_threadid (pkt
, id
); /* threadid */
2393 *pkt
= '\0'; /* terminate */
2397 /* These values tag the fields in a thread info response packet. */
2398 /* Tagging the fields allows us to request specific fields and to
2399 add more fields as time goes by. */
2401 #define TAG_THREADID 1 /* Echo the thread identifier. */
2402 #define TAG_EXISTS 2 /* Is this process defined enough to
2403 fetch registers and its stack? */
2404 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2405 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2406 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2410 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2411 struct gdb_ext_thread_info
*info
)
2413 struct remote_state
*rs
= get_remote_state ();
2417 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2420 /* info->threadid = 0; FIXME: implement zero_threadref. */
2422 info
->display
[0] = '\0';
2423 info
->shortname
[0] = '\0';
2424 info
->more_display
[0] = '\0';
2426 /* Assume the characters indicating the packet type have been
2428 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2429 pkt
= unpack_threadid (pkt
, &ref
);
2432 warning (_("Incomplete response to threadinfo request."));
2433 if (!threadmatch (&ref
, expectedref
))
2434 { /* This is an answer to a different request. */
2435 warning (_("ERROR RMT Thread info mismatch."));
2438 copy_threadref (&info
->threadid
, &ref
);
2440 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2442 /* Packets are terminated with nulls. */
2443 while ((pkt
< limit
) && mask
&& *pkt
)
2445 pkt
= unpack_int (pkt
, &tag
); /* tag */
2446 pkt
= unpack_byte (pkt
, &length
); /* length */
2447 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2449 warning (_("ERROR RMT: threadinfo tag mismatch."));
2453 if (tag
== TAG_THREADID
)
2457 warning (_("ERROR RMT: length of threadid is not 16."));
2461 pkt
= unpack_threadid (pkt
, &ref
);
2462 mask
= mask
& ~TAG_THREADID
;
2465 if (tag
== TAG_EXISTS
)
2467 info
->active
= stub_unpack_int (pkt
, length
);
2469 mask
= mask
& ~(TAG_EXISTS
);
2472 warning (_("ERROR RMT: 'exists' length too long."));
2478 if (tag
== TAG_THREADNAME
)
2480 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2481 mask
= mask
& ~TAG_THREADNAME
;
2484 if (tag
== TAG_DISPLAY
)
2486 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2487 mask
= mask
& ~TAG_DISPLAY
;
2490 if (tag
== TAG_MOREDISPLAY
)
2492 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2493 mask
= mask
& ~TAG_MOREDISPLAY
;
2496 warning (_("ERROR RMT: unknown thread info tag."));
2497 break; /* Not a tag we know about. */
2503 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2504 struct gdb_ext_thread_info
*info
)
2506 struct remote_state
*rs
= get_remote_state ();
2509 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2511 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2513 if (rs
->buf
[0] == '\0')
2516 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2521 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2524 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2525 threadref
*nextthread
)
2527 *pkt
++ = 'q'; /* info query packet */
2528 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2529 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2530 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2531 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2536 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2539 parse_threadlist_response (char *pkt
, int result_limit
,
2540 threadref
*original_echo
, threadref
*resultlist
,
2543 struct remote_state
*rs
= get_remote_state ();
2545 int count
, resultcount
, done
;
2548 /* Assume the 'q' and 'M chars have been stripped. */
2549 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2550 /* done parse past here */
2551 pkt
= unpack_byte (pkt
, &count
); /* count field */
2552 pkt
= unpack_nibble (pkt
, &done
);
2553 /* The first threadid is the argument threadid. */
2554 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2555 while ((count
-- > 0) && (pkt
< limit
))
2557 pkt
= unpack_threadid (pkt
, resultlist
++);
2558 if (resultcount
++ >= result_limit
)
2566 /* Fetch the next batch of threads from the remote. Returns -1 if the
2567 qL packet is not supported, 0 on error and 1 on success. */
2570 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2571 int *done
, int *result_count
, threadref
*threadlist
)
2573 struct remote_state
*rs
= get_remote_state ();
2576 /* Trancate result limit to be smaller than the packet size. */
2577 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2578 >= get_remote_packet_size ())
2579 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2581 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2583 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2584 if (*rs
->buf
== '\0')
2586 /* Packet not supported. */
2591 parse_threadlist_response (rs
->buf
+ 2, result_limit
,
2592 &rs
->echo_nextthread
, threadlist
, done
);
2594 if (!threadmatch (&rs
->echo_nextthread
, nextthread
))
2596 /* FIXME: This is a good reason to drop the packet. */
2597 /* Possably, there is a duplicate response. */
2599 retransmit immediatly - race conditions
2600 retransmit after timeout - yes
2602 wait for packet, then exit
2604 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2605 return 0; /* I choose simply exiting. */
2607 if (*result_count
<= 0)
2611 warning (_("RMT ERROR : failed to get remote thread list."));
2614 return result
; /* break; */
2616 if (*result_count
> result_limit
)
2619 warning (_("RMT ERROR: threadlist response longer than requested."));
2625 /* Fetch the list of remote threads, with the qL packet, and call
2626 STEPFUNCTION for each thread found. Stops iterating and returns 1
2627 if STEPFUNCTION returns true. Stops iterating and returns 0 if the
2628 STEPFUNCTION returns false. If the packet is not supported,
2632 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2635 struct remote_state
*rs
= get_remote_state ();
2636 int done
, i
, result_count
;
2644 if (loopcount
++ > looplimit
)
2647 warning (_("Remote fetch threadlist -infinite loop-."));
2650 result
= remote_get_threadlist (startflag
, &rs
->nextthread
,
2651 MAXTHREADLISTRESULTS
,
2652 &done
, &result_count
,
2653 rs
->resultthreadlist
);
2656 /* Clear for later iterations. */
2658 /* Setup to resume next batch of thread references, set nextthread. */
2659 if (result_count
>= 1)
2660 copy_threadref (&rs
->nextthread
,
2661 &rs
->resultthreadlist
[result_count
- 1]);
2663 while (result_count
--)
2665 if (!(*stepfunction
) (&rs
->resultthreadlist
[i
++], context
))
2675 /* A thread found on the remote target. */
2677 typedef struct thread_item
2679 /* The thread's PTID. */
2682 /* The thread's extra info. May be NULL. */
2685 /* The core the thread was running on. -1 if not known. */
2688 DEF_VEC_O(thread_item_t
);
2690 /* Context passed around to the various methods listing remote
2691 threads. As new threads are found, they're added to the ITEMS
2694 struct threads_listing_context
2696 /* The threads found on the remote target. */
2697 VEC (thread_item_t
) *items
;
2700 /* Discard the contents of the constructed thread listing context. */
2703 clear_threads_listing_context (void *p
)
2705 struct threads_listing_context
*context
= p
;
2707 struct thread_item
*item
;
2709 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2710 xfree (item
->extra
);
2712 VEC_free (thread_item_t
, context
->items
);
2715 /* Remove the thread specified as the related_pid field of WS
2716 from the CONTEXT list. */
2719 threads_listing_context_remove (struct target_waitstatus
*ws
,
2720 struct threads_listing_context
*context
)
2722 struct thread_item
*item
;
2724 ptid_t child_ptid
= ws
->value
.related_pid
;
2726 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2728 if (ptid_equal (item
->ptid
, child_ptid
))
2730 VEC_ordered_remove (thread_item_t
, context
->items
, i
);
2737 remote_newthread_step (threadref
*ref
, void *data
)
2739 struct threads_listing_context
*context
= data
;
2740 struct thread_item item
;
2741 int pid
= ptid_get_pid (inferior_ptid
);
2743 item
.ptid
= ptid_build (pid
, threadref_to_int (ref
), 0);
2747 VEC_safe_push (thread_item_t
, context
->items
, &item
);
2749 return 1; /* continue iterator */
2752 #define CRAZY_MAX_THREADS 1000
2755 remote_current_thread (ptid_t oldpid
)
2757 struct remote_state
*rs
= get_remote_state ();
2760 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2761 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2766 result
= read_ptid (&rs
->buf
[2], &obuf
);
2767 if (*obuf
!= '\0' && remote_debug
)
2768 fprintf_unfiltered (gdb_stdlog
,
2769 "warning: garbage in qC reply\n");
2777 /* List remote threads using the deprecated qL packet. */
2780 remote_get_threads_with_ql (struct target_ops
*ops
,
2781 struct threads_listing_context
*context
)
2783 if (remote_threadlist_iterator (remote_newthread_step
, context
,
2784 CRAZY_MAX_THREADS
) >= 0)
2790 #if defined(HAVE_LIBEXPAT)
2793 start_thread (struct gdb_xml_parser
*parser
,
2794 const struct gdb_xml_element
*element
,
2795 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2797 struct threads_listing_context
*data
= user_data
;
2799 struct thread_item item
;
2801 struct gdb_xml_value
*attr
;
2803 id
= xml_find_attribute (attributes
, "id")->value
;
2804 item
.ptid
= read_ptid (id
, NULL
);
2806 attr
= xml_find_attribute (attributes
, "core");
2808 item
.core
= *(ULONGEST
*) attr
->value
;
2814 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2818 end_thread (struct gdb_xml_parser
*parser
,
2819 const struct gdb_xml_element
*element
,
2820 void *user_data
, const char *body_text
)
2822 struct threads_listing_context
*data
= user_data
;
2824 if (body_text
&& *body_text
)
2825 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2828 const struct gdb_xml_attribute thread_attributes
[] = {
2829 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2830 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2831 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2834 const struct gdb_xml_element thread_children
[] = {
2835 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2838 const struct gdb_xml_element threads_children
[] = {
2839 { "thread", thread_attributes
, thread_children
,
2840 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2841 start_thread
, end_thread
},
2842 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2845 const struct gdb_xml_element threads_elements
[] = {
2846 { "threads", NULL
, threads_children
,
2847 GDB_XML_EF_NONE
, NULL
, NULL
},
2848 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2853 /* List remote threads using qXfer:threads:read. */
2856 remote_get_threads_with_qxfer (struct target_ops
*ops
,
2857 struct threads_listing_context
*context
)
2859 #if defined(HAVE_LIBEXPAT)
2860 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
2862 char *xml
= target_read_stralloc (ops
, TARGET_OBJECT_THREADS
, NULL
);
2863 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2865 if (xml
!= NULL
&& *xml
!= '\0')
2867 gdb_xml_parse_quick (_("threads"), "threads.dtd",
2868 threads_elements
, xml
, context
);
2871 do_cleanups (back_to
);
2879 /* List remote threads using qfThreadInfo/qsThreadInfo. */
2882 remote_get_threads_with_qthreadinfo (struct target_ops
*ops
,
2883 struct threads_listing_context
*context
)
2885 struct remote_state
*rs
= get_remote_state ();
2887 if (rs
->use_threadinfo_query
)
2891 putpkt ("qfThreadInfo");
2892 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2894 if (bufp
[0] != '\0') /* q packet recognized */
2896 while (*bufp
++ == 'm') /* reply contains one or more TID */
2900 struct thread_item item
;
2902 item
.ptid
= read_ptid (bufp
, &bufp
);
2906 VEC_safe_push (thread_item_t
, context
->items
, &item
);
2908 while (*bufp
++ == ','); /* comma-separated list */
2909 putpkt ("qsThreadInfo");
2910 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2917 /* Packet not recognized. */
2918 rs
->use_threadinfo_query
= 0;
2925 /* Implement the to_update_thread_list function for the remote
2929 remote_update_thread_list (struct target_ops
*ops
)
2931 struct remote_state
*rs
= get_remote_state ();
2932 struct threads_listing_context context
;
2933 struct cleanup
*old_chain
;
2936 context
.items
= NULL
;
2937 old_chain
= make_cleanup (clear_threads_listing_context
, &context
);
2939 /* We have a few different mechanisms to fetch the thread list. Try
2940 them all, starting with the most preferred one first, falling
2941 back to older methods. */
2942 if (remote_get_threads_with_qxfer (ops
, &context
)
2943 || remote_get_threads_with_qthreadinfo (ops
, &context
)
2944 || remote_get_threads_with_ql (ops
, &context
))
2947 struct thread_item
*item
;
2948 struct thread_info
*tp
, *tmp
;
2952 if (VEC_empty (thread_item_t
, context
.items
)
2953 && remote_thread_always_alive (ops
, inferior_ptid
))
2955 /* Some targets don't really support threads, but still
2956 reply an (empty) thread list in response to the thread
2957 listing packets, instead of replying "packet not
2958 supported". Exit early so we don't delete the main
2960 do_cleanups (old_chain
);
2964 /* CONTEXT now holds the current thread list on the remote
2965 target end. Delete GDB-side threads no longer found on the
2967 ALL_THREADS_SAFE (tp
, tmp
)
2970 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2973 if (ptid_equal (item
->ptid
, tp
->ptid
))
2977 if (i
== VEC_length (thread_item_t
, context
.items
))
2980 delete_thread (tp
->ptid
);
2984 /* Remove any unreported fork child threads from CONTEXT so
2985 that we don't interfere with follow fork, which is where
2986 creation of such threads is handled. */
2987 remove_new_fork_children (&context
);
2989 /* And now add threads we don't know about yet to our list. */
2991 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2994 if (!ptid_equal (item
->ptid
, null_ptid
))
2996 struct private_thread_info
*info
;
2997 /* In non-stop mode, we assume new found threads are
2998 running until proven otherwise with a stop reply. In
2999 all-stop, we can only get here if all threads are
3001 int running
= non_stop
? 1 : 0;
3003 remote_notice_new_inferior (item
->ptid
, running
);
3005 info
= demand_private_info (item
->ptid
);
3006 info
->core
= item
->core
;
3007 info
->extra
= item
->extra
;
3015 /* If no thread listing method is supported, then query whether
3016 each known thread is alive, one by one, with the T packet.
3017 If the target doesn't support threads at all, then this is a
3018 no-op. See remote_thread_alive. */
3022 do_cleanups (old_chain
);
3026 * Collect a descriptive string about the given thread.
3027 * The target may say anything it wants to about the thread
3028 * (typically info about its blocked / runnable state, name, etc.).
3029 * This string will appear in the info threads display.
3031 * Optional: targets are not required to implement this function.
3035 remote_threads_extra_info (struct target_ops
*self
, struct thread_info
*tp
)
3037 struct remote_state
*rs
= get_remote_state ();
3041 struct gdb_ext_thread_info threadinfo
;
3042 static char display_buf
[100]; /* arbitrary... */
3043 int n
= 0; /* position in display_buf */
3045 if (rs
->remote_desc
== 0) /* paranoia */
3046 internal_error (__FILE__
, __LINE__
,
3047 _("remote_threads_extra_info"));
3049 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
3050 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_lwp (tp
->ptid
) == 0))
3051 /* This is the main thread which was added by GDB. The remote
3052 server doesn't know about it. */
3055 if (packet_support (PACKET_qXfer_threads
) == PACKET_ENABLE
)
3057 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
3059 if (info
&& info
->priv
)
3060 return info
->priv
->extra
;
3065 if (rs
->use_threadextra_query
)
3068 char *endb
= rs
->buf
+ get_remote_packet_size ();
3070 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
3072 write_ptid (b
, endb
, tp
->ptid
);
3075 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3076 if (rs
->buf
[0] != 0)
3078 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
3079 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
3080 display_buf
[result
] = '\0';
3085 /* If the above query fails, fall back to the old method. */
3086 rs
->use_threadextra_query
= 0;
3087 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
3088 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
3089 int_to_threadref (&id
, ptid_get_lwp (tp
->ptid
));
3090 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
3091 if (threadinfo
.active
)
3093 if (*threadinfo
.shortname
)
3094 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
3095 " Name: %s,", threadinfo
.shortname
);
3096 if (*threadinfo
.display
)
3097 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3098 " State: %s,", threadinfo
.display
);
3099 if (*threadinfo
.more_display
)
3100 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
3101 " Priority: %s", threadinfo
.more_display
);
3105 /* For purely cosmetic reasons, clear up trailing commas. */
3106 if (',' == display_buf
[n
-1])
3107 display_buf
[n
-1] = ' ';
3116 remote_static_tracepoint_marker_at (struct target_ops
*self
, CORE_ADDR addr
,
3117 struct static_tracepoint_marker
*marker
)
3119 struct remote_state
*rs
= get_remote_state ();
3122 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
3124 p
+= hexnumstr (p
, addr
);
3126 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3130 error (_("Remote failure reply: %s"), p
);
3134 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3141 static VEC(static_tracepoint_marker_p
) *
3142 remote_static_tracepoint_markers_by_strid (struct target_ops
*self
,
3145 struct remote_state
*rs
= get_remote_state ();
3146 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
3147 struct static_tracepoint_marker
*marker
= NULL
;
3148 struct cleanup
*old_chain
;
3151 /* Ask for a first packet of static tracepoint marker
3154 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3157 error (_("Remote failure reply: %s"), p
);
3159 old_chain
= make_cleanup (free_current_marker
, &marker
);
3164 marker
= XCNEW (struct static_tracepoint_marker
);
3168 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
3170 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
3172 VEC_safe_push (static_tracepoint_marker_p
,
3178 release_static_tracepoint_marker (marker
);
3179 memset (marker
, 0, sizeof (*marker
));
3182 while (*p
++ == ','); /* comma-separated list */
3183 /* Ask for another packet of static tracepoint definition. */
3185 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3189 do_cleanups (old_chain
);
3194 /* Implement the to_get_ada_task_ptid function for the remote targets. */
3197 remote_get_ada_task_ptid (struct target_ops
*self
, long lwp
, long thread
)
3199 return ptid_build (ptid_get_pid (inferior_ptid
), lwp
, 0);
3203 /* Restart the remote side; this is an extended protocol operation. */
3206 extended_remote_restart (void)
3208 struct remote_state
*rs
= get_remote_state ();
3210 /* Send the restart command; for reasons I don't understand the
3211 remote side really expects a number after the "R". */
3212 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3215 remote_fileio_reset ();
3218 /* Clean up connection to a remote debugger. */
3221 remote_close (struct target_ops
*self
)
3223 struct remote_state
*rs
= get_remote_state ();
3225 if (rs
->remote_desc
== NULL
)
3226 return; /* already closed */
3228 /* Make sure we leave stdin registered in the event loop, and we
3229 don't leave the async SIGINT signal handler installed. */
3230 remote_terminal_ours (self
);
3232 serial_close (rs
->remote_desc
);
3233 rs
->remote_desc
= NULL
;
3235 /* We don't have a connection to the remote stub anymore. Get rid
3236 of all the inferiors and their threads we were controlling.
3237 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3238 will be unable to find the thread corresponding to (pid, 0, 0). */
3239 inferior_ptid
= null_ptid
;
3240 discard_all_inferiors ();
3242 /* We are closing the remote target, so we should discard
3243 everything of this target. */
3244 discard_pending_stop_replies_in_queue (rs
);
3246 if (remote_async_inferior_event_token
)
3247 delete_async_event_handler (&remote_async_inferior_event_token
);
3249 remote_notif_state_xfree (rs
->notif_state
);
3251 trace_reset_local_state ();
3254 /* Query the remote side for the text, data and bss offsets. */
3259 struct remote_state
*rs
= get_remote_state ();
3262 int lose
, num_segments
= 0, do_sections
, do_segments
;
3263 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3264 struct section_offsets
*offs
;
3265 struct symfile_segment_data
*data
;
3267 if (symfile_objfile
== NULL
)
3270 putpkt ("qOffsets");
3271 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3274 if (buf
[0] == '\000')
3275 return; /* Return silently. Stub doesn't support
3279 warning (_("Remote failure reply: %s"), buf
);
3283 /* Pick up each field in turn. This used to be done with scanf, but
3284 scanf will make trouble if CORE_ADDR size doesn't match
3285 conversion directives correctly. The following code will work
3286 with any size of CORE_ADDR. */
3287 text_addr
= data_addr
= bss_addr
= 0;
3291 if (startswith (ptr
, "Text="))
3294 /* Don't use strtol, could lose on big values. */
3295 while (*ptr
&& *ptr
!= ';')
3296 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3298 if (startswith (ptr
, ";Data="))
3301 while (*ptr
&& *ptr
!= ';')
3302 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3307 if (!lose
&& startswith (ptr
, ";Bss="))
3310 while (*ptr
&& *ptr
!= ';')
3311 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3313 if (bss_addr
!= data_addr
)
3314 warning (_("Target reported unsupported offsets: %s"), buf
);
3319 else if (startswith (ptr
, "TextSeg="))
3322 /* Don't use strtol, could lose on big values. */
3323 while (*ptr
&& *ptr
!= ';')
3324 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3327 if (startswith (ptr
, ";DataSeg="))
3330 while (*ptr
&& *ptr
!= ';')
3331 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3339 error (_("Malformed response to offset query, %s"), buf
);
3340 else if (*ptr
!= '\0')
3341 warning (_("Target reported unsupported offsets: %s"), buf
);
3343 offs
= ((struct section_offsets
*)
3344 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3345 memcpy (offs
, symfile_objfile
->section_offsets
,
3346 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3348 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3349 do_segments
= (data
!= NULL
);
3350 do_sections
= num_segments
== 0;
3352 if (num_segments
> 0)
3354 segments
[0] = text_addr
;
3355 segments
[1] = data_addr
;
3357 /* If we have two segments, we can still try to relocate everything
3358 by assuming that the .text and .data offsets apply to the whole
3359 text and data segments. Convert the offsets given in the packet
3360 to base addresses for symfile_map_offsets_to_segments. */
3361 else if (data
&& data
->num_segments
== 2)
3363 segments
[0] = data
->segment_bases
[0] + text_addr
;
3364 segments
[1] = data
->segment_bases
[1] + data_addr
;
3367 /* If the object file has only one segment, assume that it is text
3368 rather than data; main programs with no writable data are rare,
3369 but programs with no code are useless. Of course the code might
3370 have ended up in the data segment... to detect that we would need
3371 the permissions here. */
3372 else if (data
&& data
->num_segments
== 1)
3374 segments
[0] = data
->segment_bases
[0] + text_addr
;
3377 /* There's no way to relocate by segment. */
3383 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3384 offs
, num_segments
, segments
);
3386 if (ret
== 0 && !do_sections
)
3387 error (_("Can not handle qOffsets TextSeg "
3388 "response with this symbol file"));
3395 free_symfile_segment_data (data
);
3399 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3401 /* This is a temporary kludge to force data and bss to use the
3402 same offsets because that's what nlmconv does now. The real
3403 solution requires changes to the stub and remote.c that I
3404 don't have time to do right now. */
3406 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3407 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3410 objfile_relocate (symfile_objfile
, offs
);
3413 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3414 threads we know are stopped already. This is used during the
3415 initial remote connection in non-stop mode --- threads that are
3416 reported as already being stopped are left stopped. */
3419 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3421 /* If we have a stop reply for this thread, it must be stopped. */
3422 if (peek_stop_reply (thread
->ptid
))
3423 set_stop_requested (thread
->ptid
, 1);
3428 /* Send interrupt_sequence to remote target. */
3430 send_interrupt_sequence (void)
3432 struct remote_state
*rs
= get_remote_state ();
3434 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3435 remote_serial_write ("\x03", 1);
3436 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3437 serial_send_break (rs
->remote_desc
);
3438 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3440 serial_send_break (rs
->remote_desc
);
3441 remote_serial_write ("g", 1);
3444 internal_error (__FILE__
, __LINE__
,
3445 _("Invalid value for interrupt_sequence_mode: %s."),
3446 interrupt_sequence_mode
);
3450 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3451 and extract the PTID. Returns NULL_PTID if not found. */
3454 stop_reply_extract_thread (char *stop_reply
)
3456 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3460 /* Txx r:val ; r:val (...) */
3463 /* Look for "register" named "thread". */
3468 p1
= strchr (p
, ':');
3472 if (strncmp (p
, "thread", p1
- p
) == 0)
3473 return read_ptid (++p1
, &p
);
3475 p1
= strchr (p
, ';');
3487 /* Determine the remote side's current thread. If we have a stop
3488 reply handy (in WAIT_STATUS), maybe it's a T stop reply with a
3489 "thread" register we can extract the current thread from. If not,
3490 ask the remote which is the current thread with qC. The former
3491 method avoids a roundtrip. */
3494 get_current_thread (char *wait_status
)
3496 ptid_t ptid
= null_ptid
;
3498 /* Note we don't use remote_parse_stop_reply as that makes use of
3499 the target architecture, which we haven't yet fully determined at
3501 if (wait_status
!= NULL
)
3502 ptid
= stop_reply_extract_thread (wait_status
);
3503 if (ptid_equal (ptid
, null_ptid
))
3504 ptid
= remote_current_thread (inferior_ptid
);
3509 /* Query the remote target for which is the current thread/process,
3510 add it to our tables, and update INFERIOR_PTID. The caller is
3511 responsible for setting the state such that the remote end is ready
3512 to return the current thread.
3514 This function is called after handling the '?' or 'vRun' packets,
3515 whose response is a stop reply from which we can also try
3516 extracting the thread. If the target doesn't support the explicit
3517 qC query, we infer the current thread from that stop reply, passed
3518 in in WAIT_STATUS, which may be NULL. */
3521 add_current_inferior_and_thread (char *wait_status
)
3523 struct remote_state
*rs
= get_remote_state ();
3527 inferior_ptid
= null_ptid
;
3529 /* Now, if we have thread information, update inferior_ptid. */
3530 ptid
= get_current_thread (wait_status
);
3532 if (!ptid_equal (ptid
, null_ptid
))
3534 if (!remote_multi_process_p (rs
))
3537 inferior_ptid
= ptid
;
3541 /* Without this, some commands which require an active target
3542 (such as kill) won't work. This variable serves (at least)
3543 double duty as both the pid of the target process (if it has
3544 such), and as a flag indicating that a target is active. */
3545 inferior_ptid
= magic_null_ptid
;
3549 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1, 1);
3551 /* Add the main thread. */
3552 add_thread_silent (inferior_ptid
);
3556 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3558 struct remote_state
*rs
= get_remote_state ();
3559 struct packet_config
*noack_config
;
3560 char *wait_status
= NULL
;
3562 immediate_quit
++; /* Allow user to interrupt it. */
3565 if (interrupt_on_connect
)
3566 send_interrupt_sequence ();
3568 /* Ack any packet which the remote side has already sent. */
3569 serial_write (rs
->remote_desc
, "+", 1);
3571 /* Signal other parts that we're going through the initial setup,
3572 and so things may not be stable yet. */
3573 rs
->starting_up
= 1;
3575 /* The first packet we send to the target is the optional "supported
3576 packets" request. If the target can answer this, it will tell us
3577 which later probes to skip. */
3578 remote_query_supported ();
3580 /* If the stub wants to get a QAllow, compose one and send it. */
3581 if (packet_support (PACKET_QAllow
) != PACKET_DISABLE
)
3582 remote_set_permissions (target
);
3584 /* Next, we possibly activate noack mode.
3586 If the QStartNoAckMode packet configuration is set to AUTO,
3587 enable noack mode if the stub reported a wish for it with
3590 If set to TRUE, then enable noack mode even if the stub didn't
3591 report it in qSupported. If the stub doesn't reply OK, the
3592 session ends with an error.
3594 If FALSE, then don't activate noack mode, regardless of what the
3595 stub claimed should be the default with qSupported. */
3597 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3598 if (packet_config_support (noack_config
) != PACKET_DISABLE
)
3600 putpkt ("QStartNoAckMode");
3601 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3602 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3608 /* Tell the remote that we are using the extended protocol. */
3610 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3613 /* Let the target know which signals it is allowed to pass down to
3615 update_signals_program_target ();
3617 /* Next, if the target can specify a description, read it. We do
3618 this before anything involving memory or registers. */
3619 target_find_description ();
3621 /* Next, now that we know something about the target, update the
3622 address spaces in the program spaces. */
3623 update_address_spaces ();
3625 /* On OSs where the list of libraries is global to all
3626 processes, we fetch them early. */
3627 if (gdbarch_has_global_solist (target_gdbarch ()))
3628 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3632 if (packet_support (PACKET_QNonStop
) != PACKET_ENABLE
)
3633 error (_("Non-stop mode requested, but remote "
3634 "does not support non-stop"));
3636 putpkt ("QNonStop:1");
3637 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3639 if (strcmp (rs
->buf
, "OK") != 0)
3640 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3642 /* Find about threads and processes the stub is already
3643 controlling. We default to adding them in the running state.
3644 The '?' query below will then tell us about which threads are
3646 remote_update_thread_list (target
);
3648 else if (packet_support (PACKET_QNonStop
) == PACKET_ENABLE
)
3650 /* Don't assume that the stub can operate in all-stop mode.
3651 Request it explicitly. */
3652 putpkt ("QNonStop:0");
3653 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3655 if (strcmp (rs
->buf
, "OK") != 0)
3656 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3659 /* Upload TSVs regardless of whether the target is running or not. The
3660 remote stub, such as GDBserver, may have some predefined or builtin
3661 TSVs, even if the target is not running. */
3662 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3664 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3666 remote_upload_trace_state_variables (target
, &uploaded_tsvs
);
3667 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3670 /* Check whether the target is running now. */
3672 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3678 struct inferior
*inf
;
3680 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3683 error (_("The target is not running (try extended-remote?)"));
3685 /* We're connected, but not running. Drop out before we
3686 call start_remote. */
3687 rs
->starting_up
= 0;
3692 /* Save the reply for later. */
3693 wait_status
= alloca (strlen (rs
->buf
) + 1);
3694 strcpy (wait_status
, rs
->buf
);
3697 /* Fetch thread list. */
3698 target_update_thread_list ();
3700 /* Let the stub know that we want it to return the thread. */
3701 set_continue_thread (minus_one_ptid
);
3703 if (thread_count () == 0)
3705 /* Target has no concept of threads at all. GDB treats
3706 non-threaded target as single-threaded; add a main
3708 add_current_inferior_and_thread (wait_status
);
3712 /* We have thread information; select the thread the target
3713 says should be current. If we're reconnecting to a
3714 multi-threaded program, this will ideally be the thread
3715 that last reported an event before GDB disconnected. */
3716 inferior_ptid
= get_current_thread (wait_status
);
3717 if (ptid_equal (inferior_ptid
, null_ptid
))
3719 /* Odd... The target was able to list threads, but not
3720 tell us which thread was current (no "thread"
3721 register in T stop reply?). Just pick the first
3722 thread in the thread list then. */
3725 fprintf_unfiltered (gdb_stdlog
,
3726 "warning: couldn't determine remote "
3727 "current thread; picking first in list.\n");
3729 inferior_ptid
= thread_list
->ptid
;
3733 /* init_wait_for_inferior should be called before get_offsets in order
3734 to manage `inserted' flag in bp loc in a correct state.
3735 breakpoint_init_inferior, called from init_wait_for_inferior, set
3736 `inserted' flag to 0, while before breakpoint_re_set, called from
3737 start_remote, set `inserted' flag to 1. In the initialization of
3738 inferior, breakpoint_init_inferior should be called first, and then
3739 breakpoint_re_set can be called. If this order is broken, state of
3740 `inserted' flag is wrong, and cause some problems on breakpoint
3742 init_wait_for_inferior ();
3744 get_offsets (); /* Get text, data & bss offsets. */
3746 /* If we could not find a description using qXfer, and we know
3747 how to do it some other way, try again. This is not
3748 supported for non-stop; it could be, but it is tricky if
3749 there are no stopped threads when we connect. */
3750 if (remote_read_description_p (target
)
3751 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3753 target_clear_description ();
3754 target_find_description ();
3757 /* Use the previously fetched status. */
3758 gdb_assert (wait_status
!= NULL
);
3759 strcpy (rs
->buf
, wait_status
);
3760 rs
->cached_wait_status
= 1;
3763 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3767 /* Clear WFI global state. Do this before finding about new
3768 threads and inferiors, and setting the current inferior.
3769 Otherwise we would clear the proceed status of the current
3770 inferior when we want its stop_soon state to be preserved
3771 (see notice_new_inferior). */
3772 init_wait_for_inferior ();
3774 /* In non-stop, we will either get an "OK", meaning that there
3775 are no stopped threads at this time; or, a regular stop
3776 reply. In the latter case, there may be more than one thread
3777 stopped --- we pull them all out using the vStopped
3779 if (strcmp (rs
->buf
, "OK") != 0)
3781 struct notif_client
*notif
= ¬if_client_stop
;
3783 /* remote_notif_get_pending_replies acks this one, and gets
3785 rs
->notif_state
->pending_event
[notif_client_stop
.id
]
3786 = remote_notif_parse (notif
, rs
->buf
);
3787 remote_notif_get_pending_events (notif
);
3789 /* Make sure that threads that were stopped remain
3791 iterate_over_threads (set_stop_requested_callback
, NULL
);
3794 if (target_can_async_p ())
3797 if (thread_count () == 0)
3800 error (_("The target is not running (try extended-remote?)"));
3802 /* We're connected, but not running. Drop out before we
3803 call start_remote. */
3804 rs
->starting_up
= 0;
3808 /* Let the stub know that we want it to return the thread. */
3810 /* Force the stub to choose a thread. */
3811 set_general_thread (null_ptid
);
3814 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3815 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3816 error (_("remote didn't report the current thread in non-stop mode"));
3818 get_offsets (); /* Get text, data & bss offsets. */
3820 /* In non-stop mode, any cached wait status will be stored in
3821 the stop reply queue. */
3822 gdb_assert (wait_status
== NULL
);
3824 /* Report all signals during attach/startup. */
3825 remote_pass_signals (target
, 0, NULL
);
3828 /* If we connected to a live target, do some additional setup. */
3829 if (target_has_execution
)
3831 if (symfile_objfile
) /* No use without a symbol-file. */
3832 remote_check_symbols ();
3835 /* Possibly the target has been engaged in a trace run started
3836 previously; find out where things are at. */
3837 if (remote_get_trace_status (target
, current_trace_status ()) != -1)
3839 struct uploaded_tp
*uploaded_tps
= NULL
;
3841 if (current_trace_status ()->running
)
3842 printf_filtered (_("Trace is already running on the target.\n"));
3844 remote_upload_tracepoints (target
, &uploaded_tps
);
3846 merge_uploaded_tracepoints (&uploaded_tps
);
3849 /* The thread and inferior lists are now synchronized with the
3850 target, our symbols have been relocated, and we're merged the
3851 target's tracepoints with ours. We're done with basic start
3853 rs
->starting_up
= 0;
3855 /* Maybe breakpoints are global and need to be inserted now. */
3856 if (breakpoints_should_be_inserted_now ())
3857 insert_breakpoints ();
3860 /* Open a connection to a remote debugger.
3861 NAME is the filename used for communication. */
3864 remote_open (const char *name
, int from_tty
)
3866 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3869 /* Open a connection to a remote debugger using the extended
3870 remote gdb protocol. NAME is the filename used for communication. */
3873 extended_remote_open (const char *name
, int from_tty
)
3875 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3878 /* Reset all packets back to "unknown support". Called when opening a
3879 new connection to a remote target. */
3882 reset_all_packet_configs_support (void)
3886 for (i
= 0; i
< PACKET_MAX
; i
++)
3887 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
3890 /* Initialize all packet configs. */
3893 init_all_packet_configs (void)
3897 for (i
= 0; i
< PACKET_MAX
; i
++)
3899 remote_protocol_packets
[i
].detect
= AUTO_BOOLEAN_AUTO
;
3900 remote_protocol_packets
[i
].support
= PACKET_SUPPORT_UNKNOWN
;
3904 /* Symbol look-up. */
3907 remote_check_symbols (void)
3909 struct remote_state
*rs
= get_remote_state ();
3910 char *msg
, *reply
, *tmp
;
3911 struct bound_minimal_symbol sym
;
3914 /* The remote side has no concept of inferiors that aren't running
3915 yet, it only knows about running processes. If we're connected
3916 but our current inferior is not running, we should not invite the
3917 remote target to request symbol lookups related to its
3918 (unrelated) current process. */
3919 if (!target_has_execution
)
3922 if (packet_support (PACKET_qSymbol
) == PACKET_DISABLE
)
3925 /* Make sure the remote is pointing at the right process. Note
3926 there's no way to select "no process". */
3927 set_general_process ();
3929 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3930 because we need both at the same time. */
3931 msg
= alloca (get_remote_packet_size ());
3933 /* Invite target to request symbol lookups. */
3935 putpkt ("qSymbol::");
3936 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3937 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3940 while (startswith (reply
, "qSymbol:"))
3942 struct bound_minimal_symbol sym
;
3945 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3947 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3948 if (sym
.minsym
== NULL
)
3949 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3952 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
3953 CORE_ADDR sym_addr
= BMSYMBOL_VALUE_ADDRESS (sym
);
3955 /* If this is a function address, return the start of code
3956 instead of any data function descriptor. */
3957 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3961 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3962 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3966 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3971 static struct serial
*
3972 remote_serial_open (const char *name
)
3974 static int udp_warning
= 0;
3976 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3977 of in ser-tcp.c, because it is the remote protocol assuming that the
3978 serial connection is reliable and not the serial connection promising
3980 if (!udp_warning
&& startswith (name
, "udp:"))
3982 warning (_("The remote protocol may be unreliable over UDP.\n"
3983 "Some events may be lost, rendering further debugging "
3988 return serial_open (name
);
3991 /* Inform the target of our permission settings. The permission flags
3992 work without this, but if the target knows the settings, it can do
3993 a couple things. First, it can add its own check, to catch cases
3994 that somehow manage to get by the permissions checks in target
3995 methods. Second, if the target is wired to disallow particular
3996 settings (for instance, a system in the field that is not set up to
3997 be able to stop at a breakpoint), it can object to any unavailable
4001 remote_set_permissions (struct target_ops
*self
)
4003 struct remote_state
*rs
= get_remote_state ();
4005 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
4006 "WriteReg:%x;WriteMem:%x;"
4007 "InsertBreak:%x;InsertTrace:%x;"
4008 "InsertFastTrace:%x;Stop:%x",
4009 may_write_registers
, may_write_memory
,
4010 may_insert_breakpoints
, may_insert_tracepoints
,
4011 may_insert_fast_tracepoints
, may_stop
);
4013 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4015 /* If the target didn't like the packet, warn the user. Do not try
4016 to undo the user's settings, that would just be maddening. */
4017 if (strcmp (rs
->buf
, "OK") != 0)
4018 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
4021 /* This type describes each known response to the qSupported
4023 struct protocol_feature
4025 /* The name of this protocol feature. */
4028 /* The default for this protocol feature. */
4029 enum packet_support default_support
;
4031 /* The function to call when this feature is reported, or after
4032 qSupported processing if the feature is not supported.
4033 The first argument points to this structure. The second
4034 argument indicates whether the packet requested support be
4035 enabled, disabled, or probed (or the default, if this function
4036 is being called at the end of processing and this feature was
4037 not reported). The third argument may be NULL; if not NULL, it
4038 is a NUL-terminated string taken from the packet following
4039 this feature's name and an equals sign. */
4040 void (*func
) (const struct protocol_feature
*, enum packet_support
,
4043 /* The corresponding packet for this feature. Only used if
4044 FUNC is remote_supported_packet. */
4049 remote_supported_packet (const struct protocol_feature
*feature
,
4050 enum packet_support support
,
4051 const char *argument
)
4055 warning (_("Remote qSupported response supplied an unexpected value for"
4056 " \"%s\"."), feature
->name
);
4060 remote_protocol_packets
[feature
->packet
].support
= support
;
4064 remote_packet_size (const struct protocol_feature
*feature
,
4065 enum packet_support support
, const char *value
)
4067 struct remote_state
*rs
= get_remote_state ();
4072 if (support
!= PACKET_ENABLE
)
4075 if (value
== NULL
|| *value
== '\0')
4077 warning (_("Remote target reported \"%s\" without a size."),
4083 packet_size
= strtol (value
, &value_end
, 16);
4084 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
4086 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
4087 feature
->name
, value
);
4091 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
4093 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
4094 packet_size
, MAX_REMOTE_PACKET_SIZE
);
4095 packet_size
= MAX_REMOTE_PACKET_SIZE
;
4098 /* Record the new maximum packet size. */
4099 rs
->explicit_packet_size
= packet_size
;
4102 static const struct protocol_feature remote_protocol_features
[] = {
4103 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
4104 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
4105 PACKET_qXfer_auxv
},
4106 { "qXfer:exec-file:read", PACKET_DISABLE
, remote_supported_packet
,
4107 PACKET_qXfer_exec_file
},
4108 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
4109 PACKET_qXfer_features
},
4110 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
4111 PACKET_qXfer_libraries
},
4112 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
4113 PACKET_qXfer_libraries_svr4
},
4114 { "augmented-libraries-svr4-read", PACKET_DISABLE
,
4115 remote_supported_packet
, PACKET_augmented_libraries_svr4_read_feature
},
4116 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
4117 PACKET_qXfer_memory_map
},
4118 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
4119 PACKET_qXfer_spu_read
},
4120 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
4121 PACKET_qXfer_spu_write
},
4122 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
4123 PACKET_qXfer_osdata
},
4124 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
4125 PACKET_qXfer_threads
},
4126 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
4127 PACKET_qXfer_traceframe_info
},
4128 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
4129 PACKET_QPassSignals
},
4130 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
4131 PACKET_QProgramSignals
},
4132 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
4133 PACKET_QStartNoAckMode
},
4134 { "multiprocess", PACKET_DISABLE
, remote_supported_packet
,
4135 PACKET_multiprocess_feature
},
4136 { "QNonStop", PACKET_DISABLE
, remote_supported_packet
, PACKET_QNonStop
},
4137 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
4138 PACKET_qXfer_siginfo_read
},
4139 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
4140 PACKET_qXfer_siginfo_write
},
4141 { "ConditionalTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4142 PACKET_ConditionalTracepoints
},
4143 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_supported_packet
,
4144 PACKET_ConditionalBreakpoints
},
4145 { "BreakpointCommands", PACKET_DISABLE
, remote_supported_packet
,
4146 PACKET_BreakpointCommands
},
4147 { "FastTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4148 PACKET_FastTracepoints
},
4149 { "StaticTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4150 PACKET_StaticTracepoints
},
4151 {"InstallInTrace", PACKET_DISABLE
, remote_supported_packet
,
4152 PACKET_InstallInTrace
},
4153 { "DisconnectedTracing", PACKET_DISABLE
, remote_supported_packet
,
4154 PACKET_DisconnectedTracing_feature
},
4155 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
4157 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
4159 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
4160 PACKET_TracepointSource
},
4161 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
4163 { "EnableDisableTracepoints", PACKET_DISABLE
, remote_supported_packet
,
4164 PACKET_EnableDisableTracepoints_feature
},
4165 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
4166 PACKET_qXfer_fdpic
},
4167 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
4169 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
4170 PACKET_QDisableRandomization
},
4171 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
4172 { "QTBuffer:size", PACKET_DISABLE
,
4173 remote_supported_packet
, PACKET_QTBuffer_size
},
4174 { "tracenz", PACKET_DISABLE
, remote_supported_packet
, PACKET_tracenz_feature
},
4175 { "Qbtrace:off", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_off
},
4176 { "Qbtrace:bts", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_bts
},
4177 { "Qbtrace:pt", PACKET_DISABLE
, remote_supported_packet
, PACKET_Qbtrace_pt
},
4178 { "qXfer:btrace:read", PACKET_DISABLE
, remote_supported_packet
,
4179 PACKET_qXfer_btrace
},
4180 { "qXfer:btrace-conf:read", PACKET_DISABLE
, remote_supported_packet
,
4181 PACKET_qXfer_btrace_conf
},
4182 { "Qbtrace-conf:bts:size", PACKET_DISABLE
, remote_supported_packet
,
4183 PACKET_Qbtrace_conf_bts_size
},
4184 { "swbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_swbreak_feature
},
4185 { "hwbreak", PACKET_DISABLE
, remote_supported_packet
, PACKET_hwbreak_feature
},
4186 { "fork-events", PACKET_DISABLE
, remote_supported_packet
,
4187 PACKET_fork_event_feature
},
4188 { "vfork-events", PACKET_DISABLE
, remote_supported_packet
,
4189 PACKET_vfork_event_feature
},
4190 { "Qbtrace-conf:pt:size", PACKET_DISABLE
, remote_supported_packet
,
4191 PACKET_Qbtrace_conf_pt_size
}
4194 static char *remote_support_xml
;
4196 /* Register string appended to "xmlRegisters=" in qSupported query. */
4199 register_remote_support_xml (const char *xml
)
4201 #if defined(HAVE_LIBEXPAT)
4202 if (remote_support_xml
== NULL
)
4203 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4206 char *copy
= xstrdup (remote_support_xml
+ 13);
4207 char *p
= strtok (copy
, ",");
4211 if (strcmp (p
, xml
) == 0)
4218 while ((p
= strtok (NULL
, ",")) != NULL
);
4221 remote_support_xml
= reconcat (remote_support_xml
,
4222 remote_support_xml
, ",", xml
,
4229 remote_query_supported_append (char *msg
, const char *append
)
4232 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4234 return xstrdup (append
);
4238 remote_query_supported (void)
4240 struct remote_state
*rs
= get_remote_state ();
4243 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4245 /* The packet support flags are handled differently for this packet
4246 than for most others. We treat an error, a disabled packet, and
4247 an empty response identically: any features which must be reported
4248 to be used will be automatically disabled. An empty buffer
4249 accomplishes this, since that is also the representation for a list
4250 containing no features. */
4253 if (packet_support (PACKET_qSupported
) != PACKET_DISABLE
)
4256 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4258 q
= remote_query_supported_append (q
, "multiprocess+");
4260 if (packet_set_cmd_state (PACKET_swbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4261 q
= remote_query_supported_append (q
, "swbreak+");
4262 if (packet_set_cmd_state (PACKET_hwbreak_feature
) != AUTO_BOOLEAN_FALSE
)
4263 q
= remote_query_supported_append (q
, "hwbreak+");
4265 if (remote_support_xml
)
4266 q
= remote_query_supported_append (q
, remote_support_xml
);
4268 q
= remote_query_supported_append (q
, "qRelocInsn+");
4272 if (packet_set_cmd_state (PACKET_fork_event_feature
)
4273 != AUTO_BOOLEAN_FALSE
)
4274 q
= remote_query_supported_append (q
, "fork-events+");
4275 if (packet_set_cmd_state (PACKET_vfork_event_feature
)
4276 != AUTO_BOOLEAN_FALSE
)
4277 q
= remote_query_supported_append (q
, "vfork-events+");
4280 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4283 do_cleanups (old_chain
);
4285 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4287 /* If an error occured, warn, but do not return - just reset the
4288 buffer to empty and go on to disable features. */
4289 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4292 warning (_("Remote failure reply: %s"), rs
->buf
);
4297 memset (seen
, 0, sizeof (seen
));
4302 enum packet_support is_supported
;
4303 char *p
, *end
, *name_end
, *value
;
4305 /* First separate out this item from the rest of the packet. If
4306 there's another item after this, we overwrite the separator
4307 (terminated strings are much easier to work with). */
4309 end
= strchr (p
, ';');
4312 end
= p
+ strlen (p
);
4322 warning (_("empty item in \"qSupported\" response"));
4327 name_end
= strchr (p
, '=');
4330 /* This is a name=value entry. */
4331 is_supported
= PACKET_ENABLE
;
4332 value
= name_end
+ 1;
4341 is_supported
= PACKET_ENABLE
;
4345 is_supported
= PACKET_DISABLE
;
4349 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4353 warning (_("unrecognized item \"%s\" "
4354 "in \"qSupported\" response"), p
);
4360 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4361 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4363 const struct protocol_feature
*feature
;
4366 feature
= &remote_protocol_features
[i
];
4367 feature
->func (feature
, is_supported
, value
);
4372 /* If we increased the packet size, make sure to increase the global
4373 buffer size also. We delay this until after parsing the entire
4374 qSupported packet, because this is the same buffer we were
4376 if (rs
->buf_size
< rs
->explicit_packet_size
)
4378 rs
->buf_size
= rs
->explicit_packet_size
;
4379 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4382 /* Handle the defaults for unmentioned features. */
4383 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4386 const struct protocol_feature
*feature
;
4388 feature
= &remote_protocol_features
[i
];
4389 feature
->func (feature
, feature
->default_support
, NULL
);
4393 /* Remove any of the remote.c targets from target stack. Upper targets depend
4394 on it so remove them first. */
4397 remote_unpush_target (void)
4399 pop_all_targets_above (process_stratum
- 1);
4403 remote_open_1 (const char *name
, int from_tty
,
4404 struct target_ops
*target
, int extended_p
)
4406 struct remote_state
*rs
= get_remote_state ();
4409 error (_("To open a remote debug connection, you need to specify what\n"
4410 "serial device is attached to the remote system\n"
4411 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4413 /* See FIXME above. */
4414 if (!target_async_permitted
)
4415 wait_forever_enabled_p
= 1;
4417 /* If we're connected to a running target, target_preopen will kill it.
4418 Ask this question first, before target_preopen has a chance to kill
4420 if (rs
->remote_desc
!= NULL
&& !have_inferiors ())
4423 && !query (_("Already connected to a remote target. Disconnect? ")))
4424 error (_("Still connected."));
4427 /* Here the possibly existing remote target gets unpushed. */
4428 target_preopen (from_tty
);
4430 /* Make sure we send the passed signals list the next time we resume. */
4431 xfree (rs
->last_pass_packet
);
4432 rs
->last_pass_packet
= NULL
;
4434 /* Make sure we send the program signals list the next time we
4436 xfree (rs
->last_program_signals_packet
);
4437 rs
->last_program_signals_packet
= NULL
;
4439 remote_fileio_reset ();
4440 reopen_exec_file ();
4443 rs
->remote_desc
= remote_serial_open (name
);
4444 if (!rs
->remote_desc
)
4445 perror_with_name (name
);
4447 if (baud_rate
!= -1)
4449 if (serial_setbaudrate (rs
->remote_desc
, baud_rate
))
4451 /* The requested speed could not be set. Error out to
4452 top level after closing remote_desc. Take care to
4453 set remote_desc to NULL to avoid closing remote_desc
4455 serial_close (rs
->remote_desc
);
4456 rs
->remote_desc
= NULL
;
4457 perror_with_name (name
);
4461 serial_setparity (rs
->remote_desc
, serial_parity
);
4462 serial_raw (rs
->remote_desc
);
4464 /* If there is something sitting in the buffer we might take it as a
4465 response to a command, which would be bad. */
4466 serial_flush_input (rs
->remote_desc
);
4470 puts_filtered ("Remote debugging using ");
4471 puts_filtered (name
);
4472 puts_filtered ("\n");
4474 push_target (target
); /* Switch to using remote target now. */
4476 /* Register extra event sources in the event loop. */
4477 remote_async_inferior_event_token
4478 = create_async_event_handler (remote_async_inferior_event_handler
,
4480 rs
->notif_state
= remote_notif_state_allocate ();
4482 /* Reset the target state; these things will be queried either by
4483 remote_query_supported or as they are needed. */
4484 reset_all_packet_configs_support ();
4485 rs
->cached_wait_status
= 0;
4486 rs
->explicit_packet_size
= 0;
4488 rs
->extended
= extended_p
;
4489 rs
->waiting_for_stop_reply
= 0;
4490 rs
->ctrlc_pending_p
= 0;
4492 rs
->general_thread
= not_sent_ptid
;
4493 rs
->continue_thread
= not_sent_ptid
;
4494 rs
->remote_traceframe_number
= -1;
4496 /* Probe for ability to use "ThreadInfo" query, as required. */
4497 rs
->use_threadinfo_query
= 1;
4498 rs
->use_threadextra_query
= 1;
4500 if (target_async_permitted
)
4502 /* With this target we start out by owning the terminal. */
4503 remote_async_terminal_ours_p
= 1;
4505 /* FIXME: cagney/1999-09-23: During the initial connection it is
4506 assumed that the target is already ready and able to respond to
4507 requests. Unfortunately remote_start_remote() eventually calls
4508 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4509 around this. Eventually a mechanism that allows
4510 wait_for_inferior() to expect/get timeouts will be
4512 wait_forever_enabled_p
= 0;
4515 /* First delete any symbols previously loaded from shared libraries. */
4516 no_shared_libraries (NULL
, 0);
4519 init_thread_list ();
4521 /* Start the remote connection. If error() or QUIT, discard this
4522 target (we'd otherwise be in an inconsistent state) and then
4523 propogate the error on up the exception chain. This ensures that
4524 the caller doesn't stumble along blindly assuming that the
4525 function succeeded. The CLI doesn't have this problem but other
4526 UI's, such as MI do.
4528 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4529 this function should return an error indication letting the
4530 caller restore the previous state. Unfortunately the command
4531 ``target remote'' is directly wired to this function making that
4532 impossible. On a positive note, the CLI side of this problem has
4533 been fixed - the function set_cmd_context() makes it possible for
4534 all the ``target ....'' commands to share a common callback
4535 function. See cli-dump.c. */
4540 remote_start_remote (from_tty
, target
, extended_p
);
4542 CATCH (ex
, RETURN_MASK_ALL
)
4544 /* Pop the partially set up target - unless something else did
4545 already before throwing the exception. */
4546 if (rs
->remote_desc
!= NULL
)
4547 remote_unpush_target ();
4548 if (target_async_permitted
)
4549 wait_forever_enabled_p
= 1;
4550 throw_exception (ex
);
4555 remote_btrace_reset ();
4557 if (target_async_permitted
)
4558 wait_forever_enabled_p
= 1;
4561 /* Detach the specified process. */
4564 remote_detach_pid (int pid
)
4566 struct remote_state
*rs
= get_remote_state ();
4568 if (remote_multi_process_p (rs
))
4569 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4571 strcpy (rs
->buf
, "D");
4574 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4576 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4578 else if (rs
->buf
[0] == '\0')
4579 error (_("Remote doesn't know how to detach"));
4581 error (_("Can't detach process."));
4584 /* This detaches a program to which we previously attached, using
4585 inferior_ptid to identify the process. After this is done, GDB
4586 can be used to debug some other program. We better not have left
4587 any breakpoints in the target program or it'll die when it hits
4591 remote_detach_1 (const char *args
, int from_tty
)
4593 int pid
= ptid_get_pid (inferior_ptid
);
4594 struct remote_state
*rs
= get_remote_state ();
4595 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
4599 error (_("Argument given to \"detach\" when remotely debugging."));
4601 if (!target_has_execution
)
4602 error (_("No process to detach from."));
4606 char *exec_file
= get_exec_file (0);
4607 if (exec_file
== NULL
)
4609 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4610 target_pid_to_str (pid_to_ptid (pid
)));
4611 gdb_flush (gdb_stdout
);
4614 /* Tell the remote target to detach. */
4615 remote_detach_pid (pid
);
4617 if (from_tty
&& !rs
->extended
)
4618 puts_filtered (_("Ending remote debugging.\n"));
4620 /* Check to see if we are detaching a fork parent. Note that if we
4621 are detaching a fork child, tp == NULL. */
4622 is_fork_parent
= (tp
!= NULL
4623 && tp
->pending_follow
.kind
== TARGET_WAITKIND_FORKED
);
4625 /* If doing detach-on-fork, we don't mourn, because that will delete
4626 breakpoints that should be available for the followed inferior. */
4627 if (!is_fork_parent
)
4628 target_mourn_inferior ();
4631 inferior_ptid
= null_ptid
;
4632 detach_inferior (pid
);
4637 remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4639 remote_detach_1 (args
, from_tty
);
4643 extended_remote_detach (struct target_ops
*ops
, const char *args
, int from_tty
)
4645 remote_detach_1 (args
, from_tty
);
4648 /* Target follow-fork function for remote targets. On entry, and
4649 at return, the current inferior is the fork parent.
4651 Note that although this is currently only used for extended-remote,
4652 it is named remote_follow_fork in anticipation of using it for the
4653 remote target as well. */
4656 remote_follow_fork (struct target_ops
*ops
, int follow_child
,
4659 struct remote_state
*rs
= get_remote_state ();
4660 enum target_waitkind kind
= inferior_thread ()->pending_follow
.kind
;
4662 if ((kind
== TARGET_WAITKIND_FORKED
&& remote_fork_event_p (rs
))
4663 || (kind
== TARGET_WAITKIND_VFORKED
&& remote_vfork_event_p (rs
)))
4665 /* When following the parent and detaching the child, we detach
4666 the child here. For the case of following the child and
4667 detaching the parent, the detach is done in the target-
4668 independent follow fork code in infrun.c. We can't use
4669 target_detach when detaching an unfollowed child because
4670 the client side doesn't know anything about the child. */
4671 if (detach_fork
&& !follow_child
)
4673 /* Detach the fork child. */
4677 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
4678 child_pid
= ptid_get_pid (child_ptid
);
4680 remote_detach_pid (child_pid
);
4681 detach_inferior (child_pid
);
4687 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4690 remote_disconnect (struct target_ops
*target
, const char *args
, int from_tty
)
4693 error (_("Argument given to \"disconnect\" when remotely debugging."));
4695 /* Make sure we unpush even the extended remote targets; mourn
4696 won't do it. So call remote_mourn directly instead of
4697 target_mourn_inferior. */
4698 remote_mourn (target
);
4701 puts_filtered ("Ending remote debugging.\n");
4704 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4705 be chatty about it. */
4708 extended_remote_attach (struct target_ops
*target
, const char *args
,
4711 struct remote_state
*rs
= get_remote_state ();
4713 char *wait_status
= NULL
;
4715 pid
= parse_pid_to_attach (args
);
4717 /* Remote PID can be freely equal to getpid, do not check it here the same
4718 way as in other targets. */
4720 if (packet_support (PACKET_vAttach
) == PACKET_DISABLE
)
4721 error (_("This target does not support attaching to a process"));
4725 char *exec_file
= get_exec_file (0);
4728 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4729 target_pid_to_str (pid_to_ptid (pid
)));
4731 printf_unfiltered (_("Attaching to %s\n"),
4732 target_pid_to_str (pid_to_ptid (pid
)));
4734 gdb_flush (gdb_stdout
);
4737 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4739 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4741 switch (packet_ok (rs
->buf
,
4742 &remote_protocol_packets
[PACKET_vAttach
]))
4747 /* Save the reply for later. */
4748 wait_status
= alloca (strlen (rs
->buf
) + 1);
4749 strcpy (wait_status
, rs
->buf
);
4751 else if (strcmp (rs
->buf
, "OK") != 0)
4752 error (_("Attaching to %s failed with: %s"),
4753 target_pid_to_str (pid_to_ptid (pid
)),
4756 case PACKET_UNKNOWN
:
4757 error (_("This target does not support attaching to a process"));
4759 error (_("Attaching to %s failed"),
4760 target_pid_to_str (pid_to_ptid (pid
)));
4763 set_current_inferior (remote_add_inferior (0, pid
, 1, 0));
4765 inferior_ptid
= pid_to_ptid (pid
);
4769 struct thread_info
*thread
;
4771 /* Get list of threads. */
4772 remote_update_thread_list (target
);
4774 thread
= first_thread_of_process (pid
);
4776 inferior_ptid
= thread
->ptid
;
4778 inferior_ptid
= pid_to_ptid (pid
);
4780 /* Invalidate our notion of the remote current thread. */
4781 record_currthread (rs
, minus_one_ptid
);
4785 /* Now, if we have thread information, update inferior_ptid. */
4786 inferior_ptid
= remote_current_thread (inferior_ptid
);
4788 /* Add the main thread to the thread list. */
4789 add_thread_silent (inferior_ptid
);
4792 /* Next, if the target can specify a description, read it. We do
4793 this before anything involving memory or registers. */
4794 target_find_description ();
4798 /* Use the previously fetched status. */
4799 gdb_assert (wait_status
!= NULL
);
4801 if (target_can_async_p ())
4803 struct notif_event
*reply
4804 = remote_notif_parse (¬if_client_stop
, wait_status
);
4806 push_stop_reply ((struct stop_reply
*) reply
);
4812 gdb_assert (wait_status
!= NULL
);
4813 strcpy (rs
->buf
, wait_status
);
4814 rs
->cached_wait_status
= 1;
4818 gdb_assert (wait_status
== NULL
);
4821 /* Implementation of the to_post_attach method. */
4824 extended_remote_post_attach (struct target_ops
*ops
, int pid
)
4826 /* In certain cases GDB might not have had the chance to start
4827 symbol lookup up until now. This could happen if the debugged
4828 binary is not using shared libraries, the vsyscall page is not
4829 present (on Linux) and the binary itself hadn't changed since the
4830 debugging process was started. */
4831 if (symfile_objfile
!= NULL
)
4832 remote_check_symbols();
4836 /* Check for the availability of vCont. This function should also check
4840 remote_vcont_probe (struct remote_state
*rs
)
4844 strcpy (rs
->buf
, "vCont?");
4846 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4849 /* Make sure that the features we assume are supported. */
4850 if (startswith (buf
, "vCont"))
4853 int support_s
, support_S
, support_c
, support_C
;
4859 rs
->supports_vCont
.t
= 0;
4860 rs
->supports_vCont
.r
= 0;
4861 while (p
&& *p
== ';')
4864 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4866 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4868 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4870 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4872 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4873 rs
->supports_vCont
.t
= 1;
4874 else if (*p
== 'r' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4875 rs
->supports_vCont
.r
= 1;
4877 p
= strchr (p
, ';');
4880 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4881 BUF will make packet_ok disable the packet. */
4882 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4886 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4889 /* Helper function for building "vCont" resumptions. Write a
4890 resumption to P. ENDP points to one-passed-the-end of the buffer
4891 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4892 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4893 resumed thread should be single-stepped and/or signalled. If PTID
4894 equals minus_one_ptid, then all threads are resumed; if PTID
4895 represents a process, then all threads of the process are resumed;
4896 the thread to be stepped and/or signalled is given in the global
4900 append_resumption (char *p
, char *endp
,
4901 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4903 struct remote_state
*rs
= get_remote_state ();
4905 if (step
&& siggnal
!= GDB_SIGNAL_0
)
4906 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4908 /* GDB is willing to range step. */
4909 && use_range_stepping
4910 /* Target supports range stepping. */
4911 && rs
->supports_vCont
.r
4912 /* We don't currently support range stepping multiple
4913 threads with a wildcard (though the protocol allows it,
4914 so stubs shouldn't make an active effort to forbid
4916 && !(remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4918 struct thread_info
*tp
;
4920 if (ptid_equal (ptid
, minus_one_ptid
))
4922 /* If we don't know about the target thread's tid, then
4923 we're resuming magic_null_ptid (see caller). */
4924 tp
= find_thread_ptid (magic_null_ptid
);
4927 tp
= find_thread_ptid (ptid
);
4928 gdb_assert (tp
!= NULL
);
4930 if (tp
->control
.may_range_step
)
4932 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
4934 p
+= xsnprintf (p
, endp
- p
, ";r%s,%s",
4935 phex_nz (tp
->control
.step_range_start
,
4937 phex_nz (tp
->control
.step_range_end
,
4941 p
+= xsnprintf (p
, endp
- p
, ";s");
4944 p
+= xsnprintf (p
, endp
- p
, ";s");
4945 else if (siggnal
!= GDB_SIGNAL_0
)
4946 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4948 p
+= xsnprintf (p
, endp
- p
, ";c");
4950 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4954 /* All (-1) threads of process. */
4955 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
4957 p
+= xsnprintf (p
, endp
- p
, ":");
4958 p
= write_ptid (p
, endp
, nptid
);
4960 else if (!ptid_equal (ptid
, minus_one_ptid
))
4962 p
+= xsnprintf (p
, endp
- p
, ":");
4963 p
= write_ptid (p
, endp
, ptid
);
4969 /* Append a vCont continue-with-signal action for threads that have a
4970 non-zero stop signal. */
4973 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
4975 struct thread_info
*thread
;
4977 ALL_NON_EXITED_THREADS (thread
)
4978 if (ptid_match (thread
->ptid
, ptid
)
4979 && !ptid_equal (inferior_ptid
, thread
->ptid
)
4980 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
4982 p
= append_resumption (p
, endp
, thread
->ptid
,
4983 0, thread
->suspend
.stop_signal
);
4984 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4990 /* Resume the remote inferior by using a "vCont" packet. The thread
4991 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4992 resumed thread should be single-stepped and/or signalled. If PTID
4993 equals minus_one_ptid, then all threads are resumed; the thread to
4994 be stepped and/or signalled is given in the global INFERIOR_PTID.
4995 This function returns non-zero iff it resumes the inferior.
4997 This function issues a strict subset of all possible vCont commands at the
5001 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5003 struct remote_state
*rs
= get_remote_state ();
5007 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5008 remote_vcont_probe (rs
);
5010 if (packet_support (PACKET_vCont
) == PACKET_DISABLE
)
5014 endp
= rs
->buf
+ get_remote_packet_size ();
5016 /* If we could generate a wider range of packets, we'd have to worry
5017 about overflowing BUF. Should there be a generic
5018 "multi-part-packet" packet? */
5020 p
+= xsnprintf (p
, endp
- p
, "vCont");
5022 if (ptid_equal (ptid
, magic_null_ptid
))
5024 /* MAGIC_NULL_PTID means that we don't have any active threads,
5025 so we don't have any TID numbers the inferior will
5026 understand. Make sure to only send forms that do not specify
5028 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
5030 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
5032 /* Resume all threads (of all processes, or of a single
5033 process), with preference for INFERIOR_PTID. This assumes
5034 inferior_ptid belongs to the set of all threads we are about
5036 if (step
|| siggnal
!= GDB_SIGNAL_0
)
5038 /* Step inferior_ptid, with or without signal. */
5039 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
5042 /* Also pass down any pending signaled resumption for other
5043 threads not the current. */
5044 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
5046 /* And continue others without a signal. */
5047 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
5051 /* Scheduler locking; resume only PTID. */
5052 append_resumption (p
, endp
, ptid
, step
, siggnal
);
5055 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
5060 /* In non-stop, the stub replies to vCont with "OK". The stop
5061 reply will be reported asynchronously by means of a `%Stop'
5063 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5064 if (strcmp (rs
->buf
, "OK") != 0)
5065 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
5071 /* Tell the remote machine to resume. */
5074 remote_resume (struct target_ops
*ops
,
5075 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
5077 struct remote_state
*rs
= get_remote_state ();
5080 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
5081 (explained in remote-notif.c:handle_notification) so
5082 remote_notif_process is not called. We need find a place where
5083 it is safe to start a 'vNotif' sequence. It is good to do it
5084 before resuming inferior, because inferior was stopped and no RSP
5085 traffic at that moment. */
5087 remote_notif_process (rs
->notif_state
, ¬if_client_stop
);
5089 rs
->last_sent_signal
= siggnal
;
5090 rs
->last_sent_step
= step
;
5092 /* The vCont packet doesn't need to specify threads via Hc. */
5093 /* No reverse support (yet) for vCont. */
5094 if (execution_direction
!= EXEC_REVERSE
)
5095 if (remote_vcont_resume (ptid
, step
, siggnal
))
5098 /* All other supported resume packets do use Hc, so set the continue
5100 if (ptid_equal (ptid
, minus_one_ptid
))
5101 set_continue_thread (any_thread_ptid
);
5103 set_continue_thread (ptid
);
5106 if (execution_direction
== EXEC_REVERSE
)
5108 /* We don't pass signals to the target in reverse exec mode. */
5109 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
5110 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
5113 if (step
&& packet_support (PACKET_bs
) == PACKET_DISABLE
)
5114 error (_("Remote reverse-step not supported."));
5115 if (!step
&& packet_support (PACKET_bc
) == PACKET_DISABLE
)
5116 error (_("Remote reverse-continue not supported."));
5118 strcpy (buf
, step
? "bs" : "bc");
5120 else if (siggnal
!= GDB_SIGNAL_0
)
5122 buf
[0] = step
? 'S' : 'C';
5123 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
5124 buf
[2] = tohex (((int) siggnal
) & 0xf);
5128 strcpy (buf
, step
? "s" : "c");
5133 /* We are about to start executing the inferior, let's register it
5134 with the event loop. NOTE: this is the one place where all the
5135 execution commands end up. We could alternatively do this in each
5136 of the execution commands in infcmd.c. */
5137 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
5138 into infcmd.c in order to allow inferior function calls to work
5139 NOT asynchronously. */
5140 if (target_can_async_p ())
5143 /* We've just told the target to resume. The remote server will
5144 wait for the inferior to stop, and then send a stop reply. In
5145 the mean time, we can't start another command/query ourselves
5146 because the stub wouldn't be ready to process it. This applies
5147 only to the base all-stop protocol, however. In non-stop (which
5148 only supports vCont), the stub replies with an "OK", and is
5149 immediate able to process further serial input. */
5151 rs
->waiting_for_stop_reply
= 1;
5155 /* Set up the signal handler for SIGINT, while the target is
5156 executing, ovewriting the 'regular' SIGINT signal handler. */
5158 async_initialize_sigint_signal_handler (void)
5160 signal (SIGINT
, async_handle_remote_sigint
);
5163 /* Signal handler for SIGINT, while the target is executing. */
5165 async_handle_remote_sigint (int sig
)
5167 signal (sig
, async_handle_remote_sigint_twice
);
5168 /* Note we need to go through gdb_call_async_signal_handler in order
5169 to wake up the event loop on Windows. */
5170 gdb_call_async_signal_handler (async_sigint_remote_token
, 0);
5173 /* Signal handler for SIGINT, installed after SIGINT has already been
5174 sent once. It will take effect the second time that the user sends
5177 async_handle_remote_sigint_twice (int sig
)
5179 signal (sig
, async_handle_remote_sigint
);
5180 /* See note in async_handle_remote_sigint. */
5181 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 0);
5184 /* Perform the real interruption of the target execution, in response
5187 async_remote_interrupt (gdb_client_data arg
)
5190 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
5192 target_stop (inferior_ptid
);
5195 /* Perform interrupt, if the first attempt did not succeed. Just give
5196 up on the target alltogether. */
5198 async_remote_interrupt_twice (gdb_client_data arg
)
5201 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
5206 /* Reinstall the usual SIGINT handlers, after the target has
5209 async_cleanup_sigint_signal_handler (void *dummy
)
5211 signal (SIGINT
, handle_sigint
);
5214 /* Send ^C to target to halt it. Target will respond, and send us a
5216 static void (*ofunc
) (int);
5218 /* The command line interface's stop routine. This function is installed
5219 as a signal handler for SIGINT. The first time a user requests a
5220 stop, we call remote_stop to send a break or ^C. If there is no
5221 response from the target (it didn't stop when the user requested it),
5222 we ask the user if he'd like to detach from the target. */
5224 sync_remote_interrupt (int signo
)
5226 /* If this doesn't work, try more severe steps. */
5227 signal (signo
, sync_remote_interrupt_twice
);
5229 gdb_call_async_signal_handler (async_sigint_remote_token
, 1);
5232 /* The user typed ^C twice. */
5235 sync_remote_interrupt_twice (int signo
)
5237 signal (signo
, ofunc
);
5238 gdb_call_async_signal_handler (async_sigint_remote_twice_token
, 1);
5239 signal (signo
, sync_remote_interrupt
);
5242 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
5243 thread, all threads of a remote process, or all threads of all
5247 remote_stop_ns (ptid_t ptid
)
5249 struct remote_state
*rs
= get_remote_state ();
5251 char *endp
= rs
->buf
+ get_remote_packet_size ();
5253 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
5254 remote_vcont_probe (rs
);
5256 if (!rs
->supports_vCont
.t
)
5257 error (_("Remote server does not support stopping threads"));
5259 if (ptid_equal (ptid
, minus_one_ptid
)
5260 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5261 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5266 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5268 if (ptid_is_pid (ptid
))
5269 /* All (-1) threads of process. */
5270 nptid
= ptid_build (ptid_get_pid (ptid
), -1, 0);
5273 /* Small optimization: if we already have a stop reply for
5274 this thread, no use in telling the stub we want this
5276 if (peek_stop_reply (ptid
))
5282 write_ptid (p
, endp
, nptid
);
5285 /* In non-stop, we get an immediate OK reply. The stop reply will
5286 come in asynchronously by notification. */
5288 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5289 if (strcmp (rs
->buf
, "OK") != 0)
5290 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5293 /* All-stop version of target_stop. Sends a break or a ^C to stop the
5294 remote target. It is undefined which thread of which process
5295 reports the stop. */
5298 remote_stop_as (ptid_t ptid
)
5300 struct remote_state
*rs
= get_remote_state ();
5302 rs
->ctrlc_pending_p
= 1;
5304 /* If the inferior is stopped already, but the core didn't know
5305 about it yet, just ignore the request. The cached wait status
5306 will be collected in remote_wait. */
5307 if (rs
->cached_wait_status
)
5310 /* Send interrupt_sequence to remote target. */
5311 send_interrupt_sequence ();
5314 /* This is the generic stop called via the target vector. When a target
5315 interrupt is requested, either by the command line or the GUI, we
5316 will eventually end up here. */
5319 remote_stop (struct target_ops
*self
, ptid_t ptid
)
5322 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5325 remote_stop_ns (ptid
);
5327 remote_stop_as (ptid
);
5330 /* Ask the user what to do when an interrupt is received. */
5333 interrupt_query (void)
5335 target_terminal_ours ();
5337 if (target_is_async_p ())
5339 signal (SIGINT
, handle_sigint
);
5344 if (query (_("Interrupted while waiting for the program.\n\
5345 Give up (and stop debugging it)? ")))
5347 remote_unpush_target ();
5352 target_terminal_inferior ();
5355 /* Enable/disable target terminal ownership. Most targets can use
5356 terminal groups to control terminal ownership. Remote targets are
5357 different in that explicit transfer of ownership to/from GDB/target
5361 remote_terminal_inferior (struct target_ops
*self
)
5363 if (!target_async_permitted
)
5364 /* Nothing to do. */
5367 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5368 idempotent. The event-loop GDB talking to an asynchronous target
5369 with a synchronous command calls this function from both
5370 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5371 transfer the terminal to the target when it shouldn't this guard
5373 if (!remote_async_terminal_ours_p
)
5375 delete_file_handler (input_fd
);
5376 remote_async_terminal_ours_p
= 0;
5377 async_initialize_sigint_signal_handler ();
5378 /* NOTE: At this point we could also register our selves as the
5379 recipient of all input. Any characters typed could then be
5380 passed on down to the target. */
5384 remote_terminal_ours (struct target_ops
*self
)
5386 if (!target_async_permitted
)
5387 /* Nothing to do. */
5390 /* See FIXME in remote_terminal_inferior. */
5391 if (remote_async_terminal_ours_p
)
5393 async_cleanup_sigint_signal_handler (NULL
);
5394 add_file_handler (input_fd
, stdin_event_handler
, 0);
5395 remote_async_terminal_ours_p
= 1;
5399 remote_console_output (char *msg
)
5403 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5406 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5410 fputs_unfiltered (tb
, gdb_stdtarg
);
5412 gdb_flush (gdb_stdtarg
);
5415 typedef struct cached_reg
5418 gdb_byte data
[MAX_REGISTER_SIZE
];
5421 DEF_VEC_O(cached_reg_t
);
5423 typedef struct stop_reply
5425 struct notif_event base
;
5427 /* The identifier of the thread about this event */
5430 /* The remote state this event is associated with. When the remote
5431 connection, represented by a remote_state object, is closed,
5432 all the associated stop_reply events should be released. */
5433 struct remote_state
*rs
;
5435 struct target_waitstatus ws
;
5437 /* Expedited registers. This makes remote debugging a bit more
5438 efficient for those targets that provide critical registers as
5439 part of their normal status mechanism (as another roundtrip to
5440 fetch them is avoided). */
5441 VEC(cached_reg_t
) *regcache
;
5443 enum target_stop_reason stop_reason
;
5445 CORE_ADDR watch_data_address
;
5450 DECLARE_QUEUE_P (stop_reply_p
);
5451 DEFINE_QUEUE_P (stop_reply_p
);
5452 /* The list of already fetched and acknowledged stop events. This
5453 queue is used for notification Stop, and other notifications
5454 don't need queue for their events, because the notification events
5455 of Stop can't be consumed immediately, so that events should be
5456 queued first, and be consumed by remote_wait_{ns,as} one per
5457 time. Other notifications can consume their events immediately,
5458 so queue is not needed for them. */
5459 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5462 stop_reply_xfree (struct stop_reply
*r
)
5464 notif_event_xfree ((struct notif_event
*) r
);
5468 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5469 struct notif_event
*event
)
5471 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5475 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5476 struct notif_event
*event
)
5478 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5481 putpkt ((char *) self
->ack_command
);
5483 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5484 /* We got an unknown stop reply. */
5485 error (_("Unknown stop reply"));
5487 push_stop_reply (stop_reply
);
5491 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5493 /* We can't get pending events in remote_notif_process for
5494 notification stop, and we have to do this in remote_wait_ns
5495 instead. If we fetch all queued events from stub, remote stub
5496 may exit and we have no chance to process them back in
5498 mark_async_event_handler (remote_async_inferior_event_token
);
5503 stop_reply_dtr (struct notif_event
*event
)
5505 struct stop_reply
*r
= (struct stop_reply
*) event
;
5507 VEC_free (cached_reg_t
, r
->regcache
);
5510 static struct notif_event
*
5511 remote_notif_stop_alloc_reply (void)
5513 struct notif_event
*r
5514 = (struct notif_event
*) XNEW (struct stop_reply
);
5516 r
->dtr
= stop_reply_dtr
;
5521 /* A client of notification Stop. */
5523 struct notif_client notif_client_stop
=
5527 remote_notif_stop_parse
,
5528 remote_notif_stop_ack
,
5529 remote_notif_stop_can_get_pending_events
,
5530 remote_notif_stop_alloc_reply
,
5534 /* A parameter to pass data in and out. */
5536 struct queue_iter_param
5539 struct stop_reply
*output
;
5542 /* Determine if THREAD is a pending fork parent thread. ARG contains
5543 the pid of the process that owns the threads we want to check, or
5544 -1 if we want to check all threads. */
5547 is_pending_fork_parent (struct target_waitstatus
*ws
, int event_pid
,
5550 if (ws
->kind
== TARGET_WAITKIND_FORKED
5551 || ws
->kind
== TARGET_WAITKIND_VFORKED
)
5553 if (event_pid
== -1 || event_pid
== ptid_get_pid (thread_ptid
))
5560 /* Check whether EVENT is a fork event, and if it is, remove the
5561 fork child from the context list passed in DATA. */
5564 remove_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
5565 QUEUE_ITER (stop_reply_p
) *iter
,
5569 struct queue_iter_param
*param
= data
;
5570 struct threads_listing_context
*context
= param
->input
;
5572 if (event
->ws
.kind
== TARGET_WAITKIND_FORKED
5573 || event
->ws
.kind
== TARGET_WAITKIND_VFORKED
)
5575 threads_listing_context_remove (&event
->ws
, context
);
5581 /* If CONTEXT contains any fork child threads that have not been
5582 reported yet, remove them from the CONTEXT list. If such a
5583 thread exists it is because we are stopped at a fork catchpoint
5584 and have not yet called follow_fork, which will set up the
5585 host-side data structures for the new process. */
5588 remove_new_fork_children (struct threads_listing_context
*context
)
5590 struct thread_info
* thread
;
5592 struct notif_client
*notif
= ¬if_client_stop
;
5593 struct queue_iter_param param
;
5595 /* For any threads stopped at a fork event, remove the corresponding
5596 fork child threads from the CONTEXT list. */
5597 ALL_NON_EXITED_THREADS (thread
)
5599 struct target_waitstatus
*ws
= &thread
->pending_follow
;
5601 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
5603 threads_listing_context_remove (ws
, context
);
5607 /* Check for any pending fork events (not reported or processed yet)
5608 in process PID and remove those fork child threads from the
5609 CONTEXT list as well. */
5610 remote_notif_get_pending_events (notif
);
5611 param
.input
= context
;
5612 param
.output
= NULL
;
5613 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5614 remove_child_of_pending_fork
, ¶m
);
5617 /* Remove stop replies in the queue if its pid is equal to the given
5621 remove_stop_reply_for_inferior (QUEUE (stop_reply_p
) *q
,
5622 QUEUE_ITER (stop_reply_p
) *iter
,
5626 struct queue_iter_param
*param
= data
;
5627 struct inferior
*inf
= param
->input
;
5629 if (ptid_get_pid (event
->ptid
) == inf
->pid
)
5631 stop_reply_xfree (event
);
5632 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5638 /* Discard all pending stop replies of inferior INF. */
5641 discard_pending_stop_replies (struct inferior
*inf
)
5644 struct queue_iter_param param
;
5645 struct stop_reply
*reply
;
5646 struct remote_state
*rs
= get_remote_state ();
5647 struct remote_notif_state
*rns
= rs
->notif_state
;
5649 /* This function can be notified when an inferior exists. When the
5650 target is not remote, the notification state is NULL. */
5651 if (rs
->remote_desc
== NULL
)
5654 reply
= (struct stop_reply
*) rns
->pending_event
[notif_client_stop
.id
];
5656 /* Discard the in-flight notification. */
5657 if (reply
!= NULL
&& ptid_get_pid (reply
->ptid
) == inf
->pid
)
5659 stop_reply_xfree (reply
);
5660 rns
->pending_event
[notif_client_stop
.id
] = NULL
;
5664 param
.output
= NULL
;
5665 /* Discard the stop replies we have already pulled with
5667 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5668 remove_stop_reply_for_inferior
, ¶m
);
5671 /* If its remote state is equal to the given remote state,
5672 remove EVENT from the stop reply queue. */
5675 remove_stop_reply_of_remote_state (QUEUE (stop_reply_p
) *q
,
5676 QUEUE_ITER (stop_reply_p
) *iter
,
5680 struct queue_iter_param
*param
= data
;
5681 struct remote_state
*rs
= param
->input
;
5683 if (event
->rs
== rs
)
5685 stop_reply_xfree (event
);
5686 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5692 /* Discard the stop replies for RS in stop_reply_queue. */
5695 discard_pending_stop_replies_in_queue (struct remote_state
*rs
)
5697 struct queue_iter_param param
;
5700 param
.output
= NULL
;
5701 /* Discard the stop replies we have already pulled with
5703 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5704 remove_stop_reply_of_remote_state
, ¶m
);
5707 /* A parameter to pass data in and out. */
5710 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5711 QUEUE_ITER (stop_reply_p
) *iter
,
5715 struct queue_iter_param
*param
= data
;
5716 ptid_t
*ptid
= param
->input
;
5718 if (ptid_match (event
->ptid
, *ptid
))
5720 param
->output
= event
;
5721 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5728 /* Remove the first reply in 'stop_reply_queue' which matches
5731 static struct stop_reply
*
5732 remote_notif_remove_queued_reply (ptid_t ptid
)
5734 struct queue_iter_param param
;
5736 param
.input
= &ptid
;
5737 param
.output
= NULL
;
5739 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5740 remote_notif_remove_once_on_match
, ¶m
);
5742 fprintf_unfiltered (gdb_stdlog
,
5743 "notif: discard queued event: 'Stop' in %s\n",
5744 target_pid_to_str (ptid
));
5746 return param
.output
;
5749 /* Look for a queued stop reply belonging to PTID. If one is found,
5750 remove it from the queue, and return it. Returns NULL if none is
5751 found. If there are still queued events left to process, tell the
5752 event loop to get back to target_wait soon. */
5754 static struct stop_reply
*
5755 queued_stop_reply (ptid_t ptid
)
5757 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
5759 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5760 /* There's still at least an event left. */
5761 mark_async_event_handler (remote_async_inferior_event_token
);
5766 /* Push a fully parsed stop reply in the stop reply queue. Since we
5767 know that we now have at least one queued event left to pass to the
5768 core side, tell the event loop to get back to target_wait soon. */
5771 push_stop_reply (struct stop_reply
*new_event
)
5773 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
5776 fprintf_unfiltered (gdb_stdlog
,
5777 "notif: push 'Stop' %s to queue %d\n",
5778 target_pid_to_str (new_event
->ptid
),
5779 QUEUE_length (stop_reply_p
,
5782 mark_async_event_handler (remote_async_inferior_event_token
);
5786 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
5787 QUEUE_ITER (stop_reply_p
) *iter
,
5788 struct stop_reply
*event
,
5791 ptid_t
*ptid
= data
;
5793 return !(ptid_equal (*ptid
, event
->ptid
)
5794 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5797 /* Returns true if we have a stop reply for PTID. */
5800 peek_stop_reply (ptid_t ptid
)
5802 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5803 stop_reply_match_ptid_and_ws
, &ptid
);
5806 /* Skip PACKET until the next semi-colon (or end of string). */
5809 skip_to_semicolon (char *p
)
5811 while (*p
!= '\0' && *p
!= ';')
5816 /* Parse the stop reply in BUF. Either the function succeeds, and the
5817 result is stored in EVENT, or throws an error. */
5820 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5822 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5826 event
->ptid
= null_ptid
;
5827 event
->rs
= get_remote_state ();
5828 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5829 event
->ws
.value
.integer
= 0;
5830 event
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
5831 event
->regcache
= NULL
;
5836 case 'T': /* Status with PC, SP, FP, ... */
5837 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5838 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5840 n... = register number
5841 r... = register contents
5844 p
= &buf
[3]; /* after Txx */
5850 p1
= strchr (p
, ':');
5852 error (_("Malformed packet(a) (missing colon): %s\n\
5856 error (_("Malformed packet(a) (missing register number): %s\n\
5860 /* Some "registers" are actually extended stop information.
5861 Note if you're adding a new entry here: GDB 7.9 and
5862 earlier assume that all register "numbers" that start
5863 with an hex digit are real register numbers. Make sure
5864 the server only sends such a packet if it knows the
5865 client understands it. */
5867 if (strncmp (p
, "thread", p1
- p
) == 0)
5868 event
->ptid
= read_ptid (++p1
, &p
);
5869 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5870 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5871 || (strncmp (p
, "awatch", p1
- p
) == 0))
5873 event
->stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
5874 p
= unpack_varlen_hex (++p1
, &addr
);
5875 event
->watch_data_address
= (CORE_ADDR
) addr
;
5877 else if (strncmp (p
, "swbreak", p1
- p
) == 0)
5879 event
->stop_reason
= TARGET_STOPPED_BY_SW_BREAKPOINT
;
5881 /* Make sure the stub doesn't forget to indicate support
5883 if (packet_support (PACKET_swbreak_feature
) != PACKET_ENABLE
)
5884 error (_("Unexpected swbreak stop reason"));
5886 /* The value part is documented as "must be empty",
5887 though we ignore it, in case we ever decide to make
5888 use of it in a backward compatible way. */
5889 p
= skip_to_semicolon (p1
+ 1);
5891 else if (strncmp (p
, "hwbreak", p1
- p
) == 0)
5893 event
->stop_reason
= TARGET_STOPPED_BY_HW_BREAKPOINT
;
5895 /* Make sure the stub doesn't forget to indicate support
5897 if (packet_support (PACKET_hwbreak_feature
) != PACKET_ENABLE
)
5898 error (_("Unexpected hwbreak stop reason"));
5901 p
= skip_to_semicolon (p1
+ 1);
5903 else if (strncmp (p
, "library", p1
- p
) == 0)
5905 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5906 p
= skip_to_semicolon (p1
+ 1);
5908 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5910 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5911 /* p1 will indicate "begin" or "end", but it makes
5912 no difference for now, so ignore it. */
5913 p
= skip_to_semicolon (p1
+ 1);
5915 else if (strncmp (p
, "core", p1
- p
) == 0)
5919 p
= unpack_varlen_hex (++p1
, &c
);
5922 else if (strncmp (p
, "fork", p1
- p
) == 0)
5924 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
5925 event
->ws
.kind
= TARGET_WAITKIND_FORKED
;
5927 else if (strncmp (p
, "vfork", p1
- p
) == 0)
5929 event
->ws
.value
.related_pid
= read_ptid (++p1
, &p
);
5930 event
->ws
.kind
= TARGET_WAITKIND_VFORKED
;
5932 else if (strncmp (p
, "vforkdone", p1
- p
) == 0)
5934 event
->ws
.kind
= TARGET_WAITKIND_VFORK_DONE
;
5935 p
= skip_to_semicolon (p1
+ 1);
5942 /* Maybe a real ``P'' register number. */
5943 p_temp
= unpack_varlen_hex (p
, &pnum
);
5944 /* If the first invalid character is the colon, we got a
5945 register number. Otherwise, it's an unknown stop
5949 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5950 cached_reg_t cached_reg
;
5953 error (_("Remote sent bad register number %s: %s\n\
5955 hex_string (pnum
), p
, buf
);
5957 cached_reg
.num
= reg
->regnum
;
5960 fieldsize
= hex2bin (p
, cached_reg
.data
,
5961 register_size (target_gdbarch (),
5964 if (fieldsize
< register_size (target_gdbarch (),
5966 warning (_("Remote reply is too short: %s"), buf
);
5968 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5972 /* Not a number. Silently skip unknown optional
5974 p
= skip_to_semicolon (p1
+ 1);
5979 error (_("Remote register badly formatted: %s\nhere: %s"),
5984 if (event
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5988 case 'S': /* Old style status, just signal only. */
5992 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5993 sig
= (fromhex (buf
[1]) << 4) + fromhex (buf
[2]);
5994 if (GDB_SIGNAL_FIRST
<= sig
&& sig
< GDB_SIGNAL_LAST
)
5995 event
->ws
.value
.sig
= (enum gdb_signal
) sig
;
5997 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6000 case 'W': /* Target exited. */
6007 /* GDB used to accept only 2 hex chars here. Stubs should
6008 only send more if they detect GDB supports multi-process
6010 p
= unpack_varlen_hex (&buf
[1], &value
);
6014 /* The remote process exited. */
6015 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
6016 event
->ws
.value
.integer
= value
;
6020 /* The remote process exited with a signal. */
6021 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
6022 if (GDB_SIGNAL_FIRST
<= value
&& value
< GDB_SIGNAL_LAST
)
6023 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
6025 event
->ws
.value
.sig
= GDB_SIGNAL_UNKNOWN
;
6028 /* If no process is specified, assume inferior_ptid. */
6029 pid
= ptid_get_pid (inferior_ptid
);
6038 else if (startswith (p
, "process:"))
6042 p
+= sizeof ("process:") - 1;
6043 unpack_varlen_hex (p
, &upid
);
6047 error (_("unknown stop reply packet: %s"), buf
);
6050 error (_("unknown stop reply packet: %s"), buf
);
6051 event
->ptid
= pid_to_ptid (pid
);
6056 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
6057 error (_("No process or thread specified in stop reply: %s"), buf
);
6060 /* When the stub wants to tell GDB about a new notification reply, it
6061 sends a notification (%Stop, for example). Those can come it at
6062 any time, hence, we have to make sure that any pending
6063 putpkt/getpkt sequence we're making is finished, before querying
6064 the stub for more events with the corresponding ack command
6065 (vStopped, for example). E.g., if we started a vStopped sequence
6066 immediately upon receiving the notification, something like this
6074 1.6) <-- (registers reply to step #1.3)
6076 Obviously, the reply in step #1.6 would be unexpected to a vStopped
6079 To solve this, whenever we parse a %Stop notification successfully,
6080 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
6081 doing whatever we were doing:
6087 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
6088 2.5) <-- (registers reply to step #2.3)
6090 Eventualy after step #2.5, we return to the event loop, which
6091 notices there's an event on the
6092 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
6093 associated callback --- the function below. At this point, we're
6094 always safe to start a vStopped sequence. :
6097 2.7) <-- T05 thread:2
6103 remote_notif_get_pending_events (struct notif_client
*nc
)
6105 struct remote_state
*rs
= get_remote_state ();
6107 if (rs
->notif_state
->pending_event
[nc
->id
] != NULL
)
6110 fprintf_unfiltered (gdb_stdlog
,
6111 "notif: process: '%s' ack pending event\n",
6115 nc
->ack (nc
, rs
->buf
, rs
->notif_state
->pending_event
[nc
->id
]);
6116 rs
->notif_state
->pending_event
[nc
->id
] = NULL
;
6120 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6121 if (strcmp (rs
->buf
, "OK") == 0)
6124 remote_notif_ack (nc
, rs
->buf
);
6130 fprintf_unfiltered (gdb_stdlog
,
6131 "notif: process: '%s' no pending reply\n",
6136 /* Called when it is decided that STOP_REPLY holds the info of the
6137 event that is to be returned to the core. This function always
6138 destroys STOP_REPLY. */
6141 process_stop_reply (struct stop_reply
*stop_reply
,
6142 struct target_waitstatus
*status
)
6146 *status
= stop_reply
->ws
;
6147 ptid
= stop_reply
->ptid
;
6149 /* If no thread/process was reported by the stub, assume the current
6151 if (ptid_equal (ptid
, null_ptid
))
6152 ptid
= inferior_ptid
;
6154 if (status
->kind
!= TARGET_WAITKIND_EXITED
6155 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6157 struct remote_state
*rs
= get_remote_state ();
6159 /* Expedited registers. */
6160 if (stop_reply
->regcache
)
6162 struct regcache
*regcache
6163 = get_thread_arch_regcache (ptid
, target_gdbarch ());
6168 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
6170 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
6171 VEC_free (cached_reg_t
, stop_reply
->regcache
);
6174 rs
->stop_reason
= stop_reply
->stop_reason
;
6175 rs
->remote_watch_data_address
= stop_reply
->watch_data_address
;
6177 remote_notice_new_inferior (ptid
, 0);
6178 demand_private_info (ptid
)->core
= stop_reply
->core
;
6181 stop_reply_xfree (stop_reply
);
6185 /* The non-stop mode version of target_wait. */
6188 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6190 struct remote_state
*rs
= get_remote_state ();
6191 struct stop_reply
*stop_reply
;
6195 /* If in non-stop mode, get out of getpkt even if a
6196 notification is received. */
6198 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6199 0 /* forever */, &is_notif
);
6202 if (ret
!= -1 && !is_notif
)
6205 case 'E': /* Error of some sort. */
6206 /* We're out of sync with the target now. Did it continue
6207 or not? We can't tell which thread it was in non-stop,
6208 so just ignore this. */
6209 warning (_("Remote failure reply: %s"), rs
->buf
);
6211 case 'O': /* Console output. */
6212 remote_console_output (rs
->buf
+ 1);
6215 warning (_("Invalid remote reply: %s"), rs
->buf
);
6219 /* Acknowledge a pending stop reply that may have arrived in the
6221 if (rs
->notif_state
->pending_event
[notif_client_stop
.id
] != NULL
)
6222 remote_notif_get_pending_events (¬if_client_stop
);
6224 /* If indeed we noticed a stop reply, we're done. */
6225 stop_reply
= queued_stop_reply (ptid
);
6226 if (stop_reply
!= NULL
)
6227 return process_stop_reply (stop_reply
, status
);
6229 /* Still no event. If we're just polling for an event, then
6230 return to the event loop. */
6231 if (options
& TARGET_WNOHANG
)
6233 status
->kind
= TARGET_WAITKIND_IGNORE
;
6234 return minus_one_ptid
;
6237 /* Otherwise do a blocking wait. */
6238 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6239 1 /* forever */, &is_notif
);
6243 /* Wait until the remote machine stops, then return, storing status in
6244 STATUS just as `wait' would. */
6247 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6249 struct remote_state
*rs
= get_remote_state ();
6250 ptid_t event_ptid
= null_ptid
;
6252 struct stop_reply
*stop_reply
;
6256 status
->kind
= TARGET_WAITKIND_IGNORE
;
6257 status
->value
.integer
= 0;
6259 stop_reply
= queued_stop_reply (ptid
);
6260 if (stop_reply
!= NULL
)
6261 return process_stop_reply (stop_reply
, status
);
6263 if (rs
->cached_wait_status
)
6264 /* Use the cached wait status, but only once. */
6265 rs
->cached_wait_status
= 0;
6271 if (!target_is_async_p ())
6273 ofunc
= signal (SIGINT
, sync_remote_interrupt
);
6274 /* If the user hit C-c before this packet, or between packets,
6275 pretend that it was hit right here. */
6276 if (check_quit_flag ())
6279 sync_remote_interrupt (SIGINT
);
6283 /* FIXME: cagney/1999-09-27: If we're in async mode we should
6284 _never_ wait for ever -> test on target_is_async_p().
6285 However, before we do that we need to ensure that the caller
6286 knows how to take the target into/out of async mode. */
6287 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
6288 wait_forever_enabled_p
, &is_notif
);
6290 if (!target_is_async_p ())
6291 signal (SIGINT
, ofunc
);
6293 /* GDB gets a notification. Return to core as this event is
6295 if (ret
!= -1 && is_notif
)
6296 return minus_one_ptid
;
6301 rs
->stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
6303 /* We got something. */
6304 rs
->waiting_for_stop_reply
= 0;
6306 /* Assume that the target has acknowledged Ctrl-C unless we receive
6307 an 'F' or 'O' packet. */
6308 if (buf
[0] != 'F' && buf
[0] != 'O')
6309 rs
->ctrlc_pending_p
= 0;
6313 case 'E': /* Error of some sort. */
6314 /* We're out of sync with the target now. Did it continue or
6315 not? Not is more likely, so report a stop. */
6316 warning (_("Remote failure reply: %s"), buf
);
6317 status
->kind
= TARGET_WAITKIND_STOPPED
;
6318 status
->value
.sig
= GDB_SIGNAL_0
;
6320 case 'F': /* File-I/O request. */
6321 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
6322 rs
->ctrlc_pending_p
= 0;
6324 case 'T': case 'S': case 'X': case 'W':
6326 struct stop_reply
*stop_reply
6327 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
6330 event_ptid
= process_stop_reply (stop_reply
, status
);
6333 case 'O': /* Console output. */
6334 remote_console_output (buf
+ 1);
6336 /* The target didn't really stop; keep waiting. */
6337 rs
->waiting_for_stop_reply
= 1;
6341 if (rs
->last_sent_signal
!= GDB_SIGNAL_0
)
6343 /* Zero length reply means that we tried 'S' or 'C' and the
6344 remote system doesn't support it. */
6345 target_terminal_ours_for_output ();
6347 ("Can't send signals to this remote system. %s not sent.\n",
6348 gdb_signal_to_name (rs
->last_sent_signal
));
6349 rs
->last_sent_signal
= GDB_SIGNAL_0
;
6350 target_terminal_inferior ();
6352 strcpy ((char *) buf
, rs
->last_sent_step
? "s" : "c");
6353 putpkt ((char *) buf
);
6355 /* We just told the target to resume, so a stop reply is in
6357 rs
->waiting_for_stop_reply
= 1;
6360 /* else fallthrough */
6362 warning (_("Invalid remote reply: %s"), buf
);
6364 rs
->waiting_for_stop_reply
= 1;
6368 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
6370 /* Nothing interesting happened. If we're doing a non-blocking
6371 poll, we're done. Otherwise, go back to waiting. */
6372 if (options
& TARGET_WNOHANG
)
6373 return minus_one_ptid
;
6377 else if (status
->kind
!= TARGET_WAITKIND_EXITED
6378 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
6380 if (!ptid_equal (event_ptid
, null_ptid
))
6381 record_currthread (rs
, event_ptid
);
6383 event_ptid
= inferior_ptid
;
6386 /* A process exit. Invalidate our notion of current thread. */
6387 record_currthread (rs
, minus_one_ptid
);
6392 /* Wait until the remote machine stops, then return, storing status in
6393 STATUS just as `wait' would. */
6396 remote_wait (struct target_ops
*ops
,
6397 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
6402 event_ptid
= remote_wait_ns (ptid
, status
, options
);
6404 event_ptid
= remote_wait_as (ptid
, status
, options
);
6406 if (target_is_async_p ())
6408 /* If there are are events left in the queue tell the event loop
6410 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
6411 mark_async_event_handler (remote_async_inferior_event_token
);
6417 /* Fetch a single register using a 'p' packet. */
6420 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6422 struct remote_state
*rs
= get_remote_state ();
6424 char regp
[MAX_REGISTER_SIZE
];
6427 if (packet_support (PACKET_p
) == PACKET_DISABLE
)
6430 if (reg
->pnum
== -1)
6435 p
+= hexnumstr (p
, reg
->pnum
);
6438 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6442 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6446 case PACKET_UNKNOWN
:
6449 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6450 gdbarch_register_name (get_regcache_arch (regcache
),
6455 /* If this register is unfetchable, tell the regcache. */
6458 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6462 /* Otherwise, parse and supply the value. */
6468 error (_("fetch_register_using_p: early buf termination"));
6470 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6473 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6477 /* Fetch the registers included in the target's 'g' packet. */
6480 send_g_packet (void)
6482 struct remote_state
*rs
= get_remote_state ();
6485 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6486 remote_send (&rs
->buf
, &rs
->buf_size
);
6488 /* We can get out of synch in various cases. If the first character
6489 in the buffer is not a hex character, assume that has happened
6490 and try to fetch another packet to read. */
6491 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6492 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6493 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6494 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6497 fprintf_unfiltered (gdb_stdlog
,
6498 "Bad register packet; fetching a new packet\n");
6499 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6502 buf_len
= strlen (rs
->buf
);
6504 /* Sanity check the received packet. */
6505 if (buf_len
% 2 != 0)
6506 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6512 process_g_packet (struct regcache
*regcache
)
6514 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6515 struct remote_state
*rs
= get_remote_state ();
6516 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6521 buf_len
= strlen (rs
->buf
);
6523 /* Further sanity checks, with knowledge of the architecture. */
6524 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6525 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6527 /* Save the size of the packet sent to us by the target. It is used
6528 as a heuristic when determining the max size of packets that the
6529 target can safely receive. */
6530 if (rsa
->actual_register_packet_size
== 0)
6531 rsa
->actual_register_packet_size
= buf_len
;
6533 /* If this is smaller than we guessed the 'g' packet would be,
6534 update our records. A 'g' reply that doesn't include a register's
6535 value implies either that the register is not available, or that
6536 the 'p' packet must be used. */
6537 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6539 rsa
->sizeof_g_packet
= buf_len
/ 2;
6541 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6543 if (rsa
->regs
[i
].pnum
== -1)
6546 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6547 rsa
->regs
[i
].in_g_packet
= 0;
6549 rsa
->regs
[i
].in_g_packet
= 1;
6553 regs
= alloca (rsa
->sizeof_g_packet
);
6555 /* Unimplemented registers read as all bits zero. */
6556 memset (regs
, 0, rsa
->sizeof_g_packet
);
6558 /* Reply describes registers byte by byte, each byte encoded as two
6559 hex characters. Suck them all up, then supply them to the
6560 register cacheing/storage mechanism. */
6563 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6565 if (p
[0] == 0 || p
[1] == 0)
6566 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6567 internal_error (__FILE__
, __LINE__
,
6568 _("unexpected end of 'g' packet reply"));
6570 if (p
[0] == 'x' && p
[1] == 'x')
6571 regs
[i
] = 0; /* 'x' */
6573 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6577 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6579 struct packet_reg
*r
= &rsa
->regs
[i
];
6583 if (r
->offset
* 2 >= strlen (rs
->buf
))
6584 /* This shouldn't happen - we adjusted in_g_packet above. */
6585 internal_error (__FILE__
, __LINE__
,
6586 _("unexpected end of 'g' packet reply"));
6587 else if (rs
->buf
[r
->offset
* 2] == 'x')
6589 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6590 /* The register isn't available, mark it as such (at
6591 the same time setting the value to zero). */
6592 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6595 regcache_raw_supply (regcache
, r
->regnum
,
6602 fetch_registers_using_g (struct regcache
*regcache
)
6605 process_g_packet (regcache
);
6608 /* Make the remote selected traceframe match GDB's selected
6612 set_remote_traceframe (void)
6615 struct remote_state
*rs
= get_remote_state ();
6617 if (rs
->remote_traceframe_number
== get_traceframe_number ())
6620 /* Avoid recursion, remote_trace_find calls us again. */
6621 rs
->remote_traceframe_number
= get_traceframe_number ();
6623 newnum
= target_trace_find (tfind_number
,
6624 get_traceframe_number (), 0, 0, NULL
);
6626 /* Should not happen. If it does, all bets are off. */
6627 if (newnum
!= get_traceframe_number ())
6628 warning (_("could not set remote traceframe"));
6632 remote_fetch_registers (struct target_ops
*ops
,
6633 struct regcache
*regcache
, int regnum
)
6635 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6638 set_remote_traceframe ();
6639 set_general_thread (inferior_ptid
);
6643 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6645 gdb_assert (reg
!= NULL
);
6647 /* If this register might be in the 'g' packet, try that first -
6648 we are likely to read more than one register. If this is the
6649 first 'g' packet, we might be overly optimistic about its
6650 contents, so fall back to 'p'. */
6651 if (reg
->in_g_packet
)
6653 fetch_registers_using_g (regcache
);
6654 if (reg
->in_g_packet
)
6658 if (fetch_register_using_p (regcache
, reg
))
6661 /* This register is not available. */
6662 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6667 fetch_registers_using_g (regcache
);
6669 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6670 if (!rsa
->regs
[i
].in_g_packet
)
6671 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6673 /* This register is not available. */
6674 regcache_raw_supply (regcache
, i
, NULL
);
6678 /* Prepare to store registers. Since we may send them all (using a
6679 'G' request), we have to read out the ones we don't want to change
6683 remote_prepare_to_store (struct target_ops
*self
, struct regcache
*regcache
)
6685 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6687 gdb_byte buf
[MAX_REGISTER_SIZE
];
6689 /* Make sure the entire registers array is valid. */
6690 switch (packet_support (PACKET_P
))
6692 case PACKET_DISABLE
:
6693 case PACKET_SUPPORT_UNKNOWN
:
6694 /* Make sure all the necessary registers are cached. */
6695 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6696 if (rsa
->regs
[i
].in_g_packet
)
6697 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6704 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6705 packet was not recognized. */
6708 store_register_using_P (const struct regcache
*regcache
,
6709 struct packet_reg
*reg
)
6711 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6712 struct remote_state
*rs
= get_remote_state ();
6713 /* Try storing a single register. */
6714 char *buf
= rs
->buf
;
6715 gdb_byte regp
[MAX_REGISTER_SIZE
];
6718 if (packet_support (PACKET_P
) == PACKET_DISABLE
)
6721 if (reg
->pnum
== -1)
6724 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6725 p
= buf
+ strlen (buf
);
6726 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6727 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6729 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6731 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6736 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6737 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6738 case PACKET_UNKNOWN
:
6741 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6745 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6746 contents of the register cache buffer. FIXME: ignores errors. */
6749 store_registers_using_G (const struct regcache
*regcache
)
6751 struct remote_state
*rs
= get_remote_state ();
6752 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6756 /* Extract all the registers in the regcache copying them into a
6761 regs
= alloca (rsa
->sizeof_g_packet
);
6762 memset (regs
, 0, rsa
->sizeof_g_packet
);
6763 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6765 struct packet_reg
*r
= &rsa
->regs
[i
];
6768 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6772 /* Command describes registers byte by byte,
6773 each byte encoded as two hex characters. */
6776 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6778 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6780 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6781 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6782 error (_("Could not write registers; remote failure reply '%s'"),
6786 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6787 of the register cache buffer. FIXME: ignores errors. */
6790 remote_store_registers (struct target_ops
*ops
,
6791 struct regcache
*regcache
, int regnum
)
6793 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6796 set_remote_traceframe ();
6797 set_general_thread (inferior_ptid
);
6801 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6803 gdb_assert (reg
!= NULL
);
6805 /* Always prefer to store registers using the 'P' packet if
6806 possible; we often change only a small number of registers.
6807 Sometimes we change a larger number; we'd need help from a
6808 higher layer to know to use 'G'. */
6809 if (store_register_using_P (regcache
, reg
))
6812 /* For now, don't complain if we have no way to write the
6813 register. GDB loses track of unavailable registers too
6814 easily. Some day, this may be an error. We don't have
6815 any way to read the register, either... */
6816 if (!reg
->in_g_packet
)
6819 store_registers_using_G (regcache
);
6823 store_registers_using_G (regcache
);
6825 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6826 if (!rsa
->regs
[i
].in_g_packet
)
6827 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6828 /* See above for why we do not issue an error here. */
6833 /* Return the number of hex digits in num. */
6836 hexnumlen (ULONGEST num
)
6840 for (i
= 0; num
!= 0; i
++)
6846 /* Set BUF to the minimum number of hex digits representing NUM. */
6849 hexnumstr (char *buf
, ULONGEST num
)
6851 int len
= hexnumlen (num
);
6853 return hexnumnstr (buf
, num
, len
);
6857 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6860 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6866 for (i
= width
- 1; i
>= 0; i
--)
6868 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6875 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6878 remote_address_masked (CORE_ADDR addr
)
6880 unsigned int address_size
= remote_address_size
;
6882 /* If "remoteaddresssize" was not set, default to target address size. */
6884 address_size
= gdbarch_addr_bit (target_gdbarch ());
6886 if (address_size
> 0
6887 && address_size
< (sizeof (ULONGEST
) * 8))
6889 /* Only create a mask when that mask can safely be constructed
6890 in a ULONGEST variable. */
6893 mask
= (mask
<< address_size
) - 1;
6899 /* Determine whether the remote target supports binary downloading.
6900 This is accomplished by sending a no-op memory write of zero length
6901 to the target at the specified address. It does not suffice to send
6902 the whole packet, since many stubs strip the eighth bit and
6903 subsequently compute a wrong checksum, which causes real havoc with
6906 NOTE: This can still lose if the serial line is not eight-bit
6907 clean. In cases like this, the user should clear "remote
6911 check_binary_download (CORE_ADDR addr
)
6913 struct remote_state
*rs
= get_remote_state ();
6915 switch (packet_support (PACKET_X
))
6917 case PACKET_DISABLE
:
6921 case PACKET_SUPPORT_UNKNOWN
:
6927 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6929 p
+= hexnumstr (p
, (ULONGEST
) 0);
6933 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6934 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6936 if (rs
->buf
[0] == '\0')
6939 fprintf_unfiltered (gdb_stdlog
,
6940 "binary downloading NOT "
6941 "supported by target\n");
6942 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6947 fprintf_unfiltered (gdb_stdlog
,
6948 "binary downloading supported by target\n");
6949 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6956 /* Helper function to resize the payload in order to try to get a good
6957 alignment. We try to write an amount of data such that the next write will
6958 start on an address aligned on REMOTE_ALIGN_WRITES. */
6961 align_for_efficient_write (int todo
, CORE_ADDR memaddr
)
6963 return ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6966 /* Write memory data directly to the remote machine.
6967 This does not inform the data cache; the data cache uses this.
6968 HEADER is the starting part of the packet.
6969 MEMADDR is the address in the remote memory space.
6970 MYADDR is the address of the buffer in our space.
6971 LEN_UNITS is the number of addressable units to write.
6972 UNIT_SIZE is the length in bytes of an addressable unit.
6973 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6974 should send data as binary ('X'), or hex-encoded ('M').
6976 The function creates packet of the form
6977 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6979 where encoding of <DATA> is terminated by PACKET_FORMAT.
6981 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6984 Return the transferred status, error or OK (an
6985 'enum target_xfer_status' value). Save the number of addressable units
6986 transferred in *XFERED_LEN_UNITS. Only transfer a single packet.
6988 On a platform with an addressable memory size of 2 bytes (UNIT_SIZE == 2), an
6989 exchange between gdb and the stub could look like (?? in place of the
6995 -> $M1000,3:eeeeffffeeee#??
6999 <- eeeeffffeeeedddd */
7001 static enum target_xfer_status
7002 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
7003 const gdb_byte
*myaddr
, ULONGEST len_units
,
7004 int unit_size
, ULONGEST
*xfered_len_units
,
7005 char packet_format
, int use_length
)
7007 struct remote_state
*rs
= get_remote_state ();
7013 int payload_capacity_bytes
;
7014 int payload_length_bytes
;
7016 if (packet_format
!= 'X' && packet_format
!= 'M')
7017 internal_error (__FILE__
, __LINE__
,
7018 _("remote_write_bytes_aux: bad packet format"));
7021 return TARGET_XFER_EOF
;
7023 payload_capacity_bytes
= get_memory_write_packet_size ();
7025 /* The packet buffer will be large enough for the payload;
7026 get_memory_packet_size ensures this. */
7029 /* Compute the size of the actual payload by subtracting out the
7030 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
7032 payload_capacity_bytes
-= strlen ("$,:#NN");
7034 /* The comma won't be used. */
7035 payload_capacity_bytes
+= 1;
7036 payload_capacity_bytes
-= strlen (header
);
7037 payload_capacity_bytes
-= hexnumlen (memaddr
);
7039 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
7041 strcat (rs
->buf
, header
);
7042 p
= rs
->buf
+ strlen (header
);
7044 /* Compute a best guess of the number of bytes actually transfered. */
7045 if (packet_format
== 'X')
7047 /* Best guess at number of bytes that will fit. */
7048 todo_units
= min (len_units
, payload_capacity_bytes
/ unit_size
);
7050 payload_capacity_bytes
-= hexnumlen (todo_units
);
7051 todo_units
= min (todo_units
, payload_capacity_bytes
/ unit_size
);
7055 /* Number of bytes that will fit. */
7056 todo_units
= min (len_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7058 payload_capacity_bytes
-= hexnumlen (todo_units
);
7059 todo_units
= min (todo_units
, (payload_capacity_bytes
/ unit_size
) / 2);
7062 if (todo_units
<= 0)
7063 internal_error (__FILE__
, __LINE__
,
7064 _("minimum packet size too small to write data"));
7066 /* If we already need another packet, then try to align the end
7067 of this packet to a useful boundary. */
7068 if (todo_units
> 2 * REMOTE_ALIGN_WRITES
&& todo_units
< len_units
)
7069 todo_units
= align_for_efficient_write (todo_units
, memaddr
);
7071 /* Append "<memaddr>". */
7072 memaddr
= remote_address_masked (memaddr
);
7073 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7080 /* Append the length and retain its location and size. It may need to be
7081 adjusted once the packet body has been created. */
7083 plenlen
= hexnumstr (p
, (ULONGEST
) todo_units
);
7091 /* Append the packet body. */
7092 if (packet_format
== 'X')
7094 /* Binary mode. Send target system values byte by byte, in
7095 increasing byte addresses. Only escape certain critical
7097 payload_length_bytes
=
7098 remote_escape_output (myaddr
, todo_units
, unit_size
, (gdb_byte
*) p
,
7099 &units_written
, payload_capacity_bytes
);
7101 /* If not all TODO units fit, then we'll need another packet. Make
7102 a second try to keep the end of the packet aligned. Don't do
7103 this if the packet is tiny. */
7104 if (units_written
< todo_units
&& units_written
> 2 * REMOTE_ALIGN_WRITES
)
7108 new_todo_units
= align_for_efficient_write (units_written
, memaddr
);
7110 if (new_todo_units
!= units_written
)
7111 payload_length_bytes
=
7112 remote_escape_output (myaddr
, new_todo_units
, unit_size
,
7113 (gdb_byte
*) p
, &units_written
,
7114 payload_capacity_bytes
);
7117 p
+= payload_length_bytes
;
7118 if (use_length
&& units_written
< todo_units
)
7120 /* Escape chars have filled up the buffer prematurely,
7121 and we have actually sent fewer units than planned.
7122 Fix-up the length field of the packet. Use the same
7123 number of characters as before. */
7124 plen
+= hexnumnstr (plen
, (ULONGEST
) units_written
,
7126 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
7131 /* Normal mode: Send target system values byte by byte, in
7132 increasing byte addresses. Each byte is encoded as a two hex
7134 p
+= 2 * bin2hex (myaddr
, p
, todo_units
* unit_size
);
7135 units_written
= todo_units
;
7138 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
7139 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7141 if (rs
->buf
[0] == 'E')
7142 return TARGET_XFER_E_IO
;
7144 /* Return UNITS_WRITTEN, not TODO_UNITS, in case escape chars caused us to
7145 send fewer units than we'd planned. */
7146 *xfered_len_units
= (ULONGEST
) units_written
;
7147 return TARGET_XFER_OK
;
7150 /* Write memory data directly to the remote machine.
7151 This does not inform the data cache; the data cache uses this.
7152 MEMADDR is the address in the remote memory space.
7153 MYADDR is the address of the buffer in our space.
7154 LEN is the number of bytes.
7156 Return the transferred status, error or OK (an
7157 'enum target_xfer_status' value). Save the number of bytes
7158 transferred in *XFERED_LEN. Only transfer a single packet. */
7160 static enum target_xfer_status
7161 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ULONGEST len
,
7162 int unit_size
, ULONGEST
*xfered_len
)
7164 char *packet_format
= 0;
7166 /* Check whether the target supports binary download. */
7167 check_binary_download (memaddr
);
7169 switch (packet_support (PACKET_X
))
7172 packet_format
= "X";
7174 case PACKET_DISABLE
:
7175 packet_format
= "M";
7177 case PACKET_SUPPORT_UNKNOWN
:
7178 internal_error (__FILE__
, __LINE__
,
7179 _("remote_write_bytes: bad internal state"));
7181 internal_error (__FILE__
, __LINE__
, _("bad switch"));
7184 return remote_write_bytes_aux (packet_format
,
7185 memaddr
, myaddr
, len
, unit_size
, xfered_len
,
7186 packet_format
[0], 1);
7189 /* Read memory data directly from the remote machine.
7190 This does not use the data cache; the data cache uses this.
7191 MEMADDR is the address in the remote memory space.
7192 MYADDR is the address of the buffer in our space.
7193 LEN_UNITS is the number of addressable memory units to read..
7194 UNIT_SIZE is the length in bytes of an addressable unit.
7196 Return the transferred status, error or OK (an
7197 'enum target_xfer_status' value). Save the number of bytes
7198 transferred in *XFERED_LEN_UNITS.
7200 See the comment of remote_write_bytes_aux for an example of
7201 memory read/write exchange between gdb and the stub. */
7203 static enum target_xfer_status
7204 remote_read_bytes_1 (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ULONGEST len_units
,
7205 int unit_size
, ULONGEST
*xfered_len_units
)
7207 struct remote_state
*rs
= get_remote_state ();
7208 int buf_size_bytes
; /* Max size of packet output buffer. */
7213 buf_size_bytes
= get_memory_read_packet_size ();
7214 /* The packet buffer will be large enough for the payload;
7215 get_memory_packet_size ensures this. */
7217 /* Number of units that will fit. */
7218 todo_units
= min (len_units
, (buf_size_bytes
/ unit_size
) / 2);
7220 /* Construct "m"<memaddr>","<len>". */
7221 memaddr
= remote_address_masked (memaddr
);
7224 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
7226 p
+= hexnumstr (p
, (ULONGEST
) todo_units
);
7229 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7230 if (rs
->buf
[0] == 'E'
7231 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
7232 && rs
->buf
[3] == '\0')
7233 return TARGET_XFER_E_IO
;
7234 /* Reply describes memory byte by byte, each byte encoded as two hex
7237 decoded_bytes
= hex2bin (p
, myaddr
, todo_units
* unit_size
);
7238 /* Return what we have. Let higher layers handle partial reads. */
7239 *xfered_len_units
= (ULONGEST
) (decoded_bytes
/ unit_size
);
7240 return TARGET_XFER_OK
;
7243 /* Using the set of read-only target sections of remote, read live
7246 For interface/parameters/return description see target.h,
7249 static enum target_xfer_status
7250 remote_xfer_live_readonly_partial (struct target_ops
*ops
, gdb_byte
*readbuf
,
7251 ULONGEST memaddr
, ULONGEST len
,
7252 int unit_size
, ULONGEST
*xfered_len
)
7254 struct target_section
*secp
;
7255 struct target_section_table
*table
;
7257 secp
= target_section_by_addr (ops
, memaddr
);
7259 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
7260 secp
->the_bfd_section
)
7263 struct target_section
*p
;
7264 ULONGEST memend
= memaddr
+ len
;
7266 table
= target_get_section_table (ops
);
7268 for (p
= table
->sections
; p
< table
->sections_end
; p
++)
7270 if (memaddr
>= p
->addr
)
7272 if (memend
<= p
->endaddr
)
7274 /* Entire transfer is within this section. */
7275 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7278 else if (memaddr
>= p
->endaddr
)
7280 /* This section ends before the transfer starts. */
7285 /* This section overlaps the transfer. Just do half. */
7286 len
= p
->endaddr
- memaddr
;
7287 return remote_read_bytes_1 (memaddr
, readbuf
, len
, unit_size
,
7294 return TARGET_XFER_EOF
;
7297 /* Similar to remote_read_bytes_1, but it reads from the remote stub
7298 first if the requested memory is unavailable in traceframe.
7299 Otherwise, fall back to remote_read_bytes_1. */
7301 static enum target_xfer_status
7302 remote_read_bytes (struct target_ops
*ops
, CORE_ADDR memaddr
,
7303 gdb_byte
*myaddr
, ULONGEST len
, int unit_size
,
7304 ULONGEST
*xfered_len
)
7307 return TARGET_XFER_EOF
;
7309 if (get_traceframe_number () != -1)
7311 VEC(mem_range_s
) *available
;
7313 /* If we fail to get the set of available memory, then the
7314 target does not support querying traceframe info, and so we
7315 attempt reading from the traceframe anyway (assuming the
7316 target implements the old QTro packet then). */
7317 if (traceframe_available_memory (&available
, memaddr
, len
))
7319 struct cleanup
*old_chain
;
7321 old_chain
= make_cleanup (VEC_cleanup(mem_range_s
), &available
);
7323 if (VEC_empty (mem_range_s
, available
)
7324 || VEC_index (mem_range_s
, available
, 0)->start
!= memaddr
)
7326 enum target_xfer_status res
;
7328 /* Don't read into the traceframe's available
7330 if (!VEC_empty (mem_range_s
, available
))
7332 LONGEST oldlen
= len
;
7334 len
= VEC_index (mem_range_s
, available
, 0)->start
- memaddr
;
7335 gdb_assert (len
<= oldlen
);
7338 do_cleanups (old_chain
);
7340 /* This goes through the topmost target again. */
7341 res
= remote_xfer_live_readonly_partial (ops
, myaddr
, memaddr
,
7342 len
, unit_size
, xfered_len
);
7343 if (res
== TARGET_XFER_OK
)
7344 return TARGET_XFER_OK
;
7347 /* No use trying further, we know some memory starting
7348 at MEMADDR isn't available. */
7350 return TARGET_XFER_UNAVAILABLE
;
7354 /* Don't try to read more than how much is available, in
7355 case the target implements the deprecated QTro packet to
7356 cater for older GDBs (the target's knowledge of read-only
7357 sections may be outdated by now). */
7358 len
= VEC_index (mem_range_s
, available
, 0)->length
;
7360 do_cleanups (old_chain
);
7364 return remote_read_bytes_1 (memaddr
, myaddr
, len
, unit_size
, xfered_len
);
7369 /* Sends a packet with content determined by the printf format string
7370 FORMAT and the remaining arguments, then gets the reply. Returns
7371 whether the packet was a success, a failure, or unknown. */
7373 static enum packet_result
remote_send_printf (const char *format
, ...)
7374 ATTRIBUTE_PRINTF (1, 2);
7376 static enum packet_result
7377 remote_send_printf (const char *format
, ...)
7379 struct remote_state
*rs
= get_remote_state ();
7380 int max_size
= get_remote_packet_size ();
7383 va_start (ap
, format
);
7386 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
7387 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
7389 if (putpkt (rs
->buf
) < 0)
7390 error (_("Communication problem with target."));
7393 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7395 return packet_check_result (rs
->buf
);
7399 restore_remote_timeout (void *p
)
7401 int value
= *(int *)p
;
7403 remote_timeout
= value
;
7406 /* Flash writing can take quite some time. We'll set
7407 effectively infinite timeout for flash operations.
7408 In future, we'll need to decide on a better approach. */
7409 static const int remote_flash_timeout
= 1000;
7412 remote_flash_erase (struct target_ops
*ops
,
7413 ULONGEST address
, LONGEST length
)
7415 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
7416 int saved_remote_timeout
= remote_timeout
;
7417 enum packet_result ret
;
7418 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7419 &saved_remote_timeout
);
7421 remote_timeout
= remote_flash_timeout
;
7423 ret
= remote_send_printf ("vFlashErase:%s,%s",
7424 phex (address
, addr_size
),
7428 case PACKET_UNKNOWN
:
7429 error (_("Remote target does not support flash erase"));
7431 error (_("Error erasing flash with vFlashErase packet"));
7436 do_cleanups (back_to
);
7439 static enum target_xfer_status
7440 remote_flash_write (struct target_ops
*ops
, ULONGEST address
,
7441 ULONGEST length
, ULONGEST
*xfered_len
,
7442 const gdb_byte
*data
)
7444 int saved_remote_timeout
= remote_timeout
;
7445 enum target_xfer_status ret
;
7446 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7447 &saved_remote_timeout
);
7449 remote_timeout
= remote_flash_timeout
;
7450 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 1,
7452 do_cleanups (back_to
);
7458 remote_flash_done (struct target_ops
*ops
)
7460 int saved_remote_timeout
= remote_timeout
;
7462 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7463 &saved_remote_timeout
);
7465 remote_timeout
= remote_flash_timeout
;
7466 ret
= remote_send_printf ("vFlashDone");
7467 do_cleanups (back_to
);
7471 case PACKET_UNKNOWN
:
7472 error (_("Remote target does not support vFlashDone"));
7474 error (_("Error finishing flash operation"));
7481 remote_files_info (struct target_ops
*ignore
)
7483 puts_filtered ("Debugging a target over a serial line.\n");
7486 /* Stuff for dealing with the packets which are part of this protocol.
7487 See comment at top of file for details. */
7489 /* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
7490 error to higher layers. Called when a serial error is detected.
7491 The exception message is STRING, followed by a colon and a blank,
7492 the system error message for errno at function entry and final dot
7493 for output compatibility with throw_perror_with_name. */
7496 unpush_and_perror (const char *string
)
7498 int saved_errno
= errno
;
7500 remote_unpush_target ();
7501 throw_error (TARGET_CLOSE_ERROR
, "%s: %s.", string
,
7502 safe_strerror (saved_errno
));
7505 /* Read a single character from the remote end. */
7508 readchar (int timeout
)
7511 struct remote_state
*rs
= get_remote_state ();
7513 ch
= serial_readchar (rs
->remote_desc
, timeout
);
7518 switch ((enum serial_rc
) ch
)
7521 remote_unpush_target ();
7522 throw_error (TARGET_CLOSE_ERROR
, _("Remote connection closed"));
7525 unpush_and_perror (_("Remote communication error. "
7526 "Target disconnected."));
7528 case SERIAL_TIMEOUT
:
7534 /* Wrapper for serial_write that closes the target and throws if
7538 remote_serial_write (const char *str
, int len
)
7540 struct remote_state
*rs
= get_remote_state ();
7542 if (serial_write (rs
->remote_desc
, str
, len
))
7544 unpush_and_perror (_("Remote communication error. "
7545 "Target disconnected."));
7549 /* Send the command in *BUF to the remote machine, and read the reply
7550 into *BUF. Report an error if we get an error reply. Resize
7551 *BUF using xrealloc if necessary to hold the result, and update
7555 remote_send (char **buf
,
7559 getpkt (buf
, sizeof_buf
, 0);
7561 if ((*buf
)[0] == 'E')
7562 error (_("Remote failure reply: %s"), *buf
);
7565 /* Return a pointer to an xmalloc'ed string representing an escaped
7566 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7567 etc. The caller is responsible for releasing the returned
7571 escape_buffer (const char *buf
, int n
)
7573 struct cleanup
*old_chain
;
7574 struct ui_file
*stb
;
7577 stb
= mem_fileopen ();
7578 old_chain
= make_cleanup_ui_file_delete (stb
);
7580 fputstrn_unfiltered (buf
, n
, '\\', stb
);
7581 str
= ui_file_xstrdup (stb
, NULL
);
7582 do_cleanups (old_chain
);
7586 /* Display a null-terminated packet on stdout, for debugging, using C
7590 print_packet (const char *buf
)
7592 puts_filtered ("\"");
7593 fputstr_filtered (buf
, '"', gdb_stdout
);
7594 puts_filtered ("\"");
7598 putpkt (const char *buf
)
7600 return putpkt_binary (buf
, strlen (buf
));
7603 /* Send a packet to the remote machine, with error checking. The data
7604 of the packet is in BUF. The string in BUF can be at most
7605 get_remote_packet_size () - 5 to account for the $, # and checksum,
7606 and for a possible /0 if we are debugging (remote_debug) and want
7607 to print the sent packet as a string. */
7610 putpkt_binary (const char *buf
, int cnt
)
7612 struct remote_state
*rs
= get_remote_state ();
7614 unsigned char csum
= 0;
7615 char *buf2
= alloca (cnt
+ 6);
7622 /* Catch cases like trying to read memory or listing threads while
7623 we're waiting for a stop reply. The remote server wouldn't be
7624 ready to handle this request, so we'd hang and timeout. We don't
7625 have to worry about this in synchronous mode, because in that
7626 case it's not possible to issue a command while the target is
7627 running. This is not a problem in non-stop mode, because in that
7628 case, the stub is always ready to process serial input. */
7629 if (!non_stop
&& target_is_async_p () && rs
->waiting_for_stop_reply
)
7631 error (_("Cannot execute this command while the target is running.\n"
7632 "Use the \"interrupt\" command to stop the target\n"
7633 "and then try again."));
7636 /* We're sending out a new packet. Make sure we don't look at a
7637 stale cached response. */
7638 rs
->cached_wait_status
= 0;
7640 /* Copy the packet into buffer BUF2, encapsulating it
7641 and giving it a checksum. */
7646 for (i
= 0; i
< cnt
; i
++)
7652 *p
++ = tohex ((csum
>> 4) & 0xf);
7653 *p
++ = tohex (csum
& 0xf);
7655 /* Send it over and over until we get a positive ack. */
7659 int started_error_output
= 0;
7663 struct cleanup
*old_chain
;
7667 str
= escape_buffer (buf2
, p
- buf2
);
7668 old_chain
= make_cleanup (xfree
, str
);
7669 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7670 gdb_flush (gdb_stdlog
);
7671 do_cleanups (old_chain
);
7673 remote_serial_write (buf2
, p
- buf2
);
7675 /* If this is a no acks version of the remote protocol, send the
7676 packet and move on. */
7680 /* Read until either a timeout occurs (-2) or '+' is read.
7681 Handle any notification that arrives in the mean time. */
7684 ch
= readchar (remote_timeout
);
7692 case SERIAL_TIMEOUT
:
7695 if (started_error_output
)
7697 putchar_unfiltered ('\n');
7698 started_error_output
= 0;
7707 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7711 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7713 case SERIAL_TIMEOUT
:
7717 break; /* Retransmit buffer. */
7721 fprintf_unfiltered (gdb_stdlog
,
7722 "Packet instead of Ack, ignoring it\n");
7723 /* It's probably an old response sent because an ACK
7724 was lost. Gobble up the packet and ack it so it
7725 doesn't get retransmitted when we resend this
7728 remote_serial_write ("+", 1);
7729 continue; /* Now, go look for +. */
7736 /* If we got a notification, handle it, and go back to looking
7738 /* We've found the start of a notification. Now
7739 collect the data. */
7740 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7745 struct cleanup
*old_chain
;
7748 str
= escape_buffer (rs
->buf
, val
);
7749 old_chain
= make_cleanup (xfree
, str
);
7750 fprintf_unfiltered (gdb_stdlog
,
7751 " Notification received: %s\n",
7753 do_cleanups (old_chain
);
7755 handle_notification (rs
->notif_state
, rs
->buf
);
7756 /* We're in sync now, rewait for the ack. */
7763 if (!started_error_output
)
7765 started_error_output
= 1;
7766 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7768 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7769 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7778 if (!started_error_output
)
7780 started_error_output
= 1;
7781 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7783 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7787 break; /* Here to retransmit. */
7791 /* This is wrong. If doing a long backtrace, the user should be
7792 able to get out next time we call QUIT, without anything as
7793 violent as interrupt_query. If we want to provide a way out of
7794 here without getting to the next QUIT, it should be based on
7795 hitting ^C twice as in remote_wait. */
7806 /* Come here after finding the start of a frame when we expected an
7807 ack. Do our best to discard the rest of this packet. */
7816 c
= readchar (remote_timeout
);
7819 case SERIAL_TIMEOUT
:
7820 /* Nothing we can do. */
7823 /* Discard the two bytes of checksum and stop. */
7824 c
= readchar (remote_timeout
);
7826 c
= readchar (remote_timeout
);
7829 case '*': /* Run length encoding. */
7830 /* Discard the repeat count. */
7831 c
= readchar (remote_timeout
);
7836 /* A regular character. */
7842 /* Come here after finding the start of the frame. Collect the rest
7843 into *BUF, verifying the checksum, length, and handling run-length
7844 compression. NUL terminate the buffer. If there is not enough room,
7845 expand *BUF using xrealloc.
7847 Returns -1 on error, number of characters in buffer (ignoring the
7848 trailing NULL) on success. (could be extended to return one of the
7849 SERIAL status indications). */
7852 read_frame (char **buf_p
,
7859 struct remote_state
*rs
= get_remote_state ();
7866 c
= readchar (remote_timeout
);
7869 case SERIAL_TIMEOUT
:
7871 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7875 fputs_filtered ("Saw new packet start in middle of old one\n",
7877 return -1; /* Start a new packet, count retries. */
7880 unsigned char pktcsum
;
7886 check_0
= readchar (remote_timeout
);
7888 check_1
= readchar (remote_timeout
);
7890 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7893 fputs_filtered ("Timeout in checksum, retrying\n",
7897 else if (check_0
< 0 || check_1
< 0)
7900 fputs_filtered ("Communication error in checksum\n",
7905 /* Don't recompute the checksum; with no ack packets we
7906 don't have any way to indicate a packet retransmission
7911 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7912 if (csum
== pktcsum
)
7917 struct cleanup
*old_chain
;
7920 str
= escape_buffer (buf
, bc
);
7921 old_chain
= make_cleanup (xfree
, str
);
7922 fprintf_unfiltered (gdb_stdlog
,
7923 "Bad checksum, sentsum=0x%x, "
7924 "csum=0x%x, buf=%s\n",
7925 pktcsum
, csum
, str
);
7926 do_cleanups (old_chain
);
7928 /* Number of characters in buffer ignoring trailing
7932 case '*': /* Run length encoding. */
7937 c
= readchar (remote_timeout
);
7939 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7941 /* The character before ``*'' is repeated. */
7943 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7945 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7947 /* Make some more room in the buffer. */
7948 *sizeof_buf
+= repeat
;
7949 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7953 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7959 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7963 if (bc
>= *sizeof_buf
- 1)
7965 /* Make some more room in the buffer. */
7967 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7978 /* Read a packet from the remote machine, with error checking, and
7979 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7980 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7981 rather than timing out; this is used (in synchronous mode) to wait
7982 for a target that is is executing user code to stop. */
7983 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7984 don't have to change all the calls to getpkt to deal with the
7985 return value, because at the moment I don't know what the right
7986 thing to do it for those. */
7994 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7998 /* Read a packet from the remote machine, with error checking, and
7999 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
8000 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
8001 rather than timing out; this is used (in synchronous mode) to wait
8002 for a target that is is executing user code to stop. If FOREVER ==
8003 0, this function is allowed to time out gracefully and return an
8004 indication of this to the caller. Otherwise return the number of
8005 bytes read. If EXPECTING_NOTIF, consider receiving a notification
8006 enough reason to return to the caller. *IS_NOTIF is an output
8007 boolean that indicates whether *BUF holds a notification or not
8008 (a regular packet). */
8011 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
8012 int expecting_notif
, int *is_notif
)
8014 struct remote_state
*rs
= get_remote_state ();
8020 /* We're reading a new response. Make sure we don't look at a
8021 previously cached response. */
8022 rs
->cached_wait_status
= 0;
8024 strcpy (*buf
, "timeout");
8027 timeout
= watchdog
> 0 ? watchdog
: -1;
8028 else if (expecting_notif
)
8029 timeout
= 0; /* There should already be a char in the buffer. If
8032 timeout
= remote_timeout
;
8036 /* Process any number of notifications, and then return when
8040 /* If we get a timeout or bad checksum, retry up to MAX_TRIES
8042 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
8044 /* This can loop forever if the remote side sends us
8045 characters continuously, but if it pauses, we'll get
8046 SERIAL_TIMEOUT from readchar because of timeout. Then
8047 we'll count that as a retry.
8049 Note that even when forever is set, we will only wait
8050 forever prior to the start of a packet. After that, we
8051 expect characters to arrive at a brisk pace. They should
8052 show up within remote_timeout intervals. */
8054 c
= readchar (timeout
);
8055 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
8057 if (c
== SERIAL_TIMEOUT
)
8059 if (expecting_notif
)
8060 return -1; /* Don't complain, it's normal to not get
8061 anything in this case. */
8063 if (forever
) /* Watchdog went off? Kill the target. */
8066 remote_unpush_target ();
8067 throw_error (TARGET_CLOSE_ERROR
,
8068 _("Watchdog timeout has expired. "
8069 "Target detached."));
8072 fputs_filtered ("Timed out.\n", gdb_stdlog
);
8076 /* We've found the start of a packet or notification.
8077 Now collect the data. */
8078 val
= read_frame (buf
, sizeof_buf
);
8083 remote_serial_write ("-", 1);
8086 if (tries
> MAX_TRIES
)
8088 /* We have tried hard enough, and just can't receive the
8089 packet/notification. Give up. */
8090 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
8092 /* Skip the ack char if we're in no-ack mode. */
8093 if (!rs
->noack_mode
)
8094 remote_serial_write ("+", 1);
8098 /* If we got an ordinary packet, return that to our caller. */
8103 struct cleanup
*old_chain
;
8106 str
= escape_buffer (*buf
, val
);
8107 old_chain
= make_cleanup (xfree
, str
);
8108 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
8109 do_cleanups (old_chain
);
8112 /* Skip the ack char if we're in no-ack mode. */
8113 if (!rs
->noack_mode
)
8114 remote_serial_write ("+", 1);
8115 if (is_notif
!= NULL
)
8120 /* If we got a notification, handle it, and go back to looking
8124 gdb_assert (c
== '%');
8128 struct cleanup
*old_chain
;
8131 str
= escape_buffer (*buf
, val
);
8132 old_chain
= make_cleanup (xfree
, str
);
8133 fprintf_unfiltered (gdb_stdlog
,
8134 " Notification received: %s\n",
8136 do_cleanups (old_chain
);
8138 if (is_notif
!= NULL
)
8141 handle_notification (rs
->notif_state
, *buf
);
8143 /* Notifications require no acknowledgement. */
8145 if (expecting_notif
)
8152 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
8154 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
8158 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
8161 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
8165 /* Check whether EVENT is a fork event for the process specified
8166 by the pid passed in DATA, and if it is, kill the fork child. */
8169 kill_child_of_pending_fork (QUEUE (stop_reply_p
) *q
,
8170 QUEUE_ITER (stop_reply_p
) *iter
,
8174 struct queue_iter_param
*param
= data
;
8175 int parent_pid
= *(int *) param
->input
;
8177 if (is_pending_fork_parent (&event
->ws
, parent_pid
, event
->ptid
))
8179 struct remote_state
*rs
= get_remote_state ();
8180 int child_pid
= ptid_get_pid (event
->ws
.value
.related_pid
);
8183 res
= remote_vkill (child_pid
, rs
);
8185 error (_("Can't kill fork child process %d"), child_pid
);
8191 /* Kill any new fork children of process PID that haven't been
8192 processed by follow_fork. */
8195 kill_new_fork_children (int pid
, struct remote_state
*rs
)
8197 struct thread_info
*thread
;
8198 struct notif_client
*notif
= ¬if_client_stop
;
8199 struct queue_iter_param param
;
8201 /* Kill the fork child threads of any threads in process PID
8202 that are stopped at a fork event. */
8203 ALL_NON_EXITED_THREADS (thread
)
8205 struct target_waitstatus
*ws
= &thread
->pending_follow
;
8207 if (is_pending_fork_parent (ws
, pid
, thread
->ptid
))
8209 struct remote_state
*rs
= get_remote_state ();
8210 int child_pid
= ptid_get_pid (ws
->value
.related_pid
);
8213 res
= remote_vkill (child_pid
, rs
);
8215 error (_("Can't kill fork child process %d"), child_pid
);
8219 /* Check for any pending fork events (not reported or processed yet)
8220 in process PID and kill those fork child threads as well. */
8221 remote_notif_get_pending_events (notif
);
8223 param
.output
= NULL
;
8224 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
8225 kill_child_of_pending_fork
, ¶m
);
8230 remote_kill (struct target_ops
*ops
)
8233 /* Catch errors so the user can quit from gdb even when we
8234 aren't on speaking terms with the remote system. */
8239 CATCH (ex
, RETURN_MASK_ERROR
)
8241 if (ex
.error
== TARGET_CLOSE_ERROR
)
8243 /* If we got an (EOF) error that caused the target
8244 to go away, then we're done, that's what we wanted.
8245 "k" is susceptible to cause a premature EOF, given
8246 that the remote server isn't actually required to
8247 reply to "k", and it can happen that it doesn't
8248 even get to reply ACK to the "k". */
8252 /* Otherwise, something went wrong. We didn't actually kill
8253 the target. Just propagate the exception, and let the
8254 user or higher layers decide what to do. */
8255 throw_exception (ex
);
8259 /* We've killed the remote end, we get to mourn it. Since this is
8260 target remote, single-process, mourning the inferior also
8261 unpushes remote_ops. */
8262 target_mourn_inferior ();
8266 remote_vkill (int pid
, struct remote_state
*rs
)
8268 if (packet_support (PACKET_vKill
) == PACKET_DISABLE
)
8271 /* Tell the remote target to detach. */
8272 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
8274 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8276 switch (packet_ok (rs
->buf
,
8277 &remote_protocol_packets
[PACKET_vKill
]))
8283 case PACKET_UNKNOWN
:
8286 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
8291 extended_remote_kill (struct target_ops
*ops
)
8294 int pid
= ptid_get_pid (inferior_ptid
);
8295 struct remote_state
*rs
= get_remote_state ();
8297 /* If we're stopped while forking and we haven't followed yet, kill the
8298 child task. We need to do this before killing the parent task
8299 because if this is a vfork then the parent will be sleeping. */
8300 kill_new_fork_children (pid
, rs
);
8302 res
= remote_vkill (pid
, rs
);
8303 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
8305 /* Don't try 'k' on a multi-process aware stub -- it has no way
8306 to specify the pid. */
8310 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8311 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
8314 /* Don't wait for it to die. I'm not really sure it matters whether
8315 we do or not. For the existing stubs, kill is a noop. */
8321 error (_("Can't kill process"));
8323 target_mourn_inferior ();
8327 remote_mourn (struct target_ops
*target
)
8329 unpush_target (target
);
8331 /* remote_close takes care of doing most of the clean up. */
8332 generic_mourn_inferior ();
8336 extended_remote_mourn (struct target_ops
*target
)
8338 struct remote_state
*rs
= get_remote_state ();
8340 /* In case we got here due to an error, but we're going to stay
8342 rs
->waiting_for_stop_reply
= 0;
8344 /* If the current general thread belonged to the process we just
8345 detached from or has exited, the remote side current general
8346 thread becomes undefined. Considering a case like this:
8348 - We just got here due to a detach.
8349 - The process that we're detaching from happens to immediately
8350 report a global breakpoint being hit in non-stop mode, in the
8351 same thread we had selected before.
8352 - GDB attaches to this process again.
8353 - This event happens to be the next event we handle.
8355 GDB would consider that the current general thread didn't need to
8356 be set on the stub side (with Hg), since for all it knew,
8357 GENERAL_THREAD hadn't changed.
8359 Notice that although in all-stop mode, the remote server always
8360 sets the current thread to the thread reporting the stop event,
8361 that doesn't happen in non-stop mode; in non-stop, the stub *must
8362 not* change the current thread when reporting a breakpoint hit,
8363 due to the decoupling of event reporting and event handling.
8365 To keep things simple, we always invalidate our notion of the
8367 record_currthread (rs
, minus_one_ptid
);
8369 /* Unlike "target remote", we do not want to unpush the target; then
8370 the next time the user says "run", we won't be connected. */
8372 /* Call common code to mark the inferior as not running. */
8373 generic_mourn_inferior ();
8375 if (!have_inferiors ())
8377 if (!remote_multi_process_p (rs
))
8379 /* Check whether the target is running now - some remote stubs
8380 automatically restart after kill. */
8382 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8384 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
8386 /* Assume that the target has been restarted. Set
8387 inferior_ptid so that bits of core GDB realizes
8388 there's something here, e.g., so that the user can
8389 say "kill" again. */
8390 inferior_ptid
= magic_null_ptid
;
8397 extended_remote_supports_disable_randomization (struct target_ops
*self
)
8399 return packet_support (PACKET_QDisableRandomization
) == PACKET_ENABLE
;
8403 extended_remote_disable_randomization (int val
)
8405 struct remote_state
*rs
= get_remote_state ();
8408 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
8411 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
8413 error (_("Target does not support QDisableRandomization."));
8414 if (strcmp (reply
, "OK") != 0)
8415 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
8419 extended_remote_run (char *args
)
8421 struct remote_state
*rs
= get_remote_state ();
8424 /* If the user has disabled vRun support, or we have detected that
8425 support is not available, do not try it. */
8426 if (packet_support (PACKET_vRun
) == PACKET_DISABLE
)
8429 strcpy (rs
->buf
, "vRun;");
8430 len
= strlen (rs
->buf
);
8432 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
8433 error (_("Remote file name too long for run packet"));
8434 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
,
8435 strlen (remote_exec_file
));
8437 gdb_assert (args
!= NULL
);
8440 struct cleanup
*back_to
;
8444 argv
= gdb_buildargv (args
);
8445 back_to
= make_cleanup_freeargv (argv
);
8446 for (i
= 0; argv
[i
] != NULL
; i
++)
8448 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
8449 error (_("Argument list too long for run packet"));
8450 rs
->buf
[len
++] = ';';
8451 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
,
8454 do_cleanups (back_to
);
8457 rs
->buf
[len
++] = '\0';
8460 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8462 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]))
8465 /* We have a wait response. All is well. */
8467 case PACKET_UNKNOWN
:
8470 if (remote_exec_file
[0] == '\0')
8471 error (_("Running the default executable on the remote target failed; "
8472 "try \"set remote exec-file\"?"));
8474 error (_("Running \"%s\" on the remote target failed"),
8477 gdb_assert_not_reached (_("bad switch"));
8481 /* In the extended protocol we want to be able to do things like
8482 "run" and have them basically work as expected. So we need
8483 a special create_inferior function. We support changing the
8484 executable file and the command line arguments, but not the
8488 extended_remote_create_inferior (struct target_ops
*ops
,
8489 char *exec_file
, char *args
,
8490 char **env
, int from_tty
)
8494 struct remote_state
*rs
= get_remote_state ();
8496 /* If running asynchronously, register the target file descriptor
8497 with the event loop. */
8498 if (target_can_async_p ())
8501 /* Disable address space randomization if requested (and supported). */
8502 if (extended_remote_supports_disable_randomization (ops
))
8503 extended_remote_disable_randomization (disable_randomization
);
8505 /* Now restart the remote server. */
8506 run_worked
= extended_remote_run (args
) != -1;
8509 /* vRun was not supported. Fail if we need it to do what the
8511 if (remote_exec_file
[0])
8512 error (_("Remote target does not support \"set remote exec-file\""));
8514 error (_("Remote target does not support \"set args\" or run <ARGS>"));
8516 /* Fall back to "R". */
8517 extended_remote_restart ();
8520 if (!have_inferiors ())
8522 /* Clean up from the last time we ran, before we mark the target
8523 running again. This will mark breakpoints uninserted, and
8524 get_offsets may insert breakpoints. */
8525 init_thread_list ();
8526 init_wait_for_inferior ();
8529 /* vRun's success return is a stop reply. */
8530 stop_reply
= run_worked
? rs
->buf
: NULL
;
8531 add_current_inferior_and_thread (stop_reply
);
8533 /* Get updated offsets, if the stub uses qOffsets. */
8538 /* Given a location's target info BP_TGT and the packet buffer BUF, output
8539 the list of conditions (in agent expression bytecode format), if any, the
8540 target needs to evaluate. The output is placed into the packet buffer
8541 started from BUF and ended at BUF_END. */
8544 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
8545 struct bp_target_info
*bp_tgt
, char *buf
,
8548 struct agent_expr
*aexpr
= NULL
;
8551 char *buf_start
= buf
;
8553 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
8556 buf
+= strlen (buf
);
8557 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
8560 /* Send conditions to the target and free the vector. */
8562 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
8565 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
8566 buf
+= strlen (buf
);
8567 for (i
= 0; i
< aexpr
->len
; ++i
)
8568 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8575 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8576 struct bp_target_info
*bp_tgt
, char *buf
)
8578 struct agent_expr
*aexpr
= NULL
;
8581 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8584 buf
+= strlen (buf
);
8586 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8587 buf
+= strlen (buf
);
8589 /* Concatenate all the agent expressions that are commands into the
8592 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8595 sprintf (buf
, "X%x,", aexpr
->len
);
8596 buf
+= strlen (buf
);
8597 for (i
= 0; i
< aexpr
->len
; ++i
)
8598 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8603 /* Insert a breakpoint. On targets that have software breakpoint
8604 support, we ask the remote target to do the work; on targets
8605 which don't, we insert a traditional memory breakpoint. */
8608 remote_insert_breakpoint (struct target_ops
*ops
,
8609 struct gdbarch
*gdbarch
,
8610 struct bp_target_info
*bp_tgt
)
8612 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8613 If it succeeds, then set the support to PACKET_ENABLE. If it
8614 fails, and the user has explicitly requested the Z support then
8615 report an error, otherwise, mark it disabled and go on. */
8617 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8619 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
8620 struct remote_state
*rs
;
8623 struct condition_list
*cond
= NULL
;
8625 /* Make sure the remote is pointing at the right process, if
8627 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8628 set_general_process ();
8630 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8632 rs
= get_remote_state ();
8634 endbuf
= rs
->buf
+ get_remote_packet_size ();
8639 addr
= (ULONGEST
) remote_address_masked (addr
);
8640 p
+= hexnumstr (p
, addr
);
8641 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8643 if (remote_supports_cond_breakpoints (ops
))
8644 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8646 if (remote_can_run_breakpoint_commands (ops
))
8647 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8650 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8652 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8657 bp_tgt
->placed_address
= addr
;
8658 bp_tgt
->placed_size
= bpsize
;
8660 case PACKET_UNKNOWN
:
8665 /* If this breakpoint has target-side commands but this stub doesn't
8666 support Z0 packets, throw error. */
8667 if (!VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8668 throw_error (NOT_SUPPORTED_ERROR
, _("\
8669 Target doesn't support breakpoints that have target side commands."));
8671 return memory_insert_breakpoint (ops
, gdbarch
, bp_tgt
);
8675 remote_remove_breakpoint (struct target_ops
*ops
,
8676 struct gdbarch
*gdbarch
,
8677 struct bp_target_info
*bp_tgt
)
8679 CORE_ADDR addr
= bp_tgt
->placed_address
;
8680 struct remote_state
*rs
= get_remote_state ();
8682 if (packet_support (PACKET_Z0
) != PACKET_DISABLE
)
8685 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8687 /* Make sure the remote is pointing at the right process, if
8689 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8690 set_general_process ();
8696 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8697 p
+= hexnumstr (p
, addr
);
8698 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8701 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8703 return (rs
->buf
[0] == 'E');
8706 return memory_remove_breakpoint (ops
, gdbarch
, bp_tgt
);
8709 static enum Z_packet_type
8710 watchpoint_to_Z_packet (int type
)
8715 return Z_PACKET_WRITE_WP
;
8718 return Z_PACKET_READ_WP
;
8721 return Z_PACKET_ACCESS_WP
;
8724 internal_error (__FILE__
, __LINE__
,
8725 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8730 remote_insert_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
8731 enum target_hw_bp_type type
, struct expression
*cond
)
8733 struct remote_state
*rs
= get_remote_state ();
8734 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8736 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8738 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
8741 /* Make sure the remote is pointing at the right process, if
8743 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8744 set_general_process ();
8746 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8747 p
= strchr (rs
->buf
, '\0');
8748 addr
= remote_address_masked (addr
);
8749 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8750 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8753 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8755 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8759 case PACKET_UNKNOWN
:
8764 internal_error (__FILE__
, __LINE__
,
8765 _("remote_insert_watchpoint: reached end of function"));
8769 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8770 CORE_ADDR start
, int length
)
8772 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8774 return diff
< length
;
8779 remote_remove_watchpoint (struct target_ops
*self
, CORE_ADDR addr
, int len
,
8780 enum target_hw_bp_type type
, struct expression
*cond
)
8782 struct remote_state
*rs
= get_remote_state ();
8783 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8785 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8787 if (packet_support (PACKET_Z0
+ packet
) == PACKET_DISABLE
)
8790 /* Make sure the remote is pointing at the right process, if
8792 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8793 set_general_process ();
8795 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8796 p
= strchr (rs
->buf
, '\0');
8797 addr
= remote_address_masked (addr
);
8798 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8799 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8801 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8803 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8806 case PACKET_UNKNOWN
:
8811 internal_error (__FILE__
, __LINE__
,
8812 _("remote_remove_watchpoint: reached end of function"));
8816 int remote_hw_watchpoint_limit
= -1;
8817 int remote_hw_watchpoint_length_limit
= -1;
8818 int remote_hw_breakpoint_limit
= -1;
8821 remote_region_ok_for_hw_watchpoint (struct target_ops
*self
,
8822 CORE_ADDR addr
, int len
)
8824 if (remote_hw_watchpoint_length_limit
== 0)
8826 else if (remote_hw_watchpoint_length_limit
< 0)
8828 else if (len
<= remote_hw_watchpoint_length_limit
)
8835 remote_check_watch_resources (struct target_ops
*self
,
8836 enum bptype type
, int cnt
, int ot
)
8838 if (type
== bp_hardware_breakpoint
)
8840 if (remote_hw_breakpoint_limit
== 0)
8842 else if (remote_hw_breakpoint_limit
< 0)
8844 else if (cnt
<= remote_hw_breakpoint_limit
)
8849 if (remote_hw_watchpoint_limit
== 0)
8851 else if (remote_hw_watchpoint_limit
< 0)
8855 else if (cnt
<= remote_hw_watchpoint_limit
)
8861 /* The to_stopped_by_sw_breakpoint method of target remote. */
8864 remote_stopped_by_sw_breakpoint (struct target_ops
*ops
)
8866 struct remote_state
*rs
= get_remote_state ();
8868 return rs
->stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
;
8871 /* The to_supports_stopped_by_sw_breakpoint method of target
8875 remote_supports_stopped_by_sw_breakpoint (struct target_ops
*ops
)
8877 struct remote_state
*rs
= get_remote_state ();
8879 return (packet_support (PACKET_swbreak_feature
) == PACKET_ENABLE
);
8882 /* The to_stopped_by_hw_breakpoint method of target remote. */
8885 remote_stopped_by_hw_breakpoint (struct target_ops
*ops
)
8887 struct remote_state
*rs
= get_remote_state ();
8889 return rs
->stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
;
8892 /* The to_supports_stopped_by_hw_breakpoint method of target
8896 remote_supports_stopped_by_hw_breakpoint (struct target_ops
*ops
)
8898 struct remote_state
*rs
= get_remote_state ();
8900 return (packet_support (PACKET_hwbreak_feature
) == PACKET_ENABLE
);
8904 remote_stopped_by_watchpoint (struct target_ops
*ops
)
8906 struct remote_state
*rs
= get_remote_state ();
8908 return rs
->stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
;
8912 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
8914 struct remote_state
*rs
= get_remote_state ();
8917 if (remote_stopped_by_watchpoint (target
))
8919 *addr_p
= rs
->remote_watch_data_address
;
8928 remote_insert_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
8929 struct bp_target_info
*bp_tgt
)
8931 CORE_ADDR addr
= bp_tgt
->reqstd_address
;
8932 struct remote_state
*rs
;
8937 /* The length field should be set to the size of a breakpoint
8938 instruction, even though we aren't inserting one ourselves. */
8940 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8942 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
8945 /* Make sure the remote is pointing at the right process, if
8947 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
8948 set_general_process ();
8950 rs
= get_remote_state ();
8952 endbuf
= rs
->buf
+ get_remote_packet_size ();
8958 addr
= remote_address_masked (addr
);
8959 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8960 xsnprintf (p
, endbuf
- p
, ",%x", bpsize
);
8962 if (remote_supports_cond_breakpoints (self
))
8963 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8965 if (remote_can_run_breakpoint_commands (self
))
8966 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8969 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8971 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8974 if (rs
->buf
[1] == '.')
8976 message
= strchr (rs
->buf
+ 2, '.');
8978 error (_("Remote failure reply: %s"), message
+ 1);
8981 case PACKET_UNKNOWN
:
8984 bp_tgt
->placed_address
= addr
;
8985 bp_tgt
->placed_size
= bpsize
;
8988 internal_error (__FILE__
, __LINE__
,
8989 _("remote_insert_hw_breakpoint: reached end of function"));
8994 remote_remove_hw_breakpoint (struct target_ops
*self
, struct gdbarch
*gdbarch
,
8995 struct bp_target_info
*bp_tgt
)
8998 struct remote_state
*rs
= get_remote_state ();
9000 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
9002 if (packet_support (PACKET_Z1
) == PACKET_DISABLE
)
9005 /* Make sure the remote is pointing at the right process, if
9007 if (!gdbarch_has_global_breakpoints (target_gdbarch ()))
9008 set_general_process ();
9014 addr
= remote_address_masked (bp_tgt
->placed_address
);
9015 p
+= hexnumstr (p
, (ULONGEST
) addr
);
9016 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
9019 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9021 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
9024 case PACKET_UNKNOWN
:
9029 internal_error (__FILE__
, __LINE__
,
9030 _("remote_remove_hw_breakpoint: reached end of function"));
9033 /* Verify memory using the "qCRC:" request. */
9036 remote_verify_memory (struct target_ops
*ops
,
9037 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
9039 struct remote_state
*rs
= get_remote_state ();
9040 unsigned long host_crc
, target_crc
;
9043 /* It doesn't make sense to use qCRC if the remote target is
9044 connected but not running. */
9045 if (target_has_execution
&& packet_support (PACKET_qCRC
) != PACKET_DISABLE
)
9047 enum packet_result result
;
9049 /* Make sure the remote is pointing at the right process. */
9050 set_general_process ();
9052 /* FIXME: assumes lma can fit into long. */
9053 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
9054 (long) lma
, (long) size
);
9057 /* Be clever; compute the host_crc before waiting for target
9059 host_crc
= xcrc32 (data
, size
, 0xffffffff);
9061 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9063 result
= packet_ok (rs
->buf
,
9064 &remote_protocol_packets
[PACKET_qCRC
]);
9065 if (result
== PACKET_ERROR
)
9067 else if (result
== PACKET_OK
)
9069 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
9070 target_crc
= target_crc
* 16 + fromhex (*tmp
);
9072 return (host_crc
== target_crc
);
9076 return simple_verify_memory (ops
, data
, lma
, size
);
9079 /* compare-sections command
9081 With no arguments, compares each loadable section in the exec bfd
9082 with the same memory range on the target, and reports mismatches.
9083 Useful for verifying the image on the target against the exec file. */
9086 compare_sections_command (char *args
, int from_tty
)
9089 struct cleanup
*old_chain
;
9091 const char *sectname
;
9100 error (_("command cannot be used without an exec file"));
9102 /* Make sure the remote is pointing at the right process. */
9103 set_general_process ();
9105 if (args
!= NULL
&& strcmp (args
, "-r") == 0)
9111 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
9113 if (!(s
->flags
& SEC_LOAD
))
9114 continue; /* Skip non-loadable section. */
9116 if (read_only
&& (s
->flags
& SEC_READONLY
) == 0)
9117 continue; /* Skip writeable sections */
9119 size
= bfd_get_section_size (s
);
9121 continue; /* Skip zero-length section. */
9123 sectname
= bfd_get_section_name (exec_bfd
, s
);
9124 if (args
&& strcmp (args
, sectname
) != 0)
9125 continue; /* Not the section selected by user. */
9127 matched
= 1; /* Do this section. */
9130 sectdata
= xmalloc (size
);
9131 old_chain
= make_cleanup (xfree
, sectdata
);
9132 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
9134 res
= target_verify_memory (sectdata
, lma
, size
);
9137 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
9138 paddress (target_gdbarch (), lma
),
9139 paddress (target_gdbarch (), lma
+ size
));
9141 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
9142 paddress (target_gdbarch (), lma
),
9143 paddress (target_gdbarch (), lma
+ size
));
9145 printf_filtered ("matched.\n");
9148 printf_filtered ("MIS-MATCHED!\n");
9152 do_cleanups (old_chain
);
9155 warning (_("One or more sections of the target image does not match\n\
9156 the loaded file\n"));
9157 if (args
&& !matched
)
9158 printf_filtered (_("No loaded section named '%s'.\n"), args
);
9161 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
9162 into remote target. The number of bytes written to the remote
9163 target is returned, or -1 for error. */
9165 static enum target_xfer_status
9166 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
9167 const char *annex
, const gdb_byte
*writebuf
,
9168 ULONGEST offset
, LONGEST len
, ULONGEST
*xfered_len
,
9169 struct packet_config
*packet
)
9173 struct remote_state
*rs
= get_remote_state ();
9174 int max_size
= get_memory_write_packet_size ();
9176 if (packet
->support
== PACKET_DISABLE
)
9177 return TARGET_XFER_E_IO
;
9179 /* Insert header. */
9180 i
= snprintf (rs
->buf
, max_size
,
9181 "qXfer:%s:write:%s:%s:",
9182 object_name
, annex
? annex
: "",
9183 phex_nz (offset
, sizeof offset
));
9184 max_size
-= (i
+ 1);
9186 /* Escape as much data as fits into rs->buf. */
9187 buf_len
= remote_escape_output
9188 (writebuf
, len
, 1, (gdb_byte
*) rs
->buf
+ i
, &max_size
, max_size
);
9190 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
9191 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9192 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9193 return TARGET_XFER_E_IO
;
9195 unpack_varlen_hex (rs
->buf
, &n
);
9198 return TARGET_XFER_OK
;
9201 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
9202 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
9203 number of bytes read is returned, or 0 for EOF, or -1 for error.
9204 The number of bytes read may be less than LEN without indicating an
9205 EOF. PACKET is checked and updated to indicate whether the remote
9206 target supports this object. */
9208 static enum target_xfer_status
9209 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
9211 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
9212 ULONGEST
*xfered_len
,
9213 struct packet_config
*packet
)
9215 struct remote_state
*rs
= get_remote_state ();
9216 LONGEST i
, n
, packet_len
;
9218 if (packet
->support
== PACKET_DISABLE
)
9219 return TARGET_XFER_E_IO
;
9221 /* Check whether we've cached an end-of-object packet that matches
9223 if (rs
->finished_object
)
9225 if (strcmp (object_name
, rs
->finished_object
) == 0
9226 && strcmp (annex
? annex
: "", rs
->finished_annex
) == 0
9227 && offset
== rs
->finished_offset
)
9228 return TARGET_XFER_EOF
;
9231 /* Otherwise, we're now reading something different. Discard
9233 xfree (rs
->finished_object
);
9234 xfree (rs
->finished_annex
);
9235 rs
->finished_object
= NULL
;
9236 rs
->finished_annex
= NULL
;
9239 /* Request only enough to fit in a single packet. The actual data
9240 may not, since we don't know how much of it will need to be escaped;
9241 the target is free to respond with slightly less data. We subtract
9242 five to account for the response type and the protocol frame. */
9243 n
= min (get_remote_packet_size () - 5, len
);
9244 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
9245 object_name
, annex
? annex
: "",
9246 phex_nz (offset
, sizeof offset
),
9247 phex_nz (n
, sizeof n
));
9248 i
= putpkt (rs
->buf
);
9250 return TARGET_XFER_E_IO
;
9253 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9254 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9255 return TARGET_XFER_E_IO
;
9257 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
9258 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
9260 /* 'm' means there is (or at least might be) more data after this
9261 batch. That does not make sense unless there's at least one byte
9262 of data in this reply. */
9263 if (rs
->buf
[0] == 'm' && packet_len
== 1)
9264 error (_("Remote qXfer reply contained no data."));
9266 /* Got some data. */
9267 i
= remote_unescape_input ((gdb_byte
*) rs
->buf
+ 1,
9268 packet_len
- 1, readbuf
, n
);
9270 /* 'l' is an EOF marker, possibly including a final block of data,
9271 or possibly empty. If we have the final block of a non-empty
9272 object, record this fact to bypass a subsequent partial read. */
9273 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
9275 rs
->finished_object
= xstrdup (object_name
);
9276 rs
->finished_annex
= xstrdup (annex
? annex
: "");
9277 rs
->finished_offset
= offset
+ i
;
9281 return TARGET_XFER_EOF
;
9285 return TARGET_XFER_OK
;
9289 static enum target_xfer_status
9290 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
9291 const char *annex
, gdb_byte
*readbuf
,
9292 const gdb_byte
*writebuf
, ULONGEST offset
, ULONGEST len
,
9293 ULONGEST
*xfered_len
)
9295 struct remote_state
*rs
;
9299 int unit_size
= gdbarch_addressable_memory_unit_size (target_gdbarch ());
9301 set_remote_traceframe ();
9302 set_general_thread (inferior_ptid
);
9304 rs
= get_remote_state ();
9306 /* Handle memory using the standard memory routines. */
9307 if (object
== TARGET_OBJECT_MEMORY
)
9309 /* If the remote target is connected but not running, we should
9310 pass this request down to a lower stratum (e.g. the executable
9312 if (!target_has_execution
)
9313 return TARGET_XFER_EOF
;
9315 if (writebuf
!= NULL
)
9316 return remote_write_bytes (offset
, writebuf
, len
, unit_size
,
9319 return remote_read_bytes (ops
, offset
, readbuf
, len
, unit_size
,
9323 /* Handle SPU memory using qxfer packets. */
9324 if (object
== TARGET_OBJECT_SPU
)
9327 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
9328 xfered_len
, &remote_protocol_packets
9329 [PACKET_qXfer_spu_read
]);
9331 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
9332 xfered_len
, &remote_protocol_packets
9333 [PACKET_qXfer_spu_write
]);
9336 /* Handle extra signal info using qxfer packets. */
9337 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
9340 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
9341 xfered_len
, &remote_protocol_packets
9342 [PACKET_qXfer_siginfo_read
]);
9344 return remote_write_qxfer (ops
, "siginfo", annex
,
9345 writebuf
, offset
, len
, xfered_len
,
9346 &remote_protocol_packets
9347 [PACKET_qXfer_siginfo_write
]);
9350 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
9353 return remote_read_qxfer (ops
, "statictrace", annex
,
9354 readbuf
, offset
, len
, xfered_len
,
9355 &remote_protocol_packets
9356 [PACKET_qXfer_statictrace_read
]);
9358 return TARGET_XFER_E_IO
;
9361 /* Only handle flash writes. */
9362 if (writebuf
!= NULL
)
9368 case TARGET_OBJECT_FLASH
:
9369 return remote_flash_write (ops
, offset
, len
, xfered_len
,
9373 return TARGET_XFER_E_IO
;
9377 /* Map pre-existing objects onto letters. DO NOT do this for new
9378 objects!!! Instead specify new query packets. */
9381 case TARGET_OBJECT_AVR
:
9385 case TARGET_OBJECT_AUXV
:
9386 gdb_assert (annex
== NULL
);
9387 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
9389 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
9391 case TARGET_OBJECT_AVAILABLE_FEATURES
:
9392 return remote_read_qxfer
9393 (ops
, "features", annex
, readbuf
, offset
, len
, xfered_len
,
9394 &remote_protocol_packets
[PACKET_qXfer_features
]);
9396 case TARGET_OBJECT_LIBRARIES
:
9397 return remote_read_qxfer
9398 (ops
, "libraries", annex
, readbuf
, offset
, len
, xfered_len
,
9399 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
9401 case TARGET_OBJECT_LIBRARIES_SVR4
:
9402 return remote_read_qxfer
9403 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
, xfered_len
,
9404 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
9406 case TARGET_OBJECT_MEMORY_MAP
:
9407 gdb_assert (annex
== NULL
);
9408 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
9410 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
9412 case TARGET_OBJECT_OSDATA
:
9413 /* Should only get here if we're connected. */
9414 gdb_assert (rs
->remote_desc
);
9415 return remote_read_qxfer
9416 (ops
, "osdata", annex
, readbuf
, offset
, len
, xfered_len
,
9417 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
9419 case TARGET_OBJECT_THREADS
:
9420 gdb_assert (annex
== NULL
);
9421 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
9423 &remote_protocol_packets
[PACKET_qXfer_threads
]);
9425 case TARGET_OBJECT_TRACEFRAME_INFO
:
9426 gdb_assert (annex
== NULL
);
9427 return remote_read_qxfer
9428 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
, xfered_len
,
9429 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
9431 case TARGET_OBJECT_FDPIC
:
9432 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
9434 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
9436 case TARGET_OBJECT_OPENVMS_UIB
:
9437 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
9439 &remote_protocol_packets
[PACKET_qXfer_uib
]);
9441 case TARGET_OBJECT_BTRACE
:
9442 return remote_read_qxfer (ops
, "btrace", annex
, readbuf
, offset
, len
,
9444 &remote_protocol_packets
[PACKET_qXfer_btrace
]);
9446 case TARGET_OBJECT_BTRACE_CONF
:
9447 return remote_read_qxfer (ops
, "btrace-conf", annex
, readbuf
, offset
,
9449 &remote_protocol_packets
[PACKET_qXfer_btrace_conf
]);
9451 case TARGET_OBJECT_EXEC_FILE
:
9452 return remote_read_qxfer (ops
, "exec-file", annex
, readbuf
, offset
,
9454 &remote_protocol_packets
[PACKET_qXfer_exec_file
]);
9457 return TARGET_XFER_E_IO
;
9460 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
9461 large enough let the caller deal with it. */
9462 if (len
< get_remote_packet_size ())
9463 return TARGET_XFER_E_IO
;
9464 len
= get_remote_packet_size ();
9466 /* Except for querying the minimum buffer size, target must be open. */
9467 if (!rs
->remote_desc
)
9468 error (_("remote query is only available after target open"));
9470 gdb_assert (annex
!= NULL
);
9471 gdb_assert (readbuf
!= NULL
);
9477 /* We used one buffer char for the remote protocol q command and
9478 another for the query type. As the remote protocol encapsulation
9479 uses 4 chars plus one extra in case we are debugging
9480 (remote_debug), we have PBUFZIZ - 7 left to pack the query
9483 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
9485 /* Bad caller may have sent forbidden characters. */
9486 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
9491 gdb_assert (annex
[i
] == '\0');
9493 i
= putpkt (rs
->buf
);
9495 return TARGET_XFER_E_IO
;
9497 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9498 strcpy ((char *) readbuf
, rs
->buf
);
9500 *xfered_len
= strlen ((char *) readbuf
);
9501 return TARGET_XFER_OK
;
9505 remote_search_memory (struct target_ops
* ops
,
9506 CORE_ADDR start_addr
, ULONGEST search_space_len
,
9507 const gdb_byte
*pattern
, ULONGEST pattern_len
,
9508 CORE_ADDR
*found_addrp
)
9510 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
9511 struct remote_state
*rs
= get_remote_state ();
9512 int max_size
= get_memory_write_packet_size ();
9513 struct packet_config
*packet
=
9514 &remote_protocol_packets
[PACKET_qSearch_memory
];
9515 /* Number of packet bytes used to encode the pattern;
9516 this could be more than PATTERN_LEN due to escape characters. */
9517 int escaped_pattern_len
;
9518 /* Amount of pattern that was encodable in the packet. */
9519 int used_pattern_len
;
9522 ULONGEST found_addr
;
9524 /* Don't go to the target if we don't have to.
9525 This is done before checking packet->support to avoid the possibility that
9526 a success for this edge case means the facility works in general. */
9527 if (pattern_len
> search_space_len
)
9529 if (pattern_len
== 0)
9531 *found_addrp
= start_addr
;
9535 /* If we already know the packet isn't supported, fall back to the simple
9536 way of searching memory. */
9538 if (packet_config_support (packet
) == PACKET_DISABLE
)
9540 /* Target doesn't provided special support, fall back and use the
9541 standard support (copy memory and do the search here). */
9542 return simple_search_memory (ops
, start_addr
, search_space_len
,
9543 pattern
, pattern_len
, found_addrp
);
9546 /* Make sure the remote is pointing at the right process. */
9547 set_general_process ();
9549 /* Insert header. */
9550 i
= snprintf (rs
->buf
, max_size
,
9551 "qSearch:memory:%s;%s;",
9552 phex_nz (start_addr
, addr_size
),
9553 phex_nz (search_space_len
, sizeof (search_space_len
)));
9554 max_size
-= (i
+ 1);
9556 /* Escape as much data as fits into rs->buf. */
9557 escaped_pattern_len
=
9558 remote_escape_output (pattern
, pattern_len
, 1, (gdb_byte
*) rs
->buf
+ i
,
9559 &used_pattern_len
, max_size
);
9561 /* Bail if the pattern is too large. */
9562 if (used_pattern_len
!= pattern_len
)
9563 error (_("Pattern is too large to transmit to remote target."));
9565 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
9566 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
9567 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
9569 /* The request may not have worked because the command is not
9570 supported. If so, fall back to the simple way. */
9571 if (packet
->support
== PACKET_DISABLE
)
9573 return simple_search_memory (ops
, start_addr
, search_space_len
,
9574 pattern
, pattern_len
, found_addrp
);
9579 if (rs
->buf
[0] == '0')
9581 else if (rs
->buf
[0] == '1')
9584 if (rs
->buf
[1] != ',')
9585 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9586 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
9587 *found_addrp
= found_addr
;
9590 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
9596 remote_rcmd (struct target_ops
*self
, const char *command
,
9597 struct ui_file
*outbuf
)
9599 struct remote_state
*rs
= get_remote_state ();
9602 if (!rs
->remote_desc
)
9603 error (_("remote rcmd is only available after target open"));
9605 /* Send a NULL command across as an empty command. */
9606 if (command
== NULL
)
9609 /* The query prefix. */
9610 strcpy (rs
->buf
, "qRcmd,");
9611 p
= strchr (rs
->buf
, '\0');
9613 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
9614 > get_remote_packet_size ())
9615 error (_("\"monitor\" command ``%s'' is too long."), command
);
9617 /* Encode the actual command. */
9618 bin2hex ((const gdb_byte
*) command
, p
, strlen (command
));
9620 if (putpkt (rs
->buf
) < 0)
9621 error (_("Communication problem with target."));
9623 /* get/display the response */
9628 /* XXX - see also remote_get_noisy_reply(). */
9629 QUIT
; /* Allow user to bail out with ^C. */
9631 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
9633 /* Timeout. Continue to (try to) read responses.
9634 This is better than stopping with an error, assuming the stub
9635 is still executing the (long) monitor command.
9636 If needed, the user can interrupt gdb using C-c, obtaining
9637 an effect similar to stop on timeout. */
9642 error (_("Target does not support this command."));
9643 if (buf
[0] == 'O' && buf
[1] != 'K')
9645 remote_console_output (buf
+ 1); /* 'O' message from stub. */
9648 if (strcmp (buf
, "OK") == 0)
9650 if (strlen (buf
) == 3 && buf
[0] == 'E'
9651 && isdigit (buf
[1]) && isdigit (buf
[2]))
9653 error (_("Protocol error with Rcmd"));
9655 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
9657 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
9659 fputc_unfiltered (c
, outbuf
);
9665 static VEC(mem_region_s
) *
9666 remote_memory_map (struct target_ops
*ops
)
9668 VEC(mem_region_s
) *result
= NULL
;
9669 char *text
= target_read_stralloc (¤t_target
,
9670 TARGET_OBJECT_MEMORY_MAP
, NULL
);
9674 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
9676 result
= parse_memory_map (text
);
9677 do_cleanups (back_to
);
9684 packet_command (char *args
, int from_tty
)
9686 struct remote_state
*rs
= get_remote_state ();
9688 if (!rs
->remote_desc
)
9689 error (_("command can only be used with remote target"));
9692 error (_("remote-packet command requires packet text as argument"));
9694 puts_filtered ("sending: ");
9695 print_packet (args
);
9696 puts_filtered ("\n");
9699 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9700 puts_filtered ("received: ");
9701 print_packet (rs
->buf
);
9702 puts_filtered ("\n");
9706 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9708 static void display_thread_info (struct gdb_ext_thread_info
*info
);
9710 static void threadset_test_cmd (char *cmd
, int tty
);
9712 static void threadalive_test (char *cmd
, int tty
);
9714 static void threadlist_test_cmd (char *cmd
, int tty
);
9716 int get_and_display_threadinfo (threadref
*ref
);
9718 static void threadinfo_test_cmd (char *cmd
, int tty
);
9720 static int thread_display_step (threadref
*ref
, void *context
);
9722 static void threadlist_update_test_cmd (char *cmd
, int tty
);
9724 static void init_remote_threadtests (void);
9726 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9729 threadset_test_cmd (char *cmd
, int tty
)
9731 int sample_thread
= SAMPLE_THREAD
;
9733 printf_filtered (_("Remote threadset test\n"));
9734 set_general_thread (sample_thread
);
9739 threadalive_test (char *cmd
, int tty
)
9741 int sample_thread
= SAMPLE_THREAD
;
9742 int pid
= ptid_get_pid (inferior_ptid
);
9743 ptid_t ptid
= ptid_build (pid
, sample_thread
, 0);
9745 if (remote_thread_alive (ptid
))
9746 printf_filtered ("PASS: Thread alive test\n");
9748 printf_filtered ("FAIL: Thread alive test\n");
9751 void output_threadid (char *title
, threadref
*ref
);
9754 output_threadid (char *title
, threadref
*ref
)
9758 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
9760 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
9764 threadlist_test_cmd (char *cmd
, int tty
)
9767 threadref nextthread
;
9768 int done
, result_count
;
9769 threadref threadlist
[3];
9771 printf_filtered ("Remote Threadlist test\n");
9772 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9773 &result_count
, &threadlist
[0]))
9774 printf_filtered ("FAIL: threadlist test\n");
9777 threadref
*scan
= threadlist
;
9778 threadref
*limit
= scan
+ result_count
;
9780 while (scan
< limit
)
9781 output_threadid (" thread ", scan
++);
9786 display_thread_info (struct gdb_ext_thread_info
*info
)
9788 output_threadid ("Threadid: ", &info
->threadid
);
9789 printf_filtered ("Name: %s\n ", info
->shortname
);
9790 printf_filtered ("State: %s\n", info
->display
);
9791 printf_filtered ("other: %s\n\n", info
->more_display
);
9795 get_and_display_threadinfo (threadref
*ref
)
9799 struct gdb_ext_thread_info threadinfo
;
9801 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9802 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9803 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9804 display_thread_info (&threadinfo
);
9809 threadinfo_test_cmd (char *cmd
, int tty
)
9811 int athread
= SAMPLE_THREAD
;
9815 int_to_threadref (&thread
, athread
);
9816 printf_filtered ("Remote Threadinfo test\n");
9817 if (!get_and_display_threadinfo (&thread
))
9818 printf_filtered ("FAIL cannot get thread info\n");
9822 thread_display_step (threadref
*ref
, void *context
)
9824 /* output_threadid(" threadstep ",ref); *//* simple test */
9825 return get_and_display_threadinfo (ref
);
9829 threadlist_update_test_cmd (char *cmd
, int tty
)
9831 printf_filtered ("Remote Threadlist update test\n");
9832 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9836 init_remote_threadtests (void)
9838 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9839 _("Fetch and print the remote list of "
9840 "thread identifiers, one pkt only"));
9841 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9842 _("Fetch and display info about one thread"));
9843 add_com ("tset", class_obscure
, threadset_test_cmd
,
9844 _("Test setting to a different thread"));
9845 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9846 _("Iterate through updating all remote thread info"));
9847 add_com ("talive", class_obscure
, threadalive_test
,
9848 _(" Remote thread alive test "));
9853 /* Convert a thread ID to a string. Returns the string in a static
9857 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
9859 static char buf
[64];
9860 struct remote_state
*rs
= get_remote_state ();
9862 if (ptid_equal (ptid
, null_ptid
))
9863 return normal_pid_to_str (ptid
);
9864 else if (ptid_is_pid (ptid
))
9866 /* Printing an inferior target id. */
9868 /* When multi-process extensions are off, there's no way in the
9869 remote protocol to know the remote process id, if there's any
9870 at all. There's one exception --- when we're connected with
9871 target extended-remote, and we manually attached to a process
9872 with "attach PID". We don't record anywhere a flag that
9873 allows us to distinguish that case from the case of
9874 connecting with extended-remote and the stub already being
9875 attached to a process, and reporting yes to qAttached, hence
9876 no smart special casing here. */
9877 if (!remote_multi_process_p (rs
))
9879 xsnprintf (buf
, sizeof buf
, "Remote target");
9883 return normal_pid_to_str (ptid
);
9887 if (ptid_equal (magic_null_ptid
, ptid
))
9888 xsnprintf (buf
, sizeof buf
, "Thread <main>");
9889 else if (rs
->extended
&& remote_multi_process_p (rs
))
9890 if (ptid_get_lwp (ptid
) == 0)
9891 return normal_pid_to_str (ptid
);
9893 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
9894 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
9896 xsnprintf (buf
, sizeof buf
, "Thread %ld",
9897 ptid_get_lwp (ptid
));
9902 /* Get the address of the thread local variable in OBJFILE which is
9903 stored at OFFSET within the thread local storage for thread PTID. */
9906 remote_get_thread_local_address (struct target_ops
*ops
,
9907 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
9909 if (packet_support (PACKET_qGetTLSAddr
) != PACKET_DISABLE
)
9911 struct remote_state
*rs
= get_remote_state ();
9913 char *endp
= rs
->buf
+ get_remote_packet_size ();
9914 enum packet_result result
;
9916 strcpy (p
, "qGetTLSAddr:");
9918 p
= write_ptid (p
, endp
, ptid
);
9920 p
+= hexnumstr (p
, offset
);
9922 p
+= hexnumstr (p
, lm
);
9926 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9927 result
= packet_ok (rs
->buf
,
9928 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
9929 if (result
== PACKET_OK
)
9933 unpack_varlen_hex (rs
->buf
, &result
);
9936 else if (result
== PACKET_UNKNOWN
)
9937 throw_error (TLS_GENERIC_ERROR
,
9938 _("Remote target doesn't support qGetTLSAddr packet"));
9940 throw_error (TLS_GENERIC_ERROR
,
9941 _("Remote target failed to process qGetTLSAddr request"));
9944 throw_error (TLS_GENERIC_ERROR
,
9945 _("TLS not supported or disabled on this target"));
9950 /* Provide thread local base, i.e. Thread Information Block address.
9951 Returns 1 if ptid is found and thread_local_base is non zero. */
9954 remote_get_tib_address (struct target_ops
*self
, ptid_t ptid
, CORE_ADDR
*addr
)
9956 if (packet_support (PACKET_qGetTIBAddr
) != PACKET_DISABLE
)
9958 struct remote_state
*rs
= get_remote_state ();
9960 char *endp
= rs
->buf
+ get_remote_packet_size ();
9961 enum packet_result result
;
9963 strcpy (p
, "qGetTIBAddr:");
9965 p
= write_ptid (p
, endp
, ptid
);
9969 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9970 result
= packet_ok (rs
->buf
,
9971 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
9972 if (result
== PACKET_OK
)
9976 unpack_varlen_hex (rs
->buf
, &result
);
9978 *addr
= (CORE_ADDR
) result
;
9981 else if (result
== PACKET_UNKNOWN
)
9982 error (_("Remote target doesn't support qGetTIBAddr packet"));
9984 error (_("Remote target failed to process qGetTIBAddr request"));
9987 error (_("qGetTIBAddr not supported or disabled on this target"));
9992 /* Support for inferring a target description based on the current
9993 architecture and the size of a 'g' packet. While the 'g' packet
9994 can have any size (since optional registers can be left off the
9995 end), some sizes are easily recognizable given knowledge of the
9996 approximate architecture. */
9998 struct remote_g_packet_guess
10001 const struct target_desc
*tdesc
;
10003 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
10004 DEF_VEC_O(remote_g_packet_guess_s
);
10006 struct remote_g_packet_data
10008 VEC(remote_g_packet_guess_s
) *guesses
;
10011 static struct gdbarch_data
*remote_g_packet_data_handle
;
10014 remote_g_packet_data_init (struct obstack
*obstack
)
10016 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
10020 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
10021 const struct target_desc
*tdesc
)
10023 struct remote_g_packet_data
*data
10024 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
10025 struct remote_g_packet_guess new_guess
, *guess
;
10028 gdb_assert (tdesc
!= NULL
);
10031 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10033 if (guess
->bytes
== bytes
)
10034 internal_error (__FILE__
, __LINE__
,
10035 _("Duplicate g packet description added for size %d"),
10038 new_guess
.bytes
= bytes
;
10039 new_guess
.tdesc
= tdesc
;
10040 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
10043 /* Return 1 if remote_read_description would do anything on this target
10044 and architecture, 0 otherwise. */
10047 remote_read_description_p (struct target_ops
*target
)
10049 struct remote_g_packet_data
*data
10050 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
10052 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10058 static const struct target_desc
*
10059 remote_read_description (struct target_ops
*target
)
10061 struct remote_g_packet_data
*data
10062 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
10064 /* Do not try this during initial connection, when we do not know
10065 whether there is a running but stopped thread. */
10066 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
10067 return target
->beneath
->to_read_description (target
->beneath
);
10069 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
10071 struct remote_g_packet_guess
*guess
;
10073 int bytes
= send_g_packet ();
10076 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
10078 if (guess
->bytes
== bytes
)
10079 return guess
->tdesc
;
10081 /* We discard the g packet. A minor optimization would be to
10082 hold on to it, and fill the register cache once we have selected
10083 an architecture, but it's too tricky to do safely. */
10086 return target
->beneath
->to_read_description (target
->beneath
);
10089 /* Remote file transfer support. This is host-initiated I/O, not
10090 target-initiated; for target-initiated, see remote-fileio.c. */
10092 /* If *LEFT is at least the length of STRING, copy STRING to
10093 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10094 decrease *LEFT. Otherwise raise an error. */
10097 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
10099 int len
= strlen (string
);
10102 error (_("Packet too long for target."));
10104 memcpy (*buffer
, string
, len
);
10108 /* NUL-terminate the buffer as a convenience, if there is
10114 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
10115 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10116 decrease *LEFT. Otherwise raise an error. */
10119 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
10122 if (2 * len
> *left
)
10123 error (_("Packet too long for target."));
10125 bin2hex (bytes
, *buffer
, len
);
10126 *buffer
+= 2 * len
;
10129 /* NUL-terminate the buffer as a convenience, if there is
10135 /* If *LEFT is large enough, convert VALUE to hex and add it to
10136 *BUFFER, update *BUFFER to point to the new end of the buffer, and
10137 decrease *LEFT. Otherwise raise an error. */
10140 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
10142 int len
= hexnumlen (value
);
10145 error (_("Packet too long for target."));
10147 hexnumstr (*buffer
, value
);
10151 /* NUL-terminate the buffer as a convenience, if there is
10157 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
10158 value, *REMOTE_ERRNO to the remote error number or zero if none
10159 was included, and *ATTACHMENT to point to the start of the annex
10160 if any. The length of the packet isn't needed here; there may
10161 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
10163 Return 0 if the packet could be parsed, -1 if it could not. If
10164 -1 is returned, the other variables may not be initialized. */
10167 remote_hostio_parse_result (char *buffer
, int *retcode
,
10168 int *remote_errno
, char **attachment
)
10173 *attachment
= NULL
;
10175 if (buffer
[0] != 'F')
10179 *retcode
= strtol (&buffer
[1], &p
, 16);
10180 if (errno
!= 0 || p
== &buffer
[1])
10183 /* Check for ",errno". */
10187 *remote_errno
= strtol (p
+ 1, &p2
, 16);
10188 if (errno
!= 0 || p
+ 1 == p2
)
10193 /* Check for ";attachment". If there is no attachment, the
10194 packet should end here. */
10197 *attachment
= p
+ 1;
10200 else if (*p
== '\0')
10206 /* Send a prepared I/O packet to the target and read its response.
10207 The prepared packet is in the global RS->BUF before this function
10208 is called, and the answer is there when we return.
10210 COMMAND_BYTES is the length of the request to send, which may include
10211 binary data. WHICH_PACKET is the packet configuration to check
10212 before attempting a packet. If an error occurs, *REMOTE_ERRNO
10213 is set to the error number and -1 is returned. Otherwise the value
10214 returned by the function is returned.
10216 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
10217 attachment is expected; an error will be reported if there's a
10218 mismatch. If one is found, *ATTACHMENT will be set to point into
10219 the packet buffer and *ATTACHMENT_LEN will be set to the
10220 attachment's length. */
10223 remote_hostio_send_command (int command_bytes
, int which_packet
,
10224 int *remote_errno
, char **attachment
,
10225 int *attachment_len
)
10227 struct remote_state
*rs
= get_remote_state ();
10228 int ret
, bytes_read
;
10229 char *attachment_tmp
;
10231 if (!rs
->remote_desc
10232 || packet_support (which_packet
) == PACKET_DISABLE
)
10234 *remote_errno
= FILEIO_ENOSYS
;
10238 putpkt_binary (rs
->buf
, command_bytes
);
10239 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
10241 /* If it timed out, something is wrong. Don't try to parse the
10243 if (bytes_read
< 0)
10245 *remote_errno
= FILEIO_EINVAL
;
10249 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
10252 *remote_errno
= FILEIO_EINVAL
;
10254 case PACKET_UNKNOWN
:
10255 *remote_errno
= FILEIO_ENOSYS
;
10261 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
10264 *remote_errno
= FILEIO_EINVAL
;
10268 /* Make sure we saw an attachment if and only if we expected one. */
10269 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
10270 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
10272 *remote_errno
= FILEIO_EINVAL
;
10276 /* If an attachment was found, it must point into the packet buffer;
10277 work out how many bytes there were. */
10278 if (attachment_tmp
!= NULL
)
10280 *attachment
= attachment_tmp
;
10281 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
10287 /* Set the filesystem remote_hostio functions that take FILENAME
10288 arguments will use. Return 0 on success, or -1 if an error
10289 occurs (and set *REMOTE_ERRNO). */
10292 remote_hostio_set_filesystem (struct inferior
*inf
, int *remote_errno
)
10294 struct remote_state
*rs
= get_remote_state ();
10295 int required_pid
= (inf
== NULL
|| inf
->fake_pid_p
) ? 0 : inf
->pid
;
10297 int left
= get_remote_packet_size () - 1;
10301 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10304 if (rs
->fs_pid
!= -1 && required_pid
== rs
->fs_pid
)
10307 remote_buffer_add_string (&p
, &left
, "vFile:setfs:");
10309 xsnprintf (arg
, sizeof (arg
), "%x", required_pid
);
10310 remote_buffer_add_string (&p
, &left
, arg
);
10312 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_setfs
,
10313 remote_errno
, NULL
, NULL
);
10315 if (packet_support (PACKET_vFile_setfs
) == PACKET_DISABLE
)
10319 rs
->fs_pid
= required_pid
;
10324 /* Implementation of to_fileio_open. */
10327 remote_hostio_open (struct target_ops
*self
,
10328 struct inferior
*inf
, const char *filename
,
10329 int flags
, int mode
, int *remote_errno
)
10331 struct remote_state
*rs
= get_remote_state ();
10333 int left
= get_remote_packet_size () - 1;
10335 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10338 remote_buffer_add_string (&p
, &left
, "vFile:open:");
10340 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10341 strlen (filename
));
10342 remote_buffer_add_string (&p
, &left
, ",");
10344 remote_buffer_add_int (&p
, &left
, flags
);
10345 remote_buffer_add_string (&p
, &left
, ",");
10347 remote_buffer_add_int (&p
, &left
, mode
);
10349 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
10350 remote_errno
, NULL
, NULL
);
10353 /* Implementation of to_fileio_pwrite. */
10356 remote_hostio_pwrite (struct target_ops
*self
,
10357 int fd
, const gdb_byte
*write_buf
, int len
,
10358 ULONGEST offset
, int *remote_errno
)
10360 struct remote_state
*rs
= get_remote_state ();
10362 int left
= get_remote_packet_size ();
10365 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
10367 remote_buffer_add_int (&p
, &left
, fd
);
10368 remote_buffer_add_string (&p
, &left
, ",");
10370 remote_buffer_add_int (&p
, &left
, offset
);
10371 remote_buffer_add_string (&p
, &left
, ",");
10373 p
+= remote_escape_output (write_buf
, len
, 1, (gdb_byte
*) p
, &out_len
,
10374 get_remote_packet_size () - (p
- rs
->buf
));
10376 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
10377 remote_errno
, NULL
, NULL
);
10380 /* Implementation of to_fileio_pread. */
10383 remote_hostio_pread (struct target_ops
*self
,
10384 int fd
, gdb_byte
*read_buf
, int len
,
10385 ULONGEST offset
, int *remote_errno
)
10387 struct remote_state
*rs
= get_remote_state ();
10390 int left
= get_remote_packet_size ();
10391 int ret
, attachment_len
;
10394 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
10396 remote_buffer_add_int (&p
, &left
, fd
);
10397 remote_buffer_add_string (&p
, &left
, ",");
10399 remote_buffer_add_int (&p
, &left
, len
);
10400 remote_buffer_add_string (&p
, &left
, ",");
10402 remote_buffer_add_int (&p
, &left
, offset
);
10404 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
10405 remote_errno
, &attachment
,
10411 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10413 if (read_len
!= ret
)
10414 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
10419 /* Implementation of to_fileio_close. */
10422 remote_hostio_close (struct target_ops
*self
, int fd
, int *remote_errno
)
10424 struct remote_state
*rs
= get_remote_state ();
10426 int left
= get_remote_packet_size () - 1;
10428 remote_buffer_add_string (&p
, &left
, "vFile:close:");
10430 remote_buffer_add_int (&p
, &left
, fd
);
10432 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
10433 remote_errno
, NULL
, NULL
);
10436 /* Implementation of to_fileio_unlink. */
10439 remote_hostio_unlink (struct target_ops
*self
,
10440 struct inferior
*inf
, const char *filename
,
10443 struct remote_state
*rs
= get_remote_state ();
10445 int left
= get_remote_packet_size () - 1;
10447 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10450 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
10452 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10453 strlen (filename
));
10455 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
10456 remote_errno
, NULL
, NULL
);
10459 /* Implementation of to_fileio_readlink. */
10462 remote_hostio_readlink (struct target_ops
*self
,
10463 struct inferior
*inf
, const char *filename
,
10466 struct remote_state
*rs
= get_remote_state ();
10469 int left
= get_remote_packet_size ();
10470 int len
, attachment_len
;
10474 if (remote_hostio_set_filesystem (inf
, remote_errno
) != 0)
10477 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
10479 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
10480 strlen (filename
));
10482 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
10483 remote_errno
, &attachment
,
10489 ret
= xmalloc (len
+ 1);
10491 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10492 (gdb_byte
*) ret
, len
);
10493 if (read_len
!= len
)
10494 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
10500 /* Implementation of to_fileio_fstat. */
10503 remote_hostio_fstat (struct target_ops
*self
,
10504 int fd
, struct stat
*st
,
10507 struct remote_state
*rs
= get_remote_state ();
10509 int left
= get_remote_packet_size ();
10510 int attachment_len
, ret
;
10512 struct fio_stat fst
;
10515 remote_buffer_add_string (&p
, &left
, "vFile:fstat:");
10517 remote_buffer_add_int (&p
, &left
, fd
);
10519 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_fstat
,
10520 remote_errno
, &attachment
,
10524 if (*remote_errno
!= FILEIO_ENOSYS
)
10527 /* Strictly we should return -1, ENOSYS here, but when
10528 "set sysroot remote:" was implemented in August 2008
10529 BFD's need for a stat function was sidestepped with
10530 this hack. This was not remedied until March 2015
10531 so we retain the previous behavior to avoid breaking
10534 Note that the memset is a March 2015 addition; older
10535 GDBs set st_size *and nothing else* so the structure
10536 would have garbage in all other fields. This might
10537 break something but retaining the previous behavior
10538 here would be just too wrong. */
10540 memset (st
, 0, sizeof (struct stat
));
10541 st
->st_size
= INT_MAX
;
10545 read_len
= remote_unescape_input ((gdb_byte
*) attachment
, attachment_len
,
10546 (gdb_byte
*) &fst
, sizeof (fst
));
10548 if (read_len
!= ret
)
10549 error (_("vFile:fstat returned %d, but %d bytes."), ret
, read_len
);
10551 if (read_len
!= sizeof (fst
))
10552 error (_("vFile:fstat returned %d bytes, but expecting %d."),
10553 read_len
, (int) sizeof (fst
));
10555 remote_fileio_to_host_stat (&fst
, st
);
10560 /* Implementation of to_filesystem_is_local. */
10563 remote_filesystem_is_local (struct target_ops
*self
)
10565 /* Valgrind GDB presents itself as a remote target but works
10566 on the local filesystem: it does not implement remote get
10567 and users are not expected to set a sysroot. To handle
10568 this case we treat the remote filesystem as local if the
10569 sysroot is exactly TARGET_SYSROOT_PREFIX and if the stub
10570 does not support vFile:open. */
10571 if (strcmp (gdb_sysroot
, TARGET_SYSROOT_PREFIX
) == 0)
10573 enum packet_support ps
= packet_support (PACKET_vFile_open
);
10575 if (ps
== PACKET_SUPPORT_UNKNOWN
)
10577 int fd
, remote_errno
;
10579 /* Try opening a file to probe support. The supplied
10580 filename is irrelevant, we only care about whether
10581 the stub recognizes the packet or not. */
10582 fd
= remote_hostio_open (self
, NULL
, "just probing",
10583 FILEIO_O_RDONLY
, 0700,
10587 remote_hostio_close (self
, fd
, &remote_errno
);
10589 ps
= packet_support (PACKET_vFile_open
);
10592 if (ps
== PACKET_DISABLE
)
10594 static int warning_issued
= 0;
10596 if (!warning_issued
)
10598 warning (_("remote target does not support file"
10599 " transfer, attempting to access files"
10600 " from local filesystem."));
10601 warning_issued
= 1;
10612 remote_fileio_errno_to_host (int errnum
)
10618 case FILEIO_ENOENT
:
10626 case FILEIO_EACCES
:
10628 case FILEIO_EFAULT
:
10632 case FILEIO_EEXIST
:
10634 case FILEIO_ENODEV
:
10636 case FILEIO_ENOTDIR
:
10638 case FILEIO_EISDIR
:
10640 case FILEIO_EINVAL
:
10642 case FILEIO_ENFILE
:
10644 case FILEIO_EMFILE
:
10648 case FILEIO_ENOSPC
:
10650 case FILEIO_ESPIPE
:
10654 case FILEIO_ENOSYS
:
10656 case FILEIO_ENAMETOOLONG
:
10657 return ENAMETOOLONG
;
10663 remote_hostio_error (int errnum
)
10665 int host_error
= remote_fileio_errno_to_host (errnum
);
10667 if (host_error
== -1)
10668 error (_("Unknown remote I/O error %d"), errnum
);
10670 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
10674 remote_hostio_close_cleanup (void *opaque
)
10676 int fd
= *(int *) opaque
;
10679 remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
);
10683 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
10685 struct cleanup
*back_to
, *close_cleanup
;
10686 int retcode
, fd
, remote_errno
, bytes
, io_size
;
10689 int bytes_in_buffer
;
10692 struct remote_state
*rs
= get_remote_state ();
10694 if (!rs
->remote_desc
)
10695 error (_("command can only be used with remote target"));
10697 file
= gdb_fopen_cloexec (local_file
, "rb");
10699 perror_with_name (local_file
);
10700 back_to
= make_cleanup_fclose (file
);
10702 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
10703 remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
10705 0700, &remote_errno
);
10707 remote_hostio_error (remote_errno
);
10709 /* Send up to this many bytes at once. They won't all fit in the
10710 remote packet limit, so we'll transfer slightly fewer. */
10711 io_size
= get_remote_packet_size ();
10712 buffer
= xmalloc (io_size
);
10713 make_cleanup (xfree
, buffer
);
10715 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10717 bytes_in_buffer
= 0;
10720 while (bytes_in_buffer
|| !saw_eof
)
10724 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
10725 io_size
- bytes_in_buffer
,
10730 error (_("Error reading %s."), local_file
);
10733 /* EOF. Unless there is something still in the
10734 buffer from the last iteration, we are done. */
10736 if (bytes_in_buffer
== 0)
10744 bytes
+= bytes_in_buffer
;
10745 bytes_in_buffer
= 0;
10747 retcode
= remote_hostio_pwrite (find_target_at (process_stratum
),
10749 offset
, &remote_errno
);
10752 remote_hostio_error (remote_errno
);
10753 else if (retcode
== 0)
10754 error (_("Remote write of %d bytes returned 0!"), bytes
);
10755 else if (retcode
< bytes
)
10757 /* Short write. Save the rest of the read data for the next
10759 bytes_in_buffer
= bytes
- retcode
;
10760 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
10766 discard_cleanups (close_cleanup
);
10767 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
10768 remote_hostio_error (remote_errno
);
10771 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
10772 do_cleanups (back_to
);
10776 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
10778 struct cleanup
*back_to
, *close_cleanup
;
10779 int fd
, remote_errno
, bytes
, io_size
;
10783 struct remote_state
*rs
= get_remote_state ();
10785 if (!rs
->remote_desc
)
10786 error (_("command can only be used with remote target"));
10788 fd
= remote_hostio_open (find_target_at (process_stratum
), NULL
,
10789 remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
10791 remote_hostio_error (remote_errno
);
10793 file
= gdb_fopen_cloexec (local_file
, "wb");
10795 perror_with_name (local_file
);
10796 back_to
= make_cleanup_fclose (file
);
10798 /* Send up to this many bytes at once. They won't all fit in the
10799 remote packet limit, so we'll transfer slightly fewer. */
10800 io_size
= get_remote_packet_size ();
10801 buffer
= xmalloc (io_size
);
10802 make_cleanup (xfree
, buffer
);
10804 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10809 bytes
= remote_hostio_pread (find_target_at (process_stratum
),
10810 fd
, buffer
, io_size
, offset
, &remote_errno
);
10812 /* Success, but no bytes, means end-of-file. */
10815 remote_hostio_error (remote_errno
);
10819 bytes
= fwrite (buffer
, 1, bytes
, file
);
10821 perror_with_name (local_file
);
10824 discard_cleanups (close_cleanup
);
10825 if (remote_hostio_close (find_target_at (process_stratum
), fd
, &remote_errno
))
10826 remote_hostio_error (remote_errno
);
10829 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
10830 do_cleanups (back_to
);
10834 remote_file_delete (const char *remote_file
, int from_tty
)
10836 int retcode
, remote_errno
;
10837 struct remote_state
*rs
= get_remote_state ();
10839 if (!rs
->remote_desc
)
10840 error (_("command can only be used with remote target"));
10842 retcode
= remote_hostio_unlink (find_target_at (process_stratum
),
10843 NULL
, remote_file
, &remote_errno
);
10845 remote_hostio_error (remote_errno
);
10848 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
10852 remote_put_command (char *args
, int from_tty
)
10854 struct cleanup
*back_to
;
10858 error_no_arg (_("file to put"));
10860 argv
= gdb_buildargv (args
);
10861 back_to
= make_cleanup_freeargv (argv
);
10862 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10863 error (_("Invalid parameters to remote put"));
10865 remote_file_put (argv
[0], argv
[1], from_tty
);
10867 do_cleanups (back_to
);
10871 remote_get_command (char *args
, int from_tty
)
10873 struct cleanup
*back_to
;
10877 error_no_arg (_("file to get"));
10879 argv
= gdb_buildargv (args
);
10880 back_to
= make_cleanup_freeargv (argv
);
10881 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10882 error (_("Invalid parameters to remote get"));
10884 remote_file_get (argv
[0], argv
[1], from_tty
);
10886 do_cleanups (back_to
);
10890 remote_delete_command (char *args
, int from_tty
)
10892 struct cleanup
*back_to
;
10896 error_no_arg (_("file to delete"));
10898 argv
= gdb_buildargv (args
);
10899 back_to
= make_cleanup_freeargv (argv
);
10900 if (argv
[0] == NULL
|| argv
[1] != NULL
)
10901 error (_("Invalid parameters to remote delete"));
10903 remote_file_delete (argv
[0], from_tty
);
10905 do_cleanups (back_to
);
10909 remote_command (char *args
, int from_tty
)
10911 help_list (remote_cmdlist
, "remote ", all_commands
, gdb_stdout
);
10915 remote_can_execute_reverse (struct target_ops
*self
)
10917 if (packet_support (PACKET_bs
) == PACKET_ENABLE
10918 || packet_support (PACKET_bc
) == PACKET_ENABLE
)
10925 remote_supports_non_stop (struct target_ops
*self
)
10931 remote_supports_disable_randomization (struct target_ops
*self
)
10933 /* Only supported in extended mode. */
10938 remote_supports_multi_process (struct target_ops
*self
)
10940 struct remote_state
*rs
= get_remote_state ();
10942 /* Only extended-remote handles being attached to multiple
10943 processes, even though plain remote can use the multi-process
10944 thread id extensions, so that GDB knows the target process's
10946 return rs
->extended
&& remote_multi_process_p (rs
);
10950 remote_supports_cond_tracepoints (void)
10952 return packet_support (PACKET_ConditionalTracepoints
) == PACKET_ENABLE
;
10956 remote_supports_cond_breakpoints (struct target_ops
*self
)
10958 return packet_support (PACKET_ConditionalBreakpoints
) == PACKET_ENABLE
;
10962 remote_supports_fast_tracepoints (void)
10964 return packet_support (PACKET_FastTracepoints
) == PACKET_ENABLE
;
10968 remote_supports_static_tracepoints (void)
10970 return packet_support (PACKET_StaticTracepoints
) == PACKET_ENABLE
;
10974 remote_supports_install_in_trace (void)
10976 return packet_support (PACKET_InstallInTrace
) == PACKET_ENABLE
;
10980 remote_supports_enable_disable_tracepoint (struct target_ops
*self
)
10982 return (packet_support (PACKET_EnableDisableTracepoints_feature
)
10987 remote_supports_string_tracing (struct target_ops
*self
)
10989 return packet_support (PACKET_tracenz_feature
) == PACKET_ENABLE
;
10993 remote_can_run_breakpoint_commands (struct target_ops
*self
)
10995 return packet_support (PACKET_BreakpointCommands
) == PACKET_ENABLE
;
10999 remote_trace_init (struct target_ops
*self
)
11002 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11003 if (strcmp (target_buf
, "OK") != 0)
11004 error (_("Target does not support this command."));
11007 static void free_actions_list (char **actions_list
);
11008 static void free_actions_list_cleanup_wrapper (void *);
11010 free_actions_list_cleanup_wrapper (void *al
)
11012 free_actions_list (al
);
11016 free_actions_list (char **actions_list
)
11020 if (actions_list
== 0)
11023 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
11024 xfree (actions_list
[ndx
]);
11026 xfree (actions_list
);
11029 /* Recursive routine to walk through command list including loops, and
11030 download packets for each command. */
11033 remote_download_command_source (int num
, ULONGEST addr
,
11034 struct command_line
*cmds
)
11036 struct remote_state
*rs
= get_remote_state ();
11037 struct command_line
*cmd
;
11039 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
11041 QUIT
; /* Allow user to bail out with ^C. */
11042 strcpy (rs
->buf
, "QTDPsrc:");
11043 encode_source_string (num
, addr
, "cmd", cmd
->line
,
11044 rs
->buf
+ strlen (rs
->buf
),
11045 rs
->buf_size
- strlen (rs
->buf
));
11047 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11048 if (strcmp (target_buf
, "OK"))
11049 warning (_("Target does not support source download."));
11051 if (cmd
->control_type
== while_control
11052 || cmd
->control_type
== while_stepping_control
)
11054 remote_download_command_source (num
, addr
, *cmd
->body_list
);
11056 QUIT
; /* Allow user to bail out with ^C. */
11057 strcpy (rs
->buf
, "QTDPsrc:");
11058 encode_source_string (num
, addr
, "cmd", "end",
11059 rs
->buf
+ strlen (rs
->buf
),
11060 rs
->buf_size
- strlen (rs
->buf
));
11062 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11063 if (strcmp (target_buf
, "OK"))
11064 warning (_("Target does not support source download."));
11070 remote_download_tracepoint (struct target_ops
*self
, struct bp_location
*loc
)
11072 #define BUF_SIZE 2048
11076 char buf
[BUF_SIZE
];
11077 char **tdp_actions
;
11078 char **stepping_actions
;
11080 struct cleanup
*old_chain
= NULL
;
11081 struct agent_expr
*aexpr
;
11082 struct cleanup
*aexpr_chain
= NULL
;
11084 struct breakpoint
*b
= loc
->owner
;
11085 struct tracepoint
*t
= (struct tracepoint
*) b
;
11087 encode_actions_rsp (loc
, &tdp_actions
, &stepping_actions
);
11088 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
11090 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
11093 tpaddr
= loc
->address
;
11094 sprintf_vma (addrbuf
, tpaddr
);
11095 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
11096 addrbuf
, /* address */
11097 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
11098 t
->step_count
, t
->pass_count
);
11099 /* Fast tracepoints are mostly handled by the target, but we can
11100 tell the target how big of an instruction block should be moved
11102 if (b
->type
== bp_fast_tracepoint
)
11104 /* Only test for support at download time; we may not know
11105 target capabilities at definition time. */
11106 if (remote_supports_fast_tracepoints ())
11108 if (gdbarch_fast_tracepoint_valid_at (loc
->gdbarch
, tpaddr
,
11110 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
11111 gdb_insn_length (loc
->gdbarch
, tpaddr
));
11113 /* If it passed validation at definition but fails now,
11114 something is very wrong. */
11115 internal_error (__FILE__
, __LINE__
,
11116 _("Fast tracepoint not "
11117 "valid during download"));
11120 /* Fast tracepoints are functionally identical to regular
11121 tracepoints, so don't take lack of support as a reason to
11122 give up on the trace run. */
11123 warning (_("Target does not support fast tracepoints, "
11124 "downloading %d as regular tracepoint"), b
->number
);
11126 else if (b
->type
== bp_static_tracepoint
)
11128 /* Only test for support at download time; we may not know
11129 target capabilities at definition time. */
11130 if (remote_supports_static_tracepoints ())
11132 struct static_tracepoint_marker marker
;
11134 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
11135 strcat (buf
, ":S");
11137 error (_("Static tracepoint not valid during download"));
11140 /* Fast tracepoints are functionally identical to regular
11141 tracepoints, so don't take lack of support as a reason
11142 to give up on the trace run. */
11143 error (_("Target does not support static tracepoints"));
11145 /* If the tracepoint has a conditional, make it into an agent
11146 expression and append to the definition. */
11149 /* Only test support at download time, we may not know target
11150 capabilities at definition time. */
11151 if (remote_supports_cond_tracepoints ())
11153 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
11154 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
11155 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
11157 pkt
= buf
+ strlen (buf
);
11158 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
11159 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
11161 do_cleanups (aexpr_chain
);
11164 warning (_("Target does not support conditional tracepoints, "
11165 "ignoring tp %d cond"), b
->number
);
11168 if (b
->commands
|| *default_collect
)
11171 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11172 if (strcmp (target_buf
, "OK"))
11173 error (_("Target does not support tracepoints."));
11175 /* do_single_steps (t); */
11178 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
11180 QUIT
; /* Allow user to bail out with ^C. */
11181 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
11182 b
->number
, addrbuf
, /* address */
11184 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
11187 remote_get_noisy_reply (&target_buf
,
11189 if (strcmp (target_buf
, "OK"))
11190 error (_("Error on target while setting tracepoints."));
11193 if (stepping_actions
)
11195 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
11197 QUIT
; /* Allow user to bail out with ^C. */
11198 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
11199 b
->number
, addrbuf
, /* address */
11200 ((ndx
== 0) ? "S" : ""),
11201 stepping_actions
[ndx
],
11202 (stepping_actions
[ndx
+ 1] ? "-" : ""));
11204 remote_get_noisy_reply (&target_buf
,
11206 if (strcmp (target_buf
, "OK"))
11207 error (_("Error on target while setting tracepoints."));
11211 if (packet_support (PACKET_TracepointSource
) == PACKET_ENABLE
)
11213 if (b
->addr_string
)
11215 strcpy (buf
, "QTDPsrc:");
11216 encode_source_string (b
->number
, loc
->address
,
11217 "at", b
->addr_string
, buf
+ strlen (buf
),
11218 2048 - strlen (buf
));
11221 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11222 if (strcmp (target_buf
, "OK"))
11223 warning (_("Target does not support source download."));
11225 if (b
->cond_string
)
11227 strcpy (buf
, "QTDPsrc:");
11228 encode_source_string (b
->number
, loc
->address
,
11229 "cond", b
->cond_string
, buf
+ strlen (buf
),
11230 2048 - strlen (buf
));
11232 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11233 if (strcmp (target_buf
, "OK"))
11234 warning (_("Target does not support source download."));
11236 remote_download_command_source (b
->number
, loc
->address
,
11237 breakpoint_commands (b
));
11240 do_cleanups (old_chain
);
11244 remote_can_download_tracepoint (struct target_ops
*self
)
11246 struct remote_state
*rs
= get_remote_state ();
11247 struct trace_status
*ts
;
11250 /* Don't try to install tracepoints until we've relocated our
11251 symbols, and fetched and merged the target's tracepoint list with
11253 if (rs
->starting_up
)
11256 ts
= current_trace_status ();
11257 status
= remote_get_trace_status (self
, ts
);
11259 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
11262 /* If we are in a tracing experiment, but remote stub doesn't support
11263 installing tracepoint in trace, we have to return. */
11264 if (!remote_supports_install_in_trace ())
11272 remote_download_trace_state_variable (struct target_ops
*self
,
11273 struct trace_state_variable
*tsv
)
11275 struct remote_state
*rs
= get_remote_state ();
11278 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
11279 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
11281 p
= rs
->buf
+ strlen (rs
->buf
);
11282 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
11283 error (_("Trace state variable name too long for tsv definition packet"));
11284 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, strlen (tsv
->name
));
11287 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11288 if (*target_buf
== '\0')
11289 error (_("Target does not support this command."));
11290 if (strcmp (target_buf
, "OK") != 0)
11291 error (_("Error on target while downloading trace state variable."));
11295 remote_enable_tracepoint (struct target_ops
*self
,
11296 struct bp_location
*location
)
11298 struct remote_state
*rs
= get_remote_state ();
11301 sprintf_vma (addr_buf
, location
->address
);
11302 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
11303 location
->owner
->number
, addr_buf
);
11305 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11306 if (*rs
->buf
== '\0')
11307 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
11308 if (strcmp (rs
->buf
, "OK") != 0)
11309 error (_("Error on target while enabling tracepoint."));
11313 remote_disable_tracepoint (struct target_ops
*self
,
11314 struct bp_location
*location
)
11316 struct remote_state
*rs
= get_remote_state ();
11319 sprintf_vma (addr_buf
, location
->address
);
11320 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
11321 location
->owner
->number
, addr_buf
);
11323 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11324 if (*rs
->buf
== '\0')
11325 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
11326 if (strcmp (rs
->buf
, "OK") != 0)
11327 error (_("Error on target while disabling tracepoint."));
11331 remote_trace_set_readonly_regions (struct target_ops
*self
)
11335 bfd_size_type size
;
11341 return; /* No information to give. */
11343 strcpy (target_buf
, "QTro");
11344 offset
= strlen (target_buf
);
11345 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
11347 char tmp1
[40], tmp2
[40];
11350 if ((s
->flags
& SEC_LOAD
) == 0 ||
11351 /* (s->flags & SEC_CODE) == 0 || */
11352 (s
->flags
& SEC_READONLY
) == 0)
11356 vma
= bfd_get_section_vma (abfd
, s
);
11357 size
= bfd_get_section_size (s
);
11358 sprintf_vma (tmp1
, vma
);
11359 sprintf_vma (tmp2
, vma
+ size
);
11360 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
11361 if (offset
+ sec_length
+ 1 > target_buf_size
)
11363 if (packet_support (PACKET_qXfer_traceframe_info
) != PACKET_ENABLE
)
11365 Too many sections for read-only sections definition packet."));
11368 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
11370 offset
+= sec_length
;
11374 putpkt (target_buf
);
11375 getpkt (&target_buf
, &target_buf_size
, 0);
11380 remote_trace_start (struct target_ops
*self
)
11382 putpkt ("QTStart");
11383 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11384 if (*target_buf
== '\0')
11385 error (_("Target does not support this command."));
11386 if (strcmp (target_buf
, "OK") != 0)
11387 error (_("Bogus reply from target: %s"), target_buf
);
11391 remote_get_trace_status (struct target_ops
*self
, struct trace_status
*ts
)
11393 /* Initialize it just to avoid a GCC false warning. */
11395 /* FIXME we need to get register block size some other way. */
11396 extern int trace_regblock_size
;
11397 enum packet_result result
;
11399 if (packet_support (PACKET_qTStatus
) == PACKET_DISABLE
)
11402 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
11404 putpkt ("qTStatus");
11408 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11410 CATCH (ex
, RETURN_MASK_ERROR
)
11412 if (ex
.error
!= TARGET_CLOSE_ERROR
)
11414 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
11417 throw_exception (ex
);
11421 result
= packet_ok (p
, &remote_protocol_packets
[PACKET_qTStatus
]);
11423 /* If the remote target doesn't do tracing, flag it. */
11424 if (result
== PACKET_UNKNOWN
)
11427 /* We're working with a live target. */
11428 ts
->filename
= NULL
;
11431 error (_("Bogus trace status reply from target: %s"), target_buf
);
11433 /* Function 'parse_trace_status' sets default value of each field of
11434 'ts' at first, so we don't have to do it here. */
11435 parse_trace_status (p
, ts
);
11437 return ts
->running
;
11441 remote_get_tracepoint_status (struct target_ops
*self
, struct breakpoint
*bp
,
11442 struct uploaded_tp
*utp
)
11444 struct remote_state
*rs
= get_remote_state ();
11446 struct bp_location
*loc
;
11447 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
11448 size_t size
= get_remote_packet_size ();
11452 tp
->base
.hit_count
= 0;
11453 tp
->traceframe_usage
= 0;
11454 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
11456 /* If the tracepoint was never downloaded, don't go asking for
11458 if (tp
->number_on_target
== 0)
11460 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
11461 phex_nz (loc
->address
, 0));
11463 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11464 if (reply
&& *reply
)
11467 parse_tracepoint_status (reply
+ 1, bp
, utp
);
11473 utp
->hit_count
= 0;
11474 utp
->traceframe_usage
= 0;
11475 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
11476 phex_nz (utp
->addr
, 0));
11478 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11479 if (reply
&& *reply
)
11482 parse_tracepoint_status (reply
+ 1, bp
, utp
);
11488 remote_trace_stop (struct target_ops
*self
)
11491 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11492 if (*target_buf
== '\0')
11493 error (_("Target does not support this command."));
11494 if (strcmp (target_buf
, "OK") != 0)
11495 error (_("Bogus reply from target: %s"), target_buf
);
11499 remote_trace_find (struct target_ops
*self
,
11500 enum trace_find_type type
, int num
,
11501 CORE_ADDR addr1
, CORE_ADDR addr2
,
11504 struct remote_state
*rs
= get_remote_state ();
11505 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11507 int target_frameno
= -1, target_tracept
= -1;
11509 /* Lookups other than by absolute frame number depend on the current
11510 trace selected, so make sure it is correct on the remote end
11512 if (type
!= tfind_number
)
11513 set_remote_traceframe ();
11516 strcpy (p
, "QTFrame:");
11517 p
= strchr (p
, '\0');
11521 xsnprintf (p
, endbuf
- p
, "%x", num
);
11524 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
11527 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
11530 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
11531 phex_nz (addr2
, 0));
11533 case tfind_outside
:
11534 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
11535 phex_nz (addr2
, 0));
11538 error (_("Unknown trace find type %d"), type
);
11542 reply
= remote_get_noisy_reply (&(rs
->buf
), &rs
->buf_size
);
11543 if (*reply
== '\0')
11544 error (_("Target does not support this command."));
11546 while (reply
&& *reply
)
11551 target_frameno
= (int) strtol (p
, &reply
, 16);
11553 error (_("Unable to parse trace frame number"));
11554 /* Don't update our remote traceframe number cache on failure
11555 to select a remote traceframe. */
11556 if (target_frameno
== -1)
11561 target_tracept
= (int) strtol (p
, &reply
, 16);
11563 error (_("Unable to parse tracepoint number"));
11565 case 'O': /* "OK"? */
11566 if (reply
[1] == 'K' && reply
[2] == '\0')
11569 error (_("Bogus reply from target: %s"), reply
);
11572 error (_("Bogus reply from target: %s"), reply
);
11575 *tpp
= target_tracept
;
11577 rs
->remote_traceframe_number
= target_frameno
;
11578 return target_frameno
;
11582 remote_get_trace_state_variable_value (struct target_ops
*self
,
11583 int tsvnum
, LONGEST
*val
)
11585 struct remote_state
*rs
= get_remote_state ();
11589 set_remote_traceframe ();
11591 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
11593 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11594 if (reply
&& *reply
)
11598 unpack_varlen_hex (reply
+ 1, &uval
);
11599 *val
= (LONGEST
) uval
;
11607 remote_save_trace_data (struct target_ops
*self
, const char *filename
)
11609 struct remote_state
*rs
= get_remote_state ();
11613 strcpy (p
, "QTSave:");
11615 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
11616 error (_("Remote file name too long for trace save packet"));
11617 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, strlen (filename
));
11620 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11621 if (*reply
== '\0')
11622 error (_("Target does not support this command."));
11623 if (strcmp (reply
, "OK") != 0)
11624 error (_("Bogus reply from target: %s"), reply
);
11628 /* This is basically a memory transfer, but needs to be its own packet
11629 because we don't know how the target actually organizes its trace
11630 memory, plus we want to be able to ask for as much as possible, but
11631 not be unhappy if we don't get as much as we ask for. */
11634 remote_get_raw_trace_data (struct target_ops
*self
,
11635 gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
11637 struct remote_state
*rs
= get_remote_state ();
11643 strcpy (p
, "qTBuffer:");
11645 p
+= hexnumstr (p
, offset
);
11647 p
+= hexnumstr (p
, len
);
11651 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11652 if (reply
&& *reply
)
11654 /* 'l' by itself means we're at the end of the buffer and
11655 there is nothing more to get. */
11659 /* Convert the reply into binary. Limit the number of bytes to
11660 convert according to our passed-in buffer size, rather than
11661 what was returned in the packet; if the target is
11662 unexpectedly generous and gives us a bigger reply than we
11663 asked for, we don't want to crash. */
11664 rslt
= hex2bin (target_buf
, buf
, len
);
11668 /* Something went wrong, flag as an error. */
11673 remote_set_disconnected_tracing (struct target_ops
*self
, int val
)
11675 struct remote_state
*rs
= get_remote_state ();
11677 if (packet_support (PACKET_DisconnectedTracing_feature
) == PACKET_ENABLE
)
11681 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
11683 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11684 if (*reply
== '\0')
11685 error (_("Target does not support this command."));
11686 if (strcmp (reply
, "OK") != 0)
11687 error (_("Bogus reply from target: %s"), reply
);
11690 warning (_("Target does not support disconnected tracing."));
11694 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
11696 struct thread_info
*info
= find_thread_ptid (ptid
);
11698 if (info
&& info
->priv
)
11699 return info
->priv
->core
;
11704 remote_set_circular_trace_buffer (struct target_ops
*self
, int val
)
11706 struct remote_state
*rs
= get_remote_state ();
11709 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
11711 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11712 if (*reply
== '\0')
11713 error (_("Target does not support this command."));
11714 if (strcmp (reply
, "OK") != 0)
11715 error (_("Bogus reply from target: %s"), reply
);
11718 static struct traceframe_info
*
11719 remote_traceframe_info (struct target_ops
*self
)
11723 text
= target_read_stralloc (¤t_target
,
11724 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
11727 struct traceframe_info
*info
;
11728 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
11730 info
= parse_traceframe_info (text
);
11731 do_cleanups (back_to
);
11738 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11739 instruction on which a fast tracepoint may be placed. Returns -1
11740 if the packet is not supported, and 0 if the minimum instruction
11741 length is unknown. */
11744 remote_get_min_fast_tracepoint_insn_len (struct target_ops
*self
)
11746 struct remote_state
*rs
= get_remote_state ();
11749 /* If we're not debugging a process yet, the IPA can't be
11751 if (!target_has_execution
)
11754 /* Make sure the remote is pointing at the right process. */
11755 set_general_process ();
11757 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
11759 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11760 if (*reply
== '\0')
11764 ULONGEST min_insn_len
;
11766 unpack_varlen_hex (reply
, &min_insn_len
);
11768 return (int) min_insn_len
;
11773 remote_set_trace_buffer_size (struct target_ops
*self
, LONGEST val
)
11775 if (packet_support (PACKET_QTBuffer_size
) != PACKET_DISABLE
)
11777 struct remote_state
*rs
= get_remote_state ();
11778 char *buf
= rs
->buf
;
11779 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11780 enum packet_result result
;
11782 gdb_assert (val
>= 0 || val
== -1);
11783 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTBuffer:size:");
11784 /* Send -1 as literal "-1" to avoid host size dependency. */
11788 buf
+= hexnumstr (buf
, (ULONGEST
) -val
);
11791 buf
+= hexnumstr (buf
, (ULONGEST
) val
);
11794 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
11795 result
= packet_ok (rs
->buf
,
11796 &remote_protocol_packets
[PACKET_QTBuffer_size
]);
11798 if (result
!= PACKET_OK
)
11799 warning (_("Bogus reply from target: %s"), rs
->buf
);
11804 remote_set_trace_notes (struct target_ops
*self
,
11805 const char *user
, const char *notes
,
11806 const char *stop_notes
)
11808 struct remote_state
*rs
= get_remote_state ();
11810 char *buf
= rs
->buf
;
11811 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11814 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
11817 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
11818 nbytes
= bin2hex ((gdb_byte
*) user
, buf
, strlen (user
));
11824 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
11825 nbytes
= bin2hex ((gdb_byte
*) notes
, buf
, strlen (notes
));
11831 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
11832 nbytes
= bin2hex ((gdb_byte
*) stop_notes
, buf
, strlen (stop_notes
));
11836 /* Ensure the buffer is terminated. */
11840 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11841 if (*reply
== '\0')
11844 if (strcmp (reply
, "OK") != 0)
11845 error (_("Bogus reply from target: %s"), reply
);
11851 remote_use_agent (struct target_ops
*self
, int use
)
11853 if (packet_support (PACKET_QAgent
) != PACKET_DISABLE
)
11855 struct remote_state
*rs
= get_remote_state ();
11857 /* If the stub supports QAgent. */
11858 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
11860 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11862 if (strcmp (rs
->buf
, "OK") == 0)
11873 remote_can_use_agent (struct target_ops
*self
)
11875 return (packet_support (PACKET_QAgent
) != PACKET_DISABLE
);
11878 struct btrace_target_info
11880 /* The ptid of the traced thread. */
11883 /* The obtained branch trace configuration. */
11884 struct btrace_config conf
;
11887 /* Reset our idea of our target's btrace configuration. */
11890 remote_btrace_reset (void)
11892 struct remote_state
*rs
= get_remote_state ();
11894 memset (&rs
->btrace_config
, 0, sizeof (rs
->btrace_config
));
11897 /* Check whether the target supports branch tracing. */
11900 remote_supports_btrace (struct target_ops
*self
, enum btrace_format format
)
11902 if (packet_support (PACKET_Qbtrace_off
) != PACKET_ENABLE
)
11904 if (packet_support (PACKET_qXfer_btrace
) != PACKET_ENABLE
)
11909 case BTRACE_FORMAT_NONE
:
11912 case BTRACE_FORMAT_BTS
:
11913 return (packet_support (PACKET_Qbtrace_bts
) == PACKET_ENABLE
);
11915 case BTRACE_FORMAT_PT
:
11916 /* The trace is decoded on the host. Even if our target supports it,
11917 we still need to have libipt to decode the trace. */
11918 #if defined (HAVE_LIBIPT)
11919 return (packet_support (PACKET_Qbtrace_pt
) == PACKET_ENABLE
);
11920 #else /* !defined (HAVE_LIBIPT) */
11922 #endif /* !defined (HAVE_LIBIPT) */
11925 internal_error (__FILE__
, __LINE__
, _("Unknown branch trace format"));
11928 /* Synchronize the configuration with the target. */
11931 btrace_sync_conf (const struct btrace_config
*conf
)
11933 struct packet_config
*packet
;
11934 struct remote_state
*rs
;
11935 char *buf
, *pos
, *endbuf
;
11937 rs
= get_remote_state ();
11939 endbuf
= buf
+ get_remote_packet_size ();
11941 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
];
11942 if (packet_config_support (packet
) == PACKET_ENABLE
11943 && conf
->bts
.size
!= rs
->btrace_config
.bts
.size
)
11946 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
11950 getpkt (&buf
, &rs
->buf_size
, 0);
11952 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
11954 if (buf
[0] == 'E' && buf
[1] == '.')
11955 error (_("Failed to configure the BTS buffer size: %s"), buf
+ 2);
11957 error (_("Failed to configure the BTS buffer size."));
11960 rs
->btrace_config
.bts
.size
= conf
->bts
.size
;
11963 packet
= &remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
];
11964 if (packet_config_support (packet
) == PACKET_ENABLE
11965 && conf
->pt
.size
!= rs
->btrace_config
.pt
.size
)
11968 pos
+= xsnprintf (pos
, endbuf
- pos
, "%s=0x%x", packet
->name
,
11972 getpkt (&buf
, &rs
->buf_size
, 0);
11974 if (packet_ok (buf
, packet
) == PACKET_ERROR
)
11976 if (buf
[0] == 'E' && buf
[1] == '.')
11977 error (_("Failed to configure the trace buffer size: %s"), buf
+ 2);
11979 error (_("Failed to configure the trace buffer size."));
11982 rs
->btrace_config
.pt
.size
= conf
->pt
.size
;
11986 /* Read the current thread's btrace configuration from the target and
11987 store it into CONF. */
11990 btrace_read_config (struct btrace_config
*conf
)
11994 xml
= target_read_stralloc (¤t_target
,
11995 TARGET_OBJECT_BTRACE_CONF
, "");
11998 struct cleanup
*cleanup
;
12000 cleanup
= make_cleanup (xfree
, xml
);
12001 parse_xml_btrace_conf (conf
, xml
);
12002 do_cleanups (cleanup
);
12006 /* Enable branch tracing. */
12008 static struct btrace_target_info
*
12009 remote_enable_btrace (struct target_ops
*self
, ptid_t ptid
,
12010 const struct btrace_config
*conf
)
12012 struct btrace_target_info
*tinfo
= NULL
;
12013 struct packet_config
*packet
= NULL
;
12014 struct remote_state
*rs
= get_remote_state ();
12015 char *buf
= rs
->buf
;
12016 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12018 switch (conf
->format
)
12020 case BTRACE_FORMAT_BTS
:
12021 packet
= &remote_protocol_packets
[PACKET_Qbtrace_bts
];
12024 case BTRACE_FORMAT_PT
:
12025 packet
= &remote_protocol_packets
[PACKET_Qbtrace_pt
];
12029 if (packet
== NULL
|| packet_config_support (packet
) != PACKET_ENABLE
)
12030 error (_("Target does not support branch tracing."));
12032 btrace_sync_conf (conf
);
12034 set_general_thread (ptid
);
12036 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12038 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12040 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12042 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12043 error (_("Could not enable branch tracing for %s: %s"),
12044 target_pid_to_str (ptid
), rs
->buf
+ 2);
12046 error (_("Could not enable branch tracing for %s."),
12047 target_pid_to_str (ptid
));
12050 tinfo
= xzalloc (sizeof (*tinfo
));
12051 tinfo
->ptid
= ptid
;
12053 /* If we fail to read the configuration, we lose some information, but the
12054 tracing itself is not impacted. */
12057 btrace_read_config (&tinfo
->conf
);
12059 CATCH (err
, RETURN_MASK_ERROR
)
12061 if (err
.message
!= NULL
)
12062 warning ("%s", err
.message
);
12069 /* Disable branch tracing. */
12072 remote_disable_btrace (struct target_ops
*self
,
12073 struct btrace_target_info
*tinfo
)
12075 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_Qbtrace_off
];
12076 struct remote_state
*rs
= get_remote_state ();
12077 char *buf
= rs
->buf
;
12078 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
12080 if (packet_config_support (packet
) != PACKET_ENABLE
)
12081 error (_("Target does not support branch tracing."));
12083 set_general_thread (tinfo
->ptid
);
12085 buf
+= xsnprintf (buf
, endbuf
- buf
, "%s", packet
->name
);
12087 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12089 if (packet_ok (rs
->buf
, packet
) == PACKET_ERROR
)
12091 if (rs
->buf
[0] == 'E' && rs
->buf
[1] == '.')
12092 error (_("Could not disable branch tracing for %s: %s"),
12093 target_pid_to_str (tinfo
->ptid
), rs
->buf
+ 2);
12095 error (_("Could not disable branch tracing for %s."),
12096 target_pid_to_str (tinfo
->ptid
));
12102 /* Teardown branch tracing. */
12105 remote_teardown_btrace (struct target_ops
*self
,
12106 struct btrace_target_info
*tinfo
)
12108 /* We must not talk to the target during teardown. */
12112 /* Read the branch trace. */
12114 static enum btrace_error
12115 remote_read_btrace (struct target_ops
*self
,
12116 struct btrace_data
*btrace
,
12117 struct btrace_target_info
*tinfo
,
12118 enum btrace_read_type type
)
12120 struct packet_config
*packet
= &remote_protocol_packets
[PACKET_qXfer_btrace
];
12121 struct remote_state
*rs
= get_remote_state ();
12122 struct cleanup
*cleanup
;
12126 if (packet_config_support (packet
) != PACKET_ENABLE
)
12127 error (_("Target does not support branch tracing."));
12129 #if !defined(HAVE_LIBEXPAT)
12130 error (_("Cannot process branch tracing result. XML parsing not supported."));
12135 case BTRACE_READ_ALL
:
12138 case BTRACE_READ_NEW
:
12141 case BTRACE_READ_DELTA
:
12145 internal_error (__FILE__
, __LINE__
,
12146 _("Bad branch tracing read type: %u."),
12147 (unsigned int) type
);
12150 xml
= target_read_stralloc (¤t_target
,
12151 TARGET_OBJECT_BTRACE
, annex
);
12153 return BTRACE_ERR_UNKNOWN
;
12155 cleanup
= make_cleanup (xfree
, xml
);
12156 parse_xml_btrace (btrace
, xml
);
12157 do_cleanups (cleanup
);
12159 return BTRACE_ERR_NONE
;
12162 static const struct btrace_config
*
12163 remote_btrace_conf (struct target_ops
*self
,
12164 const struct btrace_target_info
*tinfo
)
12166 return &tinfo
->conf
;
12170 remote_augmented_libraries_svr4_read (struct target_ops
*self
)
12172 return (packet_support (PACKET_augmented_libraries_svr4_read_feature
)
12176 /* Implementation of to_load. */
12179 remote_load (struct target_ops
*self
, const char *name
, int from_tty
)
12181 generic_load (name
, from_tty
);
12184 /* Accepts an integer PID; returns a string representing a file that
12185 can be opened on the remote side to get the symbols for the child
12186 process. Returns NULL if the operation is not supported. */
12189 remote_pid_to_exec_file (struct target_ops
*self
, int pid
)
12191 static char *filename
= NULL
;
12192 struct inferior
*inf
;
12193 char *annex
= NULL
;
12195 if (packet_support (PACKET_qXfer_exec_file
) != PACKET_ENABLE
)
12198 if (filename
!= NULL
)
12201 inf
= find_inferior_pid (pid
);
12203 internal_error (__FILE__
, __LINE__
,
12204 _("not currently attached to process %d"), pid
);
12206 if (!inf
->fake_pid_p
)
12208 const int annex_size
= 9;
12210 annex
= alloca (annex_size
);
12211 xsnprintf (annex
, annex_size
, "%x", pid
);
12214 filename
= target_read_stralloc (¤t_target
,
12215 TARGET_OBJECT_EXEC_FILE
, annex
);
12221 init_remote_ops (void)
12223 remote_ops
.to_shortname
= "remote";
12224 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
12225 remote_ops
.to_doc
=
12226 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
12227 Specify the serial device it is connected to\n\
12228 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
12229 remote_ops
.to_open
= remote_open
;
12230 remote_ops
.to_close
= remote_close
;
12231 remote_ops
.to_detach
= remote_detach
;
12232 remote_ops
.to_disconnect
= remote_disconnect
;
12233 remote_ops
.to_resume
= remote_resume
;
12234 remote_ops
.to_wait
= remote_wait
;
12235 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
12236 remote_ops
.to_store_registers
= remote_store_registers
;
12237 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
12238 remote_ops
.to_files_info
= remote_files_info
;
12239 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
12240 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
12241 remote_ops
.to_stopped_by_sw_breakpoint
= remote_stopped_by_sw_breakpoint
;
12242 remote_ops
.to_supports_stopped_by_sw_breakpoint
= remote_supports_stopped_by_sw_breakpoint
;
12243 remote_ops
.to_stopped_by_hw_breakpoint
= remote_stopped_by_hw_breakpoint
;
12244 remote_ops
.to_supports_stopped_by_hw_breakpoint
= remote_supports_stopped_by_hw_breakpoint
;
12245 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
12246 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
12247 remote_ops
.to_watchpoint_addr_within_range
=
12248 remote_watchpoint_addr_within_range
;
12249 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
12250 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
12251 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
12252 remote_ops
.to_region_ok_for_hw_watchpoint
12253 = remote_region_ok_for_hw_watchpoint
;
12254 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
12255 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
12256 remote_ops
.to_kill
= remote_kill
;
12257 remote_ops
.to_load
= remote_load
;
12258 remote_ops
.to_mourn_inferior
= remote_mourn
;
12259 remote_ops
.to_pass_signals
= remote_pass_signals
;
12260 remote_ops
.to_program_signals
= remote_program_signals
;
12261 remote_ops
.to_thread_alive
= remote_thread_alive
;
12262 remote_ops
.to_update_thread_list
= remote_update_thread_list
;
12263 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
12264 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
12265 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
12266 remote_ops
.to_stop
= remote_stop
;
12267 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
12268 remote_ops
.to_rcmd
= remote_rcmd
;
12269 remote_ops
.to_pid_to_exec_file
= remote_pid_to_exec_file
;
12270 remote_ops
.to_log_command
= serial_log_command
;
12271 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
12272 remote_ops
.to_stratum
= process_stratum
;
12273 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
12274 remote_ops
.to_has_memory
= default_child_has_memory
;
12275 remote_ops
.to_has_stack
= default_child_has_stack
;
12276 remote_ops
.to_has_registers
= default_child_has_registers
;
12277 remote_ops
.to_has_execution
= default_child_has_execution
;
12278 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
12279 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
12280 remote_ops
.to_magic
= OPS_MAGIC
;
12281 remote_ops
.to_memory_map
= remote_memory_map
;
12282 remote_ops
.to_flash_erase
= remote_flash_erase
;
12283 remote_ops
.to_flash_done
= remote_flash_done
;
12284 remote_ops
.to_read_description
= remote_read_description
;
12285 remote_ops
.to_search_memory
= remote_search_memory
;
12286 remote_ops
.to_can_async_p
= remote_can_async_p
;
12287 remote_ops
.to_is_async_p
= remote_is_async_p
;
12288 remote_ops
.to_async
= remote_async
;
12289 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
12290 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
12291 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
12292 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
12293 remote_ops
.to_supports_disable_randomization
12294 = remote_supports_disable_randomization
;
12295 remote_ops
.to_filesystem_is_local
= remote_filesystem_is_local
;
12296 remote_ops
.to_fileio_open
= remote_hostio_open
;
12297 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
12298 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
12299 remote_ops
.to_fileio_fstat
= remote_hostio_fstat
;
12300 remote_ops
.to_fileio_close
= remote_hostio_close
;
12301 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
12302 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
12303 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
12304 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
12305 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
12306 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
12307 remote_ops
.to_trace_init
= remote_trace_init
;
12308 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
12309 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
12310 remote_ops
.to_download_trace_state_variable
12311 = remote_download_trace_state_variable
;
12312 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
12313 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
12314 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
12315 remote_ops
.to_trace_start
= remote_trace_start
;
12316 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
12317 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
12318 remote_ops
.to_trace_stop
= remote_trace_stop
;
12319 remote_ops
.to_trace_find
= remote_trace_find
;
12320 remote_ops
.to_get_trace_state_variable_value
12321 = remote_get_trace_state_variable_value
;
12322 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
12323 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
12324 remote_ops
.to_upload_trace_state_variables
12325 = remote_upload_trace_state_variables
;
12326 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
12327 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
12328 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
12329 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
12330 remote_ops
.to_set_trace_buffer_size
= remote_set_trace_buffer_size
;
12331 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
12332 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
12333 remote_ops
.to_verify_memory
= remote_verify_memory
;
12334 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
12335 remote_ops
.to_set_permissions
= remote_set_permissions
;
12336 remote_ops
.to_static_tracepoint_marker_at
12337 = remote_static_tracepoint_marker_at
;
12338 remote_ops
.to_static_tracepoint_markers_by_strid
12339 = remote_static_tracepoint_markers_by_strid
;
12340 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
12341 remote_ops
.to_use_agent
= remote_use_agent
;
12342 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
12343 remote_ops
.to_supports_btrace
= remote_supports_btrace
;
12344 remote_ops
.to_enable_btrace
= remote_enable_btrace
;
12345 remote_ops
.to_disable_btrace
= remote_disable_btrace
;
12346 remote_ops
.to_teardown_btrace
= remote_teardown_btrace
;
12347 remote_ops
.to_read_btrace
= remote_read_btrace
;
12348 remote_ops
.to_btrace_conf
= remote_btrace_conf
;
12349 remote_ops
.to_augmented_libraries_svr4_read
=
12350 remote_augmented_libraries_svr4_read
;
12353 /* Set up the extended remote vector by making a copy of the standard
12354 remote vector and adding to it. */
12357 init_extended_remote_ops (void)
12359 extended_remote_ops
= remote_ops
;
12361 extended_remote_ops
.to_shortname
= "extended-remote";
12362 extended_remote_ops
.to_longname
=
12363 "Extended remote serial target in gdb-specific protocol";
12364 extended_remote_ops
.to_doc
=
12365 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
12366 Specify the serial device it is connected to (e.g. /dev/ttya).";
12367 extended_remote_ops
.to_open
= extended_remote_open
;
12368 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
12369 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
12370 extended_remote_ops
.to_detach
= extended_remote_detach
;
12371 extended_remote_ops
.to_attach
= extended_remote_attach
;
12372 extended_remote_ops
.to_post_attach
= extended_remote_post_attach
;
12373 extended_remote_ops
.to_kill
= extended_remote_kill
;
12374 extended_remote_ops
.to_supports_disable_randomization
12375 = extended_remote_supports_disable_randomization
;
12376 extended_remote_ops
.to_follow_fork
= remote_follow_fork
;
12377 extended_remote_ops
.to_insert_fork_catchpoint
12378 = remote_insert_fork_catchpoint
;
12379 extended_remote_ops
.to_remove_fork_catchpoint
12380 = remote_remove_fork_catchpoint
;
12381 extended_remote_ops
.to_insert_vfork_catchpoint
12382 = remote_insert_vfork_catchpoint
;
12383 extended_remote_ops
.to_remove_vfork_catchpoint
12384 = remote_remove_vfork_catchpoint
;
12388 remote_can_async_p (struct target_ops
*ops
)
12390 struct remote_state
*rs
= get_remote_state ();
12392 if (!target_async_permitted
)
12393 /* We only enable async when the user specifically asks for it. */
12396 /* We're async whenever the serial device is. */
12397 return serial_can_async_p (rs
->remote_desc
);
12401 remote_is_async_p (struct target_ops
*ops
)
12403 struct remote_state
*rs
= get_remote_state ();
12405 if (!target_async_permitted
)
12406 /* We only enable async when the user specifically asks for it. */
12409 /* We're async whenever the serial device is. */
12410 return serial_is_async_p (rs
->remote_desc
);
12413 /* Pass the SERIAL event on and up to the client. One day this code
12414 will be able to delay notifying the client of an event until the
12415 point where an entire packet has been received. */
12417 static serial_event_ftype remote_async_serial_handler
;
12420 remote_async_serial_handler (struct serial
*scb
, void *context
)
12422 struct remote_state
*rs
= context
;
12424 /* Don't propogate error information up to the client. Instead let
12425 the client find out about the error by querying the target. */
12426 inferior_event_handler (INF_REG_EVENT
, NULL
);
12430 remote_async_inferior_event_handler (gdb_client_data data
)
12432 inferior_event_handler (INF_REG_EVENT
, NULL
);
12436 remote_async (struct target_ops
*ops
, int enable
)
12438 struct remote_state
*rs
= get_remote_state ();
12442 serial_async (rs
->remote_desc
, remote_async_serial_handler
, rs
);
12444 /* If there are pending events in the stop reply queue tell the
12445 event loop to process them. */
12446 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
12447 mark_async_event_handler (remote_async_inferior_event_token
);
12451 serial_async (rs
->remote_desc
, NULL
, NULL
);
12452 clear_async_event_handler (remote_async_inferior_event_token
);
12457 set_remote_cmd (char *args
, int from_tty
)
12459 help_list (remote_set_cmdlist
, "set remote ", all_commands
, gdb_stdout
);
12463 show_remote_cmd (char *args
, int from_tty
)
12465 /* We can't just use cmd_show_list here, because we want to skip
12466 the redundant "show remote Z-packet" and the legacy aliases. */
12467 struct cleanup
*showlist_chain
;
12468 struct cmd_list_element
*list
= remote_show_cmdlist
;
12469 struct ui_out
*uiout
= current_uiout
;
12471 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
12472 for (; list
!= NULL
; list
= list
->next
)
12473 if (strcmp (list
->name
, "Z-packet") == 0)
12475 else if (list
->type
== not_set_cmd
)
12476 /* Alias commands are exactly like the original, except they
12477 don't have the normal type. */
12481 struct cleanup
*option_chain
12482 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
12484 ui_out_field_string (uiout
, "name", list
->name
);
12485 ui_out_text (uiout
, ": ");
12486 if (list
->type
== show_cmd
)
12487 do_show_command ((char *) NULL
, from_tty
, list
);
12489 cmd_func (list
, NULL
, from_tty
);
12490 /* Close the tuple. */
12491 do_cleanups (option_chain
);
12494 /* Close the tuple. */
12495 do_cleanups (showlist_chain
);
12499 /* Function to be called whenever a new objfile (shlib) is detected. */
12501 remote_new_objfile (struct objfile
*objfile
)
12503 struct remote_state
*rs
= get_remote_state ();
12505 if (rs
->remote_desc
!= 0) /* Have a remote connection. */
12506 remote_check_symbols ();
12509 /* Pull all the tracepoints defined on the target and create local
12510 data structures representing them. We don't want to create real
12511 tracepoints yet, we don't want to mess up the user's existing
12515 remote_upload_tracepoints (struct target_ops
*self
, struct uploaded_tp
**utpp
)
12517 struct remote_state
*rs
= get_remote_state ();
12520 /* Ask for a first packet of tracepoint definition. */
12522 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12524 while (*p
&& *p
!= 'l')
12526 parse_tracepoint_definition (p
, utpp
);
12527 /* Ask for another packet of tracepoint definition. */
12529 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12536 remote_upload_trace_state_variables (struct target_ops
*self
,
12537 struct uploaded_tsv
**utsvp
)
12539 struct remote_state
*rs
= get_remote_state ();
12542 /* Ask for a first packet of variable definition. */
12544 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12546 while (*p
&& *p
!= 'l')
12548 parse_tsv_definition (p
, utsvp
);
12549 /* Ask for another packet of variable definition. */
12551 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
12557 /* The "set/show range-stepping" show hook. */
12560 show_range_stepping (struct ui_file
*file
, int from_tty
,
12561 struct cmd_list_element
*c
,
12564 fprintf_filtered (file
,
12565 _("Debugger's willingness to use range stepping "
12566 "is %s.\n"), value
);
12569 /* The "set/show range-stepping" set hook. */
12572 set_range_stepping (char *ignore_args
, int from_tty
,
12573 struct cmd_list_element
*c
)
12575 struct remote_state
*rs
= get_remote_state ();
12577 /* Whene enabling, check whether range stepping is actually
12578 supported by the target, and warn if not. */
12579 if (use_range_stepping
)
12581 if (rs
->remote_desc
!= NULL
)
12583 if (packet_support (PACKET_vCont
) == PACKET_SUPPORT_UNKNOWN
)
12584 remote_vcont_probe (rs
);
12586 if (packet_support (PACKET_vCont
) == PACKET_ENABLE
12587 && rs
->supports_vCont
.r
)
12591 warning (_("Range stepping is not supported by the current target"));
12596 _initialize_remote (void)
12598 struct remote_state
*rs
;
12599 struct cmd_list_element
*cmd
;
12600 const char *cmd_name
;
12602 /* architecture specific data */
12603 remote_gdbarch_data_handle
=
12604 gdbarch_data_register_post_init (init_remote_state
);
12605 remote_g_packet_data_handle
=
12606 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
12608 /* Initialize the per-target state. At the moment there is only one
12609 of these, not one per target. Only one target is active at a
12611 remote_state
= new_remote_state ();
12613 init_remote_ops ();
12614 add_target (&remote_ops
);
12616 init_extended_remote_ops ();
12617 add_target (&extended_remote_ops
);
12619 /* Hook into new objfile notification. */
12620 observer_attach_new_objfile (remote_new_objfile
);
12621 /* We're no longer interested in notification events of an inferior
12623 observer_attach_inferior_exit (discard_pending_stop_replies
);
12625 /* Set up signal handlers. */
12626 async_sigint_remote_token
=
12627 create_async_signal_handler (async_remote_interrupt
, NULL
);
12628 async_sigint_remote_twice_token
=
12629 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
12632 init_remote_threadtests ();
12635 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
12636 /* set/show remote ... */
12638 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
12639 Remote protocol specific variables\n\
12640 Configure various remote-protocol specific variables such as\n\
12641 the packets being used"),
12642 &remote_set_cmdlist
, "set remote ",
12643 0 /* allow-unknown */, &setlist
);
12644 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
12645 Remote protocol specific variables\n\
12646 Configure various remote-protocol specific variables such as\n\
12647 the packets being used"),
12648 &remote_show_cmdlist
, "show remote ",
12649 0 /* allow-unknown */, &showlist
);
12651 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
12652 Compare section data on target to the exec file.\n\
12653 Argument is a single section name (default: all loaded sections).\n\
12654 To compare only read-only loaded sections, specify the -r option."),
12657 add_cmd ("packet", class_maintenance
, packet_command
, _("\
12658 Send an arbitrary packet to a remote target.\n\
12659 maintenance packet TEXT\n\
12660 If GDB is talking to an inferior via the GDB serial protocol, then\n\
12661 this command sends the string TEXT to the inferior, and displays the\n\
12662 response packet. GDB supplies the initial `$' character, and the\n\
12663 terminating `#' character and checksum."),
12666 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
12667 Set whether to send break if interrupted."), _("\
12668 Show whether to send break if interrupted."), _("\
12669 If set, a break, instead of a cntrl-c, is sent to the remote target."),
12670 set_remotebreak
, show_remotebreak
,
12671 &setlist
, &showlist
);
12672 cmd_name
= "remotebreak";
12673 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
12674 deprecate_cmd (cmd
, "set remote interrupt-sequence");
12675 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
12676 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
12677 deprecate_cmd (cmd
, "show remote interrupt-sequence");
12679 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
12680 interrupt_sequence_modes
, &interrupt_sequence_mode
,
12682 Set interrupt sequence to remote target."), _("\
12683 Show interrupt sequence to remote target."), _("\
12684 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
12685 NULL
, show_interrupt_sequence
,
12686 &remote_set_cmdlist
,
12687 &remote_show_cmdlist
);
12689 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
12690 &interrupt_on_connect
, _("\
12691 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
12692 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
12693 If set, interrupt sequence is sent to remote target."),
12695 &remote_set_cmdlist
, &remote_show_cmdlist
);
12697 /* Install commands for configuring memory read/write packets. */
12699 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
12700 Set the maximum number of bytes per memory write packet (deprecated)."),
12702 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
12703 Show the maximum number of bytes per memory write packet (deprecated)."),
12705 add_cmd ("memory-write-packet-size", no_class
,
12706 set_memory_write_packet_size
, _("\
12707 Set the maximum number of bytes per memory-write packet.\n\
12708 Specify the number of bytes in a packet or 0 (zero) for the\n\
12709 default packet size. The actual limit is further reduced\n\
12710 dependent on the target. Specify ``fixed'' to disable the\n\
12711 further restriction and ``limit'' to enable that restriction."),
12712 &remote_set_cmdlist
);
12713 add_cmd ("memory-read-packet-size", no_class
,
12714 set_memory_read_packet_size
, _("\
12715 Set the maximum number of bytes per memory-read packet.\n\
12716 Specify the number of bytes in a packet or 0 (zero) for the\n\
12717 default packet size. The actual limit is further reduced\n\
12718 dependent on the target. Specify ``fixed'' to disable the\n\
12719 further restriction and ``limit'' to enable that restriction."),
12720 &remote_set_cmdlist
);
12721 add_cmd ("memory-write-packet-size", no_class
,
12722 show_memory_write_packet_size
,
12723 _("Show the maximum number of bytes per memory-write packet."),
12724 &remote_show_cmdlist
);
12725 add_cmd ("memory-read-packet-size", no_class
,
12726 show_memory_read_packet_size
,
12727 _("Show the maximum number of bytes per memory-read packet."),
12728 &remote_show_cmdlist
);
12730 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
12731 &remote_hw_watchpoint_limit
, _("\
12732 Set the maximum number of target hardware watchpoints."), _("\
12733 Show the maximum number of target hardware watchpoints."), _("\
12734 Specify a negative limit for unlimited."),
12735 NULL
, NULL
, /* FIXME: i18n: The maximum
12736 number of target hardware
12737 watchpoints is %s. */
12738 &remote_set_cmdlist
, &remote_show_cmdlist
);
12739 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
12740 &remote_hw_watchpoint_length_limit
, _("\
12741 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
12742 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
12743 Specify a negative limit for unlimited."),
12744 NULL
, NULL
, /* FIXME: i18n: The maximum
12745 length (in bytes) of a target
12746 hardware watchpoint is %s. */
12747 &remote_set_cmdlist
, &remote_show_cmdlist
);
12748 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
12749 &remote_hw_breakpoint_limit
, _("\
12750 Set the maximum number of target hardware breakpoints."), _("\
12751 Show the maximum number of target hardware breakpoints."), _("\
12752 Specify a negative limit for unlimited."),
12753 NULL
, NULL
, /* FIXME: i18n: The maximum
12754 number of target hardware
12755 breakpoints is %s. */
12756 &remote_set_cmdlist
, &remote_show_cmdlist
);
12758 add_setshow_zuinteger_cmd ("remoteaddresssize", class_obscure
,
12759 &remote_address_size
, _("\
12760 Set the maximum size of the address (in bits) in a memory packet."), _("\
12761 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
12763 NULL
, /* FIXME: i18n: */
12764 &setlist
, &showlist
);
12766 init_all_packet_configs ();
12768 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
12769 "X", "binary-download", 1);
12771 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
12772 "vCont", "verbose-resume", 0);
12774 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
12775 "QPassSignals", "pass-signals", 0);
12777 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
12778 "QProgramSignals", "program-signals", 0);
12780 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
12781 "qSymbol", "symbol-lookup", 0);
12783 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
12784 "P", "set-register", 1);
12786 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
12787 "p", "fetch-register", 1);
12789 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
12790 "Z0", "software-breakpoint", 0);
12792 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
12793 "Z1", "hardware-breakpoint", 0);
12795 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
12796 "Z2", "write-watchpoint", 0);
12798 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
12799 "Z3", "read-watchpoint", 0);
12801 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
12802 "Z4", "access-watchpoint", 0);
12804 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
12805 "qXfer:auxv:read", "read-aux-vector", 0);
12807 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_exec_file
],
12808 "qXfer:exec-file:read", "pid-to-exec-file", 0);
12810 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
12811 "qXfer:features:read", "target-features", 0);
12813 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
12814 "qXfer:libraries:read", "library-info", 0);
12816 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
12817 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
12819 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
12820 "qXfer:memory-map:read", "memory-map", 0);
12822 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
12823 "qXfer:spu:read", "read-spu-object", 0);
12825 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
12826 "qXfer:spu:write", "write-spu-object", 0);
12828 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
12829 "qXfer:osdata:read", "osdata", 0);
12831 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
12832 "qXfer:threads:read", "threads", 0);
12834 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
12835 "qXfer:siginfo:read", "read-siginfo-object", 0);
12837 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
12838 "qXfer:siginfo:write", "write-siginfo-object", 0);
12840 add_packet_config_cmd
12841 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
12842 "qXfer:traceframe-info:read", "traceframe-info", 0);
12844 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
12845 "qXfer:uib:read", "unwind-info-block", 0);
12847 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
12848 "qGetTLSAddr", "get-thread-local-storage-address",
12851 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
12852 "qGetTIBAddr", "get-thread-information-block-address",
12855 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
12856 "bc", "reverse-continue", 0);
12858 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
12859 "bs", "reverse-step", 0);
12861 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
12862 "qSupported", "supported-packets", 0);
12864 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
12865 "qSearch:memory", "search-memory", 0);
12867 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qTStatus
],
12868 "qTStatus", "trace-status", 0);
12870 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_setfs
],
12871 "vFile:setfs", "hostio-setfs", 0);
12873 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
12874 "vFile:open", "hostio-open", 0);
12876 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
12877 "vFile:pread", "hostio-pread", 0);
12879 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
12880 "vFile:pwrite", "hostio-pwrite", 0);
12882 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
12883 "vFile:close", "hostio-close", 0);
12885 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
12886 "vFile:unlink", "hostio-unlink", 0);
12888 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
12889 "vFile:readlink", "hostio-readlink", 0);
12891 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_fstat
],
12892 "vFile:fstat", "hostio-fstat", 0);
12894 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
12895 "vAttach", "attach", 0);
12897 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
12900 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
12901 "QStartNoAckMode", "noack", 0);
12903 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
12904 "vKill", "kill", 0);
12906 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
12907 "qAttached", "query-attached", 0);
12909 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
12910 "ConditionalTracepoints",
12911 "conditional-tracepoints", 0);
12913 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
12914 "ConditionalBreakpoints",
12915 "conditional-breakpoints", 0);
12917 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
12918 "BreakpointCommands",
12919 "breakpoint-commands", 0);
12921 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
12922 "FastTracepoints", "fast-tracepoints", 0);
12924 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
12925 "TracepointSource", "TracepointSource", 0);
12927 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
12928 "QAllow", "allow", 0);
12930 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
12931 "StaticTracepoints", "static-tracepoints", 0);
12933 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
12934 "InstallInTrace", "install-in-trace", 0);
12936 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
12937 "qXfer:statictrace:read", "read-sdata-object", 0);
12939 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
12940 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
12942 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
12943 "QDisableRandomization", "disable-randomization", 0);
12945 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
12946 "QAgent", "agent", 0);
12948 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QTBuffer_size
],
12949 "QTBuffer:size", "trace-buffer-size", 0);
12951 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_off
],
12952 "Qbtrace:off", "disable-btrace", 0);
12954 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_bts
],
12955 "Qbtrace:bts", "enable-btrace-bts", 0);
12957 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_pt
],
12958 "Qbtrace:pt", "enable-btrace-pt", 0);
12960 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace
],
12961 "qXfer:btrace", "read-btrace", 0);
12963 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_btrace_conf
],
12964 "qXfer:btrace-conf", "read-btrace-conf", 0);
12966 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_bts_size
],
12967 "Qbtrace-conf:bts:size", "btrace-conf-bts-size", 0);
12969 add_packet_config_cmd (&remote_protocol_packets
[PACKET_swbreak_feature
],
12970 "swbreak-feature", "swbreak-feature", 0);
12972 add_packet_config_cmd (&remote_protocol_packets
[PACKET_hwbreak_feature
],
12973 "hwbreak-feature", "hwbreak-feature", 0);
12975 add_packet_config_cmd (&remote_protocol_packets
[PACKET_fork_event_feature
],
12976 "fork-event-feature", "fork-event-feature", 0);
12978 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vfork_event_feature
],
12979 "vfork-event-feature", "vfork-event-feature", 0);
12981 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Qbtrace_conf_pt_size
],
12982 "Qbtrace-conf:pt:size", "btrace-conf-pt-size", 0);
12984 /* Assert that we've registered "set remote foo-packet" commands
12985 for all packet configs. */
12989 for (i
= 0; i
< PACKET_MAX
; i
++)
12991 /* Ideally all configs would have a command associated. Some
12992 still don't though. */
12997 case PACKET_QNonStop
:
12998 case PACKET_multiprocess_feature
:
12999 case PACKET_EnableDisableTracepoints_feature
:
13000 case PACKET_tracenz_feature
:
13001 case PACKET_DisconnectedTracing_feature
:
13002 case PACKET_augmented_libraries_svr4_read_feature
:
13004 /* Additions to this list need to be well justified:
13005 pre-existing packets are OK; new packets are not. */
13013 /* This catches both forgetting to add a config command, and
13014 forgetting to remove a packet from the exception list. */
13015 gdb_assert (excepted
== (remote_protocol_packets
[i
].name
== NULL
));
13019 /* Keep the old ``set remote Z-packet ...'' working. Each individual
13020 Z sub-packet has its own set and show commands, but users may
13021 have sets to this variable in their .gdbinit files (or in their
13023 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
13024 &remote_Z_packet_detect
, _("\
13025 Set use of remote protocol `Z' packets"), _("\
13026 Show use of remote protocol `Z' packets "), _("\
13027 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
13029 set_remote_protocol_Z_packet_cmd
,
13030 show_remote_protocol_Z_packet_cmd
,
13031 /* FIXME: i18n: Use of remote protocol
13032 `Z' packets is %s. */
13033 &remote_set_cmdlist
, &remote_show_cmdlist
);
13035 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
13036 Manipulate files on the remote system\n\
13037 Transfer files to and from the remote target system."),
13038 &remote_cmdlist
, "remote ",
13039 0 /* allow-unknown */, &cmdlist
);
13041 add_cmd ("put", class_files
, remote_put_command
,
13042 _("Copy a local file to the remote system."),
13045 add_cmd ("get", class_files
, remote_get_command
,
13046 _("Copy a remote file to the local system."),
13049 add_cmd ("delete", class_files
, remote_delete_command
,
13050 _("Delete a remote file."),
13053 remote_exec_file
= xstrdup ("");
13054 add_setshow_string_noescape_cmd ("exec-file", class_files
,
13055 &remote_exec_file
, _("\
13056 Set the remote pathname for \"run\""), _("\
13057 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
13058 &remote_set_cmdlist
, &remote_show_cmdlist
);
13060 add_setshow_boolean_cmd ("range-stepping", class_run
,
13061 &use_range_stepping
, _("\
13062 Enable or disable range stepping."), _("\
13063 Show whether target-assisted range stepping is enabled."), _("\
13064 If on, and the target supports it, when stepping a source line, GDB\n\
13065 tells the target to step the corresponding range of addresses itself instead\n\
13066 of issuing multiple single-steps. This speeds up source level\n\
13067 stepping. If off, GDB always issues single-steps, even if range\n\
13068 stepping is supported by the target. The default is on."),
13069 set_range_stepping
,
13070 show_range_stepping
,
13074 /* Eventually initialize fileio. See fileio.c */
13075 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
13077 /* Take advantage of the fact that the TID field is not used, to tag
13078 special ptids with it set to != 0. */
13079 magic_null_ptid
= ptid_build (42000, -1, 1);
13080 not_sent_ptid
= ptid_build (42000, -2, 1);
13081 any_thread_ptid
= ptid_build (42000, 0, 1);
13083 target_buf_size
= 2048;
13084 target_buf
= xmalloc (target_buf_size
);