1 /* Remote target communications for serial-line targets in custom GDB protocol
3 Copyright (C) 1988-2013 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"
37 #include "remote-notif.h"
40 #include "gdb_assert.h"
43 #include "cli/cli-decode.h"
44 #include "cli/cli-setshow.h"
45 #include "target-descriptions.h"
51 #include "event-loop.h"
52 #include "event-top.h"
58 #include "gdbcore.h" /* for exec_bfd */
60 #include "remote-fileio.h"
61 #include "gdb/fileio.h"
63 #include "xml-support.h"
65 #include "memory-map.h"
67 #include "tracepoint.h"
72 /* Temp hacks for tracepoint encoding migration. */
73 static char *target_buf
;
74 static long target_buf_size
;
76 /* The size to align memory write packets, when practical. The protocol
77 does not guarantee any alignment, and gdb will generate short
78 writes and unaligned writes, but even as a best-effort attempt this
79 can improve bulk transfers. For instance, if a write is misaligned
80 relative to the target's data bus, the stub may need to make an extra
81 round trip fetching data from the target. This doesn't make a
82 huge difference, but it's easy to do, so we try to be helpful.
84 The alignment chosen is arbitrary; usually data bus width is
85 important here, not the possibly larger cache line size. */
86 enum { REMOTE_ALIGN_WRITES
= 16 };
88 /* Prototypes for local functions. */
89 static void cleanup_sigint_signal_handler (void *dummy
);
90 static void initialize_sigint_signal_handler (void);
91 static int getpkt_sane (char **buf
, long *sizeof_buf
, int forever
);
92 static int getpkt_or_notif_sane (char **buf
, long *sizeof_buf
,
93 int forever
, int *is_notif
);
95 static void handle_remote_sigint (int);
96 static void handle_remote_sigint_twice (int);
97 static void async_remote_interrupt (gdb_client_data
);
98 void async_remote_interrupt_twice (gdb_client_data
);
100 static void remote_files_info (struct target_ops
*ignore
);
102 static void remote_prepare_to_store (struct regcache
*regcache
);
104 static void remote_open (char *name
, int from_tty
);
106 static void extended_remote_open (char *name
, int from_tty
);
108 static void remote_open_1 (char *, int, struct target_ops
*, int extended_p
);
110 static void remote_close (int quitting
);
112 static void remote_mourn (struct target_ops
*ops
);
114 static void extended_remote_restart (void);
116 static void extended_remote_mourn (struct target_ops
*);
118 static void remote_mourn_1 (struct target_ops
*);
120 static void remote_send (char **buf
, long *sizeof_buf_p
);
122 static int readchar (int timeout
);
124 static void remote_kill (struct target_ops
*ops
);
126 static int tohex (int nib
);
128 static int remote_can_async_p (void);
130 static int remote_is_async_p (void);
132 static void remote_async (void (*callback
) (enum inferior_event_type event_type
,
133 void *context
), void *context
);
135 static void remote_detach (struct target_ops
*ops
, char *args
, int from_tty
);
137 static void remote_interrupt (int signo
);
139 static void remote_interrupt_twice (int signo
);
141 static void interrupt_query (void);
143 static void set_general_thread (struct ptid ptid
);
144 static void set_continue_thread (struct ptid ptid
);
146 static void get_offsets (void);
148 static void skip_frame (void);
150 static long read_frame (char **buf_p
, long *sizeof_buf
);
152 static int hexnumlen (ULONGEST num
);
154 static void init_remote_ops (void);
156 static void init_extended_remote_ops (void);
158 static void remote_stop (ptid_t
);
160 static int ishex (int ch
, int *val
);
162 static int stubhex (int ch
);
164 static int hexnumstr (char *, ULONGEST
);
166 static int hexnumnstr (char *, ULONGEST
, int);
168 static CORE_ADDR
remote_address_masked (CORE_ADDR
);
170 static void print_packet (char *);
172 static void compare_sections_command (char *, int);
174 static void packet_command (char *, int);
176 static int stub_unpack_int (char *buff
, int fieldlength
);
178 static ptid_t
remote_current_thread (ptid_t oldptid
);
180 static void remote_find_new_threads (void);
182 static void record_currthread (ptid_t currthread
);
184 static int fromhex (int a
);
186 static int putpkt_binary (char *buf
, int cnt
);
188 static void check_binary_download (CORE_ADDR addr
);
190 struct packet_config
;
192 static void show_packet_config_cmd (struct packet_config
*config
);
194 static void update_packet_config (struct packet_config
*config
);
196 static void set_remote_protocol_packet_cmd (char *args
, int from_tty
,
197 struct cmd_list_element
*c
);
199 static void show_remote_protocol_packet_cmd (struct ui_file
*file
,
201 struct cmd_list_element
*c
,
204 static char *write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
);
205 static ptid_t
read_ptid (char *buf
, char **obuf
);
207 static void remote_set_permissions (void);
210 static int remote_get_trace_status (struct trace_status
*ts
);
212 static int remote_upload_tracepoints (struct uploaded_tp
**utpp
);
214 static int remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
);
216 static void remote_query_supported (void);
218 static void remote_check_symbols (struct objfile
*objfile
);
220 void _initialize_remote (void);
223 static void stop_reply_xfree (struct stop_reply
*);
224 static void remote_parse_stop_reply (char *, struct stop_reply
*);
225 static void push_stop_reply (struct stop_reply
*);
226 static void discard_pending_stop_replies (struct inferior
*);
227 static int peek_stop_reply (ptid_t ptid
);
229 static void remote_async_inferior_event_handler (gdb_client_data
);
231 static void remote_terminal_ours (void);
233 static int remote_read_description_p (struct target_ops
*target
);
235 static void remote_console_output (char *msg
);
237 static int remote_supports_cond_breakpoints (void);
239 static int remote_can_run_breakpoint_commands (void);
243 static struct cmd_list_element
*remote_cmdlist
;
245 /* For "set remote" and "show remote". */
247 static struct cmd_list_element
*remote_set_cmdlist
;
248 static struct cmd_list_element
*remote_show_cmdlist
;
250 /* Description of the remote protocol state for the currently
251 connected target. This is per-target state, and independent of the
252 selected architecture. */
256 /* A buffer to use for incoming packets, and its current size. The
257 buffer is grown dynamically for larger incoming packets.
258 Outgoing packets may also be constructed in this buffer.
259 BUF_SIZE is always at least REMOTE_PACKET_SIZE;
260 REMOTE_PACKET_SIZE should be used to limit the length of outgoing
265 /* True if we're going through initial connection setup (finding out
266 about the remote side's threads, relocating symbols, etc.). */
269 /* If we negotiated packet size explicitly (and thus can bypass
270 heuristics for the largest packet size that will not overflow
271 a buffer in the stub), this will be set to that packet size.
272 Otherwise zero, meaning to use the guessed size. */
273 long explicit_packet_size
;
275 /* remote_wait is normally called when the target is running and
276 waits for a stop reply packet. But sometimes we need to call it
277 when the target is already stopped. We can send a "?" packet
278 and have remote_wait read the response. Or, if we already have
279 the response, we can stash it in BUF and tell remote_wait to
280 skip calling getpkt. This flag is set when BUF contains a
281 stop reply packet and the target is not waiting. */
282 int cached_wait_status
;
284 /* True, if in no ack mode. That is, neither GDB nor the stub will
285 expect acks from each other. The connection is assumed to be
289 /* True if we're connected in extended remote mode. */
292 /* True if the stub reported support for multi-process
294 int multi_process_aware
;
296 /* True if we resumed the target and we're waiting for the target to
297 stop. In the mean time, we can't start another command/query.
298 The remote server wouldn't be ready to process it, so we'd
299 timeout waiting for a reply that would never come and eventually
300 we'd close the connection. This can happen in asynchronous mode
301 because we allow GDB commands while the target is running. */
302 int waiting_for_stop_reply
;
304 /* True if the stub reports support for non-stop mode. */
307 /* True if the stub reports support for vCont;t. */
310 /* True if the stub reports support for conditional tracepoints. */
311 int cond_tracepoints
;
313 /* True if the stub reports support for target-side breakpoint
315 int cond_breakpoints
;
317 /* True if the stub reports support for target-side breakpoint
319 int breakpoint_commands
;
321 /* True if the stub reports support for fast tracepoints. */
322 int fast_tracepoints
;
324 /* True if the stub reports support for static tracepoints. */
325 int static_tracepoints
;
327 /* True if the stub reports support for installing tracepoint while
329 int install_in_trace
;
331 /* True if the stub can continue running a trace while GDB is
333 int disconnected_tracing
;
335 /* True if the stub reports support for enabling and disabling
336 tracepoints while a trace experiment is running. */
337 int enable_disable_tracepoints
;
339 /* True if the stub can collect strings using tracenz bytecode. */
342 /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
343 responded to that. */
347 /* Private data that we'll store in (struct thread_info)->private. */
348 struct private_thread_info
355 free_private_thread_info (struct private_thread_info
*info
)
361 /* Returns true if the multi-process extensions are in effect. */
363 remote_multi_process_p (struct remote_state
*rs
)
365 return rs
->multi_process_aware
;
368 /* This data could be associated with a target, but we do not always
369 have access to the current target when we need it, so for now it is
370 static. This will be fine for as long as only one target is in use
372 static struct remote_state remote_state
;
374 static struct remote_state
*
375 get_remote_state_raw (void)
377 return &remote_state
;
380 /* Description of the remote protocol for a given architecture. */
384 long offset
; /* Offset into G packet. */
385 long regnum
; /* GDB's internal register number. */
386 LONGEST pnum
; /* Remote protocol register number. */
387 int in_g_packet
; /* Always part of G packet. */
388 /* long size in bytes; == register_size (target_gdbarch (), regnum);
390 /* char *name; == gdbarch_register_name (target_gdbarch (), regnum);
394 struct remote_arch_state
396 /* Description of the remote protocol registers. */
397 long sizeof_g_packet
;
399 /* Description of the remote protocol registers indexed by REGNUM
400 (making an array gdbarch_num_regs in size). */
401 struct packet_reg
*regs
;
403 /* This is the size (in chars) of the first response to the ``g''
404 packet. It is used as a heuristic when determining the maximum
405 size of memory-read and memory-write packets. A target will
406 typically only reserve a buffer large enough to hold the ``g''
407 packet. The size does not include packet overhead (headers and
409 long actual_register_packet_size
;
411 /* This is the maximum size (in chars) of a non read/write packet.
412 It is also used as a cap on the size of read/write packets. */
413 long remote_packet_size
;
416 long sizeof_pkt
= 2000;
418 /* Utility: generate error from an incoming stub packet. */
420 trace_error (char *buf
)
423 return; /* not an error msg */
426 case '1': /* malformed packet error */
427 if (*++buf
== '0') /* general case: */
428 error (_("remote.c: error in outgoing packet."));
430 error (_("remote.c: error in outgoing packet at field #%ld."),
431 strtol (buf
, NULL
, 16));
433 error (_("trace API error 0x%s."), ++buf
);
435 error (_("Target returns error code '%s'."), buf
);
439 /* Utility: wait for reply from stub, while accepting "O" packets. */
441 remote_get_noisy_reply (char **buf_p
,
444 do /* Loop on reply from remote stub. */
448 QUIT
; /* Allow user to bail out with ^C. */
449 getpkt (buf_p
, sizeof_buf
, 0);
453 else if (strncmp (buf
, "qRelocInsn:", strlen ("qRelocInsn:")) == 0)
456 CORE_ADDR from
, to
, org_to
;
458 int adjusted_size
= 0;
459 volatile struct gdb_exception ex
;
461 p
= buf
+ strlen ("qRelocInsn:");
462 pp
= unpack_varlen_hex (p
, &ul
);
464 error (_("invalid qRelocInsn packet: %s"), buf
);
468 unpack_varlen_hex (p
, &ul
);
473 TRY_CATCH (ex
, RETURN_MASK_ALL
)
475 gdbarch_relocate_instruction (target_gdbarch (), &to
, from
);
479 adjusted_size
= to
- org_to
;
481 xsnprintf (buf
, *sizeof_buf
, "qRelocInsn:%x", adjusted_size
);
484 else if (ex
.reason
< 0 && ex
.error
== MEMORY_ERROR
)
486 /* Propagate memory errors silently back to the target.
487 The stub may have limited the range of addresses we
488 can write to, for example. */
493 /* Something unexpectedly bad happened. Be verbose so
494 we can tell what, and propagate the error back to the
495 stub, so it doesn't get stuck waiting for a
497 exception_fprintf (gdb_stderr
, ex
,
498 _("warning: relocating instruction: "));
502 else if (buf
[0] == 'O' && buf
[1] != 'K')
503 remote_console_output (buf
+ 1); /* 'O' message from stub */
505 return buf
; /* Here's the actual reply. */
510 /* Handle for retreving the remote protocol data from gdbarch. */
511 static struct gdbarch_data
*remote_gdbarch_data_handle
;
513 static struct remote_arch_state
*
514 get_remote_arch_state (void)
516 return gdbarch_data (target_gdbarch (), remote_gdbarch_data_handle
);
519 /* Fetch the global remote target state. */
521 static struct remote_state
*
522 get_remote_state (void)
524 /* Make sure that the remote architecture state has been
525 initialized, because doing so might reallocate rs->buf. Any
526 function which calls getpkt also needs to be mindful of changes
527 to rs->buf, but this call limits the number of places which run
529 get_remote_arch_state ();
531 return get_remote_state_raw ();
535 compare_pnums (const void *lhs_
, const void *rhs_
)
537 const struct packet_reg
* const *lhs
= lhs_
;
538 const struct packet_reg
* const *rhs
= rhs_
;
540 if ((*lhs
)->pnum
< (*rhs
)->pnum
)
542 else if ((*lhs
)->pnum
== (*rhs
)->pnum
)
549 map_regcache_remote_table (struct gdbarch
*gdbarch
, struct packet_reg
*regs
)
551 int regnum
, num_remote_regs
, offset
;
552 struct packet_reg
**remote_regs
;
554 for (regnum
= 0; regnum
< gdbarch_num_regs (gdbarch
); regnum
++)
556 struct packet_reg
*r
= ®s
[regnum
];
558 if (register_size (gdbarch
, regnum
) == 0)
559 /* Do not try to fetch zero-sized (placeholder) registers. */
562 r
->pnum
= gdbarch_remote_register_number (gdbarch
, regnum
);
567 /* Define the g/G packet format as the contents of each register
568 with a remote protocol number, in order of ascending protocol
571 remote_regs
= alloca (gdbarch_num_regs (gdbarch
)
572 * sizeof (struct packet_reg
*));
573 for (num_remote_regs
= 0, regnum
= 0;
574 regnum
< gdbarch_num_regs (gdbarch
);
576 if (regs
[regnum
].pnum
!= -1)
577 remote_regs
[num_remote_regs
++] = ®s
[regnum
];
579 qsort (remote_regs
, num_remote_regs
, sizeof (struct packet_reg
*),
582 for (regnum
= 0, offset
= 0; regnum
< num_remote_regs
; regnum
++)
584 remote_regs
[regnum
]->in_g_packet
= 1;
585 remote_regs
[regnum
]->offset
= offset
;
586 offset
+= register_size (gdbarch
, remote_regs
[regnum
]->regnum
);
592 /* Given the architecture described by GDBARCH, return the remote
593 protocol register's number and the register's offset in the g/G
594 packets of GDB register REGNUM, in PNUM and POFFSET respectively.
595 If the target does not have a mapping for REGNUM, return false,
596 otherwise, return true. */
599 remote_register_number_and_offset (struct gdbarch
*gdbarch
, int regnum
,
600 int *pnum
, int *poffset
)
603 struct packet_reg
*regs
;
604 struct cleanup
*old_chain
;
606 gdb_assert (regnum
< gdbarch_num_regs (gdbarch
));
608 regs
= xcalloc (gdbarch_num_regs (gdbarch
), sizeof (struct packet_reg
));
609 old_chain
= make_cleanup (xfree
, regs
);
611 sizeof_g_packet
= map_regcache_remote_table (gdbarch
, regs
);
613 *pnum
= regs
[regnum
].pnum
;
614 *poffset
= regs
[regnum
].offset
;
616 do_cleanups (old_chain
);
622 init_remote_state (struct gdbarch
*gdbarch
)
624 struct remote_state
*rs
= get_remote_state_raw ();
625 struct remote_arch_state
*rsa
;
627 rsa
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct remote_arch_state
);
629 /* Use the architecture to build a regnum<->pnum table, which will be
630 1:1 unless a feature set specifies otherwise. */
631 rsa
->regs
= GDBARCH_OBSTACK_CALLOC (gdbarch
,
632 gdbarch_num_regs (gdbarch
),
635 /* Record the maximum possible size of the g packet - it may turn out
637 rsa
->sizeof_g_packet
= map_regcache_remote_table (gdbarch
, rsa
->regs
);
639 /* Default maximum number of characters in a packet body. Many
640 remote stubs have a hardwired buffer size of 400 bytes
641 (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used
642 as the maximum packet-size to ensure that the packet and an extra
643 NUL character can always fit in the buffer. This stops GDB
644 trashing stubs that try to squeeze an extra NUL into what is
645 already a full buffer (As of 1999-12-04 that was most stubs). */
646 rsa
->remote_packet_size
= 400 - 1;
648 /* This one is filled in when a ``g'' packet is received. */
649 rsa
->actual_register_packet_size
= 0;
651 /* Should rsa->sizeof_g_packet needs more space than the
652 default, adjust the size accordingly. Remember that each byte is
653 encoded as two characters. 32 is the overhead for the packet
654 header / footer. NOTE: cagney/1999-10-26: I suspect that 8
655 (``$NN:G...#NN'') is a better guess, the below has been padded a
657 if (rsa
->sizeof_g_packet
> ((rsa
->remote_packet_size
- 32) / 2))
658 rsa
->remote_packet_size
= (rsa
->sizeof_g_packet
* 2 + 32);
660 /* Make sure that the packet buffer is plenty big enough for
661 this architecture. */
662 if (rs
->buf_size
< rsa
->remote_packet_size
)
664 rs
->buf_size
= 2 * rsa
->remote_packet_size
;
665 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
671 /* Return the current allowed size of a remote packet. This is
672 inferred from the current architecture, and should be used to
673 limit the length of outgoing packets. */
675 get_remote_packet_size (void)
677 struct remote_state
*rs
= get_remote_state ();
678 struct remote_arch_state
*rsa
= get_remote_arch_state ();
680 if (rs
->explicit_packet_size
)
681 return rs
->explicit_packet_size
;
683 return rsa
->remote_packet_size
;
686 static struct packet_reg
*
687 packet_reg_from_regnum (struct remote_arch_state
*rsa
, long regnum
)
689 if (regnum
< 0 && regnum
>= gdbarch_num_regs (target_gdbarch ()))
693 struct packet_reg
*r
= &rsa
->regs
[regnum
];
695 gdb_assert (r
->regnum
== regnum
);
700 static struct packet_reg
*
701 packet_reg_from_pnum (struct remote_arch_state
*rsa
, LONGEST pnum
)
705 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
707 struct packet_reg
*r
= &rsa
->regs
[i
];
715 /* FIXME: graces/2002-08-08: These variables should eventually be
716 bound to an instance of the target object (as in gdbarch-tdep()),
717 when such a thing exists. */
719 /* This is set to the data address of the access causing the target
720 to stop for a watchpoint. */
721 static CORE_ADDR remote_watch_data_address
;
723 /* This is non-zero if target stopped for a watchpoint. */
724 static int remote_stopped_by_watchpoint_p
;
726 static struct target_ops remote_ops
;
728 static struct target_ops extended_remote_ops
;
730 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
731 ``forever'' still use the normal timeout mechanism. This is
732 currently used by the ASYNC code to guarentee that target reads
733 during the initial connect always time-out. Once getpkt has been
734 modified to return a timeout indication and, in turn
735 remote_wait()/wait_for_inferior() have gained a timeout parameter
737 static int wait_forever_enabled_p
= 1;
739 /* Allow the user to specify what sequence to send to the remote
740 when he requests a program interruption: Although ^C is usually
741 what remote systems expect (this is the default, here), it is
742 sometimes preferable to send a break. On other systems such
743 as the Linux kernel, a break followed by g, which is Magic SysRq g
744 is required in order to interrupt the execution. */
745 const char interrupt_sequence_control_c
[] = "Ctrl-C";
746 const char interrupt_sequence_break
[] = "BREAK";
747 const char interrupt_sequence_break_g
[] = "BREAK-g";
748 static const char *const interrupt_sequence_modes
[] =
750 interrupt_sequence_control_c
,
751 interrupt_sequence_break
,
752 interrupt_sequence_break_g
,
755 static const char *interrupt_sequence_mode
= interrupt_sequence_control_c
;
758 show_interrupt_sequence (struct ui_file
*file
, int from_tty
,
759 struct cmd_list_element
*c
,
762 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
763 fprintf_filtered (file
,
764 _("Send the ASCII ETX character (Ctrl-c) "
765 "to the remote target to interrupt the "
766 "execution of the program.\n"));
767 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
768 fprintf_filtered (file
,
769 _("send a break signal to the remote target "
770 "to interrupt the execution of the program.\n"));
771 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
772 fprintf_filtered (file
,
773 _("Send a break signal and 'g' a.k.a. Magic SysRq g to "
774 "the remote target to interrupt the execution "
775 "of Linux kernel.\n"));
777 internal_error (__FILE__
, __LINE__
,
778 _("Invalid value for interrupt_sequence_mode: %s."),
779 interrupt_sequence_mode
);
782 /* This boolean variable specifies whether interrupt_sequence is sent
783 to the remote target when gdb connects to it.
784 This is mostly needed when you debug the Linux kernel: The Linux kernel
785 expects BREAK g which is Magic SysRq g for connecting gdb. */
786 static int interrupt_on_connect
= 0;
788 /* This variable is used to implement the "set/show remotebreak" commands.
789 Since these commands are now deprecated in favor of "set/show remote
790 interrupt-sequence", it no longer has any effect on the code. */
791 static int remote_break
;
794 set_remotebreak (char *args
, int from_tty
, struct cmd_list_element
*c
)
797 interrupt_sequence_mode
= interrupt_sequence_break
;
799 interrupt_sequence_mode
= interrupt_sequence_control_c
;
803 show_remotebreak (struct ui_file
*file
, int from_tty
,
804 struct cmd_list_element
*c
,
809 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
810 remote_open knows that we don't have a file open when the program
812 static struct serial
*remote_desc
= NULL
;
814 /* This variable sets the number of bits in an address that are to be
815 sent in a memory ("M" or "m") packet. Normally, after stripping
816 leading zeros, the entire address would be sent. This variable
817 restricts the address to REMOTE_ADDRESS_SIZE bits. HISTORY: The
818 initial implementation of remote.c restricted the address sent in
819 memory packets to ``host::sizeof long'' bytes - (typically 32
820 bits). Consequently, for 64 bit targets, the upper 32 bits of an
821 address was never sent. Since fixing this bug may cause a break in
822 some remote targets this variable is principly provided to
823 facilitate backward compatibility. */
825 static unsigned int remote_address_size
;
827 /* Temporary to track who currently owns the terminal. See
828 remote_terminal_* for more details. */
830 static int remote_async_terminal_ours_p
;
832 /* The executable file to use for "run" on the remote side. */
834 static char *remote_exec_file
= "";
837 /* User configurable variables for the number of characters in a
838 memory read/write packet. MIN (rsa->remote_packet_size,
839 rsa->sizeof_g_packet) is the default. Some targets need smaller
840 values (fifo overruns, et.al.) and some users need larger values
841 (speed up transfers). The variables ``preferred_*'' (the user
842 request), ``current_*'' (what was actually set) and ``forced_*''
843 (Positive - a soft limit, negative - a hard limit). */
845 struct memory_packet_config
852 /* Compute the current size of a read/write packet. Since this makes
853 use of ``actual_register_packet_size'' the computation is dynamic. */
856 get_memory_packet_size (struct memory_packet_config
*config
)
858 struct remote_state
*rs
= get_remote_state ();
859 struct remote_arch_state
*rsa
= get_remote_arch_state ();
861 /* NOTE: The somewhat arbitrary 16k comes from the knowledge (folk
862 law?) that some hosts don't cope very well with large alloca()
863 calls. Eventually the alloca() code will be replaced by calls to
864 xmalloc() and make_cleanups() allowing this restriction to either
865 be lifted or removed. */
866 #ifndef MAX_REMOTE_PACKET_SIZE
867 #define MAX_REMOTE_PACKET_SIZE 16384
869 /* NOTE: 20 ensures we can write at least one byte. */
870 #ifndef MIN_REMOTE_PACKET_SIZE
871 #define MIN_REMOTE_PACKET_SIZE 20
876 if (config
->size
<= 0)
877 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
879 what_they_get
= config
->size
;
883 what_they_get
= get_remote_packet_size ();
884 /* Limit the packet to the size specified by the user. */
886 && what_they_get
> config
->size
)
887 what_they_get
= config
->size
;
889 /* Limit it to the size of the targets ``g'' response unless we have
890 permission from the stub to use a larger packet size. */
891 if (rs
->explicit_packet_size
== 0
892 && rsa
->actual_register_packet_size
> 0
893 && what_they_get
> rsa
->actual_register_packet_size
)
894 what_they_get
= rsa
->actual_register_packet_size
;
896 if (what_they_get
> MAX_REMOTE_PACKET_SIZE
)
897 what_they_get
= MAX_REMOTE_PACKET_SIZE
;
898 if (what_they_get
< MIN_REMOTE_PACKET_SIZE
)
899 what_they_get
= MIN_REMOTE_PACKET_SIZE
;
901 /* Make sure there is room in the global buffer for this packet
902 (including its trailing NUL byte). */
903 if (rs
->buf_size
< what_they_get
+ 1)
905 rs
->buf_size
= 2 * what_they_get
;
906 rs
->buf
= xrealloc (rs
->buf
, 2 * what_they_get
);
909 return what_they_get
;
912 /* Update the size of a read/write packet. If they user wants
913 something really big then do a sanity check. */
916 set_memory_packet_size (char *args
, struct memory_packet_config
*config
)
918 int fixed_p
= config
->fixed_p
;
919 long size
= config
->size
;
922 error (_("Argument required (integer, `fixed' or `limited')."));
923 else if (strcmp (args
, "hard") == 0
924 || strcmp (args
, "fixed") == 0)
926 else if (strcmp (args
, "soft") == 0
927 || strcmp (args
, "limit") == 0)
933 size
= strtoul (args
, &end
, 0);
935 error (_("Invalid %s (bad syntax)."), config
->name
);
937 /* Instead of explicitly capping the size of a packet to
938 MAX_REMOTE_PACKET_SIZE or dissallowing it, the user is
939 instead allowed to set the size to something arbitrarily
941 if (size
> MAX_REMOTE_PACKET_SIZE
)
942 error (_("Invalid %s (too large)."), config
->name
);
946 if (fixed_p
&& !config
->fixed_p
)
948 if (! query (_("The target may not be able to correctly handle a %s\n"
949 "of %ld bytes. Change the packet size? "),
951 error (_("Packet size not changed."));
953 /* Update the config. */
954 config
->fixed_p
= fixed_p
;
959 show_memory_packet_size (struct memory_packet_config
*config
)
961 printf_filtered (_("The %s is %ld. "), config
->name
, config
->size
);
963 printf_filtered (_("Packets are fixed at %ld bytes.\n"),
964 get_memory_packet_size (config
));
966 printf_filtered (_("Packets are limited to %ld bytes.\n"),
967 get_memory_packet_size (config
));
970 static struct memory_packet_config memory_write_packet_config
=
972 "memory-write-packet-size",
976 set_memory_write_packet_size (char *args
, int from_tty
)
978 set_memory_packet_size (args
, &memory_write_packet_config
);
982 show_memory_write_packet_size (char *args
, int from_tty
)
984 show_memory_packet_size (&memory_write_packet_config
);
988 get_memory_write_packet_size (void)
990 return get_memory_packet_size (&memory_write_packet_config
);
993 static struct memory_packet_config memory_read_packet_config
=
995 "memory-read-packet-size",
999 set_memory_read_packet_size (char *args
, int from_tty
)
1001 set_memory_packet_size (args
, &memory_read_packet_config
);
1005 show_memory_read_packet_size (char *args
, int from_tty
)
1007 show_memory_packet_size (&memory_read_packet_config
);
1011 get_memory_read_packet_size (void)
1013 long size
= get_memory_packet_size (&memory_read_packet_config
);
1015 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
1016 extra buffer size argument before the memory read size can be
1017 increased beyond this. */
1018 if (size
> get_remote_packet_size ())
1019 size
= get_remote_packet_size ();
1024 /* Generic configuration support for packets the stub optionally
1025 supports. Allows the user to specify the use of the packet as well
1026 as allowing GDB to auto-detect support in the remote stub. */
1030 PACKET_SUPPORT_UNKNOWN
= 0,
1035 struct packet_config
1039 enum auto_boolean detect
;
1040 enum packet_support support
;
1043 /* Analyze a packet's return value and update the packet config
1054 update_packet_config (struct packet_config
*config
)
1056 switch (config
->detect
)
1058 case AUTO_BOOLEAN_TRUE
:
1059 config
->support
= PACKET_ENABLE
;
1061 case AUTO_BOOLEAN_FALSE
:
1062 config
->support
= PACKET_DISABLE
;
1064 case AUTO_BOOLEAN_AUTO
:
1065 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1071 show_packet_config_cmd (struct packet_config
*config
)
1073 char *support
= "internal-error";
1075 switch (config
->support
)
1078 support
= "enabled";
1080 case PACKET_DISABLE
:
1081 support
= "disabled";
1083 case PACKET_SUPPORT_UNKNOWN
:
1084 support
= "unknown";
1087 switch (config
->detect
)
1089 case AUTO_BOOLEAN_AUTO
:
1090 printf_filtered (_("Support for the `%s' packet "
1091 "is auto-detected, currently %s.\n"),
1092 config
->name
, support
);
1094 case AUTO_BOOLEAN_TRUE
:
1095 case AUTO_BOOLEAN_FALSE
:
1096 printf_filtered (_("Support for the `%s' packet is currently %s.\n"),
1097 config
->name
, support
);
1103 add_packet_config_cmd (struct packet_config
*config
, const char *name
,
1104 const char *title
, int legacy
)
1110 config
->name
= name
;
1111 config
->title
= title
;
1112 config
->detect
= AUTO_BOOLEAN_AUTO
;
1113 config
->support
= PACKET_SUPPORT_UNKNOWN
;
1114 set_doc
= xstrprintf ("Set use of remote protocol `%s' (%s) packet",
1116 show_doc
= xstrprintf ("Show current use of remote "
1117 "protocol `%s' (%s) packet",
1119 /* set/show TITLE-packet {auto,on,off} */
1120 cmd_name
= xstrprintf ("%s-packet", title
);
1121 add_setshow_auto_boolean_cmd (cmd_name
, class_obscure
,
1122 &config
->detect
, set_doc
,
1123 show_doc
, NULL
, /* help_doc */
1124 set_remote_protocol_packet_cmd
,
1125 show_remote_protocol_packet_cmd
,
1126 &remote_set_cmdlist
, &remote_show_cmdlist
);
1127 /* The command code copies the documentation strings. */
1130 /* set/show remote NAME-packet {auto,on,off} -- legacy. */
1135 legacy_name
= xstrprintf ("%s-packet", name
);
1136 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1137 &remote_set_cmdlist
);
1138 add_alias_cmd (legacy_name
, cmd_name
, class_obscure
, 0,
1139 &remote_show_cmdlist
);
1143 static enum packet_result
1144 packet_check_result (const char *buf
)
1148 /* The stub recognized the packet request. Check that the
1149 operation succeeded. */
1151 && isxdigit (buf
[1]) && isxdigit (buf
[2])
1153 /* "Enn" - definitly an error. */
1154 return PACKET_ERROR
;
1156 /* Always treat "E." as an error. This will be used for
1157 more verbose error messages, such as E.memtypes. */
1158 if (buf
[0] == 'E' && buf
[1] == '.')
1159 return PACKET_ERROR
;
1161 /* The packet may or may not be OK. Just assume it is. */
1165 /* The stub does not support the packet. */
1166 return PACKET_UNKNOWN
;
1169 static enum packet_result
1170 packet_ok (const char *buf
, struct packet_config
*config
)
1172 enum packet_result result
;
1174 result
= packet_check_result (buf
);
1179 /* The stub recognized the packet request. */
1180 switch (config
->support
)
1182 case PACKET_SUPPORT_UNKNOWN
:
1184 fprintf_unfiltered (gdb_stdlog
,
1185 "Packet %s (%s) is supported\n",
1186 config
->name
, config
->title
);
1187 config
->support
= PACKET_ENABLE
;
1189 case PACKET_DISABLE
:
1190 internal_error (__FILE__
, __LINE__
,
1191 _("packet_ok: attempt to use a disabled packet"));
1197 case PACKET_UNKNOWN
:
1198 /* The stub does not support the packet. */
1199 switch (config
->support
)
1202 if (config
->detect
== AUTO_BOOLEAN_AUTO
)
1203 /* If the stub previously indicated that the packet was
1204 supported then there is a protocol error.. */
1205 error (_("Protocol error: %s (%s) conflicting enabled responses."),
1206 config
->name
, config
->title
);
1208 /* The user set it wrong. */
1209 error (_("Enabled packet %s (%s) not recognized by stub"),
1210 config
->name
, config
->title
);
1212 case PACKET_SUPPORT_UNKNOWN
:
1214 fprintf_unfiltered (gdb_stdlog
,
1215 "Packet %s (%s) is NOT supported\n",
1216 config
->name
, config
->title
);
1217 config
->support
= PACKET_DISABLE
;
1219 case PACKET_DISABLE
:
1241 PACKET_vFile_pwrite
,
1243 PACKET_vFile_unlink
,
1244 PACKET_vFile_readlink
,
1246 PACKET_qXfer_features
,
1247 PACKET_qXfer_libraries
,
1248 PACKET_qXfer_libraries_svr4
,
1249 PACKET_qXfer_memory_map
,
1250 PACKET_qXfer_spu_read
,
1251 PACKET_qXfer_spu_write
,
1252 PACKET_qXfer_osdata
,
1253 PACKET_qXfer_threads
,
1254 PACKET_qXfer_statictrace_read
,
1255 PACKET_qXfer_traceframe_info
,
1260 PACKET_QPassSignals
,
1261 PACKET_QProgramSignals
,
1262 PACKET_qSearch_memory
,
1265 PACKET_QStartNoAckMode
,
1267 PACKET_qXfer_siginfo_read
,
1268 PACKET_qXfer_siginfo_write
,
1270 PACKET_ConditionalTracepoints
,
1271 PACKET_ConditionalBreakpoints
,
1272 PACKET_BreakpointCommands
,
1273 PACKET_FastTracepoints
,
1274 PACKET_StaticTracepoints
,
1275 PACKET_InstallInTrace
,
1278 PACKET_TracepointSource
,
1281 PACKET_QDisableRandomization
,
1286 static struct packet_config remote_protocol_packets
[PACKET_MAX
];
1289 set_remote_protocol_packet_cmd (char *args
, int from_tty
,
1290 struct cmd_list_element
*c
)
1292 struct packet_config
*packet
;
1294 for (packet
= remote_protocol_packets
;
1295 packet
< &remote_protocol_packets
[PACKET_MAX
];
1298 if (&packet
->detect
== c
->var
)
1300 update_packet_config (packet
);
1304 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1309 show_remote_protocol_packet_cmd (struct ui_file
*file
, int from_tty
,
1310 struct cmd_list_element
*c
,
1313 struct packet_config
*packet
;
1315 for (packet
= remote_protocol_packets
;
1316 packet
< &remote_protocol_packets
[PACKET_MAX
];
1319 if (&packet
->detect
== c
->var
)
1321 show_packet_config_cmd (packet
);
1325 internal_error (__FILE__
, __LINE__
, _("Could not find config for %s"),
1329 /* Should we try one of the 'Z' requests? */
1333 Z_PACKET_SOFTWARE_BP
,
1334 Z_PACKET_HARDWARE_BP
,
1341 /* For compatibility with older distributions. Provide a ``set remote
1342 Z-packet ...'' command that updates all the Z packet types. */
1344 static enum auto_boolean remote_Z_packet_detect
;
1347 set_remote_protocol_Z_packet_cmd (char *args
, int from_tty
,
1348 struct cmd_list_element
*c
)
1352 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1354 remote_protocol_packets
[PACKET_Z0
+ i
].detect
= remote_Z_packet_detect
;
1355 update_packet_config (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1360 show_remote_protocol_Z_packet_cmd (struct ui_file
*file
, int from_tty
,
1361 struct cmd_list_element
*c
,
1366 for (i
= 0; i
< NR_Z_PACKET_TYPES
; i
++)
1368 show_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
+ i
]);
1372 /* Should we try the 'ThreadInfo' query packet?
1374 This variable (NOT available to the user: auto-detect only!)
1375 determines whether GDB will use the new, simpler "ThreadInfo"
1376 query or the older, more complex syntax for thread queries.
1377 This is an auto-detect variable (set to true at each connect,
1378 and set to false when the target fails to recognize it). */
1380 static int use_threadinfo_query
;
1381 static int use_threadextra_query
;
1383 /* Tokens for use by the asynchronous signal handlers for SIGINT. */
1384 static struct async_signal_handler
*sigint_remote_twice_token
;
1385 static struct async_signal_handler
*sigint_remote_token
;
1388 /* Asynchronous signal handle registered as event loop source for
1389 when we have pending events ready to be passed to the core. */
1391 static struct async_event_handler
*remote_async_inferior_event_token
;
1395 static ptid_t magic_null_ptid
;
1396 static ptid_t not_sent_ptid
;
1397 static ptid_t any_thread_ptid
;
1399 /* These are the threads which we last sent to the remote system. The
1400 TID member will be -1 for all or -2 for not sent yet. */
1402 static ptid_t general_thread
;
1403 static ptid_t continue_thread
;
1405 /* This is the traceframe which we last selected on the remote system.
1406 It will be -1 if no traceframe is selected. */
1407 static int remote_traceframe_number
= -1;
1409 /* Find out if the stub attached to PID (and hence GDB should offer to
1410 detach instead of killing it when bailing out). */
1413 remote_query_attached (int pid
)
1415 struct remote_state
*rs
= get_remote_state ();
1416 size_t size
= get_remote_packet_size ();
1418 if (remote_protocol_packets
[PACKET_qAttached
].support
== PACKET_DISABLE
)
1421 if (remote_multi_process_p (rs
))
1422 xsnprintf (rs
->buf
, size
, "qAttached:%x", pid
);
1424 xsnprintf (rs
->buf
, size
, "qAttached");
1427 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1429 switch (packet_ok (rs
->buf
,
1430 &remote_protocol_packets
[PACKET_qAttached
]))
1433 if (strcmp (rs
->buf
, "1") == 0)
1437 warning (_("Remote failure reply: %s"), rs
->buf
);
1439 case PACKET_UNKNOWN
:
1446 /* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID
1447 has been invented by GDB, instead of reported by the target. Since
1448 we can be connected to a remote system before before knowing about
1449 any inferior, mark the target with execution when we find the first
1450 inferior. If ATTACHED is 1, then we had just attached to this
1451 inferior. If it is 0, then we just created this inferior. If it
1452 is -1, then try querying the remote stub to find out if it had
1453 attached to the inferior or not. */
1455 static struct inferior
*
1456 remote_add_inferior (int fake_pid_p
, int pid
, int attached
)
1458 struct inferior
*inf
;
1460 /* Check whether this process we're learning about is to be
1461 considered attached, or if is to be considered to have been
1462 spawned by the stub. */
1464 attached
= remote_query_attached (pid
);
1466 if (gdbarch_has_global_solist (target_gdbarch ()))
1468 /* If the target shares code across all inferiors, then every
1469 attach adds a new inferior. */
1470 inf
= add_inferior (pid
);
1472 /* ... and every inferior is bound to the same program space.
1473 However, each inferior may still have its own address
1475 inf
->aspace
= maybe_new_address_space ();
1476 inf
->pspace
= current_program_space
;
1480 /* In the traditional debugging scenario, there's a 1-1 match
1481 between program/address spaces. We simply bind the inferior
1482 to the program space's address space. */
1483 inf
= current_inferior ();
1484 inferior_appeared (inf
, pid
);
1487 inf
->attach_flag
= attached
;
1488 inf
->fake_pid_p
= fake_pid_p
;
1493 /* Add thread PTID to GDB's thread list. Tag it as executing/running
1494 according to RUNNING. */
1497 remote_add_thread (ptid_t ptid
, int running
)
1501 set_executing (ptid
, running
);
1502 set_running (ptid
, running
);
1505 /* Come here when we learn about a thread id from the remote target.
1506 It may be the first time we hear about such thread, so take the
1507 opportunity to add it to GDB's thread list. In case this is the
1508 first time we're noticing its corresponding inferior, add it to
1509 GDB's inferior list as well. */
1512 remote_notice_new_inferior (ptid_t currthread
, int running
)
1514 /* If this is a new thread, add it to GDB's thread list.
1515 If we leave it up to WFI to do this, bad things will happen. */
1517 if (in_thread_list (currthread
) && is_exited (currthread
))
1519 /* We're seeing an event on a thread id we knew had exited.
1520 This has to be a new thread reusing the old id. Add it. */
1521 remote_add_thread (currthread
, running
);
1525 if (!in_thread_list (currthread
))
1527 struct inferior
*inf
= NULL
;
1528 int pid
= ptid_get_pid (currthread
);
1530 if (ptid_is_pid (inferior_ptid
)
1531 && pid
== ptid_get_pid (inferior_ptid
))
1533 /* inferior_ptid has no thread member yet. This can happen
1534 with the vAttach -> remote_wait,"TAAthread:" path if the
1535 stub doesn't support qC. This is the first stop reported
1536 after an attach, so this is the main thread. Update the
1537 ptid in the thread list. */
1538 if (in_thread_list (pid_to_ptid (pid
)))
1539 thread_change_ptid (inferior_ptid
, currthread
);
1542 remote_add_thread (currthread
, running
);
1543 inferior_ptid
= currthread
;
1548 if (ptid_equal (magic_null_ptid
, inferior_ptid
))
1550 /* inferior_ptid is not set yet. This can happen with the
1551 vRun -> remote_wait,"TAAthread:" path if the stub
1552 doesn't support qC. This is the first stop reported
1553 after an attach, so this is the main thread. Update the
1554 ptid in the thread list. */
1555 thread_change_ptid (inferior_ptid
, currthread
);
1559 /* When connecting to a target remote, or to a target
1560 extended-remote which already was debugging an inferior, we
1561 may not know about it yet. Add it before adding its child
1562 thread, so notifications are emitted in a sensible order. */
1563 if (!in_inferior_list (ptid_get_pid (currthread
)))
1565 struct remote_state
*rs
= get_remote_state ();
1566 int fake_pid_p
= !remote_multi_process_p (rs
);
1568 inf
= remote_add_inferior (fake_pid_p
,
1569 ptid_get_pid (currthread
), -1);
1572 /* This is really a new thread. Add it. */
1573 remote_add_thread (currthread
, running
);
1575 /* If we found a new inferior, let the common code do whatever
1576 it needs to with it (e.g., read shared libraries, insert
1579 notice_new_inferior (currthread
, running
, 0);
1583 /* Return the private thread data, creating it if necessary. */
1585 static struct private_thread_info
*
1586 demand_private_info (ptid_t ptid
)
1588 struct thread_info
*info
= find_thread_ptid (ptid
);
1594 info
->private = xmalloc (sizeof (*(info
->private)));
1595 info
->private_dtor
= free_private_thread_info
;
1596 info
->private->core
= -1;
1597 info
->private->extra
= 0;
1600 return info
->private;
1603 /* Call this function as a result of
1604 1) A halt indication (T packet) containing a thread id
1605 2) A direct query of currthread
1606 3) Successful execution of set thread */
1609 record_currthread (ptid_t currthread
)
1611 general_thread
= currthread
;
1614 static char *last_pass_packet
;
1616 /* If 'QPassSignals' is supported, tell the remote stub what signals
1617 it can simply pass through to the inferior without reporting. */
1620 remote_pass_signals (int numsigs
, unsigned char *pass_signals
)
1622 if (remote_protocol_packets
[PACKET_QPassSignals
].support
!= PACKET_DISABLE
)
1624 char *pass_packet
, *p
;
1627 gdb_assert (numsigs
< 256);
1628 for (i
= 0; i
< numsigs
; i
++)
1630 if (pass_signals
[i
])
1633 pass_packet
= xmalloc (count
* 3 + strlen ("QPassSignals:") + 1);
1634 strcpy (pass_packet
, "QPassSignals:");
1635 p
= pass_packet
+ strlen (pass_packet
);
1636 for (i
= 0; i
< numsigs
; i
++)
1638 if (pass_signals
[i
])
1641 *p
++ = tohex (i
>> 4);
1642 *p
++ = tohex (i
& 15);
1651 if (!last_pass_packet
|| strcmp (last_pass_packet
, pass_packet
))
1653 struct remote_state
*rs
= get_remote_state ();
1654 char *buf
= rs
->buf
;
1656 putpkt (pass_packet
);
1657 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1658 packet_ok (buf
, &remote_protocol_packets
[PACKET_QPassSignals
]);
1659 if (last_pass_packet
)
1660 xfree (last_pass_packet
);
1661 last_pass_packet
= pass_packet
;
1664 xfree (pass_packet
);
1668 /* The last QProgramSignals packet sent to the target. We bypass
1669 sending a new program signals list down to the target if the new
1670 packet is exactly the same as the last we sent. IOW, we only let
1671 the target know about program signals list changes. */
1673 static char *last_program_signals_packet
;
1675 /* If 'QProgramSignals' is supported, tell the remote stub what
1676 signals it should pass through to the inferior when detaching. */
1679 remote_program_signals (int numsigs
, unsigned char *signals
)
1681 if (remote_protocol_packets
[PACKET_QProgramSignals
].support
!= PACKET_DISABLE
)
1686 gdb_assert (numsigs
< 256);
1687 for (i
= 0; i
< numsigs
; i
++)
1692 packet
= xmalloc (count
* 3 + strlen ("QProgramSignals:") + 1);
1693 strcpy (packet
, "QProgramSignals:");
1694 p
= packet
+ strlen (packet
);
1695 for (i
= 0; i
< numsigs
; i
++)
1697 if (signal_pass_state (i
))
1700 *p
++ = tohex (i
>> 4);
1701 *p
++ = tohex (i
& 15);
1710 if (!last_program_signals_packet
1711 || strcmp (last_program_signals_packet
, packet
) != 0)
1713 struct remote_state
*rs
= get_remote_state ();
1714 char *buf
= rs
->buf
;
1717 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1718 packet_ok (buf
, &remote_protocol_packets
[PACKET_QProgramSignals
]);
1719 xfree (last_program_signals_packet
);
1720 last_program_signals_packet
= packet
;
1727 /* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is
1728 MINUS_ONE_PTID, set the thread to -1, so the stub returns the
1729 thread. If GEN is set, set the general thread, if not, then set
1730 the step/continue thread. */
1732 set_thread (struct ptid ptid
, int gen
)
1734 struct remote_state
*rs
= get_remote_state ();
1735 ptid_t state
= gen
? general_thread
: continue_thread
;
1736 char *buf
= rs
->buf
;
1737 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
1739 if (ptid_equal (state
, ptid
))
1743 *buf
++ = gen
? 'g' : 'c';
1744 if (ptid_equal (ptid
, magic_null_ptid
))
1745 xsnprintf (buf
, endbuf
- buf
, "0");
1746 else if (ptid_equal (ptid
, any_thread_ptid
))
1747 xsnprintf (buf
, endbuf
- buf
, "0");
1748 else if (ptid_equal (ptid
, minus_one_ptid
))
1749 xsnprintf (buf
, endbuf
- buf
, "-1");
1751 write_ptid (buf
, endbuf
, ptid
);
1753 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1755 general_thread
= ptid
;
1757 continue_thread
= ptid
;
1761 set_general_thread (struct ptid ptid
)
1763 set_thread (ptid
, 1);
1767 set_continue_thread (struct ptid ptid
)
1769 set_thread (ptid
, 0);
1772 /* Change the remote current process. Which thread within the process
1773 ends up selected isn't important, as long as it is the same process
1774 as what INFERIOR_PTID points to.
1776 This comes from that fact that there is no explicit notion of
1777 "selected process" in the protocol. The selected process for
1778 general operations is the process the selected general thread
1782 set_general_process (void)
1784 struct remote_state
*rs
= get_remote_state ();
1786 /* If the remote can't handle multiple processes, don't bother. */
1787 if (!rs
->extended
|| !remote_multi_process_p (rs
))
1790 /* We only need to change the remote current thread if it's pointing
1791 at some other process. */
1792 if (ptid_get_pid (general_thread
) != ptid_get_pid (inferior_ptid
))
1793 set_general_thread (inferior_ptid
);
1797 /* Return nonzero if the thread PTID is still alive on the remote
1801 remote_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
1803 struct remote_state
*rs
= get_remote_state ();
1806 if (ptid_equal (ptid
, magic_null_ptid
))
1807 /* The main thread is always alive. */
1810 if (ptid_get_pid (ptid
) != 0 && ptid_get_tid (ptid
) == 0)
1811 /* The main thread is always alive. This can happen after a
1812 vAttach, if the remote side doesn't support
1817 endp
= rs
->buf
+ get_remote_packet_size ();
1820 write_ptid (p
, endp
, ptid
);
1823 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
1824 return (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K');
1827 /* About these extended threadlist and threadinfo packets. They are
1828 variable length packets but, the fields within them are often fixed
1829 length. They are redundent enough to send over UDP as is the
1830 remote protocol in general. There is a matching unit test module
1833 #define OPAQUETHREADBYTES 8
1835 /* a 64 bit opaque identifier */
1836 typedef unsigned char threadref
[OPAQUETHREADBYTES
];
1838 /* WARNING: This threadref data structure comes from the remote O.S.,
1839 libstub protocol encoding, and remote.c. It is not particularly
1842 /* Right now, the internal structure is int. We want it to be bigger.
1843 Plan to fix this. */
1845 typedef int gdb_threadref
; /* Internal GDB thread reference. */
1847 /* gdb_ext_thread_info is an internal GDB data structure which is
1848 equivalent to the reply of the remote threadinfo packet. */
1850 struct gdb_ext_thread_info
1852 threadref threadid
; /* External form of thread reference. */
1853 int active
; /* Has state interesting to GDB?
1855 char display
[256]; /* Brief state display, name,
1856 blocked/suspended. */
1857 char shortname
[32]; /* To be used to name threads. */
1858 char more_display
[256]; /* Long info, statistics, queue depth,
1862 /* The volume of remote transfers can be limited by submitting
1863 a mask containing bits specifying the desired information.
1864 Use a union of these values as the 'selection' parameter to
1865 get_thread_info. FIXME: Make these TAG names more thread specific. */
1867 #define TAG_THREADID 1
1868 #define TAG_EXISTS 2
1869 #define TAG_DISPLAY 4
1870 #define TAG_THREADNAME 8
1871 #define TAG_MOREDISPLAY 16
1873 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
1875 char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
1877 static char *unpack_nibble (char *buf
, int *val
);
1879 static char *pack_nibble (char *buf
, int nibble
);
1881 static char *pack_hex_byte (char *pkt
, int /* unsigned char */ byte
);
1883 static char *unpack_byte (char *buf
, int *value
);
1885 static char *pack_int (char *buf
, int value
);
1887 static char *unpack_int (char *buf
, int *value
);
1889 static char *unpack_string (char *src
, char *dest
, int length
);
1891 static char *pack_threadid (char *pkt
, threadref
*id
);
1893 static char *unpack_threadid (char *inbuf
, threadref
*id
);
1895 void int_to_threadref (threadref
*id
, int value
);
1897 static int threadref_to_int (threadref
*ref
);
1899 static void copy_threadref (threadref
*dest
, threadref
*src
);
1901 static int threadmatch (threadref
*dest
, threadref
*src
);
1903 static char *pack_threadinfo_request (char *pkt
, int mode
,
1906 static int remote_unpack_thread_info_response (char *pkt
,
1907 threadref
*expectedref
,
1908 struct gdb_ext_thread_info
1912 static int remote_get_threadinfo (threadref
*threadid
,
1913 int fieldset
, /*TAG mask */
1914 struct gdb_ext_thread_info
*info
);
1916 static char *pack_threadlist_request (char *pkt
, int startflag
,
1918 threadref
*nextthread
);
1920 static int parse_threadlist_response (char *pkt
,
1922 threadref
*original_echo
,
1923 threadref
*resultlist
,
1926 static int remote_get_threadlist (int startflag
,
1927 threadref
*nextthread
,
1931 threadref
*threadlist
);
1933 typedef int (*rmt_thread_action
) (threadref
*ref
, void *context
);
1935 static int remote_threadlist_iterator (rmt_thread_action stepfunction
,
1936 void *context
, int looplimit
);
1938 static int remote_newthread_step (threadref
*ref
, void *context
);
1941 /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the
1942 buffer we're allowed to write to. Returns
1943 BUF+CHARACTERS_WRITTEN. */
1946 write_ptid (char *buf
, const char *endbuf
, ptid_t ptid
)
1949 struct remote_state
*rs
= get_remote_state ();
1951 if (remote_multi_process_p (rs
))
1953 pid
= ptid_get_pid (ptid
);
1955 buf
+= xsnprintf (buf
, endbuf
- buf
, "p-%x.", -pid
);
1957 buf
+= xsnprintf (buf
, endbuf
- buf
, "p%x.", pid
);
1959 tid
= ptid_get_tid (ptid
);
1961 buf
+= xsnprintf (buf
, endbuf
- buf
, "-%x", -tid
);
1963 buf
+= xsnprintf (buf
, endbuf
- buf
, "%x", tid
);
1968 /* Extract a PTID from BUF. If non-null, OBUF is set to the to one
1969 passed the last parsed char. Returns null_ptid on error. */
1972 read_ptid (char *buf
, char **obuf
)
1976 ULONGEST pid
= 0, tid
= 0;
1980 /* Multi-process ptid. */
1981 pp
= unpack_varlen_hex (p
+ 1, &pid
);
1983 error (_("invalid remote ptid: %s"), p
);
1986 pp
= unpack_varlen_hex (p
+ 1, &tid
);
1989 return ptid_build (pid
, 0, tid
);
1992 /* No multi-process. Just a tid. */
1993 pp
= unpack_varlen_hex (p
, &tid
);
1995 /* Since the stub is not sending a process id, then default to
1996 what's in inferior_ptid, unless it's null at this point. If so,
1997 then since there's no way to know the pid of the reported
1998 threads, use the magic number. */
1999 if (ptid_equal (inferior_ptid
, null_ptid
))
2000 pid
= ptid_get_pid (magic_null_ptid
);
2002 pid
= ptid_get_pid (inferior_ptid
);
2006 return ptid_build (pid
, 0, tid
);
2009 /* Encode 64 bits in 16 chars of hex. */
2011 static const char hexchars
[] = "0123456789abcdef";
2014 ishex (int ch
, int *val
)
2016 if ((ch
>= 'a') && (ch
<= 'f'))
2018 *val
= ch
- 'a' + 10;
2021 if ((ch
>= 'A') && (ch
<= 'F'))
2023 *val
= ch
- 'A' + 10;
2026 if ((ch
>= '0') && (ch
<= '9'))
2037 if (ch
>= 'a' && ch
<= 'f')
2038 return ch
- 'a' + 10;
2039 if (ch
>= '0' && ch
<= '9')
2041 if (ch
>= 'A' && ch
<= 'F')
2042 return ch
- 'A' + 10;
2047 stub_unpack_int (char *buff
, int fieldlength
)
2054 nibble
= stubhex (*buff
++);
2058 retval
= retval
<< 4;
2064 unpack_varlen_hex (char *buff
, /* packet to parse */
2068 ULONGEST retval
= 0;
2070 while (ishex (*buff
, &nibble
))
2073 retval
= retval
<< 4;
2074 retval
|= nibble
& 0x0f;
2081 unpack_nibble (char *buf
, int *val
)
2083 *val
= fromhex (*buf
++);
2088 pack_nibble (char *buf
, int nibble
)
2090 *buf
++ = hexchars
[(nibble
& 0x0f)];
2095 pack_hex_byte (char *pkt
, int byte
)
2097 *pkt
++ = hexchars
[(byte
>> 4) & 0xf];
2098 *pkt
++ = hexchars
[(byte
& 0xf)];
2103 unpack_byte (char *buf
, int *value
)
2105 *value
= stub_unpack_int (buf
, 2);
2110 pack_int (char *buf
, int value
)
2112 buf
= pack_hex_byte (buf
, (value
>> 24) & 0xff);
2113 buf
= pack_hex_byte (buf
, (value
>> 16) & 0xff);
2114 buf
= pack_hex_byte (buf
, (value
>> 8) & 0x0ff);
2115 buf
= pack_hex_byte (buf
, (value
& 0xff));
2120 unpack_int (char *buf
, int *value
)
2122 *value
= stub_unpack_int (buf
, 8);
2126 #if 0 /* Currently unused, uncomment when needed. */
2127 static char *pack_string (char *pkt
, char *string
);
2130 pack_string (char *pkt
, char *string
)
2135 len
= strlen (string
);
2137 len
= 200; /* Bigger than most GDB packets, junk??? */
2138 pkt
= pack_hex_byte (pkt
, len
);
2142 if ((ch
== '\0') || (ch
== '#'))
2143 ch
= '*'; /* Protect encapsulation. */
2148 #endif /* 0 (unused) */
2151 unpack_string (char *src
, char *dest
, int length
)
2160 pack_threadid (char *pkt
, threadref
*id
)
2163 unsigned char *altid
;
2165 altid
= (unsigned char *) id
;
2166 limit
= pkt
+ BUF_THREAD_ID_SIZE
;
2168 pkt
= pack_hex_byte (pkt
, *altid
++);
2174 unpack_threadid (char *inbuf
, threadref
*id
)
2177 char *limit
= inbuf
+ BUF_THREAD_ID_SIZE
;
2180 altref
= (char *) id
;
2182 while (inbuf
< limit
)
2184 x
= stubhex (*inbuf
++);
2185 y
= stubhex (*inbuf
++);
2186 *altref
++ = (x
<< 4) | y
;
2191 /* Externally, threadrefs are 64 bits but internally, they are still
2192 ints. This is due to a mismatch of specifications. We would like
2193 to use 64bit thread references internally. This is an adapter
2197 int_to_threadref (threadref
*id
, int value
)
2199 unsigned char *scan
;
2201 scan
= (unsigned char *) id
;
2207 *scan
++ = (value
>> 24) & 0xff;
2208 *scan
++ = (value
>> 16) & 0xff;
2209 *scan
++ = (value
>> 8) & 0xff;
2210 *scan
++ = (value
& 0xff);
2214 threadref_to_int (threadref
*ref
)
2217 unsigned char *scan
;
2223 value
= (value
<< 8) | ((*scan
++) & 0xff);
2228 copy_threadref (threadref
*dest
, threadref
*src
)
2231 unsigned char *csrc
, *cdest
;
2233 csrc
= (unsigned char *) src
;
2234 cdest
= (unsigned char *) dest
;
2241 threadmatch (threadref
*dest
, threadref
*src
)
2243 /* Things are broken right now, so just assume we got a match. */
2245 unsigned char *srcp
, *destp
;
2247 srcp
= (char *) src
;
2248 destp
= (char *) dest
;
2252 result
&= (*srcp
++ == *destp
++) ? 1 : 0;
2259 threadid:1, # always request threadid
2266 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */
2269 pack_threadinfo_request (char *pkt
, int mode
, threadref
*id
)
2271 *pkt
++ = 'q'; /* Info Query */
2272 *pkt
++ = 'P'; /* process or thread info */
2273 pkt
= pack_int (pkt
, mode
); /* mode */
2274 pkt
= pack_threadid (pkt
, id
); /* threadid */
2275 *pkt
= '\0'; /* terminate */
2279 /* These values tag the fields in a thread info response packet. */
2280 /* Tagging the fields allows us to request specific fields and to
2281 add more fields as time goes by. */
2283 #define TAG_THREADID 1 /* Echo the thread identifier. */
2284 #define TAG_EXISTS 2 /* Is this process defined enough to
2285 fetch registers and its stack? */
2286 #define TAG_DISPLAY 4 /* A short thing maybe to put on a window */
2287 #define TAG_THREADNAME 8 /* string, maps 1-to-1 with a thread is. */
2288 #define TAG_MOREDISPLAY 16 /* Whatever the kernel wants to say about
2292 remote_unpack_thread_info_response (char *pkt
, threadref
*expectedref
,
2293 struct gdb_ext_thread_info
*info
)
2295 struct remote_state
*rs
= get_remote_state ();
2299 char *limit
= pkt
+ rs
->buf_size
; /* Plausible parsing limit. */
2302 /* info->threadid = 0; FIXME: implement zero_threadref. */
2304 info
->display
[0] = '\0';
2305 info
->shortname
[0] = '\0';
2306 info
->more_display
[0] = '\0';
2308 /* Assume the characters indicating the packet type have been
2310 pkt
= unpack_int (pkt
, &mask
); /* arg mask */
2311 pkt
= unpack_threadid (pkt
, &ref
);
2314 warning (_("Incomplete response to threadinfo request."));
2315 if (!threadmatch (&ref
, expectedref
))
2316 { /* This is an answer to a different request. */
2317 warning (_("ERROR RMT Thread info mismatch."));
2320 copy_threadref (&info
->threadid
, &ref
);
2322 /* Loop on tagged fields , try to bail if somthing goes wrong. */
2324 /* Packets are terminated with nulls. */
2325 while ((pkt
< limit
) && mask
&& *pkt
)
2327 pkt
= unpack_int (pkt
, &tag
); /* tag */
2328 pkt
= unpack_byte (pkt
, &length
); /* length */
2329 if (!(tag
& mask
)) /* Tags out of synch with mask. */
2331 warning (_("ERROR RMT: threadinfo tag mismatch."));
2335 if (tag
== TAG_THREADID
)
2339 warning (_("ERROR RMT: length of threadid is not 16."));
2343 pkt
= unpack_threadid (pkt
, &ref
);
2344 mask
= mask
& ~TAG_THREADID
;
2347 if (tag
== TAG_EXISTS
)
2349 info
->active
= stub_unpack_int (pkt
, length
);
2351 mask
= mask
& ~(TAG_EXISTS
);
2354 warning (_("ERROR RMT: 'exists' length too long."));
2360 if (tag
== TAG_THREADNAME
)
2362 pkt
= unpack_string (pkt
, &info
->shortname
[0], length
);
2363 mask
= mask
& ~TAG_THREADNAME
;
2366 if (tag
== TAG_DISPLAY
)
2368 pkt
= unpack_string (pkt
, &info
->display
[0], length
);
2369 mask
= mask
& ~TAG_DISPLAY
;
2372 if (tag
== TAG_MOREDISPLAY
)
2374 pkt
= unpack_string (pkt
, &info
->more_display
[0], length
);
2375 mask
= mask
& ~TAG_MOREDISPLAY
;
2378 warning (_("ERROR RMT: unknown thread info tag."));
2379 break; /* Not a tag we know about. */
2385 remote_get_threadinfo (threadref
*threadid
, int fieldset
, /* TAG mask */
2386 struct gdb_ext_thread_info
*info
)
2388 struct remote_state
*rs
= get_remote_state ();
2391 pack_threadinfo_request (rs
->buf
, fieldset
, threadid
);
2393 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2395 if (rs
->buf
[0] == '\0')
2398 result
= remote_unpack_thread_info_response (rs
->buf
+ 2,
2403 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */
2406 pack_threadlist_request (char *pkt
, int startflag
, int threadcount
,
2407 threadref
*nextthread
)
2409 *pkt
++ = 'q'; /* info query packet */
2410 *pkt
++ = 'L'; /* Process LIST or threadLIST request */
2411 pkt
= pack_nibble (pkt
, startflag
); /* initflag 1 bytes */
2412 pkt
= pack_hex_byte (pkt
, threadcount
); /* threadcount 2 bytes */
2413 pkt
= pack_threadid (pkt
, nextthread
); /* 64 bit thread identifier */
2418 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
2421 parse_threadlist_response (char *pkt
, int result_limit
,
2422 threadref
*original_echo
, threadref
*resultlist
,
2425 struct remote_state
*rs
= get_remote_state ();
2427 int count
, resultcount
, done
;
2430 /* Assume the 'q' and 'M chars have been stripped. */
2431 limit
= pkt
+ (rs
->buf_size
- BUF_THREAD_ID_SIZE
);
2432 /* done parse past here */
2433 pkt
= unpack_byte (pkt
, &count
); /* count field */
2434 pkt
= unpack_nibble (pkt
, &done
);
2435 /* The first threadid is the argument threadid. */
2436 pkt
= unpack_threadid (pkt
, original_echo
); /* should match query packet */
2437 while ((count
-- > 0) && (pkt
< limit
))
2439 pkt
= unpack_threadid (pkt
, resultlist
++);
2440 if (resultcount
++ >= result_limit
)
2449 remote_get_threadlist (int startflag
, threadref
*nextthread
, int result_limit
,
2450 int *done
, int *result_count
, threadref
*threadlist
)
2452 struct remote_state
*rs
= get_remote_state ();
2453 static threadref echo_nextthread
;
2456 /* Trancate result limit to be smaller than the packet size. */
2457 if ((((result_limit
+ 1) * BUF_THREAD_ID_SIZE
) + 10)
2458 >= get_remote_packet_size ())
2459 result_limit
= (get_remote_packet_size () / BUF_THREAD_ID_SIZE
) - 2;
2461 pack_threadlist_request (rs
->buf
, startflag
, result_limit
, nextthread
);
2463 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2465 if (*rs
->buf
== '\0')
2469 parse_threadlist_response (rs
->buf
+ 2, result_limit
, &echo_nextthread
,
2472 if (!threadmatch (&echo_nextthread
, nextthread
))
2474 /* FIXME: This is a good reason to drop the packet. */
2475 /* Possably, there is a duplicate response. */
2477 retransmit immediatly - race conditions
2478 retransmit after timeout - yes
2480 wait for packet, then exit
2482 warning (_("HMM: threadlist did not echo arg thread, dropping it."));
2483 return 0; /* I choose simply exiting. */
2485 if (*result_count
<= 0)
2489 warning (_("RMT ERROR : failed to get remote thread list."));
2492 return result
; /* break; */
2494 if (*result_count
> result_limit
)
2497 warning (_("RMT ERROR: threadlist response longer than requested."));
2503 /* This is the interface between remote and threads, remotes upper
2506 /* remote_find_new_threads retrieves the thread list and for each
2507 thread in the list, looks up the thread in GDB's internal list,
2508 adding the thread if it does not already exist. This involves
2509 getting partial thread lists from the remote target so, polling the
2510 quit_flag is required. */
2513 /* About this many threadisds fit in a packet. */
2515 #define MAXTHREADLISTRESULTS 32
2518 remote_threadlist_iterator (rmt_thread_action stepfunction
, void *context
,
2521 int done
, i
, result_count
;
2525 static threadref nextthread
;
2526 static threadref resultthreadlist
[MAXTHREADLISTRESULTS
];
2531 if (loopcount
++ > looplimit
)
2534 warning (_("Remote fetch threadlist -infinite loop-."));
2537 if (!remote_get_threadlist (startflag
, &nextthread
, MAXTHREADLISTRESULTS
,
2538 &done
, &result_count
, resultthreadlist
))
2543 /* Clear for later iterations. */
2545 /* Setup to resume next batch of thread references, set nextthread. */
2546 if (result_count
>= 1)
2547 copy_threadref (&nextthread
, &resultthreadlist
[result_count
- 1]);
2549 while (result_count
--)
2550 if (!(result
= (*stepfunction
) (&resultthreadlist
[i
++], context
)))
2557 remote_newthread_step (threadref
*ref
, void *context
)
2559 int pid
= ptid_get_pid (inferior_ptid
);
2560 ptid_t ptid
= ptid_build (pid
, 0, threadref_to_int (ref
));
2562 if (!in_thread_list (ptid
))
2564 return 1; /* continue iterator */
2567 #define CRAZY_MAX_THREADS 1000
2570 remote_current_thread (ptid_t oldpid
)
2572 struct remote_state
*rs
= get_remote_state ();
2575 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2576 if (rs
->buf
[0] == 'Q' && rs
->buf
[1] == 'C')
2577 return read_ptid (&rs
->buf
[2], NULL
);
2582 /* Find new threads for info threads command.
2583 * Original version, using John Metzler's thread protocol.
2587 remote_find_new_threads (void)
2589 remote_threadlist_iterator (remote_newthread_step
, 0,
2593 #if defined(HAVE_LIBEXPAT)
2595 typedef struct thread_item
2601 DEF_VEC_O(thread_item_t
);
2603 struct threads_parsing_context
2605 VEC (thread_item_t
) *items
;
2609 start_thread (struct gdb_xml_parser
*parser
,
2610 const struct gdb_xml_element
*element
,
2611 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
2613 struct threads_parsing_context
*data
= user_data
;
2615 struct thread_item item
;
2617 struct gdb_xml_value
*attr
;
2619 id
= xml_find_attribute (attributes
, "id")->value
;
2620 item
.ptid
= read_ptid (id
, NULL
);
2622 attr
= xml_find_attribute (attributes
, "core");
2624 item
.core
= *(ULONGEST
*) attr
->value
;
2630 VEC_safe_push (thread_item_t
, data
->items
, &item
);
2634 end_thread (struct gdb_xml_parser
*parser
,
2635 const struct gdb_xml_element
*element
,
2636 void *user_data
, const char *body_text
)
2638 struct threads_parsing_context
*data
= user_data
;
2640 if (body_text
&& *body_text
)
2641 VEC_last (thread_item_t
, data
->items
)->extra
= xstrdup (body_text
);
2644 const struct gdb_xml_attribute thread_attributes
[] = {
2645 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
2646 { "core", GDB_XML_AF_OPTIONAL
, gdb_xml_parse_attr_ulongest
, NULL
},
2647 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
2650 const struct gdb_xml_element thread_children
[] = {
2651 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2654 const struct gdb_xml_element threads_children
[] = {
2655 { "thread", thread_attributes
, thread_children
,
2656 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
2657 start_thread
, end_thread
},
2658 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2661 const struct gdb_xml_element threads_elements
[] = {
2662 { "threads", NULL
, threads_children
,
2663 GDB_XML_EF_NONE
, NULL
, NULL
},
2664 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
2667 /* Discard the contents of the constructed thread info context. */
2670 clear_threads_parsing_context (void *p
)
2672 struct threads_parsing_context
*context
= p
;
2674 struct thread_item
*item
;
2676 for (i
= 0; VEC_iterate (thread_item_t
, context
->items
, i
, item
); ++i
)
2677 xfree (item
->extra
);
2679 VEC_free (thread_item_t
, context
->items
);
2685 * Find all threads for info threads command.
2686 * Uses new thread protocol contributed by Cisco.
2687 * Falls back and attempts to use the older method (above)
2688 * if the target doesn't respond to the new method.
2692 remote_threads_info (struct target_ops
*ops
)
2694 struct remote_state
*rs
= get_remote_state ();
2698 if (remote_desc
== 0) /* paranoia */
2699 error (_("Command can only be used when connected to the remote target."));
2701 #if defined(HAVE_LIBEXPAT)
2702 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2704 char *xml
= target_read_stralloc (¤t_target
,
2705 TARGET_OBJECT_THREADS
, NULL
);
2707 struct cleanup
*back_to
= make_cleanup (xfree
, xml
);
2711 struct threads_parsing_context context
;
2713 context
.items
= NULL
;
2714 make_cleanup (clear_threads_parsing_context
, &context
);
2716 if (gdb_xml_parse_quick (_("threads"), "threads.dtd",
2717 threads_elements
, xml
, &context
) == 0)
2720 struct thread_item
*item
;
2723 VEC_iterate (thread_item_t
, context
.items
, i
, item
);
2726 if (!ptid_equal (item
->ptid
, null_ptid
))
2728 struct private_thread_info
*info
;
2729 /* In non-stop mode, we assume new found threads
2730 are running until proven otherwise with a
2731 stop reply. In all-stop, we can only get
2732 here if all threads are stopped. */
2733 int running
= non_stop
? 1 : 0;
2735 remote_notice_new_inferior (item
->ptid
, running
);
2737 info
= demand_private_info (item
->ptid
);
2738 info
->core
= item
->core
;
2739 info
->extra
= item
->extra
;
2746 do_cleanups (back_to
);
2751 if (use_threadinfo_query
)
2753 putpkt ("qfThreadInfo");
2754 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2756 if (bufp
[0] != '\0') /* q packet recognized */
2758 struct cleanup
*old_chain
;
2761 /* remote_notice_new_inferior (in the loop below) may make
2762 new RSP calls, which clobber rs->buf. Work with a
2764 bufp
= saved_reply
= xstrdup (rs
->buf
);
2765 old_chain
= make_cleanup (free_current_contents
, &saved_reply
);
2767 while (*bufp
++ == 'm') /* reply contains one or more TID */
2771 new_thread
= read_ptid (bufp
, &bufp
);
2772 if (!ptid_equal (new_thread
, null_ptid
))
2774 /* In non-stop mode, we assume new found threads
2775 are running until proven otherwise with a
2776 stop reply. In all-stop, we can only get
2777 here if all threads are stopped. */
2778 int running
= non_stop
? 1 : 0;
2780 remote_notice_new_inferior (new_thread
, running
);
2783 while (*bufp
++ == ','); /* comma-separated list */
2784 free_current_contents (&saved_reply
);
2785 putpkt ("qsThreadInfo");
2786 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2787 bufp
= saved_reply
= xstrdup (rs
->buf
);
2789 do_cleanups (old_chain
);
2794 /* Only qfThreadInfo is supported in non-stop mode. */
2798 /* Else fall back to old method based on jmetzler protocol. */
2799 use_threadinfo_query
= 0;
2800 remote_find_new_threads ();
2805 * Collect a descriptive string about the given thread.
2806 * The target may say anything it wants to about the thread
2807 * (typically info about its blocked / runnable state, name, etc.).
2808 * This string will appear in the info threads display.
2810 * Optional: targets are not required to implement this function.
2814 remote_threads_extra_info (struct thread_info
*tp
)
2816 struct remote_state
*rs
= get_remote_state ();
2820 struct gdb_ext_thread_info threadinfo
;
2821 static char display_buf
[100]; /* arbitrary... */
2822 int n
= 0; /* position in display_buf */
2824 if (remote_desc
== 0) /* paranoia */
2825 internal_error (__FILE__
, __LINE__
,
2826 _("remote_threads_extra_info"));
2828 if (ptid_equal (tp
->ptid
, magic_null_ptid
)
2829 || (ptid_get_pid (tp
->ptid
) != 0 && ptid_get_tid (tp
->ptid
) == 0))
2830 /* This is the main thread which was added by GDB. The remote
2831 server doesn't know about it. */
2834 if (remote_protocol_packets
[PACKET_qXfer_threads
].support
== PACKET_ENABLE
)
2836 struct thread_info
*info
= find_thread_ptid (tp
->ptid
);
2838 if (info
&& info
->private)
2839 return info
->private->extra
;
2844 if (use_threadextra_query
)
2847 char *endb
= rs
->buf
+ get_remote_packet_size ();
2849 xsnprintf (b
, endb
- b
, "qThreadExtraInfo,");
2851 write_ptid (b
, endb
, tp
->ptid
);
2854 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2855 if (rs
->buf
[0] != 0)
2857 n
= min (strlen (rs
->buf
) / 2, sizeof (display_buf
));
2858 result
= hex2bin (rs
->buf
, (gdb_byte
*) display_buf
, n
);
2859 display_buf
[result
] = '\0';
2864 /* If the above query fails, fall back to the old method. */
2865 use_threadextra_query
= 0;
2866 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
2867 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
2868 int_to_threadref (&id
, ptid_get_tid (tp
->ptid
));
2869 if (remote_get_threadinfo (&id
, set
, &threadinfo
))
2870 if (threadinfo
.active
)
2872 if (*threadinfo
.shortname
)
2873 n
+= xsnprintf (&display_buf
[0], sizeof (display_buf
) - n
,
2874 " Name: %s,", threadinfo
.shortname
);
2875 if (*threadinfo
.display
)
2876 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2877 " State: %s,", threadinfo
.display
);
2878 if (*threadinfo
.more_display
)
2879 n
+= xsnprintf (&display_buf
[n
], sizeof (display_buf
) - n
,
2880 " Priority: %s", threadinfo
.more_display
);
2884 /* For purely cosmetic reasons, clear up trailing commas. */
2885 if (',' == display_buf
[n
-1])
2886 display_buf
[n
-1] = ' ';
2895 remote_static_tracepoint_marker_at (CORE_ADDR addr
,
2896 struct static_tracepoint_marker
*marker
)
2898 struct remote_state
*rs
= get_remote_state ();
2901 xsnprintf (p
, get_remote_packet_size (), "qTSTMat:");
2903 p
+= hexnumstr (p
, addr
);
2905 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2909 error (_("Remote failure reply: %s"), p
);
2913 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2920 static VEC(static_tracepoint_marker_p
) *
2921 remote_static_tracepoint_markers_by_strid (const char *strid
)
2923 struct remote_state
*rs
= get_remote_state ();
2924 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
2925 struct static_tracepoint_marker
*marker
= NULL
;
2926 struct cleanup
*old_chain
;
2929 /* Ask for a first packet of static tracepoint marker
2932 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2935 error (_("Remote failure reply: %s"), p
);
2937 old_chain
= make_cleanup (free_current_marker
, &marker
);
2942 marker
= XCNEW (struct static_tracepoint_marker
);
2946 parse_static_tracepoint_marker_definition (p
, &p
, marker
);
2948 if (strid
== NULL
|| strcmp (strid
, marker
->str_id
) == 0)
2950 VEC_safe_push (static_tracepoint_marker_p
,
2956 release_static_tracepoint_marker (marker
);
2957 memset (marker
, 0, sizeof (*marker
));
2960 while (*p
++ == ','); /* comma-separated list */
2961 /* Ask for another packet of static tracepoint definition. */
2963 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
2967 do_cleanups (old_chain
);
2972 /* Implement the to_get_ada_task_ptid function for the remote targets. */
2975 remote_get_ada_task_ptid (long lwp
, long thread
)
2977 return ptid_build (ptid_get_pid (inferior_ptid
), 0, lwp
);
2981 /* Restart the remote side; this is an extended protocol operation. */
2984 extended_remote_restart (void)
2986 struct remote_state
*rs
= get_remote_state ();
2988 /* Send the restart command; for reasons I don't understand the
2989 remote side really expects a number after the "R". */
2990 xsnprintf (rs
->buf
, get_remote_packet_size (), "R%x", 0);
2993 remote_fileio_reset ();
2996 /* Clean up connection to a remote debugger. */
2999 remote_close (int quitting
)
3001 if (remote_desc
== NULL
)
3002 return; /* already closed */
3004 /* Make sure we leave stdin registered in the event loop, and we
3005 don't leave the async SIGINT signal handler installed. */
3006 remote_terminal_ours ();
3008 serial_close (remote_desc
);
3011 /* We don't have a connection to the remote stub anymore. Get rid
3012 of all the inferiors and their threads we were controlling.
3013 Reset inferior_ptid to null_ptid first, as otherwise has_stack_frame
3014 will be unable to find the thread corresponding to (pid, 0, 0). */
3015 inferior_ptid
= null_ptid
;
3016 discard_all_inferiors ();
3018 /* Stop replies may from inferiors which are still unknown to GDB.
3019 We are closing the remote target, so we should discard
3020 everything, including the stop replies from GDB-unknown
3022 discard_pending_stop_replies (NULL
);
3024 if (remote_async_inferior_event_token
)
3025 delete_async_event_handler (&remote_async_inferior_event_token
);
3027 remote_notif_unregister_async_event_handler ();
3030 /* Query the remote side for the text, data and bss offsets. */
3035 struct remote_state
*rs
= get_remote_state ();
3038 int lose
, num_segments
= 0, do_sections
, do_segments
;
3039 CORE_ADDR text_addr
, data_addr
, bss_addr
, segments
[2];
3040 struct section_offsets
*offs
;
3041 struct symfile_segment_data
*data
;
3043 if (symfile_objfile
== NULL
)
3046 putpkt ("qOffsets");
3047 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3050 if (buf
[0] == '\000')
3051 return; /* Return silently. Stub doesn't support
3055 warning (_("Remote failure reply: %s"), buf
);
3059 /* Pick up each field in turn. This used to be done with scanf, but
3060 scanf will make trouble if CORE_ADDR size doesn't match
3061 conversion directives correctly. The following code will work
3062 with any size of CORE_ADDR. */
3063 text_addr
= data_addr
= bss_addr
= 0;
3067 if (strncmp (ptr
, "Text=", 5) == 0)
3070 /* Don't use strtol, could lose on big values. */
3071 while (*ptr
&& *ptr
!= ';')
3072 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3074 if (strncmp (ptr
, ";Data=", 6) == 0)
3077 while (*ptr
&& *ptr
!= ';')
3078 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3083 if (!lose
&& strncmp (ptr
, ";Bss=", 5) == 0)
3086 while (*ptr
&& *ptr
!= ';')
3087 bss_addr
= (bss_addr
<< 4) + fromhex (*ptr
++);
3089 if (bss_addr
!= data_addr
)
3090 warning (_("Target reported unsupported offsets: %s"), buf
);
3095 else if (strncmp (ptr
, "TextSeg=", 8) == 0)
3098 /* Don't use strtol, could lose on big values. */
3099 while (*ptr
&& *ptr
!= ';')
3100 text_addr
= (text_addr
<< 4) + fromhex (*ptr
++);
3103 if (strncmp (ptr
, ";DataSeg=", 9) == 0)
3106 while (*ptr
&& *ptr
!= ';')
3107 data_addr
= (data_addr
<< 4) + fromhex (*ptr
++);
3115 error (_("Malformed response to offset query, %s"), buf
);
3116 else if (*ptr
!= '\0')
3117 warning (_("Target reported unsupported offsets: %s"), buf
);
3119 offs
= ((struct section_offsets
*)
3120 alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
)));
3121 memcpy (offs
, symfile_objfile
->section_offsets
,
3122 SIZEOF_N_SECTION_OFFSETS (symfile_objfile
->num_sections
));
3124 data
= get_symfile_segment_data (symfile_objfile
->obfd
);
3125 do_segments
= (data
!= NULL
);
3126 do_sections
= num_segments
== 0;
3128 if (num_segments
> 0)
3130 segments
[0] = text_addr
;
3131 segments
[1] = data_addr
;
3133 /* If we have two segments, we can still try to relocate everything
3134 by assuming that the .text and .data offsets apply to the whole
3135 text and data segments. Convert the offsets given in the packet
3136 to base addresses for symfile_map_offsets_to_segments. */
3137 else if (data
&& data
->num_segments
== 2)
3139 segments
[0] = data
->segment_bases
[0] + text_addr
;
3140 segments
[1] = data
->segment_bases
[1] + data_addr
;
3143 /* If the object file has only one segment, assume that it is text
3144 rather than data; main programs with no writable data are rare,
3145 but programs with no code are useless. Of course the code might
3146 have ended up in the data segment... to detect that we would need
3147 the permissions here. */
3148 else if (data
&& data
->num_segments
== 1)
3150 segments
[0] = data
->segment_bases
[0] + text_addr
;
3153 /* There's no way to relocate by segment. */
3159 int ret
= symfile_map_offsets_to_segments (symfile_objfile
->obfd
, data
,
3160 offs
, num_segments
, segments
);
3162 if (ret
== 0 && !do_sections
)
3163 error (_("Can not handle qOffsets TextSeg "
3164 "response with this symbol file"));
3171 free_symfile_segment_data (data
);
3175 offs
->offsets
[SECT_OFF_TEXT (symfile_objfile
)] = text_addr
;
3177 /* This is a temporary kludge to force data and bss to use the
3178 same offsets because that's what nlmconv does now. The real
3179 solution requires changes to the stub and remote.c that I
3180 don't have time to do right now. */
3182 offs
->offsets
[SECT_OFF_DATA (symfile_objfile
)] = data_addr
;
3183 offs
->offsets
[SECT_OFF_BSS (symfile_objfile
)] = data_addr
;
3186 objfile_relocate (symfile_objfile
, offs
);
3189 /* Callback for iterate_over_threads. Set the STOP_REQUESTED flags in
3190 threads we know are stopped already. This is used during the
3191 initial remote connection in non-stop mode --- threads that are
3192 reported as already being stopped are left stopped. */
3195 set_stop_requested_callback (struct thread_info
*thread
, void *data
)
3197 /* If we have a stop reply for this thread, it must be stopped. */
3198 if (peek_stop_reply (thread
->ptid
))
3199 set_stop_requested (thread
->ptid
, 1);
3204 /* Send interrupt_sequence to remote target. */
3206 send_interrupt_sequence (void)
3208 if (interrupt_sequence_mode
== interrupt_sequence_control_c
)
3209 serial_write (remote_desc
, "\x03", 1);
3210 else if (interrupt_sequence_mode
== interrupt_sequence_break
)
3211 serial_send_break (remote_desc
);
3212 else if (interrupt_sequence_mode
== interrupt_sequence_break_g
)
3214 serial_send_break (remote_desc
);
3215 serial_write (remote_desc
, "g", 1);
3218 internal_error (__FILE__
, __LINE__
,
3219 _("Invalid value for interrupt_sequence_mode: %s."),
3220 interrupt_sequence_mode
);
3224 /* If STOP_REPLY is a T stop reply, look for the "thread" register,
3225 and extract the PTID. Returns NULL_PTID if not found. */
3228 stop_reply_extract_thread (char *stop_reply
)
3230 if (stop_reply
[0] == 'T' && strlen (stop_reply
) > 3)
3234 /* Txx r:val ; r:val (...) */
3237 /* Look for "register" named "thread". */
3242 p1
= strchr (p
, ':');
3246 if (strncmp (p
, "thread", p1
- p
) == 0)
3247 return read_ptid (++p1
, &p
);
3249 p1
= strchr (p
, ';');
3261 /* Query the remote target for which is the current thread/process,
3262 add it to our tables, and update INFERIOR_PTID. The caller is
3263 responsible for setting the state such that the remote end is ready
3264 to return the current thread.
3266 This function is called after handling the '?' or 'vRun' packets,
3267 whose response is a stop reply from which we can also try
3268 extracting the thread. If the target doesn't support the explicit
3269 qC query, we infer the current thread from that stop reply, passed
3270 in in WAIT_STATUS, which may be NULL. */
3273 add_current_inferior_and_thread (char *wait_status
)
3275 struct remote_state
*rs
= get_remote_state ();
3277 ptid_t ptid
= null_ptid
;
3279 inferior_ptid
= null_ptid
;
3281 /* Now, if we have thread information, update inferior_ptid. First
3282 if we have a stop reply handy, maybe it's a T stop reply with a
3283 "thread" register we can extract the current thread from. If
3284 not, ask the remote which is the current thread, with qC. The
3285 former method avoids a roundtrip. Note we don't use
3286 remote_parse_stop_reply as that makes use of the target
3287 architecture, which we haven't yet fully determined at this
3289 if (wait_status
!= NULL
)
3290 ptid
= stop_reply_extract_thread (wait_status
);
3291 if (ptid_equal (ptid
, null_ptid
))
3292 ptid
= remote_current_thread (inferior_ptid
);
3294 if (!ptid_equal (ptid
, null_ptid
))
3296 if (!remote_multi_process_p (rs
))
3299 inferior_ptid
= ptid
;
3303 /* Without this, some commands which require an active target
3304 (such as kill) won't work. This variable serves (at least)
3305 double duty as both the pid of the target process (if it has
3306 such), and as a flag indicating that a target is active. */
3307 inferior_ptid
= magic_null_ptid
;
3311 remote_add_inferior (fake_pid_p
, ptid_get_pid (inferior_ptid
), -1);
3313 /* Add the main thread. */
3314 add_thread_silent (inferior_ptid
);
3318 remote_start_remote (int from_tty
, struct target_ops
*target
, int extended_p
)
3320 struct remote_state
*rs
= get_remote_state ();
3321 struct packet_config
*noack_config
;
3322 char *wait_status
= NULL
;
3324 immediate_quit
++; /* Allow user to interrupt it. */
3327 if (interrupt_on_connect
)
3328 send_interrupt_sequence ();
3330 /* Ack any packet which the remote side has already sent. */
3331 serial_write (remote_desc
, "+", 1);
3333 /* Signal other parts that we're going through the initial setup,
3334 and so things may not be stable yet. */
3335 rs
->starting_up
= 1;
3337 /* The first packet we send to the target is the optional "supported
3338 packets" request. If the target can answer this, it will tell us
3339 which later probes to skip. */
3340 remote_query_supported ();
3342 /* If the stub wants to get a QAllow, compose one and send it. */
3343 if (remote_protocol_packets
[PACKET_QAllow
].support
!= PACKET_DISABLE
)
3344 remote_set_permissions ();
3346 /* Next, we possibly activate noack mode.
3348 If the QStartNoAckMode packet configuration is set to AUTO,
3349 enable noack mode if the stub reported a wish for it with
3352 If set to TRUE, then enable noack mode even if the stub didn't
3353 report it in qSupported. If the stub doesn't reply OK, the
3354 session ends with an error.
3356 If FALSE, then don't activate noack mode, regardless of what the
3357 stub claimed should be the default with qSupported. */
3359 noack_config
= &remote_protocol_packets
[PACKET_QStartNoAckMode
];
3361 if (noack_config
->detect
== AUTO_BOOLEAN_TRUE
3362 || (noack_config
->detect
== AUTO_BOOLEAN_AUTO
3363 && noack_config
->support
== PACKET_ENABLE
))
3365 putpkt ("QStartNoAckMode");
3366 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3367 if (packet_ok (rs
->buf
, noack_config
) == PACKET_OK
)
3373 /* Tell the remote that we are using the extended protocol. */
3375 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3378 /* Let the target know which signals it is allowed to pass down to
3380 update_signals_program_target ();
3382 /* Next, if the target can specify a description, read it. We do
3383 this before anything involving memory or registers. */
3384 target_find_description ();
3386 /* Next, now that we know something about the target, update the
3387 address spaces in the program spaces. */
3388 update_address_spaces ();
3390 /* On OSs where the list of libraries is global to all
3391 processes, we fetch them early. */
3392 if (gdbarch_has_global_solist (target_gdbarch ()))
3393 solib_add (NULL
, from_tty
, target
, auto_solib_add
);
3397 if (!rs
->non_stop_aware
)
3398 error (_("Non-stop mode requested, but remote "
3399 "does not support non-stop"));
3401 putpkt ("QNonStop:1");
3402 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3404 if (strcmp (rs
->buf
, "OK") != 0)
3405 error (_("Remote refused setting non-stop mode with: %s"), rs
->buf
);
3407 /* Find about threads and processes the stub is already
3408 controlling. We default to adding them in the running state.
3409 The '?' query below will then tell us about which threads are
3411 remote_threads_info (target
);
3413 else if (rs
->non_stop_aware
)
3415 /* Don't assume that the stub can operate in all-stop mode.
3416 Request it explicitly. */
3417 putpkt ("QNonStop:0");
3418 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3420 if (strcmp (rs
->buf
, "OK") != 0)
3421 error (_("Remote refused setting all-stop mode with: %s"), rs
->buf
);
3424 /* Check whether the target is running now. */
3426 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3432 struct inferior
*inf
;
3434 if (rs
->buf
[0] == 'W' || rs
->buf
[0] == 'X')
3437 error (_("The target is not running (try extended-remote?)"));
3439 /* We're connected, but not running. Drop out before we
3440 call start_remote. */
3441 rs
->starting_up
= 0;
3446 /* Save the reply for later. */
3447 wait_status
= alloca (strlen (rs
->buf
) + 1);
3448 strcpy (wait_status
, rs
->buf
);
3451 /* Let the stub know that we want it to return the thread. */
3452 set_continue_thread (minus_one_ptid
);
3454 add_current_inferior_and_thread (wait_status
);
3456 /* init_wait_for_inferior should be called before get_offsets in order
3457 to manage `inserted' flag in bp loc in a correct state.
3458 breakpoint_init_inferior, called from init_wait_for_inferior, set
3459 `inserted' flag to 0, while before breakpoint_re_set, called from
3460 start_remote, set `inserted' flag to 1. In the initialization of
3461 inferior, breakpoint_init_inferior should be called first, and then
3462 breakpoint_re_set can be called. If this order is broken, state of
3463 `inserted' flag is wrong, and cause some problems on breakpoint
3465 init_wait_for_inferior ();
3467 get_offsets (); /* Get text, data & bss offsets. */
3469 /* If we could not find a description using qXfer, and we know
3470 how to do it some other way, try again. This is not
3471 supported for non-stop; it could be, but it is tricky if
3472 there are no stopped threads when we connect. */
3473 if (remote_read_description_p (target
)
3474 && gdbarch_target_desc (target_gdbarch ()) == NULL
)
3476 target_clear_description ();
3477 target_find_description ();
3480 /* Use the previously fetched status. */
3481 gdb_assert (wait_status
!= NULL
);
3482 strcpy (rs
->buf
, wait_status
);
3483 rs
->cached_wait_status
= 1;
3486 start_remote (from_tty
); /* Initialize gdb process mechanisms. */
3490 /* Clear WFI global state. Do this before finding about new
3491 threads and inferiors, and setting the current inferior.
3492 Otherwise we would clear the proceed status of the current
3493 inferior when we want its stop_soon state to be preserved
3494 (see notice_new_inferior). */
3495 init_wait_for_inferior ();
3497 /* In non-stop, we will either get an "OK", meaning that there
3498 are no stopped threads at this time; or, a regular stop
3499 reply. In the latter case, there may be more than one thread
3500 stopped --- we pull them all out using the vStopped
3502 if (strcmp (rs
->buf
, "OK") != 0)
3504 struct notif_client
*notif
= ¬if_client_stop
;
3506 /* remote_notif_get_pending_replies acks this one, and gets
3508 notif_client_stop
.pending_event
3509 = remote_notif_parse (notif
, rs
->buf
);
3510 remote_notif_get_pending_events (notif
);
3512 /* Make sure that threads that were stopped remain
3514 iterate_over_threads (set_stop_requested_callback
, NULL
);
3517 if (target_can_async_p ())
3518 target_async (inferior_event_handler
, 0);
3520 if (thread_count () == 0)
3523 error (_("The target is not running (try extended-remote?)"));
3525 /* We're connected, but not running. Drop out before we
3526 call start_remote. */
3527 rs
->starting_up
= 0;
3531 /* Let the stub know that we want it to return the thread. */
3533 /* Force the stub to choose a thread. */
3534 set_general_thread (null_ptid
);
3537 inferior_ptid
= remote_current_thread (minus_one_ptid
);
3538 if (ptid_equal (inferior_ptid
, minus_one_ptid
))
3539 error (_("remote didn't report the current thread in non-stop mode"));
3541 get_offsets (); /* Get text, data & bss offsets. */
3543 /* In non-stop mode, any cached wait status will be stored in
3544 the stop reply queue. */
3545 gdb_assert (wait_status
== NULL
);
3547 /* Report all signals during attach/startup. */
3548 remote_pass_signals (0, NULL
);
3551 /* If we connected to a live target, do some additional setup. */
3552 if (target_has_execution
)
3554 if (exec_bfd
) /* No use without an exec file. */
3555 remote_check_symbols (symfile_objfile
);
3558 /* Possibly the target has been engaged in a trace run started
3559 previously; find out where things are at. */
3560 if (remote_get_trace_status (current_trace_status ()) != -1)
3562 struct uploaded_tp
*uploaded_tps
= NULL
;
3563 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3565 if (current_trace_status ()->running
)
3566 printf_filtered (_("Trace is already running on the target.\n"));
3568 /* Get trace state variables first, they may be checked when
3569 parsing uploaded commands. */
3571 remote_upload_trace_state_variables (&uploaded_tsvs
);
3573 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3575 remote_upload_tracepoints (&uploaded_tps
);
3577 merge_uploaded_tracepoints (&uploaded_tps
);
3580 /* The thread and inferior lists are now synchronized with the
3581 target, our symbols have been relocated, and we're merged the
3582 target's tracepoints with ours. We're done with basic start
3584 rs
->starting_up
= 0;
3586 /* If breakpoints are global, insert them now. */
3587 if (gdbarch_has_global_breakpoints (target_gdbarch ())
3588 && breakpoints_always_inserted_mode ())
3589 insert_breakpoints ();
3592 /* Open a connection to a remote debugger.
3593 NAME is the filename used for communication. */
3596 remote_open (char *name
, int from_tty
)
3598 remote_open_1 (name
, from_tty
, &remote_ops
, 0);
3601 /* Open a connection to a remote debugger using the extended
3602 remote gdb protocol. NAME is the filename used for communication. */
3605 extended_remote_open (char *name
, int from_tty
)
3607 remote_open_1 (name
, from_tty
, &extended_remote_ops
, 1 /*extended_p */);
3610 /* Generic code for opening a connection to a remote target. */
3613 init_all_packet_configs (void)
3617 for (i
= 0; i
< PACKET_MAX
; i
++)
3618 update_packet_config (&remote_protocol_packets
[i
]);
3621 /* Symbol look-up. */
3624 remote_check_symbols (struct objfile
*objfile
)
3626 struct remote_state
*rs
= get_remote_state ();
3627 char *msg
, *reply
, *tmp
;
3628 struct minimal_symbol
*sym
;
3631 /* The remote side has no concept of inferiors that aren't running
3632 yet, it only knows about running processes. If we're connected
3633 but our current inferior is not running, we should not invite the
3634 remote target to request symbol lookups related to its
3635 (unrelated) current process. */
3636 if (!target_has_execution
)
3639 if (remote_protocol_packets
[PACKET_qSymbol
].support
== PACKET_DISABLE
)
3642 /* Make sure the remote is pointing at the right process. Note
3643 there's no way to select "no process". */
3644 set_general_process ();
3646 /* Allocate a message buffer. We can't reuse the input buffer in RS,
3647 because we need both at the same time. */
3648 msg
= alloca (get_remote_packet_size ());
3650 /* Invite target to request symbol lookups. */
3652 putpkt ("qSymbol::");
3653 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3654 packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSymbol
]);
3657 while (strncmp (reply
, "qSymbol:", 8) == 0)
3660 end
= hex2bin (tmp
, (gdb_byte
*) msg
, strlen (tmp
) / 2);
3662 sym
= lookup_minimal_symbol (msg
, NULL
, NULL
);
3664 xsnprintf (msg
, get_remote_packet_size (), "qSymbol::%s", &reply
[8]);
3667 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
3668 CORE_ADDR sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
3670 /* If this is a function address, return the start of code
3671 instead of any data function descriptor. */
3672 sym_addr
= gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
3676 xsnprintf (msg
, get_remote_packet_size (), "qSymbol:%s:%s",
3677 phex_nz (sym_addr
, addr_size
), &reply
[8]);
3681 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3686 static struct serial
*
3687 remote_serial_open (char *name
)
3689 static int udp_warning
= 0;
3691 /* FIXME: Parsing NAME here is a hack. But we want to warn here instead
3692 of in ser-tcp.c, because it is the remote protocol assuming that the
3693 serial connection is reliable and not the serial connection promising
3695 if (!udp_warning
&& strncmp (name
, "udp:", 4) == 0)
3697 warning (_("The remote protocol may be unreliable over UDP.\n"
3698 "Some events may be lost, rendering further debugging "
3703 return serial_open (name
);
3706 /* Inform the target of our permission settings. The permission flags
3707 work without this, but if the target knows the settings, it can do
3708 a couple things. First, it can add its own check, to catch cases
3709 that somehow manage to get by the permissions checks in target
3710 methods. Second, if the target is wired to disallow particular
3711 settings (for instance, a system in the field that is not set up to
3712 be able to stop at a breakpoint), it can object to any unavailable
3716 remote_set_permissions (void)
3718 struct remote_state
*rs
= get_remote_state ();
3720 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAllow:"
3721 "WriteReg:%x;WriteMem:%x;"
3722 "InsertBreak:%x;InsertTrace:%x;"
3723 "InsertFastTrace:%x;Stop:%x",
3724 may_write_registers
, may_write_memory
,
3725 may_insert_breakpoints
, may_insert_tracepoints
,
3726 may_insert_fast_tracepoints
, may_stop
);
3728 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
3730 /* If the target didn't like the packet, warn the user. Do not try
3731 to undo the user's settings, that would just be maddening. */
3732 if (strcmp (rs
->buf
, "OK") != 0)
3733 warning (_("Remote refused setting permissions with: %s"), rs
->buf
);
3736 /* This type describes each known response to the qSupported
3738 struct protocol_feature
3740 /* The name of this protocol feature. */
3743 /* The default for this protocol feature. */
3744 enum packet_support default_support
;
3746 /* The function to call when this feature is reported, or after
3747 qSupported processing if the feature is not supported.
3748 The first argument points to this structure. The second
3749 argument indicates whether the packet requested support be
3750 enabled, disabled, or probed (or the default, if this function
3751 is being called at the end of processing and this feature was
3752 not reported). The third argument may be NULL; if not NULL, it
3753 is a NUL-terminated string taken from the packet following
3754 this feature's name and an equals sign. */
3755 void (*func
) (const struct protocol_feature
*, enum packet_support
,
3758 /* The corresponding packet for this feature. Only used if
3759 FUNC is remote_supported_packet. */
3764 remote_supported_packet (const struct protocol_feature
*feature
,
3765 enum packet_support support
,
3766 const char *argument
)
3770 warning (_("Remote qSupported response supplied an unexpected value for"
3771 " \"%s\"."), feature
->name
);
3775 if (remote_protocol_packets
[feature
->packet
].support
3776 == PACKET_SUPPORT_UNKNOWN
)
3777 remote_protocol_packets
[feature
->packet
].support
= support
;
3781 remote_packet_size (const struct protocol_feature
*feature
,
3782 enum packet_support support
, const char *value
)
3784 struct remote_state
*rs
= get_remote_state ();
3789 if (support
!= PACKET_ENABLE
)
3792 if (value
== NULL
|| *value
== '\0')
3794 warning (_("Remote target reported \"%s\" without a size."),
3800 packet_size
= strtol (value
, &value_end
, 16);
3801 if (errno
!= 0 || *value_end
!= '\0' || packet_size
< 0)
3803 warning (_("Remote target reported \"%s\" with a bad size: \"%s\"."),
3804 feature
->name
, value
);
3808 if (packet_size
> MAX_REMOTE_PACKET_SIZE
)
3810 warning (_("limiting remote suggested packet size (%d bytes) to %d"),
3811 packet_size
, MAX_REMOTE_PACKET_SIZE
);
3812 packet_size
= MAX_REMOTE_PACKET_SIZE
;
3815 /* Record the new maximum packet size. */
3816 rs
->explicit_packet_size
= packet_size
;
3820 remote_multi_process_feature (const struct protocol_feature
*feature
,
3821 enum packet_support support
, const char *value
)
3823 struct remote_state
*rs
= get_remote_state ();
3825 rs
->multi_process_aware
= (support
== PACKET_ENABLE
);
3829 remote_non_stop_feature (const struct protocol_feature
*feature
,
3830 enum packet_support support
, const char *value
)
3832 struct remote_state
*rs
= get_remote_state ();
3834 rs
->non_stop_aware
= (support
== PACKET_ENABLE
);
3838 remote_cond_tracepoint_feature (const struct protocol_feature
*feature
,
3839 enum packet_support support
,
3842 struct remote_state
*rs
= get_remote_state ();
3844 rs
->cond_tracepoints
= (support
== PACKET_ENABLE
);
3848 remote_cond_breakpoint_feature (const struct protocol_feature
*feature
,
3849 enum packet_support support
,
3852 struct remote_state
*rs
= get_remote_state ();
3854 rs
->cond_breakpoints
= (support
== PACKET_ENABLE
);
3858 remote_breakpoint_commands_feature (const struct protocol_feature
*feature
,
3859 enum packet_support support
,
3862 struct remote_state
*rs
= get_remote_state ();
3864 rs
->breakpoint_commands
= (support
== PACKET_ENABLE
);
3868 remote_fast_tracepoint_feature (const struct protocol_feature
*feature
,
3869 enum packet_support support
,
3872 struct remote_state
*rs
= get_remote_state ();
3874 rs
->fast_tracepoints
= (support
== PACKET_ENABLE
);
3878 remote_static_tracepoint_feature (const struct protocol_feature
*feature
,
3879 enum packet_support support
,
3882 struct remote_state
*rs
= get_remote_state ();
3884 rs
->static_tracepoints
= (support
== PACKET_ENABLE
);
3888 remote_install_in_trace_feature (const struct protocol_feature
*feature
,
3889 enum packet_support support
,
3892 struct remote_state
*rs
= get_remote_state ();
3894 rs
->install_in_trace
= (support
== PACKET_ENABLE
);
3898 remote_disconnected_tracing_feature (const struct protocol_feature
*feature
,
3899 enum packet_support support
,
3902 struct remote_state
*rs
= get_remote_state ();
3904 rs
->disconnected_tracing
= (support
== PACKET_ENABLE
);
3908 remote_enable_disable_tracepoint_feature (const struct protocol_feature
*feature
,
3909 enum packet_support support
,
3912 struct remote_state
*rs
= get_remote_state ();
3914 rs
->enable_disable_tracepoints
= (support
== PACKET_ENABLE
);
3918 remote_string_tracing_feature (const struct protocol_feature
*feature
,
3919 enum packet_support support
,
3922 struct remote_state
*rs
= get_remote_state ();
3924 rs
->string_tracing
= (support
== PACKET_ENABLE
);
3927 static struct protocol_feature remote_protocol_features
[] = {
3928 { "PacketSize", PACKET_DISABLE
, remote_packet_size
, -1 },
3929 { "qXfer:auxv:read", PACKET_DISABLE
, remote_supported_packet
,
3930 PACKET_qXfer_auxv
},
3931 { "qXfer:features:read", PACKET_DISABLE
, remote_supported_packet
,
3932 PACKET_qXfer_features
},
3933 { "qXfer:libraries:read", PACKET_DISABLE
, remote_supported_packet
,
3934 PACKET_qXfer_libraries
},
3935 { "qXfer:libraries-svr4:read", PACKET_DISABLE
, remote_supported_packet
,
3936 PACKET_qXfer_libraries_svr4
},
3937 { "qXfer:memory-map:read", PACKET_DISABLE
, remote_supported_packet
,
3938 PACKET_qXfer_memory_map
},
3939 { "qXfer:spu:read", PACKET_DISABLE
, remote_supported_packet
,
3940 PACKET_qXfer_spu_read
},
3941 { "qXfer:spu:write", PACKET_DISABLE
, remote_supported_packet
,
3942 PACKET_qXfer_spu_write
},
3943 { "qXfer:osdata:read", PACKET_DISABLE
, remote_supported_packet
,
3944 PACKET_qXfer_osdata
},
3945 { "qXfer:threads:read", PACKET_DISABLE
, remote_supported_packet
,
3946 PACKET_qXfer_threads
},
3947 { "qXfer:traceframe-info:read", PACKET_DISABLE
, remote_supported_packet
,
3948 PACKET_qXfer_traceframe_info
},
3949 { "QPassSignals", PACKET_DISABLE
, remote_supported_packet
,
3950 PACKET_QPassSignals
},
3951 { "QProgramSignals", PACKET_DISABLE
, remote_supported_packet
,
3952 PACKET_QProgramSignals
},
3953 { "QStartNoAckMode", PACKET_DISABLE
, remote_supported_packet
,
3954 PACKET_QStartNoAckMode
},
3955 { "multiprocess", PACKET_DISABLE
, remote_multi_process_feature
, -1 },
3956 { "QNonStop", PACKET_DISABLE
, remote_non_stop_feature
, -1 },
3957 { "qXfer:siginfo:read", PACKET_DISABLE
, remote_supported_packet
,
3958 PACKET_qXfer_siginfo_read
},
3959 { "qXfer:siginfo:write", PACKET_DISABLE
, remote_supported_packet
,
3960 PACKET_qXfer_siginfo_write
},
3961 { "ConditionalTracepoints", PACKET_DISABLE
, remote_cond_tracepoint_feature
,
3962 PACKET_ConditionalTracepoints
},
3963 { "ConditionalBreakpoints", PACKET_DISABLE
, remote_cond_breakpoint_feature
,
3964 PACKET_ConditionalBreakpoints
},
3965 { "BreakpointCommands", PACKET_DISABLE
, remote_breakpoint_commands_feature
,
3966 PACKET_BreakpointCommands
},
3967 { "FastTracepoints", PACKET_DISABLE
, remote_fast_tracepoint_feature
,
3968 PACKET_FastTracepoints
},
3969 { "StaticTracepoints", PACKET_DISABLE
, remote_static_tracepoint_feature
,
3970 PACKET_StaticTracepoints
},
3971 {"InstallInTrace", PACKET_DISABLE
, remote_install_in_trace_feature
,
3972 PACKET_InstallInTrace
},
3973 { "DisconnectedTracing", PACKET_DISABLE
, remote_disconnected_tracing_feature
,
3975 { "ReverseContinue", PACKET_DISABLE
, remote_supported_packet
,
3977 { "ReverseStep", PACKET_DISABLE
, remote_supported_packet
,
3979 { "TracepointSource", PACKET_DISABLE
, remote_supported_packet
,
3980 PACKET_TracepointSource
},
3981 { "QAllow", PACKET_DISABLE
, remote_supported_packet
,
3983 { "EnableDisableTracepoints", PACKET_DISABLE
,
3984 remote_enable_disable_tracepoint_feature
, -1 },
3985 { "qXfer:fdpic:read", PACKET_DISABLE
, remote_supported_packet
,
3986 PACKET_qXfer_fdpic
},
3987 { "qXfer:uib:read", PACKET_DISABLE
, remote_supported_packet
,
3989 { "QDisableRandomization", PACKET_DISABLE
, remote_supported_packet
,
3990 PACKET_QDisableRandomization
},
3991 { "QAgent", PACKET_DISABLE
, remote_supported_packet
, PACKET_QAgent
},
3992 { "tracenz", PACKET_DISABLE
,
3993 remote_string_tracing_feature
, -1 },
3996 static char *remote_support_xml
;
3998 /* Register string appended to "xmlRegisters=" in qSupported query. */
4001 register_remote_support_xml (const char *xml
)
4003 #if defined(HAVE_LIBEXPAT)
4004 if (remote_support_xml
== NULL
)
4005 remote_support_xml
= concat ("xmlRegisters=", xml
, (char *) NULL
);
4008 char *copy
= xstrdup (remote_support_xml
+ 13);
4009 char *p
= strtok (copy
, ",");
4013 if (strcmp (p
, xml
) == 0)
4020 while ((p
= strtok (NULL
, ",")) != NULL
);
4023 remote_support_xml
= reconcat (remote_support_xml
,
4024 remote_support_xml
, ",", xml
,
4031 remote_query_supported_append (char *msg
, const char *append
)
4034 return reconcat (msg
, msg
, ";", append
, (char *) NULL
);
4036 return xstrdup (append
);
4040 remote_query_supported (void)
4042 struct remote_state
*rs
= get_remote_state ();
4045 unsigned char seen
[ARRAY_SIZE (remote_protocol_features
)];
4047 /* The packet support flags are handled differently for this packet
4048 than for most others. We treat an error, a disabled packet, and
4049 an empty response identically: any features which must be reported
4050 to be used will be automatically disabled. An empty buffer
4051 accomplishes this, since that is also the representation for a list
4052 containing no features. */
4055 if (remote_protocol_packets
[PACKET_qSupported
].support
!= PACKET_DISABLE
)
4058 struct cleanup
*old_chain
= make_cleanup (free_current_contents
, &q
);
4060 q
= remote_query_supported_append (q
, "multiprocess+");
4062 if (remote_support_xml
)
4063 q
= remote_query_supported_append (q
, remote_support_xml
);
4065 q
= remote_query_supported_append (q
, "qRelocInsn+");
4067 q
= reconcat (q
, "qSupported:", q
, (char *) NULL
);
4070 do_cleanups (old_chain
);
4072 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4074 /* If an error occured, warn, but do not return - just reset the
4075 buffer to empty and go on to disable features. */
4076 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_qSupported
])
4079 warning (_("Remote failure reply: %s"), rs
->buf
);
4084 memset (seen
, 0, sizeof (seen
));
4089 enum packet_support is_supported
;
4090 char *p
, *end
, *name_end
, *value
;
4092 /* First separate out this item from the rest of the packet. If
4093 there's another item after this, we overwrite the separator
4094 (terminated strings are much easier to work with). */
4096 end
= strchr (p
, ';');
4099 end
= p
+ strlen (p
);
4109 warning (_("empty item in \"qSupported\" response"));
4114 name_end
= strchr (p
, '=');
4117 /* This is a name=value entry. */
4118 is_supported
= PACKET_ENABLE
;
4119 value
= name_end
+ 1;
4128 is_supported
= PACKET_ENABLE
;
4132 is_supported
= PACKET_DISABLE
;
4136 is_supported
= PACKET_SUPPORT_UNKNOWN
;
4140 warning (_("unrecognized item \"%s\" "
4141 "in \"qSupported\" response"), p
);
4147 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4148 if (strcmp (remote_protocol_features
[i
].name
, p
) == 0)
4150 const struct protocol_feature
*feature
;
4153 feature
= &remote_protocol_features
[i
];
4154 feature
->func (feature
, is_supported
, value
);
4159 /* If we increased the packet size, make sure to increase the global
4160 buffer size also. We delay this until after parsing the entire
4161 qSupported packet, because this is the same buffer we were
4163 if (rs
->buf_size
< rs
->explicit_packet_size
)
4165 rs
->buf_size
= rs
->explicit_packet_size
;
4166 rs
->buf
= xrealloc (rs
->buf
, rs
->buf_size
);
4169 /* Handle the defaults for unmentioned features. */
4170 for (i
= 0; i
< ARRAY_SIZE (remote_protocol_features
); i
++)
4173 const struct protocol_feature
*feature
;
4175 feature
= &remote_protocol_features
[i
];
4176 feature
->func (feature
, feature
->default_support
, NULL
);
4182 remote_open_1 (char *name
, int from_tty
,
4183 struct target_ops
*target
, int extended_p
)
4185 struct remote_state
*rs
= get_remote_state ();
4188 error (_("To open a remote debug connection, you need to specify what\n"
4189 "serial device is attached to the remote system\n"
4190 "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
4192 /* See FIXME above. */
4193 if (!target_async_permitted
)
4194 wait_forever_enabled_p
= 1;
4196 /* If we're connected to a running target, target_preopen will kill it.
4197 But if we're connected to a target system with no running process,
4198 then we will still be connected when it returns. Ask this question
4199 first, before target_preopen has a chance to kill anything. */
4200 if (remote_desc
!= NULL
&& !have_inferiors ())
4203 || query (_("Already connected to a remote target. Disconnect? ")))
4206 error (_("Still connected."));
4209 target_preopen (from_tty
);
4211 unpush_target (target
);
4213 /* This time without a query. If we were connected to an
4214 extended-remote target and target_preopen killed the running
4215 process, we may still be connected. If we are starting "target
4216 remote" now, the extended-remote target will not have been
4217 removed by unpush_target. */
4218 if (remote_desc
!= NULL
&& !have_inferiors ())
4221 /* Make sure we send the passed signals list the next time we resume. */
4222 xfree (last_pass_packet
);
4223 last_pass_packet
= NULL
;
4225 /* Make sure we send the program signals list the next time we
4227 xfree (last_program_signals_packet
);
4228 last_program_signals_packet
= NULL
;
4230 remote_fileio_reset ();
4231 reopen_exec_file ();
4234 remote_desc
= remote_serial_open (name
);
4236 perror_with_name (name
);
4238 if (baud_rate
!= -1)
4240 if (serial_setbaudrate (remote_desc
, baud_rate
))
4242 /* The requested speed could not be set. Error out to
4243 top level after closing remote_desc. Take care to
4244 set remote_desc to NULL to avoid closing remote_desc
4246 serial_close (remote_desc
);
4248 perror_with_name (name
);
4252 serial_raw (remote_desc
);
4254 /* If there is something sitting in the buffer we might take it as a
4255 response to a command, which would be bad. */
4256 serial_flush_input (remote_desc
);
4260 puts_filtered ("Remote debugging using ");
4261 puts_filtered (name
);
4262 puts_filtered ("\n");
4264 push_target (target
); /* Switch to using remote target now. */
4266 /* Register extra event sources in the event loop. */
4267 remote_async_inferior_event_token
4268 = create_async_event_handler (remote_async_inferior_event_handler
,
4270 remote_notif_register_async_event_handler ();
4272 /* Reset the target state; these things will be queried either by
4273 remote_query_supported or as they are needed. */
4274 init_all_packet_configs ();
4275 rs
->cached_wait_status
= 0;
4276 rs
->explicit_packet_size
= 0;
4278 rs
->multi_process_aware
= 0;
4279 rs
->extended
= extended_p
;
4280 rs
->non_stop_aware
= 0;
4281 rs
->waiting_for_stop_reply
= 0;
4282 rs
->ctrlc_pending_p
= 0;
4284 general_thread
= not_sent_ptid
;
4285 continue_thread
= not_sent_ptid
;
4286 remote_traceframe_number
= -1;
4288 /* Probe for ability to use "ThreadInfo" query, as required. */
4289 use_threadinfo_query
= 1;
4290 use_threadextra_query
= 1;
4292 if (target_async_permitted
)
4294 /* With this target we start out by owning the terminal. */
4295 remote_async_terminal_ours_p
= 1;
4297 /* FIXME: cagney/1999-09-23: During the initial connection it is
4298 assumed that the target is already ready and able to respond to
4299 requests. Unfortunately remote_start_remote() eventually calls
4300 wait_for_inferior() with no timeout. wait_forever_enabled_p gets
4301 around this. Eventually a mechanism that allows
4302 wait_for_inferior() to expect/get timeouts will be
4304 wait_forever_enabled_p
= 0;
4307 /* First delete any symbols previously loaded from shared libraries. */
4308 no_shared_libraries (NULL
, 0);
4311 init_thread_list ();
4313 /* Start the remote connection. If error() or QUIT, discard this
4314 target (we'd otherwise be in an inconsistent state) and then
4315 propogate the error on up the exception chain. This ensures that
4316 the caller doesn't stumble along blindly assuming that the
4317 function succeeded. The CLI doesn't have this problem but other
4318 UI's, such as MI do.
4320 FIXME: cagney/2002-05-19: Instead of re-throwing the exception,
4321 this function should return an error indication letting the
4322 caller restore the previous state. Unfortunately the command
4323 ``target remote'' is directly wired to this function making that
4324 impossible. On a positive note, the CLI side of this problem has
4325 been fixed - the function set_cmd_context() makes it possible for
4326 all the ``target ....'' commands to share a common callback
4327 function. See cli-dump.c. */
4329 volatile struct gdb_exception ex
;
4331 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4333 remote_start_remote (from_tty
, target
, extended_p
);
4337 /* Pop the partially set up target - unless something else did
4338 already before throwing the exception. */
4339 if (remote_desc
!= NULL
)
4341 if (target_async_permitted
)
4342 wait_forever_enabled_p
= 1;
4343 throw_exception (ex
);
4347 if (target_async_permitted
)
4348 wait_forever_enabled_p
= 1;
4351 /* This takes a program previously attached to and detaches it. After
4352 this is done, GDB can be used to debug some other program. We
4353 better not have left any breakpoints in the target program or it'll
4354 die when it hits one. */
4357 remote_detach_1 (char *args
, int from_tty
, int extended
)
4359 int pid
= ptid_get_pid (inferior_ptid
);
4360 struct remote_state
*rs
= get_remote_state ();
4363 error (_("Argument given to \"detach\" when remotely debugging."));
4365 if (!target_has_execution
)
4366 error (_("No process to detach from."));
4370 char *exec_file
= get_exec_file (0);
4371 if (exec_file
== NULL
)
4373 printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file
,
4374 target_pid_to_str (pid_to_ptid (pid
)));
4375 gdb_flush (gdb_stdout
);
4378 /* Tell the remote target to detach. */
4379 if (remote_multi_process_p (rs
))
4380 xsnprintf (rs
->buf
, get_remote_packet_size (), "D;%x", pid
);
4382 strcpy (rs
->buf
, "D");
4385 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4387 if (rs
->buf
[0] == 'O' && rs
->buf
[1] == 'K')
4389 else if (rs
->buf
[0] == '\0')
4390 error (_("Remote doesn't know how to detach"));
4392 error (_("Can't detach process."));
4394 if (from_tty
&& !extended
)
4395 puts_filtered (_("Ending remote debugging.\n"));
4397 target_mourn_inferior ();
4401 remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4403 remote_detach_1 (args
, from_tty
, 0);
4407 extended_remote_detach (struct target_ops
*ops
, char *args
, int from_tty
)
4409 remote_detach_1 (args
, from_tty
, 1);
4412 /* Same as remote_detach, but don't send the "D" packet; just disconnect. */
4415 remote_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
4418 error (_("Argument given to \"disconnect\" when remotely debugging."));
4420 /* Make sure we unpush even the extended remote targets; mourn
4421 won't do it. So call remote_mourn_1 directly instead of
4422 target_mourn_inferior. */
4423 remote_mourn_1 (target
);
4426 puts_filtered ("Ending remote debugging.\n");
4429 /* Attach to the process specified by ARGS. If FROM_TTY is non-zero,
4430 be chatty about it. */
4433 extended_remote_attach_1 (struct target_ops
*target
, char *args
, int from_tty
)
4435 struct remote_state
*rs
= get_remote_state ();
4437 char *wait_status
= NULL
;
4439 pid
= parse_pid_to_attach (args
);
4441 /* Remote PID can be freely equal to getpid, do not check it here the same
4442 way as in other targets. */
4444 if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4445 error (_("This target does not support attaching to a process"));
4449 char *exec_file
= get_exec_file (0);
4452 printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file
,
4453 target_pid_to_str (pid_to_ptid (pid
)));
4455 printf_unfiltered (_("Attaching to %s\n"),
4456 target_pid_to_str (pid_to_ptid (pid
)));
4458 gdb_flush (gdb_stdout
);
4461 xsnprintf (rs
->buf
, get_remote_packet_size (), "vAttach;%x", pid
);
4463 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4465 if (packet_ok (rs
->buf
,
4466 &remote_protocol_packets
[PACKET_vAttach
]) == PACKET_OK
)
4470 /* Save the reply for later. */
4471 wait_status
= alloca (strlen (rs
->buf
) + 1);
4472 strcpy (wait_status
, rs
->buf
);
4474 else if (strcmp (rs
->buf
, "OK") != 0)
4475 error (_("Attaching to %s failed with: %s"),
4476 target_pid_to_str (pid_to_ptid (pid
)),
4479 else if (remote_protocol_packets
[PACKET_vAttach
].support
== PACKET_DISABLE
)
4480 error (_("This target does not support attaching to a process"));
4482 error (_("Attaching to %s failed"),
4483 target_pid_to_str (pid_to_ptid (pid
)));
4485 set_current_inferior (remote_add_inferior (0, pid
, 1));
4487 inferior_ptid
= pid_to_ptid (pid
);
4491 struct thread_info
*thread
;
4493 /* Get list of threads. */
4494 remote_threads_info (target
);
4496 thread
= first_thread_of_process (pid
);
4498 inferior_ptid
= thread
->ptid
;
4500 inferior_ptid
= pid_to_ptid (pid
);
4502 /* Invalidate our notion of the remote current thread. */
4503 record_currthread (minus_one_ptid
);
4507 /* Now, if we have thread information, update inferior_ptid. */
4508 inferior_ptid
= remote_current_thread (inferior_ptid
);
4510 /* Add the main thread to the thread list. */
4511 add_thread_silent (inferior_ptid
);
4514 /* Next, if the target can specify a description, read it. We do
4515 this before anything involving memory or registers. */
4516 target_find_description ();
4520 /* Use the previously fetched status. */
4521 gdb_assert (wait_status
!= NULL
);
4523 if (target_can_async_p ())
4525 struct notif_event
*reply
4526 = remote_notif_parse (¬if_client_stop
, wait_status
);
4528 push_stop_reply ((struct stop_reply
*) reply
);
4530 target_async (inferior_event_handler
, 0);
4534 gdb_assert (wait_status
!= NULL
);
4535 strcpy (rs
->buf
, wait_status
);
4536 rs
->cached_wait_status
= 1;
4540 gdb_assert (wait_status
== NULL
);
4544 extended_remote_attach (struct target_ops
*ops
, char *args
, int from_tty
)
4546 extended_remote_attach_1 (ops
, args
, from_tty
);
4549 /* Convert hex digit A to a number. */
4554 if (a
>= '0' && a
<= '9')
4556 else if (a
>= 'a' && a
<= 'f')
4557 return a
- 'a' + 10;
4558 else if (a
>= 'A' && a
<= 'F')
4559 return a
- 'A' + 10;
4561 error (_("Reply contains invalid hex digit %d"), a
);
4565 hex2bin (const char *hex
, gdb_byte
*bin
, int count
)
4569 for (i
= 0; i
< count
; i
++)
4571 if (hex
[0] == 0 || hex
[1] == 0)
4573 /* Hex string is short, or of uneven length.
4574 Return the count that has been converted so far. */
4577 *bin
++ = fromhex (hex
[0]) * 16 + fromhex (hex
[1]);
4583 /* Convert number NIB to a hex digit. */
4591 return 'a' + nib
- 10;
4595 bin2hex (const gdb_byte
*bin
, char *hex
, int count
)
4599 /* May use a length, or a nul-terminated string as input. */
4601 count
= strlen ((char *) bin
);
4603 for (i
= 0; i
< count
; i
++)
4605 *hex
++ = tohex ((*bin
>> 4) & 0xf);
4606 *hex
++ = tohex (*bin
++ & 0xf);
4612 /* Check for the availability of vCont. This function should also check
4616 remote_vcont_probe (struct remote_state
*rs
)
4620 strcpy (rs
->buf
, "vCont?");
4622 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4625 /* Make sure that the features we assume are supported. */
4626 if (strncmp (buf
, "vCont", 5) == 0)
4629 int support_s
, support_S
, support_c
, support_C
;
4635 rs
->support_vCont_t
= 0;
4636 while (p
&& *p
== ';')
4639 if (*p
== 's' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4641 else if (*p
== 'S' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4643 else if (*p
== 'c' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4645 else if (*p
== 'C' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4647 else if (*p
== 't' && (*(p
+ 1) == ';' || *(p
+ 1) == 0))
4648 rs
->support_vCont_t
= 1;
4650 p
= strchr (p
, ';');
4653 /* If s, S, c, and C are not all supported, we can't use vCont. Clearing
4654 BUF will make packet_ok disable the packet. */
4655 if (!support_s
|| !support_S
|| !support_c
|| !support_C
)
4659 packet_ok (buf
, &remote_protocol_packets
[PACKET_vCont
]);
4662 /* Helper function for building "vCont" resumptions. Write a
4663 resumption to P. ENDP points to one-passed-the-end of the buffer
4664 we're allowed to write to. Returns BUF+CHARACTERS_WRITTEN. The
4665 thread to be resumed is PTID; STEP and SIGGNAL indicate whether the
4666 resumed thread should be single-stepped and/or signalled. If PTID
4667 equals minus_one_ptid, then all threads are resumed; if PTID
4668 represents a process, then all threads of the process are resumed;
4669 the thread to be stepped and/or signalled is given in the global
4673 append_resumption (char *p
, char *endp
,
4674 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4676 struct remote_state
*rs
= get_remote_state ();
4678 if (step
&& siggnal
!= GDB_SIGNAL_0
)
4679 p
+= xsnprintf (p
, endp
- p
, ";S%02x", siggnal
);
4681 p
+= xsnprintf (p
, endp
- p
, ";s");
4682 else if (siggnal
!= GDB_SIGNAL_0
)
4683 p
+= xsnprintf (p
, endp
- p
, ";C%02x", siggnal
);
4685 p
+= xsnprintf (p
, endp
- p
, ";c");
4687 if (remote_multi_process_p (rs
) && ptid_is_pid (ptid
))
4691 /* All (-1) threads of process. */
4692 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
4694 p
+= xsnprintf (p
, endp
- p
, ":");
4695 p
= write_ptid (p
, endp
, nptid
);
4697 else if (!ptid_equal (ptid
, minus_one_ptid
))
4699 p
+= xsnprintf (p
, endp
- p
, ":");
4700 p
= write_ptid (p
, endp
, ptid
);
4706 /* Append a vCont continue-with-signal action for threads that have a
4707 non-zero stop signal. */
4710 append_pending_thread_resumptions (char *p
, char *endp
, ptid_t ptid
)
4712 struct thread_info
*thread
;
4714 ALL_THREADS (thread
)
4715 if (ptid_match (thread
->ptid
, ptid
)
4716 && !ptid_equal (inferior_ptid
, thread
->ptid
)
4717 && thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4718 && signal_pass_state (thread
->suspend
.stop_signal
))
4720 p
= append_resumption (p
, endp
, thread
->ptid
,
4721 0, thread
->suspend
.stop_signal
);
4722 thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4728 /* Resume the remote inferior by using a "vCont" packet. The thread
4729 to be resumed is PTID; STEP and SIGGNAL indicate whether the
4730 resumed thread should be single-stepped and/or signalled. If PTID
4731 equals minus_one_ptid, then all threads are resumed; the thread to
4732 be stepped and/or signalled is given in the global INFERIOR_PTID.
4733 This function returns non-zero iff it resumes the inferior.
4735 This function issues a strict subset of all possible vCont commands at the
4739 remote_vcont_resume (ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4741 struct remote_state
*rs
= get_remote_state ();
4745 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4746 remote_vcont_probe (rs
);
4748 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_DISABLE
)
4752 endp
= rs
->buf
+ get_remote_packet_size ();
4754 /* If we could generate a wider range of packets, we'd have to worry
4755 about overflowing BUF. Should there be a generic
4756 "multi-part-packet" packet? */
4758 p
+= xsnprintf (p
, endp
- p
, "vCont");
4760 if (ptid_equal (ptid
, magic_null_ptid
))
4762 /* MAGIC_NULL_PTID means that we don't have any active threads,
4763 so we don't have any TID numbers the inferior will
4764 understand. Make sure to only send forms that do not specify
4766 append_resumption (p
, endp
, minus_one_ptid
, step
, siggnal
);
4768 else if (ptid_equal (ptid
, minus_one_ptid
) || ptid_is_pid (ptid
))
4770 /* Resume all threads (of all processes, or of a single
4771 process), with preference for INFERIOR_PTID. This assumes
4772 inferior_ptid belongs to the set of all threads we are about
4774 if (step
|| siggnal
!= GDB_SIGNAL_0
)
4776 /* Step inferior_ptid, with or without signal. */
4777 p
= append_resumption (p
, endp
, inferior_ptid
, step
, siggnal
);
4780 /* Also pass down any pending signaled resumption for other
4781 threads not the current. */
4782 p
= append_pending_thread_resumptions (p
, endp
, ptid
);
4784 /* And continue others without a signal. */
4785 append_resumption (p
, endp
, ptid
, /*step=*/ 0, GDB_SIGNAL_0
);
4789 /* Scheduler locking; resume only PTID. */
4790 append_resumption (p
, endp
, ptid
, step
, siggnal
);
4793 gdb_assert (strlen (rs
->buf
) < get_remote_packet_size ());
4798 /* In non-stop, the stub replies to vCont with "OK". The stop
4799 reply will be reported asynchronously by means of a `%Stop'
4801 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
4802 if (strcmp (rs
->buf
, "OK") != 0)
4803 error (_("Unexpected vCont reply in non-stop mode: %s"), rs
->buf
);
4809 /* Tell the remote machine to resume. */
4811 static enum gdb_signal last_sent_signal
= GDB_SIGNAL_0
;
4813 static int last_sent_step
;
4816 remote_resume (struct target_ops
*ops
,
4817 ptid_t ptid
, int step
, enum gdb_signal siggnal
)
4819 struct remote_state
*rs
= get_remote_state ();
4822 /* In all-stop, we can't mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
4823 (explained in remote-notif.c:handle_notification) so
4824 remote_notif_process is not called. We need find a place where
4825 it is safe to start a 'vNotif' sequence. It is good to do it
4826 before resuming inferior, because inferior was stopped and no RSP
4827 traffic at that moment. */
4829 remote_notif_process (¬if_client_stop
);
4831 last_sent_signal
= siggnal
;
4832 last_sent_step
= step
;
4834 /* The vCont packet doesn't need to specify threads via Hc. */
4835 /* No reverse support (yet) for vCont. */
4836 if (execution_direction
!= EXEC_REVERSE
)
4837 if (remote_vcont_resume (ptid
, step
, siggnal
))
4840 /* All other supported resume packets do use Hc, so set the continue
4842 if (ptid_equal (ptid
, minus_one_ptid
))
4843 set_continue_thread (any_thread_ptid
);
4845 set_continue_thread (ptid
);
4848 if (execution_direction
== EXEC_REVERSE
)
4850 /* We don't pass signals to the target in reverse exec mode. */
4851 if (info_verbose
&& siggnal
!= GDB_SIGNAL_0
)
4852 warning (_(" - Can't pass signal %d to target in reverse: ignored."),
4856 && remote_protocol_packets
[PACKET_bs
].support
== PACKET_DISABLE
)
4857 error (_("Remote reverse-step not supported."));
4859 && remote_protocol_packets
[PACKET_bc
].support
== PACKET_DISABLE
)
4860 error (_("Remote reverse-continue not supported."));
4862 strcpy (buf
, step
? "bs" : "bc");
4864 else if (siggnal
!= GDB_SIGNAL_0
)
4866 buf
[0] = step
? 'S' : 'C';
4867 buf
[1] = tohex (((int) siggnal
>> 4) & 0xf);
4868 buf
[2] = tohex (((int) siggnal
) & 0xf);
4872 strcpy (buf
, step
? "s" : "c");
4877 /* We are about to start executing the inferior, let's register it
4878 with the event loop. NOTE: this is the one place where all the
4879 execution commands end up. We could alternatively do this in each
4880 of the execution commands in infcmd.c. */
4881 /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
4882 into infcmd.c in order to allow inferior function calls to work
4883 NOT asynchronously. */
4884 if (target_can_async_p ())
4885 target_async (inferior_event_handler
, 0);
4887 /* We've just told the target to resume. The remote server will
4888 wait for the inferior to stop, and then send a stop reply. In
4889 the mean time, we can't start another command/query ourselves
4890 because the stub wouldn't be ready to process it. This applies
4891 only to the base all-stop protocol, however. In non-stop (which
4892 only supports vCont), the stub replies with an "OK", and is
4893 immediate able to process further serial input. */
4895 rs
->waiting_for_stop_reply
= 1;
4899 /* Set up the signal handler for SIGINT, while the target is
4900 executing, ovewriting the 'regular' SIGINT signal handler. */
4902 initialize_sigint_signal_handler (void)
4904 signal (SIGINT
, handle_remote_sigint
);
4907 /* Signal handler for SIGINT, while the target is executing. */
4909 handle_remote_sigint (int sig
)
4911 signal (sig
, handle_remote_sigint_twice
);
4912 mark_async_signal_handler (sigint_remote_token
);
4915 /* Signal handler for SIGINT, installed after SIGINT has already been
4916 sent once. It will take effect the second time that the user sends
4919 handle_remote_sigint_twice (int sig
)
4921 signal (sig
, handle_remote_sigint
);
4922 mark_async_signal_handler (sigint_remote_twice_token
);
4925 /* Perform the real interruption of the target execution, in response
4928 async_remote_interrupt (gdb_client_data arg
)
4931 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt called\n");
4933 target_stop (inferior_ptid
);
4936 /* Perform interrupt, if the first attempt did not succeed. Just give
4937 up on the target alltogether. */
4939 async_remote_interrupt_twice (gdb_client_data arg
)
4942 fprintf_unfiltered (gdb_stdlog
, "async_remote_interrupt_twice called\n");
4947 /* Reinstall the usual SIGINT handlers, after the target has
4950 cleanup_sigint_signal_handler (void *dummy
)
4952 signal (SIGINT
, handle_sigint
);
4955 /* Send ^C to target to halt it. Target will respond, and send us a
4957 static void (*ofunc
) (int);
4959 /* The command line interface's stop routine. This function is installed
4960 as a signal handler for SIGINT. The first time a user requests a
4961 stop, we call remote_stop to send a break or ^C. If there is no
4962 response from the target (it didn't stop when the user requested it),
4963 we ask the user if he'd like to detach from the target. */
4965 remote_interrupt (int signo
)
4967 /* If this doesn't work, try more severe steps. */
4968 signal (signo
, remote_interrupt_twice
);
4970 gdb_call_async_signal_handler (sigint_remote_token
, 1);
4973 /* The user typed ^C twice. */
4976 remote_interrupt_twice (int signo
)
4978 signal (signo
, ofunc
);
4979 gdb_call_async_signal_handler (sigint_remote_twice_token
, 1);
4980 signal (signo
, remote_interrupt
);
4983 /* Non-stop version of target_stop. Uses `vCont;t' to stop a remote
4984 thread, all threads of a remote process, or all threads of all
4988 remote_stop_ns (ptid_t ptid
)
4990 struct remote_state
*rs
= get_remote_state ();
4992 char *endp
= rs
->buf
+ get_remote_packet_size ();
4994 if (remote_protocol_packets
[PACKET_vCont
].support
== PACKET_SUPPORT_UNKNOWN
)
4995 remote_vcont_probe (rs
);
4997 if (!rs
->support_vCont_t
)
4998 error (_("Remote server does not support stopping threads"));
5000 if (ptid_equal (ptid
, minus_one_ptid
)
5001 || (!remote_multi_process_p (rs
) && ptid_is_pid (ptid
)))
5002 p
+= xsnprintf (p
, endp
- p
, "vCont;t");
5007 p
+= xsnprintf (p
, endp
- p
, "vCont;t:");
5009 if (ptid_is_pid (ptid
))
5010 /* All (-1) threads of process. */
5011 nptid
= ptid_build (ptid_get_pid (ptid
), 0, -1);
5014 /* Small optimization: if we already have a stop reply for
5015 this thread, no use in telling the stub we want this
5017 if (peek_stop_reply (ptid
))
5023 write_ptid (p
, endp
, nptid
);
5026 /* In non-stop, we get an immediate OK reply. The stop reply will
5027 come in asynchronously by notification. */
5029 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5030 if (strcmp (rs
->buf
, "OK") != 0)
5031 error (_("Stopping %s failed: %s"), target_pid_to_str (ptid
), rs
->buf
);
5034 /* All-stop version of target_stop. Sends a break or a ^C to stop the
5035 remote target. It is undefined which thread of which process
5036 reports the stop. */
5039 remote_stop_as (ptid_t ptid
)
5041 struct remote_state
*rs
= get_remote_state ();
5043 rs
->ctrlc_pending_p
= 1;
5045 /* If the inferior is stopped already, but the core didn't know
5046 about it yet, just ignore the request. The cached wait status
5047 will be collected in remote_wait. */
5048 if (rs
->cached_wait_status
)
5051 /* Send interrupt_sequence to remote target. */
5052 send_interrupt_sequence ();
5055 /* This is the generic stop called via the target vector. When a target
5056 interrupt is requested, either by the command line or the GUI, we
5057 will eventually end up here. */
5060 remote_stop (ptid_t ptid
)
5063 fprintf_unfiltered (gdb_stdlog
, "remote_stop called\n");
5066 remote_stop_ns (ptid
);
5068 remote_stop_as (ptid
);
5071 /* Ask the user what to do when an interrupt is received. */
5074 interrupt_query (void)
5076 target_terminal_ours ();
5078 if (target_can_async_p ())
5080 signal (SIGINT
, handle_sigint
);
5081 deprecated_throw_reason (RETURN_QUIT
);
5085 if (query (_("Interrupted while waiting for the program.\n\
5086 Give up (and stop debugging it)? ")))
5089 deprecated_throw_reason (RETURN_QUIT
);
5093 target_terminal_inferior ();
5096 /* Enable/disable target terminal ownership. Most targets can use
5097 terminal groups to control terminal ownership. Remote targets are
5098 different in that explicit transfer of ownership to/from GDB/target
5102 remote_terminal_inferior (void)
5104 if (!target_async_permitted
)
5105 /* Nothing to do. */
5108 /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
5109 idempotent. The event-loop GDB talking to an asynchronous target
5110 with a synchronous command calls this function from both
5111 event-top.c and infrun.c/infcmd.c. Once GDB stops trying to
5112 transfer the terminal to the target when it shouldn't this guard
5114 if (!remote_async_terminal_ours_p
)
5116 delete_file_handler (input_fd
);
5117 remote_async_terminal_ours_p
= 0;
5118 initialize_sigint_signal_handler ();
5119 /* NOTE: At this point we could also register our selves as the
5120 recipient of all input. Any characters typed could then be
5121 passed on down to the target. */
5125 remote_terminal_ours (void)
5127 if (!target_async_permitted
)
5128 /* Nothing to do. */
5131 /* See FIXME in remote_terminal_inferior. */
5132 if (remote_async_terminal_ours_p
)
5134 cleanup_sigint_signal_handler (NULL
);
5135 add_file_handler (input_fd
, stdin_event_handler
, 0);
5136 remote_async_terminal_ours_p
= 1;
5140 remote_console_output (char *msg
)
5144 for (p
= msg
; p
[0] && p
[1]; p
+= 2)
5147 char c
= fromhex (p
[0]) * 16 + fromhex (p
[1]);
5151 fputs_unfiltered (tb
, gdb_stdtarg
);
5153 gdb_flush (gdb_stdtarg
);
5156 typedef struct cached_reg
5159 gdb_byte data
[MAX_REGISTER_SIZE
];
5162 DEF_VEC_O(cached_reg_t
);
5164 typedef struct stop_reply
5166 struct notif_event base
;
5168 /* The identifier of the thread about this event */
5171 struct target_waitstatus ws
;
5173 /* Expedited registers. This makes remote debugging a bit more
5174 efficient for those targets that provide critical registers as
5175 part of their normal status mechanism (as another roundtrip to
5176 fetch them is avoided). */
5177 VEC(cached_reg_t
) *regcache
;
5179 int stopped_by_watchpoint_p
;
5180 CORE_ADDR watch_data_address
;
5188 DECLARE_QUEUE_P (stop_reply_p
);
5189 DEFINE_QUEUE_P (stop_reply_p
);
5190 /* The list of already fetched and acknowledged stop events. This
5191 queue is used for notification Stop, and other notifications
5192 don't need queue for their events, because the notification events
5193 of Stop can't be consumed immediately, so that events should be
5194 queued first, and be consumed by remote_wait_{ns,as} one per
5195 time. Other notifications can consume their events immediately,
5196 so queue is not needed for them. */
5197 static QUEUE (stop_reply_p
) *stop_reply_queue
;
5200 stop_reply_xfree (struct stop_reply
*r
)
5204 VEC_free (cached_reg_t
, r
->regcache
);
5210 remote_notif_stop_parse (struct notif_client
*self
, char *buf
,
5211 struct notif_event
*event
)
5213 remote_parse_stop_reply (buf
, (struct stop_reply
*) event
);
5217 remote_notif_stop_ack (struct notif_client
*self
, char *buf
,
5218 struct notif_event
*event
)
5220 struct stop_reply
*stop_reply
= (struct stop_reply
*) event
;
5223 putpkt ((char *) self
->ack_command
);
5225 if (stop_reply
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
5226 /* We got an unknown stop reply. */
5227 error (_("Unknown stop reply"));
5229 push_stop_reply (stop_reply
);
5233 remote_notif_stop_can_get_pending_events (struct notif_client
*self
)
5235 /* We can't get pending events in remote_notif_process for
5236 notification stop, and we have to do this in remote_wait_ns
5237 instead. If we fetch all queued events from stub, remote stub
5238 may exit and we have no chance to process them back in
5240 mark_async_event_handler (remote_async_inferior_event_token
);
5245 stop_reply_dtr (struct notif_event
*event
)
5247 struct stop_reply
*r
= (struct stop_reply
*) event
;
5249 VEC_free (cached_reg_t
, r
->regcache
);
5252 static struct notif_event
*
5253 remote_notif_stop_alloc_reply (void)
5255 struct notif_event
*r
5256 = (struct notif_event
*) XMALLOC (struct stop_reply
);
5258 r
->dtr
= stop_reply_dtr
;
5263 /* A client of notification Stop. */
5265 struct notif_client notif_client_stop
=
5269 remote_notif_stop_parse
,
5270 remote_notif_stop_ack
,
5271 remote_notif_stop_can_get_pending_events
,
5272 remote_notif_stop_alloc_reply
,
5276 /* A parameter to pass data in and out. */
5278 struct queue_iter_param
5281 struct stop_reply
*output
;
5284 /* Remove all queue elements meet the condition it checks. */
5287 remote_notif_remove_all (QUEUE (stop_reply_p
) *q
,
5288 QUEUE_ITER (stop_reply_p
) *iter
,
5292 struct queue_iter_param
*param
= data
;
5293 struct inferior
*inf
= param
->input
;
5295 if (inf
== NULL
|| ptid_get_pid (event
->ptid
) == inf
->pid
)
5297 stop_reply_xfree (event
);
5298 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5304 /* Discard all pending stop replies of inferior INF. If INF is NULL,
5305 discard everything. */
5308 discard_pending_stop_replies (struct inferior
*inf
)
5311 struct queue_iter_param param
;
5312 struct stop_reply
*reply
5313 = (struct stop_reply
*) notif_client_stop
.pending_event
;
5315 /* Discard the in-flight notification. */
5318 || ptid_get_pid (reply
->ptid
) == inf
->pid
))
5320 stop_reply_xfree (reply
);
5321 notif_client_stop
.pending_event
= NULL
;
5325 param
.output
= NULL
;
5326 /* Discard the stop replies we have already pulled with
5328 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5329 remote_notif_remove_all
, ¶m
);
5332 /* A parameter to pass data in and out. */
5335 remote_notif_remove_once_on_match (QUEUE (stop_reply_p
) *q
,
5336 QUEUE_ITER (stop_reply_p
) *iter
,
5340 struct queue_iter_param
*param
= data
;
5341 ptid_t
*ptid
= param
->input
;
5343 if (ptid_match (event
->ptid
, *ptid
))
5345 param
->output
= event
;
5346 QUEUE_remove_elem (stop_reply_p
, q
, iter
);
5353 /* Remove the first reply in 'stop_reply_queue' which matches
5356 static struct stop_reply
*
5357 remote_notif_remove_queued_reply (ptid_t ptid
)
5359 struct queue_iter_param param
;
5361 param
.input
= &ptid
;
5362 param
.output
= NULL
;
5364 QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5365 remote_notif_remove_once_on_match
, ¶m
);
5367 fprintf_unfiltered (gdb_stdlog
,
5368 "notif: discard queued event: 'Stop' in %s\n",
5369 target_pid_to_str (ptid
));
5371 return param
.output
;
5374 /* Look for a queued stop reply belonging to PTID. If one is found,
5375 remove it from the queue, and return it. Returns NULL if none is
5376 found. If there are still queued events left to process, tell the
5377 event loop to get back to target_wait soon. */
5379 static struct stop_reply
*
5380 queued_stop_reply (ptid_t ptid
)
5382 struct stop_reply
*r
= remote_notif_remove_queued_reply (ptid
);
5384 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5385 /* There's still at least an event left. */
5386 mark_async_event_handler (remote_async_inferior_event_token
);
5391 /* Push a fully parsed stop reply in the stop reply queue. Since we
5392 know that we now have at least one queued event left to pass to the
5393 core side, tell the event loop to get back to target_wait soon. */
5396 push_stop_reply (struct stop_reply
*new_event
)
5398 QUEUE_enque (stop_reply_p
, stop_reply_queue
, new_event
);
5401 fprintf_unfiltered (gdb_stdlog
,
5402 "notif: push 'Stop' %s to queue %d\n",
5403 target_pid_to_str (new_event
->ptid
),
5404 QUEUE_length (stop_reply_p
,
5407 mark_async_event_handler (remote_async_inferior_event_token
);
5411 stop_reply_match_ptid_and_ws (QUEUE (stop_reply_p
) *q
,
5412 QUEUE_ITER (stop_reply_p
) *iter
,
5413 struct stop_reply
*event
,
5416 ptid_t
*ptid
= data
;
5418 return !(ptid_equal (*ptid
, event
->ptid
)
5419 && event
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
5422 /* Returns true if we have a stop reply for PTID. */
5425 peek_stop_reply (ptid_t ptid
)
5427 return !QUEUE_iterate (stop_reply_p
, stop_reply_queue
,
5428 stop_reply_match_ptid_and_ws
, &ptid
);
5431 /* Parse the stop reply in BUF. Either the function succeeds, and the
5432 result is stored in EVENT, or throws an error. */
5435 remote_parse_stop_reply (char *buf
, struct stop_reply
*event
)
5437 struct remote_arch_state
*rsa
= get_remote_arch_state ();
5441 event
->ptid
= null_ptid
;
5442 event
->ws
.kind
= TARGET_WAITKIND_IGNORE
;
5443 event
->ws
.value
.integer
= 0;
5444 event
->solibs_changed
= 0;
5445 event
->replay_event
= 0;
5446 event
->stopped_by_watchpoint_p
= 0;
5447 event
->regcache
= NULL
;
5452 case 'T': /* Status with PC, SP, FP, ... */
5453 /* Expedited reply, containing Signal, {regno, reg} repeat. */
5454 /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
5456 n... = register number
5457 r... = register contents
5460 p
= &buf
[3]; /* after Txx */
5468 /* If the packet contains a register number, save it in
5469 pnum and set p1 to point to the character following it.
5470 Otherwise p1 points to p. */
5472 /* If this packet is an awatch packet, don't parse the 'a'
5473 as a register number. */
5475 if (strncmp (p
, "awatch", strlen("awatch")) != 0
5476 && strncmp (p
, "core", strlen ("core") != 0))
5478 /* Read the ``P'' register number. */
5479 pnum
= strtol (p
, &p_temp
, 16);
5485 if (p1
== p
) /* No register number present here. */
5487 p1
= strchr (p
, ':');
5489 error (_("Malformed packet(a) (missing colon): %s\n\
5492 if (strncmp (p
, "thread", p1
- p
) == 0)
5493 event
->ptid
= read_ptid (++p1
, &p
);
5494 else if ((strncmp (p
, "watch", p1
- p
) == 0)
5495 || (strncmp (p
, "rwatch", p1
- p
) == 0)
5496 || (strncmp (p
, "awatch", p1
- p
) == 0))
5498 event
->stopped_by_watchpoint_p
= 1;
5499 p
= unpack_varlen_hex (++p1
, &addr
);
5500 event
->watch_data_address
= (CORE_ADDR
) addr
;
5502 else if (strncmp (p
, "library", p1
- p
) == 0)
5506 while (*p_temp
&& *p_temp
!= ';')
5509 event
->solibs_changed
= 1;
5512 else if (strncmp (p
, "replaylog", p1
- p
) == 0)
5514 /* NO_HISTORY event.
5515 p1 will indicate "begin" or "end", but
5516 it makes no difference for now, so ignore it. */
5517 event
->replay_event
= 1;
5518 p_temp
= strchr (p1
+ 1, ';');
5522 else if (strncmp (p
, "core", p1
- p
) == 0)
5526 p
= unpack_varlen_hex (++p1
, &c
);
5531 /* Silently skip unknown optional info. */
5532 p_temp
= strchr (p1
+ 1, ';');
5539 struct packet_reg
*reg
= packet_reg_from_pnum (rsa
, pnum
);
5540 cached_reg_t cached_reg
;
5545 error (_("Malformed packet(b) (missing colon): %s\n\
5551 error (_("Remote sent bad register number %s: %s\n\
5553 hex_string (pnum
), p
, buf
);
5555 cached_reg
.num
= reg
->regnum
;
5557 fieldsize
= hex2bin (p
, cached_reg
.data
,
5558 register_size (target_gdbarch (),
5561 if (fieldsize
< register_size (target_gdbarch (),
5563 warning (_("Remote reply is too short: %s"), buf
);
5565 VEC_safe_push (cached_reg_t
, event
->regcache
, &cached_reg
);
5569 error (_("Remote register badly formatted: %s\nhere: %s"),
5574 case 'S': /* Old style status, just signal only. */
5575 if (event
->solibs_changed
)
5576 event
->ws
.kind
= TARGET_WAITKIND_LOADED
;
5577 else if (event
->replay_event
)
5578 event
->ws
.kind
= TARGET_WAITKIND_NO_HISTORY
;
5581 event
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
5582 event
->ws
.value
.sig
= (enum gdb_signal
)
5583 (((fromhex (buf
[1])) << 4) + (fromhex (buf
[2])));
5586 case 'W': /* Target exited. */
5593 /* GDB used to accept only 2 hex chars here. Stubs should
5594 only send more if they detect GDB supports multi-process
5596 p
= unpack_varlen_hex (&buf
[1], &value
);
5600 /* The remote process exited. */
5601 event
->ws
.kind
= TARGET_WAITKIND_EXITED
;
5602 event
->ws
.value
.integer
= value
;
5606 /* The remote process exited with a signal. */
5607 event
->ws
.kind
= TARGET_WAITKIND_SIGNALLED
;
5608 event
->ws
.value
.sig
= (enum gdb_signal
) value
;
5611 /* If no process is specified, assume inferior_ptid. */
5612 pid
= ptid_get_pid (inferior_ptid
);
5621 else if (strncmp (p
,
5622 "process:", sizeof ("process:") - 1) == 0)
5626 p
+= sizeof ("process:") - 1;
5627 unpack_varlen_hex (p
, &upid
);
5631 error (_("unknown stop reply packet: %s"), buf
);
5634 error (_("unknown stop reply packet: %s"), buf
);
5635 event
->ptid
= pid_to_ptid (pid
);
5640 if (non_stop
&& ptid_equal (event
->ptid
, null_ptid
))
5641 error (_("No process or thread specified in stop reply: %s"), buf
);
5644 /* When the stub wants to tell GDB about a new notification reply, it
5645 sends a notification (%Stop, for example). Those can come it at
5646 any time, hence, we have to make sure that any pending
5647 putpkt/getpkt sequence we're making is finished, before querying
5648 the stub for more events with the corresponding ack command
5649 (vStopped, for example). E.g., if we started a vStopped sequence
5650 immediately upon receiving the notification, something like this
5658 1.6) <-- (registers reply to step #1.3)
5660 Obviously, the reply in step #1.6 would be unexpected to a vStopped
5663 To solve this, whenever we parse a %Stop notification successfully,
5664 we mark the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN, and carry on
5665 doing whatever we were doing:
5671 <GDB marks the REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN>
5672 2.5) <-- (registers reply to step #2.3)
5674 Eventualy after step #2.5, we return to the event loop, which
5675 notices there's an event on the
5676 REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN event and calls the
5677 associated callback --- the function below. At this point, we're
5678 always safe to start a vStopped sequence. :
5681 2.7) <-- T05 thread:2
5687 remote_notif_get_pending_events (struct notif_client
*nc
)
5689 struct remote_state
*rs
= get_remote_state ();
5691 if (nc
->pending_event
)
5694 fprintf_unfiltered (gdb_stdlog
,
5695 "notif: process: '%s' ack pending event\n",
5699 nc
->ack (nc
, rs
->buf
, nc
->pending_event
);
5700 nc
->pending_event
= NULL
;
5704 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
5705 if (strcmp (rs
->buf
, "OK") == 0)
5708 remote_notif_ack (nc
, rs
->buf
);
5714 fprintf_unfiltered (gdb_stdlog
,
5715 "notif: process: '%s' no pending reply\n",
5720 /* Called when it is decided that STOP_REPLY holds the info of the
5721 event that is to be returned to the core. This function always
5722 destroys STOP_REPLY. */
5725 process_stop_reply (struct stop_reply
*stop_reply
,
5726 struct target_waitstatus
*status
)
5730 *status
= stop_reply
->ws
;
5731 ptid
= stop_reply
->ptid
;
5733 /* If no thread/process was reported by the stub, assume the current
5735 if (ptid_equal (ptid
, null_ptid
))
5736 ptid
= inferior_ptid
;
5738 if (status
->kind
!= TARGET_WAITKIND_EXITED
5739 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5741 /* Expedited registers. */
5742 if (stop_reply
->regcache
)
5744 struct regcache
*regcache
5745 = get_thread_arch_regcache (ptid
, target_gdbarch ());
5750 VEC_iterate(cached_reg_t
, stop_reply
->regcache
, ix
, reg
);
5752 regcache_raw_supply (regcache
, reg
->num
, reg
->data
);
5753 VEC_free (cached_reg_t
, stop_reply
->regcache
);
5756 remote_stopped_by_watchpoint_p
= stop_reply
->stopped_by_watchpoint_p
;
5757 remote_watch_data_address
= stop_reply
->watch_data_address
;
5759 remote_notice_new_inferior (ptid
, 0);
5760 demand_private_info (ptid
)->core
= stop_reply
->core
;
5763 stop_reply_xfree (stop_reply
);
5767 /* The non-stop mode version of target_wait. */
5770 remote_wait_ns (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5772 struct remote_state
*rs
= get_remote_state ();
5773 struct stop_reply
*stop_reply
;
5777 /* If in non-stop mode, get out of getpkt even if a
5778 notification is received. */
5780 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5781 0 /* forever */, &is_notif
);
5784 if (ret
!= -1 && !is_notif
)
5787 case 'E': /* Error of some sort. */
5788 /* We're out of sync with the target now. Did it continue
5789 or not? We can't tell which thread it was in non-stop,
5790 so just ignore this. */
5791 warning (_("Remote failure reply: %s"), rs
->buf
);
5793 case 'O': /* Console output. */
5794 remote_console_output (rs
->buf
+ 1);
5797 warning (_("Invalid remote reply: %s"), rs
->buf
);
5801 /* Acknowledge a pending stop reply that may have arrived in the
5803 if (notif_client_stop
.pending_event
!= NULL
)
5804 remote_notif_get_pending_events (¬if_client_stop
);
5806 /* If indeed we noticed a stop reply, we're done. */
5807 stop_reply
= queued_stop_reply (ptid
);
5808 if (stop_reply
!= NULL
)
5809 return process_stop_reply (stop_reply
, status
);
5811 /* Still no event. If we're just polling for an event, then
5812 return to the event loop. */
5813 if (options
& TARGET_WNOHANG
)
5815 status
->kind
= TARGET_WAITKIND_IGNORE
;
5816 return minus_one_ptid
;
5819 /* Otherwise do a blocking wait. */
5820 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5821 1 /* forever */, &is_notif
);
5825 /* Wait until the remote machine stops, then return, storing status in
5826 STATUS just as `wait' would. */
5829 remote_wait_as (ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5831 struct remote_state
*rs
= get_remote_state ();
5832 ptid_t event_ptid
= null_ptid
;
5834 struct stop_reply
*stop_reply
;
5838 status
->kind
= TARGET_WAITKIND_IGNORE
;
5839 status
->value
.integer
= 0;
5841 stop_reply
= queued_stop_reply (ptid
);
5842 if (stop_reply
!= NULL
)
5843 return process_stop_reply (stop_reply
, status
);
5845 if (rs
->cached_wait_status
)
5846 /* Use the cached wait status, but only once. */
5847 rs
->cached_wait_status
= 0;
5853 if (!target_is_async_p ())
5855 ofunc
= signal (SIGINT
, remote_interrupt
);
5856 /* If the user hit C-c before this packet, or between packets,
5857 pretend that it was hit right here. */
5858 if (check_quit_flag ())
5861 remote_interrupt (SIGINT
);
5865 /* FIXME: cagney/1999-09-27: If we're in async mode we should
5866 _never_ wait for ever -> test on target_is_async_p().
5867 However, before we do that we need to ensure that the caller
5868 knows how to take the target into/out of async mode. */
5869 ret
= getpkt_or_notif_sane (&rs
->buf
, &rs
->buf_size
,
5870 wait_forever_enabled_p
, &is_notif
);
5872 /* GDB gets a notification. Return to core as this event is
5874 if (ret
!= -1 && is_notif
)
5875 return minus_one_ptid
;
5877 if (!target_is_async_p ())
5878 signal (SIGINT
, ofunc
);
5883 remote_stopped_by_watchpoint_p
= 0;
5885 /* We got something. */
5886 rs
->waiting_for_stop_reply
= 0;
5888 /* Assume that the target has acknowledged Ctrl-C unless we receive
5889 an 'F' or 'O' packet. */
5890 if (buf
[0] != 'F' && buf
[0] != 'O')
5891 rs
->ctrlc_pending_p
= 0;
5895 case 'E': /* Error of some sort. */
5896 /* We're out of sync with the target now. Did it continue or
5897 not? Not is more likely, so report a stop. */
5898 warning (_("Remote failure reply: %s"), buf
);
5899 status
->kind
= TARGET_WAITKIND_STOPPED
;
5900 status
->value
.sig
= GDB_SIGNAL_0
;
5902 case 'F': /* File-I/O request. */
5903 remote_fileio_request (buf
, rs
->ctrlc_pending_p
);
5904 rs
->ctrlc_pending_p
= 0;
5906 case 'T': case 'S': case 'X': case 'W':
5908 struct stop_reply
*stop_reply
5909 = (struct stop_reply
*) remote_notif_parse (¬if_client_stop
,
5912 event_ptid
= process_stop_reply (stop_reply
, status
);
5915 case 'O': /* Console output. */
5916 remote_console_output (buf
+ 1);
5918 /* The target didn't really stop; keep waiting. */
5919 rs
->waiting_for_stop_reply
= 1;
5923 if (last_sent_signal
!= GDB_SIGNAL_0
)
5925 /* Zero length reply means that we tried 'S' or 'C' and the
5926 remote system doesn't support it. */
5927 target_terminal_ours_for_output ();
5929 ("Can't send signals to this remote system. %s not sent.\n",
5930 gdb_signal_to_name (last_sent_signal
));
5931 last_sent_signal
= GDB_SIGNAL_0
;
5932 target_terminal_inferior ();
5934 strcpy ((char *) buf
, last_sent_step
? "s" : "c");
5935 putpkt ((char *) buf
);
5937 /* We just told the target to resume, so a stop reply is in
5939 rs
->waiting_for_stop_reply
= 1;
5942 /* else fallthrough */
5944 warning (_("Invalid remote reply: %s"), buf
);
5946 rs
->waiting_for_stop_reply
= 1;
5950 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
5952 /* Nothing interesting happened. If we're doing a non-blocking
5953 poll, we're done. Otherwise, go back to waiting. */
5954 if (options
& TARGET_WNOHANG
)
5955 return minus_one_ptid
;
5959 else if (status
->kind
!= TARGET_WAITKIND_EXITED
5960 && status
->kind
!= TARGET_WAITKIND_SIGNALLED
)
5962 if (!ptid_equal (event_ptid
, null_ptid
))
5963 record_currthread (event_ptid
);
5965 event_ptid
= inferior_ptid
;
5968 /* A process exit. Invalidate our notion of current thread. */
5969 record_currthread (minus_one_ptid
);
5974 /* Wait until the remote machine stops, then return, storing status in
5975 STATUS just as `wait' would. */
5978 remote_wait (struct target_ops
*ops
,
5979 ptid_t ptid
, struct target_waitstatus
*status
, int options
)
5984 event_ptid
= remote_wait_ns (ptid
, status
, options
);
5986 event_ptid
= remote_wait_as (ptid
, status
, options
);
5988 if (target_can_async_p ())
5990 /* If there are are events left in the queue tell the event loop
5992 if (!QUEUE_is_empty (stop_reply_p
, stop_reply_queue
))
5993 mark_async_event_handler (remote_async_inferior_event_token
);
5999 /* Fetch a single register using a 'p' packet. */
6002 fetch_register_using_p (struct regcache
*regcache
, struct packet_reg
*reg
)
6004 struct remote_state
*rs
= get_remote_state ();
6006 char regp
[MAX_REGISTER_SIZE
];
6009 if (remote_protocol_packets
[PACKET_p
].support
== PACKET_DISABLE
)
6012 if (reg
->pnum
== -1)
6017 p
+= hexnumstr (p
, reg
->pnum
);
6020 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6024 switch (packet_ok (buf
, &remote_protocol_packets
[PACKET_p
]))
6028 case PACKET_UNKNOWN
:
6031 error (_("Could not fetch register \"%s\"; remote failure reply '%s'"),
6032 gdbarch_register_name (get_regcache_arch (regcache
),
6037 /* If this register is unfetchable, tell the regcache. */
6040 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6044 /* Otherwise, parse and supply the value. */
6050 error (_("fetch_register_using_p: early buf termination"));
6052 regp
[i
++] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6055 regcache_raw_supply (regcache
, reg
->regnum
, regp
);
6059 /* Fetch the registers included in the target's 'g' packet. */
6062 send_g_packet (void)
6064 struct remote_state
*rs
= get_remote_state ();
6067 xsnprintf (rs
->buf
, get_remote_packet_size (), "g");
6068 remote_send (&rs
->buf
, &rs
->buf_size
);
6070 /* We can get out of synch in various cases. If the first character
6071 in the buffer is not a hex character, assume that has happened
6072 and try to fetch another packet to read. */
6073 while ((rs
->buf
[0] < '0' || rs
->buf
[0] > '9')
6074 && (rs
->buf
[0] < 'A' || rs
->buf
[0] > 'F')
6075 && (rs
->buf
[0] < 'a' || rs
->buf
[0] > 'f')
6076 && rs
->buf
[0] != 'x') /* New: unavailable register value. */
6079 fprintf_unfiltered (gdb_stdlog
,
6080 "Bad register packet; fetching a new packet\n");
6081 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6084 buf_len
= strlen (rs
->buf
);
6086 /* Sanity check the received packet. */
6087 if (buf_len
% 2 != 0)
6088 error (_("Remote 'g' packet reply is of odd length: %s"), rs
->buf
);
6094 process_g_packet (struct regcache
*regcache
)
6096 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6097 struct remote_state
*rs
= get_remote_state ();
6098 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6103 buf_len
= strlen (rs
->buf
);
6105 /* Further sanity checks, with knowledge of the architecture. */
6106 if (buf_len
> 2 * rsa
->sizeof_g_packet
)
6107 error (_("Remote 'g' packet reply is too long: %s"), rs
->buf
);
6109 /* Save the size of the packet sent to us by the target. It is used
6110 as a heuristic when determining the max size of packets that the
6111 target can safely receive. */
6112 if (rsa
->actual_register_packet_size
== 0)
6113 rsa
->actual_register_packet_size
= buf_len
;
6115 /* If this is smaller than we guessed the 'g' packet would be,
6116 update our records. A 'g' reply that doesn't include a register's
6117 value implies either that the register is not available, or that
6118 the 'p' packet must be used. */
6119 if (buf_len
< 2 * rsa
->sizeof_g_packet
)
6121 rsa
->sizeof_g_packet
= buf_len
/ 2;
6123 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6125 if (rsa
->regs
[i
].pnum
== -1)
6128 if (rsa
->regs
[i
].offset
>= rsa
->sizeof_g_packet
)
6129 rsa
->regs
[i
].in_g_packet
= 0;
6131 rsa
->regs
[i
].in_g_packet
= 1;
6135 regs
= alloca (rsa
->sizeof_g_packet
);
6137 /* Unimplemented registers read as all bits zero. */
6138 memset (regs
, 0, rsa
->sizeof_g_packet
);
6140 /* Reply describes registers byte by byte, each byte encoded as two
6141 hex characters. Suck them all up, then supply them to the
6142 register cacheing/storage mechanism. */
6145 for (i
= 0; i
< rsa
->sizeof_g_packet
; i
++)
6147 if (p
[0] == 0 || p
[1] == 0)
6148 /* This shouldn't happen - we adjusted sizeof_g_packet above. */
6149 internal_error (__FILE__
, __LINE__
,
6150 _("unexpected end of 'g' packet reply"));
6152 if (p
[0] == 'x' && p
[1] == 'x')
6153 regs
[i
] = 0; /* 'x' */
6155 regs
[i
] = fromhex (p
[0]) * 16 + fromhex (p
[1]);
6159 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
6161 struct packet_reg
*r
= &rsa
->regs
[i
];
6165 if (r
->offset
* 2 >= strlen (rs
->buf
))
6166 /* This shouldn't happen - we adjusted in_g_packet above. */
6167 internal_error (__FILE__
, __LINE__
,
6168 _("unexpected end of 'g' packet reply"));
6169 else if (rs
->buf
[r
->offset
* 2] == 'x')
6171 gdb_assert (r
->offset
* 2 < strlen (rs
->buf
));
6172 /* The register isn't available, mark it as such (at
6173 the same time setting the value to zero). */
6174 regcache_raw_supply (regcache
, r
->regnum
, NULL
);
6177 regcache_raw_supply (regcache
, r
->regnum
,
6184 fetch_registers_using_g (struct regcache
*regcache
)
6187 process_g_packet (regcache
);
6190 /* Make the remote selected traceframe match GDB's selected
6194 set_remote_traceframe (void)
6198 if (remote_traceframe_number
== get_traceframe_number ())
6201 /* Avoid recursion, remote_trace_find calls us again. */
6202 remote_traceframe_number
= get_traceframe_number ();
6204 newnum
= target_trace_find (tfind_number
,
6205 get_traceframe_number (), 0, 0, NULL
);
6207 /* Should not happen. If it does, all bets are off. */
6208 if (newnum
!= get_traceframe_number ())
6209 warning (_("could not set remote traceframe"));
6213 remote_fetch_registers (struct target_ops
*ops
,
6214 struct regcache
*regcache
, int regnum
)
6216 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6219 set_remote_traceframe ();
6220 set_general_thread (inferior_ptid
);
6224 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6226 gdb_assert (reg
!= NULL
);
6228 /* If this register might be in the 'g' packet, try that first -
6229 we are likely to read more than one register. If this is the
6230 first 'g' packet, we might be overly optimistic about its
6231 contents, so fall back to 'p'. */
6232 if (reg
->in_g_packet
)
6234 fetch_registers_using_g (regcache
);
6235 if (reg
->in_g_packet
)
6239 if (fetch_register_using_p (regcache
, reg
))
6242 /* This register is not available. */
6243 regcache_raw_supply (regcache
, reg
->regnum
, NULL
);
6248 fetch_registers_using_g (regcache
);
6250 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6251 if (!rsa
->regs
[i
].in_g_packet
)
6252 if (!fetch_register_using_p (regcache
, &rsa
->regs
[i
]))
6254 /* This register is not available. */
6255 regcache_raw_supply (regcache
, i
, NULL
);
6259 /* Prepare to store registers. Since we may send them all (using a
6260 'G' request), we have to read out the ones we don't want to change
6264 remote_prepare_to_store (struct regcache
*regcache
)
6266 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6268 gdb_byte buf
[MAX_REGISTER_SIZE
];
6270 /* Make sure the entire registers array is valid. */
6271 switch (remote_protocol_packets
[PACKET_P
].support
)
6273 case PACKET_DISABLE
:
6274 case PACKET_SUPPORT_UNKNOWN
:
6275 /* Make sure all the necessary registers are cached. */
6276 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6277 if (rsa
->regs
[i
].in_g_packet
)
6278 regcache_raw_read (regcache
, rsa
->regs
[i
].regnum
, buf
);
6285 /* Helper: Attempt to store REGNUM using the P packet. Return fail IFF
6286 packet was not recognized. */
6289 store_register_using_P (const struct regcache
*regcache
,
6290 struct packet_reg
*reg
)
6292 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6293 struct remote_state
*rs
= get_remote_state ();
6294 /* Try storing a single register. */
6295 char *buf
= rs
->buf
;
6296 gdb_byte regp
[MAX_REGISTER_SIZE
];
6299 if (remote_protocol_packets
[PACKET_P
].support
== PACKET_DISABLE
)
6302 if (reg
->pnum
== -1)
6305 xsnprintf (buf
, get_remote_packet_size (), "P%s=", phex_nz (reg
->pnum
, 0));
6306 p
= buf
+ strlen (buf
);
6307 regcache_raw_collect (regcache
, reg
->regnum
, regp
);
6308 bin2hex (regp
, p
, register_size (gdbarch
, reg
->regnum
));
6310 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6312 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_P
]))
6317 error (_("Could not write register \"%s\"; remote failure reply '%s'"),
6318 gdbarch_register_name (gdbarch
, reg
->regnum
), rs
->buf
);
6319 case PACKET_UNKNOWN
:
6322 internal_error (__FILE__
, __LINE__
, _("Bad result from packet_ok"));
6326 /* Store register REGNUM, or all registers if REGNUM == -1, from the
6327 contents of the register cache buffer. FIXME: ignores errors. */
6330 store_registers_using_G (const struct regcache
*regcache
)
6332 struct remote_state
*rs
= get_remote_state ();
6333 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6337 /* Extract all the registers in the regcache copying them into a
6342 regs
= alloca (rsa
->sizeof_g_packet
);
6343 memset (regs
, 0, rsa
->sizeof_g_packet
);
6344 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6346 struct packet_reg
*r
= &rsa
->regs
[i
];
6349 regcache_raw_collect (regcache
, r
->regnum
, regs
+ r
->offset
);
6353 /* Command describes registers byte by byte,
6354 each byte encoded as two hex characters. */
6357 /* remote_prepare_to_store insures that rsa->sizeof_g_packet gets
6359 bin2hex (regs
, p
, rsa
->sizeof_g_packet
);
6361 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6362 if (packet_check_result (rs
->buf
) == PACKET_ERROR
)
6363 error (_("Could not write registers; remote failure reply '%s'"),
6367 /* Store register REGNUM, or all registers if REGNUM == -1, from the contents
6368 of the register cache buffer. FIXME: ignores errors. */
6371 remote_store_registers (struct target_ops
*ops
,
6372 struct regcache
*regcache
, int regnum
)
6374 struct remote_arch_state
*rsa
= get_remote_arch_state ();
6377 set_remote_traceframe ();
6378 set_general_thread (inferior_ptid
);
6382 struct packet_reg
*reg
= packet_reg_from_regnum (rsa
, regnum
);
6384 gdb_assert (reg
!= NULL
);
6386 /* Always prefer to store registers using the 'P' packet if
6387 possible; we often change only a small number of registers.
6388 Sometimes we change a larger number; we'd need help from a
6389 higher layer to know to use 'G'. */
6390 if (store_register_using_P (regcache
, reg
))
6393 /* For now, don't complain if we have no way to write the
6394 register. GDB loses track of unavailable registers too
6395 easily. Some day, this may be an error. We don't have
6396 any way to read the register, either... */
6397 if (!reg
->in_g_packet
)
6400 store_registers_using_G (regcache
);
6404 store_registers_using_G (regcache
);
6406 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
6407 if (!rsa
->regs
[i
].in_g_packet
)
6408 if (!store_register_using_P (regcache
, &rsa
->regs
[i
]))
6409 /* See above for why we do not issue an error here. */
6414 /* Return the number of hex digits in num. */
6417 hexnumlen (ULONGEST num
)
6421 for (i
= 0; num
!= 0; i
++)
6427 /* Set BUF to the minimum number of hex digits representing NUM. */
6430 hexnumstr (char *buf
, ULONGEST num
)
6432 int len
= hexnumlen (num
);
6434 return hexnumnstr (buf
, num
, len
);
6438 /* Set BUF to the hex digits representing NUM, padded to WIDTH characters. */
6441 hexnumnstr (char *buf
, ULONGEST num
, int width
)
6447 for (i
= width
- 1; i
>= 0; i
--)
6449 buf
[i
] = "0123456789abcdef"[(num
& 0xf)];
6456 /* Mask all but the least significant REMOTE_ADDRESS_SIZE bits. */
6459 remote_address_masked (CORE_ADDR addr
)
6461 unsigned int address_size
= remote_address_size
;
6463 /* If "remoteaddresssize" was not set, default to target address size. */
6465 address_size
= gdbarch_addr_bit (target_gdbarch ());
6467 if (address_size
> 0
6468 && address_size
< (sizeof (ULONGEST
) * 8))
6470 /* Only create a mask when that mask can safely be constructed
6471 in a ULONGEST variable. */
6474 mask
= (mask
<< address_size
) - 1;
6480 /* Convert BUFFER, binary data at least LEN bytes long, into escaped
6481 binary data in OUT_BUF. Set *OUT_LEN to the length of the data
6482 encoded in OUT_BUF, and return the number of bytes in OUT_BUF
6483 (which may be more than *OUT_LEN due to escape characters). The
6484 total number of bytes in the output buffer will be at most
6488 remote_escape_output (const gdb_byte
*buffer
, int len
,
6489 gdb_byte
*out_buf
, int *out_len
,
6492 int input_index
, output_index
;
6495 for (input_index
= 0; input_index
< len
; input_index
++)
6497 gdb_byte b
= buffer
[input_index
];
6499 if (b
== '$' || b
== '#' || b
== '}')
6501 /* These must be escaped. */
6502 if (output_index
+ 2 > out_maxlen
)
6504 out_buf
[output_index
++] = '}';
6505 out_buf
[output_index
++] = b
^ 0x20;
6509 if (output_index
+ 1 > out_maxlen
)
6511 out_buf
[output_index
++] = b
;
6515 *out_len
= input_index
;
6516 return output_index
;
6519 /* Convert BUFFER, escaped data LEN bytes long, into binary data
6520 in OUT_BUF. Return the number of bytes written to OUT_BUF.
6521 Raise an error if the total number of bytes exceeds OUT_MAXLEN.
6523 This function reverses remote_escape_output. It allows more
6524 escaped characters than that function does, in particular because
6525 '*' must be escaped to avoid the run-length encoding processing
6526 in reading packets. */
6529 remote_unescape_input (const gdb_byte
*buffer
, int len
,
6530 gdb_byte
*out_buf
, int out_maxlen
)
6532 int input_index
, output_index
;
6537 for (input_index
= 0; input_index
< len
; input_index
++)
6539 gdb_byte b
= buffer
[input_index
];
6541 if (output_index
+ 1 > out_maxlen
)
6543 warning (_("Received too much data from remote target;"
6544 " ignoring overflow."));
6545 return output_index
;
6550 out_buf
[output_index
++] = b
^ 0x20;
6556 out_buf
[output_index
++] = b
;
6560 error (_("Unmatched escape character in target response."));
6562 return output_index
;
6565 /* Determine whether the remote target supports binary downloading.
6566 This is accomplished by sending a no-op memory write of zero length
6567 to the target at the specified address. It does not suffice to send
6568 the whole packet, since many stubs strip the eighth bit and
6569 subsequently compute a wrong checksum, which causes real havoc with
6572 NOTE: This can still lose if the serial line is not eight-bit
6573 clean. In cases like this, the user should clear "remote
6577 check_binary_download (CORE_ADDR addr
)
6579 struct remote_state
*rs
= get_remote_state ();
6581 switch (remote_protocol_packets
[PACKET_X
].support
)
6583 case PACKET_DISABLE
:
6587 case PACKET_SUPPORT_UNKNOWN
:
6593 p
+= hexnumstr (p
, (ULONGEST
) addr
);
6595 p
+= hexnumstr (p
, (ULONGEST
) 0);
6599 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6600 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6602 if (rs
->buf
[0] == '\0')
6605 fprintf_unfiltered (gdb_stdlog
,
6606 "binary downloading NOT "
6607 "supported by target\n");
6608 remote_protocol_packets
[PACKET_X
].support
= PACKET_DISABLE
;
6613 fprintf_unfiltered (gdb_stdlog
,
6614 "binary downloading supported by target\n");
6615 remote_protocol_packets
[PACKET_X
].support
= PACKET_ENABLE
;
6622 /* Write memory data directly to the remote machine.
6623 This does not inform the data cache; the data cache uses this.
6624 HEADER is the starting part of the packet.
6625 MEMADDR is the address in the remote memory space.
6626 MYADDR is the address of the buffer in our space.
6627 LEN is the number of bytes.
6628 PACKET_FORMAT should be either 'X' or 'M', and indicates if we
6629 should send data as binary ('X'), or hex-encoded ('M').
6631 The function creates packet of the form
6632 <HEADER><ADDRESS>,<LENGTH>:<DATA>
6634 where encoding of <DATA> is termined by PACKET_FORMAT.
6636 If USE_LENGTH is 0, then the <LENGTH> field and the preceding comma
6639 Returns the number of bytes transferred, or 0 (setting errno) for
6640 error. Only transfer a single packet. */
6643 remote_write_bytes_aux (const char *header
, CORE_ADDR memaddr
,
6644 const gdb_byte
*myaddr
, ssize_t len
,
6645 char packet_format
, int use_length
)
6647 struct remote_state
*rs
= get_remote_state ();
6657 if (packet_format
!= 'X' && packet_format
!= 'M')
6658 internal_error (__FILE__
, __LINE__
,
6659 _("remote_write_bytes_aux: bad packet format"));
6664 payload_size
= get_memory_write_packet_size ();
6666 /* The packet buffer will be large enough for the payload;
6667 get_memory_packet_size ensures this. */
6670 /* Compute the size of the actual payload by subtracting out the
6671 packet header and footer overhead: "$M<memaddr>,<len>:...#nn". */
6673 payload_size
-= strlen ("$,:#NN");
6675 /* The comma won't be used. */
6677 header_length
= strlen (header
);
6678 payload_size
-= header_length
;
6679 payload_size
-= hexnumlen (memaddr
);
6681 /* Construct the packet excluding the data: "<header><memaddr>,<len>:". */
6683 strcat (rs
->buf
, header
);
6684 p
= rs
->buf
+ strlen (header
);
6686 /* Compute a best guess of the number of bytes actually transfered. */
6687 if (packet_format
== 'X')
6689 /* Best guess at number of bytes that will fit. */
6690 todo
= min (len
, payload_size
);
6692 payload_size
-= hexnumlen (todo
);
6693 todo
= min (todo
, payload_size
);
6697 /* Num bytes that will fit. */
6698 todo
= min (len
, payload_size
/ 2);
6700 payload_size
-= hexnumlen (todo
);
6701 todo
= min (todo
, payload_size
/ 2);
6705 internal_error (__FILE__
, __LINE__
,
6706 _("minimum packet size too small to write data"));
6708 /* If we already need another packet, then try to align the end
6709 of this packet to a useful boundary. */
6710 if (todo
> 2 * REMOTE_ALIGN_WRITES
&& todo
< len
)
6711 todo
= ((memaddr
+ todo
) & ~(REMOTE_ALIGN_WRITES
- 1)) - memaddr
;
6713 /* Append "<memaddr>". */
6714 memaddr
= remote_address_masked (memaddr
);
6715 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6722 /* Append <len>. Retain the location/size of <len>. It may need to
6723 be adjusted once the packet body has been created. */
6725 plenlen
= hexnumstr (p
, (ULONGEST
) todo
);
6733 /* Append the packet body. */
6734 if (packet_format
== 'X')
6736 /* Binary mode. Send target system values byte by byte, in
6737 increasing byte addresses. Only escape certain critical
6739 payload_length
= remote_escape_output (myaddr
, todo
, p
, &nr_bytes
,
6742 /* If not all TODO bytes fit, then we'll need another packet. Make
6743 a second try to keep the end of the packet aligned. Don't do
6744 this if the packet is tiny. */
6745 if (nr_bytes
< todo
&& nr_bytes
> 2 * REMOTE_ALIGN_WRITES
)
6749 new_nr_bytes
= (((memaddr
+ nr_bytes
) & ~(REMOTE_ALIGN_WRITES
- 1))
6751 if (new_nr_bytes
!= nr_bytes
)
6752 payload_length
= remote_escape_output (myaddr
, new_nr_bytes
,
6757 p
+= payload_length
;
6758 if (use_length
&& nr_bytes
< todo
)
6760 /* Escape chars have filled up the buffer prematurely,
6761 and we have actually sent fewer bytes than planned.
6762 Fix-up the length field of the packet. Use the same
6763 number of characters as before. */
6764 plen
+= hexnumnstr (plen
, (ULONGEST
) nr_bytes
, plenlen
);
6765 *plen
= ':'; /* overwrite \0 from hexnumnstr() */
6770 /* Normal mode: Send target system values byte by byte, in
6771 increasing byte addresses. Each byte is encoded as a two hex
6773 nr_bytes
= bin2hex (myaddr
, p
, todo
);
6777 putpkt_binary (rs
->buf
, (int) (p
- rs
->buf
));
6778 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6780 if (rs
->buf
[0] == 'E')
6782 /* There is no correspondance between what the remote protocol
6783 uses for errors and errno codes. We would like a cleaner way
6784 of representing errors (big enough to include errno codes,
6785 bfd_error codes, and others). But for now just return EIO. */
6790 /* Return NR_BYTES, not TODO, in case escape chars caused us to send
6791 fewer bytes than we'd planned. */
6795 /* Write memory data directly to the remote machine.
6796 This does not inform the data cache; the data cache uses this.
6797 MEMADDR is the address in the remote memory space.
6798 MYADDR is the address of the buffer in our space.
6799 LEN is the number of bytes.
6801 Returns number of bytes transferred, or 0 (setting errno) for
6802 error. Only transfer a single packet. */
6805 remote_write_bytes (CORE_ADDR memaddr
, const gdb_byte
*myaddr
, ssize_t len
)
6807 char *packet_format
= 0;
6809 /* Check whether the target supports binary download. */
6810 check_binary_download (memaddr
);
6812 switch (remote_protocol_packets
[PACKET_X
].support
)
6815 packet_format
= "X";
6817 case PACKET_DISABLE
:
6818 packet_format
= "M";
6820 case PACKET_SUPPORT_UNKNOWN
:
6821 internal_error (__FILE__
, __LINE__
,
6822 _("remote_write_bytes: bad internal state"));
6824 internal_error (__FILE__
, __LINE__
, _("bad switch"));
6827 return remote_write_bytes_aux (packet_format
,
6828 memaddr
, myaddr
, len
, packet_format
[0], 1);
6831 /* Read memory data directly from the remote machine.
6832 This does not use the data cache; the data cache uses this.
6833 MEMADDR is the address in the remote memory space.
6834 MYADDR is the address of the buffer in our space.
6835 LEN is the number of bytes.
6837 Returns number of bytes transferred, or 0 for error. */
6840 remote_read_bytes (CORE_ADDR memaddr
, gdb_byte
*myaddr
, int len
)
6842 struct remote_state
*rs
= get_remote_state ();
6843 int max_buf_size
; /* Max size of packet output buffer. */
6851 max_buf_size
= get_memory_read_packet_size ();
6852 /* The packet buffer will be large enough for the payload;
6853 get_memory_packet_size ensures this. */
6855 /* Number if bytes that will fit. */
6856 todo
= min (len
, max_buf_size
/ 2);
6858 /* Construct "m"<memaddr>","<len>". */
6859 memaddr
= remote_address_masked (memaddr
);
6862 p
+= hexnumstr (p
, (ULONGEST
) memaddr
);
6864 p
+= hexnumstr (p
, (ULONGEST
) todo
);
6867 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6868 if (rs
->buf
[0] == 'E'
6869 && isxdigit (rs
->buf
[1]) && isxdigit (rs
->buf
[2])
6870 && rs
->buf
[3] == '\0')
6872 /* There is no correspondance between what the remote protocol
6873 uses for errors and errno codes. We would like a cleaner way
6874 of representing errors (big enough to include errno codes,
6875 bfd_error codes, and others). But for now just return
6880 /* Reply describes memory byte by byte, each byte encoded as two hex
6883 i
= hex2bin (p
, myaddr
, todo
);
6884 /* Return what we have. Let higher layers handle partial reads. */
6889 /* Read or write LEN bytes from inferior memory at MEMADDR,
6890 transferring to or from debugger address BUFFER. Write to inferior
6891 if SHOULD_WRITE is nonzero. Returns length of data written or
6892 read; 0 for error. TARGET is unused. */
6895 remote_xfer_memory (CORE_ADDR mem_addr
, gdb_byte
*buffer
, int mem_len
,
6896 int should_write
, struct mem_attrib
*attrib
,
6897 struct target_ops
*target
)
6901 set_remote_traceframe ();
6902 set_general_thread (inferior_ptid
);
6905 res
= remote_write_bytes (mem_addr
, buffer
, mem_len
);
6907 res
= remote_read_bytes (mem_addr
, buffer
, mem_len
);
6912 /* Sends a packet with content determined by the printf format string
6913 FORMAT and the remaining arguments, then gets the reply. Returns
6914 whether the packet was a success, a failure, or unknown. */
6916 static enum packet_result
6917 remote_send_printf (const char *format
, ...)
6919 struct remote_state
*rs
= get_remote_state ();
6920 int max_size
= get_remote_packet_size ();
6923 va_start (ap
, format
);
6926 if (vsnprintf (rs
->buf
, max_size
, format
, ap
) >= max_size
)
6927 internal_error (__FILE__
, __LINE__
, _("Too long remote packet."));
6929 if (putpkt (rs
->buf
) < 0)
6930 error (_("Communication problem with target."));
6933 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
6935 return packet_check_result (rs
->buf
);
6939 restore_remote_timeout (void *p
)
6941 int value
= *(int *)p
;
6943 remote_timeout
= value
;
6946 /* Flash writing can take quite some time. We'll set
6947 effectively infinite timeout for flash operations.
6948 In future, we'll need to decide on a better approach. */
6949 static const int remote_flash_timeout
= 1000;
6952 remote_flash_erase (struct target_ops
*ops
,
6953 ULONGEST address
, LONGEST length
)
6955 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
6956 int saved_remote_timeout
= remote_timeout
;
6957 enum packet_result ret
;
6958 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6959 &saved_remote_timeout
);
6961 remote_timeout
= remote_flash_timeout
;
6963 ret
= remote_send_printf ("vFlashErase:%s,%s",
6964 phex (address
, addr_size
),
6968 case PACKET_UNKNOWN
:
6969 error (_("Remote target does not support flash erase"));
6971 error (_("Error erasing flash with vFlashErase packet"));
6976 do_cleanups (back_to
);
6980 remote_flash_write (struct target_ops
*ops
,
6981 ULONGEST address
, LONGEST length
,
6982 const gdb_byte
*data
)
6984 int saved_remote_timeout
= remote_timeout
;
6986 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
6987 &saved_remote_timeout
);
6989 remote_timeout
= remote_flash_timeout
;
6990 ret
= remote_write_bytes_aux ("vFlashWrite:", address
, data
, length
, 'X', 0);
6991 do_cleanups (back_to
);
6997 remote_flash_done (struct target_ops
*ops
)
6999 int saved_remote_timeout
= remote_timeout
;
7001 struct cleanup
*back_to
= make_cleanup (restore_remote_timeout
,
7002 &saved_remote_timeout
);
7004 remote_timeout
= remote_flash_timeout
;
7005 ret
= remote_send_printf ("vFlashDone");
7006 do_cleanups (back_to
);
7010 case PACKET_UNKNOWN
:
7011 error (_("Remote target does not support vFlashDone"));
7013 error (_("Error finishing flash operation"));
7020 remote_files_info (struct target_ops
*ignore
)
7022 puts_filtered ("Debugging a target over a serial line.\n");
7025 /* Stuff for dealing with the packets which are part of this protocol.
7026 See comment at top of file for details. */
7028 /* Read a single character from the remote end. */
7031 readchar (int timeout
)
7035 ch
= serial_readchar (remote_desc
, timeout
);
7040 switch ((enum serial_rc
) ch
)
7044 error (_("Remote connection closed"));
7048 perror_with_name (_("Remote communication error. "
7049 "Target disconnected."));
7051 case SERIAL_TIMEOUT
:
7057 /* Send the command in *BUF to the remote machine, and read the reply
7058 into *BUF. Report an error if we get an error reply. Resize
7059 *BUF using xrealloc if necessary to hold the result, and update
7063 remote_send (char **buf
,
7067 getpkt (buf
, sizeof_buf
, 0);
7069 if ((*buf
)[0] == 'E')
7070 error (_("Remote failure reply: %s"), *buf
);
7073 /* Return a pointer to an xmalloc'ed string representing an escaped
7074 version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
7075 etc. The caller is responsible for releasing the returned
7079 escape_buffer (const char *buf
, int n
)
7081 struct cleanup
*old_chain
;
7082 struct ui_file
*stb
;
7085 stb
= mem_fileopen ();
7086 old_chain
= make_cleanup_ui_file_delete (stb
);
7088 fputstrn_unfiltered (buf
, n
, 0, stb
);
7089 str
= ui_file_xstrdup (stb
, NULL
);
7090 do_cleanups (old_chain
);
7094 /* Display a null-terminated packet on stdout, for debugging, using C
7098 print_packet (char *buf
)
7100 puts_filtered ("\"");
7101 fputstr_filtered (buf
, '"', gdb_stdout
);
7102 puts_filtered ("\"");
7108 return putpkt_binary (buf
, strlen (buf
));
7111 /* Send a packet to the remote machine, with error checking. The data
7112 of the packet is in BUF. The string in BUF can be at most
7113 get_remote_packet_size () - 5 to account for the $, # and checksum,
7114 and for a possible /0 if we are debugging (remote_debug) and want
7115 to print the sent packet as a string. */
7118 putpkt_binary (char *buf
, int cnt
)
7120 struct remote_state
*rs
= get_remote_state ();
7122 unsigned char csum
= 0;
7123 char *buf2
= alloca (cnt
+ 6);
7130 /* Catch cases like trying to read memory or listing threads while
7131 we're waiting for a stop reply. The remote server wouldn't be
7132 ready to handle this request, so we'd hang and timeout. We don't
7133 have to worry about this in synchronous mode, because in that
7134 case it's not possible to issue a command while the target is
7135 running. This is not a problem in non-stop mode, because in that
7136 case, the stub is always ready to process serial input. */
7137 if (!non_stop
&& target_can_async_p () && rs
->waiting_for_stop_reply
)
7138 error (_("Cannot execute this command while the target is running."));
7140 /* We're sending out a new packet. Make sure we don't look at a
7141 stale cached response. */
7142 rs
->cached_wait_status
= 0;
7144 /* Copy the packet into buffer BUF2, encapsulating it
7145 and giving it a checksum. */
7150 for (i
= 0; i
< cnt
; i
++)
7156 *p
++ = tohex ((csum
>> 4) & 0xf);
7157 *p
++ = tohex (csum
& 0xf);
7159 /* Send it over and over until we get a positive ack. */
7163 int started_error_output
= 0;
7167 struct cleanup
*old_chain
;
7171 str
= escape_buffer (buf2
, p
- buf2
);
7172 old_chain
= make_cleanup (xfree
, str
);
7173 fprintf_unfiltered (gdb_stdlog
, "Sending packet: %s...", str
);
7174 gdb_flush (gdb_stdlog
);
7175 do_cleanups (old_chain
);
7177 if (serial_write (remote_desc
, buf2
, p
- buf2
))
7178 perror_with_name (_("putpkt: write failed"));
7180 /* If this is a no acks version of the remote protocol, send the
7181 packet and move on. */
7185 /* Read until either a timeout occurs (-2) or '+' is read.
7186 Handle any notification that arrives in the mean time. */
7189 ch
= readchar (remote_timeout
);
7197 case SERIAL_TIMEOUT
:
7200 if (started_error_output
)
7202 putchar_unfiltered ('\n');
7203 started_error_output
= 0;
7212 fprintf_unfiltered (gdb_stdlog
, "Ack\n");
7216 fprintf_unfiltered (gdb_stdlog
, "Nak\n");
7218 case SERIAL_TIMEOUT
:
7222 break; /* Retransmit buffer. */
7226 fprintf_unfiltered (gdb_stdlog
,
7227 "Packet instead of Ack, ignoring it\n");
7228 /* It's probably an old response sent because an ACK
7229 was lost. Gobble up the packet and ack it so it
7230 doesn't get retransmitted when we resend this
7233 serial_write (remote_desc
, "+", 1);
7234 continue; /* Now, go look for +. */
7241 /* If we got a notification, handle it, and go back to looking
7243 /* We've found the start of a notification. Now
7244 collect the data. */
7245 val
= read_frame (&rs
->buf
, &rs
->buf_size
);
7250 struct cleanup
*old_chain
;
7253 str
= escape_buffer (rs
->buf
, val
);
7254 old_chain
= make_cleanup (xfree
, str
);
7255 fprintf_unfiltered (gdb_stdlog
,
7256 " Notification received: %s\n",
7258 do_cleanups (old_chain
);
7260 handle_notification (rs
->buf
);
7261 /* We're in sync now, rewait for the ack. */
7268 if (!started_error_output
)
7270 started_error_output
= 1;
7271 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7273 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7274 fprintf_unfiltered (gdb_stdlog
, "%s", rs
->buf
);
7283 if (!started_error_output
)
7285 started_error_output
= 1;
7286 fprintf_unfiltered (gdb_stdlog
, "putpkt: Junk: ");
7288 fputc_unfiltered (ch
& 0177, gdb_stdlog
);
7292 break; /* Here to retransmit. */
7296 /* This is wrong. If doing a long backtrace, the user should be
7297 able to get out next time we call QUIT, without anything as
7298 violent as interrupt_query. If we want to provide a way out of
7299 here without getting to the next QUIT, it should be based on
7300 hitting ^C twice as in remote_wait. */
7311 /* Come here after finding the start of a frame when we expected an
7312 ack. Do our best to discard the rest of this packet. */
7321 c
= readchar (remote_timeout
);
7324 case SERIAL_TIMEOUT
:
7325 /* Nothing we can do. */
7328 /* Discard the two bytes of checksum and stop. */
7329 c
= readchar (remote_timeout
);
7331 c
= readchar (remote_timeout
);
7334 case '*': /* Run length encoding. */
7335 /* Discard the repeat count. */
7336 c
= readchar (remote_timeout
);
7341 /* A regular character. */
7347 /* Come here after finding the start of the frame. Collect the rest
7348 into *BUF, verifying the checksum, length, and handling run-length
7349 compression. NUL terminate the buffer. If there is not enough room,
7350 expand *BUF using xrealloc.
7352 Returns -1 on error, number of characters in buffer (ignoring the
7353 trailing NULL) on success. (could be extended to return one of the
7354 SERIAL status indications). */
7357 read_frame (char **buf_p
,
7364 struct remote_state
*rs
= get_remote_state ();
7371 c
= readchar (remote_timeout
);
7374 case SERIAL_TIMEOUT
:
7376 fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog
);
7380 fputs_filtered ("Saw new packet start in middle of old one\n",
7382 return -1; /* Start a new packet, count retries. */
7385 unsigned char pktcsum
;
7391 check_0
= readchar (remote_timeout
);
7393 check_1
= readchar (remote_timeout
);
7395 if (check_0
== SERIAL_TIMEOUT
|| check_1
== SERIAL_TIMEOUT
)
7398 fputs_filtered ("Timeout in checksum, retrying\n",
7402 else if (check_0
< 0 || check_1
< 0)
7405 fputs_filtered ("Communication error in checksum\n",
7410 /* Don't recompute the checksum; with no ack packets we
7411 don't have any way to indicate a packet retransmission
7416 pktcsum
= (fromhex (check_0
) << 4) | fromhex (check_1
);
7417 if (csum
== pktcsum
)
7422 struct cleanup
*old_chain
;
7425 str
= escape_buffer (buf
, bc
);
7426 old_chain
= make_cleanup (xfree
, str
);
7427 fprintf_unfiltered (gdb_stdlog
,
7428 "Bad checksum, sentsum=0x%x, "
7429 "csum=0x%x, buf=%s\n",
7430 pktcsum
, csum
, str
);
7431 do_cleanups (old_chain
);
7433 /* Number of characters in buffer ignoring trailing
7437 case '*': /* Run length encoding. */
7442 c
= readchar (remote_timeout
);
7444 repeat
= c
- ' ' + 3; /* Compute repeat count. */
7446 /* The character before ``*'' is repeated. */
7448 if (repeat
> 0 && repeat
<= 255 && bc
> 0)
7450 if (bc
+ repeat
- 1 >= *sizeof_buf
- 1)
7452 /* Make some more room in the buffer. */
7453 *sizeof_buf
+= repeat
;
7454 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7458 memset (&buf
[bc
], buf
[bc
- 1], repeat
);
7464 printf_filtered (_("Invalid run length encoding: %s\n"), buf
);
7468 if (bc
>= *sizeof_buf
- 1)
7470 /* Make some more room in the buffer. */
7472 *buf_p
= xrealloc (*buf_p
, *sizeof_buf
);
7483 /* Read a packet from the remote machine, with error checking, and
7484 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7485 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7486 rather than timing out; this is used (in synchronous mode) to wait
7487 for a target that is is executing user code to stop. */
7488 /* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
7489 don't have to change all the calls to getpkt to deal with the
7490 return value, because at the moment I don't know what the right
7491 thing to do it for those. */
7499 timed_out
= getpkt_sane (buf
, sizeof_buf
, forever
);
7503 /* Read a packet from the remote machine, with error checking, and
7504 store it in *BUF. Resize *BUF using xrealloc if necessary to hold
7505 the result, and update *SIZEOF_BUF. If FOREVER, wait forever
7506 rather than timing out; this is used (in synchronous mode) to wait
7507 for a target that is is executing user code to stop. If FOREVER ==
7508 0, this function is allowed to time out gracefully and return an
7509 indication of this to the caller. Otherwise return the number of
7510 bytes read. If EXPECTING_NOTIF, consider receiving a notification
7511 enough reason to return to the caller. *IS_NOTIF is an output
7512 boolean that indicates whether *BUF holds a notification or not
7513 (a regular packet). */
7516 getpkt_or_notif_sane_1 (char **buf
, long *sizeof_buf
, int forever
,
7517 int expecting_notif
, int *is_notif
)
7519 struct remote_state
*rs
= get_remote_state ();
7525 /* We're reading a new response. Make sure we don't look at a
7526 previously cached response. */
7527 rs
->cached_wait_status
= 0;
7529 strcpy (*buf
, "timeout");
7532 timeout
= watchdog
> 0 ? watchdog
: -1;
7533 else if (expecting_notif
)
7534 timeout
= 0; /* There should already be a char in the buffer. If
7537 timeout
= remote_timeout
;
7541 /* Process any number of notifications, and then return when
7545 /* If we get a timeout or bad checksm, retry up to MAX_TRIES
7547 for (tries
= 1; tries
<= MAX_TRIES
; tries
++)
7549 /* This can loop forever if the remote side sends us
7550 characters continuously, but if it pauses, we'll get
7551 SERIAL_TIMEOUT from readchar because of timeout. Then
7552 we'll count that as a retry.
7554 Note that even when forever is set, we will only wait
7555 forever prior to the start of a packet. After that, we
7556 expect characters to arrive at a brisk pace. They should
7557 show up within remote_timeout intervals. */
7559 c
= readchar (timeout
);
7560 while (c
!= SERIAL_TIMEOUT
&& c
!= '$' && c
!= '%');
7562 if (c
== SERIAL_TIMEOUT
)
7564 if (expecting_notif
)
7565 return -1; /* Don't complain, it's normal to not get
7566 anything in this case. */
7568 if (forever
) /* Watchdog went off? Kill the target. */
7572 error (_("Watchdog timeout has expired. Target detached."));
7575 fputs_filtered ("Timed out.\n", gdb_stdlog
);
7579 /* We've found the start of a packet or notification.
7580 Now collect the data. */
7581 val
= read_frame (buf
, sizeof_buf
);
7586 serial_write (remote_desc
, "-", 1);
7589 if (tries
> MAX_TRIES
)
7591 /* We have tried hard enough, and just can't receive the
7592 packet/notification. Give up. */
7593 printf_unfiltered (_("Ignoring packet error, continuing...\n"));
7595 /* Skip the ack char if we're in no-ack mode. */
7596 if (!rs
->noack_mode
)
7597 serial_write (remote_desc
, "+", 1);
7601 /* If we got an ordinary packet, return that to our caller. */
7606 struct cleanup
*old_chain
;
7609 str
= escape_buffer (*buf
, val
);
7610 old_chain
= make_cleanup (xfree
, str
);
7611 fprintf_unfiltered (gdb_stdlog
, "Packet received: %s\n", str
);
7612 do_cleanups (old_chain
);
7615 /* Skip the ack char if we're in no-ack mode. */
7616 if (!rs
->noack_mode
)
7617 serial_write (remote_desc
, "+", 1);
7618 if (is_notif
!= NULL
)
7623 /* If we got a notification, handle it, and go back to looking
7627 gdb_assert (c
== '%');
7631 struct cleanup
*old_chain
;
7634 str
= escape_buffer (*buf
, val
);
7635 old_chain
= make_cleanup (xfree
, str
);
7636 fprintf_unfiltered (gdb_stdlog
,
7637 " Notification received: %s\n",
7639 do_cleanups (old_chain
);
7641 if (is_notif
!= NULL
)
7644 handle_notification (*buf
);
7646 /* Notifications require no acknowledgement. */
7648 if (expecting_notif
)
7655 getpkt_sane (char **buf
, long *sizeof_buf
, int forever
)
7657 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 0, NULL
);
7661 getpkt_or_notif_sane (char **buf
, long *sizeof_buf
, int forever
,
7664 return getpkt_or_notif_sane_1 (buf
, sizeof_buf
, forever
, 1,
7669 /* A helper function that just calls putpkt; for type correctness. */
7672 putpkt_for_catch_errors (void *arg
)
7674 return putpkt (arg
);
7678 remote_kill (struct target_ops
*ops
)
7680 /* Use catch_errors so the user can quit from gdb even when we
7681 aren't on speaking terms with the remote system. */
7682 catch_errors (putpkt_for_catch_errors
, "k", "", RETURN_MASK_ERROR
);
7684 /* Don't wait for it to die. I'm not really sure it matters whether
7685 we do or not. For the existing stubs, kill is a noop. */
7686 target_mourn_inferior ();
7690 remote_vkill (int pid
, struct remote_state
*rs
)
7692 if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7695 /* Tell the remote target to detach. */
7696 xsnprintf (rs
->buf
, get_remote_packet_size (), "vKill;%x", pid
);
7698 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7700 if (packet_ok (rs
->buf
,
7701 &remote_protocol_packets
[PACKET_vKill
]) == PACKET_OK
)
7703 else if (remote_protocol_packets
[PACKET_vKill
].support
== PACKET_DISABLE
)
7710 extended_remote_kill (struct target_ops
*ops
)
7713 int pid
= ptid_get_pid (inferior_ptid
);
7714 struct remote_state
*rs
= get_remote_state ();
7716 res
= remote_vkill (pid
, rs
);
7717 if (res
== -1 && !(rs
->extended
&& remote_multi_process_p (rs
)))
7719 /* Don't try 'k' on a multi-process aware stub -- it has no way
7720 to specify the pid. */
7724 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7725 if (rs
->buf
[0] != 'O' || rs
->buf
[0] != 'K')
7728 /* Don't wait for it to die. I'm not really sure it matters whether
7729 we do or not. For the existing stubs, kill is a noop. */
7735 error (_("Can't kill process"));
7737 target_mourn_inferior ();
7741 remote_mourn (struct target_ops
*ops
)
7743 remote_mourn_1 (ops
);
7746 /* Worker function for remote_mourn. */
7748 remote_mourn_1 (struct target_ops
*target
)
7750 unpush_target (target
);
7752 /* remote_close takes care of doing most of the clean up. */
7753 generic_mourn_inferior ();
7757 extended_remote_mourn_1 (struct target_ops
*target
)
7759 struct remote_state
*rs
= get_remote_state ();
7761 /* In case we got here due to an error, but we're going to stay
7763 rs
->waiting_for_stop_reply
= 0;
7765 /* If the current general thread belonged to the process we just
7766 detached from or has exited, the remote side current general
7767 thread becomes undefined. Considering a case like this:
7769 - We just got here due to a detach.
7770 - The process that we're detaching from happens to immediately
7771 report a global breakpoint being hit in non-stop mode, in the
7772 same thread we had selected before.
7773 - GDB attaches to this process again.
7774 - This event happens to be the next event we handle.
7776 GDB would consider that the current general thread didn't need to
7777 be set on the stub side (with Hg), since for all it knew,
7778 GENERAL_THREAD hadn't changed.
7780 Notice that although in all-stop mode, the remote server always
7781 sets the current thread to the thread reporting the stop event,
7782 that doesn't happen in non-stop mode; in non-stop, the stub *must
7783 not* change the current thread when reporting a breakpoint hit,
7784 due to the decoupling of event reporting and event handling.
7786 To keep things simple, we always invalidate our notion of the
7788 record_currthread (minus_one_ptid
);
7790 /* Unlike "target remote", we do not want to unpush the target; then
7791 the next time the user says "run", we won't be connected. */
7793 /* Call common code to mark the inferior as not running. */
7794 generic_mourn_inferior ();
7796 if (!have_inferiors ())
7798 if (!remote_multi_process_p (rs
))
7800 /* Check whether the target is running now - some remote stubs
7801 automatically restart after kill. */
7803 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7805 if (rs
->buf
[0] == 'S' || rs
->buf
[0] == 'T')
7807 /* Assume that the target has been restarted. Set
7808 inferior_ptid so that bits of core GDB realizes
7809 there's something here, e.g., so that the user can
7810 say "kill" again. */
7811 inferior_ptid
= magic_null_ptid
;
7818 extended_remote_mourn (struct target_ops
*ops
)
7820 extended_remote_mourn_1 (ops
);
7824 extended_remote_supports_disable_randomization (void)
7826 return (remote_protocol_packets
[PACKET_QDisableRandomization
].support
7831 extended_remote_disable_randomization (int val
)
7833 struct remote_state
*rs
= get_remote_state ();
7836 xsnprintf (rs
->buf
, get_remote_packet_size (), "QDisableRandomization:%x",
7839 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
7841 error (_("Target does not support QDisableRandomization."));
7842 if (strcmp (reply
, "OK") != 0)
7843 error (_("Bogus QDisableRandomization reply from target: %s"), reply
);
7847 extended_remote_run (char *args
)
7849 struct remote_state
*rs
= get_remote_state ();
7852 /* If the user has disabled vRun support, or we have detected that
7853 support is not available, do not try it. */
7854 if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7857 strcpy (rs
->buf
, "vRun;");
7858 len
= strlen (rs
->buf
);
7860 if (strlen (remote_exec_file
) * 2 + len
>= get_remote_packet_size ())
7861 error (_("Remote file name too long for run packet"));
7862 len
+= 2 * bin2hex ((gdb_byte
*) remote_exec_file
, rs
->buf
+ len
, 0);
7864 gdb_assert (args
!= NULL
);
7867 struct cleanup
*back_to
;
7871 argv
= gdb_buildargv (args
);
7872 back_to
= make_cleanup ((void (*) (void *)) freeargv
, argv
);
7873 for (i
= 0; argv
[i
] != NULL
; i
++)
7875 if (strlen (argv
[i
]) * 2 + 1 + len
>= get_remote_packet_size ())
7876 error (_("Argument list too long for run packet"));
7877 rs
->buf
[len
++] = ';';
7878 len
+= 2 * bin2hex ((gdb_byte
*) argv
[i
], rs
->buf
+ len
, 0);
7880 do_cleanups (back_to
);
7883 rs
->buf
[len
++] = '\0';
7886 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
7888 if (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_vRun
]) == PACKET_OK
)
7890 /* We have a wait response. All is well. */
7893 else if (remote_protocol_packets
[PACKET_vRun
].support
== PACKET_DISABLE
)
7894 /* It wasn't disabled before, but it is now. */
7898 if (remote_exec_file
[0] == '\0')
7899 error (_("Running the default executable on the remote target failed; "
7900 "try \"set remote exec-file\"?"));
7902 error (_("Running \"%s\" on the remote target failed"),
7907 /* In the extended protocol we want to be able to do things like
7908 "run" and have them basically work as expected. So we need
7909 a special create_inferior function. We support changing the
7910 executable file and the command line arguments, but not the
7914 extended_remote_create_inferior_1 (char *exec_file
, char *args
,
7915 char **env
, int from_tty
)
7919 struct remote_state
*rs
= get_remote_state ();
7921 /* If running asynchronously, register the target file descriptor
7922 with the event loop. */
7923 if (target_can_async_p ())
7924 target_async (inferior_event_handler
, 0);
7926 /* Disable address space randomization if requested (and supported). */
7927 if (extended_remote_supports_disable_randomization ())
7928 extended_remote_disable_randomization (disable_randomization
);
7930 /* Now restart the remote server. */
7931 run_worked
= extended_remote_run (args
) != -1;
7934 /* vRun was not supported. Fail if we need it to do what the
7936 if (remote_exec_file
[0])
7937 error (_("Remote target does not support \"set remote exec-file\""));
7939 error (_("Remote target does not support \"set args\" or run <ARGS>"));
7941 /* Fall back to "R". */
7942 extended_remote_restart ();
7945 if (!have_inferiors ())
7947 /* Clean up from the last time we ran, before we mark the target
7948 running again. This will mark breakpoints uninserted, and
7949 get_offsets may insert breakpoints. */
7950 init_thread_list ();
7951 init_wait_for_inferior ();
7954 /* vRun's success return is a stop reply. */
7955 stop_reply
= run_worked
? rs
->buf
: NULL
;
7956 add_current_inferior_and_thread (stop_reply
);
7958 /* Get updated offsets, if the stub uses qOffsets. */
7963 extended_remote_create_inferior (struct target_ops
*ops
,
7964 char *exec_file
, char *args
,
7965 char **env
, int from_tty
)
7967 extended_remote_create_inferior_1 (exec_file
, args
, env
, from_tty
);
7971 /* Given a location's target info BP_TGT and the packet buffer BUF, output
7972 the list of conditions (in agent expression bytecode format), if any, the
7973 target needs to evaluate. The output is placed into the packet buffer
7974 started from BUF and ended at BUF_END. */
7977 remote_add_target_side_condition (struct gdbarch
*gdbarch
,
7978 struct bp_target_info
*bp_tgt
, char *buf
,
7981 struct agent_expr
*aexpr
= NULL
;
7984 char *buf_start
= buf
;
7986 if (VEC_empty (agent_expr_p
, bp_tgt
->conditions
))
7989 buf
+= strlen (buf
);
7990 xsnprintf (buf
, buf_end
- buf
, "%s", ";");
7993 /* Send conditions to the target and free the vector. */
7995 VEC_iterate (agent_expr_p
, bp_tgt
->conditions
, ix
, aexpr
);
7998 xsnprintf (buf
, buf_end
- buf
, "X%x,", aexpr
->len
);
7999 buf
+= strlen (buf
);
8000 for (i
= 0; i
< aexpr
->len
; ++i
)
8001 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8005 VEC_free (agent_expr_p
, bp_tgt
->conditions
);
8010 remote_add_target_side_commands (struct gdbarch
*gdbarch
,
8011 struct bp_target_info
*bp_tgt
, char *buf
)
8013 struct agent_expr
*aexpr
= NULL
;
8016 if (VEC_empty (agent_expr_p
, bp_tgt
->tcommands
))
8019 buf
+= strlen (buf
);
8021 sprintf (buf
, ";cmds:%x,", bp_tgt
->persist
);
8022 buf
+= strlen (buf
);
8024 /* Concatenate all the agent expressions that are commands into the
8027 VEC_iterate (agent_expr_p
, bp_tgt
->tcommands
, ix
, aexpr
);
8030 sprintf (buf
, "X%x,", aexpr
->len
);
8031 buf
+= strlen (buf
);
8032 for (i
= 0; i
< aexpr
->len
; ++i
)
8033 buf
= pack_hex_byte (buf
, aexpr
->buf
[i
]);
8037 VEC_free (agent_expr_p
, bp_tgt
->tcommands
);
8040 /* Insert a breakpoint. On targets that have software breakpoint
8041 support, we ask the remote target to do the work; on targets
8042 which don't, we insert a traditional memory breakpoint. */
8045 remote_insert_breakpoint (struct gdbarch
*gdbarch
,
8046 struct bp_target_info
*bp_tgt
)
8048 /* Try the "Z" s/w breakpoint packet if it is not already disabled.
8049 If it succeeds, then set the support to PACKET_ENABLE. If it
8050 fails, and the user has explicitly requested the Z support then
8051 report an error, otherwise, mark it disabled and go on. */
8053 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8055 CORE_ADDR addr
= bp_tgt
->placed_address
;
8056 struct remote_state
*rs
;
8059 struct condition_list
*cond
= NULL
;
8061 gdbarch_remote_breakpoint_from_pc (gdbarch
, &addr
, &bpsize
);
8063 rs
= get_remote_state ();
8065 endbuf
= rs
->buf
+ get_remote_packet_size ();
8070 addr
= (ULONGEST
) remote_address_masked (addr
);
8071 p
+= hexnumstr (p
, addr
);
8072 xsnprintf (p
, endbuf
- p
, ",%d", bpsize
);
8074 if (remote_supports_cond_breakpoints ())
8075 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8077 if (remote_can_run_breakpoint_commands ())
8078 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8081 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8083 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
]))
8088 bp_tgt
->placed_address
= addr
;
8089 bp_tgt
->placed_size
= bpsize
;
8091 case PACKET_UNKNOWN
:
8096 return memory_insert_breakpoint (gdbarch
, bp_tgt
);
8100 remote_remove_breakpoint (struct gdbarch
*gdbarch
,
8101 struct bp_target_info
*bp_tgt
)
8103 CORE_ADDR addr
= bp_tgt
->placed_address
;
8104 struct remote_state
*rs
= get_remote_state ();
8106 if (remote_protocol_packets
[PACKET_Z0
].support
!= PACKET_DISABLE
)
8109 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8115 addr
= (ULONGEST
) remote_address_masked (bp_tgt
->placed_address
);
8116 p
+= hexnumstr (p
, addr
);
8117 xsnprintf (p
, endbuf
- p
, ",%d", bp_tgt
->placed_size
);
8120 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8122 return (rs
->buf
[0] == 'E');
8125 return memory_remove_breakpoint (gdbarch
, bp_tgt
);
8129 watchpoint_to_Z_packet (int type
)
8134 return Z_PACKET_WRITE_WP
;
8137 return Z_PACKET_READ_WP
;
8140 return Z_PACKET_ACCESS_WP
;
8143 internal_error (__FILE__
, __LINE__
,
8144 _("hw_bp_to_z: bad watchpoint type %d"), type
);
8149 remote_insert_watchpoint (CORE_ADDR addr
, int len
, int type
,
8150 struct expression
*cond
)
8152 struct remote_state
*rs
= get_remote_state ();
8153 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8155 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8157 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8160 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "Z%x,", packet
);
8161 p
= strchr (rs
->buf
, '\0');
8162 addr
= remote_address_masked (addr
);
8163 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8164 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8167 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8169 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8173 case PACKET_UNKNOWN
:
8178 internal_error (__FILE__
, __LINE__
,
8179 _("remote_insert_watchpoint: reached end of function"));
8183 remote_watchpoint_addr_within_range (struct target_ops
*target
, CORE_ADDR addr
,
8184 CORE_ADDR start
, int length
)
8186 CORE_ADDR diff
= remote_address_masked (addr
- start
);
8188 return diff
< length
;
8193 remote_remove_watchpoint (CORE_ADDR addr
, int len
, int type
,
8194 struct expression
*cond
)
8196 struct remote_state
*rs
= get_remote_state ();
8197 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8199 enum Z_packet_type packet
= watchpoint_to_Z_packet (type
);
8201 if (remote_protocol_packets
[PACKET_Z0
+ packet
].support
== PACKET_DISABLE
)
8204 xsnprintf (rs
->buf
, endbuf
- rs
->buf
, "z%x,", packet
);
8205 p
= strchr (rs
->buf
, '\0');
8206 addr
= remote_address_masked (addr
);
8207 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8208 xsnprintf (p
, endbuf
- p
, ",%x", len
);
8210 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8212 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z0
+ packet
]))
8215 case PACKET_UNKNOWN
:
8220 internal_error (__FILE__
, __LINE__
,
8221 _("remote_remove_watchpoint: reached end of function"));
8225 int remote_hw_watchpoint_limit
= -1;
8226 int remote_hw_watchpoint_length_limit
= -1;
8227 int remote_hw_breakpoint_limit
= -1;
8230 remote_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
8232 if (remote_hw_watchpoint_length_limit
== 0)
8234 else if (remote_hw_watchpoint_length_limit
< 0)
8236 else if (len
<= remote_hw_watchpoint_length_limit
)
8243 remote_check_watch_resources (int type
, int cnt
, int ot
)
8245 if (type
== bp_hardware_breakpoint
)
8247 if (remote_hw_breakpoint_limit
== 0)
8249 else if (remote_hw_breakpoint_limit
< 0)
8251 else if (cnt
<= remote_hw_breakpoint_limit
)
8256 if (remote_hw_watchpoint_limit
== 0)
8258 else if (remote_hw_watchpoint_limit
< 0)
8262 else if (cnt
<= remote_hw_watchpoint_limit
)
8269 remote_stopped_by_watchpoint (void)
8271 return remote_stopped_by_watchpoint_p
;
8275 remote_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
8279 if (remote_stopped_by_watchpoint ())
8281 *addr_p
= remote_watch_data_address
;
8290 remote_insert_hw_breakpoint (struct gdbarch
*gdbarch
,
8291 struct bp_target_info
*bp_tgt
)
8294 struct remote_state
*rs
;
8298 /* The length field should be set to the size of a breakpoint
8299 instruction, even though we aren't inserting one ourselves. */
8301 gdbarch_remote_breakpoint_from_pc
8302 (gdbarch
, &bp_tgt
->placed_address
, &bp_tgt
->placed_size
);
8304 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8307 rs
= get_remote_state ();
8309 endbuf
= rs
->buf
+ get_remote_packet_size ();
8315 addr
= remote_address_masked (bp_tgt
->placed_address
);
8316 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8317 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8319 if (remote_supports_cond_breakpoints ())
8320 remote_add_target_side_condition (gdbarch
, bp_tgt
, p
, endbuf
);
8322 if (remote_can_run_breakpoint_commands ())
8323 remote_add_target_side_commands (gdbarch
, bp_tgt
, p
);
8326 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8328 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8331 if (rs
->buf
[1] == '.')
8333 message
= strchr (rs
->buf
+ 2, '.');
8335 error (_("Remote failure reply: %s"), message
+ 1);
8338 case PACKET_UNKNOWN
:
8343 internal_error (__FILE__
, __LINE__
,
8344 _("remote_insert_hw_breakpoint: reached end of function"));
8349 remote_remove_hw_breakpoint (struct gdbarch
*gdbarch
,
8350 struct bp_target_info
*bp_tgt
)
8353 struct remote_state
*rs
= get_remote_state ();
8355 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
8357 if (remote_protocol_packets
[PACKET_Z1
].support
== PACKET_DISABLE
)
8364 addr
= remote_address_masked (bp_tgt
->placed_address
);
8365 p
+= hexnumstr (p
, (ULONGEST
) addr
);
8366 xsnprintf (p
, endbuf
- p
, ",%x", bp_tgt
->placed_size
);
8369 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8371 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[PACKET_Z1
]))
8374 case PACKET_UNKNOWN
:
8379 internal_error (__FILE__
, __LINE__
,
8380 _("remote_remove_hw_breakpoint: reached end of function"));
8383 /* Table used by the crc32 function to calcuate the checksum. */
8385 static unsigned long crc32_table
[256] =
8388 static unsigned long
8389 crc32 (const unsigned char *buf
, int len
, unsigned int crc
)
8391 if (!crc32_table
[1])
8393 /* Initialize the CRC table and the decoding table. */
8397 for (i
= 0; i
< 256; i
++)
8399 for (c
= i
<< 24, j
= 8; j
> 0; --j
)
8400 c
= c
& 0x80000000 ? (c
<< 1) ^ 0x04c11db7 : (c
<< 1);
8407 crc
= (crc
<< 8) ^ crc32_table
[((crc
>> 24) ^ *buf
) & 255];
8413 /* Verify memory using the "qCRC:" request. */
8416 remote_verify_memory (struct target_ops
*ops
,
8417 const gdb_byte
*data
, CORE_ADDR lma
, ULONGEST size
)
8419 struct remote_state
*rs
= get_remote_state ();
8420 unsigned long host_crc
, target_crc
;
8423 /* FIXME: assumes lma can fit into long. */
8424 xsnprintf (rs
->buf
, get_remote_packet_size (), "qCRC:%lx,%lx",
8425 (long) lma
, (long) size
);
8428 /* Be clever; compute the host_crc before waiting for target
8430 host_crc
= crc32 (data
, size
, 0xffffffff);
8432 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8433 if (rs
->buf
[0] == 'E')
8436 if (rs
->buf
[0] != 'C')
8437 error (_("remote target does not support this operation"));
8439 for (target_crc
= 0, tmp
= &rs
->buf
[1]; *tmp
; tmp
++)
8440 target_crc
= target_crc
* 16 + fromhex (*tmp
);
8442 return (host_crc
== target_crc
);
8445 /* compare-sections command
8447 With no arguments, compares each loadable section in the exec bfd
8448 with the same memory range on the target, and reports mismatches.
8449 Useful for verifying the image on the target against the exec file. */
8452 compare_sections_command (char *args
, int from_tty
)
8455 struct cleanup
*old_chain
;
8457 const char *sectname
;
8465 error (_("command cannot be used without an exec file"));
8467 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
8469 if (!(s
->flags
& SEC_LOAD
))
8470 continue; /* Skip non-loadable section. */
8472 size
= bfd_get_section_size (s
);
8474 continue; /* Skip zero-length section. */
8476 sectname
= bfd_get_section_name (exec_bfd
, s
);
8477 if (args
&& strcmp (args
, sectname
) != 0)
8478 continue; /* Not the section selected by user. */
8480 matched
= 1; /* Do this section. */
8483 sectdata
= xmalloc (size
);
8484 old_chain
= make_cleanup (xfree
, sectdata
);
8485 bfd_get_section_contents (exec_bfd
, s
, sectdata
, 0, size
);
8487 res
= target_verify_memory (sectdata
, lma
, size
);
8490 error (_("target memory fault, section %s, range %s -- %s"), sectname
,
8491 paddress (target_gdbarch (), lma
),
8492 paddress (target_gdbarch (), lma
+ size
));
8494 printf_filtered ("Section %s, range %s -- %s: ", sectname
,
8495 paddress (target_gdbarch (), lma
),
8496 paddress (target_gdbarch (), lma
+ size
));
8498 printf_filtered ("matched.\n");
8501 printf_filtered ("MIS-MATCHED!\n");
8505 do_cleanups (old_chain
);
8508 warning (_("One or more sections of the remote executable does not match\n\
8509 the loaded file\n"));
8510 if (args
&& !matched
)
8511 printf_filtered (_("No loaded section named '%s'.\n"), args
);
8514 /* Write LEN bytes from WRITEBUF into OBJECT_NAME/ANNEX at OFFSET
8515 into remote target. The number of bytes written to the remote
8516 target is returned, or -1 for error. */
8519 remote_write_qxfer (struct target_ops
*ops
, const char *object_name
,
8520 const char *annex
, const gdb_byte
*writebuf
,
8521 ULONGEST offset
, LONGEST len
,
8522 struct packet_config
*packet
)
8526 struct remote_state
*rs
= get_remote_state ();
8527 int max_size
= get_memory_write_packet_size ();
8529 if (packet
->support
== PACKET_DISABLE
)
8532 /* Insert header. */
8533 i
= snprintf (rs
->buf
, max_size
,
8534 "qXfer:%s:write:%s:%s:",
8535 object_name
, annex
? annex
: "",
8536 phex_nz (offset
, sizeof offset
));
8537 max_size
-= (i
+ 1);
8539 /* Escape as much data as fits into rs->buf. */
8540 buf_len
= remote_escape_output
8541 (writebuf
, len
, (rs
->buf
+ i
), &max_size
, max_size
);
8543 if (putpkt_binary (rs
->buf
, i
+ buf_len
) < 0
8544 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8545 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8548 unpack_varlen_hex (rs
->buf
, &n
);
8552 /* Read OBJECT_NAME/ANNEX from the remote target using a qXfer packet.
8553 Data at OFFSET, of up to LEN bytes, is read into READBUF; the
8554 number of bytes read is returned, or 0 for EOF, or -1 for error.
8555 The number of bytes read may be less than LEN without indicating an
8556 EOF. PACKET is checked and updated to indicate whether the remote
8557 target supports this object. */
8560 remote_read_qxfer (struct target_ops
*ops
, const char *object_name
,
8562 gdb_byte
*readbuf
, ULONGEST offset
, LONGEST len
,
8563 struct packet_config
*packet
)
8565 static char *finished_object
;
8566 static char *finished_annex
;
8567 static ULONGEST finished_offset
;
8569 struct remote_state
*rs
= get_remote_state ();
8570 LONGEST i
, n
, packet_len
;
8572 if (packet
->support
== PACKET_DISABLE
)
8575 /* Check whether we've cached an end-of-object packet that matches
8577 if (finished_object
)
8579 if (strcmp (object_name
, finished_object
) == 0
8580 && strcmp (annex
? annex
: "", finished_annex
) == 0
8581 && offset
== finished_offset
)
8584 /* Otherwise, we're now reading something different. Discard
8586 xfree (finished_object
);
8587 xfree (finished_annex
);
8588 finished_object
= NULL
;
8589 finished_annex
= NULL
;
8592 /* Request only enough to fit in a single packet. The actual data
8593 may not, since we don't know how much of it will need to be escaped;
8594 the target is free to respond with slightly less data. We subtract
8595 five to account for the response type and the protocol frame. */
8596 n
= min (get_remote_packet_size () - 5, len
);
8597 snprintf (rs
->buf
, get_remote_packet_size () - 4, "qXfer:%s:read:%s:%s,%s",
8598 object_name
, annex
? annex
: "",
8599 phex_nz (offset
, sizeof offset
),
8600 phex_nz (n
, sizeof n
));
8601 i
= putpkt (rs
->buf
);
8606 packet_len
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
8607 if (packet_len
< 0 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8610 if (rs
->buf
[0] != 'l' && rs
->buf
[0] != 'm')
8611 error (_("Unknown remote qXfer reply: %s"), rs
->buf
);
8613 /* 'm' means there is (or at least might be) more data after this
8614 batch. That does not make sense unless there's at least one byte
8615 of data in this reply. */
8616 if (rs
->buf
[0] == 'm' && packet_len
== 1)
8617 error (_("Remote qXfer reply contained no data."));
8619 /* Got some data. */
8620 i
= remote_unescape_input (rs
->buf
+ 1, packet_len
- 1, readbuf
, n
);
8622 /* 'l' is an EOF marker, possibly including a final block of data,
8623 or possibly empty. If we have the final block of a non-empty
8624 object, record this fact to bypass a subsequent partial read. */
8625 if (rs
->buf
[0] == 'l' && offset
+ i
> 0)
8627 finished_object
= xstrdup (object_name
);
8628 finished_annex
= xstrdup (annex
? annex
: "");
8629 finished_offset
= offset
+ i
;
8636 remote_xfer_partial (struct target_ops
*ops
, enum target_object object
,
8637 const char *annex
, gdb_byte
*readbuf
,
8638 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
8640 struct remote_state
*rs
;
8645 set_remote_traceframe ();
8646 set_general_thread (inferior_ptid
);
8648 rs
= get_remote_state ();
8650 /* Handle memory using the standard memory routines. */
8651 if (object
== TARGET_OBJECT_MEMORY
)
8657 /* If the remote target is connected but not running, we should
8658 pass this request down to a lower stratum (e.g. the executable
8660 if (!target_has_execution
)
8663 if (writebuf
!= NULL
)
8664 xfered
= remote_write_bytes (offset
, writebuf
, len
);
8666 xfered
= remote_read_bytes (offset
, readbuf
, len
);
8670 else if (xfered
== 0 && errno
== 0)
8676 /* Handle SPU memory using qxfer packets. */
8677 if (object
== TARGET_OBJECT_SPU
)
8680 return remote_read_qxfer (ops
, "spu", annex
, readbuf
, offset
, len
,
8681 &remote_protocol_packets
8682 [PACKET_qXfer_spu_read
]);
8684 return remote_write_qxfer (ops
, "spu", annex
, writebuf
, offset
, len
,
8685 &remote_protocol_packets
8686 [PACKET_qXfer_spu_write
]);
8689 /* Handle extra signal info using qxfer packets. */
8690 if (object
== TARGET_OBJECT_SIGNAL_INFO
)
8693 return remote_read_qxfer (ops
, "siginfo", annex
, readbuf
, offset
, len
,
8694 &remote_protocol_packets
8695 [PACKET_qXfer_siginfo_read
]);
8697 return remote_write_qxfer (ops
, "siginfo", annex
,
8698 writebuf
, offset
, len
,
8699 &remote_protocol_packets
8700 [PACKET_qXfer_siginfo_write
]);
8703 if (object
== TARGET_OBJECT_STATIC_TRACE_DATA
)
8706 return remote_read_qxfer (ops
, "statictrace", annex
,
8707 readbuf
, offset
, len
,
8708 &remote_protocol_packets
8709 [PACKET_qXfer_statictrace_read
]);
8714 /* Only handle flash writes. */
8715 if (writebuf
!= NULL
)
8721 case TARGET_OBJECT_FLASH
:
8722 xfered
= remote_flash_write (ops
, offset
, len
, writebuf
);
8726 else if (xfered
== 0 && errno
== 0)
8736 /* Map pre-existing objects onto letters. DO NOT do this for new
8737 objects!!! Instead specify new query packets. */
8740 case TARGET_OBJECT_AVR
:
8744 case TARGET_OBJECT_AUXV
:
8745 gdb_assert (annex
== NULL
);
8746 return remote_read_qxfer (ops
, "auxv", annex
, readbuf
, offset
, len
,
8747 &remote_protocol_packets
[PACKET_qXfer_auxv
]);
8749 case TARGET_OBJECT_AVAILABLE_FEATURES
:
8750 return remote_read_qxfer
8751 (ops
, "features", annex
, readbuf
, offset
, len
,
8752 &remote_protocol_packets
[PACKET_qXfer_features
]);
8754 case TARGET_OBJECT_LIBRARIES
:
8755 return remote_read_qxfer
8756 (ops
, "libraries", annex
, readbuf
, offset
, len
,
8757 &remote_protocol_packets
[PACKET_qXfer_libraries
]);
8759 case TARGET_OBJECT_LIBRARIES_SVR4
:
8760 return remote_read_qxfer
8761 (ops
, "libraries-svr4", annex
, readbuf
, offset
, len
,
8762 &remote_protocol_packets
[PACKET_qXfer_libraries_svr4
]);
8764 case TARGET_OBJECT_MEMORY_MAP
:
8765 gdb_assert (annex
== NULL
);
8766 return remote_read_qxfer (ops
, "memory-map", annex
, readbuf
, offset
, len
,
8767 &remote_protocol_packets
[PACKET_qXfer_memory_map
]);
8769 case TARGET_OBJECT_OSDATA
:
8770 /* Should only get here if we're connected. */
8771 gdb_assert (remote_desc
);
8772 return remote_read_qxfer
8773 (ops
, "osdata", annex
, readbuf
, offset
, len
,
8774 &remote_protocol_packets
[PACKET_qXfer_osdata
]);
8776 case TARGET_OBJECT_THREADS
:
8777 gdb_assert (annex
== NULL
);
8778 return remote_read_qxfer (ops
, "threads", annex
, readbuf
, offset
, len
,
8779 &remote_protocol_packets
[PACKET_qXfer_threads
]);
8781 case TARGET_OBJECT_TRACEFRAME_INFO
:
8782 gdb_assert (annex
== NULL
);
8783 return remote_read_qxfer
8784 (ops
, "traceframe-info", annex
, readbuf
, offset
, len
,
8785 &remote_protocol_packets
[PACKET_qXfer_traceframe_info
]);
8787 case TARGET_OBJECT_FDPIC
:
8788 return remote_read_qxfer (ops
, "fdpic", annex
, readbuf
, offset
, len
,
8789 &remote_protocol_packets
[PACKET_qXfer_fdpic
]);
8791 case TARGET_OBJECT_OPENVMS_UIB
:
8792 return remote_read_qxfer (ops
, "uib", annex
, readbuf
, offset
, len
,
8793 &remote_protocol_packets
[PACKET_qXfer_uib
]);
8799 /* Note: a zero OFFSET and LEN can be used to query the minimum
8801 if (offset
== 0 && len
== 0)
8802 return (get_remote_packet_size ());
8803 /* Minimum outbuf size is get_remote_packet_size (). If LEN is not
8804 large enough let the caller deal with it. */
8805 if (len
< get_remote_packet_size ())
8807 len
= get_remote_packet_size ();
8809 /* Except for querying the minimum buffer size, target must be open. */
8811 error (_("remote query is only available after target open"));
8813 gdb_assert (annex
!= NULL
);
8814 gdb_assert (readbuf
!= NULL
);
8820 /* We used one buffer char for the remote protocol q command and
8821 another for the query type. As the remote protocol encapsulation
8822 uses 4 chars plus one extra in case we are debugging
8823 (remote_debug), we have PBUFZIZ - 7 left to pack the query
8826 while (annex
[i
] && (i
< (get_remote_packet_size () - 8)))
8828 /* Bad caller may have sent forbidden characters. */
8829 gdb_assert (isprint (annex
[i
]) && annex
[i
] != '$' && annex
[i
] != '#');
8834 gdb_assert (annex
[i
] == '\0');
8836 i
= putpkt (rs
->buf
);
8840 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
8841 strcpy ((char *) readbuf
, rs
->buf
);
8843 return strlen ((char *) readbuf
);
8847 remote_search_memory (struct target_ops
* ops
,
8848 CORE_ADDR start_addr
, ULONGEST search_space_len
,
8849 const gdb_byte
*pattern
, ULONGEST pattern_len
,
8850 CORE_ADDR
*found_addrp
)
8852 int addr_size
= gdbarch_addr_bit (target_gdbarch ()) / 8;
8853 struct remote_state
*rs
= get_remote_state ();
8854 int max_size
= get_memory_write_packet_size ();
8855 struct packet_config
*packet
=
8856 &remote_protocol_packets
[PACKET_qSearch_memory
];
8857 /* Number of packet bytes used to encode the pattern;
8858 this could be more than PATTERN_LEN due to escape characters. */
8859 int escaped_pattern_len
;
8860 /* Amount of pattern that was encodable in the packet. */
8861 int used_pattern_len
;
8864 ULONGEST found_addr
;
8866 /* Don't go to the target if we don't have to.
8867 This is done before checking packet->support to avoid the possibility that
8868 a success for this edge case means the facility works in general. */
8869 if (pattern_len
> search_space_len
)
8871 if (pattern_len
== 0)
8873 *found_addrp
= start_addr
;
8877 /* If we already know the packet isn't supported, fall back to the simple
8878 way of searching memory. */
8880 if (packet
->support
== PACKET_DISABLE
)
8882 /* Target doesn't provided special support, fall back and use the
8883 standard support (copy memory and do the search here). */
8884 return simple_search_memory (ops
, start_addr
, search_space_len
,
8885 pattern
, pattern_len
, found_addrp
);
8888 /* Insert header. */
8889 i
= snprintf (rs
->buf
, max_size
,
8890 "qSearch:memory:%s;%s;",
8891 phex_nz (start_addr
, addr_size
),
8892 phex_nz (search_space_len
, sizeof (search_space_len
)));
8893 max_size
-= (i
+ 1);
8895 /* Escape as much data as fits into rs->buf. */
8896 escaped_pattern_len
=
8897 remote_escape_output (pattern
, pattern_len
, (rs
->buf
+ i
),
8898 &used_pattern_len
, max_size
);
8900 /* Bail if the pattern is too large. */
8901 if (used_pattern_len
!= pattern_len
)
8902 error (_("Pattern is too large to transmit to remote target."));
8904 if (putpkt_binary (rs
->buf
, i
+ escaped_pattern_len
) < 0
8905 || getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) < 0
8906 || packet_ok (rs
->buf
, packet
) != PACKET_OK
)
8908 /* The request may not have worked because the command is not
8909 supported. If so, fall back to the simple way. */
8910 if (packet
->support
== PACKET_DISABLE
)
8912 return simple_search_memory (ops
, start_addr
, search_space_len
,
8913 pattern
, pattern_len
, found_addrp
);
8918 if (rs
->buf
[0] == '0')
8920 else if (rs
->buf
[0] == '1')
8923 if (rs
->buf
[1] != ',')
8924 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8925 unpack_varlen_hex (rs
->buf
+ 2, &found_addr
);
8926 *found_addrp
= found_addr
;
8929 error (_("Unknown qSearch:memory reply: %s"), rs
->buf
);
8935 remote_rcmd (char *command
,
8936 struct ui_file
*outbuf
)
8938 struct remote_state
*rs
= get_remote_state ();
8942 error (_("remote rcmd is only available after target open"));
8944 /* Send a NULL command across as an empty command. */
8945 if (command
== NULL
)
8948 /* The query prefix. */
8949 strcpy (rs
->buf
, "qRcmd,");
8950 p
= strchr (rs
->buf
, '\0');
8952 if ((strlen (rs
->buf
) + strlen (command
) * 2 + 8/*misc*/)
8953 > get_remote_packet_size ())
8954 error (_("\"monitor\" command ``%s'' is too long."), command
);
8956 /* Encode the actual command. */
8957 bin2hex ((gdb_byte
*) command
, p
, 0);
8959 if (putpkt (rs
->buf
) < 0)
8960 error (_("Communication problem with target."));
8962 /* get/display the response */
8967 /* XXX - see also remote_get_noisy_reply(). */
8968 QUIT
; /* Allow user to bail out with ^C. */
8970 if (getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0) == -1)
8972 /* Timeout. Continue to (try to) read responses.
8973 This is better than stopping with an error, assuming the stub
8974 is still executing the (long) monitor command.
8975 If needed, the user can interrupt gdb using C-c, obtaining
8976 an effect similar to stop on timeout. */
8981 error (_("Target does not support this command."));
8982 if (buf
[0] == 'O' && buf
[1] != 'K')
8984 remote_console_output (buf
+ 1); /* 'O' message from stub. */
8987 if (strcmp (buf
, "OK") == 0)
8989 if (strlen (buf
) == 3 && buf
[0] == 'E'
8990 && isdigit (buf
[1]) && isdigit (buf
[2]))
8992 error (_("Protocol error with Rcmd"));
8994 for (p
= buf
; p
[0] != '\0' && p
[1] != '\0'; p
+= 2)
8996 char c
= (fromhex (p
[0]) << 4) + fromhex (p
[1]);
8998 fputc_unfiltered (c
, outbuf
);
9004 static VEC(mem_region_s
) *
9005 remote_memory_map (struct target_ops
*ops
)
9007 VEC(mem_region_s
) *result
= NULL
;
9008 char *text
= target_read_stralloc (¤t_target
,
9009 TARGET_OBJECT_MEMORY_MAP
, NULL
);
9013 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
9015 result
= parse_memory_map (text
);
9016 do_cleanups (back_to
);
9023 packet_command (char *args
, int from_tty
)
9025 struct remote_state
*rs
= get_remote_state ();
9028 error (_("command can only be used with remote target"));
9031 error (_("remote-packet command requires packet text as argument"));
9033 puts_filtered ("sending: ");
9034 print_packet (args
);
9035 puts_filtered ("\n");
9038 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9039 puts_filtered ("received: ");
9040 print_packet (rs
->buf
);
9041 puts_filtered ("\n");
9045 /* --------- UNIT_TEST for THREAD oriented PACKETS ------------------- */
9047 static void display_thread_info (struct gdb_ext_thread_info
*info
);
9049 static void threadset_test_cmd (char *cmd
, int tty
);
9051 static void threadalive_test (char *cmd
, int tty
);
9053 static void threadlist_test_cmd (char *cmd
, int tty
);
9055 int get_and_display_threadinfo (threadref
*ref
);
9057 static void threadinfo_test_cmd (char *cmd
, int tty
);
9059 static int thread_display_step (threadref
*ref
, void *context
);
9061 static void threadlist_update_test_cmd (char *cmd
, int tty
);
9063 static void init_remote_threadtests (void);
9065 #define SAMPLE_THREAD 0x05060708 /* Truncated 64 bit threadid. */
9068 threadset_test_cmd (char *cmd
, int tty
)
9070 int sample_thread
= SAMPLE_THREAD
;
9072 printf_filtered (_("Remote threadset test\n"));
9073 set_general_thread (sample_thread
);
9078 threadalive_test (char *cmd
, int tty
)
9080 int sample_thread
= SAMPLE_THREAD
;
9081 int pid
= ptid_get_pid (inferior_ptid
);
9082 ptid_t ptid
= ptid_build (pid
, 0, sample_thread
);
9084 if (remote_thread_alive (ptid
))
9085 printf_filtered ("PASS: Thread alive test\n");
9087 printf_filtered ("FAIL: Thread alive test\n");
9090 void output_threadid (char *title
, threadref
*ref
);
9093 output_threadid (char *title
, threadref
*ref
)
9097 pack_threadid (&hexid
[0], ref
); /* Convert threead id into hex. */
9099 printf_filtered ("%s %s\n", title
, (&hexid
[0]));
9103 threadlist_test_cmd (char *cmd
, int tty
)
9106 threadref nextthread
;
9107 int done
, result_count
;
9108 threadref threadlist
[3];
9110 printf_filtered ("Remote Threadlist test\n");
9111 if (!remote_get_threadlist (startflag
, &nextthread
, 3, &done
,
9112 &result_count
, &threadlist
[0]))
9113 printf_filtered ("FAIL: threadlist test\n");
9116 threadref
*scan
= threadlist
;
9117 threadref
*limit
= scan
+ result_count
;
9119 while (scan
< limit
)
9120 output_threadid (" thread ", scan
++);
9125 display_thread_info (struct gdb_ext_thread_info
*info
)
9127 output_threadid ("Threadid: ", &info
->threadid
);
9128 printf_filtered ("Name: %s\n ", info
->shortname
);
9129 printf_filtered ("State: %s\n", info
->display
);
9130 printf_filtered ("other: %s\n\n", info
->more_display
);
9134 get_and_display_threadinfo (threadref
*ref
)
9138 struct gdb_ext_thread_info threadinfo
;
9140 set
= TAG_THREADID
| TAG_EXISTS
| TAG_THREADNAME
9141 | TAG_MOREDISPLAY
| TAG_DISPLAY
;
9142 if (0 != (result
= remote_get_threadinfo (ref
, set
, &threadinfo
)))
9143 display_thread_info (&threadinfo
);
9148 threadinfo_test_cmd (char *cmd
, int tty
)
9150 int athread
= SAMPLE_THREAD
;
9154 int_to_threadref (&thread
, athread
);
9155 printf_filtered ("Remote Threadinfo test\n");
9156 if (!get_and_display_threadinfo (&thread
))
9157 printf_filtered ("FAIL cannot get thread info\n");
9161 thread_display_step (threadref
*ref
, void *context
)
9163 /* output_threadid(" threadstep ",ref); *//* simple test */
9164 return get_and_display_threadinfo (ref
);
9168 threadlist_update_test_cmd (char *cmd
, int tty
)
9170 printf_filtered ("Remote Threadlist update test\n");
9171 remote_threadlist_iterator (thread_display_step
, 0, CRAZY_MAX_THREADS
);
9175 init_remote_threadtests (void)
9177 add_com ("tlist", class_obscure
, threadlist_test_cmd
,
9178 _("Fetch and print the remote list of "
9179 "thread identifiers, one pkt only"));
9180 add_com ("tinfo", class_obscure
, threadinfo_test_cmd
,
9181 _("Fetch and display info about one thread"));
9182 add_com ("tset", class_obscure
, threadset_test_cmd
,
9183 _("Test setting to a different thread"));
9184 add_com ("tupd", class_obscure
, threadlist_update_test_cmd
,
9185 _("Iterate through updating all remote thread info"));
9186 add_com ("talive", class_obscure
, threadalive_test
,
9187 _(" Remote thread alive test "));
9192 /* Convert a thread ID to a string. Returns the string in a static
9196 remote_pid_to_str (struct target_ops
*ops
, ptid_t ptid
)
9198 static char buf
[64];
9199 struct remote_state
*rs
= get_remote_state ();
9201 if (ptid_equal (ptid
, null_ptid
))
9202 return normal_pid_to_str (ptid
);
9203 else if (ptid_is_pid (ptid
))
9205 /* Printing an inferior target id. */
9207 /* When multi-process extensions are off, there's no way in the
9208 remote protocol to know the remote process id, if there's any
9209 at all. There's one exception --- when we're connected with
9210 target extended-remote, and we manually attached to a process
9211 with "attach PID". We don't record anywhere a flag that
9212 allows us to distinguish that case from the case of
9213 connecting with extended-remote and the stub already being
9214 attached to a process, and reporting yes to qAttached, hence
9215 no smart special casing here. */
9216 if (!remote_multi_process_p (rs
))
9218 xsnprintf (buf
, sizeof buf
, "Remote target");
9222 return normal_pid_to_str (ptid
);
9226 if (ptid_equal (magic_null_ptid
, ptid
))
9227 xsnprintf (buf
, sizeof buf
, "Thread <main>");
9228 else if (rs
->extended
&& remote_multi_process_p (rs
))
9229 xsnprintf (buf
, sizeof buf
, "Thread %d.%ld",
9230 ptid_get_pid (ptid
), ptid_get_tid (ptid
));
9232 xsnprintf (buf
, sizeof buf
, "Thread %ld",
9233 ptid_get_tid (ptid
));
9238 /* Get the address of the thread local variable in OBJFILE which is
9239 stored at OFFSET within the thread local storage for thread PTID. */
9242 remote_get_thread_local_address (struct target_ops
*ops
,
9243 ptid_t ptid
, CORE_ADDR lm
, CORE_ADDR offset
)
9245 if (remote_protocol_packets
[PACKET_qGetTLSAddr
].support
!= PACKET_DISABLE
)
9247 struct remote_state
*rs
= get_remote_state ();
9249 char *endp
= rs
->buf
+ get_remote_packet_size ();
9250 enum packet_result result
;
9252 strcpy (p
, "qGetTLSAddr:");
9254 p
= write_ptid (p
, endp
, ptid
);
9256 p
+= hexnumstr (p
, offset
);
9258 p
+= hexnumstr (p
, lm
);
9262 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9263 result
= packet_ok (rs
->buf
,
9264 &remote_protocol_packets
[PACKET_qGetTLSAddr
]);
9265 if (result
== PACKET_OK
)
9269 unpack_varlen_hex (rs
->buf
, &result
);
9272 else if (result
== PACKET_UNKNOWN
)
9273 throw_error (TLS_GENERIC_ERROR
,
9274 _("Remote target doesn't support qGetTLSAddr packet"));
9276 throw_error (TLS_GENERIC_ERROR
,
9277 _("Remote target failed to process qGetTLSAddr request"));
9280 throw_error (TLS_GENERIC_ERROR
,
9281 _("TLS not supported or disabled on this target"));
9286 /* Provide thread local base, i.e. Thread Information Block address.
9287 Returns 1 if ptid is found and thread_local_base is non zero. */
9290 remote_get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
9292 if (remote_protocol_packets
[PACKET_qGetTIBAddr
].support
!= PACKET_DISABLE
)
9294 struct remote_state
*rs
= get_remote_state ();
9296 char *endp
= rs
->buf
+ get_remote_packet_size ();
9297 enum packet_result result
;
9299 strcpy (p
, "qGetTIBAddr:");
9301 p
= write_ptid (p
, endp
, ptid
);
9305 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
9306 result
= packet_ok (rs
->buf
,
9307 &remote_protocol_packets
[PACKET_qGetTIBAddr
]);
9308 if (result
== PACKET_OK
)
9312 unpack_varlen_hex (rs
->buf
, &result
);
9314 *addr
= (CORE_ADDR
) result
;
9317 else if (result
== PACKET_UNKNOWN
)
9318 error (_("Remote target doesn't support qGetTIBAddr packet"));
9320 error (_("Remote target failed to process qGetTIBAddr request"));
9323 error (_("qGetTIBAddr not supported or disabled on this target"));
9328 /* Support for inferring a target description based on the current
9329 architecture and the size of a 'g' packet. While the 'g' packet
9330 can have any size (since optional registers can be left off the
9331 end), some sizes are easily recognizable given knowledge of the
9332 approximate architecture. */
9334 struct remote_g_packet_guess
9337 const struct target_desc
*tdesc
;
9339 typedef struct remote_g_packet_guess remote_g_packet_guess_s
;
9340 DEF_VEC_O(remote_g_packet_guess_s
);
9342 struct remote_g_packet_data
9344 VEC(remote_g_packet_guess_s
) *guesses
;
9347 static struct gdbarch_data
*remote_g_packet_data_handle
;
9350 remote_g_packet_data_init (struct obstack
*obstack
)
9352 return OBSTACK_ZALLOC (obstack
, struct remote_g_packet_data
);
9356 register_remote_g_packet_guess (struct gdbarch
*gdbarch
, int bytes
,
9357 const struct target_desc
*tdesc
)
9359 struct remote_g_packet_data
*data
9360 = gdbarch_data (gdbarch
, remote_g_packet_data_handle
);
9361 struct remote_g_packet_guess new_guess
, *guess
;
9364 gdb_assert (tdesc
!= NULL
);
9367 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9369 if (guess
->bytes
== bytes
)
9370 internal_error (__FILE__
, __LINE__
,
9371 _("Duplicate g packet description added for size %d"),
9374 new_guess
.bytes
= bytes
;
9375 new_guess
.tdesc
= tdesc
;
9376 VEC_safe_push (remote_g_packet_guess_s
, data
->guesses
, &new_guess
);
9379 /* Return 1 if remote_read_description would do anything on this target
9380 and architecture, 0 otherwise. */
9383 remote_read_description_p (struct target_ops
*target
)
9385 struct remote_g_packet_data
*data
9386 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9388 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9394 static const struct target_desc
*
9395 remote_read_description (struct target_ops
*target
)
9397 struct remote_g_packet_data
*data
9398 = gdbarch_data (target_gdbarch (), remote_g_packet_data_handle
);
9400 /* Do not try this during initial connection, when we do not know
9401 whether there is a running but stopped thread. */
9402 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
9405 if (!VEC_empty (remote_g_packet_guess_s
, data
->guesses
))
9407 struct remote_g_packet_guess
*guess
;
9409 int bytes
= send_g_packet ();
9412 VEC_iterate (remote_g_packet_guess_s
, data
->guesses
, ix
, guess
);
9414 if (guess
->bytes
== bytes
)
9415 return guess
->tdesc
;
9417 /* We discard the g packet. A minor optimization would be to
9418 hold on to it, and fill the register cache once we have selected
9419 an architecture, but it's too tricky to do safely. */
9425 /* Remote file transfer support. This is host-initiated I/O, not
9426 target-initiated; for target-initiated, see remote-fileio.c. */
9428 /* If *LEFT is at least the length of STRING, copy STRING to
9429 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9430 decrease *LEFT. Otherwise raise an error. */
9433 remote_buffer_add_string (char **buffer
, int *left
, char *string
)
9435 int len
= strlen (string
);
9438 error (_("Packet too long for target."));
9440 memcpy (*buffer
, string
, len
);
9444 /* NUL-terminate the buffer as a convenience, if there is
9450 /* If *LEFT is large enough, hex encode LEN bytes from BYTES into
9451 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9452 decrease *LEFT. Otherwise raise an error. */
9455 remote_buffer_add_bytes (char **buffer
, int *left
, const gdb_byte
*bytes
,
9458 if (2 * len
> *left
)
9459 error (_("Packet too long for target."));
9461 bin2hex (bytes
, *buffer
, len
);
9465 /* NUL-terminate the buffer as a convenience, if there is
9471 /* If *LEFT is large enough, convert VALUE to hex and add it to
9472 *BUFFER, update *BUFFER to point to the new end of the buffer, and
9473 decrease *LEFT. Otherwise raise an error. */
9476 remote_buffer_add_int (char **buffer
, int *left
, ULONGEST value
)
9478 int len
= hexnumlen (value
);
9481 error (_("Packet too long for target."));
9483 hexnumstr (*buffer
, value
);
9487 /* NUL-terminate the buffer as a convenience, if there is
9493 /* Parse an I/O result packet from BUFFER. Set RETCODE to the return
9494 value, *REMOTE_ERRNO to the remote error number or zero if none
9495 was included, and *ATTACHMENT to point to the start of the annex
9496 if any. The length of the packet isn't needed here; there may
9497 be NUL bytes in BUFFER, but they will be after *ATTACHMENT.
9499 Return 0 if the packet could be parsed, -1 if it could not. If
9500 -1 is returned, the other variables may not be initialized. */
9503 remote_hostio_parse_result (char *buffer
, int *retcode
,
9504 int *remote_errno
, char **attachment
)
9511 if (buffer
[0] != 'F')
9515 *retcode
= strtol (&buffer
[1], &p
, 16);
9516 if (errno
!= 0 || p
== &buffer
[1])
9519 /* Check for ",errno". */
9523 *remote_errno
= strtol (p
+ 1, &p2
, 16);
9524 if (errno
!= 0 || p
+ 1 == p2
)
9529 /* Check for ";attachment". If there is no attachment, the
9530 packet should end here. */
9533 *attachment
= p
+ 1;
9536 else if (*p
== '\0')
9542 /* Send a prepared I/O packet to the target and read its response.
9543 The prepared packet is in the global RS->BUF before this function
9544 is called, and the answer is there when we return.
9546 COMMAND_BYTES is the length of the request to send, which may include
9547 binary data. WHICH_PACKET is the packet configuration to check
9548 before attempting a packet. If an error occurs, *REMOTE_ERRNO
9549 is set to the error number and -1 is returned. Otherwise the value
9550 returned by the function is returned.
9552 ATTACHMENT and ATTACHMENT_LEN should be non-NULL if and only if an
9553 attachment is expected; an error will be reported if there's a
9554 mismatch. If one is found, *ATTACHMENT will be set to point into
9555 the packet buffer and *ATTACHMENT_LEN will be set to the
9556 attachment's length. */
9559 remote_hostio_send_command (int command_bytes
, int which_packet
,
9560 int *remote_errno
, char **attachment
,
9561 int *attachment_len
)
9563 struct remote_state
*rs
= get_remote_state ();
9564 int ret
, bytes_read
;
9565 char *attachment_tmp
;
9568 || remote_protocol_packets
[which_packet
].support
== PACKET_DISABLE
)
9570 *remote_errno
= FILEIO_ENOSYS
;
9574 putpkt_binary (rs
->buf
, command_bytes
);
9575 bytes_read
= getpkt_sane (&rs
->buf
, &rs
->buf_size
, 0);
9577 /* If it timed out, something is wrong. Don't try to parse the
9581 *remote_errno
= FILEIO_EINVAL
;
9585 switch (packet_ok (rs
->buf
, &remote_protocol_packets
[which_packet
]))
9588 *remote_errno
= FILEIO_EINVAL
;
9590 case PACKET_UNKNOWN
:
9591 *remote_errno
= FILEIO_ENOSYS
;
9597 if (remote_hostio_parse_result (rs
->buf
, &ret
, remote_errno
,
9600 *remote_errno
= FILEIO_EINVAL
;
9604 /* Make sure we saw an attachment if and only if we expected one. */
9605 if ((attachment_tmp
== NULL
&& attachment
!= NULL
)
9606 || (attachment_tmp
!= NULL
&& attachment
== NULL
))
9608 *remote_errno
= FILEIO_EINVAL
;
9612 /* If an attachment was found, it must point into the packet buffer;
9613 work out how many bytes there were. */
9614 if (attachment_tmp
!= NULL
)
9616 *attachment
= attachment_tmp
;
9617 *attachment_len
= bytes_read
- (*attachment
- rs
->buf
);
9623 /* Open FILENAME on the remote target, using FLAGS and MODE. Return a
9624 remote file descriptor, or -1 if an error occurs (and set
9628 remote_hostio_open (const char *filename
, int flags
, int mode
,
9631 struct remote_state
*rs
= get_remote_state ();
9633 int left
= get_remote_packet_size () - 1;
9635 remote_buffer_add_string (&p
, &left
, "vFile:open:");
9637 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9639 remote_buffer_add_string (&p
, &left
, ",");
9641 remote_buffer_add_int (&p
, &left
, flags
);
9642 remote_buffer_add_string (&p
, &left
, ",");
9644 remote_buffer_add_int (&p
, &left
, mode
);
9646 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_open
,
9647 remote_errno
, NULL
, NULL
);
9650 /* Write up to LEN bytes from WRITE_BUF to FD on the remote target.
9651 Return the number of bytes written, or -1 if an error occurs (and
9652 set *REMOTE_ERRNO). */
9655 remote_hostio_pwrite (int fd
, const gdb_byte
*write_buf
, int len
,
9656 ULONGEST offset
, int *remote_errno
)
9658 struct remote_state
*rs
= get_remote_state ();
9660 int left
= get_remote_packet_size ();
9663 remote_buffer_add_string (&p
, &left
, "vFile:pwrite:");
9665 remote_buffer_add_int (&p
, &left
, fd
);
9666 remote_buffer_add_string (&p
, &left
, ",");
9668 remote_buffer_add_int (&p
, &left
, offset
);
9669 remote_buffer_add_string (&p
, &left
, ",");
9671 p
+= remote_escape_output (write_buf
, len
, p
, &out_len
,
9672 get_remote_packet_size () - (p
- rs
->buf
));
9674 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pwrite
,
9675 remote_errno
, NULL
, NULL
);
9678 /* Read up to LEN bytes FD on the remote target into READ_BUF
9679 Return the number of bytes read, or -1 if an error occurs (and
9680 set *REMOTE_ERRNO). */
9683 remote_hostio_pread (int fd
, gdb_byte
*read_buf
, int len
,
9684 ULONGEST offset
, int *remote_errno
)
9686 struct remote_state
*rs
= get_remote_state ();
9689 int left
= get_remote_packet_size ();
9690 int ret
, attachment_len
;
9693 remote_buffer_add_string (&p
, &left
, "vFile:pread:");
9695 remote_buffer_add_int (&p
, &left
, fd
);
9696 remote_buffer_add_string (&p
, &left
, ",");
9698 remote_buffer_add_int (&p
, &left
, len
);
9699 remote_buffer_add_string (&p
, &left
, ",");
9701 remote_buffer_add_int (&p
, &left
, offset
);
9703 ret
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_pread
,
9704 remote_errno
, &attachment
,
9710 read_len
= remote_unescape_input (attachment
, attachment_len
,
9712 if (read_len
!= ret
)
9713 error (_("Read returned %d, but %d bytes."), ret
, (int) read_len
);
9718 /* Close FD on the remote target. Return 0, or -1 if an error occurs
9719 (and set *REMOTE_ERRNO). */
9722 remote_hostio_close (int fd
, int *remote_errno
)
9724 struct remote_state
*rs
= get_remote_state ();
9726 int left
= get_remote_packet_size () - 1;
9728 remote_buffer_add_string (&p
, &left
, "vFile:close:");
9730 remote_buffer_add_int (&p
, &left
, fd
);
9732 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_close
,
9733 remote_errno
, NULL
, NULL
);
9736 /* Unlink FILENAME on the remote target. Return 0, or -1 if an error
9737 occurs (and set *REMOTE_ERRNO). */
9740 remote_hostio_unlink (const char *filename
, int *remote_errno
)
9742 struct remote_state
*rs
= get_remote_state ();
9744 int left
= get_remote_packet_size () - 1;
9746 remote_buffer_add_string (&p
, &left
, "vFile:unlink:");
9748 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9751 return remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_unlink
,
9752 remote_errno
, NULL
, NULL
);
9755 /* Read value of symbolic link FILENAME on the remote target. Return
9756 a null-terminated string allocated via xmalloc, or NULL if an error
9757 occurs (and set *REMOTE_ERRNO). */
9760 remote_hostio_readlink (const char *filename
, int *remote_errno
)
9762 struct remote_state
*rs
= get_remote_state ();
9765 int left
= get_remote_packet_size ();
9766 int len
, attachment_len
;
9770 remote_buffer_add_string (&p
, &left
, "vFile:readlink:");
9772 remote_buffer_add_bytes (&p
, &left
, (const gdb_byte
*) filename
,
9775 len
= remote_hostio_send_command (p
- rs
->buf
, PACKET_vFile_readlink
,
9776 remote_errno
, &attachment
,
9782 ret
= xmalloc (len
+ 1);
9784 read_len
= remote_unescape_input (attachment
, attachment_len
,
9786 if (read_len
!= len
)
9787 error (_("Readlink returned %d, but %d bytes."), len
, read_len
);
9794 remote_fileio_errno_to_host (int errnum
)
9818 case FILEIO_ENOTDIR
:
9838 case FILEIO_ENAMETOOLONG
:
9839 return ENAMETOOLONG
;
9845 remote_hostio_error (int errnum
)
9847 int host_error
= remote_fileio_errno_to_host (errnum
);
9849 if (host_error
== -1)
9850 error (_("Unknown remote I/O error %d"), errnum
);
9852 error (_("Remote I/O error: %s"), safe_strerror (host_error
));
9856 remote_hostio_close_cleanup (void *opaque
)
9858 int fd
= *(int *) opaque
;
9861 remote_hostio_close (fd
, &remote_errno
);
9866 remote_bfd_iovec_open (struct bfd
*abfd
, void *open_closure
)
9868 const char *filename
= bfd_get_filename (abfd
);
9869 int fd
, remote_errno
;
9872 gdb_assert (remote_filename_p (filename
));
9874 fd
= remote_hostio_open (filename
+ 7, FILEIO_O_RDONLY
, 0, &remote_errno
);
9877 errno
= remote_fileio_errno_to_host (remote_errno
);
9878 bfd_set_error (bfd_error_system_call
);
9882 stream
= xmalloc (sizeof (int));
9888 remote_bfd_iovec_close (struct bfd
*abfd
, void *stream
)
9890 int fd
= *(int *)stream
;
9895 /* Ignore errors on close; these may happen if the remote
9896 connection was already torn down. */
9897 remote_hostio_close (fd
, &remote_errno
);
9903 remote_bfd_iovec_pread (struct bfd
*abfd
, void *stream
, void *buf
,
9904 file_ptr nbytes
, file_ptr offset
)
9906 int fd
= *(int *)stream
;
9908 file_ptr pos
, bytes
;
9911 while (nbytes
> pos
)
9913 bytes
= remote_hostio_pread (fd
, (char *)buf
+ pos
, nbytes
- pos
,
9914 offset
+ pos
, &remote_errno
);
9916 /* Success, but no bytes, means end-of-file. */
9920 errno
= remote_fileio_errno_to_host (remote_errno
);
9921 bfd_set_error (bfd_error_system_call
);
9932 remote_bfd_iovec_stat (struct bfd
*abfd
, void *stream
, struct stat
*sb
)
9934 /* FIXME: We should probably implement remote_hostio_stat. */
9935 sb
->st_size
= INT_MAX
;
9940 remote_filename_p (const char *filename
)
9942 return strncmp (filename
, "remote:", 7) == 0;
9946 remote_bfd_open (const char *remote_file
, const char *target
)
9948 bfd
*abfd
= gdb_bfd_openr_iovec (remote_file
, target
,
9949 remote_bfd_iovec_open
, NULL
,
9950 remote_bfd_iovec_pread
,
9951 remote_bfd_iovec_close
,
9952 remote_bfd_iovec_stat
);
9958 remote_file_put (const char *local_file
, const char *remote_file
, int from_tty
)
9960 struct cleanup
*back_to
, *close_cleanup
;
9961 int retcode
, fd
, remote_errno
, bytes
, io_size
;
9964 int bytes_in_buffer
;
9969 error (_("command can only be used with remote target"));
9971 file
= fopen (local_file
, "rb");
9973 perror_with_name (local_file
);
9974 back_to
= make_cleanup_fclose (file
);
9976 fd
= remote_hostio_open (remote_file
, (FILEIO_O_WRONLY
| FILEIO_O_CREAT
9978 0700, &remote_errno
);
9980 remote_hostio_error (remote_errno
);
9982 /* Send up to this many bytes at once. They won't all fit in the
9983 remote packet limit, so we'll transfer slightly fewer. */
9984 io_size
= get_remote_packet_size ();
9985 buffer
= xmalloc (io_size
);
9986 make_cleanup (xfree
, buffer
);
9988 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
9990 bytes_in_buffer
= 0;
9993 while (bytes_in_buffer
|| !saw_eof
)
9997 bytes
= fread (buffer
+ bytes_in_buffer
, 1,
9998 io_size
- bytes_in_buffer
,
10003 error (_("Error reading %s."), local_file
);
10006 /* EOF. Unless there is something still in the
10007 buffer from the last iteration, we are done. */
10009 if (bytes_in_buffer
== 0)
10017 bytes
+= bytes_in_buffer
;
10018 bytes_in_buffer
= 0;
10020 retcode
= remote_hostio_pwrite (fd
, buffer
, bytes
,
10021 offset
, &remote_errno
);
10024 remote_hostio_error (remote_errno
);
10025 else if (retcode
== 0)
10026 error (_("Remote write of %d bytes returned 0!"), bytes
);
10027 else if (retcode
< bytes
)
10029 /* Short write. Save the rest of the read data for the next
10031 bytes_in_buffer
= bytes
- retcode
;
10032 memmove (buffer
, buffer
+ retcode
, bytes_in_buffer
);
10038 discard_cleanups (close_cleanup
);
10039 if (remote_hostio_close (fd
, &remote_errno
))
10040 remote_hostio_error (remote_errno
);
10043 printf_filtered (_("Successfully sent file \"%s\".\n"), local_file
);
10044 do_cleanups (back_to
);
10048 remote_file_get (const char *remote_file
, const char *local_file
, int from_tty
)
10050 struct cleanup
*back_to
, *close_cleanup
;
10051 int fd
, remote_errno
, bytes
, io_size
;
10057 error (_("command can only be used with remote target"));
10059 fd
= remote_hostio_open (remote_file
, FILEIO_O_RDONLY
, 0, &remote_errno
);
10061 remote_hostio_error (remote_errno
);
10063 file
= fopen (local_file
, "wb");
10065 perror_with_name (local_file
);
10066 back_to
= make_cleanup_fclose (file
);
10068 /* Send up to this many bytes at once. They won't all fit in the
10069 remote packet limit, so we'll transfer slightly fewer. */
10070 io_size
= get_remote_packet_size ();
10071 buffer
= xmalloc (io_size
);
10072 make_cleanup (xfree
, buffer
);
10074 close_cleanup
= make_cleanup (remote_hostio_close_cleanup
, &fd
);
10079 bytes
= remote_hostio_pread (fd
, buffer
, io_size
, offset
, &remote_errno
);
10081 /* Success, but no bytes, means end-of-file. */
10084 remote_hostio_error (remote_errno
);
10088 bytes
= fwrite (buffer
, 1, bytes
, file
);
10090 perror_with_name (local_file
);
10093 discard_cleanups (close_cleanup
);
10094 if (remote_hostio_close (fd
, &remote_errno
))
10095 remote_hostio_error (remote_errno
);
10098 printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file
);
10099 do_cleanups (back_to
);
10103 remote_file_delete (const char *remote_file
, int from_tty
)
10105 int retcode
, remote_errno
;
10108 error (_("command can only be used with remote target"));
10110 retcode
= remote_hostio_unlink (remote_file
, &remote_errno
);
10112 remote_hostio_error (remote_errno
);
10115 printf_filtered (_("Successfully deleted file \"%s\".\n"), remote_file
);
10119 remote_put_command (char *args
, int from_tty
)
10121 struct cleanup
*back_to
;
10125 error_no_arg (_("file to put"));
10127 argv
= gdb_buildargv (args
);
10128 back_to
= make_cleanup_freeargv (argv
);
10129 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10130 error (_("Invalid parameters to remote put"));
10132 remote_file_put (argv
[0], argv
[1], from_tty
);
10134 do_cleanups (back_to
);
10138 remote_get_command (char *args
, int from_tty
)
10140 struct cleanup
*back_to
;
10144 error_no_arg (_("file to get"));
10146 argv
= gdb_buildargv (args
);
10147 back_to
= make_cleanup_freeargv (argv
);
10148 if (argv
[0] == NULL
|| argv
[1] == NULL
|| argv
[2] != NULL
)
10149 error (_("Invalid parameters to remote get"));
10151 remote_file_get (argv
[0], argv
[1], from_tty
);
10153 do_cleanups (back_to
);
10157 remote_delete_command (char *args
, int from_tty
)
10159 struct cleanup
*back_to
;
10163 error_no_arg (_("file to delete"));
10165 argv
= gdb_buildargv (args
);
10166 back_to
= make_cleanup_freeargv (argv
);
10167 if (argv
[0] == NULL
|| argv
[1] != NULL
)
10168 error (_("Invalid parameters to remote delete"));
10170 remote_file_delete (argv
[0], from_tty
);
10172 do_cleanups (back_to
);
10176 remote_command (char *args
, int from_tty
)
10178 help_list (remote_cmdlist
, "remote ", -1, gdb_stdout
);
10182 remote_can_execute_reverse (void)
10184 if (remote_protocol_packets
[PACKET_bs
].support
== PACKET_ENABLE
10185 || remote_protocol_packets
[PACKET_bc
].support
== PACKET_ENABLE
)
10192 remote_supports_non_stop (void)
10198 remote_supports_disable_randomization (void)
10200 /* Only supported in extended mode. */
10205 remote_supports_multi_process (void)
10207 struct remote_state
*rs
= get_remote_state ();
10209 /* Only extended-remote handles being attached to multiple
10210 processes, even though plain remote can use the multi-process
10211 thread id extensions, so that GDB knows the target process's
10213 return rs
->extended
&& remote_multi_process_p (rs
);
10217 remote_supports_cond_tracepoints (void)
10219 struct remote_state
*rs
= get_remote_state ();
10221 return rs
->cond_tracepoints
;
10225 remote_supports_cond_breakpoints (void)
10227 struct remote_state
*rs
= get_remote_state ();
10229 return rs
->cond_breakpoints
;
10233 remote_supports_fast_tracepoints (void)
10235 struct remote_state
*rs
= get_remote_state ();
10237 return rs
->fast_tracepoints
;
10241 remote_supports_static_tracepoints (void)
10243 struct remote_state
*rs
= get_remote_state ();
10245 return rs
->static_tracepoints
;
10249 remote_supports_install_in_trace (void)
10251 struct remote_state
*rs
= get_remote_state ();
10253 return rs
->install_in_trace
;
10257 remote_supports_enable_disable_tracepoint (void)
10259 struct remote_state
*rs
= get_remote_state ();
10261 return rs
->enable_disable_tracepoints
;
10265 remote_supports_string_tracing (void)
10267 struct remote_state
*rs
= get_remote_state ();
10269 return rs
->string_tracing
;
10273 remote_can_run_breakpoint_commands (void)
10275 struct remote_state
*rs
= get_remote_state ();
10277 return rs
->breakpoint_commands
;
10281 remote_trace_init (void)
10284 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10285 if (strcmp (target_buf
, "OK") != 0)
10286 error (_("Target does not support this command."));
10289 static void free_actions_list (char **actions_list
);
10290 static void free_actions_list_cleanup_wrapper (void *);
10292 free_actions_list_cleanup_wrapper (void *al
)
10294 free_actions_list (al
);
10298 free_actions_list (char **actions_list
)
10302 if (actions_list
== 0)
10305 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
10306 xfree (actions_list
[ndx
]);
10308 xfree (actions_list
);
10311 /* Recursive routine to walk through command list including loops, and
10312 download packets for each command. */
10315 remote_download_command_source (int num
, ULONGEST addr
,
10316 struct command_line
*cmds
)
10318 struct remote_state
*rs
= get_remote_state ();
10319 struct command_line
*cmd
;
10321 for (cmd
= cmds
; cmd
; cmd
= cmd
->next
)
10323 QUIT
; /* Allow user to bail out with ^C. */
10324 strcpy (rs
->buf
, "QTDPsrc:");
10325 encode_source_string (num
, addr
, "cmd", cmd
->line
,
10326 rs
->buf
+ strlen (rs
->buf
),
10327 rs
->buf_size
- strlen (rs
->buf
));
10329 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10330 if (strcmp (target_buf
, "OK"))
10331 warning (_("Target does not support source download."));
10333 if (cmd
->control_type
== while_control
10334 || cmd
->control_type
== while_stepping_control
)
10336 remote_download_command_source (num
, addr
, *cmd
->body_list
);
10338 QUIT
; /* Allow user to bail out with ^C. */
10339 strcpy (rs
->buf
, "QTDPsrc:");
10340 encode_source_string (num
, addr
, "cmd", "end",
10341 rs
->buf
+ strlen (rs
->buf
),
10342 rs
->buf_size
- strlen (rs
->buf
));
10344 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10345 if (strcmp (target_buf
, "OK"))
10346 warning (_("Target does not support source download."));
10352 remote_download_tracepoint (struct bp_location
*loc
)
10354 #define BUF_SIZE 2048
10358 char buf
[BUF_SIZE
];
10359 char **tdp_actions
;
10360 char **stepping_actions
;
10362 struct cleanup
*old_chain
= NULL
;
10363 struct agent_expr
*aexpr
;
10364 struct cleanup
*aexpr_chain
= NULL
;
10366 struct breakpoint
*b
= loc
->owner
;
10367 struct tracepoint
*t
= (struct tracepoint
*) b
;
10369 encode_actions (loc
->owner
, loc
, &tdp_actions
, &stepping_actions
);
10370 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
10372 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
10375 tpaddr
= loc
->address
;
10376 sprintf_vma (addrbuf
, tpaddr
);
10377 xsnprintf (buf
, BUF_SIZE
, "QTDP:%x:%s:%c:%lx:%x", b
->number
,
10378 addrbuf
, /* address */
10379 (b
->enable_state
== bp_enabled
? 'E' : 'D'),
10380 t
->step_count
, t
->pass_count
);
10381 /* Fast tracepoints are mostly handled by the target, but we can
10382 tell the target how big of an instruction block should be moved
10384 if (b
->type
== bp_fast_tracepoint
)
10386 /* Only test for support at download time; we may not know
10387 target capabilities at definition time. */
10388 if (remote_supports_fast_tracepoints ())
10392 if (gdbarch_fast_tracepoint_valid_at (target_gdbarch (),
10393 tpaddr
, &isize
, NULL
))
10394 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":F%x",
10397 /* If it passed validation at definition but fails now,
10398 something is very wrong. */
10399 internal_error (__FILE__
, __LINE__
,
10400 _("Fast tracepoint not "
10401 "valid during download"));
10404 /* Fast tracepoints are functionally identical to regular
10405 tracepoints, so don't take lack of support as a reason to
10406 give up on the trace run. */
10407 warning (_("Target does not support fast tracepoints, "
10408 "downloading %d as regular tracepoint"), b
->number
);
10410 else if (b
->type
== bp_static_tracepoint
)
10412 /* Only test for support at download time; we may not know
10413 target capabilities at definition time. */
10414 if (remote_supports_static_tracepoints ())
10416 struct static_tracepoint_marker marker
;
10418 if (target_static_tracepoint_marker_at (tpaddr
, &marker
))
10419 strcat (buf
, ":S");
10421 error (_("Static tracepoint not valid during download"));
10424 /* Fast tracepoints are functionally identical to regular
10425 tracepoints, so don't take lack of support as a reason
10426 to give up on the trace run. */
10427 error (_("Target does not support static tracepoints"));
10429 /* If the tracepoint has a conditional, make it into an agent
10430 expression and append to the definition. */
10433 /* Only test support at download time, we may not know target
10434 capabilities at definition time. */
10435 if (remote_supports_cond_tracepoints ())
10437 aexpr
= gen_eval_for_expr (tpaddr
, loc
->cond
);
10438 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
10439 xsnprintf (buf
+ strlen (buf
), BUF_SIZE
- strlen (buf
), ":X%x,",
10441 pkt
= buf
+ strlen (buf
);
10442 for (ndx
= 0; ndx
< aexpr
->len
; ++ndx
)
10443 pkt
= pack_hex_byte (pkt
, aexpr
->buf
[ndx
]);
10445 do_cleanups (aexpr_chain
);
10448 warning (_("Target does not support conditional tracepoints, "
10449 "ignoring tp %d cond"), b
->number
);
10452 if (b
->commands
|| *default_collect
)
10455 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10456 if (strcmp (target_buf
, "OK"))
10457 error (_("Target does not support tracepoints."));
10459 /* do_single_steps (t); */
10462 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
10464 QUIT
; /* Allow user to bail out with ^C. */
10465 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%c",
10466 b
->number
, addrbuf
, /* address */
10468 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
10471 remote_get_noisy_reply (&target_buf
,
10473 if (strcmp (target_buf
, "OK"))
10474 error (_("Error on target while setting tracepoints."));
10477 if (stepping_actions
)
10479 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
10481 QUIT
; /* Allow user to bail out with ^C. */
10482 xsnprintf (buf
, BUF_SIZE
, "QTDP:-%x:%s:%s%s%s",
10483 b
->number
, addrbuf
, /* address */
10484 ((ndx
== 0) ? "S" : ""),
10485 stepping_actions
[ndx
],
10486 (stepping_actions
[ndx
+ 1] ? "-" : ""));
10488 remote_get_noisy_reply (&target_buf
,
10490 if (strcmp (target_buf
, "OK"))
10491 error (_("Error on target while setting tracepoints."));
10495 if (remote_protocol_packets
[PACKET_TracepointSource
].support
10498 if (b
->addr_string
)
10500 strcpy (buf
, "QTDPsrc:");
10501 encode_source_string (b
->number
, loc
->address
,
10502 "at", b
->addr_string
, buf
+ strlen (buf
),
10503 2048 - strlen (buf
));
10506 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10507 if (strcmp (target_buf
, "OK"))
10508 warning (_("Target does not support source download."));
10510 if (b
->cond_string
)
10512 strcpy (buf
, "QTDPsrc:");
10513 encode_source_string (b
->number
, loc
->address
,
10514 "cond", b
->cond_string
, buf
+ strlen (buf
),
10515 2048 - strlen (buf
));
10517 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10518 if (strcmp (target_buf
, "OK"))
10519 warning (_("Target does not support source download."));
10521 remote_download_command_source (b
->number
, loc
->address
,
10522 breakpoint_commands (b
));
10525 do_cleanups (old_chain
);
10529 remote_can_download_tracepoint (void)
10531 struct remote_state
*rs
= get_remote_state ();
10532 struct trace_status
*ts
;
10535 /* Don't try to install tracepoints until we've relocated our
10536 symbols, and fetched and merged the target's tracepoint list with
10538 if (rs
->starting_up
)
10541 ts
= current_trace_status ();
10542 status
= remote_get_trace_status (ts
);
10544 if (status
== -1 || !ts
->running_known
|| !ts
->running
)
10547 /* If we are in a tracing experiment, but remote stub doesn't support
10548 installing tracepoint in trace, we have to return. */
10549 if (!remote_supports_install_in_trace ())
10557 remote_download_trace_state_variable (struct trace_state_variable
*tsv
)
10559 struct remote_state
*rs
= get_remote_state ();
10562 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDV:%x:%s:%x:",
10563 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8),
10565 p
= rs
->buf
+ strlen (rs
->buf
);
10566 if ((p
- rs
->buf
) + strlen (tsv
->name
) * 2 >= get_remote_packet_size ())
10567 error (_("Trace state variable name too long for tsv definition packet"));
10568 p
+= 2 * bin2hex ((gdb_byte
*) (tsv
->name
), p
, 0);
10571 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10572 if (*target_buf
== '\0')
10573 error (_("Target does not support this command."));
10574 if (strcmp (target_buf
, "OK") != 0)
10575 error (_("Error on target while downloading trace state variable."));
10579 remote_enable_tracepoint (struct bp_location
*location
)
10581 struct remote_state
*rs
= get_remote_state ();
10584 sprintf_vma (addr_buf
, location
->address
);
10585 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTEnable:%x:%s",
10586 location
->owner
->number
, addr_buf
);
10588 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10589 if (*rs
->buf
== '\0')
10590 error (_("Target does not support enabling tracepoints while a trace run is ongoing."));
10591 if (strcmp (rs
->buf
, "OK") != 0)
10592 error (_("Error on target while enabling tracepoint."));
10596 remote_disable_tracepoint (struct bp_location
*location
)
10598 struct remote_state
*rs
= get_remote_state ();
10601 sprintf_vma (addr_buf
, location
->address
);
10602 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisable:%x:%s",
10603 location
->owner
->number
, addr_buf
);
10605 remote_get_noisy_reply (&rs
->buf
, &rs
->buf_size
);
10606 if (*rs
->buf
== '\0')
10607 error (_("Target does not support disabling tracepoints while a trace run is ongoing."));
10608 if (strcmp (rs
->buf
, "OK") != 0)
10609 error (_("Error on target while disabling tracepoint."));
10613 remote_trace_set_readonly_regions (void)
10617 bfd_size_type size
;
10623 return; /* No information to give. */
10625 strcpy (target_buf
, "QTro");
10626 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
10628 char tmp1
[40], tmp2
[40];
10631 if ((s
->flags
& SEC_LOAD
) == 0 ||
10632 /* (s->flags & SEC_CODE) == 0 || */
10633 (s
->flags
& SEC_READONLY
) == 0)
10637 vma
= bfd_get_section_vma (abfd
, s
);
10638 size
= bfd_get_section_size (s
);
10639 sprintf_vma (tmp1
, vma
);
10640 sprintf_vma (tmp2
, vma
+ size
);
10641 sec_length
= 1 + strlen (tmp1
) + 1 + strlen (tmp2
);
10642 if (offset
+ sec_length
+ 1 > target_buf_size
)
10644 if (remote_protocol_packets
[PACKET_qXfer_traceframe_info
].support
10647 Too many sections for read-only sections definition packet."));
10650 xsnprintf (target_buf
+ offset
, target_buf_size
- offset
, ":%s,%s",
10652 offset
+= sec_length
;
10656 putpkt (target_buf
);
10657 getpkt (&target_buf
, &target_buf_size
, 0);
10662 remote_trace_start (void)
10664 putpkt ("QTStart");
10665 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10666 if (*target_buf
== '\0')
10667 error (_("Target does not support this command."));
10668 if (strcmp (target_buf
, "OK") != 0)
10669 error (_("Bogus reply from target: %s"), target_buf
);
10673 remote_get_trace_status (struct trace_status
*ts
)
10675 /* Initialize it just to avoid a GCC false warning. */
10677 /* FIXME we need to get register block size some other way. */
10678 extern int trace_regblock_size
;
10679 volatile struct gdb_exception ex
;
10681 trace_regblock_size
= get_remote_arch_state ()->sizeof_g_packet
;
10683 putpkt ("qTStatus");
10685 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10687 p
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10691 exception_fprintf (gdb_stderr
, ex
, "qTStatus: ");
10695 /* If the remote target doesn't do tracing, flag it. */
10699 /* We're working with a live target. */
10700 ts
->filename
= NULL
;
10703 error (_("Bogus trace status reply from target: %s"), target_buf
);
10705 /* Function 'parse_trace_status' sets default value of each field of
10706 'ts' at first, so we don't have to do it here. */
10707 parse_trace_status (p
, ts
);
10709 return ts
->running
;
10713 remote_get_tracepoint_status (struct breakpoint
*bp
,
10714 struct uploaded_tp
*utp
)
10716 struct remote_state
*rs
= get_remote_state ();
10718 struct bp_location
*loc
;
10719 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
10720 size_t size
= get_remote_packet_size ();
10724 tp
->base
.hit_count
= 0;
10725 tp
->traceframe_usage
= 0;
10726 for (loc
= tp
->base
.loc
; loc
; loc
= loc
->next
)
10728 /* If the tracepoint was never downloaded, don't go asking for
10730 if (tp
->number_on_target
== 0)
10732 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", tp
->number_on_target
,
10733 phex_nz (loc
->address
, 0));
10735 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10736 if (reply
&& *reply
)
10739 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10745 utp
->hit_count
= 0;
10746 utp
->traceframe_usage
= 0;
10747 xsnprintf (rs
->buf
, size
, "qTP:%x:%s", utp
->number
,
10748 phex_nz (utp
->addr
, 0));
10750 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10751 if (reply
&& *reply
)
10754 parse_tracepoint_status (reply
+ 1, bp
, utp
);
10760 remote_trace_stop (void)
10763 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10764 if (*target_buf
== '\0')
10765 error (_("Target does not support this command."));
10766 if (strcmp (target_buf
, "OK") != 0)
10767 error (_("Bogus reply from target: %s"), target_buf
);
10771 remote_trace_find (enum trace_find_type type
, int num
,
10772 ULONGEST addr1
, ULONGEST addr2
,
10775 struct remote_state
*rs
= get_remote_state ();
10776 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
10778 int target_frameno
= -1, target_tracept
= -1;
10780 /* Lookups other than by absolute frame number depend on the current
10781 trace selected, so make sure it is correct on the remote end
10783 if (type
!= tfind_number
)
10784 set_remote_traceframe ();
10787 strcpy (p
, "QTFrame:");
10788 p
= strchr (p
, '\0');
10792 xsnprintf (p
, endbuf
- p
, "%x", num
);
10795 xsnprintf (p
, endbuf
- p
, "pc:%s", phex_nz (addr1
, 0));
10798 xsnprintf (p
, endbuf
- p
, "tdp:%x", num
);
10801 xsnprintf (p
, endbuf
- p
, "range:%s:%s", phex_nz (addr1
, 0),
10802 phex_nz (addr2
, 0));
10804 case tfind_outside
:
10805 xsnprintf (p
, endbuf
- p
, "outside:%s:%s", phex_nz (addr1
, 0),
10806 phex_nz (addr2
, 0));
10809 error (_("Unknown trace find type %d"), type
);
10813 reply
= remote_get_noisy_reply (&(rs
->buf
), &sizeof_pkt
);
10814 if (*reply
== '\0')
10815 error (_("Target does not support this command."));
10817 while (reply
&& *reply
)
10822 target_frameno
= (int) strtol (p
, &reply
, 16);
10824 error (_("Unable to parse trace frame number"));
10825 /* Don't update our remote traceframe number cache on failure
10826 to select a remote traceframe. */
10827 if (target_frameno
== -1)
10832 target_tracept
= (int) strtol (p
, &reply
, 16);
10834 error (_("Unable to parse tracepoint number"));
10836 case 'O': /* "OK"? */
10837 if (reply
[1] == 'K' && reply
[2] == '\0')
10840 error (_("Bogus reply from target: %s"), reply
);
10843 error (_("Bogus reply from target: %s"), reply
);
10846 *tpp
= target_tracept
;
10848 remote_traceframe_number
= target_frameno
;
10849 return target_frameno
;
10853 remote_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
10855 struct remote_state
*rs
= get_remote_state ();
10859 set_remote_traceframe ();
10861 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTV:%x", tsvnum
);
10863 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10864 if (reply
&& *reply
)
10868 unpack_varlen_hex (reply
+ 1, &uval
);
10869 *val
= (LONGEST
) uval
;
10877 remote_save_trace_data (const char *filename
)
10879 struct remote_state
*rs
= get_remote_state ();
10883 strcpy (p
, "QTSave:");
10885 if ((p
- rs
->buf
) + strlen (filename
) * 2 >= get_remote_packet_size ())
10886 error (_("Remote file name too long for trace save packet"));
10887 p
+= 2 * bin2hex ((gdb_byte
*) filename
, p
, 0);
10890 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10891 if (*reply
== '\0')
10892 error (_("Target does not support this command."));
10893 if (strcmp (reply
, "OK") != 0)
10894 error (_("Bogus reply from target: %s"), reply
);
10898 /* This is basically a memory transfer, but needs to be its own packet
10899 because we don't know how the target actually organizes its trace
10900 memory, plus we want to be able to ask for as much as possible, but
10901 not be unhappy if we don't get as much as we ask for. */
10904 remote_get_raw_trace_data (gdb_byte
*buf
, ULONGEST offset
, LONGEST len
)
10906 struct remote_state
*rs
= get_remote_state ();
10912 strcpy (p
, "qTBuffer:");
10914 p
+= hexnumstr (p
, offset
);
10916 p
+= hexnumstr (p
, len
);
10920 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10921 if (reply
&& *reply
)
10923 /* 'l' by itself means we're at the end of the buffer and
10924 there is nothing more to get. */
10928 /* Convert the reply into binary. Limit the number of bytes to
10929 convert according to our passed-in buffer size, rather than
10930 what was returned in the packet; if the target is
10931 unexpectedly generous and gives us a bigger reply than we
10932 asked for, we don't want to crash. */
10933 rslt
= hex2bin (target_buf
, buf
, len
);
10937 /* Something went wrong, flag as an error. */
10942 remote_set_disconnected_tracing (int val
)
10944 struct remote_state
*rs
= get_remote_state ();
10946 if (rs
->disconnected_tracing
)
10950 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTDisconnected:%x", val
);
10952 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10953 if (*reply
== '\0')
10954 error (_("Target does not support this command."));
10955 if (strcmp (reply
, "OK") != 0)
10956 error (_("Bogus reply from target: %s"), reply
);
10959 warning (_("Target does not support disconnected tracing."));
10963 remote_core_of_thread (struct target_ops
*ops
, ptid_t ptid
)
10965 struct thread_info
*info
= find_thread_ptid (ptid
);
10967 if (info
&& info
->private)
10968 return info
->private->core
;
10973 remote_set_circular_trace_buffer (int val
)
10975 struct remote_state
*rs
= get_remote_state ();
10978 xsnprintf (rs
->buf
, get_remote_packet_size (), "QTBuffer:circular:%x", val
);
10980 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
10981 if (*reply
== '\0')
10982 error (_("Target does not support this command."));
10983 if (strcmp (reply
, "OK") != 0)
10984 error (_("Bogus reply from target: %s"), reply
);
10987 static struct traceframe_info
*
10988 remote_traceframe_info (void)
10992 text
= target_read_stralloc (¤t_target
,
10993 TARGET_OBJECT_TRACEFRAME_INFO
, NULL
);
10996 struct traceframe_info
*info
;
10997 struct cleanup
*back_to
= make_cleanup (xfree
, text
);
10999 info
= parse_traceframe_info (text
);
11000 do_cleanups (back_to
);
11007 /* Handle the qTMinFTPILen packet. Returns the minimum length of
11008 instruction on which a fast tracepoint may be placed. Returns -1
11009 if the packet is not supported, and 0 if the minimum instruction
11010 length is unknown. */
11013 remote_get_min_fast_tracepoint_insn_len (void)
11015 struct remote_state
*rs
= get_remote_state ();
11018 /* If we're not debugging a process yet, the IPA can't be
11020 if (!target_has_execution
)
11023 /* Make sure the remote is pointing at the right process. */
11024 set_general_process ();
11026 xsnprintf (rs
->buf
, get_remote_packet_size (), "qTMinFTPILen");
11028 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11029 if (*reply
== '\0')
11033 ULONGEST min_insn_len
;
11035 unpack_varlen_hex (reply
, &min_insn_len
);
11037 return (int) min_insn_len
;
11042 remote_set_trace_notes (char *user
, char *notes
, char *stop_notes
)
11044 struct remote_state
*rs
= get_remote_state ();
11046 char *buf
= rs
->buf
;
11047 char *endbuf
= rs
->buf
+ get_remote_packet_size ();
11050 buf
+= xsnprintf (buf
, endbuf
- buf
, "QTNotes:");
11053 buf
+= xsnprintf (buf
, endbuf
- buf
, "user:");
11054 nbytes
= bin2hex (user
, buf
, 0);
11060 buf
+= xsnprintf (buf
, endbuf
- buf
, "notes:");
11061 nbytes
= bin2hex (notes
, buf
, 0);
11067 buf
+= xsnprintf (buf
, endbuf
- buf
, "tstop:");
11068 nbytes
= bin2hex (stop_notes
, buf
, 0);
11072 /* Ensure the buffer is terminated. */
11076 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
11077 if (*reply
== '\0')
11080 if (strcmp (reply
, "OK") != 0)
11081 error (_("Bogus reply from target: %s"), reply
);
11087 remote_use_agent (int use
)
11089 if (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
)
11091 struct remote_state
*rs
= get_remote_state ();
11093 /* If the stub supports QAgent. */
11094 xsnprintf (rs
->buf
, get_remote_packet_size (), "QAgent:%d", use
);
11096 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11098 if (strcmp (rs
->buf
, "OK") == 0)
11109 remote_can_use_agent (void)
11111 return (remote_protocol_packets
[PACKET_QAgent
].support
!= PACKET_DISABLE
);
11115 init_remote_ops (void)
11117 remote_ops
.to_shortname
= "remote";
11118 remote_ops
.to_longname
= "Remote serial target in gdb-specific protocol";
11119 remote_ops
.to_doc
=
11120 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11121 Specify the serial device it is connected to\n\
11122 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
11123 remote_ops
.to_open
= remote_open
;
11124 remote_ops
.to_close
= remote_close
;
11125 remote_ops
.to_detach
= remote_detach
;
11126 remote_ops
.to_disconnect
= remote_disconnect
;
11127 remote_ops
.to_resume
= remote_resume
;
11128 remote_ops
.to_wait
= remote_wait
;
11129 remote_ops
.to_fetch_registers
= remote_fetch_registers
;
11130 remote_ops
.to_store_registers
= remote_store_registers
;
11131 remote_ops
.to_prepare_to_store
= remote_prepare_to_store
;
11132 remote_ops
.deprecated_xfer_memory
= remote_xfer_memory
;
11133 remote_ops
.to_files_info
= remote_files_info
;
11134 remote_ops
.to_insert_breakpoint
= remote_insert_breakpoint
;
11135 remote_ops
.to_remove_breakpoint
= remote_remove_breakpoint
;
11136 remote_ops
.to_stopped_by_watchpoint
= remote_stopped_by_watchpoint
;
11137 remote_ops
.to_stopped_data_address
= remote_stopped_data_address
;
11138 remote_ops
.to_watchpoint_addr_within_range
=
11139 remote_watchpoint_addr_within_range
;
11140 remote_ops
.to_can_use_hw_breakpoint
= remote_check_watch_resources
;
11141 remote_ops
.to_insert_hw_breakpoint
= remote_insert_hw_breakpoint
;
11142 remote_ops
.to_remove_hw_breakpoint
= remote_remove_hw_breakpoint
;
11143 remote_ops
.to_region_ok_for_hw_watchpoint
11144 = remote_region_ok_for_hw_watchpoint
;
11145 remote_ops
.to_insert_watchpoint
= remote_insert_watchpoint
;
11146 remote_ops
.to_remove_watchpoint
= remote_remove_watchpoint
;
11147 remote_ops
.to_kill
= remote_kill
;
11148 remote_ops
.to_load
= generic_load
;
11149 remote_ops
.to_mourn_inferior
= remote_mourn
;
11150 remote_ops
.to_pass_signals
= remote_pass_signals
;
11151 remote_ops
.to_program_signals
= remote_program_signals
;
11152 remote_ops
.to_thread_alive
= remote_thread_alive
;
11153 remote_ops
.to_find_new_threads
= remote_threads_info
;
11154 remote_ops
.to_pid_to_str
= remote_pid_to_str
;
11155 remote_ops
.to_extra_thread_info
= remote_threads_extra_info
;
11156 remote_ops
.to_get_ada_task_ptid
= remote_get_ada_task_ptid
;
11157 remote_ops
.to_stop
= remote_stop
;
11158 remote_ops
.to_xfer_partial
= remote_xfer_partial
;
11159 remote_ops
.to_rcmd
= remote_rcmd
;
11160 remote_ops
.to_log_command
= serial_log_command
;
11161 remote_ops
.to_get_thread_local_address
= remote_get_thread_local_address
;
11162 remote_ops
.to_stratum
= process_stratum
;
11163 remote_ops
.to_has_all_memory
= default_child_has_all_memory
;
11164 remote_ops
.to_has_memory
= default_child_has_memory
;
11165 remote_ops
.to_has_stack
= default_child_has_stack
;
11166 remote_ops
.to_has_registers
= default_child_has_registers
;
11167 remote_ops
.to_has_execution
= default_child_has_execution
;
11168 remote_ops
.to_has_thread_control
= tc_schedlock
; /* can lock scheduler */
11169 remote_ops
.to_can_execute_reverse
= remote_can_execute_reverse
;
11170 remote_ops
.to_magic
= OPS_MAGIC
;
11171 remote_ops
.to_memory_map
= remote_memory_map
;
11172 remote_ops
.to_flash_erase
= remote_flash_erase
;
11173 remote_ops
.to_flash_done
= remote_flash_done
;
11174 remote_ops
.to_read_description
= remote_read_description
;
11175 remote_ops
.to_search_memory
= remote_search_memory
;
11176 remote_ops
.to_can_async_p
= remote_can_async_p
;
11177 remote_ops
.to_is_async_p
= remote_is_async_p
;
11178 remote_ops
.to_async
= remote_async
;
11179 remote_ops
.to_terminal_inferior
= remote_terminal_inferior
;
11180 remote_ops
.to_terminal_ours
= remote_terminal_ours
;
11181 remote_ops
.to_supports_non_stop
= remote_supports_non_stop
;
11182 remote_ops
.to_supports_multi_process
= remote_supports_multi_process
;
11183 remote_ops
.to_supports_disable_randomization
11184 = remote_supports_disable_randomization
;
11185 remote_ops
.to_fileio_open
= remote_hostio_open
;
11186 remote_ops
.to_fileio_pwrite
= remote_hostio_pwrite
;
11187 remote_ops
.to_fileio_pread
= remote_hostio_pread
;
11188 remote_ops
.to_fileio_close
= remote_hostio_close
;
11189 remote_ops
.to_fileio_unlink
= remote_hostio_unlink
;
11190 remote_ops
.to_fileio_readlink
= remote_hostio_readlink
;
11191 remote_ops
.to_supports_enable_disable_tracepoint
= remote_supports_enable_disable_tracepoint
;
11192 remote_ops
.to_supports_string_tracing
= remote_supports_string_tracing
;
11193 remote_ops
.to_supports_evaluation_of_breakpoint_conditions
= remote_supports_cond_breakpoints
;
11194 remote_ops
.to_can_run_breakpoint_commands
= remote_can_run_breakpoint_commands
;
11195 remote_ops
.to_trace_init
= remote_trace_init
;
11196 remote_ops
.to_download_tracepoint
= remote_download_tracepoint
;
11197 remote_ops
.to_can_download_tracepoint
= remote_can_download_tracepoint
;
11198 remote_ops
.to_download_trace_state_variable
11199 = remote_download_trace_state_variable
;
11200 remote_ops
.to_enable_tracepoint
= remote_enable_tracepoint
;
11201 remote_ops
.to_disable_tracepoint
= remote_disable_tracepoint
;
11202 remote_ops
.to_trace_set_readonly_regions
= remote_trace_set_readonly_regions
;
11203 remote_ops
.to_trace_start
= remote_trace_start
;
11204 remote_ops
.to_get_trace_status
= remote_get_trace_status
;
11205 remote_ops
.to_get_tracepoint_status
= remote_get_tracepoint_status
;
11206 remote_ops
.to_trace_stop
= remote_trace_stop
;
11207 remote_ops
.to_trace_find
= remote_trace_find
;
11208 remote_ops
.to_get_trace_state_variable_value
11209 = remote_get_trace_state_variable_value
;
11210 remote_ops
.to_save_trace_data
= remote_save_trace_data
;
11211 remote_ops
.to_upload_tracepoints
= remote_upload_tracepoints
;
11212 remote_ops
.to_upload_trace_state_variables
11213 = remote_upload_trace_state_variables
;
11214 remote_ops
.to_get_raw_trace_data
= remote_get_raw_trace_data
;
11215 remote_ops
.to_get_min_fast_tracepoint_insn_len
= remote_get_min_fast_tracepoint_insn_len
;
11216 remote_ops
.to_set_disconnected_tracing
= remote_set_disconnected_tracing
;
11217 remote_ops
.to_set_circular_trace_buffer
= remote_set_circular_trace_buffer
;
11218 remote_ops
.to_set_trace_notes
= remote_set_trace_notes
;
11219 remote_ops
.to_core_of_thread
= remote_core_of_thread
;
11220 remote_ops
.to_verify_memory
= remote_verify_memory
;
11221 remote_ops
.to_get_tib_address
= remote_get_tib_address
;
11222 remote_ops
.to_set_permissions
= remote_set_permissions
;
11223 remote_ops
.to_static_tracepoint_marker_at
11224 = remote_static_tracepoint_marker_at
;
11225 remote_ops
.to_static_tracepoint_markers_by_strid
11226 = remote_static_tracepoint_markers_by_strid
;
11227 remote_ops
.to_traceframe_info
= remote_traceframe_info
;
11228 remote_ops
.to_use_agent
= remote_use_agent
;
11229 remote_ops
.to_can_use_agent
= remote_can_use_agent
;
11232 /* Set up the extended remote vector by making a copy of the standard
11233 remote vector and adding to it. */
11236 init_extended_remote_ops (void)
11238 extended_remote_ops
= remote_ops
;
11240 extended_remote_ops
.to_shortname
= "extended-remote";
11241 extended_remote_ops
.to_longname
=
11242 "Extended remote serial target in gdb-specific protocol";
11243 extended_remote_ops
.to_doc
=
11244 "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
11245 Specify the serial device it is connected to (e.g. /dev/ttya).";
11246 extended_remote_ops
.to_open
= extended_remote_open
;
11247 extended_remote_ops
.to_create_inferior
= extended_remote_create_inferior
;
11248 extended_remote_ops
.to_mourn_inferior
= extended_remote_mourn
;
11249 extended_remote_ops
.to_detach
= extended_remote_detach
;
11250 extended_remote_ops
.to_attach
= extended_remote_attach
;
11251 extended_remote_ops
.to_kill
= extended_remote_kill
;
11252 extended_remote_ops
.to_supports_disable_randomization
11253 = extended_remote_supports_disable_randomization
;
11257 remote_can_async_p (void)
11259 if (!target_async_permitted
)
11260 /* We only enable async when the user specifically asks for it. */
11263 /* We're async whenever the serial device is. */
11264 return serial_can_async_p (remote_desc
);
11268 remote_is_async_p (void)
11270 if (!target_async_permitted
)
11271 /* We only enable async when the user specifically asks for it. */
11274 /* We're async whenever the serial device is. */
11275 return serial_is_async_p (remote_desc
);
11278 /* Pass the SERIAL event on and up to the client. One day this code
11279 will be able to delay notifying the client of an event until the
11280 point where an entire packet has been received. */
11282 static void (*async_client_callback
) (enum inferior_event_type event_type
,
11284 static void *async_client_context
;
11285 static serial_event_ftype remote_async_serial_handler
;
11288 remote_async_serial_handler (struct serial
*scb
, void *context
)
11290 /* Don't propogate error information up to the client. Instead let
11291 the client find out about the error by querying the target. */
11292 async_client_callback (INF_REG_EVENT
, async_client_context
);
11296 remote_async_inferior_event_handler (gdb_client_data data
)
11298 inferior_event_handler (INF_REG_EVENT
, NULL
);
11302 remote_async (void (*callback
) (enum inferior_event_type event_type
,
11303 void *context
), void *context
)
11305 if (callback
!= NULL
)
11307 serial_async (remote_desc
, remote_async_serial_handler
, NULL
);
11308 async_client_callback
= callback
;
11309 async_client_context
= context
;
11312 serial_async (remote_desc
, NULL
, NULL
);
11316 set_remote_cmd (char *args
, int from_tty
)
11318 help_list (remote_set_cmdlist
, "set remote ", -1, gdb_stdout
);
11322 show_remote_cmd (char *args
, int from_tty
)
11324 /* We can't just use cmd_show_list here, because we want to skip
11325 the redundant "show remote Z-packet" and the legacy aliases. */
11326 struct cleanup
*showlist_chain
;
11327 struct cmd_list_element
*list
= remote_show_cmdlist
;
11328 struct ui_out
*uiout
= current_uiout
;
11330 showlist_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "showlist");
11331 for (; list
!= NULL
; list
= list
->next
)
11332 if (strcmp (list
->name
, "Z-packet") == 0)
11334 else if (list
->type
== not_set_cmd
)
11335 /* Alias commands are exactly like the original, except they
11336 don't have the normal type. */
11340 struct cleanup
*option_chain
11341 = make_cleanup_ui_out_tuple_begin_end (uiout
, "option");
11343 ui_out_field_string (uiout
, "name", list
->name
);
11344 ui_out_text (uiout
, ": ");
11345 if (list
->type
== show_cmd
)
11346 do_show_command ((char *) NULL
, from_tty
, list
);
11348 cmd_func (list
, NULL
, from_tty
);
11349 /* Close the tuple. */
11350 do_cleanups (option_chain
);
11353 /* Close the tuple. */
11354 do_cleanups (showlist_chain
);
11358 /* Function to be called whenever a new objfile (shlib) is detected. */
11360 remote_new_objfile (struct objfile
*objfile
)
11362 if (remote_desc
!= 0) /* Have a remote connection. */
11363 remote_check_symbols (objfile
);
11366 /* Pull all the tracepoints defined on the target and create local
11367 data structures representing them. We don't want to create real
11368 tracepoints yet, we don't want to mess up the user's existing
11372 remote_upload_tracepoints (struct uploaded_tp
**utpp
)
11374 struct remote_state
*rs
= get_remote_state ();
11377 /* Ask for a first packet of tracepoint definition. */
11379 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11381 while (*p
&& *p
!= 'l')
11383 parse_tracepoint_definition (p
, utpp
);
11384 /* Ask for another packet of tracepoint definition. */
11386 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11393 remote_upload_trace_state_variables (struct uploaded_tsv
**utsvp
)
11395 struct remote_state
*rs
= get_remote_state ();
11398 /* Ask for a first packet of variable definition. */
11400 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11402 while (*p
&& *p
!= 'l')
11404 parse_tsv_definition (p
, utsvp
);
11405 /* Ask for another packet of variable definition. */
11407 getpkt (&rs
->buf
, &rs
->buf_size
, 0);
11414 _initialize_remote (void)
11416 struct remote_state
*rs
;
11417 struct cmd_list_element
*cmd
;
11420 /* architecture specific data */
11421 remote_gdbarch_data_handle
=
11422 gdbarch_data_register_post_init (init_remote_state
);
11423 remote_g_packet_data_handle
=
11424 gdbarch_data_register_pre_init (remote_g_packet_data_init
);
11426 /* Initialize the per-target state. At the moment there is only one
11427 of these, not one per target. Only one target is active at a
11428 time. The default buffer size is unimportant; it will be expanded
11429 whenever a larger buffer is needed. */
11430 rs
= get_remote_state_raw ();
11431 rs
->buf_size
= 400;
11432 rs
->buf
= xmalloc (rs
->buf_size
);
11434 init_remote_ops ();
11435 add_target (&remote_ops
);
11437 init_extended_remote_ops ();
11438 add_target (&extended_remote_ops
);
11440 /* Hook into new objfile notification. */
11441 observer_attach_new_objfile (remote_new_objfile
);
11442 /* We're no longer interested in notification events of an inferior
11444 observer_attach_inferior_exit (discard_pending_stop_replies
);
11446 /* Set up signal handlers. */
11447 sigint_remote_token
=
11448 create_async_signal_handler (async_remote_interrupt
, NULL
);
11449 sigint_remote_twice_token
=
11450 create_async_signal_handler (async_remote_interrupt_twice
, NULL
);
11453 init_remote_threadtests ();
11456 stop_reply_queue
= QUEUE_alloc (stop_reply_p
, stop_reply_xfree
);
11457 /* set/show remote ... */
11459 add_prefix_cmd ("remote", class_maintenance
, set_remote_cmd
, _("\
11460 Remote protocol specific variables\n\
11461 Configure various remote-protocol specific variables such as\n\
11462 the packets being used"),
11463 &remote_set_cmdlist
, "set remote ",
11464 0 /* allow-unknown */, &setlist
);
11465 add_prefix_cmd ("remote", class_maintenance
, show_remote_cmd
, _("\
11466 Remote protocol specific variables\n\
11467 Configure various remote-protocol specific variables such as\n\
11468 the packets being used"),
11469 &remote_show_cmdlist
, "show remote ",
11470 0 /* allow-unknown */, &showlist
);
11472 add_cmd ("compare-sections", class_obscure
, compare_sections_command
, _("\
11473 Compare section data on target to the exec file.\n\
11474 Argument is a single section name (default: all loaded sections)."),
11477 add_cmd ("packet", class_maintenance
, packet_command
, _("\
11478 Send an arbitrary packet to a remote target.\n\
11479 maintenance packet TEXT\n\
11480 If GDB is talking to an inferior via the GDB serial protocol, then\n\
11481 this command sends the string TEXT to the inferior, and displays the\n\
11482 response packet. GDB supplies the initial `$' character, and the\n\
11483 terminating `#' character and checksum."),
11486 add_setshow_boolean_cmd ("remotebreak", no_class
, &remote_break
, _("\
11487 Set whether to send break if interrupted."), _("\
11488 Show whether to send break if interrupted."), _("\
11489 If set, a break, instead of a cntrl-c, is sent to the remote target."),
11490 set_remotebreak
, show_remotebreak
,
11491 &setlist
, &showlist
);
11492 cmd_name
= "remotebreak";
11493 cmd
= lookup_cmd (&cmd_name
, setlist
, "", -1, 1);
11494 deprecate_cmd (cmd
, "set remote interrupt-sequence");
11495 cmd_name
= "remotebreak"; /* needed because lookup_cmd updates the pointer */
11496 cmd
= lookup_cmd (&cmd_name
, showlist
, "", -1, 1);
11497 deprecate_cmd (cmd
, "show remote interrupt-sequence");
11499 add_setshow_enum_cmd ("interrupt-sequence", class_support
,
11500 interrupt_sequence_modes
, &interrupt_sequence_mode
,
11502 Set interrupt sequence to remote target."), _("\
11503 Show interrupt sequence to remote target."), _("\
11504 Valid value is \"Ctrl-C\", \"BREAK\" or \"BREAK-g\". The default is \"Ctrl-C\"."),
11505 NULL
, show_interrupt_sequence
,
11506 &remote_set_cmdlist
,
11507 &remote_show_cmdlist
);
11509 add_setshow_boolean_cmd ("interrupt-on-connect", class_support
,
11510 &interrupt_on_connect
, _("\
11511 Set whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11512 Show whether interrupt-sequence is sent to remote target when gdb connects to."), _(" \
11513 If set, interrupt sequence is sent to remote target."),
11515 &remote_set_cmdlist
, &remote_show_cmdlist
);
11517 /* Install commands for configuring memory read/write packets. */
11519 add_cmd ("remotewritesize", no_class
, set_memory_write_packet_size
, _("\
11520 Set the maximum number of bytes per memory write packet (deprecated)."),
11522 add_cmd ("remotewritesize", no_class
, show_memory_write_packet_size
, _("\
11523 Show the maximum number of bytes per memory write packet (deprecated)."),
11525 add_cmd ("memory-write-packet-size", no_class
,
11526 set_memory_write_packet_size
, _("\
11527 Set the maximum number of bytes per memory-write packet.\n\
11528 Specify the number of bytes in a packet or 0 (zero) for the\n\
11529 default packet size. The actual limit is further reduced\n\
11530 dependent on the target. Specify ``fixed'' to disable the\n\
11531 further restriction and ``limit'' to enable that restriction."),
11532 &remote_set_cmdlist
);
11533 add_cmd ("memory-read-packet-size", no_class
,
11534 set_memory_read_packet_size
, _("\
11535 Set the maximum number of bytes per memory-read packet.\n\
11536 Specify the number of bytes in a packet or 0 (zero) for the\n\
11537 default packet size. The actual limit is further reduced\n\
11538 dependent on the target. Specify ``fixed'' to disable the\n\
11539 further restriction and ``limit'' to enable that restriction."),
11540 &remote_set_cmdlist
);
11541 add_cmd ("memory-write-packet-size", no_class
,
11542 show_memory_write_packet_size
,
11543 _("Show the maximum number of bytes per memory-write packet."),
11544 &remote_show_cmdlist
);
11545 add_cmd ("memory-read-packet-size", no_class
,
11546 show_memory_read_packet_size
,
11547 _("Show the maximum number of bytes per memory-read packet."),
11548 &remote_show_cmdlist
);
11550 add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class
,
11551 &remote_hw_watchpoint_limit
, _("\
11552 Set the maximum number of target hardware watchpoints."), _("\
11553 Show the maximum number of target hardware watchpoints."), _("\
11554 Specify a negative limit for unlimited."),
11555 NULL
, NULL
, /* FIXME: i18n: The maximum
11556 number of target hardware
11557 watchpoints is %s. */
11558 &remote_set_cmdlist
, &remote_show_cmdlist
);
11559 add_setshow_zinteger_cmd ("hardware-watchpoint-length-limit", no_class
,
11560 &remote_hw_watchpoint_length_limit
, _("\
11561 Set the maximum length (in bytes) of a target hardware watchpoint."), _("\
11562 Show the maximum length (in bytes) of a target hardware watchpoint."), _("\
11563 Specify a negative limit for unlimited."),
11564 NULL
, NULL
, /* FIXME: i18n: The maximum
11565 length (in bytes) of a target
11566 hardware watchpoint is %s. */
11567 &remote_set_cmdlist
, &remote_show_cmdlist
);
11568 add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class
,
11569 &remote_hw_breakpoint_limit
, _("\
11570 Set the maximum number of target hardware breakpoints."), _("\
11571 Show the maximum number of target hardware breakpoints."), _("\
11572 Specify a negative limit for unlimited."),
11573 NULL
, NULL
, /* FIXME: i18n: The maximum
11574 number of target hardware
11575 breakpoints is %s. */
11576 &remote_set_cmdlist
, &remote_show_cmdlist
);
11578 add_setshow_uinteger_cmd ("remoteaddresssize", class_obscure
,
11579 &remote_address_size
, _("\
11580 Set the maximum size of the address (in bits) in a memory packet."), _("\
11581 Show the maximum size of the address (in bits) in a memory packet."), NULL
,
11583 NULL
, /* FIXME: i18n: */
11584 &setlist
, &showlist
);
11586 add_packet_config_cmd (&remote_protocol_packets
[PACKET_X
],
11587 "X", "binary-download", 1);
11589 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vCont
],
11590 "vCont", "verbose-resume", 0);
11592 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QPassSignals
],
11593 "QPassSignals", "pass-signals", 0);
11595 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QProgramSignals
],
11596 "QProgramSignals", "program-signals", 0);
11598 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSymbol
],
11599 "qSymbol", "symbol-lookup", 0);
11601 add_packet_config_cmd (&remote_protocol_packets
[PACKET_P
],
11602 "P", "set-register", 1);
11604 add_packet_config_cmd (&remote_protocol_packets
[PACKET_p
],
11605 "p", "fetch-register", 1);
11607 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z0
],
11608 "Z0", "software-breakpoint", 0);
11610 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z1
],
11611 "Z1", "hardware-breakpoint", 0);
11613 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z2
],
11614 "Z2", "write-watchpoint", 0);
11616 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z3
],
11617 "Z3", "read-watchpoint", 0);
11619 add_packet_config_cmd (&remote_protocol_packets
[PACKET_Z4
],
11620 "Z4", "access-watchpoint", 0);
11622 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_auxv
],
11623 "qXfer:auxv:read", "read-aux-vector", 0);
11625 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_features
],
11626 "qXfer:features:read", "target-features", 0);
11628 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries
],
11629 "qXfer:libraries:read", "library-info", 0);
11631 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_libraries_svr4
],
11632 "qXfer:libraries-svr4:read", "library-info-svr4", 0);
11634 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_memory_map
],
11635 "qXfer:memory-map:read", "memory-map", 0);
11637 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_read
],
11638 "qXfer:spu:read", "read-spu-object", 0);
11640 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_spu_write
],
11641 "qXfer:spu:write", "write-spu-object", 0);
11643 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_osdata
],
11644 "qXfer:osdata:read", "osdata", 0);
11646 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_threads
],
11647 "qXfer:threads:read", "threads", 0);
11649 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_read
],
11650 "qXfer:siginfo:read", "read-siginfo-object", 0);
11652 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_siginfo_write
],
11653 "qXfer:siginfo:write", "write-siginfo-object", 0);
11655 add_packet_config_cmd
11656 (&remote_protocol_packets
[PACKET_qXfer_traceframe_info
],
11657 "qXfer:trace-frame-info:read", "traceframe-info", 0);
11659 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_uib
],
11660 "qXfer:uib:read", "unwind-info-block", 0);
11662 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTLSAddr
],
11663 "qGetTLSAddr", "get-thread-local-storage-address",
11666 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qGetTIBAddr
],
11667 "qGetTIBAddr", "get-thread-information-block-address",
11670 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bc
],
11671 "bc", "reverse-continue", 0);
11673 add_packet_config_cmd (&remote_protocol_packets
[PACKET_bs
],
11674 "bs", "reverse-step", 0);
11676 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSupported
],
11677 "qSupported", "supported-packets", 0);
11679 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qSearch_memory
],
11680 "qSearch:memory", "search-memory", 0);
11682 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_open
],
11683 "vFile:open", "hostio-open", 0);
11685 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pread
],
11686 "vFile:pread", "hostio-pread", 0);
11688 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_pwrite
],
11689 "vFile:pwrite", "hostio-pwrite", 0);
11691 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_close
],
11692 "vFile:close", "hostio-close", 0);
11694 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_unlink
],
11695 "vFile:unlink", "hostio-unlink", 0);
11697 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vFile_readlink
],
11698 "vFile:readlink", "hostio-readlink", 0);
11700 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vAttach
],
11701 "vAttach", "attach", 0);
11703 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vRun
],
11706 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QStartNoAckMode
],
11707 "QStartNoAckMode", "noack", 0);
11709 add_packet_config_cmd (&remote_protocol_packets
[PACKET_vKill
],
11710 "vKill", "kill", 0);
11712 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qAttached
],
11713 "qAttached", "query-attached", 0);
11715 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalTracepoints
],
11716 "ConditionalTracepoints",
11717 "conditional-tracepoints", 0);
11719 add_packet_config_cmd (&remote_protocol_packets
[PACKET_ConditionalBreakpoints
],
11720 "ConditionalBreakpoints",
11721 "conditional-breakpoints", 0);
11723 add_packet_config_cmd (&remote_protocol_packets
[PACKET_BreakpointCommands
],
11724 "BreakpointCommands",
11725 "breakpoint-commands", 0);
11727 add_packet_config_cmd (&remote_protocol_packets
[PACKET_FastTracepoints
],
11728 "FastTracepoints", "fast-tracepoints", 0);
11730 add_packet_config_cmd (&remote_protocol_packets
[PACKET_TracepointSource
],
11731 "TracepointSource", "TracepointSource", 0);
11733 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAllow
],
11734 "QAllow", "allow", 0);
11736 add_packet_config_cmd (&remote_protocol_packets
[PACKET_StaticTracepoints
],
11737 "StaticTracepoints", "static-tracepoints", 0);
11739 add_packet_config_cmd (&remote_protocol_packets
[PACKET_InstallInTrace
],
11740 "InstallInTrace", "install-in-trace", 0);
11742 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_statictrace_read
],
11743 "qXfer:statictrace:read", "read-sdata-object", 0);
11745 add_packet_config_cmd (&remote_protocol_packets
[PACKET_qXfer_fdpic
],
11746 "qXfer:fdpic:read", "read-fdpic-loadmap", 0);
11748 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QDisableRandomization
],
11749 "QDisableRandomization", "disable-randomization", 0);
11751 add_packet_config_cmd (&remote_protocol_packets
[PACKET_QAgent
],
11752 "QAgent", "agent", 0);
11754 /* Keep the old ``set remote Z-packet ...'' working. Each individual
11755 Z sub-packet has its own set and show commands, but users may
11756 have sets to this variable in their .gdbinit files (or in their
11758 add_setshow_auto_boolean_cmd ("Z-packet", class_obscure
,
11759 &remote_Z_packet_detect
, _("\
11760 Set use of remote protocol `Z' packets"), _("\
11761 Show use of remote protocol `Z' packets "), _("\
11762 When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
11764 set_remote_protocol_Z_packet_cmd
,
11765 show_remote_protocol_Z_packet_cmd
,
11766 /* FIXME: i18n: Use of remote protocol
11767 `Z' packets is %s. */
11768 &remote_set_cmdlist
, &remote_show_cmdlist
);
11770 add_prefix_cmd ("remote", class_files
, remote_command
, _("\
11771 Manipulate files on the remote system\n\
11772 Transfer files to and from the remote target system."),
11773 &remote_cmdlist
, "remote ",
11774 0 /* allow-unknown */, &cmdlist
);
11776 add_cmd ("put", class_files
, remote_put_command
,
11777 _("Copy a local file to the remote system."),
11780 add_cmd ("get", class_files
, remote_get_command
,
11781 _("Copy a remote file to the local system."),
11784 add_cmd ("delete", class_files
, remote_delete_command
,
11785 _("Delete a remote file."),
11788 remote_exec_file
= xstrdup ("");
11789 add_setshow_string_noescape_cmd ("exec-file", class_files
,
11790 &remote_exec_file
, _("\
11791 Set the remote pathname for \"run\""), _("\
11792 Show the remote pathname for \"run\""), NULL
, NULL
, NULL
,
11793 &remote_set_cmdlist
, &remote_show_cmdlist
);
11795 /* Eventually initialize fileio. See fileio.c */
11796 initialize_remote_fileio (remote_set_cmdlist
, remote_show_cmdlist
);
11798 /* Take advantage of the fact that the LWP field is not used, to tag
11799 special ptids with it set to != 0. */
11800 magic_null_ptid
= ptid_build (42000, 1, -1);
11801 not_sent_ptid
= ptid_build (42000, 1, -2);
11802 any_thread_ptid
= ptid_build (42000, 1, 0);
11804 target_buf_size
= 2048;
11805 target_buf
= xmalloc (target_buf_size
);