1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2012 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. */
23 #include "gdb_string.h"
29 #include "exceptions.h"
31 /*#include "terminal.h" */
34 #include "gdb-stabs.h"
35 #include "gdbthread.h"
39 #include "gdb_assert.h"
42 #include "cli/cli-decode.h"
43 #include "cli/cli-setshow.h"
44 #include "target-descriptions.h"
50 #include "event-loop.h"
51 #include "event-top.h"
57 #include "gdbcore.h" /* for exec_bfd */
59 #include "remote-fileio.h"
60 #include "gdb/fileio.h"
62 #include "xml-support.h"
64 #include "memory-map.h"
66 #include "tracepoint.h"
71 /* Temp hacks for tracepoint encoding migration. */
72 static char *target_buf
;
73 static long target_buf_size
;
75 /* The size to align memory write packets, when practical. The protocol
76 does not guarantee any alignment, and gdb will generate short
77 writes and unaligned writes, but even as a best-effort attempt this
78 can improve bulk transfers. For instance, if a write is misaligned
79 relative to the target's data bus, the stub may need to make an extra
80 round trip fetching data from the target. This doesn't make a
81 huge difference, but it's easy to do, so we try to be helpful.
83 The alignment chosen is arbitrary; usually data bus width is
84 important here, not the possibly larger cache line size. */
85 enum { REMOTE_ALIGN_WRITES
= 16 };
87 /* Prototypes for local functions. */
88 static void cleanup_sigint_signal_handler (void *dummy
);
89 static void initialize_sigint_signal_handler (void);
90 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
91 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
94 static void handle_remote_sigint (int);
95 static void handle_remote_sigint_twice (int);
96 static void async_remote_interrupt (gdb_client_data
);
97 void async_remote_interrupt_twice (gdb_client_data
);
99 static void remote_files_info (struct target_ops
*ignore
);
101 static void remote_prepare_to_store (struct regcache
*regcache
);
103 static void remote_open (char *name
, int from_tty
);
105 static void extended_remote_open (char *name
, int from_tty
);
107 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
109 static void remote_close (int quitting
);
111 static void remote_mourn (struct target_ops
*ops
);
113 static void extended_remote_restart (void);
115 static void extended_remote_mourn (struct target_ops
*);
117 static void remote_mourn_1 (struct target_ops
*);
119 static void remote_send (char **buf
, long *sizeof_buf_p
);
121 static int readchar (int timeout
);
123 static void remote_kill (struct target_ops
*ops
);
125 static int tohex (int nib
);
127 static int remote_can_async_p (void);
129 static int remote_is_async_p (void);
131 static void remote_async (void (*callback
) (enum inferior_event_type event_type
,
132 void *context
), void *context
);
134 static void remote_detach (struct target_ops
*ops
, char *args
, int from_tty
);
136 static void remote_interrupt (int signo
);
138 static void remote_interrupt_twice (int signo
);
140 static void interrupt_query (void);
142 static void set_general_thread (struct ptid ptid
);
143 static void set_continue_thread (struct ptid ptid
);
145 static void get_offsets (void);
147 static void skip_frame (void);
149 static long read_frame (char **buf_p
, long *sizeof_buf
);
151 static int hexnumlen (ULONGEST num
);
153 static void init_remote_ops (void);
155 static void init_extended_remote_ops (void);
157 static void remote_stop (ptid_t
);
159 static int ishex (int ch
, int *val
);
161 static int stubhex (int ch
);
163 static int hexnumstr (char *, ULONGEST
);
165 static int hexnumnstr (char *, ULONGEST
, int);
167 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
169 static void print_packet (char *);
171 static void compare_sections_command (char *, int);
173 static void packet_command (char *, int);
175 static int stub_unpack_int (char *buff
, int fieldlength
);
177 static ptid_t
remote_current_thread (ptid_t oldptid
);
179 static void remote_find_new_threads (void);
181 static void record_currthread (ptid_t currthread
);
183 static int fromhex (int a
);
185 extern int hex2bin (const char *hex
, gdb_byte
*bin
, int count
);
187 extern int bin2hex (const gdb_byte
*bin
, char *hex
, int count
);
189 static int putpkt_binary (char *buf
, int cnt
);
191 static void check_binary_download (CORE_ADDR addr
);
193 struct packet_config
;
195 static void show_packet_config_cmd (struct packet_config
*config
);
197 static void update_packet_config (struct packet_config
*config
);
199 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
200 struct cmd_list_element
*c
);
202 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
204 struct cmd_list_element
*c
,
207 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
208 static ptid_t
read_ptid (char *buf
, char **obuf
);
210 static void remote_set_permissions (void);
213 static int remote_get_trace_status (struct trace_status
*ts
);
215 static int remote_upload_tracepoints (struct uploaded_tp
**utpp
);
217 static int remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
);
219 static void remote_query_supported (void);
221 static void remote_check_symbols (struct objfile
*objfile
);
223 void _initialize_remote (void);
226 static struct stop_reply
*stop_reply_xmalloc (void);
227 static void stop_reply_xfree (struct stop_reply
*);
228 static void do_stop_reply_xfree (void *arg
);
229 static void remote_parse_stop_reply (char *buf
, struct stop_reply
*);
230 static void push_stop_reply (struct stop_reply
*);
231 static void remote_get_pending_stop_replies (void);
232 static void discard_pending_stop_replies (int pid
);
233 static int peek_stop_reply (ptid_t ptid
);
235 static void remote_async_inferior_event_handler (gdb_client_data
);
236 static void remote_async_get_pending_events_handler (gdb_client_data
);
238 static void remote_terminal_ours (void);
240 static int remote_read_description_p (struct target_ops
*target
);
242 static void remote_console_output (char *msg
);
244 static int remote_supports_cond_breakpoints (void);
246 static int remote_can_run_breakpoint_commands (void);
248 /* The non-stop remote protocol provisions for one pending stop reply.
249 This is where we keep it until it is acknowledged. */
251 static struct stop_reply
*pending_stop_reply
= NULL
;
255 static struct cmd_list_element
*remote_cmdlist
;
257 /* For "set remote" and "show remote". */
259 static struct cmd_list_element
*remote_set_cmdlist
;
260 static struct cmd_list_element
*remote_show_cmdlist
;
262 /* Description of the remote protocol state for the currently
263 connected target. This is per-target state, and independent of the
264 selected architecture. */
268 /* A buffer to use for incoming packets, and its current size. The
269 buffer is grown dynamically for larger incoming packets.
270 Outgoing packets may also be constructed in this buffer.
271 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
272 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
277 /* True if we're going through initial connection setup (finding out
278 about the remote side's threads, relocating symbols, etc.). */
281 /* If we negotiated packet size explicitly (and thus can bypass
282 heuristics for the largest packet size that will not overflow
283 a buffer in the stub), this will be set to that packet size.
284 Otherwise zero, meaning to use the guessed size. */
285 long explicit_packet_size
;
287 /* remote_wait is normally called when the target is running and
288 waits for a stop reply packet. But sometimes we need to call it
289 when the target is already stopped. We can send a "?" packet
290 and have remote_wait read the response. Or, if we already have
291 the response, we can stash it in BUF and tell remote_wait to
292 skip calling getpkt. This flag is set when BUF contains a
293 stop reply packet and the target is not waiting. */
294 int cached_wait_status
;
296 /* True, if in no ack mode. That is, neither GDB nor the stub will
297 expect acks from each other. The connection is assumed to be
301 /* True if we're connected in extended remote mode. */
304 /* True if the stub reported support for multi-process
306 int multi_process_aware
;
308 /* True if we resumed the target and we're waiting for the target to
309 stop. In the mean time, we can't start another command/query.
310 The remote server wouldn't be ready to process it, so we'd
311 timeout waiting for a reply that would never come and eventually
312 we'd close the connection. This can happen in asynchronous mode
313 because we allow GDB commands while the target is running. */
314 int waiting_for_stop_reply
;
316 /* True if the stub reports support for non-stop mode. */
319 /* True if the stub reports support for vCont;t. */
322 /* True if the stub reports support for conditional tracepoints. */
323 int cond_tracepoints
;
325 /* True if the stub reports support for target-side breakpoint
327 int cond_breakpoints
;
329 /* True if the stub reports support for target-side breakpoint
331 int breakpoint_commands
;
333 /* True if the stub reports support for fast tracepoints. */
334 int fast_tracepoints
;
336 /* True if the stub reports support for static tracepoints. */
337 int static_tracepoints
;
339 /* True if the stub reports support for installing tracepoint while
341 int install_in_trace
;
343 /* True if the stub can continue running a trace while GDB is
345 int disconnected_tracing
;
347 /* True if the stub reports support for enabling and disabling
348 tracepoints while a trace experiment is running. */
349 int enable_disable_tracepoints
;
351 /* True if the stub can collect strings using tracenz bytecode. */
354 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
355 responded to that. */
359 /* Private data that we'll store in (struct thread_info)->private. */
360 struct private_thread_info
367 free_private_thread_info (struct private_thread_info
*info
)
373 /* Returns true if the multi-process extensions are in effect. */
375 remote_multi_process_p (struct remote_state
*rs
)
377 return rs
->multi_process_aware
;
380 /* This data could be associated with a target, but we do not always
381 have access to the current target when we need it, so for now it is
382 static. This will be fine for as long as only one target is in use
384 static struct remote_state remote_state
;
386 static struct remote_state
*
387 get_remote_state_raw (void)
389 return &remote_state
;
392 /* Description of the remote protocol for a given architecture. */
396 long offset
; /* Offset into G packet. */
397 long regnum
; /* GDB's internal register number. */
398 LONGEST pnum
; /* Remote protocol register number. */
399 int in_g_packet
; /* Always part of G packet. */
400 /* long size in bytes; == register_size (target_gdbarch, regnum);
402 /* char *name; == gdbarch_register_name (target_gdbarch, regnum);
406 struct remote_arch_state
408 /* Description of the remote protocol registers. */
409 long sizeof_g_packet
;
411 /* Description of the remote protocol registers indexed by REGNUM
412 (making an array gdbarch_num_regs in size). */
413 struct packet_reg
*regs
;
415 /* This is the size (in chars) of the first response to the ``g''
416 packet. It is used as a heuristic when determining the maximum
417 size of memory-read and memory-write packets. A target will
418 typically only reserve a buffer large enough to hold the ``g''
419 packet. The size does not include packet overhead (headers and
421 long actual_register_packet_size
;
423 /* This is the maximum size (in chars) of a non read/write packet.
424 It is also used as a cap on the size of read/write packets. */
425 long remote_packet_size
;
428 long sizeof_pkt
= 2000;
430 /* Utility: generate error from an incoming stub packet. */
432 trace_error (char *buf
)
435 return; /* not an error msg */
438 case '1': /* malformed packet error */
439 if (*++buf
== '0') /* general case: */
440 error (_("remote.c: error in outgoing packet."));
442 error (_("remote.c: error in outgoing packet at field #%ld."),
443 strtol (buf
, NULL
, 16));
445 error (_("trace API error 0x%s."), ++buf
);
447 error (_("Target returns error code '%s'."), buf
);
451 /* Utility: wait for reply from stub, while accepting "O" packets. */
453 remote_get_noisy_reply (char **buf_p
,
456 do /* Loop on reply from remote stub. */
460 QUIT
; /* Allow user to bail out with ^C. */
461 getpkt (buf_p
, sizeof_buf
, 0);
465 else if (strncmp (buf
, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
468 CORE_ADDR from
, to
, org_to
;
470 int adjusted_size
= 0;
471 volatile struct gdb_exception ex
;
473 p
= buf
+ strlen ("qRelocInsn:");
474 pp
= unpack_varlen_hex (p
, &ul
);
476 error (_("invalid qRelocInsn packet: %s"), buf
);
480 unpack_varlen_hex (p
, &ul
);
485 TRY_CATCH (ex
, RETURN_MASK_ALL
)
487 gdbarch_relocate_instruction (target_gdbarch
, &to
, from
);
491 adjusted_size
= to
- org_to
;
493 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
496 else if (ex
.reason
< 0 && ex
.error
== MEMORY_ERROR
)
498 /* Propagate memory errors silently back to the target.
499 The stub may have limited the range of addresses we
500 can write to, for example. */
505 /* Something unexpectedly bad happened. Be verbose so
506 we can tell what, and propagate the error back to the
507 stub, so it doesn't get stuck waiting for a
509 exception_fprintf (gdb_stderr
, ex
,
510 _("warning: relocating instruction: "));
514 else if (buf
[0] == 'O' && buf
[1] != 'K')
515 remote_console_output (buf
+ 1); /* 'O' message from stub */
517 return buf
; /* Here's the actual reply. */
522 /* Handle for retreving the remote protocol data from gdbarch. */
523 static struct gdbarch_data
*remote_gdbarch_data_handle
;
525 static struct remote_arch_state
*
526 get_remote_arch_state (void)
528 return gdbarch_data (target_gdbarch
, remote_gdbarch_data_handle
);
531 /* Fetch the global remote target state. */
533 static struct remote_state
*
534 get_remote_state (void)
536 /* Make sure that the remote architecture state has been
537 initialized, because doing so might reallocate rs->buf. Any
538 function which calls getpkt also needs to be mindful of changes
539 to rs->buf, but this call limits the number of places which run
541 get_remote_arch_state ();
543 return get_remote_state_raw ();
547 compare_pnums (const void *lhs_
, const void *rhs_
)
549 const struct packet_reg
* const *lhs
= lhs_
;
550 const struct packet_reg
* const *rhs
= rhs_
;
552 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
554 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
561 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
563 int regnum
, num_remote_regs
, offset
;
564 struct packet_reg
**remote_regs
;
566 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
568 struct packet_reg
*r
= ®s
[regnum
];
570 if (register_size (gdbarch
, regnum
) == 0)
571 /* Do not try to fetch zero-sized (placeholder) registers. */
574 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
579 /* Define the g/G packet format as the contents of each register
580 with a remote protocol number, in order of ascending protocol
583 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
584 * sizeof (struct packet_reg
*));
585 for (num_remote_regs
= 0, regnum
= 0;
586 regnum
< gdbarch_num_regs (gdbarch
);
588 if (regs
[regnum
].pnum
!= -1)
589 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
591 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
594 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
596 remote_regs
[regnum
]->in_g_packet
= 1;
597 remote_regs
[regnum
]->offset
= offset
;
598 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
604 /* Given the architecture described by GDBARCH, return the remote
605 protocol register's number and the register's offset in the g/G
606 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
607 If the target does not have a mapping for REGNUM, return false,
608 otherwise, return true. */
611 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
612 int *pnum
, int *poffset
)
615 struct packet_reg
*regs
;
616 struct cleanup
*old_chain
;
618 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
620 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
621 old_chain
= make_cleanup (xfree
, regs
);
623 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
625 *pnum
= regs
[regnum
].pnum
;
626 *poffset
= regs
[regnum
].offset
;
628 do_cleanups (old_chain
);
634 init_remote_state (struct gdbarch
*gdbarch
)
636 struct remote_state
*rs
= get_remote_state_raw ();
637 struct remote_arch_state
*rsa
;
639 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
641 /* Use the architecture to build a regnum<->pnum table, which will be
642 1:1 unless a feature set specifies otherwise. */
643 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
644 gdbarch_num_regs (gdbarch
),
647 /* Record the maximum possible size of the g packet - it may turn out
649 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
651 /* Default maximum number of characters in a packet body. Many
652 remote stubs have a hardwired buffer size of 400 bytes
653 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
654 as the maximum packet-size to ensure that the packet and an extra
655 NUL character can always fit in the buffer. This stops GDB
656 trashing stubs that try to squeeze an extra NUL into what is
657 already a full buffer (As of 1999-12-04 that was most stubs). */
658 rsa
->remote_packet_size
= 400 - 1;
660 /* This one is filled in when a ``g'' packet is received. */
661 rsa
->actual_register_packet_size
= 0;
663 /* Should rsa->sizeof_g_packet needs more space than the
664 default, adjust the size accordingly. Remember that each byte is
665 encoded as two characters. 32 is the overhead for the packet
666 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
667 (``$NN:G...#NN'') is a better guess, the below has been padded a
669 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
670 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
672 /* Make sure that the packet buffer is plenty big enough for
673 this architecture. */
674 if (rs
->buf_size
< rsa
->remote_packet_size
)
676 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
677 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
683 /* Return the current allowed size of a remote packet. This is
684 inferred from the current architecture, and should be used to
685 limit the length of outgoing packets. */
687 get_remote_packet_size (void)
689 struct remote_state
*rs
= get_remote_state ();
690 struct remote_arch_state
*rsa
= get_remote_arch_state ();
692 if (rs
->explicit_packet_size
)
693 return rs
->explicit_packet_size
;
695 return rsa
->remote_packet_size
;
698 static struct packet_reg
*
699 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
701 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch
))
705 struct packet_reg
*r
= &rsa
->regs
[regnum
];
707 gdb_assert (r
->regnum
== regnum
);
712 static struct packet_reg
*
713 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
717 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch
); i
++)
719 struct packet_reg
*r
= &rsa
->regs
[i
];
727 /* FIXME: graces/2002-08-08: These variables should eventually be
728 bound to an instance of the target object (as in gdbarch-tdep()),
729 when such a thing exists. */
731 /* This is set to the data address of the access causing the target
732 to stop for a watchpoint. */
733 static CORE_ADDR remote_watch_data_address
;
735 /* This is non-zero if target stopped for a watchpoint. */
736 static int remote_stopped_by_watchpoint_p
;
738 static struct target_ops remote_ops
;
740 static struct target_ops extended_remote_ops
;
742 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
743 ``forever'' still use the normal timeout mechanism. This is
744 currently used by the ASYNC code to guarentee that target reads
745 during the initial connect always time-out. Once getpkt has been
746 modified to return a timeout indication and, in turn
747 remote_wait()/wait_for_inferior() have gained a timeout parameter
749 static int wait_forever_enabled_p
= 1;
751 /* Allow the user to specify what sequence to send to the remote
752 when he requests a program interruption: Although ^C is usually
753 what remote systems expect (this is the default, here), it is
754 sometimes preferable to send a break. On other systems such
755 as the Linux kernel, a break followed by g, which is Magic SysRq g
756 is required in order to interrupt the execution. */
757 const char interrupt_sequence_control_c
[] = "Ctrl-C";
758 const char interrupt_sequence_break
[] = "BREAK";
759 const char interrupt_sequence_break_g
[] = "BREAK-g";
760 static const char *const interrupt_sequence_modes
[] =
762 interrupt_sequence_control_c
,
763 interrupt_sequence_break
,
764 interrupt_sequence_break_g
,
767 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
770 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
771 struct cmd_list_element
*c
,
774 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
775 fprintf_filtered (file
,
776 _("Send the ASCII ETX character (Ctrl-c) "
777 "to the remote target to interrupt the "
778 "execution of the program.\n"));
779 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
780 fprintf_filtered (file
,
781 _("send a break signal to the remote target "
782 "to interrupt the execution of the program.\n"));
783 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
784 fprintf_filtered (file
,
785 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
786 "the remote target to interrupt the execution "
787 "of Linux kernel.\n"));
789 internal_error (__FILE__
, __LINE__
,
790 _("Invalid value for interrupt_sequence_mode: %s."),
791 interrupt_sequence_mode
);
794 /* This boolean variable specifies whether interrupt_sequence is sent
795 to the remote target when gdb connects to it.
796 This is mostly needed when you debug the Linux kernel: The Linux kernel
797 expects BREAK g which is Magic SysRq g for connecting gdb. */
798 static int interrupt_on_connect
= 0;
800 /* This variable is used to implement the "set/show remotebreak" commands.
801 Since these commands are now deprecated in favor of "set/show remote
802 interrupt-sequence", it no longer has any effect on the code. */
803 static int remote_break
;
806 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
809 interrupt_sequence_mode
= interrupt_sequence_break
;
811 interrupt_sequence_mode
= interrupt_sequence_control_c
;
815 show_remotebreak (struct ui_file
*file
, int from_tty
,
816 struct cmd_list_element
*c
,
821 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
822 remote_open knows that we don't have a file open when the program
824 static struct serial
*remote_desc
= NULL
;
826 /* This variable sets the number of bits in an address that are to be
827 sent in a memory ("M" or "m") packet. Normally, after stripping
828 leading zeros, the entire address would be sent. This variable
829 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
830 initial implementation of remote.c restricted the address sent in
831 memory packets to ``host::sizeof long'' bytes - (typically 32
832 bits). Consequently, for 64 bit targets, the upper 32 bits of an
833 address was never sent. Since fixing this bug may cause a break in
834 some remote targets this variable is principly provided to
835 facilitate backward compatibility. */
837 static unsigned int remote_address_size
;
839 /* Temporary to track who currently owns the terminal. See
840 remote_terminal_* for more details. */
842 static int remote_async_terminal_ours_p
;
844 /* The executable file to use for "run" on the remote side. */
846 static char *remote_exec_file
= "";
849 /* User configurable variables for the number of characters in a
850 memory read/write packet. MIN (rsa->remote_packet_size,
851 rsa->sizeof_g_packet) is the default. Some targets need smaller
852 values (fifo overruns, et.al.) and some users need larger values
853 (speed up transfers). The variables ``preferred_*'' (the user
854 request), ``current_*'' (what was actually set) and ``forced_*''
855 (Positive - a soft limit, negative - a hard limit). */
857 struct memory_packet_config
864 /* Compute the current size of a read/write packet. Since this makes
865 use of ``actual_register_packet_size'' the computation is dynamic. */
868 get_memory_packet_size (struct memory_packet_config
*config
)
870 struct remote_state
*rs
= get_remote_state ();
871 struct remote_arch_state
*rsa
= get_remote_arch_state ();
873 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
874 law?) that some hosts don't cope very well with large alloca()
875 calls. Eventually the alloca() code will be replaced by calls to
876 xmalloc() and make_cleanups() allowing this restriction to either
877 be lifted or removed. */
878 #ifndef MAX_REMOTE_PACKET_SIZE
879 #define MAX_REMOTE_PACKET_SIZE 16384
881 /* NOTE: 20 ensures we can write at least one byte. */
882 #ifndef MIN_REMOTE_PACKET_SIZE
883 #define MIN_REMOTE_PACKET_SIZE 20
888 if (config
->size
<= 0)
889 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
891 what_they_get
= config
->size
;
895 what_they_get
= get_remote_packet_size ();
896 /* Limit the packet to the size specified by the user. */
898 && what_they_get
> config
->size
)
899 what_they_get
= config
->size
;
901 /* Limit it to the size of the targets ``g'' response unless we have
902 permission from the stub to use a larger packet size. */
903 if (rs
->explicit_packet_size
== 0
904 && rsa
->actual_register_packet_size
> 0
905 && what_they_get
> rsa
->actual_register_packet_size
)
906 what_they_get
= rsa
->actual_register_packet_size
;
908 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
909 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
910 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
911 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
913 /* Make sure there is room in the global buffer for this packet
914 (including its trailing NUL byte). */
915 if (rs
->buf_size
< what_they_get
+ 1)
917 rs
->buf_size
= 2 * what_they_get
;
918 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
921 return what_they_get
;
924 /* Update the size of a read/write packet. If they user wants
925 something really big then do a sanity check. */
928 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
930 int fixed_p
= config
->fixed_p
;
931 long size
= config
->size
;
934 error (_("Argument required (integer, `fixed' or `limited')."));
935 else if (strcmp (args
, "hard") == 0
936 || strcmp (args
, "fixed") == 0)
938 else if (strcmp (args
, "soft") == 0
939 || strcmp (args
, "limit") == 0)
945 size
= strtoul (args
, &end
, 0);
947 error (_("Invalid %s (bad syntax)."), config
->name
);
949 /* Instead of explicitly capping the size of a packet to
950 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
951 instead allowed to set the size to something arbitrarily
953 if (size
> MAX_REMOTE_PACKET_SIZE
)
954 error (_("Invalid %s (too large)."), config
->name
);
958 if (fixed_p
&& !config
->fixed_p
)
960 if (! query (_("The target may not be able to correctly handle a %s\n"
961 "of %ld bytes. Change the packet size? "),
963 error (_("Packet size not changed."));
965 /* Update the config. */
966 config
->fixed_p
= fixed_p
;
971 show_memory_packet_size (struct memory_packet_config
*config
)
973 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
975 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
976 get_memory_packet_size (config
));
978 printf_filtered (_("Packets are limited to %ld bytes.\n"),
979 get_memory_packet_size (config
));
982 static struct memory_packet_config memory_write_packet_config
=
984 "memory-write-packet-size",
988 set_memory_write_packet_size (char *args
, int from_tty
)
990 set_memory_packet_size (args
, &memory_write_packet_config
);
994 show_memory_write_packet_size (char *args
, int from_tty
)
996 show_memory_packet_size (&memory_write_packet_config
);
1000 get_memory_write_packet_size (void)
1002 return get_memory_packet_size (&memory_write_packet_config
);
1005 static struct memory_packet_config memory_read_packet_config
=
1007 "memory-read-packet-size",
1011 set_memory_read_packet_size (char *args
, int from_tty
)
1013 set_memory_packet_size (args
, &memory_read_packet_config
);
1017 show_memory_read_packet_size (char *args
, int from_tty
)
1019 show_memory_packet_size (&memory_read_packet_config
);
1023 get_memory_read_packet_size (void)
1025 long size
= get_memory_packet_size (&memory_read_packet_config
);
1027 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1028 extra buffer size argument before the memory read size can be
1029 increased beyond this. */
1030 if (size
> get_remote_packet_size ())
1031 size
= get_remote_packet_size ();
1036 /* Generic configuration support for packets the stub optionally
1037 supports. Allows the user to specify the use of the packet as well
1038 as allowing GDB to auto-detect support in the remote stub. */
1042 PACKET_SUPPORT_UNKNOWN
= 0,
1047 struct packet_config
1051 enum auto_boolean detect
;
1052 enum packet_support support
;
1055 /* Analyze a packet's return value and update the packet config
1066 update_packet_config (struct packet_config
*config
)
1068 switch (config
->detect
)
1070 case AUTO_BOOLEAN_TRUE
:
1071 config
->support
= PACKET_ENABLE
;
1073 case AUTO_BOOLEAN_FALSE
:
1074 config
->support
= PACKET_DISABLE
;
1076 case AUTO_BOOLEAN_AUTO
:
1077 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1083 show_packet_config_cmd (struct packet_config
*config
)
1085 char *support
= "internal-error";
1087 switch (config
->support
)
1090 support
= "enabled";
1092 case PACKET_DISABLE
:
1093 support
= "disabled";
1095 case PACKET_SUPPORT_UNKNOWN
:
1096 support
= "unknown";
1099 switch (config
->detect
)
1101 case AUTO_BOOLEAN_AUTO
:
1102 printf_filtered (_("Support for the `%s' packet "
1103 "is auto-detected, currently %s.\n"),
1104 config
->name
, support
);
1106 case AUTO_BOOLEAN_TRUE
:
1107 case AUTO_BOOLEAN_FALSE
:
1108 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1109 config
->name
, support
);
1115 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1116 const char *title
, int legacy
)
1122 config
->name
= name
;
1123 config
->title
= title
;
1124 config
->detect
= AUTO_BOOLEAN_AUTO
;
1125 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1126 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1128 show_doc
= xstrprintf ("Show current use of remote "
1129 "protocol `%s' (%s) packet",
1131 /* set/show TITLE-packet {auto,on,off} */
1132 cmd_name
= xstrprintf ("%s-packet", title
);
1133 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1134 &config
->detect
, set_doc
,
1135 show_doc
, NULL
, /* help_doc */
1136 set_remote_protocol_packet_cmd
,
1137 show_remote_protocol_packet_cmd
,
1138 &remote_set_cmdlist
, &remote_show_cmdlist
);
1139 /* The command code copies the documentation strings. */
1142 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1147 legacy_name
= xstrprintf ("%s-packet", name
);
1148 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1149 &remote_set_cmdlist
);
1150 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1151 &remote_show_cmdlist
);
1155 static enum packet_result
1156 packet_check_result (const char *buf
)
1160 /* The stub recognized the packet request. Check that the
1161 operation succeeded. */
1163 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1165 /* "Enn" - definitly an error. */
1166 return PACKET_ERROR
;
1168 /* Always treat "E." as an error. This will be used for
1169 more verbose error messages, such as E.memtypes. */
1170 if (buf
[0] == 'E' && buf
[1] == '.')
1171 return PACKET_ERROR
;
1173 /* The packet may or may not be OK. Just assume it is. */
1177 /* The stub does not support the packet. */
1178 return PACKET_UNKNOWN
;
1181 static enum packet_result
1182 packet_ok (const char *buf
, struct packet_config
*config
)
1184 enum packet_result result
;
1186 result
= packet_check_result (buf
);
1191 /* The stub recognized the packet request. */
1192 switch (config
->support
)
1194 case PACKET_SUPPORT_UNKNOWN
:
1196 fprintf_unfiltered (gdb_stdlog
,
1197 "Packet %s (%s) is supported\n",
1198 config
->name
, config
->title
);
1199 config
->support
= PACKET_ENABLE
;
1201 case PACKET_DISABLE
:
1202 internal_error (__FILE__
, __LINE__
,
1203 _("packet_ok: attempt to use a disabled packet"));
1209 case PACKET_UNKNOWN
:
1210 /* The stub does not support the packet. */
1211 switch (config
->support
)
1214 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1215 /* If the stub previously indicated that the packet was
1216 supported then there is a protocol error.. */
1217 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1218 config
->name
, config
->title
);
1220 /* The user set it wrong. */
1221 error (_("Enabled packet %s (%s) not recognized by stub"),
1222 config
->name
, config
->title
);
1224 case PACKET_SUPPORT_UNKNOWN
:
1226 fprintf_unfiltered (gdb_stdlog
,
1227 "Packet %s (%s) is NOT supported\n",
1228 config
->name
, config
->title
);
1229 config
->support
= PACKET_DISABLE
;
1231 case PACKET_DISABLE
:
1253 PACKET_vFile_pwrite
,
1255 PACKET_vFile_unlink
,
1256 PACKET_vFile_readlink
,
1258 PACKET_qXfer_features
,
1259 PACKET_qXfer_libraries
,
1260 PACKET_qXfer_libraries_svr4
,
1261 PACKET_qXfer_memory_map
,
1262 PACKET_qXfer_spu_read
,
1263 PACKET_qXfer_spu_write
,
1264 PACKET_qXfer_osdata
,
1265 PACKET_qXfer_threads
,
1266 PACKET_qXfer_statictrace_read
,
1267 PACKET_qXfer_traceframe_info
,
1272 PACKET_QPassSignals
,
1273 PACKET_QProgramSignals
,
1274 PACKET_qSearch_memory
,
1277 PACKET_QStartNoAckMode
,
1279 PACKET_qXfer_siginfo_read
,
1280 PACKET_qXfer_siginfo_write
,
1282 PACKET_ConditionalTracepoints
,
1283 PACKET_ConditionalBreakpoints
,
1284 PACKET_BreakpointCommands
,
1285 PACKET_FastTracepoints
,
1286 PACKET_StaticTracepoints
,
1287 PACKET_InstallInTrace
,
1290 PACKET_TracepointSource
,
1293 PACKET_QDisableRandomization
,
1298 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1301 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1302 struct cmd_list_element
*c
)
1304 struct packet_config
*packet
;
1306 for (packet
= remote_protocol_packets
;
1307 packet
< &remote_protocol_packets
[PACKET_MAX
];
1310 if (&packet
->detect
== c
->var
)
1312 update_packet_config (packet
);
1316 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1321 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1322 struct cmd_list_element
*c
,
1325 struct packet_config
*packet
;
1327 for (packet
= remote_protocol_packets
;
1328 packet
< &remote_protocol_packets
[PACKET_MAX
];
1331 if (&packet
->detect
== c
->var
)
1333 show_packet_config_cmd (packet
);
1337 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1341 /* Should we try one of the 'Z' requests? */
1345 Z_PACKET_SOFTWARE_BP
,
1346 Z_PACKET_HARDWARE_BP
,
1353 /* For compatibility with older distributions. Provide a ``set remote
1354 Z-packet ...'' command that updates all the Z packet types. */
1356 static enum auto_boolean remote_Z_packet_detect
;
1359 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1360 struct cmd_list_element
*c
)
1364 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1366 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1367 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1372 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1373 struct cmd_list_element
*c
,
1378 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1380 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1384 /* Should we try the 'ThreadInfo' query packet?
1386 This variable (NOT available to the user: auto-detect only!)
1387 determines whether GDB will use the new, simpler "ThreadInfo"
1388 query or the older, more complex syntax for thread queries.
1389 This is an auto-detect variable (set to true at each connect,
1390 and set to false when the target fails to recognize it). */
1392 static int use_threadinfo_query
;
1393 static int use_threadextra_query
;
1395 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1396 static struct async_signal_handler
*sigint_remote_twice_token
;
1397 static struct async_signal_handler
*sigint_remote_token
;
1400 /* Asynchronous signal handle registered as event loop source for
1401 when we have pending events ready to be passed to the core. */
1403 static struct async_event_handler
*remote_async_inferior_event_token
;
1405 /* Asynchronous signal handle registered as event loop source for when
1406 the remote sent us a %Stop notification. The registered callback
1407 will do a vStopped sequence to pull the rest of the events out of
1408 the remote side into our event queue. */
1410 static struct async_event_handler
*remote_async_get_pending_events_token
;
1413 static ptid_t magic_null_ptid
;
1414 static ptid_t not_sent_ptid
;
1415 static ptid_t any_thread_ptid
;
1417 /* These are the threads which we last sent to the remote system. The
1418 TID member will be -1 for all or -2 for not sent yet. */
1420 static ptid_t general_thread
;
1421 static ptid_t continue_thread
;
1423 /* This is the traceframe which we last selected on the remote system.
1424 It will be -1 if no traceframe is selected. */
1425 static int remote_traceframe_number
= -1;
1427 /* Find out if the stub attached to PID (and hence GDB should offer to
1428 detach instead of killing it when bailing out). */
1431 remote_query_attached (int pid
)
1433 struct remote_state
*rs
= get_remote_state ();
1434 size_t size
= get_remote_packet_size ();
1436 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1439 if (remote_multi_process_p (rs
))
1440 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1442 xsnprintf (rs
->buf
, size
, "qAttached");
1445 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1447 switch (packet_ok (rs
->buf
,
1448 &remote_protocol_packets
[PACKET_qAttached
]))
1451 if (strcmp (rs
->buf
, "1") == 0)
1455 warning (_("Remote failure reply: %s"), rs
->buf
);
1457 case PACKET_UNKNOWN
:
1464 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1465 has been invented by GDB, instead of reported by the target. Since
1466 we can be connected to a remote system before before knowing about
1467 any inferior, mark the target with execution when we find the first
1468 inferior. If ATTACHED is 1, then we had just attached to this
1469 inferior. If it is 0, then we just created this inferior. If it
1470 is -1, then try querying the remote stub to find out if it had
1471 attached to the inferior or not. */
1473 static struct inferior
*
1474 remote_add_inferior (int fake_pid_p
, int pid
, int attached
)
1476 struct inferior
*inf
;
1478 /* Check whether this process we're learning about is to be
1479 considered attached, or if is to be considered to have been
1480 spawned by the stub. */
1482 attached
= remote_query_attached (pid
);
1484 if (gdbarch_has_global_solist (target_gdbarch
))
1486 /* If the target shares code across all inferiors, then every
1487 attach adds a new inferior. */
1488 inf
= add_inferior (pid
);
1490 /* ... and every inferior is bound to the same program space.
1491 However, each inferior may still have its own address
1493 inf
->aspace
= maybe_new_address_space ();
1494 inf
->pspace
= current_program_space
;
1498 /* In the traditional debugging scenario, there's a 1-1 match
1499 between program/address spaces. We simply bind the inferior
1500 to the program space's address space. */
1501 inf
= current_inferior ();
1502 inferior_appeared (inf
, pid
);
1505 inf
->attach_flag
= attached
;
1506 inf
->fake_pid_p
= fake_pid_p
;
1511 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1512 according to RUNNING. */
1515 remote_add_thread (ptid_t ptid
, int running
)
1519 set_executing (ptid
, running
);
1520 set_running (ptid
, running
);
1523 /* Come here when we learn about a thread id from the remote target.
1524 It may be the first time we hear about such thread, so take the
1525 opportunity to add it to GDB's thread list. In case this is the
1526 first time we're noticing its corresponding inferior, add it to
1527 GDB's inferior list as well. */
1530 remote_notice_new_inferior (ptid_t currthread
, int running
)
1532 /* If this is a new thread, add it to GDB's thread list.
1533 If we leave it up to WFI to do this, bad things will happen. */
1535 if (in_thread_list (currthread
) && is_exited (currthread
))
1537 /* We're seeing an event on a thread id we knew had exited.
1538 This has to be a new thread reusing the old id. Add it. */
1539 remote_add_thread (currthread
, running
);
1543 if (!in_thread_list (currthread
))
1545 struct inferior
*inf
= NULL
;
1546 int pid
= ptid_get_pid (currthread
);
1548 if (ptid_is_pid (inferior_ptid
)
1549 && pid
== ptid_get_pid (inferior_ptid
))
1551 /* inferior_ptid has no thread member yet. This can happen
1552 with the vAttach -> remote_wait,"TAAthread:" path if the
1553 stub doesn't support qC. This is the first stop reported
1554 after an attach, so this is the main thread. Update the
1555 ptid in the thread list. */
1556 if (in_thread_list (pid_to_ptid (pid
)))
1557 thread_change_ptid (inferior_ptid
, currthread
);
1560 remote_add_thread (currthread
, running
);
1561 inferior_ptid
= currthread
;
1566 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1568 /* inferior_ptid is not set yet. This can happen with the
1569 vRun -> remote_wait,"TAAthread:" path if the stub
1570 doesn't support qC. This is the first stop reported
1571 after an attach, so this is the main thread. Update the
1572 ptid in the thread list. */
1573 thread_change_ptid (inferior_ptid
, currthread
);
1577 /* When connecting to a target remote, or to a target
1578 extended-remote which already was debugging an inferior, we
1579 may not know about it yet. Add it before adding its child
1580 thread, so notifications are emitted in a sensible order. */
1581 if (!in_inferior_list (ptid_get_pid (currthread
)))
1583 struct remote_state
*rs
= get_remote_state ();
1584 int fake_pid_p
= !remote_multi_process_p (rs
);
1586 inf
= remote_add_inferior (fake_pid_p
,
1587 ptid_get_pid (currthread
), -1);
1590 /* This is really a new thread. Add it. */
1591 remote_add_thread (currthread
, running
);
1593 /* If we found a new inferior, let the common code do whatever
1594 it needs to with it (e.g., read shared libraries, insert
1597 notice_new_inferior (currthread
, running
, 0);
1601 /* Return the private thread data, creating it if necessary. */
1603 static struct private_thread_info
*
1604 demand_private_info (ptid_t ptid
)
1606 struct thread_info
*info
= find_thread_ptid (ptid
);
1612 info
->private = xmalloc (sizeof (*(info
->private)));
1613 info
->private_dtor
= free_private_thread_info
;
1614 info
->private->core
= -1;
1615 info
->private->extra
= 0;
1618 return info
->private;
1621 /* Call this function as a result of
1622 1) A halt indication (T packet) containing a thread id
1623 2) A direct query of currthread
1624 3) Successful execution of set thread */
1627 record_currthread (ptid_t currthread
)
1629 general_thread
= currthread
;
1632 static char *last_pass_packet
;
1634 /* If 'QPassSignals' is supported, tell the remote stub what signals
1635 it can simply pass through to the inferior without reporting. */
1638 remote_pass_signals (int numsigs
, unsigned char *pass_signals
)
1640 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1642 char *pass_packet
, *p
;
1645 gdb_assert (numsigs
< 256);
1646 for (i
= 0; i
< numsigs
; i
++)
1648 if (pass_signals
[i
])
1651 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1652 strcpy (pass_packet
, "QPassSignals:");
1653 p
= pass_packet
+ strlen (pass_packet
);
1654 for (i
= 0; i
< numsigs
; i
++)
1656 if (pass_signals
[i
])
1659 *p
++ = tohex (i
>> 4);
1660 *p
++ = tohex (i
& 15);
1669 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1671 struct remote_state
*rs
= get_remote_state ();
1672 char *buf
= rs
->buf
;
1674 putpkt (pass_packet
);
1675 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1676 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1677 if (last_pass_packet
)
1678 xfree (last_pass_packet
);
1679 last_pass_packet
= pass_packet
;
1682 xfree (pass_packet
);
1686 /* The last QProgramSignals packet sent to the target. We bypass
1687 sending a new program signals list down to the target if the new
1688 packet is exactly the same as the last we sent. IOW, we only let
1689 the target know about program signals list changes. */
1691 static char *last_program_signals_packet
;
1693 /* If 'QProgramSignals' is supported, tell the remote stub what
1694 signals it should pass through to the inferior when detaching. */
1697 remote_program_signals (int numsigs
, unsigned char *signals
)
1699 if (remote_protocol_packets
[PACKET_QProgramSignals
].support
!= PACKET_DISABLE
)
1704 gdb_assert (numsigs
< 256);
1705 for (i
= 0; i
< numsigs
; i
++)
1710 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1711 strcpy (packet
, "QProgramSignals:");
1712 p
= packet
+ strlen (packet
);
1713 for (i
= 0; i
< numsigs
; i
++)
1715 if (signal_pass_state (i
))
1718 *p
++ = tohex (i
>> 4);
1719 *p
++ = tohex (i
& 15);
1728 if (!last_program_signals_packet
1729 || strcmp (last_program_signals_packet
, packet
) != 0)
1731 struct remote_state
*rs
= get_remote_state ();
1732 char *buf
= rs
->buf
;
1735 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1736 packet_ok (buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1737 xfree (last_program_signals_packet
);
1738 last_program_signals_packet
= packet
;
1745 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1746 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1747 thread. If GEN is set, set the general thread, if not, then set
1748 the step/continue thread. */
1750 set_thread (struct ptid ptid
, int gen
)
1752 struct remote_state
*rs
= get_remote_state ();
1753 ptid_t state
= gen
? general_thread
: continue_thread
;
1754 char *buf
= rs
->buf
;
1755 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1757 if (ptid_equal (state
, ptid
))
1761 *buf
++ = gen
? 'g' : 'c';
1762 if (ptid_equal (ptid
, magic_null_ptid
))
1763 xsnprintf (buf
, endbuf
- buf
, "0");
1764 else if (ptid_equal (ptid
, any_thread_ptid
))
1765 xsnprintf (buf
, endbuf
- buf
, "0");
1766 else if (ptid_equal (ptid
, minus_one_ptid
))
1767 xsnprintf (buf
, endbuf
- buf
, "-1");
1769 write_ptid (buf
, endbuf
, ptid
);
1771 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1773 general_thread
= ptid
;
1775 continue_thread
= ptid
;
1779 set_general_thread (struct ptid ptid
)
1781 set_thread (ptid
, 1);
1785 set_continue_thread (struct ptid ptid
)
1787 set_thread (ptid
, 0);
1790 /* Change the remote current process. Which thread within the process
1791 ends up selected isn't important, as long as it is the same process
1792 as what INFERIOR_PTID points to.
1794 This comes from that fact that there is no explicit notion of
1795 "selected process" in the protocol. The selected process for
1796 general operations is the process the selected general thread
1800 set_general_process (void)
1802 struct remote_state
*rs
= get_remote_state ();
1804 /* If the remote can't handle multiple processes, don't bother. */
1805 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1808 /* We only need to change the remote current thread if it's pointing
1809 at some other process. */
1810 if (ptid_get_pid (general_thread
) != ptid_get_pid (inferior_ptid
))
1811 set_general_thread (inferior_ptid
);
1815 /* Return nonzero if the thread PTID is still alive on the remote
1819 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1821 struct remote_state
*rs
= get_remote_state ();
1824 if (ptid_equal (ptid
, magic_null_ptid
))
1825 /* The main thread is always alive. */
1828 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1829 /* The main thread is always alive. This can happen after a
1830 vAttach, if the remote side doesn't support
1835 endp
= rs
->buf
+ get_remote_packet_size ();
1838 write_ptid (p
, endp
, ptid
);
1841 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1842 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1845 /* About these extended threadlist and threadinfo packets. They are
1846 variable length packets but, the fields within them are often fixed
1847 length. They are redundent enough to send over UDP as is the
1848 remote protocol in general. There is a matching unit test module
1851 #define OPAQUETHREADBYTES 8
1853 /* a 64 bit opaque identifier */
1854 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1856 /* WARNING: This threadref data structure comes from the remote O.S.,
1857 libstub protocol encoding, and remote.c. It is not particularly
1860 /* Right now, the internal structure is int. We want it to be bigger.
1861 Plan to fix this. */
1863 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1865 /* gdb_ext_thread_info is an internal GDB data structure which is
1866 equivalent to the reply of the remote threadinfo packet. */
1868 struct gdb_ext_thread_info
1870 threadref threadid
; /* External form of thread reference. */
1871 int active
; /* Has state interesting to GDB?
1873 char display
[256]; /* Brief state display, name,
1874 blocked/suspended. */
1875 char shortname
[32]; /* To be used to name threads. */
1876 char more_display
[256]; /* Long info, statistics, queue depth,
1880 /* The volume of remote transfers can be limited by submitting
1881 a mask containing bits specifying the desired information.
1882 Use a union of these values as the 'selection' parameter to
1883 get_thread_info. FIXME: Make these TAG names more thread specific. */
1885 #define TAG_THREADID 1
1886 #define TAG_EXISTS 2
1887 #define TAG_DISPLAY 4
1888 #define TAG_THREADNAME 8
1889 #define TAG_MOREDISPLAY 16
1891 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1893 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1895 static char *unpack_nibble (char *buf
, int *val
);
1897 static char *pack_nibble (char *buf
, int nibble
);
1899 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1901 static char *unpack_byte (char *buf
, int *value
);
1903 static char *pack_int (char *buf
, int value
);
1905 static char *unpack_int (char *buf
, int *value
);
1907 static char *unpack_string (char *src
, char *dest
, int length
);
1909 static char *pack_threadid (char *pkt
, threadref
*id
);
1911 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1913 void int_to_threadref (threadref
*id
, int value
);
1915 static int threadref_to_int (threadref
*ref
);
1917 static void copy_threadref (threadref
*dest
, threadref
*src
);
1919 static int threadmatch (threadref
*dest
, threadref
*src
);
1921 static char *pack_threadinfo_request (char *pkt
, int mode
,
1924 static int remote_unpack_thread_info_response (char *pkt
,
1925 threadref
*expectedref
,
1926 struct gdb_ext_thread_info
1930 static int remote_get_threadinfo (threadref
*threadid
,
1931 int fieldset
, /*TAG mask */
1932 struct gdb_ext_thread_info
*info
);
1934 static char *pack_threadlist_request (char *pkt
, int startflag
,
1936 threadref
*nextthread
);
1938 static int parse_threadlist_response (char *pkt
,
1940 threadref
*original_echo
,
1941 threadref
*resultlist
,
1944 static int remote_get_threadlist (int startflag
,
1945 threadref
*nextthread
,
1949 threadref
*threadlist
);
1951 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1953 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1954 void *context
, int looplimit
);
1956 static int remote_newthread_step (threadref
*ref
, void *context
);
1959 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1960 buffer we're allowed to write to. Returns
1961 BUF+CHARACTERS_WRITTEN. */
1964 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1967 struct remote_state
*rs
= get_remote_state ();
1969 if (remote_multi_process_p (rs
))
1971 pid
= ptid_get_pid (ptid
);
1973 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1975 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1977 tid
= ptid_get_tid (ptid
);
1979 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1981 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1986 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1987 passed the last parsed char. Returns null_ptid on error. */
1990 read_ptid (char *buf
, char **obuf
)
1994 ULONGEST pid
= 0, tid
= 0;
1998 /* Multi-process ptid. */
1999 pp
= unpack_varlen_hex (p
+ 1, &pid
);
2001 error (_("invalid remote ptid: %s"), p
);
2004 pp
= unpack_varlen_hex (p
+ 1, &tid
);
2007 return ptid_build (pid
, 0, tid
);
2010 /* No multi-process. Just a tid. */
2011 pp
= unpack_varlen_hex (p
, &tid
);
2013 /* Since the stub is not sending a process id, then default to
2014 what's in inferior_ptid, unless it's null at this point. If so,
2015 then since there's no way to know the pid of the reported
2016 threads, use the magic number. */
2017 if (ptid_equal (inferior_ptid
, null_ptid
))
2018 pid
= ptid_get_pid (magic_null_ptid
);
2020 pid
= ptid_get_pid (inferior_ptid
);
2024 return ptid_build (pid
, 0, tid
);
2027 /* Encode 64 bits in 16 chars of hex. */
2029 static const char hexchars
[] = "0123456789abcdef";
2032 ishex (int ch
, int *val
)
2034 if ((ch
>= 'a') && (ch
<= 'f'))
2036 *val
= ch
- 'a' + 10;
2039 if ((ch
>= 'A') && (ch
<= 'F'))
2041 *val
= ch
- 'A' + 10;
2044 if ((ch
>= '0') && (ch
<= '9'))
2055 if (ch
>= 'a' && ch
<= 'f')
2056 return ch
- 'a' + 10;
2057 if (ch
>= '0' && ch
<= '9')
2059 if (ch
>= 'A' && ch
<= 'F')
2060 return ch
- 'A' + 10;
2065 stub_unpack_int (char *buff
, int fieldlength
)
2072 nibble
= stubhex (*buff
++);
2076 retval
= retval
<< 4;
2082 unpack_varlen_hex (char *buff
, /* packet to parse */
2086 ULONGEST retval
= 0;
2088 while (ishex (*buff
, &nibble
))
2091 retval
= retval
<< 4;
2092 retval
|= nibble
& 0x0f;
2099 unpack_nibble (char *buf
, int *val
)
2101 *val
= fromhex (*buf
++);
2106 pack_nibble (char *buf
, int nibble
)
2108 *buf
++ = hexchars
[(nibble
& 0x0f)];
2113 pack_hex_byte (char *pkt
, int byte
)
2115 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
2116 *pkt
++ = hexchars
[(byte
& 0xf)];
2121 unpack_byte (char *buf
, int *value
)
2123 *value
= stub_unpack_int (buf
, 2);
2128 pack_int (char *buf
, int value
)
2130 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2131 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2132 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2133 buf
= pack_hex_byte (buf
, (value
& 0xff));
2138 unpack_int (char *buf
, int *value
)
2140 *value
= stub_unpack_int (buf
, 8);
2144 #if 0 /* Currently unused, uncomment when needed. */
2145 static char *pack_string (char *pkt
, char *string
);
2148 pack_string (char *pkt
, char *string
)
2153 len
= strlen (string
);
2155 len
= 200; /* Bigger than most GDB packets, junk??? */
2156 pkt
= pack_hex_byte (pkt
, len
);
2160 if ((ch
== '\0') || (ch
== '#'))
2161 ch
= '*'; /* Protect encapsulation. */
2166 #endif /* 0 (unused) */
2169 unpack_string (char *src
, char *dest
, int length
)
2178 pack_threadid (char *pkt
, threadref
*id
)
2181 unsigned char *altid
;
2183 altid
= (unsigned char *) id
;
2184 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2186 pkt
= pack_hex_byte (pkt
, *altid
++);
2192 unpack_threadid (char *inbuf
, threadref
*id
)
2195 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2198 altref
= (char *) id
;
2200 while (inbuf
< limit
)
2202 x
= stubhex (*inbuf
++);
2203 y
= stubhex (*inbuf
++);
2204 *altref
++ = (x
<< 4) | y
;
2209 /* Externally, threadrefs are 64 bits but internally, they are still
2210 ints. This is due to a mismatch of specifications. We would like
2211 to use 64bit thread references internally. This is an adapter
2215 int_to_threadref (threadref
*id
, int value
)
2217 unsigned char *scan
;
2219 scan
= (unsigned char *) id
;
2225 *scan
++ = (value
>> 24) & 0xff;
2226 *scan
++ = (value
>> 16) & 0xff;
2227 *scan
++ = (value
>> 8) & 0xff;
2228 *scan
++ = (value
& 0xff);
2232 threadref_to_int (threadref
*ref
)
2235 unsigned char *scan
;
2241 value
= (value
<< 8) | ((*scan
++) & 0xff);
2246 copy_threadref (threadref
*dest
, threadref
*src
)
2249 unsigned char *csrc
, *cdest
;
2251 csrc
= (unsigned char *) src
;
2252 cdest
= (unsigned char *) dest
;
2259 threadmatch (threadref
*dest
, threadref
*src
)
2261 /* Things are broken right now, so just assume we got a match. */
2263 unsigned char *srcp
, *destp
;
2265 srcp
= (char *) src
;
2266 destp
= (char *) dest
;
2270 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2277 threadid:1, # always request threadid
2284 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2287 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2289 *pkt
++ = 'q'; /* Info Query */
2290 *pkt
++ = 'P'; /* process or thread info */
2291 pkt
= pack_int (pkt
, mode
); /* mode */
2292 pkt
= pack_threadid (pkt
, id
); /* threadid */
2293 *pkt
= '\0'; /* terminate */
2297 /* These values tag the fields in a thread info response packet. */
2298 /* Tagging the fields allows us to request specific fields and to
2299 add more fields as time goes by. */
2301 #define TAG_THREADID 1 /* Echo the thread identifier. */
2302 #define TAG_EXISTS 2 /* Is this process defined enough to
2303 fetch registers and its stack? */
2304 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2305 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2306 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2310 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2311 struct gdb_ext_thread_info
*info
)
2313 struct remote_state
*rs
= get_remote_state ();
2317 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2320 /* info->threadid = 0; FIXME: implement zero_threadref. */
2322 info
->display
[0] = '\0';
2323 info
->shortname
[0] = '\0';
2324 info
->more_display
[0] = '\0';
2326 /* Assume the characters indicating the packet type have been
2328 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2329 pkt
= unpack_threadid (pkt
, &ref
);
2332 warning (_("Incomplete response to threadinfo request."));
2333 if (!threadmatch (&ref
, expectedref
))
2334 { /* This is an answer to a different request. */
2335 warning (_("ERROR RMT Thread info mismatch."));
2338 copy_threadref (&info
->threadid
, &ref
);
2340 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2342 /* Packets are terminated with nulls. */
2343 while ((pkt
< limit
) && mask
&& *pkt
)
2345 pkt
= unpack_int (pkt
, &tag
); /* tag */
2346 pkt
= unpack_byte (pkt
, &length
); /* length */
2347 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2349 warning (_("ERROR RMT: threadinfo tag mismatch."));
2353 if (tag
== TAG_THREADID
)
2357 warning (_("ERROR RMT: length of threadid is not 16."));
2361 pkt
= unpack_threadid (pkt
, &ref
);
2362 mask
= mask
& ~TAG_THREADID
;
2365 if (tag
== TAG_EXISTS
)
2367 info
->active
= stub_unpack_int (pkt
, length
);
2369 mask
= mask
& ~(TAG_EXISTS
);
2372 warning (_("ERROR RMT: 'exists' length too long."));
2378 if (tag
== TAG_THREADNAME
)
2380 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2381 mask
= mask
& ~TAG_THREADNAME
;
2384 if (tag
== TAG_DISPLAY
)
2386 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2387 mask
= mask
& ~TAG_DISPLAY
;
2390 if (tag
== TAG_MOREDISPLAY
)
2392 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2393 mask
= mask
& ~TAG_MOREDISPLAY
;
2396 warning (_("ERROR RMT: unknown thread info tag."));
2397 break; /* Not a tag we know about. */
2403 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2404 struct gdb_ext_thread_info
*info
)
2406 struct remote_state
*rs
= get_remote_state ();
2409 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2411 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2413 if (rs
->buf
[0] == '\0')
2416 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2421 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2424 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2425 threadref
*nextthread
)
2427 *pkt
++ = 'q'; /* info query packet */
2428 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2429 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2430 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2431 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2436 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2439 parse_threadlist_response (char *pkt
, int result_limit
,
2440 threadref
*original_echo
, threadref
*resultlist
,
2443 struct remote_state
*rs
= get_remote_state ();
2445 int count
, resultcount
, done
;
2448 /* Assume the 'q' and 'M chars have been stripped. */
2449 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2450 /* done parse past here */
2451 pkt
= unpack_byte (pkt
, &count
); /* count field */
2452 pkt
= unpack_nibble (pkt
, &done
);
2453 /* The first threadid is the argument threadid. */
2454 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2455 while ((count
-- > 0) && (pkt
< limit
))
2457 pkt
= unpack_threadid (pkt
, resultlist
++);
2458 if (resultcount
++ >= result_limit
)
2467 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2468 int *done
, int *result_count
, threadref
*threadlist
)
2470 struct remote_state
*rs
= get_remote_state ();
2471 static threadref echo_nextthread
;
2474 /* Trancate result limit to be smaller than the packet size. */
2475 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2476 >= get_remote_packet_size ())
2477 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2479 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2481 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2483 if (*rs
->buf
== '\0')
2487 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2490 if (!threadmatch (&echo_nextthread
, nextthread
))
2492 /* FIXME: This is a good reason to drop the packet. */
2493 /* Possably, there is a duplicate response. */
2495 retransmit immediatly - race conditions
2496 retransmit after timeout - yes
2498 wait for packet, then exit
2500 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2501 return 0; /* I choose simply exiting. */
2503 if (*result_count
<= 0)
2507 warning (_("RMT ERROR : failed to get remote thread list."));
2510 return result
; /* break; */
2512 if (*result_count
> result_limit
)
2515 warning (_("RMT ERROR: threadlist response longer than requested."));
2521 /* This is the interface between remote and threads, remotes upper
2524 /* remote_find_new_threads retrieves the thread list and for each
2525 thread in the list, looks up the thread in GDB's internal list,
2526 adding the thread if it does not already exist. This involves
2527 getting partial thread lists from the remote target so, polling the
2528 quit_flag is required. */
2531 /* About this many threadisds fit in a packet. */
2533 #define MAXTHREADLISTRESULTS 32
2536 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2539 int done
, i
, result_count
;
2543 static threadref nextthread
;
2544 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2549 if (loopcount
++ > looplimit
)
2552 warning (_("Remote fetch threadlist -infinite loop-."));
2555 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2556 &done
, &result_count
, resultthreadlist
))
2561 /* Clear for later iterations. */
2563 /* Setup to resume next batch of thread references, set nextthread. */
2564 if (result_count
>= 1)
2565 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2567 while (result_count
--)
2568 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2575 remote_newthread_step (threadref
*ref
, void *context
)
2577 int pid
= ptid_get_pid (inferior_ptid
);
2578 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2580 if (!in_thread_list (ptid
))
2582 return 1; /* continue iterator */
2585 #define CRAZY_MAX_THREADS 1000
2588 remote_current_thread (ptid_t oldpid
)
2590 struct remote_state
*rs
= get_remote_state ();
2593 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2594 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2595 return read_ptid (&rs
->buf
[2], NULL
);
2600 /* Find new threads for info threads command.
2601 * Original version, using John Metzler's thread protocol.
2605 remote_find_new_threads (void)
2607 remote_threadlist_iterator (remote_newthread_step
, 0,
2611 #if defined(HAVE_LIBEXPAT)
2613 typedef struct thread_item
2619 DEF_VEC_O(thread_item_t
);
2621 struct threads_parsing_context
2623 VEC (thread_item_t
) *items
;
2627 start_thread (struct gdb_xml_parser
*parser
,
2628 const struct gdb_xml_element
*element
,
2629 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2631 struct threads_parsing_context
*data
= user_data
;
2633 struct thread_item item
;
2635 struct gdb_xml_value
*attr
;
2637 id
= xml_find_attribute (attributes
, "id")->value
;
2638 item
.ptid
= read_ptid (id
, NULL
);
2640 attr
= xml_find_attribute (attributes
, "core");
2642 item
.core
= *(ULONGEST
*) attr
->value
;
2648 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2652 end_thread (struct gdb_xml_parser
*parser
,
2653 const struct gdb_xml_element
*element
,
2654 void *user_data
, const char *body_text
)
2656 struct threads_parsing_context
*data
= user_data
;
2658 if (body_text
&& *body_text
)
2659 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2662 const struct gdb_xml_attribute thread_attributes
[] = {
2663 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2664 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2665 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2668 const struct gdb_xml_element thread_children
[] = {
2669 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2672 const struct gdb_xml_element threads_children
[] = {
2673 { "thread", thread_attributes
, thread_children
,
2674 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2675 start_thread
, end_thread
},
2676 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2679 const struct gdb_xml_element threads_elements
[] = {
2680 { "threads", NULL
, threads_children
,
2681 GDB_XML_EF_NONE
, NULL
, NULL
},
2682 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2685 /* Discard the contents of the constructed thread info context. */
2688 clear_threads_parsing_context (void *p
)
2690 struct threads_parsing_context
*context
= p
;
2692 struct thread_item
*item
;
2694 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2695 xfree (item
->extra
);
2697 VEC_free (thread_item_t
, context
->items
);
2703 * Find all threads for info threads command.
2704 * Uses new thread protocol contributed by Cisco.
2705 * Falls back and attempts to use the older method (above)
2706 * if the target doesn't respond to the new method.
2710 remote_threads_info (struct target_ops
*ops
)
2712 struct remote_state
*rs
= get_remote_state ();
2716 if (remote_desc
== 0) /* paranoia */
2717 error (_("Command can only be used when connected to the remote target."));
2719 #if defined(HAVE_LIBEXPAT)
2720 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2722 char *xml
= target_read_stralloc (¤t_target
,
2723 TARGET_OBJECT_THREADS
, NULL
);
2725 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2729 struct threads_parsing_context context
;
2731 context
.items
= NULL
;
2732 make_cleanup (clear_threads_parsing_context
, &context
);
2734 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2735 threads_elements
, xml
, &context
) == 0)
2738 struct thread_item
*item
;
2741 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2744 if (!ptid_equal (item
->ptid
, null_ptid
))
2746 struct private_thread_info
*info
;
2747 /* In non-stop mode, we assume new found threads
2748 are running until proven otherwise with a
2749 stop reply. In all-stop, we can only get
2750 here if all threads are stopped. */
2751 int running
= non_stop
? 1 : 0;
2753 remote_notice_new_inferior (item
->ptid
, running
);
2755 info
= demand_private_info (item
->ptid
);
2756 info
->core
= item
->core
;
2757 info
->extra
= item
->extra
;
2764 do_cleanups (back_to
);
2769 if (use_threadinfo_query
)
2771 putpkt ("qfThreadInfo");
2772 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2774 if (bufp
[0] != '\0') /* q packet recognized */
2776 while (*bufp
++ == 'm') /* reply contains one or more TID */
2780 new_thread
= read_ptid (bufp
, &bufp
);
2781 if (!ptid_equal (new_thread
, null_ptid
))
2783 /* In non-stop mode, we assume new found threads
2784 are running until proven otherwise with a
2785 stop reply. In all-stop, we can only get
2786 here if all threads are stopped. */
2787 int running
= non_stop
? 1 : 0;
2789 remote_notice_new_inferior (new_thread
, running
);
2792 while (*bufp
++ == ','); /* comma-separated list */
2793 putpkt ("qsThreadInfo");
2794 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2801 /* Only qfThreadInfo is supported in non-stop mode. */
2805 /* Else fall back to old method based on jmetzler protocol. */
2806 use_threadinfo_query
= 0;
2807 remote_find_new_threads ();
2812 * Collect a descriptive string about the given thread.
2813 * The target may say anything it wants to about the thread
2814 * (typically info about its blocked / runnable state, name, etc.).
2815 * This string will appear in the info threads display.
2817 * Optional: targets are not required to implement this function.
2821 remote_threads_extra_info (struct thread_info
*tp
)
2823 struct remote_state
*rs
= get_remote_state ();
2827 struct gdb_ext_thread_info threadinfo
;
2828 static char display_buf
[100]; /* arbitrary... */
2829 int n
= 0; /* position in display_buf */
2831 if (remote_desc
== 0) /* paranoia */
2832 internal_error (__FILE__
, __LINE__
,
2833 _("remote_threads_extra_info"));
2835 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2836 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2837 /* This is the main thread which was added by GDB. The remote
2838 server doesn't know about it. */
2841 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2843 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2845 if (info
&& info
->private)
2846 return info
->private->extra
;
2851 if (use_threadextra_query
)
2854 char *endb
= rs
->buf
+ get_remote_packet_size ();
2856 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2858 write_ptid (b
, endb
, tp
->ptid
);
2861 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2862 if (rs
->buf
[0] != 0)
2864 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2865 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2866 display_buf
[result
] = '\0';
2871 /* If the above query fails, fall back to the old method. */
2872 use_threadextra_query
= 0;
2873 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2874 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2875 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2876 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2877 if (threadinfo
.active
)
2879 if (*threadinfo
.shortname
)
2880 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2881 " Name: %s,", threadinfo
.shortname
);
2882 if (*threadinfo
.display
)
2883 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2884 " State: %s,", threadinfo
.display
);
2885 if (*threadinfo
.more_display
)
2886 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2887 " Priority: %s", threadinfo
.more_display
);
2891 /* For purely cosmetic reasons, clear up trailing commas. */
2892 if (',' == display_buf
[n
-1])
2893 display_buf
[n
-1] = ' ';
2902 remote_static_tracepoint_marker_at (CORE_ADDR addr
,
2903 struct static_tracepoint_marker
*marker
)
2905 struct remote_state
*rs
= get_remote_state ();
2908 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
2910 p
+= hexnumstr (p
, addr
);
2912 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2916 error (_("Remote failure reply: %s"), p
);
2920 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2927 static VEC(static_tracepoint_marker_p
) *
2928 remote_static_tracepoint_markers_by_strid (const char *strid
)
2930 struct remote_state
*rs
= get_remote_state ();
2931 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
2932 struct static_tracepoint_marker
*marker
= NULL
;
2933 struct cleanup
*old_chain
;
2936 /* Ask for a first packet of static tracepoint marker
2939 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2942 error (_("Remote failure reply: %s"), p
);
2944 old_chain
= make_cleanup (free_current_marker
, &marker
);
2949 marker
= XCNEW (struct static_tracepoint_marker
);
2953 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2955 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
2957 VEC_safe_push (static_tracepoint_marker_p
,
2963 release_static_tracepoint_marker (marker
);
2964 memset (marker
, 0, sizeof (*marker
));
2967 while (*p
++ == ','); /* comma-separated list */
2968 /* Ask for another packet of static tracepoint definition. */
2970 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2974 do_cleanups (old_chain
);
2979 /* Implement the to_get_ada_task_ptid function for the remote targets. */
2982 remote_get_ada_task_ptid (long lwp
, long thread
)
2984 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
2988 /* Restart the remote side; this is an extended protocol operation. */
2991 extended_remote_restart (void)
2993 struct remote_state
*rs
= get_remote_state ();
2995 /* Send the restart command; for reasons I don't understand the
2996 remote side really expects a number after the "R". */
2997 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
3000 remote_fileio_reset ();
3003 /* Clean up connection to a remote debugger. */
3006 remote_close (int quitting
)
3008 if (remote_desc
== NULL
)
3009 return; /* already closed */
3011 /* Make sure we leave stdin registered in the event loop, and we
3012 don't leave the async SIGINT signal handler installed. */
3013 remote_terminal_ours ();
3015 serial_close (remote_desc
);
3018 /* We don't have a connection to the remote stub anymore. Get rid
3019 of all the inferiors and their threads we were controlling.
3020 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3021 will be unable to find the thread corresponding to (pid, 0, 0). */
3022 inferior_ptid
= null_ptid
;
3023 discard_all_inferiors ();
3025 /* We're no longer interested in any of these events. */
3026 discard_pending_stop_replies (-1);
3028 if (remote_async_inferior_event_token
)
3029 delete_async_event_handler (&remote_async_inferior_event_token
);
3030 if (remote_async_get_pending_events_token
)
3031 delete_async_event_handler (&remote_async_get_pending_events_token
);
3034 /* Query the remote side for the text, data and bss offsets. */
3039 struct remote_state
*rs
= get_remote_state ();
3042 int lose
, num_segments
= 0, do_sections
, do_segments
;
3043 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3044 struct section_offsets
*offs
;
3045 struct symfile_segment_data
*data
;
3047 if (symfile_objfile
== NULL
)
3050 putpkt ("qOffsets");
3051 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3054 if (buf
[0] == '\000')
3055 return; /* Return silently. Stub doesn't support
3059 warning (_("Remote failure reply: %s"), buf
);
3063 /* Pick up each field in turn. This used to be done with scanf, but
3064 scanf will make trouble if CORE_ADDR size doesn't match
3065 conversion directives correctly. The following code will work
3066 with any size of CORE_ADDR. */
3067 text_addr
= data_addr
= bss_addr
= 0;
3071 if (strncmp (ptr
, "Text=", 5) == 0)
3074 /* Don't use strtol, could lose on big values. */
3075 while (*ptr
&& *ptr
!= ';')
3076 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3078 if (strncmp (ptr
, ";Data=", 6) == 0)
3081 while (*ptr
&& *ptr
!= ';')
3082 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3087 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
3090 while (*ptr
&& *ptr
!= ';')
3091 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3093 if (bss_addr
!= data_addr
)
3094 warning (_("Target reported unsupported offsets: %s"), buf
);
3099 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
3102 /* Don't use strtol, could lose on big values. */
3103 while (*ptr
&& *ptr
!= ';')
3104 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3107 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
3110 while (*ptr
&& *ptr
!= ';')
3111 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3119 error (_("Malformed response to offset query, %s"), buf
);
3120 else if (*ptr
!= '\0')
3121 warning (_("Target reported unsupported offsets: %s"), buf
);
3123 offs
= ((struct section_offsets
*)
3124 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3125 memcpy (offs
, symfile_objfile
->section_offsets
,
3126 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3128 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3129 do_segments
= (data
!= NULL
);
3130 do_sections
= num_segments
== 0;
3132 if (num_segments
> 0)
3134 segments
[0] = text_addr
;
3135 segments
[1] = data_addr
;
3137 /* If we have two segments, we can still try to relocate everything
3138 by assuming that the .text and .data offsets apply to the whole
3139 text and data segments. Convert the offsets given in the packet
3140 to base addresses for symfile_map_offsets_to_segments. */
3141 else if (data
&& data
->num_segments
== 2)
3143 segments
[0] = data
->segment_bases
[0] + text_addr
;
3144 segments
[1] = data
->segment_bases
[1] + data_addr
;
3147 /* If the object file has only one segment, assume that it is text
3148 rather than data; main programs with no writable data are rare,
3149 but programs with no code are useless. Of course the code might
3150 have ended up in the data segment... to detect that we would need
3151 the permissions here. */
3152 else if (data
&& data
->num_segments
== 1)
3154 segments
[0] = data
->segment_bases
[0] + text_addr
;
3157 /* There's no way to relocate by segment. */
3163 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3164 offs
, num_segments
, segments
);
3166 if (ret
== 0 && !do_sections
)
3167 error (_("Can not handle qOffsets TextSeg "
3168 "response with this symbol file"));
3175 free_symfile_segment_data (data
);
3179 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3181 /* This is a temporary kludge to force data and bss to use the
3182 same offsets because that's what nlmconv does now. The real
3183 solution requires changes to the stub and remote.c that I
3184 don't have time to do right now. */
3186 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3187 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3190 objfile_relocate (symfile_objfile
, offs
);
3193 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3194 threads we know are stopped already. This is used during the
3195 initial remote connection in non-stop mode --- threads that are
3196 reported as already being stopped are left stopped. */
3199 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3201 /* If we have a stop reply for this thread, it must be stopped. */
3202 if (peek_stop_reply (thread
->ptid
))
3203 set_stop_requested (thread
->ptid
, 1);
3208 /* Send interrupt_sequence to remote target. */
3210 send_interrupt_sequence (void)
3212 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3213 serial_write (remote_desc
, "\x03", 1);
3214 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3215 serial_send_break (remote_desc
);
3216 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3218 serial_send_break (remote_desc
);
3219 serial_write (remote_desc
, "g", 1);
3222 internal_error (__FILE__
, __LINE__
,
3223 _("Invalid value for interrupt_sequence_mode: %s."),
3224 interrupt_sequence_mode
);
3227 /* Query the remote target for which is the current thread/process,
3228 add it to our tables, and update INFERIOR_PTID. The caller is
3229 responsible for setting the state such that the remote end is ready
3230 to return the current thread. */
3233 add_current_inferior_and_thread (void)
3235 struct remote_state
*rs
= get_remote_state ();
3239 inferior_ptid
= null_ptid
;
3241 /* Now, if we have thread information, update inferior_ptid. */
3242 ptid
= remote_current_thread (inferior_ptid
);
3243 if (!ptid_equal (ptid
, null_ptid
))
3245 if (!remote_multi_process_p (rs
))
3248 inferior_ptid
= ptid
;
3252 /* Without this, some commands which require an active target
3253 (such as kill) won't work. This variable serves (at least)
3254 double duty as both the pid of the target process (if it has
3255 such), and as a flag indicating that a target is active. */
3256 inferior_ptid
= magic_null_ptid
;
3260 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1);
3262 /* Add the main thread. */
3263 add_thread_silent (inferior_ptid
);
3267 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3269 struct remote_state
*rs
= get_remote_state ();
3270 struct packet_config
*noack_config
;
3271 char *wait_status
= NULL
;
3273 immediate_quit
++; /* Allow user to interrupt it. */
3276 if (interrupt_on_connect
)
3277 send_interrupt_sequence ();
3279 /* Ack any packet which the remote side has already sent. */
3280 serial_write (remote_desc
, "+", 1);
3282 /* Signal other parts that we're going through the initial setup,
3283 and so things may not be stable yet. */
3284 rs
->starting_up
= 1;
3286 /* The first packet we send to the target is the optional "supported
3287 packets" request. If the target can answer this, it will tell us
3288 which later probes to skip. */
3289 remote_query_supported ();
3291 /* If the stub wants to get a QAllow, compose one and send it. */
3292 if (remote_protocol_packets
[PACKET_QAllow
].support
!= PACKET_DISABLE
)
3293 remote_set_permissions ();
3295 /* Next, we possibly activate noack mode.
3297 If the QStartNoAckMode packet configuration is set to AUTO,
3298 enable noack mode if the stub reported a wish for it with
3301 If set to TRUE, then enable noack mode even if the stub didn't
3302 report it in qSupported. If the stub doesn't reply OK, the
3303 session ends with an error.
3305 If FALSE, then don't activate noack mode, regardless of what the
3306 stub claimed should be the default with qSupported. */
3308 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3310 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
3311 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
3312 && noack_config
->support
== PACKET_ENABLE
))
3314 putpkt ("QStartNoAckMode");
3315 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3316 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3322 /* Tell the remote that we are using the extended protocol. */
3324 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3327 /* Let the target know which signals it is allowed to pass down to
3329 update_signals_program_target ();
3331 /* Next, if the target can specify a description, read it. We do
3332 this before anything involving memory or registers. */
3333 target_find_description ();
3335 /* Next, now that we know something about the target, update the
3336 address spaces in the program spaces. */
3337 update_address_spaces ();
3339 /* On OSs where the list of libraries is global to all
3340 processes, we fetch them early. */
3341 if (gdbarch_has_global_solist (target_gdbarch
))
3342 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3346 if (!rs
->non_stop_aware
)
3347 error (_("Non-stop mode requested, but remote "
3348 "does not support non-stop"));
3350 putpkt ("QNonStop:1");
3351 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3353 if (strcmp (rs
->buf
, "OK") != 0)
3354 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3356 /* Find about threads and processes the stub is already
3357 controlling. We default to adding them in the running state.
3358 The '?' query below will then tell us about which threads are
3360 remote_threads_info (target
);
3362 else if (rs
->non_stop_aware
)
3364 /* Don't assume that the stub can operate in all-stop mode.
3365 Request it explicitely. */
3366 putpkt ("QNonStop:0");
3367 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3369 if (strcmp (rs
->buf
, "OK") != 0)
3370 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3373 /* Check whether the target is running now. */
3375 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3381 struct inferior
*inf
;
3383 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3386 error (_("The target is not running (try extended-remote?)"));
3388 /* We're connected, but not running. Drop out before we
3389 call start_remote. */
3390 rs
->starting_up
= 0;
3395 /* Save the reply for later. */
3396 wait_status
= alloca (strlen (rs
->buf
) + 1);
3397 strcpy (wait_status
, rs
->buf
);
3400 /* Let the stub know that we want it to return the thread. */
3401 set_continue_thread (minus_one_ptid
);
3403 add_current_inferior_and_thread ();
3405 /* init_wait_for_inferior should be called before get_offsets in order
3406 to manage `inserted' flag in bp loc in a correct state.
3407 breakpoint_init_inferior, called from init_wait_for_inferior, set
3408 `inserted' flag to 0, while before breakpoint_re_set, called from
3409 start_remote, set `inserted' flag to 1. In the initialization of
3410 inferior, breakpoint_init_inferior should be called first, and then
3411 breakpoint_re_set can be called. If this order is broken, state of
3412 `inserted' flag is wrong, and cause some problems on breakpoint
3414 init_wait_for_inferior ();
3416 get_offsets (); /* Get text, data & bss offsets. */
3418 /* If we could not find a description using qXfer, and we know
3419 how to do it some other way, try again. This is not
3420 supported for non-stop; it could be, but it is tricky if
3421 there are no stopped threads when we connect. */
3422 if (remote_read_description_p (target
)
3423 && gdbarch_target_desc (target_gdbarch
) == NULL
)
3425 target_clear_description ();
3426 target_find_description ();
3429 /* Use the previously fetched status. */
3430 gdb_assert (wait_status
!= NULL
);
3431 strcpy (rs
->buf
, wait_status
);
3432 rs
->cached_wait_status
= 1;
3435 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3439 /* Clear WFI global state. Do this before finding about new
3440 threads and inferiors, and setting the current inferior.
3441 Otherwise we would clear the proceed status of the current
3442 inferior when we want its stop_soon state to be preserved
3443 (see notice_new_inferior). */
3444 init_wait_for_inferior ();
3446 /* In non-stop, we will either get an "OK", meaning that there
3447 are no stopped threads at this time; or, a regular stop
3448 reply. In the latter case, there may be more than one thread
3449 stopped --- we pull them all out using the vStopped
3451 if (strcmp (rs
->buf
, "OK") != 0)
3453 struct stop_reply
*stop_reply
;
3454 struct cleanup
*old_chain
;
3456 stop_reply
= stop_reply_xmalloc ();
3457 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
3459 remote_parse_stop_reply (rs
->buf
, stop_reply
);
3460 discard_cleanups (old_chain
);
3462 /* get_pending_stop_replies acks this one, and gets the rest
3464 pending_stop_reply
= stop_reply
;
3465 remote_get_pending_stop_replies ();
3467 /* Make sure that threads that were stopped remain
3469 iterate_over_threads (set_stop_requested_callback
, NULL
);
3472 if (target_can_async_p ())
3473 target_async (inferior_event_handler
, 0);
3475 if (thread_count () == 0)
3478 error (_("The target is not running (try extended-remote?)"));
3480 /* We're connected, but not running. Drop out before we
3481 call start_remote. */
3482 rs
->starting_up
= 0;
3486 /* Let the stub know that we want it to return the thread. */
3488 /* Force the stub to choose a thread. */
3489 set_general_thread (null_ptid
);
3492 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3493 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3494 error (_("remote didn't report the current thread in non-stop mode"));
3496 get_offsets (); /* Get text, data & bss offsets. */
3498 /* In non-stop mode, any cached wait status will be stored in
3499 the stop reply queue. */
3500 gdb_assert (wait_status
== NULL
);
3502 /* Report all signals during attach/startup. */
3503 remote_pass_signals (0, NULL
);
3506 /* If we connected to a live target, do some additional setup. */
3507 if (target_has_execution
)
3509 if (exec_bfd
) /* No use without an exec file. */
3510 remote_check_symbols (symfile_objfile
);
3513 /* Possibly the target has been engaged in a trace run started
3514 previously; find out where things are at. */
3515 if (remote_get_trace_status (current_trace_status ()) != -1)
3517 struct uploaded_tp
*uploaded_tps
= NULL
;
3518 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3520 if (current_trace_status ()->running
)
3521 printf_filtered (_("Trace is already running on the target.\n"));
3523 /* Get trace state variables first, they may be checked when
3524 parsing uploaded commands. */
3526 remote_upload_trace_state_variables (&uploaded_tsvs
);
3528 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3530 remote_upload_tracepoints (&uploaded_tps
);
3532 merge_uploaded_tracepoints (&uploaded_tps
);
3535 /* The thread and inferior lists are now synchronized with the
3536 target, our symbols have been relocated, and we're merged the
3537 target's tracepoints with ours. We're done with basic start
3539 rs
->starting_up
= 0;
3541 /* If breakpoints are global, insert them now. */
3542 if (gdbarch_has_global_breakpoints (target_gdbarch
)
3543 && breakpoints_always_inserted_mode ())
3544 insert_breakpoints ();
3547 /* Open a connection to a remote debugger.
3548 NAME is the filename used for communication. */
3551 remote_open (char *name
, int from_tty
)
3553 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3556 /* Open a connection to a remote debugger using the extended
3557 remote gdb protocol. NAME is the filename used for communication. */
3560 extended_remote_open (char *name
, int from_tty
)
3562 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3565 /* Generic code for opening a connection to a remote target. */
3568 init_all_packet_configs (void)
3572 for (i
= 0; i
< PACKET_MAX
; i
++)
3573 update_packet_config (&remote_protocol_packets
[i
]);
3576 /* Symbol look-up. */
3579 remote_check_symbols (struct objfile
*objfile
)
3581 struct remote_state
*rs
= get_remote_state ();
3582 char *msg
, *reply
, *tmp
;
3583 struct minimal_symbol
*sym
;
3586 /* The remote side has no concept of inferiors that aren't running
3587 yet, it only knows about running processes. If we're connected
3588 but our current inferior is not running, we should not invite the
3589 remote target to request symbol lookups related to its
3590 (unrelated) current process. */
3591 if (!target_has_execution
)
3594 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3597 /* Make sure the remote is pointing at the right process. Note
3598 there's no way to select "no process". */
3599 set_general_process ();
3601 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3602 because we need both at the same time. */
3603 msg
= alloca (get_remote_packet_size ());
3605 /* Invite target to request symbol lookups. */
3607 putpkt ("qSymbol::");
3608 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3609 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3612 while (strncmp (reply
, "qSymbol:", 8) == 0)
3615 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3617 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3619 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3622 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
3623 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3625 /* If this is a function address, return the start of code
3626 instead of any data function descriptor. */
3627 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch
,
3631 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3632 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3636 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3641 static struct serial
*
3642 remote_serial_open (char *name
)
3644 static int udp_warning
= 0;
3646 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3647 of in ser-tcp.c, because it is the remote protocol assuming that the
3648 serial connection is reliable and not the serial connection promising
3650 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3652 warning (_("The remote protocol may be unreliable over UDP.\n"
3653 "Some events may be lost, rendering further debugging "
3658 return serial_open (name
);
3661 /* Inform the target of our permission settings. The permission flags
3662 work without this, but if the target knows the settings, it can do
3663 a couple things. First, it can add its own check, to catch cases
3664 that somehow manage to get by the permissions checks in target
3665 methods. Second, if the target is wired to disallow particular
3666 settings (for instance, a system in the field that is not set up to
3667 be able to stop at a breakpoint), it can object to any unavailable
3671 remote_set_permissions (void)
3673 struct remote_state
*rs
= get_remote_state ();
3675 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
3676 "WriteReg:%x;WriteMem:%x;"
3677 "InsertBreak:%x;InsertTrace:%x;"
3678 "InsertFastTrace:%x;Stop:%x",
3679 may_write_registers
, may_write_memory
,
3680 may_insert_breakpoints
, may_insert_tracepoints
,
3681 may_insert_fast_tracepoints
, may_stop
);
3683 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3685 /* If the target didn't like the packet, warn the user. Do not try
3686 to undo the user's settings, that would just be maddening. */
3687 if (strcmp (rs
->buf
, "OK") != 0)
3688 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3691 /* This type describes each known response to the qSupported
3693 struct protocol_feature
3695 /* The name of this protocol feature. */
3698 /* The default for this protocol feature. */
3699 enum packet_support default_support
;
3701 /* The function to call when this feature is reported, or after
3702 qSupported processing if the feature is not supported.
3703 The first argument points to this structure. The second
3704 argument indicates whether the packet requested support be
3705 enabled, disabled, or probed (or the default, if this function
3706 is being called at the end of processing and this feature was
3707 not reported). The third argument may be NULL; if not NULL, it
3708 is a NUL-terminated string taken from the packet following
3709 this feature's name and an equals sign. */
3710 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3713 /* The corresponding packet for this feature. Only used if
3714 FUNC is remote_supported_packet. */
3719 remote_supported_packet (const struct protocol_feature
*feature
,
3720 enum packet_support support
,
3721 const char *argument
)
3725 warning (_("Remote qSupported response supplied an unexpected value for"
3726 " \"%s\"."), feature
->name
);
3730 if (remote_protocol_packets
[feature
->packet
].support
3731 == PACKET_SUPPORT_UNKNOWN
)
3732 remote_protocol_packets
[feature
->packet
].support
= support
;
3736 remote_packet_size (const struct protocol_feature
*feature
,
3737 enum packet_support support
, const char *value
)
3739 struct remote_state
*rs
= get_remote_state ();
3744 if (support
!= PACKET_ENABLE
)
3747 if (value
== NULL
|| *value
== '\0')
3749 warning (_("Remote target reported \"%s\" without a size."),
3755 packet_size
= strtol (value
, &value_end
, 16);
3756 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3758 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3759 feature
->name
, value
);
3763 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3765 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3766 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3767 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3770 /* Record the new maximum packet size. */
3771 rs
->explicit_packet_size
= packet_size
;
3775 remote_multi_process_feature (const struct protocol_feature
*feature
,
3776 enum packet_support support
, const char *value
)
3778 struct remote_state
*rs
= get_remote_state ();
3780 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3784 remote_non_stop_feature (const struct protocol_feature
*feature
,
3785 enum packet_support support
, const char *value
)
3787 struct remote_state
*rs
= get_remote_state ();
3789 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3793 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3794 enum packet_support support
,
3797 struct remote_state
*rs
= get_remote_state ();
3799 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3803 remote_cond_breakpoint_feature (const struct protocol_feature
*feature
,
3804 enum packet_support support
,
3807 struct remote_state
*rs
= get_remote_state ();
3809 rs
->cond_breakpoints
= (support
== PACKET_ENABLE
);
3813 remote_breakpoint_commands_feature (const struct protocol_feature
*feature
,
3814 enum packet_support support
,
3817 struct remote_state
*rs
= get_remote_state ();
3819 rs
->breakpoint_commands
= (support
== PACKET_ENABLE
);
3823 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3824 enum packet_support support
,
3827 struct remote_state
*rs
= get_remote_state ();
3829 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3833 remote_static_tracepoint_feature (const struct protocol_feature
*feature
,
3834 enum packet_support support
,
3837 struct remote_state
*rs
= get_remote_state ();
3839 rs
->static_tracepoints
= (support
== PACKET_ENABLE
);
3843 remote_install_in_trace_feature (const struct protocol_feature
*feature
,
3844 enum packet_support support
,
3847 struct remote_state
*rs
= get_remote_state ();
3849 rs
->install_in_trace
= (support
== PACKET_ENABLE
);
3853 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3854 enum packet_support support
,
3857 struct remote_state
*rs
= get_remote_state ();
3859 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3863 remote_enable_disable_tracepoint_feature (const struct protocol_feature
*feature
,
3864 enum packet_support support
,
3867 struct remote_state
*rs
= get_remote_state ();
3869 rs
->enable_disable_tracepoints
= (support
== PACKET_ENABLE
);
3873 remote_string_tracing_feature (const struct protocol_feature
*feature
,
3874 enum packet_support support
,
3877 struct remote_state
*rs
= get_remote_state ();
3879 rs
->string_tracing
= (support
== PACKET_ENABLE
);
3882 static struct protocol_feature remote_protocol_features
[] = {
3883 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3884 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3885 PACKET_qXfer_auxv
},
3886 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3887 PACKET_qXfer_features
},
3888 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3889 PACKET_qXfer_libraries
},
3890 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
3891 PACKET_qXfer_libraries_svr4
},
3892 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3893 PACKET_qXfer_memory_map
},
3894 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3895 PACKET_qXfer_spu_read
},
3896 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3897 PACKET_qXfer_spu_write
},
3898 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3899 PACKET_qXfer_osdata
},
3900 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3901 PACKET_qXfer_threads
},
3902 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
3903 PACKET_qXfer_traceframe_info
},
3904 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3905 PACKET_QPassSignals
},
3906 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
3907 PACKET_QProgramSignals
},
3908 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3909 PACKET_QStartNoAckMode
},
3910 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3911 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3912 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3913 PACKET_qXfer_siginfo_read
},
3914 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3915 PACKET_qXfer_siginfo_write
},
3916 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3917 PACKET_ConditionalTracepoints
},
3918 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_cond_breakpoint_feature
,
3919 PACKET_ConditionalBreakpoints
},
3920 { "BreakpointCommands", PACKET_DISABLE
, remote_breakpoint_commands_feature
,
3921 PACKET_BreakpointCommands
},
3922 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
3923 PACKET_FastTracepoints
},
3924 { "StaticTracepoints", PACKET_DISABLE
, remote_static_tracepoint_feature
,
3925 PACKET_StaticTracepoints
},
3926 {"InstallInTrace", PACKET_DISABLE
, remote_install_in_trace_feature
,
3927 PACKET_InstallInTrace
},
3928 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
3930 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3932 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3934 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
3935 PACKET_TracepointSource
},
3936 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
3938 { "EnableDisableTracepoints", PACKET_DISABLE
,
3939 remote_enable_disable_tracepoint_feature
, -1 },
3940 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
3941 PACKET_qXfer_fdpic
},
3942 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
3944 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
3945 PACKET_QDisableRandomization
},
3946 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
3947 { "tracenz", PACKET_DISABLE
,
3948 remote_string_tracing_feature
, -1 },
3951 static char *remote_support_xml
;
3953 /* Register string appended to "xmlRegisters=" in qSupported query. */
3956 register_remote_support_xml (const char *xml
)
3958 #if defined(HAVE_LIBEXPAT)
3959 if (remote_support_xml
== NULL
)
3960 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
3963 char *copy
= xstrdup (remote_support_xml
+ 13);
3964 char *p
= strtok (copy
, ",");
3968 if (strcmp (p
, xml
) == 0)
3975 while ((p
= strtok (NULL
, ",")) != NULL
);
3978 remote_support_xml
= reconcat (remote_support_xml
,
3979 remote_support_xml
, ",", xml
,
3986 remote_query_supported_append (char *msg
, const char *append
)
3989 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
3991 return xstrdup (append
);
3995 remote_query_supported (void)
3997 struct remote_state
*rs
= get_remote_state ();
4000 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4002 /* The packet support flags are handled differently for this packet
4003 than for most others. We treat an error, a disabled packet, and
4004 an empty response identically: any features which must be reported
4005 to be used will be automatically disabled. An empty buffer
4006 accomplishes this, since that is also the representation for a list
4007 containing no features. */
4010 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
4013 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4015 q
= remote_query_supported_append (q
, "multiprocess+");
4017 if (remote_support_xml
)
4018 q
= remote_query_supported_append (q
, remote_support_xml
);
4020 q
= remote_query_supported_append (q
, "qRelocInsn+");
4022 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4025 do_cleanups (old_chain
);
4027 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4029 /* If an error occured, warn, but do not return - just reset the
4030 buffer to empty and go on to disable features. */
4031 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4034 warning (_("Remote failure reply: %s"), rs
->buf
);
4039 memset (seen
, 0, sizeof (seen
));
4044 enum packet_support is_supported
;
4045 char *p
, *end
, *name_end
, *value
;
4047 /* First separate out this item from the rest of the packet. If
4048 there's another item after this, we overwrite the separator
4049 (terminated strings are much easier to work with). */
4051 end
= strchr (p
, ';');
4054 end
= p
+ strlen (p
);
4064 warning (_("empty item in \"qSupported\" response"));
4069 name_end
= strchr (p
, '=');
4072 /* This is a name=value entry. */
4073 is_supported
= PACKET_ENABLE
;
4074 value
= name_end
+ 1;
4083 is_supported
= PACKET_ENABLE
;
4087 is_supported
= PACKET_DISABLE
;
4091 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4095 warning (_("unrecognized item \"%s\" "
4096 "in \"qSupported\" response"), p
);
4102 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4103 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4105 const struct protocol_feature
*feature
;
4108 feature
= &remote_protocol_features
[i
];
4109 feature
->func (feature
, is_supported
, value
);
4114 /* If we increased the packet size, make sure to increase the global
4115 buffer size also. We delay this until after parsing the entire
4116 qSupported packet, because this is the same buffer we were
4118 if (rs
->buf_size
< rs
->explicit_packet_size
)
4120 rs
->buf_size
= rs
->explicit_packet_size
;
4121 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4124 /* Handle the defaults for unmentioned features. */
4125 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4128 const struct protocol_feature
*feature
;
4130 feature
= &remote_protocol_features
[i
];
4131 feature
->func (feature
, feature
->default_support
, NULL
);
4137 remote_open_1 (char *name
, int from_tty
,
4138 struct target_ops
*target
, int extended_p
)
4140 struct remote_state
*rs
= get_remote_state ();
4143 error (_("To open a remote debug connection, you need to specify what\n"
4144 "serial device is attached to the remote system\n"
4145 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4147 /* See FIXME above. */
4148 if (!target_async_permitted
)
4149 wait_forever_enabled_p
= 1;
4151 /* If we're connected to a running target, target_preopen will kill it.
4152 But if we're connected to a target system with no running process,
4153 then we will still be connected when it returns. Ask this question
4154 first, before target_preopen has a chance to kill anything. */
4155 if (remote_desc
!= NULL
&& !have_inferiors ())
4158 || query (_("Already connected to a remote target. Disconnect? ")))
4161 error (_("Still connected."));
4164 target_preopen (from_tty
);
4166 unpush_target (target
);
4168 /* This time without a query. If we were connected to an
4169 extended-remote target and target_preopen killed the running
4170 process, we may still be connected. If we are starting "target
4171 remote" now, the extended-remote target will not have been
4172 removed by unpush_target. */
4173 if (remote_desc
!= NULL
&& !have_inferiors ())
4176 /* Make sure we send the passed signals list the next time we resume. */
4177 xfree (last_pass_packet
);
4178 last_pass_packet
= NULL
;
4180 /* Make sure we send the program signals list the next time we
4182 xfree (last_program_signals_packet
);
4183 last_program_signals_packet
= NULL
;
4185 remote_fileio_reset ();
4186 reopen_exec_file ();
4189 remote_desc
= remote_serial_open (name
);
4191 perror_with_name (name
);
4193 if (baud_rate
!= -1)
4195 if (serial_setbaudrate (remote_desc
, baud_rate
))
4197 /* The requested speed could not be set. Error out to
4198 top level after closing remote_desc. Take care to
4199 set remote_desc to NULL to avoid closing remote_desc
4201 serial_close (remote_desc
);
4203 perror_with_name (name
);
4207 serial_raw (remote_desc
);
4209 /* If there is something sitting in the buffer we might take it as a
4210 response to a command, which would be bad. */
4211 serial_flush_input (remote_desc
);
4215 puts_filtered ("Remote debugging using ");
4216 puts_filtered (name
);
4217 puts_filtered ("\n");
4219 push_target (target
); /* Switch to using remote target now. */
4221 /* Register extra event sources in the event loop. */
4222 remote_async_inferior_event_token
4223 = create_async_event_handler (remote_async_inferior_event_handler
,
4225 remote_async_get_pending_events_token
4226 = create_async_event_handler (remote_async_get_pending_events_handler
,
4229 /* Reset the target state; these things will be queried either by
4230 remote_query_supported or as they are needed. */
4231 init_all_packet_configs ();
4232 rs
->cached_wait_status
= 0;
4233 rs
->explicit_packet_size
= 0;
4235 rs
->multi_process_aware
= 0;
4236 rs
->extended
= extended_p
;
4237 rs
->non_stop_aware
= 0;
4238 rs
->waiting_for_stop_reply
= 0;
4239 rs
->ctrlc_pending_p
= 0;
4241 general_thread
= not_sent_ptid
;
4242 continue_thread
= not_sent_ptid
;
4243 remote_traceframe_number
= -1;
4245 /* Probe for ability to use "ThreadInfo" query, as required. */
4246 use_threadinfo_query
= 1;
4247 use_threadextra_query
= 1;
4249 if (target_async_permitted
)
4251 /* With this target we start out by owning the terminal. */
4252 remote_async_terminal_ours_p
= 1;
4254 /* FIXME: cagney/1999-09-23: During the initial connection it is
4255 assumed that the target is already ready and able to respond to
4256 requests. Unfortunately remote_start_remote() eventually calls
4257 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4258 around this. Eventually a mechanism that allows
4259 wait_for_inferior() to expect/get timeouts will be
4261 wait_forever_enabled_p
= 0;
4264 /* First delete any symbols previously loaded from shared libraries. */
4265 no_shared_libraries (NULL
, 0);
4268 init_thread_list ();
4270 /* Start the remote connection. If error() or QUIT, discard this
4271 target (we'd otherwise be in an inconsistent state) and then
4272 propogate the error on up the exception chain. This ensures that
4273 the caller doesn't stumble along blindly assuming that the
4274 function succeeded. The CLI doesn't have this problem but other
4275 UI's, such as MI do.
4277 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4278 this function should return an error indication letting the
4279 caller restore the previous state. Unfortunately the command
4280 ``target remote'' is directly wired to this function making that
4281 impossible. On a positive note, the CLI side of this problem has
4282 been fixed - the function set_cmd_context() makes it possible for
4283 all the ``target ....'' commands to share a common callback
4284 function. See cli-dump.c. */
4286 volatile struct gdb_exception ex
;
4288 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4290 remote_start_remote (from_tty
, target
, extended_p
);
4294 /* Pop the partially set up target - unless something else did
4295 already before throwing the exception. */
4296 if (remote_desc
!= NULL
)
4298 if (target_async_permitted
)
4299 wait_forever_enabled_p
= 1;
4300 throw_exception (ex
);
4304 if (target_async_permitted
)
4305 wait_forever_enabled_p
= 1;
4308 /* This takes a program previously attached to and detaches it. After
4309 this is done, GDB can be used to debug some other program. We
4310 better not have left any breakpoints in the target program or it'll
4311 die when it hits one. */
4314 remote_detach_1 (char *args
, int from_tty
, int extended
)
4316 int pid
= ptid_get_pid (inferior_ptid
);
4317 struct remote_state
*rs
= get_remote_state ();
4320 error (_("Argument given to \"detach\" when remotely debugging."));
4322 if (!target_has_execution
)
4323 error (_("No process to detach from."));
4327 char *exec_file
= get_exec_file (0);
4328 if (exec_file
== NULL
)
4330 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4331 target_pid_to_str (pid_to_ptid (pid
)));
4332 gdb_flush (gdb_stdout
);
4335 /* Tell the remote target to detach. */
4336 if (remote_multi_process_p (rs
))
4337 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4339 strcpy (rs
->buf
, "D");
4342 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4344 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4346 else if (rs
->buf
[0] == '\0')
4347 error (_("Remote doesn't know how to detach"));
4349 error (_("Can't detach process."));
4351 if (from_tty
&& !extended
)
4352 puts_filtered (_("Ending remote debugging.\n"));
4354 discard_pending_stop_replies (pid
);
4355 target_mourn_inferior ();
4359 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4361 remote_detach_1 (args
, from_tty
, 0);
4365 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4367 remote_detach_1 (args
, from_tty
, 1);
4370 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4373 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
4376 error (_("Argument given to \"disconnect\" when remotely debugging."));
4378 /* Make sure we unpush even the extended remote targets; mourn
4379 won't do it. So call remote_mourn_1 directly instead of
4380 target_mourn_inferior. */
4381 remote_mourn_1 (target
);
4384 puts_filtered ("Ending remote debugging.\n");
4387 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4388 be chatty about it. */
4391 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
4393 struct remote_state
*rs
= get_remote_state ();
4395 char *wait_status
= NULL
;
4397 pid
= parse_pid_to_attach (args
);
4399 /* Remote PID can be freely equal to getpid, do not check it here the same
4400 way as in other targets. */
4402 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4403 error (_("This target does not support attaching to a process"));
4407 char *exec_file
= get_exec_file (0);
4410 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4411 target_pid_to_str (pid_to_ptid (pid
)));
4413 printf_unfiltered (_("Attaching to %s\n"),
4414 target_pid_to_str (pid_to_ptid (pid
)));
4416 gdb_flush (gdb_stdout
);
4419 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4421 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4423 if (packet_ok (rs
->buf
,
4424 &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
4428 /* Save the reply for later. */
4429 wait_status
= alloca (strlen (rs
->buf
) + 1);
4430 strcpy (wait_status
, rs
->buf
);
4432 else if (strcmp (rs
->buf
, "OK") != 0)
4433 error (_("Attaching to %s failed with: %s"),
4434 target_pid_to_str (pid_to_ptid (pid
)),
4437 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4438 error (_("This target does not support attaching to a process"));
4440 error (_("Attaching to %s failed"),
4441 target_pid_to_str (pid_to_ptid (pid
)));
4443 set_current_inferior (remote_add_inferior (0, pid
, 1));
4445 inferior_ptid
= pid_to_ptid (pid
);
4449 struct thread_info
*thread
;
4451 /* Get list of threads. */
4452 remote_threads_info (target
);
4454 thread
= first_thread_of_process (pid
);
4456 inferior_ptid
= thread
->ptid
;
4458 inferior_ptid
= pid_to_ptid (pid
);
4460 /* Invalidate our notion of the remote current thread. */
4461 record_currthread (minus_one_ptid
);
4465 /* Now, if we have thread information, update inferior_ptid. */
4466 inferior_ptid
= remote_current_thread (inferior_ptid
);
4468 /* Add the main thread to the thread list. */
4469 add_thread_silent (inferior_ptid
);
4472 /* Next, if the target can specify a description, read it. We do
4473 this before anything involving memory or registers. */
4474 target_find_description ();
4478 /* Use the previously fetched status. */
4479 gdb_assert (wait_status
!= NULL
);
4481 if (target_can_async_p ())
4483 struct stop_reply
*stop_reply
;
4484 struct cleanup
*old_chain
;
4486 stop_reply
= stop_reply_xmalloc ();
4487 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
4488 remote_parse_stop_reply (wait_status
, stop_reply
);
4489 discard_cleanups (old_chain
);
4490 push_stop_reply (stop_reply
);
4492 target_async (inferior_event_handler
, 0);
4496 gdb_assert (wait_status
!= NULL
);
4497 strcpy (rs
->buf
, wait_status
);
4498 rs
->cached_wait_status
= 1;
4502 gdb_assert (wait_status
== NULL
);
4506 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4508 extended_remote_attach_1 (ops
, args
, from_tty
);
4511 /* Convert hex digit A to a number. */
4516 if (a
>= '0' && a
<= '9')
4518 else if (a
>= 'a' && a
<= 'f')
4519 return a
- 'a' + 10;
4520 else if (a
>= 'A' && a
<= 'F')
4521 return a
- 'A' + 10;
4523 error (_("Reply contains invalid hex digit %d"), a
);
4527 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4531 for (i
= 0; i
< count
; i
++)
4533 if (hex
[0] == 0 || hex
[1] == 0)
4535 /* Hex string is short, or of uneven length.
4536 Return the count that has been converted so far. */
4539 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4545 /* Convert number NIB to a hex digit. */
4553 return 'a' + nib
- 10;
4557 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4561 /* May use a length, or a nul-terminated string as input. */
4563 count
= strlen ((char *) bin
);
4565 for (i
= 0; i
< count
; i
++)
4567 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4568 *hex
++ = tohex (*bin
++ & 0xf);
4574 /* Check for the availability of vCont. This function should also check
4578 remote_vcont_probe (struct remote_state
*rs
)
4582 strcpy (rs
->buf
, "vCont?");
4584 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4587 /* Make sure that the features we assume are supported. */
4588 if (strncmp (buf
, "vCont", 5) == 0)
4591 int support_s
, support_S
, support_c
, support_C
;
4597 rs
->support_vCont_t
= 0;
4598 while (p
&& *p
== ';')
4601 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4603 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4605 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4607 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4609 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4610 rs
->support_vCont_t
= 1;
4612 p
= strchr (p
, ';');
4615 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4616 BUF will make packet_ok disable the packet. */
4617 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4621 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4624 /* Helper function for building "vCont" resumptions. Write a
4625 resumption to P. ENDP points to one-passed-the-end of the buffer
4626 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4627 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4628 resumed thread should be single-stepped and/or signalled. If PTID
4629 equals minus_one_ptid, then all threads are resumed; if PTID
4630 represents a process, then all threads of the process are resumed;
4631 the thread to be stepped and/or signalled is given in the global
4635 append_resumption (char *p
, char *endp
,
4636 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4638 struct remote_state
*rs
= get_remote_state ();
4640 if (step
&& siggnal
!= GDB_SIGNAL_0
)
4641 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4643 p
+= xsnprintf (p
, endp
- p
, ";s");
4644 else if (siggnal
!= GDB_SIGNAL_0
)
4645 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4647 p
+= xsnprintf (p
, endp
- p
, ";c");
4649 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4653 /* All (-1) threads of process. */
4654 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4656 p
+= xsnprintf (p
, endp
- p
, ":");
4657 p
= write_ptid (p
, endp
, nptid
);
4659 else if (!ptid_equal (ptid
, minus_one_ptid
))
4661 p
+= xsnprintf (p
, endp
- p
, ":");
4662 p
= write_ptid (p
, endp
, ptid
);
4668 /* Append a vCont continue-with-signal action for threads that have a
4669 non-zero stop signal. */
4672 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
4674 struct thread_info
*thread
;
4676 ALL_THREADS (thread
)
4677 if (ptid_match (thread
->ptid
, ptid
)
4678 && !ptid_equal (inferior_ptid
, thread
->ptid
)
4679 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4680 && signal_pass_state (thread
->suspend
.stop_signal
))
4682 p
= append_resumption (p
, endp
, thread
->ptid
,
4683 0, thread
->suspend
.stop_signal
);
4684 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4690 /* Resume the remote inferior by using a "vCont" packet. The thread
4691 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4692 resumed thread should be single-stepped and/or signalled. If PTID
4693 equals minus_one_ptid, then all threads are resumed; the thread to
4694 be stepped and/or signalled is given in the global INFERIOR_PTID.
4695 This function returns non-zero iff it resumes the inferior.
4697 This function issues a strict subset of all possible vCont commands at the
4701 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4703 struct remote_state
*rs
= get_remote_state ();
4707 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4708 remote_vcont_probe (rs
);
4710 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4714 endp
= rs
->buf
+ get_remote_packet_size ();
4716 /* If we could generate a wider range of packets, we'd have to worry
4717 about overflowing BUF. Should there be a generic
4718 "multi-part-packet" packet? */
4720 p
+= xsnprintf (p
, endp
- p
, "vCont");
4722 if (ptid_equal (ptid
, magic_null_ptid
))
4724 /* MAGIC_NULL_PTID means that we don't have any active threads,
4725 so we don't have any TID numbers the inferior will
4726 understand. Make sure to only send forms that do not specify
4728 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4730 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4732 /* Resume all threads (of all processes, or of a single
4733 process), with preference for INFERIOR_PTID. This assumes
4734 inferior_ptid belongs to the set of all threads we are about
4736 if (step
|| siggnal
!= GDB_SIGNAL_0
)
4738 /* Step inferior_ptid, with or without signal. */
4739 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4742 /* Also pass down any pending signaled resumption for other
4743 threads not the current. */
4744 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
4746 /* And continue others without a signal. */
4747 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
4751 /* Scheduler locking; resume only PTID. */
4752 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4755 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4760 /* In non-stop, the stub replies to vCont with "OK". The stop
4761 reply will be reported asynchronously by means of a `%Stop'
4763 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4764 if (strcmp (rs
->buf
, "OK") != 0)
4765 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4771 /* Tell the remote machine to resume. */
4773 static enum gdb_signal last_sent_signal
= GDB_SIGNAL_0
;
4775 static int last_sent_step
;
4778 remote_resume (struct target_ops
*ops
,
4779 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4781 struct remote_state
*rs
= get_remote_state ();
4784 last_sent_signal
= siggnal
;
4785 last_sent_step
= step
;
4787 /* The vCont packet doesn't need to specify threads via Hc. */
4788 /* No reverse support (yet) for vCont. */
4789 if (execution_direction
!= EXEC_REVERSE
)
4790 if (remote_vcont_resume (ptid
, step
, siggnal
))
4793 /* All other supported resume packets do use Hc, so set the continue
4795 if (ptid_equal (ptid
, minus_one_ptid
))
4796 set_continue_thread (any_thread_ptid
);
4798 set_continue_thread (ptid
);
4801 if (execution_direction
== EXEC_REVERSE
)
4803 /* We don't pass signals to the target in reverse exec mode. */
4804 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
4805 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4809 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4810 error (_("Remote reverse-step not supported."));
4812 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4813 error (_("Remote reverse-continue not supported."));
4815 strcpy (buf
, step
? "bs" : "bc");
4817 else if (siggnal
!= GDB_SIGNAL_0
)
4819 buf
[0] = step
? 'S' : 'C';
4820 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4821 buf
[2] = tohex (((int) siggnal
) & 0xf);
4825 strcpy (buf
, step
? "s" : "c");
4830 /* We are about to start executing the inferior, let's register it
4831 with the event loop. NOTE: this is the one place where all the
4832 execution commands end up. We could alternatively do this in each
4833 of the execution commands in infcmd.c. */
4834 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4835 into infcmd.c in order to allow inferior function calls to work
4836 NOT asynchronously. */
4837 if (target_can_async_p ())
4838 target_async (inferior_event_handler
, 0);
4840 /* We've just told the target to resume. The remote server will
4841 wait for the inferior to stop, and then send a stop reply. In
4842 the mean time, we can't start another command/query ourselves
4843 because the stub wouldn't be ready to process it. This applies
4844 only to the base all-stop protocol, however. In non-stop (which
4845 only supports vCont), the stub replies with an "OK", and is
4846 immediate able to process further serial input. */
4848 rs
->waiting_for_stop_reply
= 1;
4852 /* Set up the signal handler for SIGINT, while the target is
4853 executing, ovewriting the 'regular' SIGINT signal handler. */
4855 initialize_sigint_signal_handler (void)
4857 signal (SIGINT
, handle_remote_sigint
);
4860 /* Signal handler for SIGINT, while the target is executing. */
4862 handle_remote_sigint (int sig
)
4864 signal (sig
, handle_remote_sigint_twice
);
4865 mark_async_signal_handler_wrapper (sigint_remote_token
);
4868 /* Signal handler for SIGINT, installed after SIGINT has already been
4869 sent once. It will take effect the second time that the user sends
4872 handle_remote_sigint_twice (int sig
)
4874 signal (sig
, handle_remote_sigint
);
4875 mark_async_signal_handler_wrapper (sigint_remote_twice_token
);
4878 /* Perform the real interruption of the target execution, in response
4881 async_remote_interrupt (gdb_client_data arg
)
4884 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
4886 target_stop (inferior_ptid
);
4889 /* Perform interrupt, if the first attempt did not succeed. Just give
4890 up on the target alltogether. */
4892 async_remote_interrupt_twice (gdb_client_data arg
)
4895 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
4900 /* Reinstall the usual SIGINT handlers, after the target has
4903 cleanup_sigint_signal_handler (void *dummy
)
4905 signal (SIGINT
, handle_sigint
);
4908 /* Send ^C to target to halt it. Target will respond, and send us a
4910 static void (*ofunc
) (int);
4912 /* The command line interface's stop routine. This function is installed
4913 as a signal handler for SIGINT. The first time a user requests a
4914 stop, we call remote_stop to send a break or ^C. If there is no
4915 response from the target (it didn't stop when the user requested it),
4916 we ask the user if he'd like to detach from the target. */
4918 remote_interrupt (int signo
)
4920 /* If this doesn't work, try more severe steps. */
4921 signal (signo
, remote_interrupt_twice
);
4923 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4926 /* The user typed ^C twice. */
4929 remote_interrupt_twice (int signo
)
4931 signal (signo
, ofunc
);
4932 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4933 signal (signo
, remote_interrupt
);
4936 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4937 thread, all threads of a remote process, or all threads of all
4941 remote_stop_ns (ptid_t ptid
)
4943 struct remote_state
*rs
= get_remote_state ();
4945 char *endp
= rs
->buf
+ get_remote_packet_size ();
4947 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4948 remote_vcont_probe (rs
);
4950 if (!rs
->support_vCont_t
)
4951 error (_("Remote server does not support stopping threads"));
4953 if (ptid_equal (ptid
, minus_one_ptid
)
4954 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
4955 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
4960 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
4962 if (ptid_is_pid (ptid
))
4963 /* All (-1) threads of process. */
4964 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4967 /* Small optimization: if we already have a stop reply for
4968 this thread, no use in telling the stub we want this
4970 if (peek_stop_reply (ptid
))
4976 write_ptid (p
, endp
, nptid
);
4979 /* In non-stop, we get an immediate OK reply. The stop reply will
4980 come in asynchronously by notification. */
4982 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4983 if (strcmp (rs
->buf
, "OK") != 0)
4984 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
4987 /* All-stop version of target_stop. Sends a break or a ^C to stop the
4988 remote target. It is undefined which thread of which process
4989 reports the stop. */
4992 remote_stop_as (ptid_t ptid
)
4994 struct remote_state
*rs
= get_remote_state ();
4996 rs
->ctrlc_pending_p
= 1;
4998 /* If the inferior is stopped already, but the core didn't know
4999 about it yet, just ignore the request. The cached wait status
5000 will be collected in remote_wait. */
5001 if (rs
->cached_wait_status
)
5004 /* Send interrupt_sequence to remote target. */
5005 send_interrupt_sequence ();
5008 /* This is the generic stop called via the target vector. When a target
5009 interrupt is requested, either by the command line or the GUI, we
5010 will eventually end up here. */
5013 remote_stop (ptid_t ptid
)
5016 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5019 remote_stop_ns (ptid
);
5021 remote_stop_as (ptid
);
5024 /* Ask the user what to do when an interrupt is received. */
5027 interrupt_query (void)
5029 target_terminal_ours ();
5031 if (target_can_async_p ())
5033 signal (SIGINT
, handle_sigint
);
5034 deprecated_throw_reason (RETURN_QUIT
);
5038 if (query (_("Interrupted while waiting for the program.\n\
5039 Give up (and stop debugging it)? ")))
5042 deprecated_throw_reason (RETURN_QUIT
);
5046 target_terminal_inferior ();
5049 /* Enable/disable target terminal ownership. Most targets can use
5050 terminal groups to control terminal ownership. Remote targets are
5051 different in that explicit transfer of ownership to/from GDB/target
5055 remote_terminal_inferior (void)
5057 if (!target_async_permitted
)
5058 /* Nothing to do. */
5061 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5062 idempotent. The event-loop GDB talking to an asynchronous target
5063 with a synchronous command calls this function from both
5064 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5065 transfer the terminal to the target when it shouldn't this guard
5067 if (!remote_async_terminal_ours_p
)
5069 delete_file_handler (input_fd
);
5070 remote_async_terminal_ours_p
= 0;
5071 initialize_sigint_signal_handler ();
5072 /* NOTE: At this point we could also register our selves as the
5073 recipient of all input. Any characters typed could then be
5074 passed on down to the target. */
5078 remote_terminal_ours (void)
5080 if (!target_async_permitted
)
5081 /* Nothing to do. */
5084 /* See FIXME in remote_terminal_inferior. */
5085 if (remote_async_terminal_ours_p
)
5087 cleanup_sigint_signal_handler (NULL
);
5088 add_file_handler (input_fd
, stdin_event_handler
, 0);
5089 remote_async_terminal_ours_p
= 1;
5093 remote_console_output (char *msg
)
5097 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5100 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5104 fputs_unfiltered (tb
, gdb_stdtarg
);
5106 gdb_flush (gdb_stdtarg
);
5109 typedef struct cached_reg
5112 gdb_byte data
[MAX_REGISTER_SIZE
];
5115 DEF_VEC_O(cached_reg_t
);
5119 struct stop_reply
*next
;
5123 struct target_waitstatus ws
;
5125 /* Expedited registers. This makes remote debugging a bit more
5126 efficient for those targets that provide critical registers as
5127 part of their normal status mechanism (as another roundtrip to
5128 fetch them is avoided). */
5129 VEC(cached_reg_t
) *regcache
;
5131 int stopped_by_watchpoint_p
;
5132 CORE_ADDR watch_data_address
;
5140 /* The list of already fetched and acknowledged stop events. */
5141 static struct stop_reply
*stop_reply_queue
;
5143 static struct stop_reply
*
5144 stop_reply_xmalloc (void)
5146 struct stop_reply
*r
= XMALLOC (struct stop_reply
);
5153 stop_reply_xfree (struct stop_reply
*r
)
5157 VEC_free (cached_reg_t
, r
->regcache
);
5162 /* Discard all pending stop replies of inferior PID. If PID is -1,
5163 discard everything. */
5166 discard_pending_stop_replies (int pid
)
5168 struct stop_reply
*prev
= NULL
, *reply
, *next
;
5170 /* Discard the in-flight notification. */
5171 if (pending_stop_reply
!= NULL
5173 || ptid_get_pid (pending_stop_reply
->ptid
) == pid
))
5175 stop_reply_xfree (pending_stop_reply
);
5176 pending_stop_reply
= NULL
;
5179 /* Discard the stop replies we have already pulled with
5181 for (reply
= stop_reply_queue
; reply
; reply
= next
)
5185 || ptid_get_pid (reply
->ptid
) == pid
)
5187 if (reply
== stop_reply_queue
)
5188 stop_reply_queue
= reply
->next
;
5190 prev
->next
= reply
->next
;
5192 stop_reply_xfree (reply
);
5199 /* Cleanup wrapper. */
5202 do_stop_reply_xfree (void *arg
)
5204 struct stop_reply
*r
= arg
;
5206 stop_reply_xfree (r
);
5209 /* Look for a queued stop reply belonging to PTID. If one is found,
5210 remove it from the queue, and return it. Returns NULL if none is
5211 found. If there are still queued events left to process, tell the
5212 event loop to get back to target_wait soon. */
5214 static struct stop_reply
*
5215 queued_stop_reply (ptid_t ptid
)
5217 struct stop_reply
*it
;
5218 struct stop_reply
**it_link
;
5220 it
= stop_reply_queue
;
5221 it_link
= &stop_reply_queue
;
5224 if (ptid_match (it
->ptid
, ptid
))
5226 *it_link
= it
->next
;
5231 it_link
= &it
->next
;
5235 if (stop_reply_queue
)
5236 /* There's still at least an event left. */
5237 mark_async_event_handler (remote_async_inferior_event_token
);
5242 /* Push a fully parsed stop reply in the stop reply queue. Since we
5243 know that we now have at least one queued event left to pass to the
5244 core side, tell the event loop to get back to target_wait soon. */
5247 push_stop_reply (struct stop_reply
*new_event
)
5249 struct stop_reply
*event
;
5251 if (stop_reply_queue
)
5253 for (event
= stop_reply_queue
;
5254 event
&& event
->next
;
5255 event
= event
->next
)
5258 event
->next
= new_event
;
5261 stop_reply_queue
= new_event
;
5263 mark_async_event_handler (remote_async_inferior_event_token
);
5266 /* Returns true if we have a stop reply for PTID. */
5269 peek_stop_reply (ptid_t ptid
)
5271 struct stop_reply
*it
;
5273 for (it
= stop_reply_queue
; it
; it
= it
->next
)
5274 if (ptid_equal (ptid
, it
->ptid
))
5276 if (it
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
5283 /* Parse the stop reply in BUF. Either the function succeeds, and the
5284 result is stored in EVENT, or throws an error. */
5287 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5289 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5293 event
->ptid
= null_ptid
;
5294 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5295 event
->ws
.value
.integer
= 0;
5296 event
->solibs_changed
= 0;
5297 event
->replay_event
= 0;
5298 event
->stopped_by_watchpoint_p
= 0;
5299 event
->regcache
= NULL
;
5304 case 'T': /* Status with PC, SP, FP, ... */
5305 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5306 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5308 n... = register number
5309 r... = register contents
5312 p
= &buf
[3]; /* after Txx */
5320 /* If the packet contains a register number, save it in
5321 pnum and set p1 to point to the character following it.
5322 Otherwise p1 points to p. */
5324 /* If this packet is an awatch packet, don't parse the 'a'
5325 as a register number. */
5327 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5328 && strncmp (p
, "core", strlen ("core") != 0))
5330 /* Read the ``P'' register number. */
5331 pnum
= strtol (p
, &p_temp
, 16);
5337 if (p1
== p
) /* No register number present here. */
5339 p1
= strchr (p
, ':');
5341 error (_("Malformed packet(a) (missing colon): %s\n\
5344 if (strncmp (p
, "thread", p1
- p
) == 0)
5345 event
->ptid
= read_ptid (++p1
, &p
);
5346 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5347 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5348 || (strncmp (p
, "awatch", p1
- p
) == 0))
5350 event
->stopped_by_watchpoint_p
= 1;
5351 p
= unpack_varlen_hex (++p1
, &addr
);
5352 event
->watch_data_address
= (CORE_ADDR
) addr
;
5354 else if (strncmp (p
, "library", p1
- p
) == 0)
5358 while (*p_temp
&& *p_temp
!= ';')
5361 event
->solibs_changed
= 1;
5364 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5366 /* NO_HISTORY event.
5367 p1 will indicate "begin" or "end", but
5368 it makes no difference for now, so ignore it. */
5369 event
->replay_event
= 1;
5370 p_temp
= strchr (p1
+ 1, ';');
5374 else if (strncmp (p
, "core", p1
- p
) == 0)
5378 p
= unpack_varlen_hex (++p1
, &c
);
5383 /* Silently skip unknown optional info. */
5384 p_temp
= strchr (p1
+ 1, ';');
5391 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5392 cached_reg_t cached_reg
;
5397 error (_("Malformed packet(b) (missing colon): %s\n\
5403 error (_("Remote sent bad register number %s: %s\n\
5405 hex_string (pnum
), p
, buf
);
5407 cached_reg
.num
= reg
->regnum
;
5409 fieldsize
= hex2bin (p
, cached_reg
.data
,
5410 register_size (target_gdbarch
,
5413 if (fieldsize
< register_size (target_gdbarch
,
5415 warning (_("Remote reply is too short: %s"), buf
);
5417 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5421 error (_("Remote register badly formatted: %s\nhere: %s"),
5426 case 'S': /* Old style status, just signal only. */
5427 if (event
->solibs_changed
)
5428 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5429 else if (event
->replay_event
)
5430 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5433 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5434 event
->ws
.value
.sig
= (enum gdb_signal
)
5435 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
5438 case 'W': /* Target exited. */
5445 /* GDB used to accept only 2 hex chars here. Stubs should
5446 only send more if they detect GDB supports multi-process
5448 p
= unpack_varlen_hex (&buf
[1], &value
);
5452 /* The remote process exited. */
5453 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5454 event
->ws
.value
.integer
= value
;
5458 /* The remote process exited with a signal. */
5459 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5460 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
5463 /* If no process is specified, assume inferior_ptid. */
5464 pid
= ptid_get_pid (inferior_ptid
);
5473 else if (strncmp (p
,
5474 "process:", sizeof ("process:") - 1) == 0)
5478 p
+= sizeof ("process:") - 1;
5479 unpack_varlen_hex (p
, &upid
);
5483 error (_("unknown stop reply packet: %s"), buf
);
5486 error (_("unknown stop reply packet: %s"), buf
);
5487 event
->ptid
= pid_to_ptid (pid
);
5492 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5493 error (_("No process or thread specified in stop reply: %s"), buf
);
5496 /* When the stub wants to tell GDB about a new stop reply, it sends a
5497 stop notification (%Stop). Those can come it at any time, hence,
5498 we have to make sure that any pending putpkt/getpkt sequence we're
5499 making is finished, before querying the stub for more events with
5500 vStopped. E.g., if we started a vStopped sequence immediatelly
5501 upon receiving the %Stop notification, something like this could
5509 1.6) <-- (registers reply to step #1.3)
5511 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5514 To solve this, whenever we parse a %Stop notification sucessfully,
5515 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5516 doing whatever we were doing:
5522 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5523 2.5) <-- (registers reply to step #2.3)
5525 Eventualy after step #2.5, we return to the event loop, which
5526 notices there's an event on the
5527 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5528 associated callback --- the function below. At this point, we're
5529 always safe to start a vStopped sequence. :
5532 2.7) <-- T05 thread:2
5538 remote_get_pending_stop_replies (void)
5540 struct remote_state
*rs
= get_remote_state ();
5542 if (pending_stop_reply
)
5545 putpkt ("vStopped");
5547 /* Now we can rely on it. */
5548 push_stop_reply (pending_stop_reply
);
5549 pending_stop_reply
= NULL
;
5553 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5554 if (strcmp (rs
->buf
, "OK") == 0)
5558 struct cleanup
*old_chain
;
5559 struct stop_reply
*stop_reply
= stop_reply_xmalloc ();
5561 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5562 remote_parse_stop_reply (rs
->buf
, stop_reply
);
5565 putpkt ("vStopped");
5567 if (stop_reply
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
5569 /* Now we can rely on it. */
5570 discard_cleanups (old_chain
);
5571 push_stop_reply (stop_reply
);
5574 /* We got an unknown stop reply. */
5575 do_cleanups (old_chain
);
5582 /* Called when it is decided that STOP_REPLY holds the info of the
5583 event that is to be returned to the core. This function always
5584 destroys STOP_REPLY. */
5587 process_stop_reply (struct stop_reply
*stop_reply
,
5588 struct target_waitstatus
*status
)
5592 *status
= stop_reply
->ws
;
5593 ptid
= stop_reply
->ptid
;
5595 /* If no thread/process was reported by the stub, assume the current
5597 if (ptid_equal (ptid
, null_ptid
))
5598 ptid
= inferior_ptid
;
5600 if (status
->kind
!= TARGET_WAITKIND_EXITED
5601 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5603 /* Expedited registers. */
5604 if (stop_reply
->regcache
)
5606 struct regcache
*regcache
5607 = get_thread_arch_regcache (ptid
, target_gdbarch
);
5612 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5614 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5615 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5618 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5619 remote_watch_data_address
= stop_reply
->watch_data_address
;
5621 remote_notice_new_inferior (ptid
, 0);
5622 demand_private_info (ptid
)->core
= stop_reply
->core
;
5625 stop_reply_xfree (stop_reply
);
5629 /* The non-stop mode version of target_wait. */
5632 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5634 struct remote_state
*rs
= get_remote_state ();
5635 struct stop_reply
*stop_reply
;
5638 /* If in non-stop mode, get out of getpkt even if a
5639 notification is received. */
5641 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5648 case 'E': /* Error of some sort. */
5649 /* We're out of sync with the target now. Did it continue
5650 or not? We can't tell which thread it was in non-stop,
5651 so just ignore this. */
5652 warning (_("Remote failure reply: %s"), rs
->buf
);
5654 case 'O': /* Console output. */
5655 remote_console_output (rs
->buf
+ 1);
5658 warning (_("Invalid remote reply: %s"), rs
->buf
);
5662 /* Acknowledge a pending stop reply that may have arrived in the
5664 if (pending_stop_reply
!= NULL
)
5665 remote_get_pending_stop_replies ();
5667 /* If indeed we noticed a stop reply, we're done. */
5668 stop_reply
= queued_stop_reply (ptid
);
5669 if (stop_reply
!= NULL
)
5670 return process_stop_reply (stop_reply
, status
);
5672 /* Still no event. If we're just polling for an event, then
5673 return to the event loop. */
5674 if (options
& TARGET_WNOHANG
)
5676 status
->kind
= TARGET_WAITKIND_IGNORE
;
5677 return minus_one_ptid
;
5680 /* Otherwise do a blocking wait. */
5681 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5686 /* Wait until the remote machine stops, then return, storing status in
5687 STATUS just as `wait' would. */
5690 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5692 struct remote_state
*rs
= get_remote_state ();
5693 ptid_t event_ptid
= null_ptid
;
5695 struct stop_reply
*stop_reply
;
5699 status
->kind
= TARGET_WAITKIND_IGNORE
;
5700 status
->value
.integer
= 0;
5702 stop_reply
= queued_stop_reply (ptid
);
5703 if (stop_reply
!= NULL
)
5704 return process_stop_reply (stop_reply
, status
);
5706 if (rs
->cached_wait_status
)
5707 /* Use the cached wait status, but only once. */
5708 rs
->cached_wait_status
= 0;
5713 if (!target_is_async_p ())
5715 ofunc
= signal (SIGINT
, remote_interrupt
);
5716 /* If the user hit C-c before this packet, or between packets,
5717 pretend that it was hit right here. */
5718 if (check_quit_flag ())
5721 remote_interrupt (SIGINT
);
5725 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5726 _never_ wait for ever -> test on target_is_async_p().
5727 However, before we do that we need to ensure that the caller
5728 knows how to take the target into/out of async mode. */
5729 ret
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, wait_forever_enabled_p
);
5730 if (!target_is_async_p ())
5731 signal (SIGINT
, ofunc
);
5736 remote_stopped_by_watchpoint_p
= 0;
5738 /* We got something. */
5739 rs
->waiting_for_stop_reply
= 0;
5741 /* Assume that the target has acknowledged Ctrl-C unless we receive
5742 an 'F' or 'O' packet. */
5743 if (buf
[0] != 'F' && buf
[0] != 'O')
5744 rs
->ctrlc_pending_p
= 0;
5748 case 'E': /* Error of some sort. */
5749 /* We're out of sync with the target now. Did it continue or
5750 not? Not is more likely, so report a stop. */
5751 warning (_("Remote failure reply: %s"), buf
);
5752 status
->kind
= TARGET_WAITKIND_STOPPED
;
5753 status
->value
.sig
= GDB_SIGNAL_0
;
5755 case 'F': /* File-I/O request. */
5756 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5757 rs
->ctrlc_pending_p
= 0;
5759 case 'T': case 'S': case 'X': case 'W':
5761 struct stop_reply
*stop_reply
;
5762 struct cleanup
*old_chain
;
5764 stop_reply
= stop_reply_xmalloc ();
5765 old_chain
= make_cleanup (do_stop_reply_xfree
, stop_reply
);
5766 remote_parse_stop_reply (buf
, stop_reply
);
5767 discard_cleanups (old_chain
);
5768 event_ptid
= process_stop_reply (stop_reply
, status
);
5771 case 'O': /* Console output. */
5772 remote_console_output (buf
+ 1);
5774 /* The target didn't really stop; keep waiting. */
5775 rs
->waiting_for_stop_reply
= 1;
5779 if (last_sent_signal
!= GDB_SIGNAL_0
)
5781 /* Zero length reply means that we tried 'S' or 'C' and the
5782 remote system doesn't support it. */
5783 target_terminal_ours_for_output ();
5785 ("Can't send signals to this remote system. %s not sent.\n",
5786 gdb_signal_to_name (last_sent_signal
));
5787 last_sent_signal
= GDB_SIGNAL_0
;
5788 target_terminal_inferior ();
5790 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
5791 putpkt ((char *) buf
);
5793 /* We just told the target to resume, so a stop reply is in
5795 rs
->waiting_for_stop_reply
= 1;
5798 /* else fallthrough */
5800 warning (_("Invalid remote reply: %s"), buf
);
5802 rs
->waiting_for_stop_reply
= 1;
5806 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5808 /* Nothing interesting happened. If we're doing a non-blocking
5809 poll, we're done. Otherwise, go back to waiting. */
5810 if (options
& TARGET_WNOHANG
)
5811 return minus_one_ptid
;
5815 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5816 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5818 if (!ptid_equal (event_ptid
, null_ptid
))
5819 record_currthread (event_ptid
);
5821 event_ptid
= inferior_ptid
;
5824 /* A process exit. Invalidate our notion of current thread. */
5825 record_currthread (minus_one_ptid
);
5830 /* Wait until the remote machine stops, then return, storing status in
5831 STATUS just as `wait' would. */
5834 remote_wait (struct target_ops
*ops
,
5835 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5840 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5842 event_ptid
= remote_wait_as (ptid
, status
, options
);
5844 if (target_can_async_p ())
5846 /* If there are are events left in the queue tell the event loop
5848 if (stop_reply_queue
)
5849 mark_async_event_handler (remote_async_inferior_event_token
);
5855 /* Fetch a single register using a 'p' packet. */
5858 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
5860 struct remote_state
*rs
= get_remote_state ();
5862 char regp
[MAX_REGISTER_SIZE
];
5865 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
5868 if (reg
->pnum
== -1)
5873 p
+= hexnumstr (p
, reg
->pnum
);
5876 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5880 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
5884 case PACKET_UNKNOWN
:
5887 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
5888 gdbarch_register_name (get_regcache_arch (regcache
),
5893 /* If this register is unfetchable, tell the regcache. */
5896 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
5900 /* Otherwise, parse and supply the value. */
5906 error (_("fetch_register_using_p: early buf termination"));
5908 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
5911 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
5915 /* Fetch the registers included in the target's 'g' packet. */
5918 send_g_packet (void)
5920 struct remote_state
*rs
= get_remote_state ();
5923 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
5924 remote_send (&rs
->buf
, &rs
->buf_size
);
5926 /* We can get out of synch in various cases. If the first character
5927 in the buffer is not a hex character, assume that has happened
5928 and try to fetch another packet to read. */
5929 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
5930 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
5931 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
5932 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
5935 fprintf_unfiltered (gdb_stdlog
,
5936 "Bad register packet; fetching a new packet\n");
5937 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5940 buf_len
= strlen (rs
->buf
);
5942 /* Sanity check the received packet. */
5943 if (buf_len
% 2 != 0)
5944 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
5950 process_g_packet (struct regcache
*regcache
)
5952 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
5953 struct remote_state
*rs
= get_remote_state ();
5954 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5959 buf_len
= strlen (rs
->buf
);
5961 /* Further sanity checks, with knowledge of the architecture. */
5962 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
5963 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
5965 /* Save the size of the packet sent to us by the target. It is used
5966 as a heuristic when determining the max size of packets that the
5967 target can safely receive. */
5968 if (rsa
->actual_register_packet_size
== 0)
5969 rsa
->actual_register_packet_size
= buf_len
;
5971 /* If this is smaller than we guessed the 'g' packet would be,
5972 update our records. A 'g' reply that doesn't include a register's
5973 value implies either that the register is not available, or that
5974 the 'p' packet must be used. */
5975 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
5977 rsa
->sizeof_g_packet
= buf_len
/ 2;
5979 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
5981 if (rsa
->regs
[i
].pnum
== -1)
5984 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
5985 rsa
->regs
[i
].in_g_packet
= 0;
5987 rsa
->regs
[i
].in_g_packet
= 1;
5991 regs
= alloca (rsa
->sizeof_g_packet
);
5993 /* Unimplemented registers read as all bits zero. */
5994 memset (regs
, 0, rsa
->sizeof_g_packet
);
5996 /* Reply describes registers byte by byte, each byte encoded as two
5997 hex characters. Suck them all up, then supply them to the
5998 register cacheing/storage mechanism. */
6001 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6003 if (p
[0] == 0 || p
[1] == 0)
6004 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6005 internal_error (__FILE__
, __LINE__
,
6006 _("unexpected end of 'g' packet reply"));
6008 if (p
[0] == 'x' && p
[1] == 'x')
6009 regs
[i
] = 0; /* 'x' */
6011 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6015 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6017 struct packet_reg
*r
= &rsa
->regs
[i
];
6021 if (r
->offset
* 2 >= strlen (rs
->buf
))
6022 /* This shouldn't happen - we adjusted in_g_packet above. */
6023 internal_error (__FILE__
, __LINE__
,
6024 _("unexpected end of 'g' packet reply"));
6025 else if (rs
->buf
[r
->offset
* 2] == 'x')
6027 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6028 /* The register isn't available, mark it as such (at
6029 the same time setting the value to zero). */
6030 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6033 regcache_raw_supply (regcache
, r
->regnum
,
6040 fetch_registers_using_g (struct regcache
*regcache
)
6043 process_g_packet (regcache
);
6046 /* Make the remote selected traceframe match GDB's selected
6050 set_remote_traceframe (void)
6054 if (remote_traceframe_number
== get_traceframe_number ())
6057 /* Avoid recursion, remote_trace_find calls us again. */
6058 remote_traceframe_number
= get_traceframe_number ();
6060 newnum
= target_trace_find (tfind_number
,
6061 get_traceframe_number (), 0, 0, NULL
);
6063 /* Should not happen. If it does, all bets are off. */
6064 if (newnum
!= get_traceframe_number ())
6065 warning (_("could not set remote traceframe"));
6069 remote_fetch_registers (struct target_ops
*ops
,
6070 struct regcache
*regcache
, int regnum
)
6072 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6075 set_remote_traceframe ();
6076 set_general_thread (inferior_ptid
);
6080 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6082 gdb_assert (reg
!= NULL
);
6084 /* If this register might be in the 'g' packet, try that first -
6085 we are likely to read more than one register. If this is the
6086 first 'g' packet, we might be overly optimistic about its
6087 contents, so fall back to 'p'. */
6088 if (reg
->in_g_packet
)
6090 fetch_registers_using_g (regcache
);
6091 if (reg
->in_g_packet
)
6095 if (fetch_register_using_p (regcache
, reg
))
6098 /* This register is not available. */
6099 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6104 fetch_registers_using_g (regcache
);
6106 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6107 if (!rsa
->regs
[i
].in_g_packet
)
6108 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6110 /* This register is not available. */
6111 regcache_raw_supply (regcache
, i
, NULL
);
6115 /* Prepare to store registers. Since we may send them all (using a
6116 'G' request), we have to read out the ones we don't want to change
6120 remote_prepare_to_store (struct regcache
*regcache
)
6122 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6124 gdb_byte buf
[MAX_REGISTER_SIZE
];
6126 /* Make sure the entire registers array is valid. */
6127 switch (remote_protocol_packets
[PACKET_P
].support
)
6129 case PACKET_DISABLE
:
6130 case PACKET_SUPPORT_UNKNOWN
:
6131 /* Make sure all the necessary registers are cached. */
6132 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6133 if (rsa
->regs
[i
].in_g_packet
)
6134 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6141 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6142 packet was not recognized. */
6145 store_register_using_P (const struct regcache
*regcache
,
6146 struct packet_reg
*reg
)
6148 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6149 struct remote_state
*rs
= get_remote_state ();
6150 /* Try storing a single register. */
6151 char *buf
= rs
->buf
;
6152 gdb_byte regp
[MAX_REGISTER_SIZE
];
6155 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
6158 if (reg
->pnum
== -1)
6161 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6162 p
= buf
+ strlen (buf
);
6163 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6164 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6166 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6168 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6173 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6174 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6175 case PACKET_UNKNOWN
:
6178 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6182 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6183 contents of the register cache buffer. FIXME: ignores errors. */
6186 store_registers_using_G (const struct regcache
*regcache
)
6188 struct remote_state
*rs
= get_remote_state ();
6189 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6193 /* Extract all the registers in the regcache copying them into a
6198 regs
= alloca (rsa
->sizeof_g_packet
);
6199 memset (regs
, 0, rsa
->sizeof_g_packet
);
6200 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6202 struct packet_reg
*r
= &rsa
->regs
[i
];
6205 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6209 /* Command describes registers byte by byte,
6210 each byte encoded as two hex characters. */
6213 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6215 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6217 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6218 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6219 error (_("Could not write registers; remote failure reply '%s'"),
6223 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6224 of the register cache buffer. FIXME: ignores errors. */
6227 remote_store_registers (struct target_ops
*ops
,
6228 struct regcache
*regcache
, int regnum
)
6230 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6233 set_remote_traceframe ();
6234 set_general_thread (inferior_ptid
);
6238 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6240 gdb_assert (reg
!= NULL
);
6242 /* Always prefer to store registers using the 'P' packet if
6243 possible; we often change only a small number of registers.
6244 Sometimes we change a larger number; we'd need help from a
6245 higher layer to know to use 'G'. */
6246 if (store_register_using_P (regcache
, reg
))
6249 /* For now, don't complain if we have no way to write the
6250 register. GDB loses track of unavailable registers too
6251 easily. Some day, this may be an error. We don't have
6252 any way to read the register, either... */
6253 if (!reg
->in_g_packet
)
6256 store_registers_using_G (regcache
);
6260 store_registers_using_G (regcache
);
6262 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6263 if (!rsa
->regs
[i
].in_g_packet
)
6264 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6265 /* See above for why we do not issue an error here. */
6270 /* Return the number of hex digits in num. */
6273 hexnumlen (ULONGEST num
)
6277 for (i
= 0; num
!= 0; i
++)
6283 /* Set BUF to the minimum number of hex digits representing NUM. */
6286 hexnumstr (char *buf
, ULONGEST num
)
6288 int len
= hexnumlen (num
);
6290 return hexnumnstr (buf
, num
, len
);
6294 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6297 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6303 for (i
= width
- 1; i
>= 0; i
--)
6305 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6312 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6315 remote_address_masked (CORE_ADDR addr
)
6317 unsigned int address_size
= remote_address_size
;
6319 /* If "remoteaddresssize" was not set, default to target address size. */
6321 address_size
= gdbarch_addr_bit (target_gdbarch
);
6323 if (address_size
> 0
6324 && address_size
< (sizeof (ULONGEST
) * 8))
6326 /* Only create a mask when that mask can safely be constructed
6327 in a ULONGEST variable. */
6330 mask
= (mask
<< address_size
) - 1;
6336 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
6337 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
6338 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
6339 (which may be more than *OUT_LEN due to escape characters). The
6340 total number of bytes in the output buffer will be at most
6344 remote_escape_output (const gdb_byte
*buffer
, int len
,
6345 gdb_byte
*out_buf
, int *out_len
,
6348 int input_index
, output_index
;
6351 for (input_index
= 0; input_index
< len
; input_index
++)
6353 gdb_byte b
= buffer
[input_index
];
6355 if (b
== '$' || b
== '#' || b
== '}')
6357 /* These must be escaped. */
6358 if (output_index
+ 2 > out_maxlen
)
6360 out_buf
[output_index
++] = '}';
6361 out_buf
[output_index
++] = b
^ 0x20;
6365 if (output_index
+ 1 > out_maxlen
)
6367 out_buf
[output_index
++] = b
;
6371 *out_len
= input_index
;
6372 return output_index
;
6375 /* Convert BUFFER, escaped data LEN bytes long, into binary data
6376 in OUT_BUF. Return the number of bytes written to OUT_BUF.
6377 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
6379 This function reverses remote_escape_output. It allows more
6380 escaped characters than that function does, in particular because
6381 '*' must be escaped to avoid the run-length encoding processing
6382 in reading packets. */
6385 remote_unescape_input (const gdb_byte
*buffer
, int len
,
6386 gdb_byte
*out_buf
, int out_maxlen
)
6388 int input_index
, output_index
;
6393 for (input_index
= 0; input_index
< len
; input_index
++)
6395 gdb_byte b
= buffer
[input_index
];
6397 if (output_index
+ 1 > out_maxlen
)
6399 warning (_("Received too much data from remote target;"
6400 " ignoring overflow."));
6401 return output_index
;
6406 out_buf
[output_index
++] = b
^ 0x20;
6412 out_buf
[output_index
++] = b
;
6416 error (_("Unmatched escape character in target response."));
6418 return output_index
;
6421 /* Determine whether the remote target supports binary downloading.
6422 This is accomplished by sending a no-op memory write of zero length
6423 to the target at the specified address. It does not suffice to send
6424 the whole packet, since many stubs strip the eighth bit and
6425 subsequently compute a wrong checksum, which causes real havoc with
6428 NOTE: This can still lose if the serial line is not eight-bit
6429 clean. In cases like this, the user should clear "remote
6433 check_binary_download (CORE_ADDR addr
)
6435 struct remote_state
*rs
= get_remote_state ();
6437 switch (remote_protocol_packets
[PACKET_X
].support
)
6439 case PACKET_DISABLE
:
6443 case PACKET_SUPPORT_UNKNOWN
:
6449 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6451 p
+= hexnumstr (p
, (ULONGEST
) 0);
6455 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6456 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6458 if (rs
->buf
[0] == '\0')
6461 fprintf_unfiltered (gdb_stdlog
,
6462 "binary downloading NOT "
6463 "supported by target\n");
6464 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6469 fprintf_unfiltered (gdb_stdlog
,
6470 "binary downloading supported by target\n");
6471 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6478 /* Write memory data directly to the remote machine.
6479 This does not inform the data cache; the data cache uses this.
6480 HEADER is the starting part of the packet.
6481 MEMADDR is the address in the remote memory space.
6482 MYADDR is the address of the buffer in our space.
6483 LEN is the number of bytes.
6484 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6485 should send data as binary ('X'), or hex-encoded ('M').
6487 The function creates packet of the form
6488 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6490 where encoding of <DATA> is termined by PACKET_FORMAT.
6492 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6495 Returns the number of bytes transferred, or 0 (setting errno) for
6496 error. Only transfer a single packet. */
6499 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6500 const gdb_byte
*myaddr
, ssize_t len
,
6501 char packet_format
, int use_length
)
6503 struct remote_state
*rs
= get_remote_state ();
6513 if (packet_format
!= 'X' && packet_format
!= 'M')
6514 internal_error (__FILE__
, __LINE__
,
6515 _("remote_write_bytes_aux: bad packet format"));
6520 payload_size
= get_memory_write_packet_size ();
6522 /* The packet buffer will be large enough for the payload;
6523 get_memory_packet_size ensures this. */
6526 /* Compute the size of the actual payload by subtracting out the
6527 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6529 payload_size
-= strlen ("$,:#NN");
6531 /* The comma won't be used. */
6533 header_length
= strlen (header
);
6534 payload_size
-= header_length
;
6535 payload_size
-= hexnumlen (memaddr
);
6537 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6539 strcat (rs
->buf
, header
);
6540 p
= rs
->buf
+ strlen (header
);
6542 /* Compute a best guess of the number of bytes actually transfered. */
6543 if (packet_format
== 'X')
6545 /* Best guess at number of bytes that will fit. */
6546 todo
= min (len
, payload_size
);
6548 payload_size
-= hexnumlen (todo
);
6549 todo
= min (todo
, payload_size
);
6553 /* Num bytes that will fit. */
6554 todo
= min (len
, payload_size
/ 2);
6556 payload_size
-= hexnumlen (todo
);
6557 todo
= min (todo
, payload_size
/ 2);
6561 internal_error (__FILE__
, __LINE__
,
6562 _("minimum packet size too small to write data"));
6564 /* If we already need another packet, then try to align the end
6565 of this packet to a useful boundary. */
6566 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6567 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6569 /* Append "<memaddr>". */
6570 memaddr
= remote_address_masked (memaddr
);
6571 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6578 /* Append <len>. Retain the location/size of <len>. It may need to
6579 be adjusted once the packet body has been created. */
6581 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6589 /* Append the packet body. */
6590 if (packet_format
== 'X')
6592 /* Binary mode. Send target system values byte by byte, in
6593 increasing byte addresses. Only escape certain critical
6595 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
6598 /* If not all TODO bytes fit, then we'll need another packet. Make
6599 a second try to keep the end of the packet aligned. Don't do
6600 this if the packet is tiny. */
6601 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6605 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6607 if (new_nr_bytes
!= nr_bytes
)
6608 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6613 p
+= payload_length
;
6614 if (use_length
&& nr_bytes
< todo
)
6616 /* Escape chars have filled up the buffer prematurely,
6617 and we have actually sent fewer bytes than planned.
6618 Fix-up the length field of the packet. Use the same
6619 number of characters as before. */
6620 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6621 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6626 /* Normal mode: Send target system values byte by byte, in
6627 increasing byte addresses. Each byte is encoded as a two hex
6629 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6633 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6634 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6636 if (rs
->buf
[0] == 'E')
6638 /* There is no correspondance between what the remote protocol
6639 uses for errors and errno codes. We would like a cleaner way
6640 of representing errors (big enough to include errno codes,
6641 bfd_error codes, and others). But for now just return EIO. */
6646 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6647 fewer bytes than we'd planned. */
6651 /* Write memory data directly to the remote machine.
6652 This does not inform the data cache; the data cache uses this.
6653 MEMADDR is the address in the remote memory space.
6654 MYADDR is the address of the buffer in our space.
6655 LEN is the number of bytes.
6657 Returns number of bytes transferred, or 0 (setting errno) for
6658 error. Only transfer a single packet. */
6661 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ssize_t len
)
6663 char *packet_format
= 0;
6665 /* Check whether the target supports binary download. */
6666 check_binary_download (memaddr
);
6668 switch (remote_protocol_packets
[PACKET_X
].support
)
6671 packet_format
= "X";
6673 case PACKET_DISABLE
:
6674 packet_format
= "M";
6676 case PACKET_SUPPORT_UNKNOWN
:
6677 internal_error (__FILE__
, __LINE__
,
6678 _("remote_write_bytes: bad internal state"));
6680 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6683 return remote_write_bytes_aux (packet_format
,
6684 memaddr
, myaddr
, len
, packet_format
[0], 1);
6687 /* Read memory data directly from the remote machine.
6688 This does not use the data cache; the data cache uses this.
6689 MEMADDR is the address in the remote memory space.
6690 MYADDR is the address of the buffer in our space.
6691 LEN is the number of bytes.
6693 Returns number of bytes transferred, or 0 for error. */
6696 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6698 struct remote_state
*rs
= get_remote_state ();
6699 int max_buf_size
; /* Max size of packet output buffer. */
6707 max_buf_size
= get_memory_read_packet_size ();
6708 /* The packet buffer will be large enough for the payload;
6709 get_memory_packet_size ensures this. */
6711 /* Number if bytes that will fit. */
6712 todo
= min (len
, max_buf_size
/ 2);
6714 /* Construct "m"<memaddr>","<len>". */
6715 memaddr
= remote_address_masked (memaddr
);
6718 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6720 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6723 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6724 if (rs
->buf
[0] == 'E'
6725 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6726 && rs
->buf
[3] == '\0')
6728 /* There is no correspondance between what the remote protocol
6729 uses for errors and errno codes. We would like a cleaner way
6730 of representing errors (big enough to include errno codes,
6731 bfd_error codes, and others). But for now just return
6736 /* Reply describes memory byte by byte, each byte encoded as two hex
6739 i
= hex2bin (p
, myaddr
, todo
);
6740 /* Return what we have. Let higher layers handle partial reads. */
6745 /* Remote notification handler. */
6748 handle_notification (char *buf
)
6750 if (strncmp (buf
, "Stop:", 5) == 0)
6752 if (pending_stop_reply
)
6754 /* We've already parsed the in-flight stop-reply, but the
6755 stub for some reason thought we didn't, possibly due to
6756 timeout on its side. Just ignore it. */
6758 fprintf_unfiltered (gdb_stdlog
, "ignoring resent notification\n");
6762 struct cleanup
*old_chain
;
6763 struct stop_reply
*reply
= stop_reply_xmalloc ();
6765 old_chain
= make_cleanup (do_stop_reply_xfree
, reply
);
6767 remote_parse_stop_reply (buf
+ 5, reply
);
6769 discard_cleanups (old_chain
);
6771 /* Be careful to only set it after parsing, since an error
6772 may be thrown then. */
6773 pending_stop_reply
= reply
;
6775 /* Notify the event loop there's a stop reply to acknowledge
6776 and that there may be more events to fetch. */
6777 mark_async_event_handler (remote_async_get_pending_events_token
);
6780 fprintf_unfiltered (gdb_stdlog
, "stop notification captured\n");
6784 /* We ignore notifications we don't recognize, for compatibility
6785 with newer stubs. */
6790 /* Read or write LEN bytes from inferior memory at MEMADDR,
6791 transferring to or from debugger address BUFFER. Write to inferior
6792 if SHOULD_WRITE is nonzero. Returns length of data written or
6793 read; 0 for error. TARGET is unused. */
6796 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6797 int should_write
, struct mem_attrib
*attrib
,
6798 struct target_ops
*target
)
6802 set_remote_traceframe ();
6803 set_general_thread (inferior_ptid
);
6806 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
6808 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
6813 /* Sends a packet with content determined by the printf format string
6814 FORMAT and the remaining arguments, then gets the reply. Returns
6815 whether the packet was a success, a failure, or unknown. */
6817 static enum packet_result
6818 remote_send_printf (const char *format
, ...)
6820 struct remote_state
*rs
= get_remote_state ();
6821 int max_size
= get_remote_packet_size ();
6824 va_start (ap
, format
);
6827 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6828 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
6830 if (putpkt (rs
->buf
) < 0)
6831 error (_("Communication problem with target."));
6834 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6836 return packet_check_result (rs
->buf
);
6840 restore_remote_timeout (void *p
)
6842 int value
= *(int *)p
;
6844 remote_timeout
= value
;
6847 /* Flash writing can take quite some time. We'll set
6848 effectively infinite timeout for flash operations.
6849 In future, we'll need to decide on a better approach. */
6850 static const int remote_flash_timeout
= 1000;
6853 remote_flash_erase (struct target_ops
*ops
,
6854 ULONGEST address
, LONGEST length
)
6856 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
6857 int saved_remote_timeout
= remote_timeout
;
6858 enum packet_result ret
;
6859 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6860 &saved_remote_timeout
);
6862 remote_timeout
= remote_flash_timeout
;
6864 ret
= remote_send_printf ("vFlashErase:%s,%s",
6865 phex (address
, addr_size
),
6869 case PACKET_UNKNOWN
:
6870 error (_("Remote target does not support flash erase"));
6872 error (_("Error erasing flash with vFlashErase packet"));
6877 do_cleanups (back_to
);
6881 remote_flash_write (struct target_ops
*ops
,
6882 ULONGEST address
, LONGEST length
,
6883 const gdb_byte
*data
)
6885 int saved_remote_timeout
= remote_timeout
;
6887 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6888 &saved_remote_timeout
);
6890 remote_timeout
= remote_flash_timeout
;
6891 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
6892 do_cleanups (back_to
);
6898 remote_flash_done (struct target_ops
*ops
)
6900 int saved_remote_timeout
= remote_timeout
;
6902 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6903 &saved_remote_timeout
);
6905 remote_timeout
= remote_flash_timeout
;
6906 ret
= remote_send_printf ("vFlashDone");
6907 do_cleanups (back_to
);
6911 case PACKET_UNKNOWN
:
6912 error (_("Remote target does not support vFlashDone"));
6914 error (_("Error finishing flash operation"));
6921 remote_files_info (struct target_ops
*ignore
)
6923 puts_filtered ("Debugging a target over a serial line.\n");
6926 /* Stuff for dealing with the packets which are part of this protocol.
6927 See comment at top of file for details. */
6929 /* Read a single character from the remote end. */
6932 readchar (int timeout
)
6936 ch
= serial_readchar (remote_desc
, timeout
);
6941 switch ((enum serial_rc
) ch
)
6945 error (_("Remote connection closed"));
6949 perror_with_name (_("Remote communication error. "
6950 "Target disconnected."));
6952 case SERIAL_TIMEOUT
:
6958 /* Send the command in *BUF to the remote machine, and read the reply
6959 into *BUF. Report an error if we get an error reply. Resize
6960 *BUF using xrealloc if necessary to hold the result, and update
6964 remote_send (char **buf
,
6968 getpkt (buf
, sizeof_buf
, 0);
6970 if ((*buf
)[0] == 'E')
6971 error (_("Remote failure reply: %s"), *buf
);
6974 /* Return a pointer to an xmalloc'ed string representing an escaped
6975 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
6976 etc. The caller is responsible for releasing the returned
6980 escape_buffer (const char *buf
, int n
)
6982 struct cleanup
*old_chain
;
6983 struct ui_file
*stb
;
6986 stb
= mem_fileopen ();
6987 old_chain
= make_cleanup_ui_file_delete (stb
);
6989 fputstrn_unfiltered (buf
, n
, 0, stb
);
6990 str
= ui_file_xstrdup (stb
, NULL
);
6991 do_cleanups (old_chain
);
6995 /* Display a null-terminated packet on stdout, for debugging, using C
6999 print_packet (char *buf
)
7001 puts_filtered ("\"");
7002 fputstr_filtered (buf
, '"', gdb_stdout
);
7003 puts_filtered ("\"");
7009 return putpkt_binary (buf
, strlen (buf
));
7012 /* Send a packet to the remote machine, with error checking. The data
7013 of the packet is in BUF. The string in BUF can be at most
7014 get_remote_packet_size () - 5 to account for the $, # and checksum,
7015 and for a possible /0 if we are debugging (remote_debug) and want
7016 to print the sent packet as a string. */
7019 putpkt_binary (char *buf
, int cnt
)
7021 struct remote_state
*rs
= get_remote_state ();
7023 unsigned char csum
= 0;
7024 char *buf2
= alloca (cnt
+ 6);
7031 /* Catch cases like trying to read memory or listing threads while
7032 we're waiting for a stop reply. The remote server wouldn't be
7033 ready to handle this request, so we'd hang and timeout. We don't
7034 have to worry about this in synchronous mode, because in that
7035 case it's not possible to issue a command while the target is
7036 running. This is not a problem in non-stop mode, because in that
7037 case, the stub is always ready to process serial input. */
7038 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
7039 error (_("Cannot execute this command while the target is running."));
7041 /* We're sending out a new packet. Make sure we don't look at a
7042 stale cached response. */
7043 rs
->cached_wait_status
= 0;
7045 /* Copy the packet into buffer BUF2, encapsulating it
7046 and giving it a checksum. */
7051 for (i
= 0; i
< cnt
; i
++)
7057 *p
++ = tohex ((csum
>> 4) & 0xf);
7058 *p
++ = tohex (csum
& 0xf);
7060 /* Send it over and over until we get a positive ack. */
7064 int started_error_output
= 0;
7068 struct cleanup
*old_chain
;
7072 str
= escape_buffer (buf2
, p
- buf2
);
7073 old_chain
= make_cleanup (xfree
, str
);
7074 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7075 gdb_flush (gdb_stdlog
);
7076 do_cleanups (old_chain
);
7078 if (serial_write (remote_desc
, buf2
, p
- buf2
))
7079 perror_with_name (_("putpkt: write failed"));
7081 /* If this is a no acks version of the remote protocol, send the
7082 packet and move on. */
7086 /* Read until either a timeout occurs (-2) or '+' is read.
7087 Handle any notification that arrives in the mean time. */
7090 ch
= readchar (remote_timeout
);
7098 case SERIAL_TIMEOUT
:
7101 if (started_error_output
)
7103 putchar_unfiltered ('\n');
7104 started_error_output
= 0;
7113 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7117 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7119 case SERIAL_TIMEOUT
:
7123 break; /* Retransmit buffer. */
7127 fprintf_unfiltered (gdb_stdlog
,
7128 "Packet instead of Ack, ignoring it\n");
7129 /* It's probably an old response sent because an ACK
7130 was lost. Gobble up the packet and ack it so it
7131 doesn't get retransmitted when we resend this
7134 serial_write (remote_desc
, "+", 1);
7135 continue; /* Now, go look for +. */
7142 /* If we got a notification, handle it, and go back to looking
7144 /* We've found the start of a notification. Now
7145 collect the data. */
7146 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7151 struct cleanup
*old_chain
;
7154 str
= escape_buffer (rs
->buf
, val
);
7155 old_chain
= make_cleanup (xfree
, str
);
7156 fprintf_unfiltered (gdb_stdlog
,
7157 " Notification received: %s\n",
7159 do_cleanups (old_chain
);
7161 handle_notification (rs
->buf
);
7162 /* We're in sync now, rewait for the ack. */
7169 if (!started_error_output
)
7171 started_error_output
= 1;
7172 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7174 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7175 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7184 if (!started_error_output
)
7186 started_error_output
= 1;
7187 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7189 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7193 break; /* Here to retransmit. */
7197 /* This is wrong. If doing a long backtrace, the user should be
7198 able to get out next time we call QUIT, without anything as
7199 violent as interrupt_query. If we want to provide a way out of
7200 here without getting to the next QUIT, it should be based on
7201 hitting ^C twice as in remote_wait. */
7212 /* Come here after finding the start of a frame when we expected an
7213 ack. Do our best to discard the rest of this packet. */
7222 c
= readchar (remote_timeout
);
7225 case SERIAL_TIMEOUT
:
7226 /* Nothing we can do. */
7229 /* Discard the two bytes of checksum and stop. */
7230 c
= readchar (remote_timeout
);
7232 c
= readchar (remote_timeout
);
7235 case '*': /* Run length encoding. */
7236 /* Discard the repeat count. */
7237 c
= readchar (remote_timeout
);
7242 /* A regular character. */
7248 /* Come here after finding the start of the frame. Collect the rest
7249 into *BUF, verifying the checksum, length, and handling run-length
7250 compression. NUL terminate the buffer. If there is not enough room,
7251 expand *BUF using xrealloc.
7253 Returns -1 on error, number of characters in buffer (ignoring the
7254 trailing NULL) on success. (could be extended to return one of the
7255 SERIAL status indications). */
7258 read_frame (char **buf_p
,
7265 struct remote_state
*rs
= get_remote_state ();
7272 c
= readchar (remote_timeout
);
7275 case SERIAL_TIMEOUT
:
7277 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7281 fputs_filtered ("Saw new packet start in middle of old one\n",
7283 return -1; /* Start a new packet, count retries. */
7286 unsigned char pktcsum
;
7292 check_0
= readchar (remote_timeout
);
7294 check_1
= readchar (remote_timeout
);
7296 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7299 fputs_filtered ("Timeout in checksum, retrying\n",
7303 else if (check_0
< 0 || check_1
< 0)
7306 fputs_filtered ("Communication error in checksum\n",
7311 /* Don't recompute the checksum; with no ack packets we
7312 don't have any way to indicate a packet retransmission
7317 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7318 if (csum
== pktcsum
)
7323 struct cleanup
*old_chain
;
7326 str
= escape_buffer (buf
, bc
);
7327 old_chain
= make_cleanup (xfree
, str
);
7328 fprintf_unfiltered (gdb_stdlog
,
7329 "Bad checksum, sentsum=0x%x, "
7330 "csum=0x%x, buf=%s\n",
7331 pktcsum
, csum
, str
);
7332 do_cleanups (old_chain
);
7334 /* Number of characters in buffer ignoring trailing
7338 case '*': /* Run length encoding. */
7343 c
= readchar (remote_timeout
);
7345 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7347 /* The character before ``*'' is repeated. */
7349 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7351 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7353 /* Make some more room in the buffer. */
7354 *sizeof_buf
+= repeat
;
7355 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7359 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7365 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7369 if (bc
>= *sizeof_buf
- 1)
7371 /* Make some more room in the buffer. */
7373 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7384 /* Read a packet from the remote machine, with error checking, and
7385 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7386 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7387 rather than timing out; this is used (in synchronous mode) to wait
7388 for a target that is is executing user code to stop. */
7389 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7390 don't have to change all the calls to getpkt to deal with the
7391 return value, because at the moment I don't know what the right
7392 thing to do it for those. */
7400 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7404 /* Read a packet from the remote machine, with error checking, and
7405 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7406 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7407 rather than timing out; this is used (in synchronous mode) to wait
7408 for a target that is is executing user code to stop. If FOREVER ==
7409 0, this function is allowed to time out gracefully and return an
7410 indication of this to the caller. Otherwise return the number of
7411 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7412 enough reason to return to the caller. */
7415 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7416 int expecting_notif
)
7418 struct remote_state
*rs
= get_remote_state ();
7424 /* We're reading a new response. Make sure we don't look at a
7425 previously cached response. */
7426 rs
->cached_wait_status
= 0;
7428 strcpy (*buf
, "timeout");
7431 timeout
= watchdog
> 0 ? watchdog
: -1;
7432 else if (expecting_notif
)
7433 timeout
= 0; /* There should already be a char in the buffer. If
7436 timeout
= remote_timeout
;
7440 /* Process any number of notifications, and then return when
7444 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
7446 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7448 /* This can loop forever if the remote side sends us
7449 characters continuously, but if it pauses, we'll get
7450 SERIAL_TIMEOUT from readchar because of timeout. Then
7451 we'll count that as a retry.
7453 Note that even when forever is set, we will only wait
7454 forever prior to the start of a packet. After that, we
7455 expect characters to arrive at a brisk pace. They should
7456 show up within remote_timeout intervals. */
7458 c
= readchar (timeout
);
7459 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7461 if (c
== SERIAL_TIMEOUT
)
7463 if (expecting_notif
)
7464 return -1; /* Don't complain, it's normal to not get
7465 anything in this case. */
7467 if (forever
) /* Watchdog went off? Kill the target. */
7471 error (_("Watchdog timeout has expired. Target detached."));
7474 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7478 /* We've found the start of a packet or notification.
7479 Now collect the data. */
7480 val
= read_frame (buf
, sizeof_buf
);
7485 serial_write (remote_desc
, "-", 1);
7488 if (tries
> MAX_TRIES
)
7490 /* We have tried hard enough, and just can't receive the
7491 packet/notification. Give up. */
7492 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7494 /* Skip the ack char if we're in no-ack mode. */
7495 if (!rs
->noack_mode
)
7496 serial_write (remote_desc
, "+", 1);
7500 /* If we got an ordinary packet, return that to our caller. */
7505 struct cleanup
*old_chain
;
7508 str
= escape_buffer (*buf
, val
);
7509 old_chain
= make_cleanup (xfree
, str
);
7510 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7511 do_cleanups (old_chain
);
7514 /* Skip the ack char if we're in no-ack mode. */
7515 if (!rs
->noack_mode
)
7516 serial_write (remote_desc
, "+", 1);
7520 /* If we got a notification, handle it, and go back to looking
7524 gdb_assert (c
== '%');
7528 struct cleanup
*old_chain
;
7531 str
= escape_buffer (*buf
, val
);
7532 old_chain
= make_cleanup (xfree
, str
);
7533 fprintf_unfiltered (gdb_stdlog
,
7534 " Notification received: %s\n",
7536 do_cleanups (old_chain
);
7539 handle_notification (*buf
);
7541 /* Notifications require no acknowledgement. */
7543 if (expecting_notif
)
7550 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7552 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0);
7556 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
)
7558 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1);
7562 /* A helper function that just calls putpkt; for type correctness. */
7565 putpkt_for_catch_errors (void *arg
)
7567 return putpkt (arg
);
7571 remote_kill (struct target_ops
*ops
)
7573 /* Use catch_errors so the user can quit from gdb even when we
7574 aren't on speaking terms with the remote system. */
7575 catch_errors (putpkt_for_catch_errors
, "k", "", RETURN_MASK_ERROR
);
7577 /* Don't wait for it to die. I'm not really sure it matters whether
7578 we do or not. For the existing stubs, kill is a noop. */
7579 target_mourn_inferior ();
7583 remote_vkill (int pid
, struct remote_state
*rs
)
7585 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7588 /* Tell the remote target to detach. */
7589 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
7591 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7593 if (packet_ok (rs
->buf
,
7594 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7596 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7603 extended_remote_kill (struct target_ops
*ops
)
7606 int pid
= ptid_get_pid (inferior_ptid
);
7607 struct remote_state
*rs
= get_remote_state ();
7609 res
= remote_vkill (pid
, rs
);
7610 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
7612 /* Don't try 'k' on a multi-process aware stub -- it has no way
7613 to specify the pid. */
7617 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7618 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7621 /* Don't wait for it to die. I'm not really sure it matters whether
7622 we do or not. For the existing stubs, kill is a noop. */
7628 error (_("Can't kill process"));
7630 target_mourn_inferior ();
7634 remote_mourn (struct target_ops
*ops
)
7636 remote_mourn_1 (ops
);
7639 /* Worker function for remote_mourn. */
7641 remote_mourn_1 (struct target_ops
*target
)
7643 unpush_target (target
);
7645 /* remote_close takes care of doing most of the clean up. */
7646 generic_mourn_inferior ();
7650 extended_remote_mourn_1 (struct target_ops
*target
)
7652 struct remote_state
*rs
= get_remote_state ();
7654 /* In case we got here due to an error, but we're going to stay
7656 rs
->waiting_for_stop_reply
= 0;
7658 /* We're no longer interested in these events. */
7659 discard_pending_stop_replies (ptid_get_pid (inferior_ptid
));
7661 /* If the current general thread belonged to the process we just
7662 detached from or has exited, the remote side current general
7663 thread becomes undefined. Considering a case like this:
7665 - We just got here due to a detach.
7666 - The process that we're detaching from happens to immediately
7667 report a global breakpoint being hit in non-stop mode, in the
7668 same thread we had selected before.
7669 - GDB attaches to this process again.
7670 - This event happens to be the next event we handle.
7672 GDB would consider that the current general thread didn't need to
7673 be set on the stub side (with Hg), since for all it knew,
7674 GENERAL_THREAD hadn't changed.
7676 Notice that although in all-stop mode, the remote server always
7677 sets the current thread to the thread reporting the stop event,
7678 that doesn't happen in non-stop mode; in non-stop, the stub *must
7679 not* change the current thread when reporting a breakpoint hit,
7680 due to the decoupling of event reporting and event handling.
7682 To keep things simple, we always invalidate our notion of the
7684 record_currthread (minus_one_ptid
);
7686 /* Unlike "target remote", we do not want to unpush the target; then
7687 the next time the user says "run", we won't be connected. */
7689 /* Call common code to mark the inferior as not running. */
7690 generic_mourn_inferior ();
7692 if (!have_inferiors ())
7694 if (!remote_multi_process_p (rs
))
7696 /* Check whether the target is running now - some remote stubs
7697 automatically restart after kill. */
7699 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7701 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7703 /* Assume that the target has been restarted. Set
7704 inferior_ptid so that bits of core GDB realizes
7705 there's something here, e.g., so that the user can
7706 say "kill" again. */
7707 inferior_ptid
= magic_null_ptid
;
7714 extended_remote_mourn (struct target_ops
*ops
)
7716 extended_remote_mourn_1 (ops
);
7720 extended_remote_supports_disable_randomization (void)
7722 return (remote_protocol_packets
[PACKET_QDisableRandomization
].support
7727 extended_remote_disable_randomization (int val
)
7729 struct remote_state
*rs
= get_remote_state ();
7732 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
7735 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
7737 error (_("Target does not support QDisableRandomization."));
7738 if (strcmp (reply
, "OK") != 0)
7739 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
7743 extended_remote_run (char *args
)
7745 struct remote_state
*rs
= get_remote_state ();
7748 /* If the user has disabled vRun support, or we have detected that
7749 support is not available, do not try it. */
7750 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7753 strcpy (rs
->buf
, "vRun;");
7754 len
= strlen (rs
->buf
);
7756 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7757 error (_("Remote file name too long for run packet"));
7758 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7760 gdb_assert (args
!= NULL
);
7763 struct cleanup
*back_to
;
7767 argv
= gdb_buildargv (args
);
7768 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7769 for (i
= 0; argv
[i
] != NULL
; i
++)
7771 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7772 error (_("Argument list too long for run packet"));
7773 rs
->buf
[len
++] = ';';
7774 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7776 do_cleanups (back_to
);
7779 rs
->buf
[len
++] = '\0';
7782 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7784 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7786 /* We have a wait response; we don't need it, though. All is well. */
7789 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7790 /* It wasn't disabled before, but it is now. */
7794 if (remote_exec_file
[0] == '\0')
7795 error (_("Running the default executable on the remote target failed; "
7796 "try \"set remote exec-file\"?"));
7798 error (_("Running \"%s\" on the remote target failed"),
7803 /* In the extended protocol we want to be able to do things like
7804 "run" and have them basically work as expected. So we need
7805 a special create_inferior function. We support changing the
7806 executable file and the command line arguments, but not the
7810 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7811 char **env
, int from_tty
)
7813 /* If running asynchronously, register the target file descriptor
7814 with the event loop. */
7815 if (target_can_async_p ())
7816 target_async (inferior_event_handler
, 0);
7818 /* Disable address space randomization if requested (and supported). */
7819 if (extended_remote_supports_disable_randomization ())
7820 extended_remote_disable_randomization (disable_randomization
);
7822 /* Now restart the remote server. */
7823 if (extended_remote_run (args
) == -1)
7825 /* vRun was not supported. Fail if we need it to do what the
7827 if (remote_exec_file
[0])
7828 error (_("Remote target does not support \"set remote exec-file\""));
7830 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7832 /* Fall back to "R". */
7833 extended_remote_restart ();
7836 if (!have_inferiors ())
7838 /* Clean up from the last time we ran, before we mark the target
7839 running again. This will mark breakpoints uninserted, and
7840 get_offsets may insert breakpoints. */
7841 init_thread_list ();
7842 init_wait_for_inferior ();
7845 add_current_inferior_and_thread ();
7847 /* Get updated offsets, if the stub uses qOffsets. */
7852 extended_remote_create_inferior (struct target_ops
*ops
,
7853 char *exec_file
, char *args
,
7854 char **env
, int from_tty
)
7856 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
7860 /* Given a location's target info BP_TGT and the packet buffer BUF, output
7861 the list of conditions (in agent expression bytecode format), if any, the
7862 target needs to evaluate. The output is placed into the packet buffer
7863 started from BUF and ended at BUF_END. */
7866 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
7867 struct bp_target_info
*bp_tgt
, char *buf
,
7870 struct agent_expr
*aexpr
= NULL
;
7873 char *buf_start
= buf
;
7875 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
7878 buf
+= strlen (buf
);
7879 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
7882 /* Send conditions to the target and free the vector. */
7884 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
7887 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
7888 buf
+= strlen (buf
);
7889 for (i
= 0; i
< aexpr
->len
; ++i
)
7890 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
7894 VEC_free (agent_expr_p
, bp_tgt
->conditions
);
7899 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
7900 struct bp_target_info
*bp_tgt
, char *buf
)
7902 struct agent_expr
*aexpr
= NULL
;
7905 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
7908 buf
+= strlen (buf
);
7910 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
7911 buf
+= strlen (buf
);
7913 /* Concatenate all the agent expressions that are commands into the
7916 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
7919 sprintf (buf
, "X%x,", aexpr
->len
);
7920 buf
+= strlen (buf
);
7921 for (i
= 0; i
< aexpr
->len
; ++i
)
7922 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
7926 VEC_free (agent_expr_p
, bp_tgt
->tcommands
);
7929 /* Insert a breakpoint. On targets that have software breakpoint
7930 support, we ask the remote target to do the work; on targets
7931 which don't, we insert a traditional memory breakpoint. */
7934 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
7935 struct bp_target_info
*bp_tgt
)
7937 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
7938 If it succeeds, then set the support to PACKET_ENABLE. If it
7939 fails, and the user has explicitly requested the Z support then
7940 report an error, otherwise, mark it disabled and go on. */
7942 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7944 CORE_ADDR addr
= bp_tgt
->placed_address
;
7945 struct remote_state
*rs
;
7948 struct condition_list
*cond
= NULL
;
7950 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
7952 rs
= get_remote_state ();
7954 endbuf
= rs
->buf
+ get_remote_packet_size ();
7959 addr
= (ULONGEST
) remote_address_masked (addr
);
7960 p
+= hexnumstr (p
, addr
);
7961 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
7963 if (remote_supports_cond_breakpoints ())
7964 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
7966 if (remote_can_run_breakpoint_commands ())
7967 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
7970 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7972 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
7977 bp_tgt
->placed_address
= addr
;
7978 bp_tgt
->placed_size
= bpsize
;
7980 case PACKET_UNKNOWN
:
7985 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
7989 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
7990 struct bp_target_info
*bp_tgt
)
7992 CORE_ADDR addr
= bp_tgt
->placed_address
;
7993 struct remote_state
*rs
= get_remote_state ();
7995 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
7998 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8004 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8005 p
+= hexnumstr (p
, addr
);
8006 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8009 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8011 return (rs
->buf
[0] == 'E');
8014 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
8018 watchpoint_to_Z_packet (int type
)
8023 return Z_PACKET_WRITE_WP
;
8026 return Z_PACKET_READ_WP
;
8029 return Z_PACKET_ACCESS_WP
;
8032 internal_error (__FILE__
, __LINE__
,
8033 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8038 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
8039 struct expression
*cond
)
8041 struct remote_state
*rs
= get_remote_state ();
8042 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8044 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8046 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8049 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8050 p
= strchr (rs
->buf
, '\0');
8051 addr
= remote_address_masked (addr
);
8052 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8053 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8056 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8058 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8062 case PACKET_UNKNOWN
:
8067 internal_error (__FILE__
, __LINE__
,
8068 _("remote_insert_watchpoint: reached end of function"));
8072 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8073 CORE_ADDR start
, int length
)
8075 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8077 return diff
< length
;
8082 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
8083 struct expression
*cond
)
8085 struct remote_state
*rs
= get_remote_state ();
8086 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8088 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8090 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8093 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8094 p
= strchr (rs
->buf
, '\0');
8095 addr
= remote_address_masked (addr
);
8096 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8097 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8099 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8101 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8104 case PACKET_UNKNOWN
:
8109 internal_error (__FILE__
, __LINE__
,
8110 _("remote_remove_watchpoint: reached end of function"));
8114 int remote_hw_watchpoint_limit
= -1;
8115 int remote_hw_watchpoint_length_limit
= -1;
8116 int remote_hw_breakpoint_limit
= -1;
8119 remote_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
8121 if (remote_hw_watchpoint_length_limit
== 0)
8123 else if (remote_hw_watchpoint_length_limit
< 0)
8125 else if (len
<= remote_hw_watchpoint_length_limit
)
8132 remote_check_watch_resources (int type
, int cnt
, int ot
)
8134 if (type
== bp_hardware_breakpoint
)
8136 if (remote_hw_breakpoint_limit
== 0)
8138 else if (remote_hw_breakpoint_limit
< 0)
8140 else if (cnt
<= remote_hw_breakpoint_limit
)
8145 if (remote_hw_watchpoint_limit
== 0)
8147 else if (remote_hw_watchpoint_limit
< 0)
8151 else if (cnt
<= remote_hw_watchpoint_limit
)
8158 remote_stopped_by_watchpoint (void)
8160 return remote_stopped_by_watchpoint_p
;
8164 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
8168 if (remote_stopped_by_watchpoint ())
8170 *addr_p
= remote_watch_data_address
;
8179 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
8180 struct bp_target_info
*bp_tgt
)
8183 struct remote_state
*rs
;
8187 /* The length field should be set to the size of a breakpoint
8188 instruction, even though we aren't inserting one ourselves. */
8190 gdbarch_remote_breakpoint_from_pc
8191 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
8193 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8196 rs
= get_remote_state ();
8198 endbuf
= rs
->buf
+ get_remote_packet_size ();
8204 addr
= remote_address_masked (bp_tgt
->placed_address
);
8205 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8206 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8208 if (remote_supports_cond_breakpoints ())
8209 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8211 if (remote_can_run_breakpoint_commands ())
8212 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8215 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8217 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8220 if (rs
->buf
[1] == '.')
8222 message
= strchr (rs
->buf
+ 2, '.');
8224 error ("Remote failure reply: %s", message
+ 1);
8227 case PACKET_UNKNOWN
:
8232 internal_error (__FILE__
, __LINE__
,
8233 _("remote_insert_hw_breakpoint: reached end of function"));
8238 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
8239 struct bp_target_info
*bp_tgt
)
8242 struct remote_state
*rs
= get_remote_state ();
8244 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8246 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8253 addr
= remote_address_masked (bp_tgt
->placed_address
);
8254 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8255 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8258 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8260 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8263 case PACKET_UNKNOWN
:
8268 internal_error (__FILE__
, __LINE__
,
8269 _("remote_remove_hw_breakpoint: reached end of function"));
8272 /* Table used by the crc32 function to calcuate the checksum. */
8274 static unsigned long crc32_table
[256] =
8277 static unsigned long
8278 crc32 (const unsigned char *buf
, int len
, unsigned int crc
)
8280 if (!crc32_table
[1])
8282 /* Initialize the CRC table and the decoding table. */
8286 for (i
= 0; i
< 256; i
++)
8288 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
8289 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
8296 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
8302 /* Verify memory using the "qCRC:" request. */
8305 remote_verify_memory (struct target_ops
*ops
,
8306 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8308 struct remote_state
*rs
= get_remote_state ();
8309 unsigned long host_crc
, target_crc
;
8312 /* FIXME: assumes lma can fit into long. */
8313 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8314 (long) lma
, (long) size
);
8317 /* Be clever; compute the host_crc before waiting for target
8319 host_crc
= crc32 (data
, size
, 0xffffffff);
8321 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8322 if (rs
->buf
[0] == 'E')
8325 if (rs
->buf
[0] != 'C')
8326 error (_("remote target does not support this operation"));
8328 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8329 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8331 return (host_crc
== target_crc
);
8334 /* compare-sections command
8336 With no arguments, compares each loadable section in the exec bfd
8337 with the same memory range on the target, and reports mismatches.
8338 Useful for verifying the image on the target against the exec file. */
8341 compare_sections_command (char *args
, int from_tty
)
8344 struct cleanup
*old_chain
;
8346 const char *sectname
;
8354 error (_("command cannot be used without an exec file"));
8356 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8358 if (!(s
->flags
& SEC_LOAD
))
8359 continue; /* Skip non-loadable section. */
8361 size
= bfd_get_section_size (s
);
8363 continue; /* Skip zero-length section. */
8365 sectname
= bfd_get_section_name (exec_bfd
, s
);
8366 if (args
&& strcmp (args
, sectname
) != 0)
8367 continue; /* Not the section selected by user. */
8369 matched
= 1; /* Do this section. */
8372 sectdata
= xmalloc (size
);
8373 old_chain
= make_cleanup (xfree
, sectdata
);
8374 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8376 res
= target_verify_memory (sectdata
, lma
, size
);
8379 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8380 paddress (target_gdbarch
, lma
),
8381 paddress (target_gdbarch
, lma
+ size
));
8383 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8384 paddress (target_gdbarch
, lma
),
8385 paddress (target_gdbarch
, lma
+ size
));
8387 printf_filtered ("matched.\n");
8390 printf_filtered ("MIS-MATCHED!\n");
8394 do_cleanups (old_chain
);
8397 warning (_("One or more sections of the remote executable does not match\n\
8398 the loaded file\n"));
8399 if (args
&& !matched
)
8400 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8403 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8404 into remote target. The number of bytes written to the remote
8405 target is returned, or -1 for error. */
8408 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8409 const char *annex
, const gdb_byte
*writebuf
,
8410 ULONGEST offset
, LONGEST len
,
8411 struct packet_config
*packet
)
8415 struct remote_state
*rs
= get_remote_state ();
8416 int max_size
= get_memory_write_packet_size ();
8418 if (packet
->support
== PACKET_DISABLE
)
8421 /* Insert header. */
8422 i
= snprintf (rs
->buf
, max_size
,
8423 "qXfer:%s:write:%s:%s:",
8424 object_name
, annex
? annex
: "",
8425 phex_nz (offset
, sizeof offset
));
8426 max_size
-= (i
+ 1);
8428 /* Escape as much data as fits into rs->buf. */
8429 buf_len
= remote_escape_output
8430 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
8432 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8433 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8434 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8437 unpack_varlen_hex (rs
->buf
, &n
);
8441 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8442 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8443 number of bytes read is returned, or 0 for EOF, or -1 for error.
8444 The number of bytes read may be less than LEN without indicating an
8445 EOF. PACKET is checked and updated to indicate whether the remote
8446 target supports this object. */
8449 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8451 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8452 struct packet_config
*packet
)
8454 static char *finished_object
;
8455 static char *finished_annex
;
8456 static ULONGEST finished_offset
;
8458 struct remote_state
*rs
= get_remote_state ();
8459 LONGEST i
, n
, packet_len
;
8461 if (packet
->support
== PACKET_DISABLE
)
8464 /* Check whether we've cached an end-of-object packet that matches
8466 if (finished_object
)
8468 if (strcmp (object_name
, finished_object
) == 0
8469 && strcmp (annex
? annex
: "", finished_annex
) == 0
8470 && offset
== finished_offset
)
8473 /* Otherwise, we're now reading something different. Discard
8475 xfree (finished_object
);
8476 xfree (finished_annex
);
8477 finished_object
= NULL
;
8478 finished_annex
= NULL
;
8481 /* Request only enough to fit in a single packet. The actual data
8482 may not, since we don't know how much of it will need to be escaped;
8483 the target is free to respond with slightly less data. We subtract
8484 five to account for the response type and the protocol frame. */
8485 n
= min (get_remote_packet_size () - 5, len
);
8486 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8487 object_name
, annex
? annex
: "",
8488 phex_nz (offset
, sizeof offset
),
8489 phex_nz (n
, sizeof n
));
8490 i
= putpkt (rs
->buf
);
8495 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8496 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8499 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8500 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8502 /* 'm' means there is (or at least might be) more data after this
8503 batch. That does not make sense unless there's at least one byte
8504 of data in this reply. */
8505 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8506 error (_("Remote qXfer reply contained no data."));
8508 /* Got some data. */
8509 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
8511 /* 'l' is an EOF marker, possibly including a final block of data,
8512 or possibly empty. If we have the final block of a non-empty
8513 object, record this fact to bypass a subsequent partial read. */
8514 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8516 finished_object
= xstrdup (object_name
);
8517 finished_annex
= xstrdup (annex
? annex
: "");
8518 finished_offset
= offset
+ i
;
8525 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8526 const char *annex
, gdb_byte
*readbuf
,
8527 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
8529 struct remote_state
*rs
;
8534 set_remote_traceframe ();
8535 set_general_thread (inferior_ptid
);
8537 rs
= get_remote_state ();
8539 /* Handle memory using the standard memory routines. */
8540 if (object
== TARGET_OBJECT_MEMORY
)
8546 /* If the remote target is connected but not running, we should
8547 pass this request down to a lower stratum (e.g. the executable
8549 if (!target_has_execution
)
8552 if (writebuf
!= NULL
)
8553 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8555 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8559 else if (xfered
== 0 && errno
== 0)
8565 /* Handle SPU memory using qxfer packets. */
8566 if (object
== TARGET_OBJECT_SPU
)
8569 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8570 &remote_protocol_packets
8571 [PACKET_qXfer_spu_read
]);
8573 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8574 &remote_protocol_packets
8575 [PACKET_qXfer_spu_write
]);
8578 /* Handle extra signal info using qxfer packets. */
8579 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8582 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8583 &remote_protocol_packets
8584 [PACKET_qXfer_siginfo_read
]);
8586 return remote_write_qxfer (ops
, "siginfo", annex
,
8587 writebuf
, offset
, len
,
8588 &remote_protocol_packets
8589 [PACKET_qXfer_siginfo_write
]);
8592 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8595 return remote_read_qxfer (ops
, "statictrace", annex
,
8596 readbuf
, offset
, len
,
8597 &remote_protocol_packets
8598 [PACKET_qXfer_statictrace_read
]);
8603 /* Only handle flash writes. */
8604 if (writebuf
!= NULL
)
8610 case TARGET_OBJECT_FLASH
:
8611 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
8615 else if (xfered
== 0 && errno
== 0)
8625 /* Map pre-existing objects onto letters. DO NOT do this for new
8626 objects!!! Instead specify new query packets. */
8629 case TARGET_OBJECT_AVR
:
8633 case TARGET_OBJECT_AUXV
:
8634 gdb_assert (annex
== NULL
);
8635 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8636 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8638 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8639 return remote_read_qxfer
8640 (ops
, "features", annex
, readbuf
, offset
, len
,
8641 &remote_protocol_packets
[PACKET_qXfer_features
]);
8643 case TARGET_OBJECT_LIBRARIES
:
8644 return remote_read_qxfer
8645 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8646 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8648 case TARGET_OBJECT_LIBRARIES_SVR4
:
8649 return remote_read_qxfer
8650 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
,
8651 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
8653 case TARGET_OBJECT_MEMORY_MAP
:
8654 gdb_assert (annex
== NULL
);
8655 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8656 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8658 case TARGET_OBJECT_OSDATA
:
8659 /* Should only get here if we're connected. */
8660 gdb_assert (remote_desc
);
8661 return remote_read_qxfer
8662 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8663 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8665 case TARGET_OBJECT_THREADS
:
8666 gdb_assert (annex
== NULL
);
8667 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8668 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8670 case TARGET_OBJECT_TRACEFRAME_INFO
:
8671 gdb_assert (annex
== NULL
);
8672 return remote_read_qxfer
8673 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8674 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8676 case TARGET_OBJECT_FDPIC
:
8677 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
8678 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
8680 case TARGET_OBJECT_OPENVMS_UIB
:
8681 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
8682 &remote_protocol_packets
[PACKET_qXfer_uib
]);
8688 /* Note: a zero OFFSET and LEN can be used to query the minimum
8690 if (offset
== 0 && len
== 0)
8691 return (get_remote_packet_size ());
8692 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8693 large enough let the caller deal with it. */
8694 if (len
< get_remote_packet_size ())
8696 len
= get_remote_packet_size ();
8698 /* Except for querying the minimum buffer size, target must be open. */
8700 error (_("remote query is only available after target open"));
8702 gdb_assert (annex
!= NULL
);
8703 gdb_assert (readbuf
!= NULL
);
8709 /* We used one buffer char for the remote protocol q command and
8710 another for the query type. As the remote protocol encapsulation
8711 uses 4 chars plus one extra in case we are debugging
8712 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8715 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8717 /* Bad caller may have sent forbidden characters. */
8718 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8723 gdb_assert (annex
[i
] == '\0');
8725 i
= putpkt (rs
->buf
);
8729 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8730 strcpy ((char *) readbuf
, rs
->buf
);
8732 return strlen ((char *) readbuf
);
8736 remote_search_memory (struct target_ops
* ops
,
8737 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8738 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8739 CORE_ADDR
*found_addrp
)
8741 int addr_size
= gdbarch_addr_bit (target_gdbarch
) / 8;
8742 struct remote_state
*rs
= get_remote_state ();
8743 int max_size
= get_memory_write_packet_size ();
8744 struct packet_config
*packet
=
8745 &remote_protocol_packets
[PACKET_qSearch_memory
];
8746 /* Number of packet bytes used to encode the pattern;
8747 this could be more than PATTERN_LEN due to escape characters. */
8748 int escaped_pattern_len
;
8749 /* Amount of pattern that was encodable in the packet. */
8750 int used_pattern_len
;
8753 ULONGEST found_addr
;
8755 /* Don't go to the target if we don't have to.
8756 This is done before checking packet->support to avoid the possibility that
8757 a success for this edge case means the facility works in general. */
8758 if (pattern_len
> search_space_len
)
8760 if (pattern_len
== 0)
8762 *found_addrp
= start_addr
;
8766 /* If we already know the packet isn't supported, fall back to the simple
8767 way of searching memory. */
8769 if (packet
->support
== PACKET_DISABLE
)
8771 /* Target doesn't provided special support, fall back and use the
8772 standard support (copy memory and do the search here). */
8773 return simple_search_memory (ops
, start_addr
, search_space_len
,
8774 pattern
, pattern_len
, found_addrp
);
8777 /* Insert header. */
8778 i
= snprintf (rs
->buf
, max_size
,
8779 "qSearch:memory:%s;%s;",
8780 phex_nz (start_addr
, addr_size
),
8781 phex_nz (search_space_len
, sizeof (search_space_len
)));
8782 max_size
-= (i
+ 1);
8784 /* Escape as much data as fits into rs->buf. */
8785 escaped_pattern_len
=
8786 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
8787 &used_pattern_len
, max_size
);
8789 /* Bail if the pattern is too large. */
8790 if (used_pattern_len
!= pattern_len
)
8791 error (_("Pattern is too large to transmit to remote target."));
8793 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8794 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8795 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8797 /* The request may not have worked because the command is not
8798 supported. If so, fall back to the simple way. */
8799 if (packet
->support
== PACKET_DISABLE
)
8801 return simple_search_memory (ops
, start_addr
, search_space_len
,
8802 pattern
, pattern_len
, found_addrp
);
8807 if (rs
->buf
[0] == '0')
8809 else if (rs
->buf
[0] == '1')
8812 if (rs
->buf
[1] != ',')
8813 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8814 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8815 *found_addrp
= found_addr
;
8818 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8824 remote_rcmd (char *command
,
8825 struct ui_file
*outbuf
)
8827 struct remote_state
*rs
= get_remote_state ();
8831 error (_("remote rcmd is only available after target open"));
8833 /* Send a NULL command across as an empty command. */
8834 if (command
== NULL
)
8837 /* The query prefix. */
8838 strcpy (rs
->buf
, "qRcmd,");
8839 p
= strchr (rs
->buf
, '\0');
8841 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
8842 > get_remote_packet_size ())
8843 error (_("\"monitor\" command ``%s'' is too long."), command
);
8845 /* Encode the actual command. */
8846 bin2hex ((gdb_byte
*) command
, p
, 0);
8848 if (putpkt (rs
->buf
) < 0)
8849 error (_("Communication problem with target."));
8851 /* get/display the response */
8856 /* XXX - see also remote_get_noisy_reply(). */
8857 QUIT
; /* Allow user to bail out with ^C. */
8859 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
8861 /* Timeout. Continue to (try to) read responses.
8862 This is better than stopping with an error, assuming the stub
8863 is still executing the (long) monitor command.
8864 If needed, the user can interrupt gdb using C-c, obtaining
8865 an effect similar to stop on timeout. */
8870 error (_("Target does not support this command."));
8871 if (buf
[0] == 'O' && buf
[1] != 'K')
8873 remote_console_output (buf
+ 1); /* 'O' message from stub. */
8876 if (strcmp (buf
, "OK") == 0)
8878 if (strlen (buf
) == 3 && buf
[0] == 'E'
8879 && isdigit (buf
[1]) && isdigit (buf
[2]))
8881 error (_("Protocol error with Rcmd"));
8883 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
8885 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
8887 fputc_unfiltered (c
, outbuf
);
8893 static VEC(mem_region_s
) *
8894 remote_memory_map (struct target_ops
*ops
)
8896 VEC(mem_region_s
) *result
= NULL
;
8897 char *text
= target_read_stralloc (¤t_target
,
8898 TARGET_OBJECT_MEMORY_MAP
, NULL
);
8902 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
8904 result
= parse_memory_map (text
);
8905 do_cleanups (back_to
);
8912 packet_command (char *args
, int from_tty
)
8914 struct remote_state
*rs
= get_remote_state ();
8917 error (_("command can only be used with remote target"));
8920 error (_("remote-packet command requires packet text as argument"));
8922 puts_filtered ("sending: ");
8923 print_packet (args
);
8924 puts_filtered ("\n");
8927 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8928 puts_filtered ("received: ");
8929 print_packet (rs
->buf
);
8930 puts_filtered ("\n");
8934 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
8936 static void display_thread_info (struct gdb_ext_thread_info
*info
);
8938 static void threadset_test_cmd (char *cmd
, int tty
);
8940 static void threadalive_test (char *cmd
, int tty
);
8942 static void threadlist_test_cmd (char *cmd
, int tty
);
8944 int get_and_display_threadinfo (threadref
*ref
);
8946 static void threadinfo_test_cmd (char *cmd
, int tty
);
8948 static int thread_display_step (threadref
*ref
, void *context
);
8950 static void threadlist_update_test_cmd (char *cmd
, int tty
);
8952 static void init_remote_threadtests (void);
8954 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
8957 threadset_test_cmd (char *cmd
, int tty
)
8959 int sample_thread
= SAMPLE_THREAD
;
8961 printf_filtered (_("Remote threadset test\n"));
8962 set_general_thread (sample_thread
);
8967 threadalive_test (char *cmd
, int tty
)
8969 int sample_thread
= SAMPLE_THREAD
;
8970 int pid
= ptid_get_pid (inferior_ptid
);
8971 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
8973 if (remote_thread_alive (ptid
))
8974 printf_filtered ("PASS: Thread alive test\n");
8976 printf_filtered ("FAIL: Thread alive test\n");
8979 void output_threadid (char *title
, threadref
*ref
);
8982 output_threadid (char *title
, threadref
*ref
)
8986 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
8988 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
8992 threadlist_test_cmd (char *cmd
, int tty
)
8995 threadref nextthread
;
8996 int done
, result_count
;
8997 threadref threadlist
[3];
8999 printf_filtered ("Remote Threadlist test\n");
9000 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9001 &result_count
, &threadlist
[0]))
9002 printf_filtered ("FAIL: threadlist test\n");
9005 threadref
*scan
= threadlist
;
9006 threadref
*limit
= scan
+ result_count
;
9008 while (scan
< limit
)
9009 output_threadid (" thread ", scan
++);
9014 display_thread_info (struct gdb_ext_thread_info
*info
)
9016 output_threadid ("Threadid: ", &info
->threadid
);
9017 printf_filtered ("Name: %s\n ", info
->shortname
);
9018 printf_filtered ("State: %s\n", info
->display
);
9019 printf_filtered ("other: %s\n\n", info
->more_display
);
9023 get_and_display_threadinfo (threadref
*ref
)
9027 struct gdb_ext_thread_info threadinfo
;
9029 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9030 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9031 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9032 display_thread_info (&threadinfo
);
9037 threadinfo_test_cmd (char *cmd
, int tty
)
9039 int athread
= SAMPLE_THREAD
;
9043 int_to_threadref (&thread
, athread
);
9044 printf_filtered ("Remote Threadinfo test\n");
9045 if (!get_and_display_threadinfo (&thread
))
9046 printf_filtered ("FAIL cannot get thread info\n");
9050 thread_display_step (threadref
*ref
, void *context
)
9052 /* output_threadid(" threadstep ",ref); *//* simple test */
9053 return get_and_display_threadinfo (ref
);
9057 threadlist_update_test_cmd (char *cmd
, int tty
)
9059 printf_filtered ("Remote Threadlist update test\n");
9060 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9064 init_remote_threadtests (void)
9066 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9067 _("Fetch and print the remote list of "
9068 "thread identifiers, one pkt only"));
9069 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9070 _("Fetch and display info about one thread"));
9071 add_com ("tset", class_obscure
, threadset_test_cmd
,
9072 _("Test setting to a different thread"));
9073 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9074 _("Iterate through updating all remote thread info"));
9075 add_com ("talive", class_obscure
, threadalive_test
,
9076 _(" Remote thread alive test "));
9081 /* Convert a thread ID to a string. Returns the string in a static
9085 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
9087 static char buf
[64];
9088 struct remote_state
*rs
= get_remote_state ();
9090 if (ptid_equal (ptid
, null_ptid
))
9091 return normal_pid_to_str (ptid
);
9092 else if (ptid_is_pid (ptid
))
9094 /* Printing an inferior target id. */
9096 /* When multi-process extensions are off, there's no way in the
9097 remote protocol to know the remote process id, if there's any
9098 at all. There's one exception --- when we're connected with
9099 target extended-remote, and we manually attached to a process
9100 with "attach PID". We don't record anywhere a flag that
9101 allows us to distinguish that case from the case of
9102 connecting with extended-remote and the stub already being
9103 attached to a process, and reporting yes to qAttached, hence
9104 no smart special casing here. */
9105 if (!remote_multi_process_p (rs
))
9107 xsnprintf (buf
, sizeof buf
, "Remote target");
9111 return normal_pid_to_str (ptid
);
9115 if (ptid_equal (magic_null_ptid
, ptid
))
9116 xsnprintf (buf
, sizeof buf
, "Thread <main>");
9117 else if (rs
->extended
&& remote_multi_process_p (rs
))
9118 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
9119 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
9121 xsnprintf (buf
, sizeof buf
, "Thread %ld",
9122 ptid_get_tid (ptid
));
9127 /* Get the address of the thread local variable in OBJFILE which is
9128 stored at OFFSET within the thread local storage for thread PTID. */
9131 remote_get_thread_local_address (struct target_ops
*ops
,
9132 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
9134 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
9136 struct remote_state
*rs
= get_remote_state ();
9138 char *endp
= rs
->buf
+ get_remote_packet_size ();
9139 enum packet_result result
;
9141 strcpy (p
, "qGetTLSAddr:");
9143 p
= write_ptid (p
, endp
, ptid
);
9145 p
+= hexnumstr (p
, offset
);
9147 p
+= hexnumstr (p
, lm
);
9151 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9152 result
= packet_ok (rs
->buf
,
9153 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
9154 if (result
== PACKET_OK
)
9158 unpack_varlen_hex (rs
->buf
, &result
);
9161 else if (result
== PACKET_UNKNOWN
)
9162 throw_error (TLS_GENERIC_ERROR
,
9163 _("Remote target doesn't support qGetTLSAddr packet"));
9165 throw_error (TLS_GENERIC_ERROR
,
9166 _("Remote target failed to process qGetTLSAddr request"));
9169 throw_error (TLS_GENERIC_ERROR
,
9170 _("TLS not supported or disabled on this target"));
9175 /* Provide thread local base, i.e. Thread Information Block address.
9176 Returns 1 if ptid is found and thread_local_base is non zero. */
9179 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
9181 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
9183 struct remote_state
*rs
= get_remote_state ();
9185 char *endp
= rs
->buf
+ get_remote_packet_size ();
9186 enum packet_result result
;
9188 strcpy (p
, "qGetTIBAddr:");
9190 p
= write_ptid (p
, endp
, ptid
);
9194 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9195 result
= packet_ok (rs
->buf
,
9196 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
9197 if (result
== PACKET_OK
)
9201 unpack_varlen_hex (rs
->buf
, &result
);
9203 *addr
= (CORE_ADDR
) result
;
9206 else if (result
== PACKET_UNKNOWN
)
9207 error (_("Remote target doesn't support qGetTIBAddr packet"));
9209 error (_("Remote target failed to process qGetTIBAddr request"));
9212 error (_("qGetTIBAddr not supported or disabled on this target"));
9217 /* Support for inferring a target description based on the current
9218 architecture and the size of a 'g' packet. While the 'g' packet
9219 can have any size (since optional registers can be left off the
9220 end), some sizes are easily recognizable given knowledge of the
9221 approximate architecture. */
9223 struct remote_g_packet_guess
9226 const struct target_desc
*tdesc
;
9228 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
9229 DEF_VEC_O(remote_g_packet_guess_s
);
9231 struct remote_g_packet_data
9233 VEC(remote_g_packet_guess_s
) *guesses
;
9236 static struct gdbarch_data
*remote_g_packet_data_handle
;
9239 remote_g_packet_data_init (struct obstack
*obstack
)
9241 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
9245 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
9246 const struct target_desc
*tdesc
)
9248 struct remote_g_packet_data
*data
9249 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
9250 struct remote_g_packet_guess new_guess
, *guess
;
9253 gdb_assert (tdesc
!= NULL
);
9256 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9258 if (guess
->bytes
== bytes
)
9259 internal_error (__FILE__
, __LINE__
,
9260 _("Duplicate g packet description added for size %d"),
9263 new_guess
.bytes
= bytes
;
9264 new_guess
.tdesc
= tdesc
;
9265 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
9268 /* Return 1 if remote_read_description would do anything on this target
9269 and architecture, 0 otherwise. */
9272 remote_read_description_p (struct target_ops
*target
)
9274 struct remote_g_packet_data
*data
9275 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
9277 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9283 static const struct target_desc
*
9284 remote_read_description (struct target_ops
*target
)
9286 struct remote_g_packet_data
*data
9287 = gdbarch_data (target_gdbarch
, remote_g_packet_data_handle
);
9289 /* Do not try this during initial connection, when we do not know
9290 whether there is a running but stopped thread. */
9291 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
9294 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9296 struct remote_g_packet_guess
*guess
;
9298 int bytes
= send_g_packet ();
9301 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9303 if (guess
->bytes
== bytes
)
9304 return guess
->tdesc
;
9306 /* We discard the g packet. A minor optimization would be to
9307 hold on to it, and fill the register cache once we have selected
9308 an architecture, but it's too tricky to do safely. */
9314 /* Remote file transfer support. This is host-initiated I/O, not
9315 target-initiated; for target-initiated, see remote-fileio.c. */
9317 /* If *LEFT is at least the length of STRING, copy STRING to
9318 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9319 decrease *LEFT. Otherwise raise an error. */
9322 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9324 int len
= strlen (string
);
9327 error (_("Packet too long for target."));
9329 memcpy (*buffer
, string
, len
);
9333 /* NUL-terminate the buffer as a convenience, if there is
9339 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9340 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9341 decrease *LEFT. Otherwise raise an error. */
9344 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9347 if (2 * len
> *left
)
9348 error (_("Packet too long for target."));
9350 bin2hex (bytes
, *buffer
, len
);
9354 /* NUL-terminate the buffer as a convenience, if there is
9360 /* If *LEFT is large enough, convert VALUE to hex and add it to
9361 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9362 decrease *LEFT. Otherwise raise an error. */
9365 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9367 int len
= hexnumlen (value
);
9370 error (_("Packet too long for target."));
9372 hexnumstr (*buffer
, value
);
9376 /* NUL-terminate the buffer as a convenience, if there is
9382 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9383 value, *REMOTE_ERRNO to the remote error number or zero if none
9384 was included, and *ATTACHMENT to point to the start of the annex
9385 if any. The length of the packet isn't needed here; there may
9386 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9388 Return 0 if the packet could be parsed, -1 if it could not. If
9389 -1 is returned, the other variables may not be initialized. */
9392 remote_hostio_parse_result (char *buffer
, int *retcode
,
9393 int *remote_errno
, char **attachment
)
9400 if (buffer
[0] != 'F')
9404 *retcode
= strtol (&buffer
[1], &p
, 16);
9405 if (errno
!= 0 || p
== &buffer
[1])
9408 /* Check for ",errno". */
9412 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9413 if (errno
!= 0 || p
+ 1 == p2
)
9418 /* Check for ";attachment". If there is no attachment, the
9419 packet should end here. */
9422 *attachment
= p
+ 1;
9425 else if (*p
== '\0')
9431 /* Send a prepared I/O packet to the target and read its response.
9432 The prepared packet is in the global RS->BUF before this function
9433 is called, and the answer is there when we return.
9435 COMMAND_BYTES is the length of the request to send, which may include
9436 binary data. WHICH_PACKET is the packet configuration to check
9437 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9438 is set to the error number and -1 is returned. Otherwise the value
9439 returned by the function is returned.
9441 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9442 attachment is expected; an error will be reported if there's a
9443 mismatch. If one is found, *ATTACHMENT will be set to point into
9444 the packet buffer and *ATTACHMENT_LEN will be set to the
9445 attachment's length. */
9448 remote_hostio_send_command (int command_bytes
, int which_packet
,
9449 int *remote_errno
, char **attachment
,
9450 int *attachment_len
)
9452 struct remote_state
*rs
= get_remote_state ();
9453 int ret
, bytes_read
;
9454 char *attachment_tmp
;
9457 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9459 *remote_errno
= FILEIO_ENOSYS
;
9463 putpkt_binary (rs
->buf
, command_bytes
);
9464 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9466 /* If it timed out, something is wrong. Don't try to parse the
9470 *remote_errno
= FILEIO_EINVAL
;
9474 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9477 *remote_errno
= FILEIO_EINVAL
;
9479 case PACKET_UNKNOWN
:
9480 *remote_errno
= FILEIO_ENOSYS
;
9486 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9489 *remote_errno
= FILEIO_EINVAL
;
9493 /* Make sure we saw an attachment if and only if we expected one. */
9494 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9495 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9497 *remote_errno
= FILEIO_EINVAL
;
9501 /* If an attachment was found, it must point into the packet buffer;
9502 work out how many bytes there were. */
9503 if (attachment_tmp
!= NULL
)
9505 *attachment
= attachment_tmp
;
9506 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9512 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9513 remote file descriptor, or -1 if an error occurs (and set
9517 remote_hostio_open (const char *filename
, int flags
, int mode
,
9520 struct remote_state
*rs
= get_remote_state ();
9522 int left
= get_remote_packet_size () - 1;
9524 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9526 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9528 remote_buffer_add_string (&p
, &left
, ",");
9530 remote_buffer_add_int (&p
, &left
, flags
);
9531 remote_buffer_add_string (&p
, &left
, ",");
9533 remote_buffer_add_int (&p
, &left
, mode
);
9535 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9536 remote_errno
, NULL
, NULL
);
9539 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9540 Return the number of bytes written, or -1 if an error occurs (and
9541 set *REMOTE_ERRNO). */
9544 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9545 ULONGEST offset
, int *remote_errno
)
9547 struct remote_state
*rs
= get_remote_state ();
9549 int left
= get_remote_packet_size ();
9552 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9554 remote_buffer_add_int (&p
, &left
, fd
);
9555 remote_buffer_add_string (&p
, &left
, ",");
9557 remote_buffer_add_int (&p
, &left
, offset
);
9558 remote_buffer_add_string (&p
, &left
, ",");
9560 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
9561 get_remote_packet_size () - (p
- rs
->buf
));
9563 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9564 remote_errno
, NULL
, NULL
);
9567 /* Read up to LEN bytes FD on the remote target into READ_BUF
9568 Return the number of bytes read, or -1 if an error occurs (and
9569 set *REMOTE_ERRNO). */
9572 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9573 ULONGEST offset
, int *remote_errno
)
9575 struct remote_state
*rs
= get_remote_state ();
9578 int left
= get_remote_packet_size ();
9579 int ret
, attachment_len
;
9582 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9584 remote_buffer_add_int (&p
, &left
, fd
);
9585 remote_buffer_add_string (&p
, &left
, ",");
9587 remote_buffer_add_int (&p
, &left
, len
);
9588 remote_buffer_add_string (&p
, &left
, ",");
9590 remote_buffer_add_int (&p
, &left
, offset
);
9592 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9593 remote_errno
, &attachment
,
9599 read_len
= remote_unescape_input (attachment
, attachment_len
,
9601 if (read_len
!= ret
)
9602 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9607 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9608 (and set *REMOTE_ERRNO). */
9611 remote_hostio_close (int fd
, int *remote_errno
)
9613 struct remote_state
*rs
= get_remote_state ();
9615 int left
= get_remote_packet_size () - 1;
9617 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9619 remote_buffer_add_int (&p
, &left
, fd
);
9621 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9622 remote_errno
, NULL
, NULL
);
9625 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9626 occurs (and set *REMOTE_ERRNO). */
9629 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9631 struct remote_state
*rs
= get_remote_state ();
9633 int left
= get_remote_packet_size () - 1;
9635 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9637 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9640 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9641 remote_errno
, NULL
, NULL
);
9644 /* Read value of symbolic link FILENAME on the remote target. Return
9645 a null-terminated string allocated via xmalloc, or NULL if an error
9646 occurs (and set *REMOTE_ERRNO). */
9649 remote_hostio_readlink (const char *filename
, int *remote_errno
)
9651 struct remote_state
*rs
= get_remote_state ();
9654 int left
= get_remote_packet_size ();
9655 int len
, attachment_len
;
9659 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
9661 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9664 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
9665 remote_errno
, &attachment
,
9671 ret
= xmalloc (len
+ 1);
9673 read_len
= remote_unescape_input (attachment
, attachment_len
,
9675 if (read_len
!= len
)
9676 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
9683 remote_fileio_errno_to_host (int errnum
)
9707 case FILEIO_ENOTDIR
:
9727 case FILEIO_ENAMETOOLONG
:
9728 return ENAMETOOLONG
;
9734 remote_hostio_error (int errnum
)
9736 int host_error
= remote_fileio_errno_to_host (errnum
);
9738 if (host_error
== -1)
9739 error (_("Unknown remote I/O error %d"), errnum
);
9741 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
9745 remote_hostio_close_cleanup (void *opaque
)
9747 int fd
= *(int *) opaque
;
9750 remote_hostio_close (fd
, &remote_errno
);
9755 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
9757 const char *filename
= bfd_get_filename (abfd
);
9758 int fd
, remote_errno
;
9761 gdb_assert (remote_filename_p (filename
));
9763 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
9766 errno
= remote_fileio_errno_to_host (remote_errno
);
9767 bfd_set_error (bfd_error_system_call
);
9771 stream
= xmalloc (sizeof (int));
9777 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
9779 int fd
= *(int *)stream
;
9784 /* Ignore errors on close; these may happen if the remote
9785 connection was already torn down. */
9786 remote_hostio_close (fd
, &remote_errno
);
9792 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
9793 file_ptr nbytes
, file_ptr offset
)
9795 int fd
= *(int *)stream
;
9797 file_ptr pos
, bytes
;
9800 while (nbytes
> pos
)
9802 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
9803 offset
+ pos
, &remote_errno
);
9805 /* Success, but no bytes, means end-of-file. */
9809 errno
= remote_fileio_errno_to_host (remote_errno
);
9810 bfd_set_error (bfd_error_system_call
);
9821 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
9823 /* FIXME: We should probably implement remote_hostio_stat. */
9824 sb
->st_size
= INT_MAX
;
9829 remote_filename_p (const char *filename
)
9831 return strncmp (filename
, "remote:", 7) == 0;
9835 remote_bfd_open (const char *remote_file
, const char *target
)
9837 bfd
*abfd
= gdb_bfd_openr_iovec (remote_file
, target
,
9838 remote_bfd_iovec_open
, NULL
,
9839 remote_bfd_iovec_pread
,
9840 remote_bfd_iovec_close
,
9841 remote_bfd_iovec_stat
);
9847 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
9849 struct cleanup
*back_to
, *close_cleanup
;
9850 int retcode
, fd
, remote_errno
, bytes
, io_size
;
9853 int bytes_in_buffer
;
9858 error (_("command can only be used with remote target"));
9860 file
= fopen (local_file
, "rb");
9862 perror_with_name (local_file
);
9863 back_to
= make_cleanup_fclose (file
);
9865 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
9867 0700, &remote_errno
);
9869 remote_hostio_error (remote_errno
);
9871 /* Send up to this many bytes at once. They won't all fit in the
9872 remote packet limit, so we'll transfer slightly fewer. */
9873 io_size
= get_remote_packet_size ();
9874 buffer
= xmalloc (io_size
);
9875 make_cleanup (xfree
, buffer
);
9877 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9879 bytes_in_buffer
= 0;
9882 while (bytes_in_buffer
|| !saw_eof
)
9886 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
9887 io_size
- bytes_in_buffer
,
9892 error (_("Error reading %s."), local_file
);
9895 /* EOF. Unless there is something still in the
9896 buffer from the last iteration, we are done. */
9898 if (bytes_in_buffer
== 0)
9906 bytes
+= bytes_in_buffer
;
9907 bytes_in_buffer
= 0;
9909 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
9910 offset
, &remote_errno
);
9913 remote_hostio_error (remote_errno
);
9914 else if (retcode
== 0)
9915 error (_("Remote write of %d bytes returned 0!"), bytes
);
9916 else if (retcode
< bytes
)
9918 /* Short write. Save the rest of the read data for the next
9920 bytes_in_buffer
= bytes
- retcode
;
9921 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
9927 discard_cleanups (close_cleanup
);
9928 if (remote_hostio_close (fd
, &remote_errno
))
9929 remote_hostio_error (remote_errno
);
9932 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
9933 do_cleanups (back_to
);
9937 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
9939 struct cleanup
*back_to
, *close_cleanup
;
9940 int fd
, remote_errno
, bytes
, io_size
;
9946 error (_("command can only be used with remote target"));
9948 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
9950 remote_hostio_error (remote_errno
);
9952 file
= fopen (local_file
, "wb");
9954 perror_with_name (local_file
);
9955 back_to
= make_cleanup_fclose (file
);
9957 /* Send up to this many bytes at once. They won't all fit in the
9958 remote packet limit, so we'll transfer slightly fewer. */
9959 io_size
= get_remote_packet_size ();
9960 buffer
= xmalloc (io_size
);
9961 make_cleanup (xfree
, buffer
);
9963 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9968 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
9970 /* Success, but no bytes, means end-of-file. */
9973 remote_hostio_error (remote_errno
);
9977 bytes
= fwrite (buffer
, 1, bytes
, file
);
9979 perror_with_name (local_file
);
9982 discard_cleanups (close_cleanup
);
9983 if (remote_hostio_close (fd
, &remote_errno
))
9984 remote_hostio_error (remote_errno
);
9987 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
9988 do_cleanups (back_to
);
9992 remote_file_delete (const char *remote_file
, int from_tty
)
9994 int retcode
, remote_errno
;
9997 error (_("command can only be used with remote target"));
9999 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
10001 remote_hostio_error (remote_errno
);
10004 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
10008 remote_put_command (char *args
, int from_tty
)
10010 struct cleanup
*back_to
;
10014 error_no_arg (_("file to put"));
10016 argv
= gdb_buildargv (args
);
10017 back_to
= make_cleanup_freeargv (argv
);
10018 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10019 error (_("Invalid parameters to remote put"));
10021 remote_file_put (argv
[0], argv
[1], from_tty
);
10023 do_cleanups (back_to
);
10027 remote_get_command (char *args
, int from_tty
)
10029 struct cleanup
*back_to
;
10033 error_no_arg (_("file to get"));
10035 argv
= gdb_buildargv (args
);
10036 back_to
= make_cleanup_freeargv (argv
);
10037 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10038 error (_("Invalid parameters to remote get"));
10040 remote_file_get (argv
[0], argv
[1], from_tty
);
10042 do_cleanups (back_to
);
10046 remote_delete_command (char *args
, int from_tty
)
10048 struct cleanup
*back_to
;
10052 error_no_arg (_("file to delete"));
10054 argv
= gdb_buildargv (args
);
10055 back_to
= make_cleanup_freeargv (argv
);
10056 if (argv
[0] == NULL
|| argv
[1] != NULL
)
10057 error (_("Invalid parameters to remote delete"));
10059 remote_file_delete (argv
[0], from_tty
);
10061 do_cleanups (back_to
);
10065 remote_command (char *args
, int from_tty
)
10067 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
10071 remote_can_execute_reverse (void)
10073 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
10074 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
10081 remote_supports_non_stop (void)
10087 remote_supports_disable_randomization (void)
10089 /* Only supported in extended mode. */
10094 remote_supports_multi_process (void)
10096 struct remote_state
*rs
= get_remote_state ();
10098 /* Only extended-remote handles being attached to multiple
10099 processes, even though plain remote can use the multi-process
10100 thread id extensions, so that GDB knows the target process's
10102 return rs
->extended
&& remote_multi_process_p (rs
);
10106 remote_supports_cond_tracepoints (void)
10108 struct remote_state
*rs
= get_remote_state ();
10110 return rs
->cond_tracepoints
;
10114 remote_supports_cond_breakpoints (void)
10116 struct remote_state
*rs
= get_remote_state ();
10118 return rs
->cond_breakpoints
;
10122 remote_supports_fast_tracepoints (void)
10124 struct remote_state
*rs
= get_remote_state ();
10126 return rs
->fast_tracepoints
;
10130 remote_supports_static_tracepoints (void)
10132 struct remote_state
*rs
= get_remote_state ();
10134 return rs
->static_tracepoints
;
10138 remote_supports_install_in_trace (void)
10140 struct remote_state
*rs
= get_remote_state ();
10142 return rs
->install_in_trace
;
10146 remote_supports_enable_disable_tracepoint (void)
10148 struct remote_state
*rs
= get_remote_state ();
10150 return rs
->enable_disable_tracepoints
;
10154 remote_supports_string_tracing (void)
10156 struct remote_state
*rs
= get_remote_state ();
10158 return rs
->string_tracing
;
10162 remote_can_run_breakpoint_commands (void)
10164 struct remote_state
*rs
= get_remote_state ();
10166 return rs
->breakpoint_commands
;
10170 remote_trace_init (void)
10173 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10174 if (strcmp (target_buf
, "OK") != 0)
10175 error (_("Target does not support this command."));
10178 static void free_actions_list (char **actions_list
);
10179 static void free_actions_list_cleanup_wrapper (void *);
10181 free_actions_list_cleanup_wrapper (void *al
)
10183 free_actions_list (al
);
10187 free_actions_list (char **actions_list
)
10191 if (actions_list
== 0)
10194 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
10195 xfree (actions_list
[ndx
]);
10197 xfree (actions_list
);
10200 /* Recursive routine to walk through command list including loops, and
10201 download packets for each command. */
10204 remote_download_command_source (int num
, ULONGEST addr
,
10205 struct command_line
*cmds
)
10207 struct remote_state
*rs
= get_remote_state ();
10208 struct command_line
*cmd
;
10210 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
10212 QUIT
; /* Allow user to bail out with ^C. */
10213 strcpy (rs
->buf
, "QTDPsrc:");
10214 encode_source_string (num
, addr
, "cmd", cmd
->line
,
10215 rs
->buf
+ strlen (rs
->buf
),
10216 rs
->buf_size
- strlen (rs
->buf
));
10218 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10219 if (strcmp (target_buf
, "OK"))
10220 warning (_("Target does not support source download."));
10222 if (cmd
->control_type
== while_control
10223 || cmd
->control_type
== while_stepping_control
)
10225 remote_download_command_source (num
, addr
, *cmd
->body_list
);
10227 QUIT
; /* Allow user to bail out with ^C. */
10228 strcpy (rs
->buf
, "QTDPsrc:");
10229 encode_source_string (num
, addr
, "cmd", "end",
10230 rs
->buf
+ strlen (rs
->buf
),
10231 rs
->buf_size
- strlen (rs
->buf
));
10233 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10234 if (strcmp (target_buf
, "OK"))
10235 warning (_("Target does not support source download."));
10241 remote_download_tracepoint (struct bp_location
*loc
)
10243 #define BUF_SIZE 2048
10247 char buf
[BUF_SIZE
];
10248 char **tdp_actions
;
10249 char **stepping_actions
;
10251 struct cleanup
*old_chain
= NULL
;
10252 struct agent_expr
*aexpr
;
10253 struct cleanup
*aexpr_chain
= NULL
;
10255 struct breakpoint
*b
= loc
->owner
;
10256 struct tracepoint
*t
= (struct tracepoint
*) b
;
10258 encode_actions (loc
->owner
, loc
, &tdp_actions
, &stepping_actions
);
10259 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
10261 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
10264 tpaddr
= loc
->address
;
10265 sprintf_vma (addrbuf
, tpaddr
);
10266 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
10267 addrbuf
, /* address */
10268 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
10269 t
->step_count
, t
->pass_count
);
10270 /* Fast tracepoints are mostly handled by the target, but we can
10271 tell the target how big of an instruction block should be moved
10273 if (b
->type
== bp_fast_tracepoint
)
10275 /* Only test for support at download time; we may not know
10276 target capabilities at definition time. */
10277 if (remote_supports_fast_tracepoints ())
10281 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch
,
10282 tpaddr
, &isize
, NULL
))
10283 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
10286 /* If it passed validation at definition but fails now,
10287 something is very wrong. */
10288 internal_error (__FILE__
, __LINE__
,
10289 _("Fast tracepoint not "
10290 "valid during download"));
10293 /* Fast tracepoints are functionally identical to regular
10294 tracepoints, so don't take lack of support as a reason to
10295 give up on the trace run. */
10296 warning (_("Target does not support fast tracepoints, "
10297 "downloading %d as regular tracepoint"), b
->number
);
10299 else if (b
->type
== bp_static_tracepoint
)
10301 /* Only test for support at download time; we may not know
10302 target capabilities at definition time. */
10303 if (remote_supports_static_tracepoints ())
10305 struct static_tracepoint_marker marker
;
10307 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
10308 strcat (buf
, ":S");
10310 error (_("Static tracepoint not valid during download"));
10313 /* Fast tracepoints are functionally identical to regular
10314 tracepoints, so don't take lack of support as a reason
10315 to give up on the trace run. */
10316 error (_("Target does not support static tracepoints"));
10318 /* If the tracepoint has a conditional, make it into an agent
10319 expression and append to the definition. */
10322 /* Only test support at download time, we may not know target
10323 capabilities at definition time. */
10324 if (remote_supports_cond_tracepoints ())
10326 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
10327 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
10328 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
10330 pkt
= buf
+ strlen (buf
);
10331 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
10332 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
10334 do_cleanups (aexpr_chain
);
10337 warning (_("Target does not support conditional tracepoints, "
10338 "ignoring tp %d cond"), b
->number
);
10341 if (b
->commands
|| *default_collect
)
10344 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10345 if (strcmp (target_buf
, "OK"))
10346 error (_("Target does not support tracepoints."));
10348 /* do_single_steps (t); */
10351 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
10353 QUIT
; /* Allow user to bail out with ^C. */
10354 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
10355 b
->number
, addrbuf
, /* address */
10357 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
10360 remote_get_noisy_reply (&target_buf
,
10362 if (strcmp (target_buf
, "OK"))
10363 error (_("Error on target while setting tracepoints."));
10366 if (stepping_actions
)
10368 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10370 QUIT
; /* Allow user to bail out with ^C. */
10371 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
10372 b
->number
, addrbuf
, /* address */
10373 ((ndx
== 0) ? "S" : ""),
10374 stepping_actions
[ndx
],
10375 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10377 remote_get_noisy_reply (&target_buf
,
10379 if (strcmp (target_buf
, "OK"))
10380 error (_("Error on target while setting tracepoints."));
10384 if (remote_protocol_packets
[PACKET_TracepointSource
].support
10387 if (b
->addr_string
)
10389 strcpy (buf
, "QTDPsrc:");
10390 encode_source_string (b
->number
, loc
->address
,
10391 "at", b
->addr_string
, buf
+ strlen (buf
),
10392 2048 - strlen (buf
));
10395 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10396 if (strcmp (target_buf
, "OK"))
10397 warning (_("Target does not support source download."));
10399 if (b
->cond_string
)
10401 strcpy (buf
, "QTDPsrc:");
10402 encode_source_string (b
->number
, loc
->address
,
10403 "cond", b
->cond_string
, buf
+ strlen (buf
),
10404 2048 - strlen (buf
));
10406 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10407 if (strcmp (target_buf
, "OK"))
10408 warning (_("Target does not support source download."));
10410 remote_download_command_source (b
->number
, loc
->address
,
10411 breakpoint_commands (b
));
10414 do_cleanups (old_chain
);
10418 remote_can_download_tracepoint (void)
10420 struct remote_state
*rs
= get_remote_state ();
10421 struct trace_status
*ts
;
10424 /* Don't try to install tracepoints until we've relocated our
10425 symbols, and fetched and merged the target's tracepoint list with
10427 if (rs
->starting_up
)
10430 ts
= current_trace_status ();
10431 status
= remote_get_trace_status (ts
);
10433 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10436 /* If we are in a tracing experiment, but remote stub doesn't support
10437 installing tracepoint in trace, we have to return. */
10438 if (!remote_supports_install_in_trace ())
10446 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
10448 struct remote_state
*rs
= get_remote_state ();
10451 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
10452 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
10454 p
= rs
->buf
+ strlen (rs
->buf
);
10455 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10456 error (_("Trace state variable name too long for tsv definition packet"));
10457 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
10460 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10461 if (*target_buf
== '\0')
10462 error (_("Target does not support this command."));
10463 if (strcmp (target_buf
, "OK") != 0)
10464 error (_("Error on target while downloading trace state variable."));
10468 remote_enable_tracepoint (struct bp_location
*location
)
10470 struct remote_state
*rs
= get_remote_state ();
10473 sprintf_vma (addr_buf
, location
->address
);
10474 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
10475 location
->owner
->number
, addr_buf
);
10477 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10478 if (*rs
->buf
== '\0')
10479 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10480 if (strcmp (rs
->buf
, "OK") != 0)
10481 error (_("Error on target while enabling tracepoint."));
10485 remote_disable_tracepoint (struct bp_location
*location
)
10487 struct remote_state
*rs
= get_remote_state ();
10490 sprintf_vma (addr_buf
, location
->address
);
10491 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
10492 location
->owner
->number
, addr_buf
);
10494 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10495 if (*rs
->buf
== '\0')
10496 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10497 if (strcmp (rs
->buf
, "OK") != 0)
10498 error (_("Error on target while disabling tracepoint."));
10502 remote_trace_set_readonly_regions (void)
10506 bfd_size_type size
;
10512 return; /* No information to give. */
10514 strcpy (target_buf
, "QTro");
10515 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10517 char tmp1
[40], tmp2
[40];
10520 if ((s
->flags
& SEC_LOAD
) == 0 ||
10521 /* (s->flags & SEC_CODE) == 0 || */
10522 (s
->flags
& SEC_READONLY
) == 0)
10526 vma
= bfd_get_section_vma (abfd
, s
);
10527 size
= bfd_get_section_size (s
);
10528 sprintf_vma (tmp1
, vma
);
10529 sprintf_vma (tmp2
, vma
+ size
);
10530 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10531 if (offset
+ sec_length
+ 1 > target_buf_size
)
10533 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10536 Too many sections for read-only sections definition packet."));
10539 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
10541 offset
+= sec_length
;
10545 putpkt (target_buf
);
10546 getpkt (&target_buf
, &target_buf_size
, 0);
10551 remote_trace_start (void)
10553 putpkt ("QTStart");
10554 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10555 if (*target_buf
== '\0')
10556 error (_("Target does not support this command."));
10557 if (strcmp (target_buf
, "OK") != 0)
10558 error (_("Bogus reply from target: %s"), target_buf
);
10562 remote_get_trace_status (struct trace_status
*ts
)
10564 /* Initialize it just to avoid a GCC false warning. */
10566 /* FIXME we need to get register block size some other way. */
10567 extern int trace_regblock_size
;
10568 volatile struct gdb_exception ex
;
10570 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10572 putpkt ("qTStatus");
10574 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10576 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10580 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10584 /* If the remote target doesn't do tracing, flag it. */
10588 /* We're working with a live target. */
10591 /* Set some defaults. */
10592 ts
->running_known
= 0;
10593 ts
->stop_reason
= trace_stop_reason_unknown
;
10594 ts
->traceframe_count
= -1;
10595 ts
->buffer_free
= 0;
10598 error (_("Bogus trace status reply from target: %s"), target_buf
);
10600 parse_trace_status (p
, ts
);
10602 return ts
->running
;
10606 remote_get_tracepoint_status (struct breakpoint
*bp
,
10607 struct uploaded_tp
*utp
)
10609 struct remote_state
*rs
= get_remote_state ();
10611 struct bp_location
*loc
;
10612 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10613 size_t size
= get_remote_packet_size ();
10617 tp
->base
.hit_count
= 0;
10618 tp
->traceframe_usage
= 0;
10619 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10621 /* If the tracepoint was never downloaded, don't go asking for
10623 if (tp
->number_on_target
== 0)
10625 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
10626 phex_nz (loc
->address
, 0));
10628 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10629 if (reply
&& *reply
)
10632 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10638 utp
->hit_count
= 0;
10639 utp
->traceframe_usage
= 0;
10640 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
10641 phex_nz (utp
->addr
, 0));
10643 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10644 if (reply
&& *reply
)
10647 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10653 remote_trace_stop (void)
10656 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10657 if (*target_buf
== '\0')
10658 error (_("Target does not support this command."));
10659 if (strcmp (target_buf
, "OK") != 0)
10660 error (_("Bogus reply from target: %s"), target_buf
);
10664 remote_trace_find (enum trace_find_type type
, int num
,
10665 ULONGEST addr1
, ULONGEST addr2
,
10668 struct remote_state
*rs
= get_remote_state ();
10669 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10671 int target_frameno
= -1, target_tracept
= -1;
10673 /* Lookups other than by absolute frame number depend on the current
10674 trace selected, so make sure it is correct on the remote end
10676 if (type
!= tfind_number
)
10677 set_remote_traceframe ();
10680 strcpy (p
, "QTFrame:");
10681 p
= strchr (p
, '\0');
10685 xsnprintf (p
, endbuf
- p
, "%x", num
);
10688 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
10691 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
10694 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
10695 phex_nz (addr2
, 0));
10697 case tfind_outside
:
10698 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
10699 phex_nz (addr2
, 0));
10702 error (_("Unknown trace find type %d"), type
);
10706 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
10707 if (*reply
== '\0')
10708 error (_("Target does not support this command."));
10710 while (reply
&& *reply
)
10715 target_frameno
= (int) strtol (p
, &reply
, 16);
10717 error (_("Unable to parse trace frame number"));
10718 /* Don't update our remote traceframe number cache on failure
10719 to select a remote traceframe. */
10720 if (target_frameno
== -1)
10725 target_tracept
= (int) strtol (p
, &reply
, 16);
10727 error (_("Unable to parse tracepoint number"));
10729 case 'O': /* "OK"? */
10730 if (reply
[1] == 'K' && reply
[2] == '\0')
10733 error (_("Bogus reply from target: %s"), reply
);
10736 error (_("Bogus reply from target: %s"), reply
);
10739 *tpp
= target_tracept
;
10741 remote_traceframe_number
= target_frameno
;
10742 return target_frameno
;
10746 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
10748 struct remote_state
*rs
= get_remote_state ();
10752 set_remote_traceframe ();
10754 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
10756 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10757 if (reply
&& *reply
)
10761 unpack_varlen_hex (reply
+ 1, &uval
);
10762 *val
= (LONGEST
) uval
;
10770 remote_save_trace_data (const char *filename
)
10772 struct remote_state
*rs
= get_remote_state ();
10776 strcpy (p
, "QTSave:");
10778 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
10779 error (_("Remote file name too long for trace save packet"));
10780 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
10783 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10784 if (*reply
== '\0')
10785 error (_("Target does not support this command."));
10786 if (strcmp (reply
, "OK") != 0)
10787 error (_("Bogus reply from target: %s"), reply
);
10791 /* This is basically a memory transfer, but needs to be its own packet
10792 because we don't know how the target actually organizes its trace
10793 memory, plus we want to be able to ask for as much as possible, but
10794 not be unhappy if we don't get as much as we ask for. */
10797 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
10799 struct remote_state
*rs
= get_remote_state ();
10805 strcpy (p
, "qTBuffer:");
10807 p
+= hexnumstr (p
, offset
);
10809 p
+= hexnumstr (p
, len
);
10813 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10814 if (reply
&& *reply
)
10816 /* 'l' by itself means we're at the end of the buffer and
10817 there is nothing more to get. */
10821 /* Convert the reply into binary. Limit the number of bytes to
10822 convert according to our passed-in buffer size, rather than
10823 what was returned in the packet; if the target is
10824 unexpectedly generous and gives us a bigger reply than we
10825 asked for, we don't want to crash. */
10826 rslt
= hex2bin (target_buf
, buf
, len
);
10830 /* Something went wrong, flag as an error. */
10835 remote_set_disconnected_tracing (int val
)
10837 struct remote_state
*rs
= get_remote_state ();
10839 if (rs
->disconnected_tracing
)
10843 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
10845 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10846 if (*reply
== '\0')
10847 error (_("Target does not support this command."));
10848 if (strcmp (reply
, "OK") != 0)
10849 error (_("Bogus reply from target: %s"), reply
);
10852 warning (_("Target does not support disconnected tracing."));
10856 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
10858 struct thread_info
*info
= find_thread_ptid (ptid
);
10860 if (info
&& info
->private)
10861 return info
->private->core
;
10866 remote_set_circular_trace_buffer (int val
)
10868 struct remote_state
*rs
= get_remote_state ();
10871 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
10873 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10874 if (*reply
== '\0')
10875 error (_("Target does not support this command."));
10876 if (strcmp (reply
, "OK") != 0)
10877 error (_("Bogus reply from target: %s"), reply
);
10880 static struct traceframe_info
*
10881 remote_traceframe_info (void)
10885 text
= target_read_stralloc (¤t_target
,
10886 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
10889 struct traceframe_info
*info
;
10890 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10892 info
= parse_traceframe_info (text
);
10893 do_cleanups (back_to
);
10900 /* Handle the qTMinFTPILen packet. Returns the minimum length of
10901 instruction on which a fast tracepoint may be placed. Returns -1
10902 if the packet is not supported, and 0 if the minimum instruction
10903 length is unknown. */
10906 remote_get_min_fast_tracepoint_insn_len (void)
10908 struct remote_state
*rs
= get_remote_state ();
10911 /* If we're not debugging a process yet, the IPA can't be
10913 if (!target_has_execution
)
10916 /* Make sure the remote is pointing at the right process. */
10917 set_general_process ();
10919 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
10921 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10922 if (*reply
== '\0')
10926 ULONGEST min_insn_len
;
10928 unpack_varlen_hex (reply
, &min_insn_len
);
10930 return (int) min_insn_len
;
10935 remote_set_trace_notes (char *user
, char *notes
, char *stop_notes
)
10937 struct remote_state
*rs
= get_remote_state ();
10939 char *buf
= rs
->buf
;
10940 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10943 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
10946 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
10947 nbytes
= bin2hex (user
, buf
, 0);
10953 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
10954 nbytes
= bin2hex (notes
, buf
, 0);
10960 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
10961 nbytes
= bin2hex (stop_notes
, buf
, 0);
10965 /* Ensure the buffer is terminated. */
10969 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10970 if (*reply
== '\0')
10973 if (strcmp (reply
, "OK") != 0)
10974 error (_("Bogus reply from target: %s"), reply
);
10980 remote_use_agent (int use
)
10982 if (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
)
10984 struct remote_state
*rs
= get_remote_state ();
10986 /* If the stub supports QAgent. */
10987 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
10989 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
10991 if (strcmp (rs
->buf
, "OK") == 0)
11002 remote_can_use_agent (void)
11004 return (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
);
11008 init_remote_ops (void)
11010 remote_ops
.to_shortname
= "remote";
11011 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
11012 remote_ops
.to_doc
=
11013 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11014 Specify the serial device it is connected to\n\
11015 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
11016 remote_ops
.to_open
= remote_open
;
11017 remote_ops
.to_close
= remote_close
;
11018 remote_ops
.to_detach
= remote_detach
;
11019 remote_ops
.to_disconnect
= remote_disconnect
;
11020 remote_ops
.to_resume
= remote_resume
;
11021 remote_ops
.to_wait
= remote_wait
;
11022 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
11023 remote_ops
.to_store_registers
= remote_store_registers
;
11024 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
11025 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
11026 remote_ops
.to_files_info
= remote_files_info
;
11027 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
11028 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
11029 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
11030 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
11031 remote_ops
.to_watchpoint_addr_within_range
=
11032 remote_watchpoint_addr_within_range
;
11033 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
11034 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
11035 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
11036 remote_ops
.to_region_ok_for_hw_watchpoint
11037 = remote_region_ok_for_hw_watchpoint
;
11038 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
11039 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
11040 remote_ops
.to_kill
= remote_kill
;
11041 remote_ops
.to_load
= generic_load
;
11042 remote_ops
.to_mourn_inferior
= remote_mourn
;
11043 remote_ops
.to_pass_signals
= remote_pass_signals
;
11044 remote_ops
.to_program_signals
= remote_program_signals
;
11045 remote_ops
.to_thread_alive
= remote_thread_alive
;
11046 remote_ops
.to_find_new_threads
= remote_threads_info
;
11047 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
11048 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
11049 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
11050 remote_ops
.to_stop
= remote_stop
;
11051 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
11052 remote_ops
.to_rcmd
= remote_rcmd
;
11053 remote_ops
.to_log_command
= serial_log_command
;
11054 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
11055 remote_ops
.to_stratum
= process_stratum
;
11056 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
11057 remote_ops
.to_has_memory
= default_child_has_memory
;
11058 remote_ops
.to_has_stack
= default_child_has_stack
;
11059 remote_ops
.to_has_registers
= default_child_has_registers
;
11060 remote_ops
.to_has_execution
= default_child_has_execution
;
11061 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
11062 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
11063 remote_ops
.to_magic
= OPS_MAGIC
;
11064 remote_ops
.to_memory_map
= remote_memory_map
;
11065 remote_ops
.to_flash_erase
= remote_flash_erase
;
11066 remote_ops
.to_flash_done
= remote_flash_done
;
11067 remote_ops
.to_read_description
= remote_read_description
;
11068 remote_ops
.to_search_memory
= remote_search_memory
;
11069 remote_ops
.to_can_async_p
= remote_can_async_p
;
11070 remote_ops
.to_is_async_p
= remote_is_async_p
;
11071 remote_ops
.to_async
= remote_async
;
11072 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
11073 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
11074 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
11075 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
11076 remote_ops
.to_supports_disable_randomization
11077 = remote_supports_disable_randomization
;
11078 remote_ops
.to_fileio_open
= remote_hostio_open
;
11079 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
11080 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
11081 remote_ops
.to_fileio_close
= remote_hostio_close
;
11082 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
11083 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
11084 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
11085 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
11086 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
11087 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
11088 remote_ops
.to_trace_init
= remote_trace_init
;
11089 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
11090 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
11091 remote_ops
.to_download_trace_state_variable
11092 = remote_download_trace_state_variable
;
11093 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
11094 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
11095 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
11096 remote_ops
.to_trace_start
= remote_trace_start
;
11097 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
11098 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
11099 remote_ops
.to_trace_stop
= remote_trace_stop
;
11100 remote_ops
.to_trace_find
= remote_trace_find
;
11101 remote_ops
.to_get_trace_state_variable_value
11102 = remote_get_trace_state_variable_value
;
11103 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
11104 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
11105 remote_ops
.to_upload_trace_state_variables
11106 = remote_upload_trace_state_variables
;
11107 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
11108 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
11109 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
11110 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
11111 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
11112 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
11113 remote_ops
.to_verify_memory
= remote_verify_memory
;
11114 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
11115 remote_ops
.to_set_permissions
= remote_set_permissions
;
11116 remote_ops
.to_static_tracepoint_marker_at
11117 = remote_static_tracepoint_marker_at
;
11118 remote_ops
.to_static_tracepoint_markers_by_strid
11119 = remote_static_tracepoint_markers_by_strid
;
11120 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
11121 remote_ops
.to_use_agent
= remote_use_agent
;
11122 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
11125 /* Set up the extended remote vector by making a copy of the standard
11126 remote vector and adding to it. */
11129 init_extended_remote_ops (void)
11131 extended_remote_ops
= remote_ops
;
11133 extended_remote_ops
.to_shortname
= "extended-remote";
11134 extended_remote_ops
.to_longname
=
11135 "Extended remote serial target in gdb-specific protocol";
11136 extended_remote_ops
.to_doc
=
11137 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11138 Specify the serial device it is connected to (e.g. /dev/ttya).";
11139 extended_remote_ops
.to_open
= extended_remote_open
;
11140 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
11141 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
11142 extended_remote_ops
.to_detach
= extended_remote_detach
;
11143 extended_remote_ops
.to_attach
= extended_remote_attach
;
11144 extended_remote_ops
.to_kill
= extended_remote_kill
;
11145 extended_remote_ops
.to_supports_disable_randomization
11146 = extended_remote_supports_disable_randomization
;
11150 remote_can_async_p (void)
11152 if (!target_async_permitted
)
11153 /* We only enable async when the user specifically asks for it. */
11156 /* We're async whenever the serial device is. */
11157 return serial_can_async_p (remote_desc
);
11161 remote_is_async_p (void)
11163 if (!target_async_permitted
)
11164 /* We only enable async when the user specifically asks for it. */
11167 /* We're async whenever the serial device is. */
11168 return serial_is_async_p (remote_desc
);
11171 /* Pass the SERIAL event on and up to the client. One day this code
11172 will be able to delay notifying the client of an event until the
11173 point where an entire packet has been received. */
11175 static void (*async_client_callback
) (enum inferior_event_type event_type
,
11177 static void *async_client_context
;
11178 static serial_event_ftype remote_async_serial_handler
;
11181 remote_async_serial_handler (struct serial
*scb
, void *context
)
11183 /* Don't propogate error information up to the client. Instead let
11184 the client find out about the error by querying the target. */
11185 async_client_callback (INF_REG_EVENT
, async_client_context
);
11189 remote_async_inferior_event_handler (gdb_client_data data
)
11191 inferior_event_handler (INF_REG_EVENT
, NULL
);
11195 remote_async_get_pending_events_handler (gdb_client_data data
)
11197 remote_get_pending_stop_replies ();
11201 remote_async (void (*callback
) (enum inferior_event_type event_type
,
11202 void *context
), void *context
)
11204 if (callback
!= NULL
)
11206 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
11207 async_client_callback
= callback
;
11208 async_client_context
= context
;
11211 serial_async (remote_desc
, NULL
, NULL
);
11215 set_remote_cmd (char *args
, int from_tty
)
11217 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
11221 show_remote_cmd (char *args
, int from_tty
)
11223 /* We can't just use cmd_show_list here, because we want to skip
11224 the redundant "show remote Z-packet" and the legacy aliases. */
11225 struct cleanup
*showlist_chain
;
11226 struct cmd_list_element
*list
= remote_show_cmdlist
;
11227 struct ui_out
*uiout
= current_uiout
;
11229 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
11230 for (; list
!= NULL
; list
= list
->next
)
11231 if (strcmp (list
->name
, "Z-packet") == 0)
11233 else if (list
->type
== not_set_cmd
)
11234 /* Alias commands are exactly like the original, except they
11235 don't have the normal type. */
11239 struct cleanup
*option_chain
11240 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
11242 ui_out_field_string (uiout
, "name", list
->name
);
11243 ui_out_text (uiout
, ": ");
11244 if (list
->type
== show_cmd
)
11245 do_show_command ((char *) NULL
, from_tty
, list
);
11247 cmd_func (list
, NULL
, from_tty
);
11248 /* Close the tuple. */
11249 do_cleanups (option_chain
);
11252 /* Close the tuple. */
11253 do_cleanups (showlist_chain
);
11257 /* Function to be called whenever a new objfile (shlib) is detected. */
11259 remote_new_objfile (struct objfile
*objfile
)
11261 if (remote_desc
!= 0) /* Have a remote connection. */
11262 remote_check_symbols (objfile
);
11265 /* Pull all the tracepoints defined on the target and create local
11266 data structures representing them. We don't want to create real
11267 tracepoints yet, we don't want to mess up the user's existing
11271 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
11273 struct remote_state
*rs
= get_remote_state ();
11276 /* Ask for a first packet of tracepoint definition. */
11278 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11280 while (*p
&& *p
!= 'l')
11282 parse_tracepoint_definition (p
, utpp
);
11283 /* Ask for another packet of tracepoint definition. */
11285 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11292 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
11294 struct remote_state
*rs
= get_remote_state ();
11297 /* Ask for a first packet of variable definition. */
11299 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11301 while (*p
&& *p
!= 'l')
11303 parse_tsv_definition (p
, utsvp
);
11304 /* Ask for another packet of variable definition. */
11306 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11313 _initialize_remote (void)
11315 struct remote_state
*rs
;
11316 struct cmd_list_element
*cmd
;
11319 /* architecture specific data */
11320 remote_gdbarch_data_handle
=
11321 gdbarch_data_register_post_init (init_remote_state
);
11322 remote_g_packet_data_handle
=
11323 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
11325 /* Initialize the per-target state. At the moment there is only one
11326 of these, not one per target. Only one target is active at a
11327 time. The default buffer size is unimportant; it will be expanded
11328 whenever a larger buffer is needed. */
11329 rs
= get_remote_state_raw ();
11330 rs
->buf_size
= 400;
11331 rs
->buf
= xmalloc (rs
->buf_size
);
11333 init_remote_ops ();
11334 add_target (&remote_ops
);
11336 init_extended_remote_ops ();
11337 add_target (&extended_remote_ops
);
11339 /* Hook into new objfile notification. */
11340 observer_attach_new_objfile (remote_new_objfile
);
11342 /* Set up signal handlers. */
11343 sigint_remote_token
=
11344 create_async_signal_handler (async_remote_interrupt
, NULL
);
11345 sigint_remote_twice_token
=
11346 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
11349 init_remote_threadtests ();
11352 /* set/show remote ... */
11354 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
11355 Remote protocol specific variables\n\
11356 Configure various remote-protocol specific variables such as\n\
11357 the packets being used"),
11358 &remote_set_cmdlist
, "set remote ",
11359 0 /* allow-unknown */, &setlist
);
11360 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
11361 Remote protocol specific variables\n\
11362 Configure various remote-protocol specific variables such as\n\
11363 the packets being used"),
11364 &remote_show_cmdlist
, "show remote ",
11365 0 /* allow-unknown */, &showlist
);
11367 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
11368 Compare section data on target to the exec file.\n\
11369 Argument is a single section name (default: all loaded sections)."),
11372 add_cmd ("packet", class_maintenance
, packet_command
, _("\
11373 Send an arbitrary packet to a remote target.\n\
11374 maintenance packet TEXT\n\
11375 If GDB is talking to an inferior via the GDB serial protocol, then\n\
11376 this command sends the string TEXT to the inferior, and displays the\n\
11377 response packet. GDB supplies the initial `$' character, and the\n\
11378 terminating `#' character and checksum."),
11381 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
11382 Set whether to send break if interrupted."), _("\
11383 Show whether to send break if interrupted."), _("\
11384 If set, a break, instead of a cntrl-c, is sent to the remote target."),
11385 set_remotebreak
, show_remotebreak
,
11386 &setlist
, &showlist
);
11387 cmd_name
= "remotebreak";
11388 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
11389 deprecate_cmd (cmd
, "set remote interrupt-sequence");
11390 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
11391 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
11392 deprecate_cmd (cmd
, "show remote interrupt-sequence");
11394 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
11395 interrupt_sequence_modes
, &interrupt_sequence_mode
,
11397 Set interrupt sequence to remote target."), _("\
11398 Show interrupt sequence to remote target."), _("\
11399 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
11400 NULL
, show_interrupt_sequence
,
11401 &remote_set_cmdlist
,
11402 &remote_show_cmdlist
);
11404 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
11405 &interrupt_on_connect
, _("\
11406 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11407 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11408 If set, interrupt sequence is sent to remote target."),
11410 &remote_set_cmdlist
, &remote_show_cmdlist
);
11412 /* Install commands for configuring memory read/write packets. */
11414 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
11415 Set the maximum number of bytes per memory write packet (deprecated)."),
11417 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
11418 Show the maximum number of bytes per memory write packet (deprecated)."),
11420 add_cmd ("memory-write-packet-size", no_class
,
11421 set_memory_write_packet_size
, _("\
11422 Set the maximum number of bytes per memory-write packet.\n\
11423 Specify the number of bytes in a packet or 0 (zero) for the\n\
11424 default packet size. The actual limit is further reduced\n\
11425 dependent on the target. Specify ``fixed'' to disable the\n\
11426 further restriction and ``limit'' to enable that restriction."),
11427 &remote_set_cmdlist
);
11428 add_cmd ("memory-read-packet-size", no_class
,
11429 set_memory_read_packet_size
, _("\
11430 Set the maximum number of bytes per memory-read packet.\n\
11431 Specify the number of bytes in a packet or 0 (zero) for the\n\
11432 default packet size. The actual limit is further reduced\n\
11433 dependent on the target. Specify ``fixed'' to disable the\n\
11434 further restriction and ``limit'' to enable that restriction."),
11435 &remote_set_cmdlist
);
11436 add_cmd ("memory-write-packet-size", no_class
,
11437 show_memory_write_packet_size
,
11438 _("Show the maximum number of bytes per memory-write packet."),
11439 &remote_show_cmdlist
);
11440 add_cmd ("memory-read-packet-size", no_class
,
11441 show_memory_read_packet_size
,
11442 _("Show the maximum number of bytes per memory-read packet."),
11443 &remote_show_cmdlist
);
11445 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
11446 &remote_hw_watchpoint_limit
, _("\
11447 Set the maximum number of target hardware watchpoints."), _("\
11448 Show the maximum number of target hardware watchpoints."), _("\
11449 Specify a negative limit for unlimited."),
11450 NULL
, NULL
, /* FIXME: i18n: The maximum
11451 number of target hardware
11452 watchpoints is %s. */
11453 &remote_set_cmdlist
, &remote_show_cmdlist
);
11454 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
11455 &remote_hw_watchpoint_length_limit
, _("\
11456 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
11457 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
11458 Specify a negative limit for unlimited."),
11459 NULL
, NULL
, /* FIXME: i18n: The maximum
11460 length (in bytes) of a target
11461 hardware watchpoint is %s. */
11462 &remote_set_cmdlist
, &remote_show_cmdlist
);
11463 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
11464 &remote_hw_breakpoint_limit
, _("\
11465 Set the maximum number of target hardware breakpoints."), _("\
11466 Show the maximum number of target hardware breakpoints."), _("\
11467 Specify a negative limit for unlimited."),
11468 NULL
, NULL
, /* FIXME: i18n: The maximum
11469 number of target hardware
11470 breakpoints is %s. */
11471 &remote_set_cmdlist
, &remote_show_cmdlist
);
11473 add_setshow_uinteger_cmd ("remoteaddresssize", class_obscure
,
11474 &remote_address_size
, _("\
11475 Set the maximum size of the address (in bits) in a memory packet."), _("\
11476 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
11478 NULL
, /* FIXME: i18n: */
11479 &setlist
, &showlist
);
11481 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
11482 "X", "binary-download", 1);
11484 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
11485 "vCont", "verbose-resume", 0);
11487 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
11488 "QPassSignals", "pass-signals", 0);
11490 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
11491 "QProgramSignals", "program-signals", 0);
11493 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
11494 "qSymbol", "symbol-lookup", 0);
11496 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
11497 "P", "set-register", 1);
11499 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
11500 "p", "fetch-register", 1);
11502 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
11503 "Z0", "software-breakpoint", 0);
11505 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
11506 "Z1", "hardware-breakpoint", 0);
11508 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
11509 "Z2", "write-watchpoint", 0);
11511 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
11512 "Z3", "read-watchpoint", 0);
11514 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
11515 "Z4", "access-watchpoint", 0);
11517 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
11518 "qXfer:auxv:read", "read-aux-vector", 0);
11520 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
11521 "qXfer:features:read", "target-features", 0);
11523 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
11524 "qXfer:libraries:read", "library-info", 0);
11526 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
11527 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
11529 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
11530 "qXfer:memory-map:read", "memory-map", 0);
11532 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
11533 "qXfer:spu:read", "read-spu-object", 0);
11535 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
11536 "qXfer:spu:write", "write-spu-object", 0);
11538 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
11539 "qXfer:osdata:read", "osdata", 0);
11541 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
11542 "qXfer:threads:read", "threads", 0);
11544 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
11545 "qXfer:siginfo:read", "read-siginfo-object", 0);
11547 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
11548 "qXfer:siginfo:write", "write-siginfo-object", 0);
11550 add_packet_config_cmd
11551 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
11552 "qXfer:trace-frame-info:read", "traceframe-info", 0);
11554 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
11555 "qXfer:uib:read", "unwind-info-block", 0);
11557 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
11558 "qGetTLSAddr", "get-thread-local-storage-address",
11561 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
11562 "qGetTIBAddr", "get-thread-information-block-address",
11565 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
11566 "bc", "reverse-continue", 0);
11568 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
11569 "bs", "reverse-step", 0);
11571 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
11572 "qSupported", "supported-packets", 0);
11574 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
11575 "qSearch:memory", "search-memory", 0);
11577 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
11578 "vFile:open", "hostio-open", 0);
11580 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
11581 "vFile:pread", "hostio-pread", 0);
11583 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
11584 "vFile:pwrite", "hostio-pwrite", 0);
11586 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
11587 "vFile:close", "hostio-close", 0);
11589 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
11590 "vFile:unlink", "hostio-unlink", 0);
11592 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
11593 "vFile:readlink", "hostio-readlink", 0);
11595 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
11596 "vAttach", "attach", 0);
11598 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
11601 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
11602 "QStartNoAckMode", "noack", 0);
11604 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
11605 "vKill", "kill", 0);
11607 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
11608 "qAttached", "query-attached", 0);
11610 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
11611 "ConditionalTracepoints",
11612 "conditional-tracepoints", 0);
11614 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
11615 "ConditionalBreakpoints",
11616 "conditional-breakpoints", 0);
11618 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
11619 "BreakpointCommands",
11620 "breakpoint-commands", 0);
11622 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
11623 "FastTracepoints", "fast-tracepoints", 0);
11625 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
11626 "TracepointSource", "TracepointSource", 0);
11628 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
11629 "QAllow", "allow", 0);
11631 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
11632 "StaticTracepoints", "static-tracepoints", 0);
11634 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
11635 "InstallInTrace", "install-in-trace", 0);
11637 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
11638 "qXfer:statictrace:read", "read-sdata-object", 0);
11640 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
11641 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
11643 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
11644 "QDisableRandomization", "disable-randomization", 0);
11646 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
11647 "QAgent", "agent", 0);
11649 /* Keep the old ``set remote Z-packet ...'' working. Each individual
11650 Z sub-packet has its own set and show commands, but users may
11651 have sets to this variable in their .gdbinit files (or in their
11653 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
11654 &remote_Z_packet_detect
, _("\
11655 Set use of remote protocol `Z' packets"), _("\
11656 Show use of remote protocol `Z' packets "), _("\
11657 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
11659 set_remote_protocol_Z_packet_cmd
,
11660 show_remote_protocol_Z_packet_cmd
,
11661 /* FIXME: i18n: Use of remote protocol
11662 `Z' packets is %s. */
11663 &remote_set_cmdlist
, &remote_show_cmdlist
);
11665 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
11666 Manipulate files on the remote system\n\
11667 Transfer files to and from the remote target system."),
11668 &remote_cmdlist
, "remote ",
11669 0 /* allow-unknown */, &cmdlist
);
11671 add_cmd ("put", class_files
, remote_put_command
,
11672 _("Copy a local file to the remote system."),
11675 add_cmd ("get", class_files
, remote_get_command
,
11676 _("Copy a remote file to the local system."),
11679 add_cmd ("delete", class_files
, remote_delete_command
,
11680 _("Delete a remote file."),
11683 remote_exec_file
= xstrdup ("");
11684 add_setshow_string_noescape_cmd ("exec-file", class_files
,
11685 &remote_exec_file
, _("\
11686 Set the remote pathname for \"run\""), _("\
11687 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
11688 &remote_set_cmdlist
, &remote_show_cmdlist
);
11690 /* Eventually initialize fileio. See fileio.c */
11691 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
11693 /* Take advantage of the fact that the LWP field is not used, to tag
11694 special ptids with it set to != 0. */
11695 magic_null_ptid
= ptid_build (42000, 1, -1);
11696 not_sent_ptid
= ptid_build (42000, 1, -2);
11697 any_thread_ptid
= ptid_build (42000, 1, 0);
11699 target_buf_size
= 2048;
11700 target_buf
= xmalloc (target_buf_size
);